Skip to content

Commit

Permalink
Added a deployment script for the Hyperdrive matching engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jalextowle committed Dec 6, 2024
1 parent 407ecb9 commit 0359eee
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 4 deletions.
4 changes: 4 additions & 0 deletions hardhat.config.mainnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions tasks/deploy/hyperdrive-matching-engine.ts
Original file line number Diff line number Diff line change
@@ -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,
);
},
);
8 changes: 8 additions & 0 deletions tasks/deploy/hyperdrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
13 changes: 9 additions & 4 deletions tasks/deploy/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions tasks/deploy/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ export type HyperdriveConfig = {
CoordinatorPrefix<ContractName>
>[];
instances: HyperdriveInstanceConfig<InstancePrefix<ContractName>>[];
hyperdriveMatchingEngine?: {
name: string;
morpho: Address;
};
uniV3Zap?: {
name: string;
swapRouter: Address;
Expand Down

0 comments on commit 0359eee

Please sign in to comment.