Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit fixes #86

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions abi/IEthFoxVault.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@
"name": "Redeemed",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "shares",
"type": "uint256"
}
],
"name": "UserEjected",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down
7 changes: 7 additions & 0 deletions contracts/interfaces/IEthFoxVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ interface IEthFoxVault is
IVaultBlocklist,
IMulticall
{
/**
* @notice Event emitted when a user is ejected from the Vault
* @param user The address of the user
* @param shares The amount of shares ejected
*/
event UserEjected(address user, uint256 shares);

/**
* @dev Struct for initializing the EthFoxVault contract
* @param admin The address of the Vault admin
Expand Down
1 change: 1 addition & 0 deletions contracts/vaults/ethereum/custom/EthFoxVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ contract EthFoxVault is
// redeem user shares
_redeem(user, userShares, user);
}
emit UserEjected(user, userShares);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export async function deployContract(
hre: HardhatRuntimeEnvironment,
contractName: string,
constructorArgs: any[],
path?: string
path?: string,
options?: any
): Promise<Contract> {
const contract = await hre.ethers.deployContract(contractName, constructorArgs)
const contract = await hre.ethers.deployContract(contractName, constructorArgs, options)
await contract.waitForDeployment()

const contractAddress = await contract.getAddress()
Expand Down
56 changes: 33 additions & 23 deletions tasks/eth-full-deploy-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,34 +211,44 @@ task('eth-full-deploy-local', 'deploys StakeWise V3 for Ethereum to local networ
const foxVaultFactory = await ethers.getContractFactory('EthFoxVault')
await simulateDeployImpl(hre, foxVaultFactory, { constructorArgs }, foxVaultImplAddress)

// Deploy EthFoxVault proxy
proxy = await deployContract(hre, 'ERC1967Proxy', [foxVaultImplAddress, '0x'])
const foxVaultAddress = await proxy.getAddress()
const foxVault = foxVaultFactory.attach(foxVaultAddress)
const foxVaultAddress = ethers.getCreateAddress({
from: deployer.address,
nonce: (await ethers.provider.getTransactionCount(deployer.address)) + 1,
})

// Initialize EthFoxVault
// Deploy ownMevEscrow for EthFoxVault
const ownMevEscrowFactory = await ethers.getContractFactory('OwnMevEscrow')
const ownMevEscrow = await ownMevEscrowFactory.deploy(foxVaultAddress)
await callContract(
foxVault.initialize(
ethers.AbiCoder.defaultAbiCoder().encode(
[
'tuple(address admin, address ownMevEscrow, uint256 capacity, uint16 feePercent, string metadataIpfsHash)',
],
[
[
networkConfig.foxVault.admin,
await ownMevEscrow.getAddress(),
networkConfig.foxVault.capacity,
networkConfig.foxVault.feePercent,
networkConfig.foxVault.metadataIpfsHash,
],
]
),
{ value: networkConfig.securityDeposit }
)

// Deploy EthFoxVault proxy
const initCall = ethers.AbiCoder.defaultAbiCoder().encode(
[
'tuple(address admin, address ownMevEscrow, uint256 capacity, uint16 feePercent, string metadataIpfsHash)',
],
[
[
networkConfig.foxVault.admin,
await ownMevEscrow.getAddress(),
networkConfig.foxVault.capacity,
networkConfig.foxVault.feePercent,
networkConfig.foxVault.metadataIpfsHash,
],
]
)

proxy = await deployContract(
hre,
'ERC1967Proxy',
[foxVaultImplAddress, foxVaultFactory.interface.encodeFunctionData('initialize', [initCall])],
undefined,
{
value: networkConfig.securityDeposit,
}
)
if ((await proxy.getAddress()) !== foxVaultAddress) {
throw new Error('EthFoxVault address mismatch')
}

await callContract(vaultsRegistry.addVault(foxVaultAddress))
console.log('Added EthFoxVault to VaultsRegistry')

Expand Down
62 changes: 34 additions & 28 deletions tasks/eth-full-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,39 +244,45 @@ task('eth-full-deploy', 'deploys StakeWise V3 for Ethereum').setAction(async (ta
const foxVaultFactory = await ethers.getContractFactory('EthFoxVault')
await simulateDeployImpl(hre, foxVaultFactory, { constructorArgs }, foxVaultImplAddress)

// Deploy EthFoxVault proxy
proxy = await deployContract(
hre,
'ERC1967Proxy',
[foxVaultImplAddress, '0x'],
'@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy'
)
const foxVaultAddress = await proxy.getAddress()
const foxVault = foxVaultFactory.attach(foxVaultAddress)
// calculate EthFoxVault address
const foxVaultAddress = ethers.getCreateAddress({
from: deployer.address,
nonce: (await ethers.provider.getTransactionCount(deployer.address)) + 1,
})

// Initialize EthFoxVault
// Deploy OwnMevEscrow for EthFoxVault
const ownMevEscrowFactory = await ethers.getContractFactory('OwnMevEscrow')
const ownMevEscrow = await ownMevEscrowFactory.deploy(foxVaultAddress)
await callContract(
foxVault.initialize(
ethers.AbiCoder.defaultAbiCoder().encode(
[
'tuple(address admin, address ownMevEscrow, uint256 capacity, uint16 feePercent, string metadataIpfsHash)',
],
[
[
networkConfig.foxVault.admin,
await ownMevEscrow.getAddress(),
networkConfig.foxVault.capacity,
networkConfig.foxVault.feePercent,
networkConfig.foxVault.metadataIpfsHash,
],
]
),
{ value: networkConfig.securityDeposit }
)

// Deploy and initialize EthFoxVault proxy
const initCall = ethers.AbiCoder.defaultAbiCoder().encode(
[
'tuple(address admin, address ownMevEscrow, uint256 capacity, uint16 feePercent, string metadataIpfsHash)',
],
[
[
networkConfig.foxVault.admin,
await ownMevEscrow.getAddress(),
networkConfig.foxVault.capacity,
networkConfig.foxVault.feePercent,
networkConfig.foxVault.metadataIpfsHash,
],
]
)

proxy = await deployContract(
hre,
'ERC1967Proxy',
[foxVaultImplAddress, foxVaultFactory.interface.encodeFunctionData('initialize', [initCall])],
'@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy',
{
value: networkConfig.securityDeposit,
}
)
if ((await proxy.getAddress()) !== foxVaultAddress) {
throw new Error('EthFoxVault address mismatch')
}

await callContract(vaultsRegistry.addVault(foxVaultAddress))
console.log('Added EthFoxVault to VaultsRegistry')

Expand Down
2 changes: 2 additions & 0 deletions test/EthFoxVault.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ describe('EthFoxVault', () => {
await expect(tx)
.to.emit(vault, 'Redeemed')
.withArgs(sender.address, sender.address, senderAssets, senderShares)
await expect(tx).to.emit(vault, 'UserEjected').withArgs(sender.address, senderShares)
expect(await vault.getShares(sender.address)).to.eq(0)
await snapshotGasCost(tx)
})
Expand All @@ -245,6 +246,7 @@ describe('EthFoxVault', () => {
await expect(tx)
.to.emit(vault, 'ExitQueueEntered')
.withArgs(sender.address, sender.address, positionTicket, senderShares)
await expect(tx).to.emit(vault, 'UserEjected').withArgs(sender.address, senderShares)
expect(await vault.getShares(sender.address)).to.eq(0)
await snapshotGasCost(tx)
})
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/EthFoxVault.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ Object {
exports[`EthFoxVault ejecting user blocklist manager can eject all of the user assets for collateralized vault 1`] = `
Object {
"calldataByteLength": 36,
"gasUsed": 112108,
"gasUsed": 113416,
}
`;

exports[`EthFoxVault ejecting user blocklist manager can eject all of the user assets for not collateralized vault 1`] = `
Object {
"calldataByteLength": 36,
"gasUsed": 83278,
"gasUsed": 84597,
}
`;

exports[`EthFoxVault ejecting user does not fail for user with no vault shares 1`] = `
Object {
"calldataByteLength": 36,
"gasUsed": 55808,
"gasUsed": 55813,
}
`;

Expand Down
Loading