Skip to content

Commit

Permalink
Merge pull request #237 from NexusMutual/fix/beacon-proxies
Browse files Browse the repository at this point in the history
Fix proxy code hash used in staking pools addresses
  • Loading branch information
danoctavian committed Jun 14, 2022
2 parents 7c576dc + 1ccbf2d commit 855d917
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
5 changes: 3 additions & 2 deletions contracts/modules/cover/Cover.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,16 @@ contract Cover is ICover, MasterAwareV2, IStakingPoolBeacon, ReentrancyGuard {
IQuotationData _quotationData,
IProductsV1 _productsV1,
address _coverNFT,
address _stakingPoolImplementation
address _stakingPoolImplementation,
address coverProxyAddress
) {

// initialize immutable fields only
quotationData = _quotationData;
productsV1 = _productsV1;
coverNFT = _coverNFT;

stakingPoolProxyCodeHash = CoverUtilsLib.calculateProxyCodeHash();
stakingPoolProxyCodeHash = CoverUtilsLib.calculateProxyCodeHash(coverProxyAddress);
stakingPoolImplementation = _stakingPoolImplementation;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/modules/cover/CoverUtilsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ library CoverUtilsLib {
params.coverNFT.safeMint(params.toNewOwner, newCoverId);
}

function calculateProxyCodeHash() external view returns (bytes32) {
function calculateProxyCodeHash(address coverProxyAddress) external view returns (bytes32) {
return keccak256(
abi.encodePacked(
type(MinimalBeaconProxy).creationCode,
abi.encode(address(this))
abi.encode(coverProxyAddress)
));
}

Expand Down
9 changes: 4 additions & 5 deletions test/integration/setup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { accounts, artifacts, web3, ethers } = require('hardhat');
const { ether } = require('@openzeppelin/test-helpers');
const { parseEther } = ethers.utils;
const { setupUniswap } = require('../utils');
const { ContractTypes } = require('../utils').constants;
const { hex } = require('../utils').helpers;
const { proposalCategories } = require('../utils');
Expand All @@ -28,7 +27,6 @@ const web3ToEthers = (x, signers) => {
};

async function setup () {

// external
const ERC20BlacklistableMock = artifacts.require('ERC20BlacklistableMock');
const OwnedUpgradeabilityProxy = artifacts.require('OwnedUpgradeabilityProxy');
Expand Down Expand Up @@ -118,7 +116,7 @@ async function setup () {

const chainlinkDAI = await ChainlinkAggregatorMock.new();
const chainlinkSteth = await ChainlinkAggregatorMock.new();
await chainlinkSteth.setLatestAnswer(new BN(1e18.toString()));
await chainlinkSteth.setLatestAnswer(new BN((1e18).toString()));
const priceFeedOracle = await PriceFeedOracle.new(
[dai.address, stETH.address],
[chainlinkDAI.address, chainlinkSteth.address],
Expand Down Expand Up @@ -153,7 +151,7 @@ async function setup () {
cowSettlement.address,
owner, // _swapController,
master.address,
weth.address
weth.address,
);

const productsV1 = await ProductsV1.new();
Expand Down Expand Up @@ -328,7 +326,8 @@ async function setup () {
qd.address,
productsV1.address,
stakingPool.address,
coverNFT.address
coverNFT.address,
cover.address,
]);
//
// {
Expand Down
46 changes: 26 additions & 20 deletions test/unit/Cover/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ async function setup () {
const CoverUtilsLib = await ethers.getContractFactory('CoverUtilsLib');
const ERC20CustomDecimalsMock = await ethers.getContractFactory('ERC20CustomDecimalsMock');


const coverUtilsLib = await CoverUtilsLib.deploy();

const Cover = await ethers.getContractFactory('Cover', {
libraries: {
CoverUtilsLib: coverUtilsLib.address
}
CoverUtilsLib: coverUtilsLib.address,
},
});

const [owner] = await ethers.getSigners();
Expand Down Expand Up @@ -90,7 +89,8 @@ async function setup () {
quotationData.address,
ethers.constants.AddressZero,
futureCoverNFTAddress,
stakingPool.address
stakingPool.address,
coverAddress,
);
await cover.deployed();

Expand Down Expand Up @@ -169,23 +169,29 @@ async function setup () {
}

// add products
await cover.connect(accounts.advisoryBoardMembers[0]).addProducts([
{
productType: '0',
productAddress: '0x0000000000000000000000000000000000000000',
coverAssets: parseInt('111', 2), // ETH DAI and USDC supported
initialPriceRatio: '1000', // 10%
capacityReductionRatio: '0',
},
], ['']);
await cover.connect(accounts.advisoryBoardMembers[0]).addProducts(
[
{
productType: '0',
productAddress: '0x0000000000000000000000000000000000000000',
coverAssets: parseInt('111', 2), // ETH DAI and USDC supported
initialPriceRatio: '1000', // 10%
capacityReductionRatio: '0',
},
],
[''],
);

await cover.connect(accounts.advisoryBoardMembers[0]).addProductTypes([
{
descriptionIpfsHash: 'my ipfs hash',
claimMethod: '1',
gracePeriodInDays: '120',
},
], ['']);
await cover.connect(accounts.advisoryBoardMembers[0]).addProductTypes(
[
{
descriptionIpfsHash: 'my ipfs hash',
claimMethod: '1',
gracePeriodInDays: '120',
},
],
[''],
);

const capacityFactor = '10000';

Expand Down

0 comments on commit 855d917

Please sign in to comment.