From 1253529dfc9827aceb1118f9313fc0b5bb0000e5 Mon Sep 17 00:00:00 2001 From: teddy-nodeset <155682239+teddy-nodeset@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:50:27 -0700 Subject: [PATCH] Devops/deployment scripts (#164) * safety redundancy * llint * Update RPLVault.sol * typo * deployment scripts * add more impl * fix tests --- contracts/FundRouter.sol | 4 +- contracts/Testing/Mocks/MockNodeAccountV2.sol | 13 ++ contracts/Tokens/RPLVault.sol | 3 +- gas-report.txt | 38 ++-- scripts/dev_setup.ts | 43 +---- scripts/utils/deployment.ts | 180 ++++++++++++++++++ test/test-validator-account.ts | 36 +++- test/test.ts | 57 ++---- test/utils/utils.ts | 2 +- 9 files changed, 268 insertions(+), 108 deletions(-) create mode 100644 contracts/Testing/Mocks/MockNodeAccountV2.sol create mode 100644 scripts/utils/deployment.ts diff --git a/contracts/FundRouter.sol b/contracts/FundRouter.sol index 60de2a71..e3c65ee4 100644 --- a/contracts/FundRouter.sol +++ b/contracts/FundRouter.sol @@ -91,7 +91,7 @@ contract FundRouter is UpgradeableBase { ); } - function sendEthToDistributors() public { + function sendEthToDistributors() public nonReentrant { console.log('sendEthToDistributors.A'); // Convert entire WETH balance of this contract to ETH IWETH WETH = IWETH(_directory.getWETHAddress()); @@ -140,7 +140,7 @@ contract FundRouter is UpgradeableBase { console.log('sendEthToDistributors.I'); } - function sendRplToDistributors() public { + function sendRplToDistributors() public nonReentrant { console.log('sendRplToDistributors.A'); // Initialize the RPLVault and the Operator Distributor addresses diff --git a/contracts/Testing/Mocks/MockNodeAccountV2.sol b/contracts/Testing/Mocks/MockNodeAccountV2.sol new file mode 100644 index 00000000..3547720e --- /dev/null +++ b/contracts/Testing/Mocks/MockNodeAccountV2.sol @@ -0,0 +1,13 @@ +// SPDX License Identifier: GPL v3 + +pragma solidity 0.8.17; + +import '../../Operator/NodeAccount.sol'; + +contract MockNodeAccountV2 is NodeAccount { + + function test() public pure returns(uint256) { + return 69; + } + +} \ No newline at end of file diff --git a/contracts/Tokens/RPLVault.sol b/contracts/Tokens/RPLVault.sol index 4e566009..23d7280c 100644 --- a/contracts/Tokens/RPLVault.sol +++ b/contracts/Tokens/RPLVault.sol @@ -61,8 +61,9 @@ contract RPLVault is UpgradeableBase, ERC4626Upgradeable { * @param caller The address initiating the deposit. * @param receiver The address designated to receive the issued shares for the deposit. * @param assets The amount of assets being deposited. - * @param shares The number of shares to be minted in exchange for the deposit. + * @param shares The number of shares to be exchanged for the deposit. */ function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual override { + require(caller == receiver, "caller must be receiver"); if (_directory.isSanctioned(caller, receiver)) { return; } diff --git a/gas-report.txt b/gas-report.txt index 6f29c034..a9f309d2 100644 --- a/gas-report.txt +++ b/gas-report.txt @@ -5,9 +5,9 @@ ·····························|·························|·············|·············|·············|···············|·············· | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ·····························|·························|·············|·············|·············|···············|·············· -| AdminTreasury · claimToken · - · - · 91115 · 1 · - │ +| AdminTreasury · claimToken · - · - · 91127 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| AdminTreasury · upgradeTo · 49671 · 49776 · 49741 · 3 · - │ +| AdminTreasury · upgradeTo · 49671 · 64429 · 55616 · 5 · - │ ·····························|·························|·············|·············|·············|···············|·············· | Directory · enableSanctions · - · - · 30872 · 2 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -15,7 +15,7 @@ ·····························|·························|·············|·············|·············|···············|·············· | Directory · setTreasury · - · - · 34226 · 2 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| ERC20Upgradeable · approve · - · - · 51263 · 1 · - │ +| ERC20Upgradeable · approve · - · - · 51251 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· | MockERC20 · transfer · 46638 · 51438 · 49038 · 2 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -25,9 +25,11 @@ ·····························|·························|·············|·············|·············|···············|·············· | MockSanctions · addBlacklist · - · - · 43876 · 3 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| NodeAccount · stake · 230278 · 247378 · 237118 · 10 · - │ +| NodeAccount · stake · 230278 · 247378 · 237403 · 12 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| NodeAccountFactory · createNewNodeAccount · 3161886 · 3428916 · 3299958 · 13 · - │ +| NodeAccountFactory · createNewNodeAccount · 3164628 · 3431658 · 3301272 · 15 · - │ +·····························|·························|·············|·············|·············|···············|·············· +| NodeAccountFactory · setImplementation · - · - · 44495 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· | OperatorDistributor · processNextMinipool · 144624 · 336848 · 259937 · 5 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -37,9 +39,9 @@ ·····························|·························|·············|·············|·············|···············|·············· | RocketDAOProtocol · bootstrapSettingUint · - · - · 86433 · 2 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RocketDepositPool · assignDeposits · - · - · 116147 · 10 · - │ +| RocketDepositPool · assignDeposits · - · - · 116147 · 12 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RocketDepositPool · deposit · 324960 · 376260 · 345480 · 10 · - │ +| RocketDepositPool · deposit · 324960 · 376260 · 346335 · 12 · - │ ·····························|·························|·············|·············|·············|···············|·············· | RocketStorage · setAddress · 51027 · 51051 · 51048 · 50 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -51,9 +53,9 @@ ·····························|·························|·············|·············|·············|···············|·············· | RocketStorage · setUint · - · - · 50825 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RocketTokenRPL · approve · - · - · 46159 · 6 · - │ +| RocketTokenRPL · approve · - · - · 46147 · 6 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RocketTokenRPL · transfer · 34516 · 51628 · 45398 · 29 · - │ +| RocketTokenRPL · transfer · 34516 · 51628 · 44913 · 32 · - │ ·····························|·························|·············|·············|·············|···············|·············· | RocketUpgradeOneDotThree · execute · - · - · 14994030 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -61,9 +63,9 @@ ·····························|·························|·············|·············|·············|···············|·············· | RPLVault · claimAdminFee · 116110 · 124510 · 118910 · 6 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RPLVault · deposit · 118264 · 580845 · 284946 · 15 · - │ +| RPLVault · deposit · 118323 · 583216 · 294356 · 15 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| RPLVault · redeem · 232785 · 411538 · 311148 · 6 · - │ +| RPLVault · redeem · 235156 · 413909 · 313519 · 6 · - │ ·····························|·························|·············|·············|·············|···············|·············· | WETH · approve · 46261 · 46273 · 46268 · 5 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -71,7 +73,7 @@ ·····························|·························|·············|·············|·············|···············|·············· | WETHVault · setRplCoverageRatio · - · - · 44251 · 1 · - │ ·····························|·························|·············|·············|·············|···············|·············· -| WhitelistV2 · addOperator · 367807 · 596461 · 460987 · 27 · - │ +| WhitelistV2 · addOperator · 367807 · 596461 · 469363 · 29 · - │ ·····························|·························|·············|·············|·············|···············|·············· | WhitelistV2 · addOperators · - · - · 675408 · 4 · - │ ·····························|·························|·············|·············|·············|···············|·············· @@ -95,10 +97,12 @@ ·······················································|·············|·············|·············|···············|·············· | Directory · - · - · 3082153 · 10.3 % · - │ ·······················································|·············|·············|·············|···············|·············· -| FundRouter · - · - · 2386611 · 8 % · - │ +| FundRouter · - · - · 2412806 · 8 % · - │ ·······················································|·············|·············|·············|···············|·············· | MockERC20 · - · - · 868977 · 2.9 % · - │ ·······················································|·············|·············|·············|···············|·············· +| MockNodeAccountV2 · - · - · 4207997 · 14 % · - │ +·······················································|·············|·············|·············|···············|·············· | MockPriceFetcher · - · - · 836728 · 2.8 % · - │ ·······················································|·············|·············|·············|···············|·············· | MockRETHOracle · - · - · 92827 · 0.3 % · - │ @@ -107,9 +111,9 @@ ·······················································|·············|·············|·············|···············|·············· | MockUniswapV3Pool · - · - · 131311 · 0.4 % · - │ ·······················································|·············|·············|·············|···············|·············· -| NodeAccount · - · - · 4191022 · 14 % · - │ +| NodeAccount · - · - · 4197932 · 14 % · - │ ·······················································|·············|·············|·············|···············|·············· -| NodeAccountFactory · - · - · 2299120 · 7.7 % · - │ +| NodeAccountFactory · - · - · 2299132 · 7.7 % · - │ ·······················································|·············|·············|·············|···············|·············· | OperatorDistributor · - · - · 4038989 · 13.5 % · - │ ·······················································|·············|·············|·············|···············|·············· @@ -265,13 +269,13 @@ ·······················································|·············|·············|·············|···············|·············· | RocketVault · - · - · 1693348 · 5.6 % · - │ ·······················································|·············|·············|·············|···············|·············· -| RPLVault · - · - · 3277868 · 10.9 % · - │ +| RPLVault · - · - · 3298753 · 11 % · - │ ·······················································|·············|·············|·············|···············|·············· | WETH · - · - · 756259 · 2.5 % · - │ ·······················································|·············|·············|·············|···············|·············· | WETHVault · - · - · 4383653 · 14.6 % · - │ ·······················································|·············|·············|·············|···············|·············· -| Whitelist · - · - · 2323076 · 7.7 % · - │ +| Whitelist · - · - · 2323088 · 7.7 % · - │ ·······················································|·············|·············|·············|···············|·············· | WhitelistV2 · - · - · 2329709 · 7.8 % · - │ ·······················································|·············|·············|·············|···············|·············· diff --git a/scripts/dev_setup.ts b/scripts/dev_setup.ts index 64dae9f8..36ac6777 100644 --- a/scripts/dev_setup.ts +++ b/scripts/dev_setup.ts @@ -6,54 +6,13 @@ import { getNextContractAddress } from "../test/utils/utils"; import { IXRETHOracle, NodeAccountFactory } from "../typechain-types"; import { expect } from "chai"; import readline from 'readline'; +import { generateBytes32Identifier, retryOperation } from "./utils/deployment"; -// Function to prompt user for input -function askQuestion(query: string): Promise { - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - return new Promise(resolve => rl.question(query, ans => { - rl.close(); - resolve(ans); - })); -} - -// Updated retry operation function -async function retryOperation(operation: () => Promise, retries: number = 3, extendedRetries: number = 3) { - try { - return await operation(); - } catch (error) { - console.log(error); - - if (retries > 0) { - console.log(`Retrying operation, attempts remaining: ${retries}...`); - return await retryOperation(operation, retries - 1, extendedRetries); - } else if (extendedRetries > 0) { - const answer = await askQuestion('Operation failed. Do you want to retry? (y/n): '); - if (answer.toLowerCase() === 'y') { - console.log(`Extended retry, attempts remaining: ${extendedRetries}...`); - return await retryOperation(operation, 0, extendedRetries - 1); - } else { - throw new Error('Operation aborted by the user.'); - } - } else { - throw error; - } - } -} async function main() { const predictedNonce = 12; const [deployer, admin] = await ethers.getSigners(); - // Function to generate bytes32 representation for contract identifiers - const generateBytes32Identifier = (identifier: string) => { - // Correctly concatenate 'contract.address' with the identifier before hashing - return ethers.utils.solidityKeccak256(["string"], [`contract.address${identifier}`]); - }; - // Contract identifiers const contractIdentifiers = { diff --git a/scripts/utils/deployment.ts b/scripts/utils/deployment.ts new file mode 100644 index 00000000..49e3077b --- /dev/null +++ b/scripts/utils/deployment.ts @@ -0,0 +1,180 @@ +import { ethers, upgrades } from "hardhat"; +import fs from 'fs'; +import path from 'path'; +import { FunctionFragment } from 'ethers/lib/utils'; +import { getNextContractAddress } from "../../test/utils/utils"; +import { getInitializerData } from "@openzeppelin/hardhat-upgrades/dist/utils"; +import readline from 'readline'; +import { AdminTreasury, Directory, FundRouter, NodeAccountFactory, OperatorDistributor, PriceFetcher, RPLVault, WETHVault, Whitelist, YieldDistributor } from "../../typechain-types"; +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; + +// Function to prompt user for input +function askQuestion(query: string): Promise { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return new Promise(resolve => rl.question(query, ans => { + rl.close(); + resolve(ans); + })); +} + +// Updated retry operation function +export async function retryOperation(operation: () => Promise, retries: number = 3, extendedRetries: number = 3) { + try { + return await operation(); + } catch (error) { + console.log(error); + + if (retries > 0) { + console.log(`Retrying operation, attempts remaining: ${retries}...`); + return await retryOperation(operation, retries - 1, extendedRetries); + } else if (extendedRetries > 0) { + const answer = await askQuestion('Operation failed. Do you want to retry? (y/n): '); + if (answer.toLowerCase() === 'y') { + console.log(`Extended retry, attempts remaining: ${extendedRetries}...`); + return await retryOperation(operation, 0, extendedRetries - 1); + } else { + throw new Error('Operation aborted by the user.'); + } + } else { + throw error; + } + } +} + +// Function to generate bytes32 representation for contract identifiers +export const generateBytes32Identifier = (identifier: string) => { + // Correctly concatenate 'contract.address' with the identifier before hashing + return ethers.utils.solidityKeccak256(["string"], [`contract.address${identifier}`]); +}; + +export async function fastDeployProtocol(deployer: SignerWithAddress, directoryDeployer: SignerWithAddress, rocketStorage: string, weth: string, sanctions: string, uniswapV3: string, oracle: string, admin: string, log: boolean) { + + const directoryAddress = await getNextContractAddress(directoryDeployer, 1) + + const whitelistProxy = await retryOperation(async () => { + const whitelist = await upgrades.deployProxy(await ethers.getContractFactory("contracts/Whitelist/Whitelist.sol:Whitelist", deployer), [directoryAddress], { 'initializer': 'initializeWhitelist', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); + if (log) console.log("whitelist deployed to", whitelist.address) + return whitelist; + }); + + const vCWETHProxy = await retryOperation(async () => { + const vCWETH = await upgrades.deployProxy(await ethers.getContractFactory("WETHVault", deployer), [directoryAddress, weth], { 'initializer': 'initializeVault', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); + if (log) console.log("vaulted constellation eth deployed to", vCWETH.address) + return vCWETH; + }); + + const addressRplContract = await retryOperation(async () => { + const bytes32IdentifierRplContract = generateBytes32Identifier('rocketTokenRPL'); + const rocketStorageDeployment = await ethers.getContractAt("RocketStorage", rocketStorage); + const addressRplContract = await rocketStorageDeployment.getAddress(bytes32IdentifierRplContract); + return addressRplContract + }) + + const rplContract = await retryOperation(async function () { + return await ethers.getContractAt("@openzeppelin/contracts/token/ERC20/ERC20.sol:ERC20", addressRplContract); + }); + + const vCRPLProxy = await retryOperation(async function () { + const vCRPL = await upgrades.deployProxy(await ethers.getContractFactory("RPLVault", deployer), [directoryAddress, rplContract.address], { 'initializer': 'initializeVault', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); + if (log) console.log("vaulted constellation rpl deployed to", vCRPL.address) + return vCRPL + }) + + const depositPoolProxy = await retryOperation(async function () { + const dp = await upgrades.deployProxy(await ethers.getContractFactory("FundRouter", deployer), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); + if (log) console.log("Fund Router (Deposit Pool) deployed to", dp.address) + return dp + }) + + const operatorDistributorProxy = await retryOperation(async function () { + const od = await upgrades.deployProxy(await ethers.getContractFactory("OperatorDistributor", deployer), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); + if (log) console.log("operator distributor deployed to", od.address) + return od + }) + + const yieldDistributorProxy = await retryOperation(async function () { + const yd = await upgrades.deployProxy(await ethers.getContractFactory("YieldDistributor", deployer), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); + if (log) console.log("yield distributor deployed to", yd.address) + return yd + }) + + const priceFetcherProxy = await retryOperation(async function () { + const pf = await upgrades.deployProxy(await ethers.getContractFactory("PriceFetcher", deployer), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); + if (log) console.log("price fetcher deployed to", pf.address) + return pf + }) + + const adminTreasuryProxy = await retryOperation(async function () { + const at = await upgrades.deployProxy(await ethers.getContractFactory("AdminTreasury", deployer), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); + if (log) console.log("admin treasury deployed to", at.address) + return at + }) + + const nodeAccountLogic = await retryOperation(async function () { + const NodeAccountLogic = await ethers.getContractFactory("NodeAccount", deployer); + const nodeAccountLogic = await NodeAccountLogic.deploy(); + await nodeAccountLogic.deployed(); + if (log) console.log("node account impl for cloning deployed to", nodeAccountLogic.address) + return nodeAccountLogic; + }) + + const nodeAccountFactoryProxy = await retryOperation(async () => { + const naf = await upgrades.deployProxy(await ethers.getContractFactory("NodeAccountFactory", deployer), [directoryAddress, nodeAccountLogic.address], { 'initializer': 'initializeWithImplementation', 'kind': 'uups', 'unsafeAllow': ['constructor'] }) + if (log) console.log("node account factory deployed to", naf.address) + return naf + }); + + const directoryProxy = await retryOperation(async () => { + const dir = await upgrades.deployProxy(await ethers.getContractFactory("Directory", directoryDeployer), + [ + [ + whitelistProxy.address, + vCWETHProxy.address, + vCRPLProxy.address, + depositPoolProxy.address, + operatorDistributorProxy.address, + nodeAccountFactoryProxy.address, + yieldDistributorProxy.address, + oracle, + priceFetcherProxy.address, + rocketStorage, + weth, + uniswapV3, + sanctions, + ], + adminTreasuryProxy.address, + admin, + ], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); + + if (log) console.log("directory deployed to", dir.address) + + return dir + }) + + if(log) { + if(directoryAddress.toLocaleLowerCase() === directoryProxy.address.toLocaleLowerCase()) { + console.log("directory matches predicted address", directoryAddress) + } else { + console.error("failed to deploy directory address to predicted address", directoryAddress, directoryProxy.address) + throw new Error("Bad predicted directory") + } + } + + + return { + whitelist: whitelistProxy as Whitelist, + vCWETH: vCWETHProxy as WETHVault, + vCRPL: vCRPLProxy as RPLVault, + depositPool: depositPoolProxy as FundRouter, + operatorDistributor: operatorDistributorProxy as OperatorDistributor, + yieldDistributor: yieldDistributorProxy as YieldDistributor, + priceFetcher: priceFetcherProxy as PriceFetcher, + adminTreasury: adminTreasuryProxy as AdminTreasury, + nodeAccountFactory: nodeAccountFactoryProxy as NodeAccountFactory, + directory: directoryProxy as Directory + } +} \ No newline at end of file diff --git a/test/test-validator-account.ts b/test/test-validator-account.ts index 88c9ecad..8b66fd55 100644 --- a/test/test-validator-account.ts +++ b/test/test-validator-account.ts @@ -11,15 +11,47 @@ import { generateDepositData } from "./rocketpool/_helpers/minipool"; describe("Validator Account Factory", function () { it("test initialize", async function () { - const setupData = await loadFixture(protocolFixture); const { protocol, signers } = setupData; await prepareOperatorDistributionContract(setupData, 2); - const NodeAccounts = await registerNewValidator(setupData, [signers.random, signers.random2]); + const nodeAccounts = await registerNewValidator(setupData, [signers.random, signers.random2]); }); + it("test upgrade", async function() { + const setupData = await loadFixture(protocolFixture); + const { protocol, signers } = setupData; + + await prepareOperatorDistributionContract(setupData, 2); + const nodeAccounts = await registerNewValidator(setupData, [signers.random, signers.random2]); + + const vaf = protocol.NodeAccountFactory; + const oldImpl = vaf.implementationAddress(); + + const V2 = await ethers.getContractFactory("MockNodeAccountV2"); + const v2 = await V2.deploy(); + + await vaf.connect(signers.admin).setImplementation(v2.address); + + expect(await vaf.implementationAddress()).not.equals(oldImpl); + expect(await vaf.implementationAddress()).equals(v2.address); + + await nodeAccounts[0].connect(signers.random).upgradeTo(await vaf.implementationAddress()); + + const v2_0 = await ethers.getContractAt("MockNodeAccountV2", nodeAccounts[0].address); + const v2_1 = await ethers.getContractAt("MockNodeAccountV2", nodeAccounts[1].address); + + expect(await v2_0.test()).equals(69) + await expect(v2_1.test()).to.be.rejectedWith("CALL_EXCEPTION") + + await nodeAccounts[1].connect(signers.random2).upgradeTo(await vaf.implementationAddress()); + + expect(await v2_0.test()).equals(69) + expect(await v2_1.test()).equals(69) + + }) + }); \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index e24eb002..5ce2df98 100644 --- a/test/test.ts +++ b/test/test.ts @@ -15,6 +15,7 @@ import { upgradeExecuted } from "./rocketpool/_utils/upgrade"; import { loadFixture } from "@nomicfoundation/hardhat-network-helpers"; import { ERC20 } from "../typechain-types/contracts/Testing/Rocketpool/contract/util"; import { IERC20 } from "../typechain-types/oz-contracts-3-4-0/token/ERC20"; +import { fastDeployProtocol } from "../scripts/utils/deployment"; export const protocolParams = { trustBuildPeriod: ethers.utils.parseUnits("1.5768", 7) }; // ~6 months in seconds @@ -147,51 +148,21 @@ async function deployProtocol(signers: Signers): Promise { const deployer = (await ethers.getSigners())[0]; - const directoryAddress = await getNextContractAddress(deployer, predictedNonce-1) const initNonce = await deployer.getTransactionCount(); - const whitelist = await upgrades.deployProxy(await ethers.getContractFactory("contracts/Whitelist/Whitelist.sol:Whitelist"), [directoryAddress], { 'initializer': 'initializeWhitelist', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); - const vCWETHProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("WETHVault"), [directoryAddress, wETH.address], { 'initializer': 'initializeVault', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); - const vCWETH = await ethers.getContractAt("WETHVault", vCWETHProxyAbi.address); - const vCRPLProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("RPLVault"), [directoryAddress, rplContract.address], { 'initializer': 'initializeVault', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); - const vCRPL = await ethers.getContractAt("RPLVault", vCRPLProxyAbi.address); - const depositPoolProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("FundRouter"), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); - const depositPool = await ethers.getContractAt("FundRouter", depositPoolProxyAbi.address); - const operatorDistributorProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("OperatorDistributor"), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); - const operatorDistributor = await ethers.getContractAt("OperatorDistributor", operatorDistributorProxyAbi.address); - const yieldDistributorProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("YieldDistributor"), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor', 'delegatecall'] }); - const yieldDistributor = await ethers.getContractAt("YieldDistributor", yieldDistributorProxyAbi.address); - const oracle = (await (await ethers.getContractFactory("MockRETHOracle")).deploy()) as IXRETHOracle; - const priceFetcher = await upgrades.deployProxy(await ethers.getContractFactory("PriceFetcher"), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); - const adminTreasury = await upgrades.deployProxy(await ethers.getContractFactory("AdminTreasury"), [directoryAddress], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); - const NodeAccountLogic = await ethers.getContractFactory("NodeAccount"); - const nodeAccountLogic = await NodeAccountLogic.deploy(); - await nodeAccountLogic.deployed(); - const NodeAccountFactory = await upgrades.deployProxy(await ethers.getContractFactory("NodeAccountFactory"), [directoryAddress, nodeAccountLogic.address], { 'initializer': 'initializeWithImplementation', 'kind': 'uups', 'unsafeAllow': ['constructor'] }) as NodeAccountFactory; - const directoryProxyAbi = await upgrades.deployProxy(await ethers.getContractFactory("Directory"), - [ - [ - whitelist.address, - vCWETH.address, - vCRPL.address, - depositPool.address, - operatorDistributor.address, - NodeAccountFactory.address, - yieldDistributor.address, - oracle.address, - priceFetcher.address, - rockStorageContract.address, - wETH.address, - uniswapV3Pool.address, - sanctions.address, - ], - adminTreasury.address, + const oracle = (await (await ethers.getContractFactory("MockRETHOracle")).deploy()) as IXRETHOracle; + + const {whitelist, vCWETH, vCRPL, depositPool, operatorDistributor, nodeAccountFactory, yieldDistributor, priceFetcher, directory, adminTreasury} = await fastDeployProtocol( + signers.deployer, + signers.random5, + rockStorageContract.address, + wETH.address, + sanctions.address, + uniswapV3Pool.address, + oracle.address, signers.admin.address, - ], { 'initializer': 'initialize', 'kind': 'uups', 'unsafeAllow': ['constructor'] }); - const finalNonce = await deployer.getTransactionCount(); - const directory = await ethers.getContractAt("Directory", directoryProxyAbi.address); - expect(finalNonce - initNonce).to.equal(predictedNonce); - expect(directory.address).to.hexEqual(directoryAddress); + true + ) // set adminServer to be ADMIN_SERVER_ROLE const adminRole = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("ADMIN_SERVER_ROLE")); @@ -209,7 +180,7 @@ async function deployProtocol(signers: Signers): Promise { expect(await directory.getTreasuryAddress()).to.equal(adminTreasury.address); await directory.connect(signers.admin).setTreasury(deployer.address); - const returnData: Protocol = { directory, whitelist, vCWETH, vCRPL, depositPool, operatorDistributor, NodeAccountFactory, yieldDistributor, oracle, priceFetcher, wETH, sanctions }; + const returnData: Protocol = { directory, whitelist, vCWETH, vCRPL, depositPool, operatorDistributor, NodeAccountFactory: nodeAccountFactory, yieldDistributor, oracle, priceFetcher, wETH, sanctions }; // send all rpl from admin to rplWhale const rplWhaleBalance = await rplContract.balanceOf(signers.deployer.address); diff --git a/test/utils/utils.ts b/test/utils/utils.ts index 359ce3be..48556ac7 100644 --- a/test/utils/utils.ts +++ b/test/utils/utils.ts @@ -158,7 +158,7 @@ export const assertSingleTransferExists = async ( export async function deployNodeAccount(setupData: SetupData, bondValue: BigNumber) { const salt = 3; - const nextAddress = "0xD9bf496401781cc411AE0F465Fe073872A50D639"; + const nextAddress = "0x3622082BD98490ddd32c9aaD1AdCdc472569e864"; const depositData = await generateDepositData(nextAddress, salt); const config = {