|
| 1 | +import { ethers } from "ethers"; |
| 2 | +import { runOnEvms, ChainInfo, getChainConfig, LoggerFn, getDependencyAddress, writeDeployedContract } from "../../helpers"; |
| 3 | +import { MatchingEngineConfiguration } from "../../config/config-types"; |
| 4 | + |
| 5 | +import { MatchingEngine__factory, ERC1967Upgrade__factory } from "../../contract-bindings"; |
| 6 | +import { ERC1967Proxy__factory } from "@certusone/wormhole-sdk/lib/cjs/ethers-contracts"; |
| 7 | + |
| 8 | +runOnEvms("deploy-matching-engine", async (chain: ChainInfo, signer: ethers.Signer, log: LoggerFn) => { |
| 9 | + const config = await getMachingEngineConfiguration(chain); |
| 10 | + const implementation = await deployImplementation(signer, config, log); |
| 11 | + const proxy = await deployProxy(signer, config, implementation, log); |
| 12 | + |
| 13 | +}); |
| 14 | + |
| 15 | +function getMachingEngineConfiguration (chain: ChainInfo): Promise<MatchingEngineConfiguration> { |
| 16 | + return getChainConfig<MatchingEngineConfiguration>("matching-engine", chain.chainId); |
| 17 | +} |
| 18 | + |
| 19 | +async function deployImplementation (signer: ethers.Signer, config: MatchingEngineConfiguration, log: LoggerFn) { |
| 20 | + const factory = new MatchingEngine__factory(signer); |
| 21 | + const token = getDependencyAddress("Token", config.chainId); |
| 22 | + const wormhole = getDependencyAddress("Wormhole", config.chainId); |
| 23 | + const tokenMessenger = getDependencyAddress("TokenMessenger", config.chainId); |
| 24 | + const deployment = await factory.deploy( |
| 25 | + token, |
| 26 | + wormhole, |
| 27 | + tokenMessenger, |
| 28 | + config.userPenaltyRewardBps, |
| 29 | + config.initialPenaltyBps, |
| 30 | + config.auctionDuration, |
| 31 | + config.auctionGracePeriod, |
| 32 | + config.auctionPenaltyBlocks, |
| 33 | + {} // overrides |
| 34 | + ); |
| 35 | + |
| 36 | + await deployment.deployed(); |
| 37 | + |
| 38 | + log(`MatchingEngine deployed at ${deployment.address}`); |
| 39 | + |
| 40 | + writeDeployedContract(config.chainId, "MatchingEngineImplementations", deployment.address); |
| 41 | + |
| 42 | + return deployment; |
| 43 | +} |
| 44 | + |
| 45 | +async function deployProxy (signer: ethers.Signer, config: MatchingEngineConfiguration, implementation: ethers.Contract, log: LoggerFn) { |
| 46 | + const factory = new ERC1967Proxy__factory(signer); |
| 47 | + |
| 48 | + const abi = ["function initialize(address,address)"]; |
| 49 | + const iface = new ethers.utils.Interface(abi); |
| 50 | + const encodedCall = iface.encodeFunctionData("initialize", [config.ownerAssistant, config.feeRecipient]); |
| 51 | + |
| 52 | + const deployment = await factory.deploy( |
| 53 | + implementation.address, |
| 54 | + encodedCall, |
| 55 | + ); |
| 56 | + |
| 57 | + await deployment.deployed(); |
| 58 | + |
| 59 | + log(`MatchingEngineProxy deployed at ${deployment.address}`); |
| 60 | + |
| 61 | + writeDeployedContract(config.chainId, "MatchingEngineProxies", deployment.address); |
| 62 | + |
| 63 | + return deployment; |
| 64 | +} |
0 commit comments