Skip to content

Commit

Permalink
Review fixes 3
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeny-stakewise committed May 22, 2024
1 parent f8e866c commit df7128a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 69 deletions.
3 changes: 2 additions & 1 deletion contracts/interfaces/IValidatorsChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import {IERC5267} from '@openzeppelin/contracts/interfaces/IERC5267.sol';
/**
* @title IValidatorsChecker
* @author StakeWise
* @notice Defines the interface for EthValidatorsChecker
* @notice Defines the interface for ValidatorsChecker
*/
interface IValidatorsChecker is IERC5267 {
/**
* @notice Function for checking validators manager signature
* @param vault The address of the vault
* @param validatorsRegistryRoot The validators registry root
* @param publicKeys The concatenation of the validators' public keys
* @param signature The validators manager signature
* @return Current block number
*/
function checkValidatorsManagerSignature(
Expand Down
11 changes: 2 additions & 9 deletions contracts/validators/EthValidatorsChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
pragma solidity =0.8.22;

import {EIP712} from '@openzeppelin/contracts/utils/cryptography/EIP712.sol';

import {IValidatorsRegistry} from '../interfaces/IValidatorsRegistry.sol';
import {IKeeper} from '../interfaces/IKeeper.sol';
import {IDepositDataRegistry} from '../interfaces/IDepositDataRegistry.sol';
import {IVaultsRegistry} from '../interfaces/IVaultsRegistry.sol';

import {ValidatorsChecker} from './ValidatorsChecker.sol';

/**
Expand All @@ -17,11 +15,6 @@ import {ValidatorsChecker} from './ValidatorsChecker.sol';
* @notice Defines Ethereum-specific settings for ValidatorsChecker contract
*/
contract EthValidatorsChecker is ValidatorsChecker {
IValidatorsRegistry private immutable _validatorsRegistry;
IKeeper private immutable _keeper;
IVaultsRegistry private immutable _vaultsRegistry;
IDepositDataRegistry private immutable _depositDataRegistry;

/**
* @dev Constructor
* @param validatorsRegistry The address of the beacon chain validators registry contract
Expand All @@ -39,14 +32,14 @@ contract EthValidatorsChecker is ValidatorsChecker {
EIP712('EthValidatorsChecker', '1')
{}

function validatorsManagerSignatureTypeHash() public pure override returns (bytes32) {
function validatorsManagerSignatureTypeHash() internal pure override returns (bytes32) {
return
keccak256(
'EthValidatorsChecker(bytes32 validatorsRegistryRoot,address vault,bytes validators)'
);
}

function depositAmount() public pure override returns (uint256) {
function depositAmount() internal pure override returns (uint256) {
return 32 ether;
}
}
11 changes: 2 additions & 9 deletions contracts/validators/GnoValidatorsChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
pragma solidity =0.8.22;

import {EIP712} from '@openzeppelin/contracts/utils/cryptography/EIP712.sol';

import {IValidatorsRegistry} from '../interfaces/IValidatorsRegistry.sol';
import {IKeeper} from '../interfaces/IKeeper.sol';
import {IDepositDataRegistry} from '../interfaces/IDepositDataRegistry.sol';
import {IVaultsRegistry} from '../interfaces/IVaultsRegistry.sol';

import {ValidatorsChecker} from './ValidatorsChecker.sol';

/**
Expand All @@ -17,11 +15,6 @@ import {ValidatorsChecker} from './ValidatorsChecker.sol';
* @notice Defines Gnosis-specific settings for ValidatorsChecker contract
*/
contract GnoValidatorsChecker is ValidatorsChecker {
IValidatorsRegistry private immutable _validatorsRegistry;
IKeeper private immutable _keeper;
IVaultsRegistry private immutable _vaultsRegistry;
IDepositDataRegistry private immutable _depositDataRegistry;

/**
* @dev Constructor
* @param validatorsRegistry The address of the beacon chain validators registry contract
Expand All @@ -39,14 +32,14 @@ contract GnoValidatorsChecker is ValidatorsChecker {
EIP712('GnoValidatorsChecker', '1')
{}

function validatorsManagerSignatureTypeHash() public pure override returns (bytes32) {
function validatorsManagerSignatureTypeHash() internal pure override returns (bytes32) {
return
keccak256(
'GnoValidatorsChecker(bytes32 validatorsRegistryRoot,address vault,bytes validators)'
);
}

function depositAmount() public pure override returns (uint256) {
function depositAmount() internal pure override returns (uint256) {
return 1 ether;
}
}
4 changes: 2 additions & 2 deletions contracts/validators/ValidatorsChecker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ abstract contract ValidatorsChecker is IValidatorsChecker, EIP712 {
return block.number;
}

function validatorsManagerSignatureTypeHash() public pure virtual returns (bytes32);
function validatorsManagerSignatureTypeHash() internal pure virtual returns (bytes32);

function depositAmount() public pure virtual returns (uint256);
function depositAmount() internal pure virtual returns (uint256);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ import {
import { MAX_UINT256, ZERO_ADDRESS } from './shared/constants'
import { getEthVaultV1Factory } from './shared/contracts'
import { expect } from './shared/expect'
import { deployEthVaultV1, encodeEthVaultInitParams, ethVaultFixture } from './shared/fixtures'
import {
createEthValidatorsChecker,
deployEthVaultV1,
encodeEthVaultInitParams,
ethVaultFixture,
} from './shared/fixtures'
import {
EthValidatorsData,
createEthValidatorsData,
createValidatorPublicKeys,
getValidatorsCheckerSigningData,
getValidatorsMultiProof,
} from './shared/validators'
import { createGnoValidatorsChecker } from './shared/gnoFixtures'

const networks = ['ETHEREUM', 'GNOSIS']

networks.forEach((network) => {
describe(`EthValidatorsChecker [${network}]`, () => {
describe(`ValidatorsChecker [${network}]`, () => {
let validatorDeposit = ethers.parseEther('32')
if (network == 'GNOSIS') {
validatorDeposit = ethers.parseEther('1')
Expand Down Expand Up @@ -57,17 +63,28 @@ networks.forEach((network) => {
validatorsRegistry = fixture.validatorsRegistry
keeper = fixture.keeper
depositDataRegistry = fixture.depositDataRegistry
vaultsRegistry = fixture.vaultsRegistry

validatorsCheckerTypeName = 'EthValidatorsChecker'
validatorsChecker = fixture.ethValidatorsChecker

if (network == 'GNOSIS') {
if (network == 'ETHEREUM') {
validatorsCheckerTypeName = 'EthValidatorsChecker'
validatorsChecker = await createEthValidatorsChecker(
validatorsRegistry,
keeper,
vaultsRegistry,
depositDataRegistry
)
} else if (network == 'GNOSIS') {
validatorsCheckerTypeName = 'GnoValidatorsChecker'
validatorsChecker = fixture.gnoValidatorsChecker
validatorsChecker = await createGnoValidatorsChecker(
validatorsRegistry,
keeper,
vaultsRegistry,
depositDataRegistry
)
} else {
throw Error('unknown network')
}

vaultsRegistry = fixture.vaultsRegistry

vault = await fixture.createEthVault(admin, {
capacity,
feePercent,
Expand Down
40 changes: 1 addition & 39 deletions test/shared/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ import {
VaultsRegistry__factory,
DepositDataRegistry,
DepositDataRegistry__factory,
EthValidatorsChecker,
EthValidatorsChecker__factory,
GnoValidatorsChecker,
GnoValidatorsChecker__factory,
} from '../../typechain-types'
import { getEthValidatorsRegistryFactory, getOsTokenConfigV1Factory } from './contracts'
import {
Expand Down Expand Up @@ -278,23 +275,6 @@ export const createEthValidatorsChecker = async function (
return EthValidatorsChecker__factory.connect(await contract.getAddress(), signer)
}

export const createGnoValidatorsChecker = async function (
validatorsRegistry: Contract,
keeper: Keeper,
vaultsRegistry: VaultsRegistry,
depositDataRegistry: DepositDataRegistry
) {
const signer = await ethers.provider.getSigner()
const factory = await ethers.getContractFactory('GnoValidatorsChecker')
const contract = await factory.deploy(
await validatorsRegistry.getAddress(),
await keeper.getAddress(),
await vaultsRegistry.getAddress(),
await depositDataRegistry.getAddress()
)
return GnoValidatorsChecker__factory.connect(await contract.getAddress(), signer)
}

export const createOsTokenVaultController = async function (
keeperAddress: string,
registry: VaultsRegistry,
Expand Down Expand Up @@ -622,8 +602,6 @@ interface EthVaultFixture {
osToken: OsToken
osTokenVaultController: OsTokenVaultController
osTokenConfig: OsTokenConfig
ethValidatorsChecker: EthValidatorsChecker
gnoValidatorsChecker: GnoValidatorsChecker

createEthVault(
admin: Signer,
Expand Down Expand Up @@ -750,21 +728,7 @@ export const ethVaultFixture = async function (): Promise<EthVaultFixture> {
// 7. deploy depositDataRegistry
const depositDataRegistry = await createDepositDataRegistry(vaultsRegistry)

// 8. deploy ValidatorsCheckers for Ethereum and Gnosis
const ethValidatorsChecker = await createEthValidatorsChecker(
validatorsRegistry,
keeper,
vaultsRegistry,
depositDataRegistry
)
const gnoValidatorsChecker = await createGnoValidatorsChecker(
validatorsRegistry,
keeper,
vaultsRegistry,
depositDataRegistry
)

// 9. deploy implementations and factories
// 8. deploy implementations and factories
const factories = {}
const implementations = {}

Expand Down Expand Up @@ -822,8 +786,6 @@ export const ethVaultFixture = async function (): Promise<EthVaultFixture> {
osTokenVaultController,
osTokenConfig,
osToken,
ethValidatorsChecker,
gnoValidatorsChecker,
createEthVault: async (
admin: Signer,
vaultParams: EthVaultInitParamsStruct,
Expand Down
18 changes: 18 additions & 0 deletions test/shared/gnoFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
XdaiExchange__factory,
PriceFeedMock,
PriceFeedMock__factory,
GnoValidatorsChecker__factory,
} from '../../typechain-types'
import { getGnoValidatorsRegistryFactory } from './contracts'
import {
Expand Down Expand Up @@ -706,3 +707,20 @@ export const gnoVaultFixture = async function (): Promise<GnoVaultFixture> {
},
}
}

export const createGnoValidatorsChecker = async function (
validatorsRegistry: Contract,
keeper: Keeper,
vaultsRegistry: VaultsRegistry,
depositDataRegistry: DepositDataRegistry
) {
const signer = await ethers.provider.getSigner()
const factory = await ethers.getContractFactory('GnoValidatorsChecker')
const contract = await factory.deploy(
await validatorsRegistry.getAddress(),
await keeper.getAddress(),
await vaultsRegistry.getAddress(),
await depositDataRegistry.getAddress()
)
return GnoValidatorsChecker__factory.connect(await contract.getAddress(), signer)
}

0 comments on commit df7128a

Please sign in to comment.