Skip to content

Commit

Permalink
evm deploy matching engine script
Browse files Browse the repository at this point in the history
  • Loading branch information
solanoepalacio committed May 10, 2024
1 parent dc116d3 commit a9a09f0
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions deployment/scripts/evm/deploy-matching-engine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ethers } from "ethers";
import { runOnEvms, ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract } from "../../helpers";
import { MatchingEngineConfiguration } from "../../config/config-types";

import { MatchingEngine__factory, ERC1967Upgrade__factory } from "../../contract-bindings";
import { ERC1967Proxy__factory } from "@certusone/wormhole-sdk/lib/cjs/ethers-contracts";

runOnEvms("deploy-matching-engine", async (chain: ChainInfo, signer: ethers.Signer, log: LoggerFn) => {
const config = await getMachingEngineConfiguration(chain);
const implementation = await deployImplementation(signer, config, log);
const proxy = await deployProxy(signer, config, implementation, log);

});

function getMachingEngineConfiguration (chain: ChainInfo): Promise<MatchingEngineConfiguration> {
return getChainConfig<MatchingEngineConfiguration>("matching-engine", chain.chainId);
}

async function deployImplementation (signer: ethers.Signer, config: MatchingEngineConfiguration, log: LoggerFn) {
const factory = new MatchingEngine__factory(signer);
const token = getDependencyAddress("Token", config.chainId);
const wormhole = getDependencyAddress("Wormhole", config.chainId);
const tokenMessenger = getDependencyAddress("TokenMessenger", config.chainId);
const deployment = await factory.deploy(
token,
wormhole,
tokenMessenger,
config.userPenaltyRewardBps,
config.initialPenaltyBps,
config.auctionDuration,
config.auctionGracePeriod,
config.auctionPenaltyBlocks,
{} // overrides
);

await deployment.deployed();

log(`MatchingEngine deployed at ${deployment.address}`);

writeDeployedContract(config.chainId, "MatchingEngineImplementations", deployment.address);

return deployment;
}

async function deployProxy (signer: ethers.Signer, config: MatchingEngineConfiguration, implementation: ethers.Contract, log: LoggerFn) {
const factory = new ERC1967Proxy__factory(signer);

const abi = ["function initialize(address,address)"];
const iface = new ethers.utils.Interface(abi);
const encodedCall = iface.encodeFunctionData("initialize", [config.ownerAssistant, config.feeRecipient]);

const deployment = await factory.deploy(
implementation.address,
encodedCall,
);

await deployment.deployed();

log(`MatchingEngineProxy deployed at ${deployment.address}`);

writeDeployedContract(config.chainId, "MatchingEngineProxies", deployment.address);

return deployment;
}

0 comments on commit a9a09f0

Please sign in to comment.