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

Deployment preparation: Vault Factory V2 #209

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Returns an object with all contracts from a deployment and their addresses.
| V3 Protocol Fee Sweeper | [`20250228-v3-protocol-fee-sweeper`](./v3/tasks/20250228-v3-protocol-fee-sweeper) |
| V3 Router V2 | [`20250307-v3-router-v2`](./v3/tasks/20250307-v3-router-v2) |
| V3 Liquidity Bootstrapping Pool | [`20250307-v3-liquidity-bootstrapping-pool`](./v3/tasks/20250307-v3-liquidity-bootstrapping-pool) |
| V3 Vault Factory V2, and Vault contracts | [`20250321-v3-vault-factory-v2`](./v3/tasks/20250321-v3-vault-factory-v2) |
| V3 Stable Pool V2 | [`20250324-v3-stable-pool-v2`](./v3/tasks/20250324-v3-stable-pool-v2) |

## Scripts
Expand Down
37 changes: 30 additions & 7 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type ContractInfo = {
export default class Task {
id: string;
mode: TaskMode;
evm: Promise<EVM>;

_network?: Network;
_verifier?: Verifier;
Expand All @@ -71,6 +72,7 @@ export default class Task {
this.mode = mode;
this._network = network;
this._verifier = verifier;
this.evm = this.createEVM();
}

get network(): string {
Expand Down Expand Up @@ -160,7 +162,9 @@ export default class Task {
// NOTE: contractsInfo must be sorted by deployment order
async saveAndVerifyFactoryContracts(
contractsInfo: Array<ContractInfo>,
deployTransaction?: ethers.providers.TransactionReceipt
deployTransaction?: ethers.providers.TransactionReceipt,
externalTask?: Task,
factoryAddress?: string
): Promise<void> {
const { ethers } = await import('hardhat');

Expand All @@ -171,14 +175,17 @@ export default class Task {
deployTransaction = await ethers.provider.getTransactionReceipt(deploymentTxHash);
}

const evm = await this.createEVM();
// Pass in an external task if the artifacts are not in the present task.
// For instance, vault-factory-v2, where for safety we don't want to duplicate the artifacts.
const artifactSource = externalTask === undefined ? this : externalTask;

for (const contractInfo of contractsInfo) {
const isDeployedBytecodeValid = await this.checkBytecodeAndSaveEVMState(
evm,
deployTransaction,
this.artifact(contractInfo.name),
artifactSource.artifact(contractInfo.name),
contractInfo.expectedAddress,
contractInfo.args
contractInfo.args,
factoryAddress
);

if (isDeployedBytecodeValid && this.mode === TaskMode.CHECK) {
Expand Down Expand Up @@ -219,12 +226,13 @@ export default class Task {
return evm;
}

// NOTE: If a contract is deployed by a factory, we must set the factoryAddress in the function arguments.
async checkBytecodeAndSaveEVMState(
evm: EVM,
deployTransaction: ethers.providers.TransactionReceipt,
artifact: Artifact,
contractAddress: string,
args: Array<Param> = []
args: Array<Param> = [],
factoryAddress?: string
): Promise<boolean> {
const { ethers } = await import('hardhat');

Expand All @@ -239,9 +247,12 @@ export default class Task {
throw Error(`Could not find block ${deployTransaction.blockNumber}`);
}

const evm = await this.evm;
const res = await evm.runCode({
code: runBytecode,
to: Address.fromString(contractAddress),
caller: factoryAddress ? Address.fromString(factoryAddress) : Address.fromString(deployTransaction.from),
origin: Address.fromString(deployTransaction.from),
block: {
header: {
number: BigInt(block.number),
Expand Down Expand Up @@ -289,6 +300,8 @@ export default class Task {
this.save({ [name]: instance });
logger.success(`Deployed ${name} at ${instance.address}`);

await this.saveInInternalEVMState(instance.address);

if (this.mode === TaskMode.LIVE) {
saveContractDeploymentTransactionHash(instance.address, instance.deployTransaction.hash, this.network);
}
Expand All @@ -300,6 +313,16 @@ export default class Task {
return instance;
}

async saveInInternalEVMState(address: string): Promise<void> {
const { ethers } = await import('hardhat');
const evm = await this.evm;

await evm.stateManager.putContractCode(
Address.fromString(address),
hexToBytes(await ethers.provider.getCode(address))
);
}

async verify(
name: string,
address: string,
Expand Down
2 changes: 1 addition & 1 deletion v2/tasks/20231031-batch-relayer-v6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async (task: Task, { force, from }: TaskRunOptions = {}): Promise
const relayerLibrary = await task.deployAndVerify('BatchRelayerLibrary', relayerLibraryArgs, from, force);

// The relayer library automatically also deploys the query library, and then the relayer itself: we must verify them
const relayer: Contract = await task.instanceAt('BalancerRelayer', relayerLibrary.getEntrypoint());
const relayer: Contract = await task.instanceAt('BalancerRelayer', await relayerLibrary.getEntrypoint());
const queryLibrary: string = await relayer.getQueryLibrary();
const relayerAddress = await relayer.address;

Expand Down
Loading
Loading