Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
21bdc5c
add restriction for cover amount = 0
danoctavian Jun 8, 2022
db96a3e
add pure and view functions for asset deprecation
danoctavian Jun 8, 2022
c4a2107
add editCover check for deprecation
danoctavian Jun 8, 2022
d9ff858
performPayoutBurn -> performStakeBurn
danoctavian Jun 8, 2022
2c1c9d9
add test for performStakeBurn
danoctavian Jun 8, 2022
5e2900e
complete test for performPayoutBurn
danoctavian Jun 8, 2022
ee27924
rm .only
danoctavian Jun 8, 2022
228198a
move cap calculation from Cover.sol
danoctavian Jun 8, 2022
0f66379
move functions
danoctavian Jun 8, 2022
ca53d5e
added a TODO
danoctavian Jun 8, 2022
e19bd62
add the actual covered amount instead of requested to active cover tr…
danoctavian Jun 8, 2022
d27ea29
add cover asset availability check when editing cover
danoctavian Jun 8, 2022
d40f69d
fix Tokencontroller deposits vs rewards bug
danoctavian Jun 8, 2022
720347c
fix expiration condition on cover
danoctavian Jun 8, 2022
82f02cc
use nonReentrant on buyCover and editCover
danoctavian Jun 9, 2022
5ee0dc0
eliminate memory reads
danoctavian Jun 9, 2022
1aacb99
storage -> memory for allocation
danoctavian Jun 9, 2022
d2298c8
eliminate the use of asset decimals. not needed
danoctavian Jun 9, 2022
2c2ca58
add usdc (6 decimals) to test setup
danoctavian Jun 9, 2022
a7a4c9b
add test with USDC (6 decimals)
danoctavian Jun 9, 2022
9bddbdd
add case for expired cover editing
danoctavian Jun 9, 2022
ea330c8
remove console.log
danoctavian Jun 9, 2022
1e8cc4a
remove use of PooledStaking in setup.js
danoctavian Jun 9, 2022
5860a16
partially fix integration test setup.js
danoctavian Jun 9, 2022
30ac473
Merge branch 'nexus-v2' into feature/extra-cover-tests
roxdanila Jun 10, 2022
f104d9a
partially fix setup.js
danoctavian Jun 10, 2022
1fe5e68
fixed setup.js
danoctavian Jun 10, 2022
f1036b3
Merge branch 'feature/extra-cover-tests' of github.com:NexusMutual/sm…
danoctavian Jun 10, 2022
74d95d5
add mock for staking pool
danoctavian Jun 10, 2022
3382766
fix compilation of CoverMockStakingPool
danoctavian Jun 10, 2022
bf1b80c
enable only IndividualClaims integration test
danoctavian Jun 10, 2022
eb79b8a
partially implement enroll function
danoctavian Jun 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/interfaces/ICover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ interface ICover {

function totalActiveCoverInAsset(uint24 coverAsset) external view returns (uint);

function calculateCapacity(uint staked, uint capacityReductionRatio) external view returns (uint);
function globalCapacityRatio() external view returns (uint24);

/* === MUTATIVE FUNCTIONS ==== */

Expand Down Expand Up @@ -166,7 +166,7 @@ interface ICover {
string[] calldata ipfsMetadata
) external;

function performPayoutBurn(
function performStakeBurn(
uint coverId,
uint segmentId,
uint amount
Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,7 @@ interface IPool {

function getMCRRatio() external view returns (uint);

function deprecatedCoverAssetsBitmap() external view returns (uint32);

function setSwapValue(uint value) external;
}
8 changes: 4 additions & 4 deletions contracts/mocks/Claims/CLMockCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract CLMockCover {

IERC721Mock public immutable coverNFT;

struct PerformPayoutBurnCalledWith {
struct PerformStakeBurnCalledWith {
uint coverId;
uint segmentId;
uint amount;
Expand All @@ -22,7 +22,7 @@ contract CLMockCover {
address toNewOwner;
}

PerformPayoutBurnCalledWith public performPayoutBurnCalledWith;
PerformStakeBurnCalledWith public performStakeBurnCalledWith;
MigrateCoverFromOwnerCalledWith public migrateCoverFromOwnerCalledWith;
CoverData[] public coverData;
mapping(uint => CoverSegment[]) _coverSegments;
Expand Down Expand Up @@ -122,8 +122,8 @@ contract CLMockCover {
_products.push(product);
}

function performPayoutBurn(uint coverId, uint segmentId, uint amount) external returns (address) {
performPayoutBurnCalledWith = PerformPayoutBurnCalledWith(coverId, segmentId, amount);
function performStakeBurn(uint coverId, uint segmentId, uint amount) external returns (address) {
performStakeBurnCalledWith = PerformStakeBurnCalledWith(coverId, segmentId, amount);
return coverNFT.ownerOf(coverId);
}

Expand Down
6 changes: 6 additions & 0 deletions contracts/mocks/Cover/CoverMockPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ contract CoverMockPool {
mapping (uint => uint) prices;
IPool.Asset[] public coverAssets;

uint32 public deprecatedCoverAssetsBitmap;

address constant public ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

constructor() {
Expand All @@ -30,6 +32,10 @@ contract CoverMockPool {
}
}

function setDeprecatedCoverAssetsBitmap(uint32 bitmap) external {
deprecatedCoverAssetsBitmap = bitmap;
}

fallback() external payable {}

receive() external payable {}
Expand Down
12 changes: 11 additions & 1 deletion contracts/mocks/Cover/CoverMockStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import "../../modules/staking/StakingPool.sol";

contract CoverMockStakingPool is IStakingPool, ERC721 {

struct BurnStakeCalledWith {
uint productId;
uint start;
uint period;
uint amount;
}

/* immutables */
address public immutable memberRoles;

Expand All @@ -29,6 +36,8 @@ contract CoverMockStakingPool is IStakingPool, ERC721 {
uint public totalSupply;
address public manager;

BurnStakeCalledWith public burnStakeCalledWith;

constructor (
address /* _nxm */,
address /* _coverContract */,
Expand Down Expand Up @@ -161,8 +170,9 @@ contract CoverMockStakingPool is IStakingPool, ERC721 {
// noop
}

function burnStake(uint /* productId */, uint /* start */, uint /* period */, uint /* amount */) external {
function burnStake(uint productId, uint start, uint period, uint amount) external {
// no-op
burnStakeCalledWith = BurnStakeCalledWith(productId, start, period, amount);
}

function depositTo(DepositRequest[] memory /* requests */) external returns (uint[] memory /* tokenIds */) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/Disposables/DisposableGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract DisposableGovernance is IGovernance, LegacyMasterAware {

function createProposalwithSolution(string calldata, string calldata, string calldata, uint, string calldata, bytes calldata) external {}

function submitVote(uint, uint) external {}
function submitVote(uint, uint, uint[] calldata) external {}

function closeProposal(uint) external {}

Expand Down
8 changes: 4 additions & 4 deletions contracts/mocks/Incidents/ICMockCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "../../interfaces/IERC721Mock.sol";

contract ICMockCover {

struct PerformPayoutBurnCalledWith {
struct PerformStakeBurnCalledWith {
uint coverId;
uint segmentId;
uint amount;
Expand All @@ -16,7 +16,7 @@ contract ICMockCover {
IERC721Mock public immutable coverNFT;

CoverData[] public coverData;
PerformPayoutBurnCalledWith public performPayoutBurnCalledWith;
PerformStakeBurnCalledWith public performStakeBurnCalledWith;
mapping(uint => CoverSegment[]) _coverSegments;

mapping(uint => PoolAllocation[]) poolAllocations;
Expand Down Expand Up @@ -121,8 +121,8 @@ contract ICMockCover {
}


function performPayoutBurn(uint coverId, uint segmentId, uint amount) external returns (address) {
performPayoutBurnCalledWith = PerformPayoutBurnCalledWith(coverId, segmentId, amount);
function performStakeBurn(uint coverId, uint segmentId, uint amount) external returns (address) {
performStakeBurnCalledWith = PerformStakeBurnCalledWith(coverId, segmentId, amount);
return coverNFT.ownerOf(coverId);
}
}
124 changes: 124 additions & 0 deletions contracts/mocks/integration/IntegrationMockStakingPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.9;

import "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-v4/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts-v4/utils/Strings.sol";

import "../../modules/staking/StakingPool.sol";

contract IntegrationMockStakingPool is StakingPool {

/* immutables */
address public immutable memberRoles;

mapping (uint => uint) public usedCapacity;
mapping (uint => uint) public stakedAmount;

mapping (uint => uint) public mockPrices;

uint public constant MAX_PRICE_RATIO = 1e20;

constructor (
address _nxm,
address _coverContract,
ITokenController _tokenController,
address _memberRoles
)
StakingPool("Nexus Mutual Staking Pool", "NMSPT", _nxm, _coverContract, _tokenController)
{
memberRoles = _memberRoles;
}

function name() public view override returns (string memory) {
return string(abi.encodePacked(super.name(), " ", Strings.toString(poolId)));
}

function initialize(address _manager, uint _poolId) external /*override*/ {
_mint(_manager, totalSupply++);
poolId = _poolId;
}

function operatorTransferFrom(address from, address to, uint256 amount) external /*override*/ {
require(msg.sender == memberRoles, "StakingPool: Caller is not MemberRoles");
_transfer(from, to, amount);
}

function allocateCapacity(
uint productId,
uint amountInNXM,
uint period,
uint rewardRatio,
uint initialPriceRatio
) external /*override*/ returns (uint coveredAmountInNXM, uint premiumInNXM) {
period;
rewardRatio;
initialPriceRatio;
usedCapacity[productId] += amountInNXM;
return (amountInNXM, calculatePremium(mockPrices[productId], amountInNXM, period));
}

function calculatePremium(uint priceRatio, uint coverAmount, uint period) public pure returns (uint) {
return priceRatio * coverAmount / MAX_PRICE_RATIO * period / 365 days;
}

function stake(uint amount) external {
_mint(msg.sender, amount);
}

function freeCapacity(
uint productId,
uint previousPeriod,
uint previousStartTime,
uint previousRewardAmount,
uint periodReduction,
uint coveredAmount
) external /*override*/ {
// no-op
}

function getAvailableCapacity(uint productId, uint capacityFactor) external /*override*/ view returns (uint) {
return stakedAmount[productId] * capacityFactor - usedCapacity[productId];
}

function getCapacity(uint productId, uint capacityFactor) external /*override*/ view returns (uint) {
return stakedAmount[productId] * capacityFactor;
}

function getUsedCapacity(uint productId) external /*override*/ view returns (uint) {
return usedCapacity[productId];
}

function getTargetPrice(uint productId) external /*override*/ view returns (uint) {
return products[productId].targetPrice;
}

function getStake(uint productId) external /*override*/ view returns (uint) {
return stakedAmount[productId];
}

function setUsedCapacity(uint productId, uint amount) external {
usedCapacity[productId] = amount;
}

function setTargetPrice(uint productId, uint amount) external {
products[productId].targetPrice = uint96(amount);
}

function setStake(uint productId, uint amount) external {
stakedAmount[productId] = amount;
}

function setPrice(uint productId, uint price) external {
mockPrices[productId] = price;
}

function changeMasterAddress(address payable _a) external {
// noop
}

function changeDependentContractAddress() external {
// noop
}
}
2 changes: 1 addition & 1 deletion contracts/modules/assessment/IndividualClaims.sol
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ contract IndividualClaims is IIndividualClaims, MasterAwareV2 {
require(!claim.payoutRedeemed, "Payout has already been redeemed");
claims[claimId].payoutRedeemed = true;

address payable coverOwner = payable(cover().performPayoutBurn(
address payable coverOwner = payable(cover().performStakeBurn(
claim.coverId,
claim.segmentId,
claim.amount
Expand Down
2 changes: 1 addition & 1 deletion contracts/modules/assessment/YieldTokenIncidents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ contract YieldTokenIncidents is IYieldTokenIncidents, MasterAwareV2 {
}

require(payoutAmount <= coverSegment.amount, "Payout exceeds covered amount");
coverContract.performPayoutBurn(coverId, segmentId, payoutAmount);
coverContract.performStakeBurn(coverId, segmentId, payoutAmount);
SafeERC20.safeTransferFrom(
IERC20(product.productAddress),
msg.sender,
Expand Down
2 changes: 1 addition & 1 deletion contracts/modules/capital/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract Pool is IPool, MasterAware, ReentrancyGuard {
address public swapOperator;

// Binary map where each on bit, starting from the LSB, represents whether the cover asset found
// at the same index as the bit's position should be ignored when calulating the value of the pool
// at the same index as the bit's position should be ignored when calculating the value of the pool
// in ETH.
//
// Examples:
Expand Down
Loading