Skip to content

Commit

Permalink
Add DisposableCoverProducts contract
Browse files Browse the repository at this point in the history
  • Loading branch information
MilGard91 committed Dec 14, 2023
1 parent ed356d2 commit 4af53cf
Show file tree
Hide file tree
Showing 9 changed files with 1,428 additions and 32 deletions.
2 changes: 1 addition & 1 deletion contracts/interfaces/ICoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity >=0.5.0;

import "./ILegacyCover.sol";
import "./ICover.sol";

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

Expand Down
71 changes: 71 additions & 0 deletions contracts/interfaces/IDisposableCoverProducts.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.5.0;

import "./ILegacyCover.sol";

interface IDisposableCoverProducts {

/* ========== 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 getProductTypes() external view returns (ProductType[] memory);

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

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

function getProductWithType(uint productId) external view returns (Product memory, ProductType memory);

/* === 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();

function getPriceAndCapacityRatios(uint[] calldata productIds) external view returns (
uint[] memory _initialPrices,
uint[] memory _capacityReductionRatios
);
}
146 changes: 143 additions & 3 deletions contracts/interfaces/ILegacyCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,159 @@

pragma solidity >=0.5.0;

import "./ICoverNFT.sol";
import "./ICover.sol";
import "./IStakingNFT.sol";
import "./IStakingPool.sol";
import "./IStakingPoolFactory.sol";
import "./ICoverProducts.sol";

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

interface ILegacyCover {

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

function coverData(uint coverId) external view returns (CoverData memory);

function coverDataCount() external view returns (uint);

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

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

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

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

function getProductTypes() external view returns (ProductType[] memory);
function products(uint id) external view returns (Product memory);

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

function productNames(uint id) external view returns (string memory);
function stakingPool(uint index) external view returns (IStakingPool);

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

function productTypeNames(uint id) 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);

function globalRewardsRatio() external view returns (uint);

function getPriceAndCapacityRatios(uint[] calldata productIds) external view returns (
uint _globalCapacityRatio,
uint _globalMinPriceRatio,
uint[] memory _initialPriceRatios,
uint[] memory _capacityReductionRatios
);

function GLOBAL_MIN_PRICE_RATIO() external view returns (uint);

function allowedPools(uint productId) external view returns (uint[] memory);

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

function addLegacyCover(
uint productId,
uint coverAsset,
uint amount,
uint start,
uint period,
address newOwner
) external returns (uint coverId);

function buyCover(
BuyCoverParams calldata params,
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,
uint amount
) external returns (address coverOwner);

function coverNFT() external returns (ICoverNFT);

function stakingNFT() external returns (IStakingNFT);

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
error OnlyMemberRolesCanOperateTransfer();
error OnlyOwnerOrApproved();

// Cover details
error CoverPeriodTooShort();
error CoverPeriodTooLong();
error CoverOutsideOfTheGracePeriod();
error CoverAmountIsZero();

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

// Cover and payment assets
error CoverAssetNotSupported();
error InvalidPaymentAsset();
error UnexpectedCoverAsset();
error UnsupportedCoverAssets();
error UnexpectedEthSent();
error EditNotSupported();

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

// ETH transfers
error InsufficientEthSent();
error SendingEthToPoolFailed();
error SendingEthToCommissionDestinationFailed();
error ReturningEthRemainderToSenderFailed();

// Misc
error AlreadyInitialized();
error ExpiredCoversCannotBeEdited();
error CoverNotYetExpired(uint coverId);
error CoverAlreadyExpired(uint coverId);
error InsufficientCoverAmountAllocated();
error UnexpectedPoolId();
error CapacityReductionRatioAbove100Percent();
}
4 changes: 2 additions & 2 deletions contracts/mocks/CoverProducts/CoverProductsMockCover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
pragma solidity ^0.8.18;

import "../../interfaces/IStakingPool.sol";
import "../../interfaces/ILegacyCover.sol";
import "../../interfaces/ICover.sol";
import "../../interfaces/IStakingProducts.sol";
import "../../interfaces/IStakingPoolFactory.sol";
import "../../interfaces/ICoverProducts.sol";

contract CoverProductsMockCover is ILegacyCover {
contract CoverProductsMockCover is ICover {
uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1%

Product[] internal _products;
Expand Down

0 comments on commit 4af53cf

Please sign in to comment.