Skip to content

Commit

Permalink
fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Aug 27, 2023
1 parent f05e2c0 commit 04541cc
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 118 deletions.
7 changes: 7 additions & 0 deletions contracts/interfaces/ICoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ interface ICoverProducts {

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;
Expand Down Expand Up @@ -76,4 +78,9 @@ interface ICoverProducts {

// Misc
error CapacityReductionRatioAbove100Percent();

function getPriceAndCapacityRatios(uint[] calldata productIds) external view returns (
uint[] memory _initialPrices,
uint[] memory _capacityReductionRatios
);
}
50 changes: 49 additions & 1 deletion contracts/mocks/Claims/CLMockCoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
pragma solidity ^0.8.18;

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


contract CLMockCoverProducts {
contract CLMockCoverProducts is ICoverProducts {

Product[] internal _products;
mapping(uint => uint) capacityFactors;
Expand Down Expand Up @@ -37,4 +38,51 @@ contract CLMockCoverProducts {
function addProduct(Product calldata product) external {
_products.push(product);
}

function productsCount() external view returns (uint) {
return _products.length;
}

function allowedPoolsCount(uint /* productId */ ) external pure returns (uint) {
revert("Unsupported");
}

function isPoolAllowed(uint /* productId */, uint /* poolId */) external pure returns (bool) {
revert("Unsupported");
}

function requirePoolIsAllowed(uint[] calldata /* productIds */, uint /* poolId */) external pure {
revert("Unsupported");
}

function getProducts() external pure returns (Product[] memory) {
revert("Unsupported");
}

function productTypesCount() external pure returns (uint) {
revert("Unsupported");
}

function getPriceAndCapacityRatios(uint[] calldata /* productIds */ ) external pure returns (
uint[] memory /* _initialPrices */,
uint[] memory /* _capacityReductionRatios */
) {
revert("Unsupported");
}

function productNames(uint /* productId */) external pure returns (string memory) {
revert("Unsupported");
}

function getProductWithType(uint /* productId */ ) external pure returns (Product memory, ProductType memory) {
revert("Unsupported");
}

function setProductTypes(ProductTypeParam[] calldata /* productTypes */ ) external pure {
revert("Unsupported");
}

function setProducts(ProductParam[] calldata /* params */ ) external pure {
revert("Unsupported");
}
}
53 changes: 52 additions & 1 deletion contracts/mocks/Incidents/ICMockCoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
pragma solidity ^0.8.18;

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

contract ICMockCoverProducts {
contract ICMockCoverProducts is ICoverProducts {

struct BurnStakeCalledWith {
uint coverId;
Expand Down Expand Up @@ -36,6 +37,7 @@ contract ICMockCoverProducts {
uint public constant PRICE_CURVE_EXPONENT = 7;
uint public constant MAX_PRICE_PERCENTAGE = 1e20;

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

function products(uint id) external view returns (Product memory) {
return _products[id];
Expand All @@ -45,6 +47,55 @@ contract ICMockCoverProducts {
return _productTypes[id];
}

function productTypesCount() external view returns (uint) {
return _productTypes.length;
}

function productsCount() public view returns (uint) {
return _products.length;
}

function getProducts() external view returns (Product[] memory) {
return _products;
}

function allowedPoolsCount(uint /* productId */) external pure returns (uint) {
revert("Unsupported");
}

function getPriceAndCapacityRatios(uint[] calldata /* productIds */ ) external pure returns (
uint[] memory /* _initialPrices */,
uint[] memory /* _capacityReductionRatios */
) {
revert("Unsupported");
}

function isPoolAllowed(uint /* productId */, uint /* poolId */) external pure returns (bool) {
revert("Unsupported");
}

function productNames(uint /* productId */) external pure returns (string memory) {
revert("Unsupported");
}

function getProductWithType(uint productId) external override view returns (Product memory product, ProductType memory) {
product = _products[productId];
return (product, _productTypes[product.productType]);
}


function requirePoolIsAllowed(uint[] calldata /* productIds */, uint /* poolId */ ) external pure {
revert("Unsupported");
}

function setProducts(ProductParam[] calldata /* params */ ) external pure {
revert("Unsupported");
}

function setProductTypes(ProductTypeParam[] calldata /* productTypes */ ) external pure {
revert("Unsupported");
}

function addProductType(
uint8 claimMethod,
uint16 gracePeriod,
Expand Down
14 changes: 4 additions & 10 deletions contracts/mocks/StakingPool/SPMockStakingProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract SPMockStakingProducts is IStakingProducts, MasterAwareV2, Multicall {
coverProductsContract = _coverProductsContract;
}

function getStakingPool(uint poolId) internal view returns (IStakingPool stakingPoolAddress) {
function stakingPool(uint poolId) public view returns (IStakingPool stakingPoolAddress) {
stakingPoolAddress = IStakingPool(StakingPoolLibrary.getAddress(stakingPoolFactory, poolId));
}

Expand Down Expand Up @@ -82,7 +82,7 @@ contract SPMockStakingProducts is IStakingProducts, MasterAwareV2, Multicall {

function recalculateEffectiveWeights(uint poolId, uint[] calldata productIds) external {

IStakingPool _stakingPool = getStakingPool(poolId);
IStakingPool _stakingPool = stakingPool(poolId);

(
uint globalCapacityRatio,
Expand Down Expand Up @@ -115,7 +115,7 @@ contract SPMockStakingProducts is IStakingProducts, MasterAwareV2, Multicall {

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

IStakingPool _stakingPool = getStakingPool(poolId);
IStakingPool _stakingPool = stakingPool(poolId);

if (msg.sender != _stakingPool.manager()) {
revert OnlyManager();
Expand Down Expand Up @@ -238,7 +238,7 @@ contract SPMockStakingProducts is IStakingProducts, MasterAwareV2, Multicall {
uint capacityReductionRatio
) public view returns (uint effectiveWeight) {

IStakingPool _stakingPool = getStakingPool(poolId);
IStakingPool _stakingPool = stakingPool(poolId);

return _getEffectiveWeight(
_stakingPool,
Expand Down Expand Up @@ -507,12 +507,6 @@ contract SPMockStakingProducts is IStakingProducts, MasterAwareV2, Multicall {
// none :)
}

function stakingPool(uint poolId) public view returns (IStakingPool) {
return IStakingPool(
StakingPoolLibrary.getAddress(address(stakingPoolFactory), poolId)
);
}

function createStakingPool(
bool /* isPrivatePool */,
uint /* initialPoolFee */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ pragma solidity ^0.8.18;
import "../../interfaces/IStakingPool.sol";
import "../../interfaces/ICover.sol";
import "../../interfaces/IStakingProducts.sol";
import "../../interfaces/ICoverProducts.sol";
import "../../interfaces/IStakingPoolFactory.sol";

contract StakingProductsMockCoverProducts {
contract StakingProductsMockCoverProducts is ICoverProducts {

mapping(uint => Product) public products;
mapping(uint => ProductType) public productTypes;
mapping(uint => Product) public _products;
mapping(uint => ProductType) public _productTypes;
mapping(uint => mapping(uint => bool)) public allowedPools;
uint public productsCount;
mapping(uint => uint) private _allowedPoolsCount;
Expand All @@ -21,23 +22,23 @@ contract StakingProductsMockCoverProducts {
}

function setProduct(Product memory _product, uint id) public {
products[id] = _product;
_products[id] = _product;
productsCount++;
}

function allowedPoolsCount(uint productId) external view returns (uint) {
return _allowedPoolsCount[productId];
}

function setProducts(Product[] memory _products, uint[] memory productIds) public {
for (uint i = 0; i < _products.length; i++) {
products[productIds[i]] = _products[i];
productsCount++;
}
}
// function setProducts(Product[] memory newProducts, uint[] memory productIds) public {
// for (uint i = 0; i < newProducts.length; i++) {
// _products[productIds[i]] = newProducts[i];
// productsCount++;
// }
// }

function setProductType(ProductType calldata product, uint id) public {
productTypes[id] = product;
_productTypes[id] = product;
}

function initializeStaking(
Expand Down Expand Up @@ -75,4 +76,43 @@ contract StakingProductsMockCoverProducts {
}
}
}

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 getProducts() external pure returns (Product[] memory) {
revert("Unsupported");
}

function productTypesCount() external pure returns (uint) {
revert("Unsupported");
}

function getPriceAndCapacityRatios(uint[] calldata /* productIds */ ) external pure returns (
uint[] memory /* _initialPrices */,
uint[] memory /* _capacityReductionRatios */
) {
revert("Unsupported");
}

function productNames(uint /* productId */) external pure returns (string memory) {
revert("Unsupported");
}

function getProductWithType(uint /* productId */ ) external pure returns (Product memory, ProductType memory) {
revert("Unsupported");
}

function setProductTypes(ProductTypeParam[] calldata /* productTypes */ ) external pure {
revert("Unsupported");
}

function setProducts(ProductParam[] calldata /* params */ ) external pure {
revert("Unsupported");
}
}
3 changes: 1 addition & 2 deletions contracts/modules/assessment/IndividualClaims.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ contract IndividualClaims is IIndividualClaims, MasterAwareV2 {
CoverSegment memory segment = cover().coverSegmentWithRemainingAmount(coverId, segmentId);

{
Product memory product = coverProductsContract.products(coverData.productId);
ProductType memory productType = coverProductsContract.productTypes(product.productType);
(, ProductType memory productType) = coverProductsContract.getProductWithType(coverData.productId);

require(
productType.claimMethod == uint8(ClaimMethod.IndividualClaims),
Expand Down
14 changes: 3 additions & 11 deletions contracts/modules/cover/Cover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu

/* ========== STATE VARIABLES ========== */

Product[] internal _products;

mapping(uint => CoverData) private _coverData;

// cover id => segment id => pool allocations array
Expand Down Expand Up @@ -658,20 +660,10 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu
) {
_globalMinPriceRatio = GLOBAL_MIN_PRICE_RATIO;
_globalCapacityRatio = GLOBAL_CAPACITY_RATIO;
_capacityReductionRatios = new uint[](productIds.length);
_initialPrices = new uint[](productIds.length);

ICoverProducts _coverProducts = coverProducts();
for (uint i = 0; i < productIds.length; i++) {
uint productId = productIds[i];

if (productId >= _coverProducts.productsCount()) {
revert ProductDoesntExist();
}
(_initialPrices, _capacityReductionRatios) = _coverProducts.getPriceAndCapacityRatios(productIds);

_initialPrices[i] = uint(_coverProducts.products(productId).initialPriceRatio);
_capacityReductionRatios[i] = uint(_coverProducts.products(productId).capacityReductionRatio);
}
}

function isCoverAssetSupported(uint assetId, uint productCoverAssetsBitmap) internal view returns (bool) {
Expand Down
27 changes: 26 additions & 1 deletion contracts/modules/cover/CoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,39 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall {
return _productTypes.length;
}

function productsCount() external view returns (uint) {
function productsCount() public view returns (uint) {
return _products.length;
}

function getProducts() external view returns (Product[] memory) {
return _products;
}

function getProductWithType(uint productId) external override view returns (Product memory product, ProductType memory) {
product = _products[productId];
return (product, _productTypes[product.productType]);
}

function getPriceAndCapacityRatios(uint[] calldata productIds) external view returns (
uint[] memory _initialPrices,
uint[] memory _capacityReductionRatios
) {
_capacityReductionRatios = new uint[](productIds.length);
_initialPrices = new uint[](productIds.length);

for (uint i = 0; i < productIds.length; i++) {
uint productId = productIds[i];

uint _productsCount = _products.length;
if (productId >= _productsCount) {
revert ProductDoesntExist();
}

_initialPrices[i] = uint(_products[productId].initialPriceRatio);
_capacityReductionRatios[i] = uint(_products[productId].capacityReductionRatio);
}
}

/* ========== PRODUCT CONFIGURATION ========== */

function setProducts(ProductParam[] calldata productParams) external override onlyAdvisoryBoard {
Expand Down
Loading

0 comments on commit 04541cc

Please sign in to comment.