-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc116d3
commit a9a09f0
Showing
1 changed file
with
64 additions
and
0 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
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; | ||
} |