From 0359eee0c983280f1642f691e53a6f7a21beb38b Mon Sep 17 00:00:00 2001 From: Alex Towle Date: Tue, 3 Dec 2024 16:21:24 -0600 Subject: [PATCH] Added a deployment script for the Hyperdrive matching engine --- hardhat.config.mainnet.ts | 4 + tasks/deploy/hyperdrive-matching-engine.ts | 92 ++++++++++++++++++++++ tasks/deploy/hyperdrive.ts | 8 ++ tasks/deploy/lib/constants.ts | 13 ++- tasks/deploy/lib/types.ts | 4 + 5 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 tasks/deploy/hyperdrive-matching-engine.ts diff --git a/hardhat.config.mainnet.ts b/hardhat.config.mainnet.ts index 93fc57fb3..deaee16a2 100644 --- a/hardhat.config.mainnet.ts +++ b/hardhat.config.mainnet.ts @@ -55,6 +55,10 @@ const config: HardhatUserConfig = { ], checkpointRewarders: [], checkpointSubrewarders: [], + hyperdriveMatchingEngine: { + name: "DELV Hyperdrive Matching Engine", + morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb", // Morpho + }, uniV3Zap: { name: "DELV UniV3 Zap", swapRouter: "0xE592427A0AEce92De3Edee1F18E0157C05861564", // Uniswap V3 SwapRouter diff --git a/tasks/deploy/hyperdrive-matching-engine.ts b/tasks/deploy/hyperdrive-matching-engine.ts new file mode 100644 index 000000000..39b8b5562 --- /dev/null +++ b/tasks/deploy/hyperdrive-matching-engine.ts @@ -0,0 +1,92 @@ +import { subtask } from "hardhat/config"; +import { + Address, + decodeEventLog, + encodeDeployData, + encodePacked, + parseEther, +} from "viem"; +import { CREATEX_ABI } from "../../lib/createx/interface/src/lib/constants"; +import { + CREATE_X_FACTORY, + CREATE_X_FACTORY_DEPLOYER, + CREATE_X_PRESIGNED_TRANSACTION, + HyperdriveDeployBaseTask, + HyperdriveDeployNamedTaskParams, + UNI_V3_ZAP_SALT, +} from "./lib"; + +// Extend params to include the additional constructor arguments +export interface DeployHyperdriveMatchingEngineParams + extends HyperdriveDeployNamedTaskParams { + morpho: Address; +} + +HyperdriveDeployBaseTask( + subtask( + "deploy:hyperdrive-matching-engine", + "deploys the HyperdriveMatchingEngine contract to the configured chain", + ), +).setAction( + async ( + { name, morpho }: DeployHyperdriveMatchingEngineParams, + { hyperdriveDeploy, artifacts, viem, network }, + ) => { + console.log("\nRunning deploy:hyperdrive-matching-engine ..."); + + if (network.name == "anvil") { + let tc = await viem.getTestClient(); + await tc.setBalance({ + value: parseEther("1"), + address: CREATE_X_FACTORY_DEPLOYER, + }); + let wc = await viem.getWalletClient(CREATE_X_FACTORY_DEPLOYER); + await wc.sendRawTransaction({ + serializedTransaction: CREATE_X_PRESIGNED_TRANSACTION, + }); + } + + // Skip if the zap is already deployed + if (!!hyperdriveDeploy.deployments.byNameSafe(name)) { + console.log(`skipping ${name}, found existing deployment`); + return; + } + + // Assemble the creation code by packing the contract's bytecode with + // its constructor arguments. + let artifact = artifacts.readArtifactSync("HyperdriveMatchingEngine"); + let deployData = encodeDeployData({ + abi: artifact.abi, + bytecode: artifact.bytecode, + args: [name, morpho], + }); + let creationCode = encodePacked(["bytes"], [deployData]); + + // Call the Create3 deployer to deploy the contract + // Note: No initialization data needed since we're using a constructor + let createXDeployer = await viem.getContractAt( + "IDeterministicDeployer", + CREATE_X_FACTORY, + ); + let tx = await createXDeployer.write.deployCreate3([ + UNI_V3_ZAP_SALT, + creationCode, + ]); + let pc = await viem.getPublicClient(); + let { logs } = await pc.waitForTransactionReceipt({ hash: tx }); + const decodedLog = decodeEventLog({ + abi: CREATEX_ABI, + topics: logs[1].topics, + data: logs[1].data, + }); + let deployedAddress = decodedLog.args.newContract; + + // Save the deployment + console.log(` - saving ${name}...`); + hyperdriveDeploy.deployments.add( + name, + "HyperdriveMatchingEngine", + deployedAddress as Address, + ); + }, +); diff --git a/tasks/deploy/hyperdrive.ts b/tasks/deploy/hyperdrive.ts index 719c83734..c7b8ad66b 100644 --- a/tasks/deploy/hyperdrive.ts +++ b/tasks/deploy/hyperdrive.ts @@ -69,6 +69,14 @@ HyperdriveDeployBaseTask( } as DeployInstanceParams); } + // deploy the HyperdriveMatchingEngine contract. + if (hyperdriveDeploy.hyperdriveMatchingEngine) { + await run("deploy:hyperdrive-matching-engine", { + name: hyperdriveDeploy.hyperdriveMatchingEngine.name, + swapRouter: hyperdriveDeploy.hyperdriveMatchingEngine.morpho, + }); + } + // deploy the UniV3Zap contract. if (hyperdriveDeploy.uniV3Zap) { await run("deploy:uni-v3-zap", { diff --git a/tasks/deploy/lib/constants.ts b/tasks/deploy/lib/constants.ts index e76038823..e5e9027f4 100644 --- a/tasks/deploy/lib/constants.ts +++ b/tasks/deploy/lib/constants.ts @@ -3,16 +3,21 @@ import { Address } from "viem"; export const ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE" as Address; -// The salt for the Create 3 deployment of the Hyperdrive UniV3Zap. This will -// generate the address "0x66603aa2734f3ed7fc435f592207d269507c1666". -export const UNI_V3_ZAP_SALT = - "0x9eb168ab44b7c479431681558fdf34230c969de901ba322c4a7bd1b203703f7a" as `0x${string}`; +// The salt for the Create 3 deployment of the Hyperdrive Matching Engine. This will +// generate the address "0x6662b6e771facd61e33ccafdc23be16b4ead0666". +export const HYPERDRIVE_MATCHING_ENGINE_SALT = + "0xdc32683411729a01a997be000000000000000000000000000000000000000000" as `0x${string}`; // The salt for the Create 3 deployment of the Hyperdrive Registry. This will // generate the address "0x6668310631Ad5a5ac92dC9549353a5BaaE16C666". export const REGISTRY_SALT = "0x01f4fa8cb977b40332a83c000000000000000000000000000000000000000000" as `0x${string}`; +// The salt for the Create 3 deployment of the Hyperdrive UniV3Zap. This will +// generate the address "0x6662a80a8d2dea71065cb38ee8b931db0105d666". +export const UNI_V3_ZAP_SALT = + "0xbb06acea8880460066ae5a000000000000000000000000000000000000000000" as `0x${string}`; + // Address for Create 2/3 factory https://github.com/pcaversaccio/createx/tree/main export const CREATE_X_FACTORY = "0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed" as Address; diff --git a/tasks/deploy/lib/types.ts b/tasks/deploy/lib/types.ts index 65c9d4d15..f310a27ec 100644 --- a/tasks/deploy/lib/types.ts +++ b/tasks/deploy/lib/types.ts @@ -224,6 +224,10 @@ export type HyperdriveConfig = { CoordinatorPrefix >[]; instances: HyperdriveInstanceConfig>[]; + hyperdriveMatchingEngine?: { + name: string; + morpho: Address; + }; uniV3Zap?: { name: string; swapRouter: Address;