-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy scripts for
UniV3Zap
and the matching engine (#1224)
* Added the UniV3 zap tooling * Wired up the UniV3Zap * Added a deployment script for the Hyperdrive matching engine * Updated the deploy scripts * Addressed review feedback from John McClure * Fixed issue with the publish script
- Loading branch information
1 parent
5e39e30
commit e4d61f6
Showing
9 changed files
with
274 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { subtask } from "hardhat/config"; | ||
import { Address, decodeEventLog, encodeDeployData, encodePacked } from "viem"; | ||
import { CREATEX_ABI } from "../../lib/createx/interface/src/lib/constants"; | ||
import { | ||
CREATE_X_FACTORY, | ||
HYPERDRIVE_MATCHING_ENGINE_SALT, | ||
HyperdriveDeployBaseTask, | ||
HyperdriveDeployNamedTaskParams, | ||
deployCreateX, | ||
} 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, hre) => { | ||
console.log("\nRunning deploy:hyperdrive-matching-engine ..."); | ||
const { hyperdriveDeploy, artifacts, viem, network } = hre; | ||
|
||
// If the network is anvil, we need to deploy the CREATEX factory if it | ||
// hasn't been deployed before. | ||
await deployCreateX(hre); | ||
|
||
// 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([ | ||
HYPERDRIVE_MATCHING_ENGINE_SALT, | ||
creationCode, | ||
]); | ||
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, | ||
); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.