From f6f004e280b6830db015379db489f5af6c8b471f Mon Sep 17 00:00:00 2001 From: DuXXuD Date: Tue, 3 Dec 2024 11:50:34 +0100 Subject: [PATCH 1/3] refactor: rename global min price to default min price --- contracts/interfaces/ICover.sol | 2 +- contracts/mocks/generic/CoverGeneric.sol | 2 +- contracts/mocks/modules/Cover/COMockStakingPool.sol | 2 +- .../mocks/modules/Cover/COMockStakingProducts.sol | 4 ++-- .../mocks/modules/CoverProducts/CPMockCover.sol | 2 +- contracts/mocks/modules/StakingPool/SKMockCover.sol | 2 +- .../mocks/modules/StakingProducts/SPMockCover.sol | 6 +++--- contracts/modules/cover/Cover.sol | 8 ++++---- test/fork/utils.js | 2 +- test/unit/Cover/setup.js | 4 ++-- test/unit/CoverProducts/setProducts.js | 12 ++++++------ test/unit/CoverProducts/setup.js | 4 ++-- test/unit/StakingPool/requestAllocation.js | 4 ++-- test/unit/StakingPool/setup.js | 2 +- test/unit/StakingProducts/createStakingPool.js | 4 ++-- test/unit/StakingProducts/helpers.js | 4 ++-- test/unit/StakingProducts/setProducts.js | 10 +++++----- test/unit/StakingProducts/setup.js | 2 +- 18 files changed, 38 insertions(+), 38 deletions(-) diff --git a/contracts/interfaces/ICover.sol b/contracts/interfaces/ICover.sol index df0c93b02f..cbf54d6480 100644 --- a/contracts/interfaces/ICover.sol +++ b/contracts/interfaces/ICover.sol @@ -110,7 +110,7 @@ interface ICover { uint _globalMinPriceRatio ); - function GLOBAL_MIN_PRICE_RATIO() external view returns (uint); + function DEFAULT_MIN_PRICE_RATIO() external view returns (uint); /* === MUTATIVE FUNCTIONS ==== */ diff --git a/contracts/mocks/generic/CoverGeneric.sol b/contracts/mocks/generic/CoverGeneric.sol index ca25eda729..29a5a59494 100644 --- a/contracts/mocks/generic/CoverGeneric.sol +++ b/contracts/mocks/generic/CoverGeneric.sol @@ -7,7 +7,7 @@ import "../../interfaces/ICoverNFT.sol"; contract CoverGeneric is ICover { - uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1% + uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% uint public constant MAX_COMMISSION_RATIO = 3000; // 30% function getGlobalMinPriceRatio() public virtual pure returns (uint) { diff --git a/contracts/mocks/modules/Cover/COMockStakingPool.sol b/contracts/mocks/modules/Cover/COMockStakingPool.sol index 0b8246d4a6..fde7297fc8 100644 --- a/contracts/mocks/modules/Cover/COMockStakingPool.sol +++ b/contracts/mocks/modules/Cover/COMockStakingPool.sol @@ -27,7 +27,7 @@ contract COMockStakingPool is StakingPoolGeneric { uint public constant MAX_PRICE_RATIO = 10_000; uint constant REWARDS_DENOMINATOR = 10_000; - uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1% + uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% uint public constant ONE_NXM = 1 ether; uint public constant ALLOCATION_UNITS_PER_NXM = 100; uint public constant NXM_PER_ALLOCATION_UNIT = ONE_NXM / ALLOCATION_UNITS_PER_NXM; diff --git a/contracts/mocks/modules/Cover/COMockStakingProducts.sol b/contracts/mocks/modules/Cover/COMockStakingProducts.sol index 6b88638a07..8695b29dab 100644 --- a/contracts/mocks/modules/Cover/COMockStakingProducts.sol +++ b/contracts/mocks/modules/Cover/COMockStakingProducts.sol @@ -13,7 +13,7 @@ contract COMockStakingProducts is StakingProductsGeneric { mapping(uint => mapping(uint => StakedProduct)) private _products; - uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1% + uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% address public immutable coverContract; address public immutable tokenControllerContract; @@ -78,7 +78,7 @@ contract COMockStakingProducts is StakingProductsGeneric { // override with initial price and check if pool is allowed for (uint i = 0; i < numProducts; i++) { - if (productInitParams[i].targetPrice < GLOBAL_MIN_PRICE_RATIO) { + if (productInitParams[i].targetPrice < DEFAULT_MIN_PRICE_RATIO) { revert TargetPriceBelowGlobalMinPriceRatio(); } diff --git a/contracts/mocks/modules/CoverProducts/CPMockCover.sol b/contracts/mocks/modules/CoverProducts/CPMockCover.sol index b8152d231d..db36dc8530 100644 --- a/contracts/mocks/modules/CoverProducts/CPMockCover.sol +++ b/contracts/mocks/modules/CoverProducts/CPMockCover.sol @@ -46,7 +46,7 @@ contract CPMockCover is CoverGeneric { } function getGlobalMinPriceRatio() public override pure returns (uint) { - return GLOBAL_MIN_PRICE_RATIO; + return DEFAULT_MIN_PRICE_RATIO; } function getProducts() external view returns (Product[] memory) { diff --git a/contracts/mocks/modules/StakingPool/SKMockCover.sol b/contracts/mocks/modules/StakingPool/SKMockCover.sol index 6304669ae1..058608fac3 100644 --- a/contracts/mocks/modules/StakingPool/SKMockCover.sol +++ b/contracts/mocks/modules/StakingPool/SKMockCover.sol @@ -60,7 +60,7 @@ contract SKMockCover is CoverGeneric { _globalCapacityRatio, product.capacityReductionRatio, _globalRewardsRatio, - GLOBAL_MIN_PRICE_RATIO + DEFAULT_MIN_PRICE_RATIO ) ); diff --git a/contracts/mocks/modules/StakingProducts/SPMockCover.sol b/contracts/mocks/modules/StakingProducts/SPMockCover.sol index 03d22d84ea..b9b4d156b2 100644 --- a/contracts/mocks/modules/StakingProducts/SPMockCover.sol +++ b/contracts/mocks/modules/StakingProducts/SPMockCover.sol @@ -47,7 +47,7 @@ contract SPMockCover is CoverGeneric { } function getGlobalMinPriceRatio() public override pure returns (uint) { - return GLOBAL_MIN_PRICE_RATIO; + return DEFAULT_MIN_PRICE_RATIO; } function getGlobalCapacityRatio() public override pure returns (uint) { @@ -55,7 +55,7 @@ contract SPMockCover is CoverGeneric { } function getGlobalCapacityAndPriceRatios() public override pure returns (uint, uint) { - return (GLOBAL_CAPACITY_RATIO, GLOBAL_MIN_PRICE_RATIO); + return (GLOBAL_CAPACITY_RATIO, DEFAULT_MIN_PRICE_RATIO); } // TODO: remove me. see https://github.com/NexusMutual/smart-contracts/issues/1161 @@ -87,7 +87,7 @@ contract SPMockCover is CoverGeneric { GLOBAL_CAPACITY_RATIO, product.capacityReductionRatio, GLOBAL_REWARDS_RATIO, - GLOBAL_MIN_PRICE_RATIO + DEFAULT_MIN_PRICE_RATIO ) ); diff --git a/contracts/modules/cover/Cover.sol b/contracts/modules/cover/Cover.sol index b123306a9f..2e92455e53 100644 --- a/contracts/modules/cover/Cover.sol +++ b/contracts/modules/cover/Cover.sol @@ -67,7 +67,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu uint public constant MAX_COMMISSION_RATIO = 3000; // 30% - uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1% + uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% uint private constant ONE_NXM = 1e18; @@ -164,7 +164,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu allocationRequest.globalCapacityRatio = GLOBAL_CAPACITY_RATIO; allocationRequest.capacityReductionRatio = product.capacityReductionRatio; allocationRequest.rewardRatio = GLOBAL_REWARDS_RATIO; - allocationRequest.globalMinPrice = GLOBAL_MIN_PRICE_RATIO; + allocationRequest.globalMinPrice = DEFAULT_MIN_PRICE_RATIO; } uint previousSegmentAmount; @@ -639,7 +639,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu } function getGlobalMinPriceRatio() external pure returns (uint) { - return GLOBAL_MIN_PRICE_RATIO; + return DEFAULT_MIN_PRICE_RATIO; } function getGlobalCapacityAndPriceRatios() external pure returns ( @@ -647,7 +647,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu uint _globalMinPriceRatio ) { _globalCapacityRatio = GLOBAL_CAPACITY_RATIO; - _globalMinPriceRatio = GLOBAL_MIN_PRICE_RATIO; + _globalMinPriceRatio = DEFAULT_MIN_PRICE_RATIO; } function isCoverAssetSupported(uint assetId, uint productCoverAssetsBitmap) internal view returns (bool) { diff --git a/test/fork/utils.js b/test/fork/utils.js index 388eb6566d..be3c774098 100644 --- a/test/fork/utils.js +++ b/test/fork/utils.js @@ -274,7 +274,7 @@ async function getConfig() { TRANCHE_DURATION: stakingProducts.TRANCHE_DURATION(), GLOBAL_CAPACITY_RATIO: cover.globalCapacityRatio(), GLOBAL_REWARDS_RATIO: cover.getGlobalRewardsRatio(), - GLOBAL_MIN_PRICE_RATIO: cover.GLOBAL_MIN_PRICE_RATIO(), + DEFAULT_MIN_PRICE_RATIO: cover.DEFAULT_MIN_PRICE_RATIO(), }; await Promise.all(Object.keys(config).map(async key => (config[key] = await config[key]))); return config; diff --git a/test/unit/Cover/setup.js b/test/unit/Cover/setup.js index c3a094f642..d35ff24c63 100644 --- a/test/unit/Cover/setup.js +++ b/test/unit/Cover/setup.js @@ -195,7 +195,7 @@ async function setup() { }, ]); - const GLOBAL_MIN_PRICE_RATIO = await cover.GLOBAL_MIN_PRICE_RATIO(); + const DEFAULT_MIN_PRICE_RATIO = await cover.DEFAULT_MIN_PRICE_RATIO(); const MAX_COMMISSION_RATIO = await cover.MAX_COMMISSION_RATIO(); const BUCKET_SIZE = BigNumber.from(7 * 24 * 3600); // 7 days const capacityFactor = '20000'; @@ -216,7 +216,7 @@ async function setup() { stakingPoolFactory, stakingProducts, coverProducts, - config: { GLOBAL_MIN_PRICE_RATIO, BUCKET_SIZE, MAX_COMMISSION_RATIO }, + config: { DEFAULT_MIN_PRICE_RATIO, BUCKET_SIZE, MAX_COMMISSION_RATIO }, Assets, pooledStakingSigner, }; diff --git a/test/unit/CoverProducts/setProducts.js b/test/unit/CoverProducts/setProducts.js index a95209c9a4..b879e461df 100644 --- a/test/unit/CoverProducts/setProducts.js +++ b/test/unit/CoverProducts/setProducts.js @@ -279,12 +279,12 @@ describe('setProducts', function () { ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioAbove100Percent'); }); - it('should revert if initialPriceRatio is below GLOBAL_MIN_PRICE_RATIO', async function () { + it('should revert if initialPriceRatio is below DEFAULT_MIN_PRICE_RATIO', async function () { const fixture = await loadFixture(setup); const { coverProducts } = fixture; const [advisoryBoardMember0] = fixture.accounts.advisoryBoardMembers; - const { GLOBAL_MIN_PRICE_RATIO } = fixture.config; - const initialPriceRatio = GLOBAL_MIN_PRICE_RATIO - 1; + const { DEFAULT_MIN_PRICE_RATIO } = fixture.config; + const initialPriceRatio = DEFAULT_MIN_PRICE_RATIO - 1; const product = { ...productTemplate, initialPriceRatio }; const productParams = { ...productParamsTemplate, product }; await expect( @@ -292,16 +292,16 @@ describe('setProducts', function () { ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioBelowGlobalMinPriceRatio'); }); - it('should revert if initialPriceRatio is below GLOBAL_MIN_PRICE_RATIO when editing a product', async function () { + it('should revert if initialPriceRatio is below DEFAULT_MIN_PRICE_RATIO when editing a product', async function () { const fixture = await loadFixture(setup); const { coverProducts } = fixture; const [advisoryBoardMember0] = fixture.accounts.advisoryBoardMembers; const productId = 1; - const { GLOBAL_MIN_PRICE_RATIO } = fixture.config; + const { DEFAULT_MIN_PRICE_RATIO } = fixture.config; const productParams = { ...productParamsTemplate }; await coverProducts.connect(advisoryBoardMember0).setProducts([productParams]); { - const initialPriceRatio = GLOBAL_MIN_PRICE_RATIO - 1; + const initialPriceRatio = DEFAULT_MIN_PRICE_RATIO - 1; const product = { ...productTemplate, initialPriceRatio }; const productParams = { ...productParamsTemplate, product, productId }; await expect( diff --git a/test/unit/CoverProducts/setup.js b/test/unit/CoverProducts/setup.js index 8b75b4c5ed..bf4a200a42 100644 --- a/test/unit/CoverProducts/setup.js +++ b/test/unit/CoverProducts/setup.js @@ -174,7 +174,7 @@ async function setup() { // add products await coverProducts.connect(accounts.advisoryBoardMembers[0]).setProducts(products); - const GLOBAL_MIN_PRICE_RATIO = await cover.GLOBAL_MIN_PRICE_RATIO(); + const DEFAULT_MIN_PRICE_RATIO = await cover.DEFAULT_MIN_PRICE_RATIO(); const BUCKET_SIZE = BigNumber.from(7 * 24 * 3600); // 7 days const capacityFactor = '20000'; @@ -193,7 +193,7 @@ async function setup() { capacityFactor, stakingProducts, coverProducts, - config: { GLOBAL_MIN_PRICE_RATIO, BUCKET_SIZE }, + config: { DEFAULT_MIN_PRICE_RATIO, BUCKET_SIZE }, Assets, pooledStakingSigner, productTypes, diff --git a/test/unit/StakingPool/requestAllocation.js b/test/unit/StakingPool/requestAllocation.js index 2d3ae0aa81..e4a1a3e1ce 100644 --- a/test/unit/StakingPool/requestAllocation.js +++ b/test/unit/StakingPool/requestAllocation.js @@ -163,7 +163,7 @@ describe('requestAllocation', function () { it('should update allocation amount', async function () { const fixture = await loadFixture(requestAllocationSetup); const { stakingPool, cover } = fixture; - const { GLOBAL_CAPACITY_RATIO, GLOBAL_MIN_PRICE_RATIO, GLOBAL_REWARDS_RATIO, NXM_PER_ALLOCATION_UNIT } = + const { GLOBAL_CAPACITY_RATIO, DEFAULT_MIN_PRICE_RATIO, GLOBAL_REWARDS_RATIO, NXM_PER_ALLOCATION_UNIT } = fixture.config; const { timestamp } = await ethers.provider.getBlock('latest'); const allocationId = await stakingPool.getNextAllocationId(); @@ -182,7 +182,7 @@ describe('requestAllocation', function () { globalCapacityRatio: GLOBAL_CAPACITY_RATIO, capacityReductionRatio: coverProductTemplate.capacityReductionRatio, rewardRatio: GLOBAL_REWARDS_RATIO, - globalMinPrice: GLOBAL_MIN_PRICE_RATIO, + globalMinPrice: DEFAULT_MIN_PRICE_RATIO, }; await cover.requestAllocation(buyCoverParamsTemplate.amount, 0, request, stakingPool.address); diff --git a/test/unit/StakingPool/setup.js b/test/unit/StakingPool/setup.js index be00b2d809..108923c6e7 100644 --- a/test/unit/StakingPool/setup.js +++ b/test/unit/StakingPool/setup.js @@ -89,7 +89,7 @@ async function setup() { TRANCHE_DURATION: await stakingProducts.TRANCHE_DURATION(), GLOBAL_CAPACITY_RATIO: await cover.globalCapacityRatio(), GLOBAL_REWARDS_RATIO: await cover.getGlobalRewardsRatio(), - GLOBAL_MIN_PRICE_RATIO: await cover.GLOBAL_MIN_PRICE_RATIO(), + DEFAULT_MIN_PRICE_RATIO: await cover.DEFAULT_MIN_PRICE_RATIO(), }; const coverSigner = await ethers.getImpersonatedSigner(cover.address); diff --git a/test/unit/StakingProducts/createStakingPool.js b/test/unit/StakingProducts/createStakingPool.js index 29247f5871..395f99a18c 100644 --- a/test/unit/StakingProducts/createStakingPool.js +++ b/test/unit/StakingProducts/createStakingPool.js @@ -258,11 +258,11 @@ describe('createStakingPool', function () { it('should fail to initialize products with targetPrice below global minimum', async function () { const fixture = await loadFixture(createStakingPoolSetup); const { stakingProducts } = fixture; - const { GLOBAL_MIN_PRICE_RATIO } = fixture.config; + const { DEFAULT_MIN_PRICE_RATIO } = fixture.config; const [stakingPoolCreator] = fixture.accounts.members; const { initialPoolFee, maxPoolFee, productInitializationParams, ipfsDescriptionHash } = newPoolFixture; - const products = [{ ...productInitializationParams[0], targetPrice: GLOBAL_MIN_PRICE_RATIO - 1 }]; + const products = [{ ...productInitializationParams[0], targetPrice: DEFAULT_MIN_PRICE_RATIO - 1 }]; await expect( stakingProducts.connect(stakingPoolCreator).createStakingPool( false, // isPrivatePool, diff --git a/test/unit/StakingProducts/helpers.js b/test/unit/StakingProducts/helpers.js index 97dfaa494e..eda0f052ef 100644 --- a/test/unit/StakingProducts/helpers.js +++ b/test/unit/StakingProducts/helpers.js @@ -111,7 +111,7 @@ async function depositTo(params) { async function allocateCapacity({ amount, productId }) { const { stakingPool, coverSigner, coverProductTemplate } = this; - const { GLOBAL_CAPACITY_RATIO, GLOBAL_REWARDS_RATIO, GLOBAL_MIN_PRICE_RATIO } = this.config; + const { GLOBAL_CAPACITY_RATIO, GLOBAL_REWARDS_RATIO, DEFAULT_MIN_PRICE_RATIO } = this.config; const allocationRequest = { ...allocationRequestTemplate, @@ -120,7 +120,7 @@ async function allocateCapacity({ amount, productId }) { capacityReductionRatio: coverProductTemplate.capacityReductionRatio, useFixedPrice: coverProductTemplate.useFixedPrice, rewardRatio: GLOBAL_REWARDS_RATIO, - globalMinPrice: GLOBAL_MIN_PRICE_RATIO, + globalMinPrice: DEFAULT_MIN_PRICE_RATIO, }; await stakingPool.connect(coverSigner).requestAllocation(amount, 0, allocationRequest); diff --git a/test/unit/StakingProducts/setProducts.js b/test/unit/StakingProducts/setProducts.js index f30df705b5..9fb730be79 100644 --- a/test/unit/StakingProducts/setProducts.js +++ b/test/unit/StakingProducts/setProducts.js @@ -366,7 +366,7 @@ describe('setProducts unit tests', function () { it('should edit prices and skip weights', async function () { const fixture = await loadFixture(setup); const { stakingProducts } = fixture; - const { GLOBAL_MIN_PRICE_RATIO } = fixture.config; + const { DEFAULT_MIN_PRICE_RATIO } = fixture.config; const [manager] = fixture.accounts.members; const newProductParams = { ...newProductTemplate }; @@ -382,7 +382,7 @@ describe('setProducts unit tests', function () { await stakingProducts .connect(manager) .setProducts(poolId, [ - { ...newProductParams, targetWeight: 1, setTargetWeight: false, targetPrice: GLOBAL_MIN_PRICE_RATIO }, + { ...newProductParams, targetWeight: 1, setTargetWeight: false, targetPrice: DEFAULT_MIN_PRICE_RATIO }, ]); const { timestamp: bumpedPriceUpdateTimeAfter } = await ethers.provider.getBlock('latest'); @@ -390,7 +390,7 @@ describe('setProducts unit tests', function () { product: await stakingProducts.getProduct(poolId, 0), productParams: { ...newProductTemplate, - targetPrice: GLOBAL_MIN_PRICE_RATIO, + targetPrice: DEFAULT_MIN_PRICE_RATIO, bumpedPriceUpdateTimeAfter, }, }); @@ -411,10 +411,10 @@ describe('setProducts unit tests', function () { it('should fail with targetPrice below global min price ratio', async function () { const fixture = await loadFixture(setup); const { stakingProducts } = fixture; - const { GLOBAL_MIN_PRICE_RATIO } = fixture.config; + const { DEFAULT_MIN_PRICE_RATIO } = fixture.config; const [manager] = fixture.accounts.members; - const product = { ...newProductTemplate, targetPrice: GLOBAL_MIN_PRICE_RATIO - 1 }; + const product = { ...newProductTemplate, targetPrice: DEFAULT_MIN_PRICE_RATIO - 1 }; await expect(stakingProducts.connect(manager).setProducts(poolId, [product])).to.be.revertedWithCustomError( stakingProducts, 'TargetPriceBelowMin', diff --git a/test/unit/StakingProducts/setup.js b/test/unit/StakingProducts/setup.js index f84ae251f0..0e992d7f78 100644 --- a/test/unit/StakingProducts/setup.js +++ b/test/unit/StakingProducts/setup.js @@ -162,7 +162,7 @@ async function setup() { TRANCHE_DURATION: await stakingProducts.TRANCHE_DURATION(), GLOBAL_CAPACITY_RATIO: await cover.GLOBAL_CAPACITY_RATIO(), GLOBAL_REWARDS_RATIO: await cover.GLOBAL_REWARDS_RATIO(), - GLOBAL_MIN_PRICE_RATIO: await cover.GLOBAL_MIN_PRICE_RATIO(), + DEFAULT_MIN_PRICE_RATIO: await cover.DEFAULT_MIN_PRICE_RATIO(), }; const coverSigner = await ethers.getImpersonatedSigner(cover.address); From 085e0de6a3f5cad36b2959f1213c26aab1cb2675 Mon Sep 17 00:00:00 2001 From: DuXXuD Date: Tue, 3 Dec 2024 16:05:11 +0100 Subject: [PATCH 2/3] refactor: rename global min price to default min price --- contracts/interfaces/ICover.sol | 4 ++-- contracts/interfaces/ICoverProducts.sol | 2 +- contracts/interfaces/IStakingPool.sol | 2 +- contracts/interfaces/IStakingProducts.sol | 4 ++-- contracts/mocks/generic/CoverGeneric.sol | 2 +- .../mocks/modules/Cover/COMockStakingProducts.sol | 2 +- .../mocks/modules/CoverProducts/CPMockCover.sol | 2 +- .../modules/StakingPool/SKMockStakingProducts.sol | 10 +++++----- .../mocks/modules/StakingProducts/SPMockCover.sol | 2 +- contracts/modules/cover/Cover.sol | 8 ++++---- contracts/modules/cover/CoverProducts.sol | 6 +++--- contracts/modules/staking/StakingPool.sol | 2 +- contracts/modules/staking/StakingProducts.sol | 14 +++++++------- .../recalculateEffectiveWeightsForAllProducts.js | 12 ++++++------ test/unit/CoverProducts/setProducts.js | 4 ++-- test/unit/StakingPool/burnStake.js | 2 +- test/unit/StakingPool/depositTo.js | 6 +++--- test/unit/StakingPool/helpers.js | 2 +- test/unit/StakingPool/requestAllocation.js | 4 ++-- test/unit/StakingPool/setPoolFee.js | 2 +- test/unit/StakingPool/withdraw.js | 2 +- test/unit/StakingProducts/createStakingPool.js | 2 +- test/unit/StakingProducts/helpers.js | 2 +- 23 files changed, 49 insertions(+), 49 deletions(-) diff --git a/contracts/interfaces/ICover.sol b/contracts/interfaces/ICover.sol index cbf54d6480..0c7f9a0f58 100644 --- a/contracts/interfaces/ICover.sol +++ b/contracts/interfaces/ICover.sol @@ -103,11 +103,11 @@ interface ICover { function getGlobalRewardsRatio() external view returns (uint); - function getGlobalMinPriceRatio() external pure returns (uint); + function getDefaultMinPriceRatio() external pure returns (uint); function getGlobalCapacityAndPriceRatios() external view returns ( uint _globalCapacityRatio, - uint _globalMinPriceRatio + uint _defaultMinPriceRatio ); function DEFAULT_MIN_PRICE_RATIO() external view returns (uint); diff --git a/contracts/interfaces/ICoverProducts.sol b/contracts/interfaces/ICoverProducts.sol index 3adec13f4e..e281fa7b5c 100644 --- a/contracts/interfaces/ICoverProducts.sol +++ b/contracts/interfaces/ICoverProducts.sol @@ -129,7 +129,7 @@ interface ICoverProducts { // Misc error UnsupportedCoverAssets(); - error InitialPriceRatioBelowGlobalMinPriceRatio(); + error InitialPriceRatioBelowDefaultMinPriceRatio(); error InitialPriceRatioAbove100Percent(); error CapacityReductionRatioAbove100Percent(); diff --git a/contracts/interfaces/IStakingPool.sol b/contracts/interfaces/IStakingPool.sol index 5d67cd7972..4ea6730f14 100644 --- a/contracts/interfaces/IStakingPool.sol +++ b/contracts/interfaces/IStakingPool.sol @@ -17,7 +17,7 @@ struct AllocationRequest { uint globalCapacityRatio; uint capacityReductionRatio; uint rewardRatio; - uint globalMinPrice; + uint defaultMinPrice; } struct BurnStakeParams { diff --git a/contracts/interfaces/IStakingProducts.sol b/contracts/interfaces/IStakingProducts.sol index 3e034b399d..b621291304 100644 --- a/contracts/interfaces/IStakingProducts.sol +++ b/contracts/interfaces/IStakingProducts.sol @@ -58,7 +58,7 @@ interface IStakingProducts { uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint globalMinPrice, + uint defaultMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNxm @@ -149,7 +149,7 @@ interface IStakingProducts { // Staking Pool creation error ProductDoesntExistOrIsDeprecated(); error InvalidProductType(); - error TargetPriceBelowGlobalMinPriceRatio(); + error TargetPriceBelowDefaultMinPriceRatio(); // IPFS error IpfsHashRequired(); diff --git a/contracts/mocks/generic/CoverGeneric.sol b/contracts/mocks/generic/CoverGeneric.sol index 29a5a59494..7803ca5acc 100644 --- a/contracts/mocks/generic/CoverGeneric.sol +++ b/contracts/mocks/generic/CoverGeneric.sol @@ -10,7 +10,7 @@ contract CoverGeneric is ICover { uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% uint public constant MAX_COMMISSION_RATIO = 3000; // 30% - function getGlobalMinPriceRatio() public virtual pure returns (uint) { + function getDefaultMinPriceRatio() public virtual pure returns (uint) { revert("Unsupported"); } diff --git a/contracts/mocks/modules/Cover/COMockStakingProducts.sol b/contracts/mocks/modules/Cover/COMockStakingProducts.sol index 8695b29dab..caf6c06dc5 100644 --- a/contracts/mocks/modules/Cover/COMockStakingProducts.sol +++ b/contracts/mocks/modules/Cover/COMockStakingProducts.sol @@ -79,7 +79,7 @@ contract COMockStakingProducts is StakingProductsGeneric { for (uint i = 0; i < numProducts; i++) { if (productInitParams[i].targetPrice < DEFAULT_MIN_PRICE_RATIO) { - revert TargetPriceBelowGlobalMinPriceRatio(); + revert TargetPriceBelowDefaultMinPriceRatio(); } uint productId = productInitParams[i].productId; diff --git a/contracts/mocks/modules/CoverProducts/CPMockCover.sol b/contracts/mocks/modules/CoverProducts/CPMockCover.sol index db36dc8530..1eaf083ba9 100644 --- a/contracts/mocks/modules/CoverProducts/CPMockCover.sol +++ b/contracts/mocks/modules/CoverProducts/CPMockCover.sol @@ -45,7 +45,7 @@ contract CPMockCover is CoverGeneric { } } - function getGlobalMinPriceRatio() public override pure returns (uint) { + function getDefaultMinPriceRatio() public override pure returns (uint) { return DEFAULT_MIN_PRICE_RATIO; } diff --git a/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol b/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol index 7b53ae5e59..f181f26ca3 100644 --- a/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol +++ b/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol @@ -118,7 +118,7 @@ contract SKMockStakingProducts is StakingProductsGeneric, MasterAwareV2, Multica } uint globalCapacityRatio; - uint globalMinPriceRatio; + uint defaultMinPriceRatio; uint[] memory initialPriceRatios; uint[] memory capacityReductionRatios; @@ -138,7 +138,7 @@ contract SKMockStakingProducts is StakingProductsGeneric, MasterAwareV2, Multica ICover _cover = ICover(coverContract); globalCapacityRatio = _cover.getGlobalCapacityRatio(); - globalMinPriceRatio = _cover.getGlobalMinPriceRatio(); + defaultMinPriceRatio = _cover.getDefaultMinPriceRatio(); initialPriceRatios = _coverProducts.getInitialPrices(productIds); capacityReductionRatios = _coverProducts.getCapacityReductionRatios(productIds); @@ -169,7 +169,7 @@ contract SKMockStakingProducts is StakingProductsGeneric, MasterAwareV2, Multica if (_param.targetPrice > TARGET_PRICE_DENOMINATOR) { revert TargetPriceTooHigh(); } - if (_param.targetPrice < globalMinPriceRatio) { + if (_param.targetPrice < defaultMinPriceRatio) { revert TargetPriceBelowMin(); } _product.targetPrice = _param.targetPrice; @@ -324,14 +324,14 @@ contract SKMockStakingProducts is StakingProductsGeneric, MasterAwareV2, Multica uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint globalMinPrice, + uint defaultMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNXM ) public override returns (uint premium) { StakedProduct memory product = _products[poolId][productId]; - uint targetPrice = Math.max(product.targetPrice, globalMinPrice); + uint targetPrice = Math.max(product.targetPrice, defaultMinPrice); if (useFixedPrice) { return calculateFixedPricePremium(period, coverAmount, targetPrice, nxmPerAllocationUnit, TARGET_PRICE_DENOMINATOR); diff --git a/contracts/mocks/modules/StakingProducts/SPMockCover.sol b/contracts/mocks/modules/StakingProducts/SPMockCover.sol index b9b4d156b2..2784d585a2 100644 --- a/contracts/mocks/modules/StakingProducts/SPMockCover.sol +++ b/contracts/mocks/modules/StakingProducts/SPMockCover.sol @@ -46,7 +46,7 @@ contract SPMockCover is CoverGeneric { stakingPool[id] = addr; } - function getGlobalMinPriceRatio() public override pure returns (uint) { + function getDefaultMinPriceRatio() public override pure returns (uint) { return DEFAULT_MIN_PRICE_RATIO; } diff --git a/contracts/modules/cover/Cover.sol b/contracts/modules/cover/Cover.sol index 2e92455e53..4860c01867 100644 --- a/contracts/modules/cover/Cover.sol +++ b/contracts/modules/cover/Cover.sol @@ -164,7 +164,7 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu allocationRequest.globalCapacityRatio = GLOBAL_CAPACITY_RATIO; allocationRequest.capacityReductionRatio = product.capacityReductionRatio; allocationRequest.rewardRatio = GLOBAL_REWARDS_RATIO; - allocationRequest.globalMinPrice = DEFAULT_MIN_PRICE_RATIO; + allocationRequest.defaultMinPrice = DEFAULT_MIN_PRICE_RATIO; } uint previousSegmentAmount; @@ -638,16 +638,16 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu return GLOBAL_REWARDS_RATIO; } - function getGlobalMinPriceRatio() external pure returns (uint) { + function getDefaultMinPriceRatio() external pure returns (uint) { return DEFAULT_MIN_PRICE_RATIO; } function getGlobalCapacityAndPriceRatios() external pure returns ( uint _globalCapacityRatio, - uint _globalMinPriceRatio + uint _defaultMinPriceRatio ) { _globalCapacityRatio = GLOBAL_CAPACITY_RATIO; - _globalMinPriceRatio = DEFAULT_MIN_PRICE_RATIO; + _defaultMinPriceRatio = DEFAULT_MIN_PRICE_RATIO; } function isCoverAssetSupported(uint assetId, uint productCoverAssetsBitmap) internal view returns (bool) { diff --git a/contracts/modules/cover/CoverProducts.sol b/contracts/modules/cover/CoverProducts.sol index d4f56676bc..b0eeda8f76 100644 --- a/contracts/modules/cover/CoverProducts.sol +++ b/contracts/modules/cover/CoverProducts.sol @@ -191,7 +191,7 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall { function setProducts(ProductParam[] calldata productParams) external override onlyAdvisoryBoard { uint unsupportedCoverAssetsBitmap = type(uint).max; - uint globalMinPriceRatio = cover().getGlobalMinPriceRatio(); + uint defaultMinPriceRatio = cover().getDefaultMinPriceRatio(); uint poolCount = stakingProducts().getStakingPoolCount(); Asset[] memory assets = pool().getAssets(); @@ -217,8 +217,8 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall { revert UnsupportedCoverAssets(); } - if (product.initialPriceRatio < globalMinPriceRatio) { - revert InitialPriceRatioBelowGlobalMinPriceRatio(); + if (product.initialPriceRatio < defaultMinPriceRatio) { + revert InitialPriceRatioBelowDefaultMinPriceRatio(); } if (product.initialPriceRatio > PRICE_DENOMINATOR) { diff --git a/contracts/modules/staking/StakingPool.sol b/contracts/modules/staking/StakingPool.sol index 25d1758cdf..f4e723e21b 100644 --- a/contracts/modules/staking/StakingPool.sol +++ b/contracts/modules/staking/StakingPool.sol @@ -615,7 +615,7 @@ contract StakingPool is IStakingPool, Multicall { coverAllocationAmount, initialCapacityUsed, totalCapacity, - request.globalMinPrice, + request.defaultMinPrice, request.useFixedPrice, NXM_PER_ALLOCATION_UNIT, ALLOCATION_UNITS_PER_NXM diff --git a/contracts/modules/staking/StakingProducts.sol b/contracts/modules/staking/StakingProducts.sol index 8a9ee5b9ee..0c06a9987c 100644 --- a/contracts/modules/staking/StakingProducts.sol +++ b/contracts/modules/staking/StakingProducts.sol @@ -192,7 +192,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { ( uint globalCapacityRatio, - uint globalMinPriceRatio + uint defaultMinPriceRatio ) = ICover(coverContract).getGlobalCapacityAndPriceRatios(); uint[] memory initialPriceRatios; @@ -244,7 +244,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { revert TargetPriceTooHigh(); } - if (_param.targetPrice < globalMinPriceRatio) { + if (_param.targetPrice < defaultMinPriceRatio) { revert TargetPriceBelowMin(); } @@ -375,7 +375,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint globalMinPrice, + uint defaultMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNXM @@ -386,7 +386,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { } StakedProduct memory product = _products[poolId][productId]; - uint targetPrice = Math.max(product.targetPrice, globalMinPrice); + uint targetPrice = Math.max(product.targetPrice, defaultMinPrice); if (useFixedPrice) { return calculateFixedPricePremium(coverAmount, period, targetPrice, nxmPerAllocationUnit, TARGET_PRICE_DENOMINATOR); @@ -617,15 +617,15 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { function _setInitialProducts(uint poolId, ProductInitializationParams[] memory params) internal { - uint globalMinPriceRatio = cover().getGlobalMinPriceRatio(); + uint defaultMinPriceRatio = cover().getDefaultMinPriceRatio(); uint totalTargetWeight; for (uint i = 0; i < params.length; i++) { ProductInitializationParams memory param = params[i]; - if (params[i].targetPrice < globalMinPriceRatio) { - revert TargetPriceBelowGlobalMinPriceRatio(); + if (params[i].targetPrice < defaultMinPriceRatio) { + revert TargetPriceBelowDefaultMinPriceRatio(); } if (param.targetPrice > TARGET_PRICE_DENOMINATOR) { diff --git a/test/integration/StakingProducts/recalculateEffectiveWeightsForAllProducts.js b/test/integration/StakingProducts/recalculateEffectiveWeightsForAllProducts.js index 9995b20256..6042281ee1 100644 --- a/test/integration/StakingProducts/recalculateEffectiveWeightsForAllProducts.js +++ b/test/integration/StakingProducts/recalculateEffectiveWeightsForAllProducts.js @@ -95,11 +95,11 @@ describe('recalculateEffectiveWeightsForAllProducts', function () { divCeil(amount.mul(ONE_NXM), nxmPriceInCoverAsset), NXM_PER_ALLOCATION_UNIT, ); - const { _globalCapacityRatio, _globalMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); + const { _globalCapacityRatio, _defaultMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); const expectedCapacity = stakeAmount .mul(_globalCapacityRatio) - .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_globalMinPriceRatio)) + .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_defaultMinPriceRatio)) .div(GLOBAL_CAPACITY_DENOMINATOR) .div(CAPACITY_REDUCTION_DENOMINATOR); const expectedActiveWeight = coverAmountInNXM.mul(WEIGHT_DENOMINATOR).div(expectedCapacity); @@ -173,11 +173,11 @@ describe('recalculateEffectiveWeightsForAllProducts', function () { divCeil(amount.mul(ONE_NXM), nxmPriceInCoverAsset), NXM_PER_ALLOCATION_UNIT, ); - const { _globalCapacityRatio, _globalMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); + const { _globalCapacityRatio, _defaultMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); const expectedCapacity = stakeAmount .mul(_globalCapacityRatio) - .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_globalMinPriceRatio)) + .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_defaultMinPriceRatio)) .div(GLOBAL_CAPACITY_DENOMINATOR) .div(CAPACITY_REDUCTION_DENOMINATOR); const expectedActiveWeight = coverAmountInNXM.mul(WEIGHT_DENOMINATOR).div(expectedCapacity); @@ -214,11 +214,11 @@ describe('recalculateEffectiveWeightsForAllProducts', function () { divCeil(amount.mul(ONE_NXM), nxmPriceInCoverAsset), NXM_PER_ALLOCATION_UNIT, ); - const { _globalCapacityRatio, _globalMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); + const { _globalCapacityRatio, _defaultMinPriceRatio } = await cover.getGlobalCapacityAndPriceRatios(); const expectedCapacity = stakeAmount .mul(_globalCapacityRatio) - .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_globalMinPriceRatio)) + .mul(CAPACITY_REDUCTION_DENOMINATOR.sub(_defaultMinPriceRatio)) .div(GLOBAL_CAPACITY_DENOMINATOR) .div(CAPACITY_REDUCTION_DENOMINATOR); const expectedActiveWeight = coverAmountInNXM.mul(WEIGHT_DENOMINATOR).div(expectedCapacity); diff --git a/test/unit/CoverProducts/setProducts.js b/test/unit/CoverProducts/setProducts.js index b879e461df..ebaf6374d6 100644 --- a/test/unit/CoverProducts/setProducts.js +++ b/test/unit/CoverProducts/setProducts.js @@ -289,7 +289,7 @@ describe('setProducts', function () { const productParams = { ...productParamsTemplate, product }; await expect( coverProducts.connect(advisoryBoardMember0).setProducts([productParams]), - ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioBelowGlobalMinPriceRatio'); + ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioBelowDefaultMinPriceRatio'); }); it('should revert if initialPriceRatio is below DEFAULT_MIN_PRICE_RATIO when editing a product', async function () { @@ -306,7 +306,7 @@ describe('setProducts', function () { const productParams = { ...productParamsTemplate, product, productId }; await expect( coverProducts.connect(advisoryBoardMember0).setProducts([productParams]), - ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioBelowGlobalMinPriceRatio'); + ).to.be.revertedWithCustomError(coverProducts, 'InitialPriceRatioBelowDefaultMinPriceRatio'); } }); diff --git a/test/unit/StakingPool/burnStake.js b/test/unit/StakingPool/burnStake.js index d01465c1b2..6fa131722d 100644 --- a/test/unit/StakingPool/burnStake.js +++ b/test/unit/StakingPool/burnStake.js @@ -66,7 +66,7 @@ const allocationRequestParams = { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const stakedNxmAmount = parseEther('100'); diff --git a/test/unit/StakingPool/depositTo.js b/test/unit/StakingPool/depositTo.js index 988897b576..841e1025aa 100644 --- a/test/unit/StakingPool/depositTo.js +++ b/test/unit/StakingPool/depositTo.js @@ -276,7 +276,7 @@ describe('depositTo', function () { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const { firstActiveTrancheId } = await getTranches(allocationRequest.period, allocationRequest.gracePeriod); @@ -342,7 +342,7 @@ describe('depositTo', function () { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const { firstActiveTrancheId } = await getTranches(allocationRequest.period, allocationRequest.gracePeriod); @@ -400,7 +400,7 @@ describe('depositTo', function () { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const { firstActiveTrancheId } = await getTranches(allocationRequest.period, allocationRequest.gracePeriod); diff --git a/test/unit/StakingPool/helpers.js b/test/unit/StakingPool/helpers.js index 0bb55c0d20..f0a1704a27 100644 --- a/test/unit/StakingPool/helpers.js +++ b/test/unit/StakingPool/helpers.js @@ -170,7 +170,7 @@ async function generateRewards( globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; await stakingPool.connect(signer).requestAllocation(amount, previousPremium, allocationRequest); } diff --git a/test/unit/StakingPool/requestAllocation.js b/test/unit/StakingPool/requestAllocation.js index e4a1a3e1ce..f919700ac7 100644 --- a/test/unit/StakingPool/requestAllocation.js +++ b/test/unit/StakingPool/requestAllocation.js @@ -55,7 +55,7 @@ const allocationRequestParams = { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const buyCoverParamsTemplate = { @@ -182,7 +182,7 @@ describe('requestAllocation', function () { globalCapacityRatio: GLOBAL_CAPACITY_RATIO, capacityReductionRatio: coverProductTemplate.capacityReductionRatio, rewardRatio: GLOBAL_REWARDS_RATIO, - globalMinPrice: DEFAULT_MIN_PRICE_RATIO, + defaultMinPrice: DEFAULT_MIN_PRICE_RATIO, }; await cover.requestAllocation(buyCoverParamsTemplate.amount, 0, request, stakingPool.address); diff --git a/test/unit/StakingPool/setPoolFee.js b/test/unit/StakingPool/setPoolFee.js index ab2e7b973a..0a1f9d7d2c 100644 --- a/test/unit/StakingPool/setPoolFee.js +++ b/test/unit/StakingPool/setPoolFee.js @@ -22,7 +22,7 @@ const allocationRequestTemplate = { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 5000, - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const product = { diff --git a/test/unit/StakingPool/withdraw.js b/test/unit/StakingPool/withdraw.js index d1a38d994e..6c1a738ced 100644 --- a/test/unit/StakingPool/withdraw.js +++ b/test/unit/StakingPool/withdraw.js @@ -490,7 +490,7 @@ describe('withdraw', function () { globalCapacityRatio: 20000, capacityReductionRatio: 0, rewardRatio: 10000, // 1:1 - globalMinPrice: 10000, + defaultMinPrice: 10000, }; const poolId = initializeParams.poolId; diff --git a/test/unit/StakingProducts/createStakingPool.js b/test/unit/StakingProducts/createStakingPool.js index 395f99a18c..32e94cba96 100644 --- a/test/unit/StakingProducts/createStakingPool.js +++ b/test/unit/StakingProducts/createStakingPool.js @@ -271,6 +271,6 @@ describe('createStakingPool', function () { products, ipfsDescriptionHash, ), - ).to.be.revertedWithCustomError(stakingProducts, 'TargetPriceBelowGlobalMinPriceRatio'); + ).to.be.revertedWithCustomError(stakingProducts, 'TargetPriceBelowDefaultMinPriceRatio'); }); }); diff --git a/test/unit/StakingProducts/helpers.js b/test/unit/StakingProducts/helpers.js index eda0f052ef..19b0beb4b1 100644 --- a/test/unit/StakingProducts/helpers.js +++ b/test/unit/StakingProducts/helpers.js @@ -120,7 +120,7 @@ async function allocateCapacity({ amount, productId }) { capacityReductionRatio: coverProductTemplate.capacityReductionRatio, useFixedPrice: coverProductTemplate.useFixedPrice, rewardRatio: GLOBAL_REWARDS_RATIO, - globalMinPrice: DEFAULT_MIN_PRICE_RATIO, + defaultMinPrice: DEFAULT_MIN_PRICE_RATIO, }; await stakingPool.connect(coverSigner).requestAllocation(amount, 0, allocationRequest); From c18c39f45b5df67f0560897152c7f12ccbdc23be Mon Sep 17 00:00:00 2001 From: DuXXuD Date: Tue, 3 Dec 2024 17:24:22 +0100 Subject: [PATCH 3/3] feat: add product min price checks --- contracts/interfaces/ICoverProducts.sol | 2 ++ contracts/interfaces/IStakingPool.sol | 2 +- contracts/interfaces/IStakingProducts.sol | 2 +- .../mocks/generic/CoverProductsGeneric.sol | 6 ++++ .../StakingPool/SKMockStakingProducts.sol | 4 +-- .../StakingProducts/SPMockCoverProducts.sol | 11 +++++++ contracts/modules/cover/Cover.sol | 6 +++- contracts/modules/cover/CoverProducts.sol | 33 +++++++++++++++++-- contracts/modules/staking/StakingPool.sol | 2 +- contracts/modules/staking/StakingProducts.sol | 13 ++++---- 10 files changed, 66 insertions(+), 15 deletions(-) diff --git a/contracts/interfaces/ICoverProducts.sol b/contracts/interfaces/ICoverProducts.sol index e281fa7b5c..50f75605c4 100644 --- a/contracts/interfaces/ICoverProducts.sol +++ b/contracts/interfaces/ICoverProducts.sol @@ -101,6 +101,8 @@ interface ICoverProducts { function getInitialPrices(uint[] calldata productIds) external view returns (uint[] memory); + function getMinPrices(uint[] calldata productIds) external view returns (uint[] memory); + function prepareStakingProductsParams( ProductInitializationParams[] calldata params ) external returns ( diff --git a/contracts/interfaces/IStakingPool.sol b/contracts/interfaces/IStakingPool.sol index 4ea6730f14..efd5c7d709 100644 --- a/contracts/interfaces/IStakingPool.sol +++ b/contracts/interfaces/IStakingPool.sol @@ -17,7 +17,7 @@ struct AllocationRequest { uint globalCapacityRatio; uint capacityReductionRatio; uint rewardRatio; - uint defaultMinPrice; + uint productMinPrice; } struct BurnStakeParams { diff --git a/contracts/interfaces/IStakingProducts.sol b/contracts/interfaces/IStakingProducts.sol index b621291304..27b4adef4a 100644 --- a/contracts/interfaces/IStakingProducts.sol +++ b/contracts/interfaces/IStakingProducts.sol @@ -58,7 +58,7 @@ interface IStakingProducts { uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint defaultMinPrice, + uint productMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNxm diff --git a/contracts/mocks/generic/CoverProductsGeneric.sol b/contracts/mocks/generic/CoverProductsGeneric.sol index 6d656a177d..f507e6c4bb 100644 --- a/contracts/mocks/generic/CoverProductsGeneric.sol +++ b/contracts/mocks/generic/CoverProductsGeneric.sol @@ -6,6 +6,8 @@ import "../../interfaces/ICoverProducts.sol"; contract CoverProductsGeneric is ICoverProducts { + uint public constant DEFAULT_MIN_PRICE_RATIO = 100; // 1% + /* ========== VIEWS ========== */ function getProductType(uint) external virtual view returns (ProductType memory) { @@ -85,6 +87,10 @@ contract CoverProductsGeneric is ICoverProducts { revert("Unsupported"); } + function getMinPrices(uint[] calldata) external view virtual returns (uint[] memory) { + revert("Unsupported"); + } + function prepareStakingProductsParams( ProductInitializationParams[] calldata ) external virtual pure returns ( diff --git a/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol b/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol index f181f26ca3..1aa6a51ff4 100644 --- a/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol +++ b/contracts/mocks/modules/StakingPool/SKMockStakingProducts.sol @@ -324,14 +324,14 @@ contract SKMockStakingProducts is StakingProductsGeneric, MasterAwareV2, Multica uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint defaultMinPrice, + uint productMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNXM ) public override returns (uint premium) { StakedProduct memory product = _products[poolId][productId]; - uint targetPrice = Math.max(product.targetPrice, defaultMinPrice); + uint targetPrice = Math.max(product.targetPrice, productMinPrice); if (useFixedPrice) { return calculateFixedPricePremium(period, coverAmount, targetPrice, nxmPerAllocationUnit, TARGET_PRICE_DENOMINATOR); diff --git a/contracts/mocks/modules/StakingProducts/SPMockCoverProducts.sol b/contracts/mocks/modules/StakingProducts/SPMockCoverProducts.sol index 048bae4b41..a9f52c78e1 100644 --- a/contracts/mocks/modules/StakingProducts/SPMockCoverProducts.sol +++ b/contracts/mocks/modules/StakingProducts/SPMockCoverProducts.sol @@ -93,4 +93,15 @@ contract SPMockCoverProducts is CoverProductsGeneric { reductionRatios[i] = _products[productIds[i]].capacityReductionRatio; } } + + function getMinPrices(uint[] calldata productIds) external override view returns (uint[] memory minPrices) { + minPrices = new uint[](productIds.length); + for (uint i = 0; i < productIds.length; i++) { + if (_products[productIds[i]].minPrice != 0) { + minPrices[i] = _products[productIds[i]].minPrice; + } else { + minPrices[i] = DEFAULT_MIN_PRICE_RATIO; + } + } + } } diff --git a/contracts/modules/cover/Cover.sol b/contracts/modules/cover/Cover.sol index 4860c01867..d3f2e44ff6 100644 --- a/contracts/modules/cover/Cover.sol +++ b/contracts/modules/cover/Cover.sol @@ -164,7 +164,11 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard, Mu allocationRequest.globalCapacityRatio = GLOBAL_CAPACITY_RATIO; allocationRequest.capacityReductionRatio = product.capacityReductionRatio; allocationRequest.rewardRatio = GLOBAL_REWARDS_RATIO; - allocationRequest.defaultMinPrice = DEFAULT_MIN_PRICE_RATIO; + if (product.minPrice != 0) { + allocationRequest.productMinPrice = product.minPrice; + } else { + allocationRequest.productMinPrice = DEFAULT_MIN_PRICE_RATIO; + } } uint previousSegmentAmount; diff --git a/contracts/modules/cover/CoverProducts.sol b/contracts/modules/cover/CoverProducts.sol index b0eeda8f76..0d27079713 100644 --- a/contracts/modules/cover/CoverProducts.sol +++ b/contracts/modules/cover/CoverProducts.sol @@ -132,6 +132,28 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall { } } + function getMinPrices( + uint[] calldata productIds + ) external view returns (uint[] memory minPrices) { + uint productCount = _products.length; + minPrices = new uint[](productIds.length); + uint defaultMinPrice = cover().getDefaultMinPriceRatio(); + + for (uint i = 0; i < productIds.length; i++) { + uint productId = productIds[i]; + + if (productId >= productCount) { + revert ProductNotFound(); + } + + if (_products[productId].minPrice == 0) { + minPrices[i] = defaultMinPrice; + } else { + minPrices[i] = _products[productId].minPrice; + } + } + } + function getCapacityReductionRatios( uint[] calldata productIds ) external view returns (uint[] memory capacityReductionRatios) { @@ -217,8 +239,15 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall { revert UnsupportedCoverAssets(); } - if (product.initialPriceRatio < defaultMinPriceRatio) { - revert InitialPriceRatioBelowDefaultMinPriceRatio(); + if (product.minPrice == 0) { + if (product.initialPriceRatio < defaultMinPriceRatio) { + revert InitialPriceRatioBelowDefaultMinPriceRatio(); + } + } else { + // TODO: define new error here? + if (product.initialPriceRatio < product.minPrice) { + revert InitialPriceRatioBelowDefaultMinPriceRatio(); + } } if (product.initialPriceRatio > PRICE_DENOMINATOR) { diff --git a/contracts/modules/staking/StakingPool.sol b/contracts/modules/staking/StakingPool.sol index f4e723e21b..94a8891f5f 100644 --- a/contracts/modules/staking/StakingPool.sol +++ b/contracts/modules/staking/StakingPool.sol @@ -615,7 +615,7 @@ contract StakingPool is IStakingPool, Multicall { coverAllocationAmount, initialCapacityUsed, totalCapacity, - request.defaultMinPrice, + request.productMinPrice, request.useFixedPrice, NXM_PER_ALLOCATION_UNIT, ALLOCATION_UNITS_PER_NXM diff --git a/contracts/modules/staking/StakingProducts.sol b/contracts/modules/staking/StakingProducts.sol index 0c06a9987c..05e3169948 100644 --- a/contracts/modules/staking/StakingProducts.sol +++ b/contracts/modules/staking/StakingProducts.sol @@ -190,13 +190,11 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { revert OnlyManager(); } - ( - uint globalCapacityRatio, - uint defaultMinPriceRatio - ) = ICover(coverContract).getGlobalCapacityAndPriceRatios(); + (uint globalCapacityRatio,) = ICover(coverContract).getGlobalCapacityAndPriceRatios(); uint[] memory initialPriceRatios; uint[] memory capacityReductionRatios; + uint[] memory minPriceRatios; { uint numProducts = params.length; @@ -213,6 +211,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { initialPriceRatios = _coverProducts.getInitialPrices(productIds); capacityReductionRatios = _coverProducts.getCapacityReductionRatios(productIds); + minPriceRatios = _coverProducts.getMinPrices(productIds); } Weights memory _weights = weights[poolId]; @@ -244,7 +243,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { revert TargetPriceTooHigh(); } - if (_param.targetPrice < defaultMinPriceRatio) { + if (_param.targetPrice < minPriceRatios[i]) { revert TargetPriceBelowMin(); } @@ -375,7 +374,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { uint coverAmount, uint initialCapacityUsed, uint totalCapacity, - uint defaultMinPrice, + uint productMinPrice, bool useFixedPrice, uint nxmPerAllocationUnit, uint allocationUnitsPerNXM @@ -386,7 +385,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall { } StakedProduct memory product = _products[poolId][productId]; - uint targetPrice = Math.max(product.targetPrice, defaultMinPrice); + uint targetPrice = Math.max(product.targetPrice, productMinPrice); if (useFixedPrice) { return calculateFixedPricePremium(coverAmount, period, targetPrice, nxmPerAllocationUnit, TARGET_PRICE_DENOMINATOR);