mirror of
https://github.com/Instadapp/yield-contract.git
synced 2024-07-29 21:47:29 +00:00
Added comments; Added user
address in deposit and withdraw
This commit is contained in:
parent
1c2bd398f1
commit
2da1029857
|
@ -36,8 +36,8 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
event LogDeploy(address indexed dsa, address token, uint amount);
|
event LogDeploy(address indexed dsa, address token, uint amount);
|
||||||
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
|
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
|
||||||
event LogSettle(uint settleBlock);
|
event LogSettle(uint settleBlock);
|
||||||
event LogDeposit(uint depositAmt, uint poolMintAmt);
|
event LogDeposit(address indexed user, uint depositAmt, uint poolMintAmt);
|
||||||
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
|
event LogWithdraw(address indexed user, uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
|
||||||
event LogAddInsurance(uint amount);
|
event LogAddInsurance(uint amount);
|
||||||
event LogWithdrawInsurance(uint amount);
|
event LogWithdrawInsurance(uint amount);
|
||||||
event LogPausePool(bool);
|
event LogPausePool(bool);
|
||||||
|
@ -66,6 +66,12 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deploy assets to DSA.
|
||||||
|
* @param _dsa DSA address
|
||||||
|
* @param token token address
|
||||||
|
* @param amount token amount
|
||||||
|
*/
|
||||||
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");
|
require(AccountInterface(_dsa).isAuth(address(this)), "token-pool-not-auth");
|
||||||
|
@ -116,6 +122,13 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Settle the assets on dsa and update exchange rate
|
||||||
|
* @param _dsa DSA address
|
||||||
|
* @param _targets array of connector's address
|
||||||
|
* @param _datas array of connector's function calldata
|
||||||
|
* @param _origin origin address
|
||||||
|
*/
|
||||||
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);
|
AccountInterface dsaWallet = AccountInterface(_dsa);
|
||||||
|
@ -127,6 +140,11 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
emit LogSettle(block.number);
|
emit LogSettle(block.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit token.
|
||||||
|
* @param tknAmt token amount
|
||||||
|
* @return _mintAmt amount of wrap token minted
|
||||||
|
*/
|
||||||
function deposit(uint tknAmt) external whenNotPaused payable returns (uint _mintAmt) {
|
function deposit(uint tknAmt) external whenNotPaused payable returns (uint _mintAmt) {
|
||||||
require(msg.value == 0, "non-eth-pool");
|
require(msg.value == 0, "non-eth-pool");
|
||||||
tokenBalance = add(tokenBalance, tknAmt);
|
tokenBalance = add(tokenBalance, tknAmt);
|
||||||
|
@ -135,9 +153,15 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
_mintAmt = wmul(tknAmt, exchangeRate);
|
_mintAmt = wmul(tknAmt, exchangeRate);
|
||||||
_mint(msg.sender, _mintAmt);
|
_mint(msg.sender, _mintAmt);
|
||||||
|
|
||||||
emit LogDeposit(tknAmt, _mintAmt);
|
emit LogDeposit(msg.sender, tknAmt, _mintAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw tokens.
|
||||||
|
* @param tknAmt token amount
|
||||||
|
* @param to withdraw tokens to address
|
||||||
|
* @return _tknAmt amount of token withdrawn
|
||||||
|
*/
|
||||||
function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) {
|
function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) {
|
||||||
uint poolBal = baseToken.balanceOf(address(this));
|
uint poolBal = baseToken.balanceOf(address(this));
|
||||||
require(tknAmt <= poolBal, "not-enough-liquidity-available");
|
require(tknAmt <= poolBal, "not-enough-liquidity-available");
|
||||||
|
@ -167,15 +191,24 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
|
|
||||||
baseToken.safeTransfer(to, _tknAmt);
|
baseToken.safeTransfer(to, _tknAmt);
|
||||||
|
|
||||||
emit LogWithdraw(tknAmt, _burnAmt, _feeAmt);
|
emit LogWithdraw(msg.sender, tknAmt, _burnAmt, _feeAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Add Insurance to the pool.
|
||||||
|
* @param tknAmt insurance token amount to add
|
||||||
|
*/
|
||||||
function addInsurance(uint tknAmt) external {
|
function addInsurance(uint tknAmt) external {
|
||||||
baseToken.safeTransferFrom(msg.sender, address(this), tknAmt);
|
baseToken.safeTransferFrom(msg.sender, address(this), tknAmt);
|
||||||
insuranceAmt = add(insuranceAmt, tknAmt);
|
insuranceAmt = add(insuranceAmt, tknAmt);
|
||||||
emit LogAddInsurance(tknAmt);
|
emit LogAddInsurance(tknAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Insurance from the pool.
|
||||||
|
* @notice only master can call this function.
|
||||||
|
* @param tknAmt insurance token amount to remove
|
||||||
|
*/
|
||||||
function withdrawInsurance(uint tknAmt) external {
|
function withdrawInsurance(uint tknAmt) external {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
require(tknAmt <= insuranceAmt, "not-enough-insurance");
|
require(tknAmt <= insuranceAmt, "not-enough-insurance");
|
||||||
|
@ -184,6 +217,10 @@ contract PoolToken is ReentrancyGuard, DSMath, ERC20Pausable {
|
||||||
emit LogWithdrawInsurance(tknAmt);
|
emit LogWithdrawInsurance(tknAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Shut the pool.
|
||||||
|
* @notice only master can call this function.
|
||||||
|
*/
|
||||||
function shutdown() external {
|
function shutdown() external {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
paused() ? _unpause() : _pause();
|
paused() ? _unpause() : _pause();
|
||||||
|
|
|
@ -36,8 +36,8 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
event LogDeploy(address indexed dsa, address indexed token, uint amount);
|
event LogDeploy(address indexed dsa, address indexed token, uint amount);
|
||||||
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
|
event LogExchangeRate(uint exchangeRate, uint tokenBalance, uint insuranceAmt);
|
||||||
event LogSettle(uint settleBlock);
|
event LogSettle(uint settleBlock);
|
||||||
event LogDeposit(uint depositAmt, uint poolMintAmt);
|
event LogDeposit(address indexed user, uint depositAmt, uint poolMintAmt);
|
||||||
event LogWithdraw(uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
|
event LogWithdraw(address indexed user, uint withdrawAmt, uint poolBurnAmt, uint feeAmt);
|
||||||
event LogAddInsurance(uint amount);
|
event LogAddInsurance(uint amount);
|
||||||
event LogWithdrawInsurance(uint amount);
|
event LogWithdrawInsurance(uint amount);
|
||||||
event LogPausePool(bool);
|
event LogPausePool(bool);
|
||||||
|
@ -46,7 +46,7 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
IndexInterface public constant instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723);
|
||||||
|
|
||||||
IERC20 public immutable baseToken; // Base token.
|
IERC20 public immutable baseToken; // Base token.
|
||||||
uint private tokenBalance; // total token balance since last rebalancing
|
uint private tokenBalance; // total token balance
|
||||||
uint public exchangeRate = 10 ** 18; // initial 1 token = 1
|
uint public exchangeRate = 10 ** 18; // initial 1 token = 1
|
||||||
uint public insuranceAmt; // insurance amount to keep pool safe
|
uint public insuranceAmt; // insurance amount to keep pool safe
|
||||||
|
|
||||||
|
@ -65,6 +65,12 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deploy assets to DSA.
|
||||||
|
* @param _dsa DSA address
|
||||||
|
* @param token token address
|
||||||
|
* @param amount token amount
|
||||||
|
*/
|
||||||
function deploy(address _dsa, address token, uint amount) external isChief {
|
function deploy(address _dsa, address token, uint amount) external 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");
|
require(AccountInterface(_dsa).isAuth(address(this)), "token-pool-not-auth");
|
||||||
|
@ -79,14 +85,14 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
/**
|
/**
|
||||||
* @dev get pool token rate
|
* @dev get pool token rate
|
||||||
* @param tokenAmt total token amount
|
* @param tokenAmt total token amount
|
||||||
*/
|
*/
|
||||||
function getCurrentRate(uint tokenAmt) public view returns (uint) {
|
function getCurrentRate(uint tokenAmt) public view returns (uint) {
|
||||||
return wdiv(totalSupply(), tokenAmt);
|
return wdiv(totalSupply(), tokenAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev sets exchange rates
|
* @dev sets exchange rates
|
||||||
*/
|
*/
|
||||||
function setExchangeRate() public isChief {
|
function setExchangeRate() public isChief {
|
||||||
uint _previousRate = exchangeRate;
|
uint _previousRate = exchangeRate;
|
||||||
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
uint _totalToken = RateInterface(registry.poolLogic(address(this))).getTotalToken();
|
||||||
|
@ -113,6 +119,13 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
emit LogExchangeRate(exchangeRate, tokenBalance, insuranceAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Settle the assets on dsa and update exchange rate
|
||||||
|
* @param _dsa DSA address
|
||||||
|
* @param _targets array of connector's address
|
||||||
|
* @param _datas array of connector's function calldata
|
||||||
|
* @param _origin origin address
|
||||||
|
*/
|
||||||
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);
|
AccountInterface dsaWallet = AccountInterface(_dsa);
|
||||||
|
@ -124,6 +137,11 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
emit LogSettle(block.number);
|
emit LogSettle(block.number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit token.
|
||||||
|
* @param tknAmt token amount
|
||||||
|
* @return _mintAmt amount of wrap token minted
|
||||||
|
*/
|
||||||
function deposit(uint tknAmt) public whenNotPaused payable returns (uint _mintAmt) {
|
function deposit(uint tknAmt) public whenNotPaused payable returns (uint _mintAmt) {
|
||||||
require(tknAmt == msg.value, "unmatched-amount");
|
require(tknAmt == msg.value, "unmatched-amount");
|
||||||
tokenBalance = add(tokenBalance, tknAmt);
|
tokenBalance = add(tokenBalance, tknAmt);
|
||||||
|
@ -131,9 +149,15 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
_mintAmt = wmul(msg.value, exchangeRate);
|
_mintAmt = wmul(msg.value, exchangeRate);
|
||||||
_mint(msg.sender, _mintAmt);
|
_mint(msg.sender, _mintAmt);
|
||||||
|
|
||||||
emit LogDeposit(tknAmt, _mintAmt);
|
emit LogDeposit(msg.sender, tknAmt, _mintAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw tokens.
|
||||||
|
* @param tknAmt token amount
|
||||||
|
* @param to withdraw tokens to address
|
||||||
|
* @return _tknAmt amount of token withdrawn
|
||||||
|
*/
|
||||||
function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) {
|
function withdraw(uint tknAmt, address to) external nonReentrant whenNotPaused returns (uint _tknAmt) {
|
||||||
uint poolBal = address(this).balance;
|
uint poolBal = address(this).balance;
|
||||||
require(tknAmt <= poolBal, "not-enough-liquidity-available");
|
require(tknAmt <= poolBal, "not-enough-liquidity-available");
|
||||||
|
@ -163,15 +187,24 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
|
|
||||||
payable(to).transfer(_tknAmt);
|
payable(to).transfer(_tknAmt);
|
||||||
|
|
||||||
emit LogWithdraw(tknAmt, _burnAmt, _feeAmt);
|
emit LogWithdraw(msg.sender, tknAmt, _burnAmt, _feeAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Add Insurance to the pool.
|
||||||
|
* @param tknAmt insurance token amount to add
|
||||||
|
*/
|
||||||
function addInsurance(uint tknAmt) external payable {
|
function addInsurance(uint tknAmt) external payable {
|
||||||
require(tknAmt == msg.value, "unmatched-amount");
|
require(tknAmt == msg.value, "unmatched-amount");
|
||||||
insuranceAmt = add(insuranceAmt, tknAmt);
|
insuranceAmt = add(insuranceAmt, tknAmt);
|
||||||
emit LogAddInsurance(tknAmt);
|
emit LogAddInsurance(tknAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw Insurance from the pool.
|
||||||
|
* @notice only master can call this function.
|
||||||
|
* @param tknAmt insurance token amount to remove
|
||||||
|
*/
|
||||||
function withdrawInsurance(uint tknAmt) external {
|
function withdrawInsurance(uint tknAmt) external {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
require(tknAmt <= insuranceAmt, "not-enough-insurance");
|
require(tknAmt <= insuranceAmt, "not-enough-insurance");
|
||||||
|
@ -180,11 +213,14 @@ contract PoolToken is ReentrancyGuard, ERC20Pausable, DSMath {
|
||||||
emit LogWithdrawInsurance(tknAmt);
|
emit LogWithdrawInsurance(tknAmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Shut the pool.
|
||||||
|
* @notice only master can call this function.
|
||||||
|
*/
|
||||||
function shutdown() external {
|
function shutdown() external {
|
||||||
require(msg.sender == instaIndex.master(), "not-master");
|
require(msg.sender == instaIndex.master(), "not-master");
|
||||||
paused() ? _unpause() : _pause();
|
paused() ? _unpause() : _pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
receive() external payable {}
|
receive() external payable {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user