mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
Merge branch 'master' into variable-exchangeRate-decimal
This commit is contained in:
commit
a81ed67a7e
|
@ -1,63 +0,0 @@
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
pragma solidity ^0.6.8;
|
|
||||||
pragma experimental ABIEncoderV2;
|
|
||||||
|
|
||||||
interface IndexInterface {
|
|
||||||
function master() external view returns (address);
|
|
||||||
}
|
|
||||||
|
|
||||||
contract Registry {
|
|
||||||
|
|
||||||
event LogAddSigner(address indexed signer);
|
|
||||||
event LogRemoveSigner(address indexed signer);
|
|
||||||
|
|
||||||
event LogSuccess(address indexed flusher, bytes callData);
|
|
||||||
event LogFailed(address indexed flusher, bytes callData);
|
|
||||||
|
|
||||||
|
|
||||||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
|
||||||
|
|
||||||
mapping (address => bool) public signer;
|
|
||||||
|
|
||||||
modifier isMaster() {
|
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
modifier isSigner() {
|
|
||||||
require(signer[msg.sender], "not-chief");
|
|
||||||
_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Enable New Signer.
|
|
||||||
* @param _signer Address of the new signer.
|
|
||||||
*/
|
|
||||||
function enableSigner(address _signer) external isMaster {
|
|
||||||
require(_signer != address(0), "invalid-address");
|
|
||||||
require(!signer[_signer], "signer-already-enabled");
|
|
||||||
signer[_signer] = true;
|
|
||||||
emit LogAddSigner(_signer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dev Disable Signer.
|
|
||||||
* @param _signer Address of the existing signer.
|
|
||||||
*/
|
|
||||||
function disableSigner(address _signer) external isMaster {
|
|
||||||
require(_signer != address(0), "invalid-address");
|
|
||||||
require(signer[_signer], "signer-already-disabled");
|
|
||||||
delete signer[_signer];
|
|
||||||
emit LogRemoveSigner(_signer);
|
|
||||||
}
|
|
||||||
|
|
||||||
function batchTx(address[] memory flushers, bytes[] memory calldatas) external isSigner {
|
|
||||||
require(flushers.length == calldatas.length, "not-same-length");
|
|
||||||
for (uint i = 0; i < flushers.length; i++) {
|
|
||||||
(bool status, ) = payable(flushers[i]).call(calldatas[i]);
|
|
||||||
if (status) emit LogSuccess(flushers[i], calldatas[i]);
|
|
||||||
else emit LogFailed(flushers[i], calldatas[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -37,53 +37,31 @@ contract Flusher {
|
||||||
|
|
||||||
event LogInit(address indexed owner);
|
event LogInit(address indexed owner);
|
||||||
event LogSwitch(bool indexed shieldState);
|
event LogSwitch(bool indexed shieldState);
|
||||||
|
event LogDeposit(address indexed token, address indexed tokenPool, uint amount);
|
||||||
event LogDeposit(
|
event LogWithdraw(address indexed token, address indexed tokenPool,uint amount);
|
||||||
address indexed caller,
|
event LogWithdrawToOwner(address indexed token, address indexed owner, uint amount);
|
||||||
address indexed token,
|
|
||||||
address indexed tokenPool,
|
|
||||||
uint amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event LogWithdraw(
|
|
||||||
address indexed caller,
|
|
||||||
address indexed token,
|
|
||||||
address indexed tokenPool,
|
|
||||||
uint amount
|
|
||||||
);
|
|
||||||
|
|
||||||
event LogWithdrawToOwner(
|
|
||||||
address indexed caller,
|
|
||||||
address indexed token,
|
|
||||||
address indexed owner,
|
|
||||||
uint amount
|
|
||||||
);
|
|
||||||
|
|
||||||
function deposit(address token) public payable isSigner {
|
function deposit(address token) public payable isSigner {
|
||||||
require(address(token) != address(0), "invalid-token");
|
require(address(token) != address(0), "invalid-token");
|
||||||
|
|
||||||
address poolToken = registry.poolToken(token);
|
address poolToken = registry.poolToken(token);
|
||||||
IERC20 tokenContract = IERC20(token);
|
require(poolToken != address(0), "invalid-pool");
|
||||||
|
|
||||||
if (poolToken != address(0)) {
|
IERC20 tokenContract = IERC20(token);
|
||||||
YieldPool poolContract = YieldPool(poolToken);
|
|
||||||
uint amt;
|
|
||||||
if (address(tokenContract) == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) {
|
|
||||||
amt = address(this).balance;
|
|
||||||
poolContract.deposit{value: amt}(amt);
|
|
||||||
} else {
|
|
||||||
amt = tokenContract.balanceOf(address(this));
|
|
||||||
if (tokenContract.allowance(address(this), address(poolContract)) == 0)
|
|
||||||
tokenContract.approve(address(poolContract), uint(-1));
|
|
||||||
|
|
||||||
poolContract.deposit(amt);
|
YieldPool poolContract = YieldPool(poolToken);
|
||||||
}
|
uint amt;
|
||||||
emit LogDeposit(msg.sender, token, address(poolContract), amt);
|
if (address(tokenContract) == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)) {
|
||||||
|
amt = address(this).balance;
|
||||||
|
poolContract.deposit{value: amt}(amt);
|
||||||
} else {
|
} else {
|
||||||
uint amt = tokenContract.balanceOf(address(this));
|
amt = tokenContract.balanceOf(address(this));
|
||||||
tokenContract.safeTransfer(owner, amt);
|
if (tokenContract.allowance(address(this), address(poolContract)) == 0)
|
||||||
emit LogWithdrawToOwner(msg.sender, token, owner, amt);
|
tokenContract.approve(address(poolContract), uint(-1));
|
||||||
|
|
||||||
|
poolContract.deposit(amt);
|
||||||
}
|
}
|
||||||
|
emit LogDeposit(token, address(poolContract), amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function withdraw(address token, uint amount) external isSigner returns (uint _amount) {
|
function withdraw(address token, uint amount) external isSigner returns (uint _amount) {
|
||||||
|
@ -92,7 +70,7 @@ contract Flusher {
|
||||||
require(poolToken != address(0), "invalid-pool");
|
require(poolToken != address(0), "invalid-pool");
|
||||||
|
|
||||||
_amount = YieldPool(poolToken).withdraw(amount, owner);
|
_amount = YieldPool(poolToken).withdraw(amount, owner);
|
||||||
emit LogWithdraw(msg.sender, token, poolToken, _amount);
|
emit LogWithdraw(token, poolToken, _amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,11 +88,13 @@ contract Flusher {
|
||||||
amount = tokenContract.balanceOf(address(this));
|
amount = tokenContract.balanceOf(address(this));
|
||||||
tokenContract.safeTransfer(address(owner), amount);
|
tokenContract.safeTransfer(address(owner), amount);
|
||||||
}
|
}
|
||||||
emit LogWithdrawToOwner(msg.sender, token, owner, amount);
|
emit LogWithdrawToOwner(token, owner, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBasic(address newOwner, address token) external {
|
function setBasic(address newOwner, address token) external {
|
||||||
require(owner == address(0), "already-an-owner");
|
require(owner == address(0), "already-an-owner");
|
||||||
|
require(newOwner != address(0), "not-vaild-owner-address");
|
||||||
|
require(token != address(0), "not-vaild-token-address");
|
||||||
owner = payable(newOwner);
|
owner = payable(newOwner);
|
||||||
deposit(token);
|
deposit(token);
|
||||||
emit LogInit(newOwner);
|
emit LogInit(newOwner);
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
pragma solidity ^0.6.8;
|
|
||||||
|
|
||||||
import { DSMath } from "../libs/safeMath.sol";
|
|
||||||
|
|
||||||
interface PoolTokenInterface {
|
|
||||||
function totalBalance() external view returns (uint);
|
|
||||||
function dsaAmount() external view returns (uint);
|
|
||||||
function totalSupply() external view returns (uint);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ATokenInterface {
|
|
||||||
function balanceOf(address) external view returns (uint);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CTokenInterface {
|
|
||||||
function getExchangeRate() external view returns (uint);
|
|
||||||
function balanceOf(address) external view returns (uint);
|
|
||||||
}
|
|
||||||
|
|
||||||
contract RateLogic is DSMath {
|
|
||||||
PoolTokenInterface poolToken = PoolTokenInterface(address(0));
|
|
||||||
ATokenInterface atoken = ATokenInterface(address(0));
|
|
||||||
CTokenInterface ctoken = CTokenInterface(address(0));
|
|
||||||
CTokenInterface token = CTokenInterface(address(0));
|
|
||||||
|
|
||||||
function getTotalToken() public view returns (uint) {
|
|
||||||
address _dsa;
|
|
||||||
uint abal = atoken.balanceOf(_dsa);
|
|
||||||
uint cbal = wmul(ctoken.balanceOf(_dsa), ctoken.getExchangeRate());
|
|
||||||
uint dsaBal = token.balanceOf(_dsa);
|
|
||||||
uint poolBal = token.balanceOf(address(poolToken));
|
|
||||||
return add(add(abal, poolBal) , add(cbal, dsaBal));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,6 +5,7 @@ pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
interface IndexInterface {
|
interface IndexInterface {
|
||||||
function master() external view returns (address);
|
function master() external view returns (address);
|
||||||
|
function build(address _owner, uint accountVersion, address _origin) external returns (address _account);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
|
@ -13,12 +14,14 @@ contract Registry {
|
||||||
event LogRemoveChief(address indexed chief);
|
event LogRemoveChief(address indexed chief);
|
||||||
event LogAddSigner(address indexed signer);
|
event LogAddSigner(address indexed signer);
|
||||||
event LogRemoveSigner(address indexed signer);
|
event LogRemoveSigner(address indexed signer);
|
||||||
event LogSwitchPool(address pool, bool);
|
event LogSwitchPool(address pool, bool poolState);
|
||||||
event LogUpdatePoolCap(address pool, uint newCap);
|
event LogUpdatePoolCap(address pool, uint newCap);
|
||||||
event LogUpdatePoolLogic(address pool, address newLogic);
|
event LogUpdatePoolLogic(address pool, address newLogic);
|
||||||
event LogUpdateInsureFee(address pool, uint newFee);
|
event LogUpdateInsureFee(address pool, uint newFee);
|
||||||
event LogAddPool(address indexed token, address indexed pool);
|
event LogAddPool(address indexed token, address indexed pool);
|
||||||
event LogRemovePool(address indexed token, address indexed pool);
|
event LogRemovePool(address indexed token, address indexed pool);
|
||||||
|
event LogNewDSA(address indexed pool, address indexed dsa);
|
||||||
|
event LogRemoveDSA(address indexed pool, address indexed dsa);
|
||||||
|
|
||||||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
||||||
|
|
||||||
|
@ -134,13 +137,20 @@ contract Registry {
|
||||||
emit LogUpdateInsureFee(_pool, _newFee);
|
emit LogUpdateInsureFee(_pool, _newFee);
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableDsa(address _pool, address _dsa) external isMaster {
|
function addDsa(address _pool, address _dsa) external isMaster {
|
||||||
require(isPool[_pool], "not-pool");
|
require(isPool[_pool], "not-pool");
|
||||||
|
if (_dsa == address(0)) {
|
||||||
|
_dsa = instaIndex.build(_pool, 1, address(this));
|
||||||
|
}
|
||||||
isDsa[_pool][_dsa] = true;
|
isDsa[_pool][_dsa] = true;
|
||||||
|
emit LogNewDSA(_pool, _dsa);
|
||||||
}
|
}
|
||||||
|
|
||||||
function disableDsa(address _pool, address _dsa) external isMaster {
|
function removeDsa(address _pool, address _dsa) external isMaster {
|
||||||
|
require(isPool[_pool], "not-pool");
|
||||||
|
require(isDsa[_pool][_dsa], "not-dsa-for-pool");
|
||||||
delete isDsa[_pool][_dsa];
|
delete isDsa[_pool][_dsa];
|
||||||
|
emit LogRemoveDSA(_pool, _dsa);
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(address _chief) public {
|
constructor(address _chief) public {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { DSMath } from "./libs/safeMath.sol";
|
||||||
|
|
||||||
interface AccountInterface {
|
interface AccountInterface {
|
||||||
function enable(address authority) external;
|
function enable(address authority) external;
|
||||||
|
function isAuth(address) external view returns(bool);
|
||||||
function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable;
|
function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
|
|
||||||
function deploy(address _dsa, address token, uint amount) public isChief {
|
function deploy(address _dsa, address token, uint amount) public isChief {
|
||||||
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
|
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
|
||||||
|
require(AccountInterface(_dsa).isAuth(address(this)), "token-pool-not-auth");
|
||||||
if (token == address(0)) {
|
if (token == address(0)) {
|
||||||
baseToken.safeTransfer(_dsa, amount);
|
baseToken.safeTransfer(_dsa, amount);
|
||||||
} else if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE){
|
} else if (token == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE){
|
||||||
|
@ -99,9 +101,12 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
|
|
||||||
function settle(address _dsa, address[] calldata _targets, bytes[] calldata _datas, address _origin) external isChief {
|
function settle(address _dsa, address[] calldata _targets, bytes[] calldata _datas, address _origin) external isChief {
|
||||||
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
|
require(registry.isDsa(address(this), _dsa), "not-autheticated-dsa");
|
||||||
|
AccountInterface dsaWallet = AccountInterface(_dsa);
|
||||||
if (_targets.length > 0 && _datas.length > 0) {
|
if (_targets.length > 0 && _datas.length > 0) {
|
||||||
AccountInterface(_dsa).cast(_targets, _datas, _origin);
|
dsaWallet.cast(_targets, _datas, _origin);
|
||||||
}
|
}
|
||||||
|
require(dsaWallet.isAuth(address(this)), "token-pool-not-auth");
|
||||||
|
|
||||||
setExchangeRate();
|
setExchangeRate();
|
||||||
emit LogSettle(block.timestamp);
|
emit LogSettle(block.timestamp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user