Skip to content

Commit

Permalink
CoverProducts + createStakingPool refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Aug 3, 2023
1 parent 069a815 commit f6e39d5
Show file tree
Hide file tree
Showing 56 changed files with 1,839 additions and 1,547 deletions.
45 changes: 0 additions & 45 deletions contracts/interfaces/ICover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,6 @@ struct BuyCoverParams {
string ipfsData;
}

struct ProductParam {
string productName;
uint productId;
string ipfsMetadata;
Product product;
uint[] allowedPools;
}

struct ProductTypeParam {
string productTypeName;
uint productTypeId;
string ipfsMetadata;
ProductType productType;
}

struct ProductInitializationParams {
uint productId;
uint8 weight;
Expand Down Expand Up @@ -142,18 +127,6 @@ interface ICover {
uint segmentId
) external view returns (CoverSegment memory);

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

function productTypes(uint id) external view returns (ProductType memory);

function stakingPool(uint index) external view returns (IStakingPool);

function productNames(uint productId) external view returns (string memory);

function productsCount() external view returns (uint);

function productTypesCount() external view returns (uint);

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

function globalCapacityRatio() external view returns (uint);
Expand Down Expand Up @@ -183,10 +156,6 @@ interface ICover {
PoolAllocationRequest[] calldata coverChunkRequests
) external payable returns (uint coverId);

function setProductTypes(ProductTypeParam[] calldata productTypes) external;

function setProducts(ProductParam[] calldata params) external;

function burnStake(
uint coverId,
uint segmentId,
Expand All @@ -199,21 +168,8 @@ interface ICover {

function stakingPoolFactory() external returns (IStakingPoolFactory);

function createStakingPool(
bool isPrivatePool,
uint initialPoolFee,
uint maxPoolFee,
ProductInitializationParams[] calldata productInitParams,
string calldata ipfsDescriptionHash
) external returns (uint poolId, address stakingPoolAddress);

function isPoolAllowed(uint productId, uint poolId) external returns (bool);
function requirePoolIsAllowed(uint[] calldata productIds, uint poolId) external view;

/* ========== EVENTS ========== */

event ProductSet(uint id, string ipfsMetadata);
event ProductTypeSet(uint id, string ipfsMetadata);
event CoverEdited(uint indexed coverId, uint indexed productId, uint indexed segmentId, address buyer, string ipfsMetadata);

// Auth
Expand Down Expand Up @@ -244,7 +200,6 @@ interface ICover {

// Price & Commission
error PriceExceedsMaxPremiumInAsset();
error TargetPriceBelowGlobalMinPriceRatio();
error InitialPriceRatioBelowGlobalMinPriceRatio();
error InitialPriceRatioAbove100Percent();
error CommissionRateTooHigh();
Expand Down
79 changes: 79 additions & 0 deletions contracts/interfaces/ICoverProducts.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ICover.sol";

/* ========== DATA STRUCTURES ========== */

struct ProductParam {
string productName;
uint productId;
string ipfsMetadata;
Product product;
uint[] allowedPools;
}

struct ProductTypeParam {
string productTypeName;
uint productTypeId;
string ipfsMetadata;
ProductType productType;
}

interface ICoverProducts {

/* ========== VIEWS ========== */

function allowedPoolsCount(uint productId) external view returns (uint);

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

function productNames(uint productId) external view returns (string memory);

function productsCount() external view returns (uint);

function productTypesCount() external view returns (uint);

function productTypes(uint id) external view returns (ProductType memory);

function getProducts() external view returns (Product[] memory);

function isPoolAllowed(uint productId, uint poolId) external view returns (bool);

function requirePoolIsAllowed(uint[] calldata productIds, uint poolId) external view;

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

function setProductTypes(ProductTypeParam[] calldata productTypes) external;

function setProducts(ProductParam[] calldata params) external;


/* ========== EVENTS ========== */

event ProductSet(uint id, string ipfsMetadata);
event ProductTypeSet(uint id, string ipfsMetadata);

// Products
error ProductDoesntExist();
error ProductTypeNotFound();
error ProductDeprecated();
error InvalidProductType();
error UnexpectedProductId();
error PoolNotAllowedForThisProduct(uint productId);

// Cover and payment assets
error UnsupportedCoverAssets();
error UnexpectedEthSent();

// Price & Commission
error PriceExceedsMaxPremiumInAsset();
error TargetPriceBelowGlobalMinPriceRatio();
error InitialPriceRatioBelowGlobalMinPriceRatio();
error InitialPriceRatioAbove100Percent();
error CommissionRateTooHigh();

// Misc
error CapacityReductionRatioAbove100Percent();
}
3 changes: 2 additions & 1 deletion contracts/interfaces/IMasterAwareV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ interface IMasterAwareV2 {
// TODO: 2) TK is not an internal contract!
// If you want to add a new contract below TK, remove TK and make it immutable in all
// contracts that are using it (currently LegacyGateway and LegacyPooledStaking).
TK // NXMToken.sol
TK, // NXMToken.sol
CP
}

function changeMasterAddress(address masterAddress) external;
Expand Down
1 change: 1 addition & 0 deletions contracts/interfaces/IStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ interface IStakingPool {

// Auth
error OnlyCoverContract();
error OnlyStakingProductsContract();
error OnlyManager();
error PrivatePool();
error SystemPaused();
Expand Down
20 changes: 18 additions & 2 deletions contracts/interfaces/IStakingProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ interface IStakingProducts {

function setProducts(uint poolId, StakedProductParam[] memory params) external;

function setInitialProducts(uint poolId, ProductInitializationParams[] memory params) external;

function getProductTargetWeight(uint poolId, uint productId) external view returns (uint);

function getTotalTargetWeight(uint poolId) external view returns (uint);
Expand Down Expand Up @@ -95,6 +93,18 @@ interface IStakingProducts {
uint allocationUnitsPerNxm
) external pure returns (uint);

/* ========== STAKING POOL CREATION ========== */

function stakingPool(uint poolId) external view returns (IStakingPool);

function createStakingPool(
bool isPrivatePool,
uint initialPoolFee,
uint maxPoolFee,
ProductInitializationParams[] calldata productInitParams,
string calldata ipfsDescriptionHash
) external returns (uint poolId, address stakingPoolAddress);

/* ============= EVENTS ============= */

event ProductUpdated(uint productId, uint8 targetWeight, uint96 targetPrice);
Expand All @@ -116,4 +126,10 @@ interface IStakingProducts {
error TotalTargetWeightExceeded();
error TotalEffectiveWeightExceeded();

// Staking Pool creation
error ProductDoesntExistOrIsDeprecated();
error InvalidProductType();
error PoolNotAllowedForThisProduct(uint productId);
error TargetPriceBelowGlobalMinPriceRatio();

}
40 changes: 40 additions & 0 deletions contracts/mocks/Claims/CLMockCoverProducts.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.18;

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


contract CLMockCoverProducts {

Product[] internal _products;
mapping(uint => uint) capacityFactors;

ProductType[] internal _productTypes;


function products(uint id) external view returns (Product memory) {
return _products[id];
}

function productTypes(uint id) external view returns (ProductType memory) {
return _productTypes[id];
}


function addProductType(
uint8 claimMethod,
uint32 gracePeriod,
uint16 /*burnRatio*/
) external {
_productTypes.push(ProductType(
claimMethod,
gracePeriod
));
}

function addProduct(Product calldata product) external {
_products.push(product);
}
}
Loading

0 comments on commit f6e39d5

Please sign in to comment.