Skip to content

Commit

Permalink
Merge pull request #744 from NexusMutual/chore/get-covers
Browse files Browse the repository at this point in the history
Reimplement getCovers in CoverViewer
  • Loading branch information
roxdanila committed Feb 24, 2023
2 parents 0b32e10 + 23070dd commit 2f717f3
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 247 deletions.
7 changes: 6 additions & 1 deletion contracts/interfaces/ICover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ interface ICover {

function coverSegmentsCount(uint coverId) external view returns (uint);

function coverSegments(uint coverId, uint segmentId) external view returns (CoverSegment memory);
function coverSegments(uint coverId) external view returns (CoverSegment[] memory);

function coverSegmentWithRemainingAmount(
uint coverId,
uint segmentId
) external view returns (CoverSegment memory);

function products(uint id) external view returns (Product memory);

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/Claims/CLMockCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ contract CLMockCover {

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

function coverSegments(
function coverSegmentWithRemainingAmount(
uint coverId,
uint segmentId
) external view returns (CoverSegment memory) {
Expand Down
40 changes: 40 additions & 0 deletions contracts/mocks/CoverViewer/CVMockCover.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.9;

import "../../interfaces/ICover.sol";

contract CVMockCover {

mapping(uint => CoverSegment[]) public _coverSegments;
mapping(uint => CoverData) public _coverData;

function addCoverData(uint coverId, CoverData memory coverData) public {
_coverData[coverId] = coverData;
}

function addSegments(uint coverId, CoverSegment[] memory segments) public {
for (uint i = 0; i < segments.length; i++) {
_coverSegments[coverId].push(segments[i]);
}
}

function coverData(uint coverId) external view returns (CoverData memory) {
return _coverData[coverId];
}

function coverSegmentsCount(uint coverId) external view returns (uint) {
return _coverSegments[coverId].length;
}

function coverSegments(uint coverId) external view returns (CoverSegment[] memory) {
return _coverSegments[coverId];
}

function coverSegmentWithRemainingAmount(
uint coverId,
uint segmentId
) external view returns (CoverSegment memory) {
return _coverSegments[coverId][segmentId];
}
}
26 changes: 0 additions & 26 deletions contracts/mocks/CoverViewer/CoverViewerMockCover.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/mocks/Incidents/ICMockCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract ICMockCover {
}
}

function coverSegments(
function coverSegmentWithRemainingAmount(
uint coverId,
uint segmentId
) external view returns (CoverSegment memory) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/assessment/IndividualClaims.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ contract IndividualClaims is IIndividualClaims, MasterAwareV2 {

CoverData memory coverData = cover().coverData(claim.coverId);

CoverSegment memory segment = cover().coverSegments(claim.coverId, claim.segmentId);
CoverSegment memory segment = cover().coverSegmentWithRemainingAmount(claim.coverId, claim.segmentId);

uint segmentEnd = segment.start + segment.period;

Expand Down Expand Up @@ -280,7 +280,7 @@ contract IndividualClaims is IIndividualClaims, MasterAwareV2 {

ICover coverContract = cover();
CoverData memory coverData = cover().coverData(coverId);
CoverSegment memory segment = cover().coverSegments(coverId, segmentId);
CoverSegment memory segment = cover().coverSegmentWithRemainingAmount(coverId, segmentId);

{
Product memory product = coverContract.products(coverData.productId);
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 @@ -215,7 +215,7 @@ contract YieldTokenIncidents is IYieldTokenIncidents, MasterAwareV2 {

uint payoutAmount;
{
CoverSegment memory coverSegment = coverContract.coverSegments(coverId, segmentId);
CoverSegment memory coverSegment = coverContract.coverSegmentWithRemainingAmount(coverId, segmentId);

require(
coverSegment.start + coverSegment.period + coverSegment.gracePeriod >= block.timestamp,
Expand Down
10 changes: 7 additions & 3 deletions contracts/modules/cover/Cover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
}

segmentId = _coverSegments[coverId].length;
CoverSegment memory lastSegment = coverSegments(coverId, segmentId - 1);
CoverSegment memory lastSegment = coverSegmentWithRemainingAmount(coverId, segmentId - 1);

// require last segment not to be expired
if (lastSegment.start + lastSegment.period <= block.timestamp) {
Expand Down Expand Up @@ -557,7 +557,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {

CoverData storage cover = _coverData[coverId];
ActiveCover storage _activeCover = activeCover[cover.coverAsset];
CoverSegment memory segment = coverSegments(coverId, segmentId);
CoverSegment memory segment = coverSegmentWithRemainingAmount(coverId, segmentId);
PoolAllocation[] storage allocations = coverSegmentAllocations[coverId][segmentId];

// Update expired buckets and calculate the amount of active cover that should be burned
Expand Down Expand Up @@ -621,7 +621,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
return _coverData[coverId];
}

function coverSegments(
function coverSegmentWithRemainingAmount(
uint coverId,
uint segmentId
) public override view returns (CoverSegment memory) {
Expand All @@ -633,6 +633,10 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
return segment;
}

function coverSegments(uint coverId) external override view returns (CoverSegment[] memory) {
return _coverSegments[coverId];
}

function coverSegmentsCount(uint coverId) external override view returns (uint) {
return _coverSegments[coverId].length;
}
Expand Down
Loading

0 comments on commit 2f717f3

Please sign in to comment.