-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More work to scripts to prep for mainnet
- Loading branch information
Showing
14 changed files
with
448 additions
and
85 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
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,68 @@ | ||
import { BytesLike, Contract, ContractFactory, utils } from 'ethers'; | ||
|
||
import { EnvironmentInfo } from './environment'; | ||
import { newContractFactory } from './helper-functions'; | ||
import { WalletOptions } from './wallet-options'; | ||
import ContractDeployerInterface from './abi/OwnableCreate2Deployer.json'; | ||
|
||
// Key for the salt, use this to change the address of the contract | ||
|
||
/** | ||
* We use the key to generate a salt to generate a deterministic address for | ||
* the contract that isn't dependent on the nonce of the contract deployer account. | ||
*/ | ||
const getSaltFromKey = (): string => { | ||
let key: string = 'relayer-deployer-key-2'; | ||
return utils.keccak256(utils.defaultAbiCoder.encode(['string'], [key])); | ||
}; | ||
|
||
/** | ||
* Load the OwnableCreate2Deployer | ||
*/ | ||
const loadDeployerContract = async (env: EnvironmentInfo, walletOptions: WalletOptions): Promise<Contract> => { | ||
return new Contract(env.deployerContractAddress, ContractDeployerInterface.abi, walletOptions.getWallet()); | ||
} | ||
|
||
/** | ||
* Deploy the contract using the OwnableCreate2Deployer contract. | ||
*/ | ||
export async function deployContractViaCREATE2( | ||
env: EnvironmentInfo, | ||
walletsOptions: WalletOptions, | ||
contractName: string, | ||
constructorArgs: Array<string | undefined>): Promise<Contract> { | ||
|
||
const salt: string = getSaltFromKey(); | ||
const deployer: Contract = await loadDeployerContract(env, walletsOptions); | ||
const contractFactory: ContractFactory = await newContractFactory(walletsOptions.getWallet(), contractName); | ||
const bytecode: BytesLike | undefined = contractFactory.getDeployTransaction(...constructorArgs).data; | ||
|
||
// Deploy the contract | ||
let tx = await deployer.deploy(bytecode, salt, { | ||
gasLimit: 30000000, | ||
maxFeePerGas: 10000000000, | ||
maxPriorityFeePerGas: 10000000000, | ||
}); | ||
await tx.wait(); | ||
|
||
// Calculate the address the contract is deployed to, and attach to return it | ||
const contractAddress = await deployer.deployedAddress(bytecode, await walletsOptions.getWallet().getAddress(), salt); | ||
console.log(`[${env.network}] Deployed ${contractName} to ${contractAddress}`); | ||
|
||
return contractFactory.attach(contractAddress); | ||
} | ||
|
||
/** | ||
* Deploy the contract via a wallet | ||
*/ | ||
export async function deployContract( | ||
env: EnvironmentInfo, | ||
walletsOptions: WalletOptions, | ||
contractName: string, | ||
constructorArgs: Array<string | undefined>): Promise<Contract> { | ||
|
||
const contractFactory: ContractFactory = await newContractFactory(walletsOptions.getWallet(), contractName); | ||
const contract: Contract = await contractFactory.connect(walletsOptions.getWallet()).deploy(...constructorArgs); | ||
console.log(`[${env.network}] Deployed ${contractName} to ${contract.address}`); | ||
return contract; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as fs from 'fs'; | ||
import * as hre from 'hardhat'; | ||
import { EnvironmentInfo, loadEnvironmentInfo } from './environment'; | ||
import { newWalletOptions, WalletOptions } from './wallet-options'; | ||
import { deployContract } from './contract'; | ||
import { waitForInput } from './helper-functions'; | ||
|
||
// Addresses that need to be pre-determined | ||
// 1. Factory | ||
// 2. StartupWalletImpl | ||
// 3. SignerContract | ||
|
||
/** | ||
* Step 1. | ||
**/ | ||
async function step1(): Promise<EnvironmentInfo> { | ||
const env = loadEnvironmentInfo(hre.network.name); | ||
const { network, submitterAddress, signerAddress, } = env; | ||
const multiCallAdminPubKey = '0x575be326c482a487add43974e0eaf232e3366e13'; | ||
const factoryAdminPubKey = '0xddb70ddcd14dbd57ae18ec591f47454e4fc818bb'; | ||
|
||
console.log(`[${network}] Starting deployment...`); | ||
console.log(`[${network}] Submitter address ${submitterAddress}`); | ||
console.log(`[${network}] Signer address ${signerAddress}`); | ||
console.log(`[${network}] multiCallAdminPubKey ${multiCallAdminPubKey}`); | ||
console.log(`[${network}] factoryAdminPubKey ${factoryAdminPubKey}`); | ||
|
||
await waitForInput(); | ||
|
||
// Setup wallet | ||
const wallets: WalletOptions = await newWalletOptions(env); | ||
|
||
// --- STEP 1: Deployed using Passport Nonce Reserver. | ||
// Deploy multi call deploy (PNR) | ||
const multiCallDeploy = await deployContract(env, wallets, 'MultiCallDeploy', [multiCallAdminPubKey, submitterAddress]); | ||
|
||
// Deploy factory with multi call deploy address as deployer role EST (PNR) | ||
const factory = await deployContract(env, wallets, 'Factory', [factoryAdminPubKey, multiCallDeploy.address]); | ||
|
||
fs.writeFileSync('step1.json', JSON.stringify({ | ||
multiCallDeploy: multiCallDeploy.address, | ||
factory: factory.address, | ||
}, null, 1)); | ||
|
||
return env; | ||
} | ||
|
||
// Call primary function | ||
step1() | ||
.then((env: EnvironmentInfo) => { | ||
console.log(`[${env.network}] Contracts deployment successful...`); | ||
process.exit(0); | ||
}) | ||
.catch(err => { | ||
console.error(err.message); | ||
process.exit(1); | ||
}); |
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,51 @@ | ||
import * as fs from 'fs'; | ||
import * as hre from 'hardhat'; | ||
import { EnvironmentInfo, loadEnvironmentInfo } from './environment'; | ||
import { newWalletOptions, WalletOptions } from './wallet-options'; | ||
import { deployContractViaCREATE2 } from './contract'; | ||
import { waitForInput } from './helper-functions'; | ||
|
||
/** | ||
* Step 2 | ||
**/ | ||
async function step2(): Promise<EnvironmentInfo> { | ||
const env = loadEnvironmentInfo(hre.network.name); | ||
const { network, deployerContractAddress } = env; | ||
|
||
console.log(`[${network}] Starting deployment...`); | ||
console.log(`[${network}] CREATE2 Factory address ${deployerContractAddress}`); | ||
|
||
await waitForInput(); | ||
|
||
// Administration accounts | ||
// Is this correct for Mainnet? | ||
let walletImplLocatorAdmin = '0xb49c99a17776c10350c2be790e13d4d8dfb1c578'; | ||
|
||
// Setup wallet | ||
const wallets: WalletOptions = await newWalletOptions(env); | ||
console.log( | ||
`[${network}] Wallet Impl Locator Changer Address: ${await wallets.getWalletImplLocatorChanger().getAddress()}` | ||
); | ||
|
||
// --- Step 2: Deployed using CREATE2 Factory | ||
const latestWalletImplLocator = await deployContractViaCREATE2(env, wallets, 'LatestWalletImplLocator', [ | ||
walletImplLocatorAdmin, await wallets.getWalletImplLocatorChanger().getAddress() | ||
]); | ||
|
||
fs.writeFileSync('step2.json', JSON.stringify({ | ||
latestWalletImplLocator: latestWalletImplLocator.address, | ||
}, null, 1)); | ||
|
||
return env; | ||
} | ||
|
||
// Call primary function | ||
step2() | ||
.then((env: EnvironmentInfo) => { | ||
console.log(`[${env.network}] Contracts deployment successful...`); | ||
process.exit(0); | ||
}) | ||
.catch(err => { | ||
console.error(err.message); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.