Skip to content

Commit

Permalink
fix: add back simple policy info struct (#68)
Browse files Browse the repository at this point in the history
struct without the arrays is needed for web3j compatibility
  • Loading branch information
amarinkovic authored Jun 2, 2023
1 parent 11fdd89 commit dcc8c1e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
17 changes: 14 additions & 3 deletions src/diamonds/nayms/facets/SimplePolicyFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity 0.8.17;

import { Modifiers } from "../Modifiers.sol";
import { Entity, SimplePolicy, PolicyCommissionsBasisPoints } from "../AppStorage.sol";
import { Entity, SimplePolicy, SimplePolicyInfo, PolicyCommissionsBasisPoints } from "../AppStorage.sol";
import { LibObject } from "../libs/LibObject.sol";
import { LibHelpers } from "../libs/LibHelpers.sol";
import { LibSimplePolicy } from "../libs/LibSimplePolicy.sol";
Expand Down Expand Up @@ -48,8 +48,19 @@ contract SimplePolicyFacet is ISimplePolicyFacet, Modifiers {
* @param _policyId Id of the simple policy
* @return Simple policy metadata
*/
function getSimplePolicyInfo(bytes32 _policyId) external view returns (SimplePolicy memory) {
return LibSimplePolicy._getSimplePolicyInfo(_policyId);
function getSimplePolicyInfo(bytes32 _policyId) external view returns (SimplePolicyInfo memory) {
SimplePolicy memory p = LibSimplePolicy._getSimplePolicyInfo(_policyId);
return
SimplePolicyInfo({
startDate: p.startDate,
maturationDate: p.maturationDate,
asset: p.asset,
limit: p.limit,
fundsLocked: p.fundsLocked,
cancelled: p.cancelled,
claimsPaid: p.claimsPaid,
premiumsPaid: p.premiumsPaid
});
}

function getPremiumCommissionBasisPoints() external view returns (PolicyCommissionsBasisPoints memory bp) {
Expand Down
11 changes: 11 additions & 0 deletions src/diamonds/nayms/interfaces/FreeStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ struct SimplePolicy {
uint256[] commissionBasisPoints;
}

struct SimplePolicyInfo {
uint256 startDate;
uint256 maturationDate;
bytes32 asset;
uint256 limit;
bool fundsLocked;
bool cancelled;
uint256 claimsPaid;
uint256 premiumsPaid;
}

struct PolicyCommissionsBasisPoints {
uint16 premiumCommissionNaymsLtdBP;
uint16 premiumCommissionNDFBP;
Expand Down
4 changes: 2 additions & 2 deletions src/diamonds/nayms/interfaces/ISimplePolicyFacet.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import { SimplePolicy, PolicyCommissionsBasisPoints } from "./FreeStructs.sol";
import { SimplePolicyInfo, PolicyCommissionsBasisPoints } from "./FreeStructs.sol";

/**
* @title Simple Policies
Expand Down Expand Up @@ -52,7 +52,7 @@ interface ISimplePolicyFacet {
* @param _id Id of the simple policy
* @return Simple policy metadata
*/
function getSimplePolicyInfo(bytes32 _id) external view returns (SimplePolicy memory);
function getSimplePolicyInfo(bytes32 _id) external view returns (SimplePolicyInfo memory);

/**
* @notice Get the policy premium commissions basis points.
Expand Down
6 changes: 3 additions & 3 deletions test/T04Entity.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.17;
import { Vm } from "forge-std/Vm.sol";

import { D03ProtocolDefaults, console2, LibConstants, LibHelpers, LibObject } from "./defaults/D03ProtocolDefaults.sol";
import { Entity, MarketInfo, SimplePolicy, Stakeholders } from "src/diamonds/nayms/interfaces/FreeStructs.sol";
import { Entity, MarketInfo, SimplePolicy, SimplePolicyInfo, Stakeholders } from "src/diamonds/nayms/interfaces/FreeStructs.sol";
import { INayms, IDiamondCut } from "src/diamonds/nayms/INayms.sol";

import { LibACL } from "src/diamonds/nayms/libs/LibACL.sol";
Expand Down Expand Up @@ -491,7 +491,7 @@ contract T04EntityTest is D03ProtocolDefaults {
// create it successfully
nayms.createSimplePolicy(policyId1, entityId1, stakeholders, simplePolicy, testPolicyDataHash);

SimplePolicy memory simplePolicyInfo = nayms.getSimplePolicyInfo(policyId1);
SimplePolicyInfo memory simplePolicyInfo = nayms.getSimplePolicyInfo(policyId1);
assertEq(simplePolicyInfo.startDate, simplePolicy.startDate, "Start dates should match");
assertEq(simplePolicyInfo.maturationDate, simplePolicy.maturationDate, "Maturation dates should match");
assertEq(simplePolicyInfo.asset, simplePolicy.asset, "Assets should match");
Expand Down Expand Up @@ -999,7 +999,7 @@ contract T04EntityTest is D03ProtocolDefaults {
"utilized capacity should change"
);

SimplePolicy memory simplePolicyInfo = nayms.getSimplePolicyInfo(policyId1);
SimplePolicyInfo memory simplePolicyInfo = nayms.getSimplePolicyInfo(policyId1);
assertEq(simplePolicyInfo.cancelled, true, "Simple policy should be cancelled");

vm.expectRevert("Policy already cancelled");
Expand Down

0 comments on commit dcc8c1e

Please sign in to comment.