Skip to content

Commit

Permalink
remove duplicate GLOBAL_MIN_PRICE_RATIO
Browse files Browse the repository at this point in the history
  • Loading branch information
danoctavian committed Aug 27, 2023
1 parent 8c06048 commit bc7d420
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 10 deletions.
2 changes: 2 additions & 0 deletions contracts/interfaces/ICover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ interface ICover {
uint[] memory _capacityReductionRatios
);

function GLOBAL_MIN_PRICE_RATIO() external view returns (uint);

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

function addLegacyCover(
Expand Down
97 changes: 97 additions & 0 deletions contracts/mocks/CoverProducts/CoverProductsMockCover.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity ^0.8.18;

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

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

function coverData(uint /* coverId */) external pure returns (CoverData memory) {
revert("Unsupported");
}

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

function coverSegmentsCount(uint /* coverId */ ) external pure returns (uint) {
revert("Unsupported");
}

function coverSegments(uint /* coverId */ ) external pure returns (CoverSegment[] memory) {
revert("Unsupported");
}

function coverSegmentWithRemainingAmount(
uint /* coverId */,
uint /* segmentId */
) external pure returns (CoverSegment memory) {
revert("Unsupported");
}

function totalActiveCoverInAsset(uint /* coverAsset */) external pure returns (uint) {
revert("Unsupported");
}

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

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

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

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

function addLegacyCover(
uint /* productId */,
uint /* coverAsset */,
uint /* amount */,
uint /* start */,
uint /* period */,
address /* newOwner */
) external pure returns (uint /* coverId */) {
revert("Unsupported");
}

function buyCover(
BuyCoverParams calldata /* params */,
PoolAllocationRequest[] calldata /* coverChunkRequests */
) external payable returns (uint /* coverId */ ) {
revert("Unsupported");
}

function burnStake(
uint /* coverId */,
uint /* segmentId */,
uint /* amount */
) external pure returns (address /* coverOwner */) {
revert("Unsupported");
}

function coverNFT() external pure returns (ICoverNFT) {
revert("Unsupported");
}

function stakingNFT() external pure returns (IStakingNFT) {
revert("Unsupported");
}

function stakingPoolFactory() external pure returns (IStakingPoolFactory) {
revert("Unsupported");
}
}
10 changes: 6 additions & 4 deletions contracts/modules/cover/CoverProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall {

/* ========== CONSTANTS ========== */

uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1%

uint private constant PRICE_DENOMINATOR = 10000;

uint private constant CAPACITY_REDUCTION_DENOMINATOR = 10000;
Expand Down Expand Up @@ -126,7 +124,7 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall {
revert UnsupportedCoverAssets();
}

if (product.initialPriceRatio < GLOBAL_MIN_PRICE_RATIO) {
if (product.initialPriceRatio < cover().GLOBAL_MIN_PRICE_RATIO()) {
revert InitialPriceRatioBelowGlobalMinPriceRatio();
}

Expand Down Expand Up @@ -238,9 +236,13 @@ contract CoverProducts is ICoverProducts, MasterAwareV2, Multicall {
return IPool(internalContracts[uint(ID.P1)]);
}

function cover() internal view returns (ICover) {
return ICover(internalContracts[uint(ID.CO)]);
}

function changeDependentContractAddress() public {
internalContracts[uint(ID.P1)] = master.getLatestAddress("P1");
internalContracts[uint(ID.TC)] = master.getLatestAddress("TC");
internalContracts[uint(ID.CO)] = master.getLatestAddress("CO");
internalContracts[uint(ID.MR)] = master.getLatestAddress("MR");
internalContracts[uint(ID.SP)] = master.getLatestAddress("SP");
internalContracts[uint(ID.CP)] = master.getLatestAddress("CP");
Expand Down
4 changes: 1 addition & 3 deletions contracts/modules/staking/StakingProducts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall {
uint public constant ALLOCATION_UNITS_PER_NXM = 100;
uint public constant NXM_PER_ALLOCATION_UNIT = ONE_NXM / ALLOCATION_UNITS_PER_NXM;

uint public constant GLOBAL_MIN_PRICE_RATIO = 100; // 1%

// pool id => product id => Product
mapping(uint => mapping(uint => StakedProduct)) private _products;
// pool id => { totalEffectiveWeight, totalTargetWeight }
Expand Down Expand Up @@ -624,7 +622,7 @@ contract StakingProducts is IStakingProducts, MasterAwareV2, Multicall {
// 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 < ICover(coverContract).GLOBAL_MIN_PRICE_RATIO()) {
revert TargetPriceBelowGlobalMinPriceRatio();
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/utils/staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function stakeOnly({ stakingPool, staker, period, gracePeriod, trancheIdOf
);
}

async function stake({ stakingPool, staker, productId, period, gracePeriod, amount = 0, trancheIncrement = 0 }) {
async function stake({ stakingPool, staker, productId, period, gracePeriod, amount = 0 }) {
// Staking inputs
const stakingAmount = amount !== 0 ? BigNumber.from(amount) : parseEther('10000');
const lastBlock = await ethers.provider.getBlock('latest');
Expand All @@ -31,7 +31,7 @@ async function stake({ stakingPool, staker, productId, period, gracePeriod, amou
// Stake to open up capacity
await stakingPool.connect(staker).depositTo(
stakingAmount,
firstTrancheId + trancheIncrement,
firstTrancheId,
0, // new position
AddressZero, // destination
);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/CoverProducts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async function setup() {
await mcr.setMCR(parseEther('600000'));

const coverProducts = await ethers.deployContract('CoverProducts');
const cover = await ethers.deployContract('CoverProductsMockCover');

const stakingProducts = await ethers.deployContract('CoverMockStakingProducts', [
AddressZero,
Expand Down Expand Up @@ -56,6 +57,7 @@ async function setup() {
await master.setLatestAddress(hex('TC'), tokenController.address);
await master.setLatestAddress(hex('MC'), mcr.address);
await master.setLatestAddress(hex('SP'), stakingProducts.address);
await master.setLatestAddress(hex('CO'), cover.address);

const pooledStakingSigner = accounts.members[4];
await master.setLatestAddress(hex('PS'), pooledStakingSigner.address);
Expand Down Expand Up @@ -163,7 +165,7 @@ async function setup() {
},
]);

const GLOBAL_MIN_PRICE_RATIO = await coverProducts.GLOBAL_MIN_PRICE_RATIO();
const GLOBAL_MIN_PRICE_RATIO = await cover.GLOBAL_MIN_PRICE_RATIO();
const BUCKET_SIZE = BigNumber.from(7 * 24 * 3600); // 7 days
const capacityFactor = '20000';

Expand Down

0 comments on commit bc7d420

Please sign in to comment.