Skip to content

Commit c8c233e

Browse files
authored
Merge pull request #50 from keep-network/cov-rework
COV token minting rework: reward compounding and value accrued
2 parents 42a416d + 97b2ca3 commit c8c233e

4 files changed

Lines changed: 354 additions & 224 deletions

File tree

contracts/AssetPool.sol

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
pragma solidity <0.9.0;
44

5-
import "./UnderwriterToken.sol";
6-
75
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
86
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
97
import "@openzeppelin/contracts/math/SafeMath.sol";
108
import "@openzeppelin/contracts/access/Ownable.sol";
119

10+
import "./RewardsPool.sol";
11+
import "./UnderwriterToken.sol";
12+
1213
/// @title AssetPool
13-
/// @notice Asset pool is a component of a Coverage Pool. Each Asset Pool
14+
/// @notice Asset pool is a component of a Coverage Pool. Asset Pool
1415
/// accepts a single ERC20 token as collateral, and returns an
1516
/// underwriter token. For example, an asset pool might accept deposits
16-
/// in WETH in return for covETH underwriter tokens. Underwriter tokens
17+
/// in KEEP in return for covKEEP underwriter tokens. Underwriter tokens
1718
/// represent an ownership share in the underlying collateral of the
1819
/// Asset Pool.
1920
contract AssetPool is Ownable {
@@ -24,9 +25,18 @@ contract AssetPool is Ownable {
2425
IERC20 public collateralToken;
2526
UnderwriterToken public underwriterToken;
2627

27-
constructor(IERC20 _collateralToken, UnderwriterToken _underwriterToken) {
28+
RewardsPool public rewardsPool;
29+
30+
constructor(
31+
IERC20 _collateralToken,
32+
UnderwriterToken _underwriterToken,
33+
address rewardsManager
34+
) {
2835
collateralToken = _collateralToken;
2936
underwriterToken = _underwriterToken;
37+
38+
rewardsPool = new RewardsPool(_collateralToken, this);
39+
rewardsPool.transferOwnership(rewardsManager);
3040
}
3141

3242
/// @notice Accepts the given amount of collateral token as a deposit and
@@ -60,16 +70,18 @@ contract AssetPool is Ownable {
6070
/// @dev Before calling this function, underwriter token needs to have the
6171
/// required amount accepted to transfer to the asset pool.
6272
function withdraw(uint256 covAmount) external {
63-
// TODO: Implement exit market. All withdrawals from the pool that
64-
// accept a fixed delay can do so without a fee. Any underwriter who
65-
// wants to withdraw more quickly will forfeit part of their collateral
66-
// to the pool, with a fee rate based on their percent ownership of the
67-
// pool.
6873
uint256 covBalance = underwriterToken.balanceOf(msg.sender);
6974
require(
7075
covAmount <= covBalance,
7176
"Underwriter token amount exceeds balance"
7277
);
78+
require(
79+
covAmount > 0,
80+
"Underwriter token amount must be greater than 0"
81+
);
82+
83+
rewardsPool.withdraw();
84+
7385
uint256 covSupply = underwriterToken.totalSupply();
7486
uint256 collateralBalance = collateralToken.balanceOf(address(this));
7587

@@ -84,10 +96,13 @@ contract AssetPool is Ownable {
8496
/// @notice Allows the coverage pool to demand coverage from the asset hold
8597
/// by this pool and send it to the provided recipient address.
8698
function claim(address recipient, uint256 amount) external onlyOwner {
99+
rewardsPool.withdraw();
87100
collateralToken.safeTransfer(recipient, amount);
88101
}
89102

90103
function _deposit(address depositor, uint256 amount) internal {
104+
rewardsPool.withdraw();
105+
91106
uint256 covSupply = underwriterToken.totalSupply();
92107
uint256 collateralBalance = collateralToken.balanceOf(address(this));
93108

0 commit comments

Comments
 (0)