|
|
@ -34,9 +34,18 @@ import { MultiProvider } from '../providers/MultiProvider'; |
|
|
|
import { MailboxClientConfig } from '../router/types'; |
|
|
|
import { MailboxClientConfig } from '../router/types'; |
|
|
|
import { ChainMap, ChainName } from '../types'; |
|
|
|
import { ChainMap, ChainName } from '../types'; |
|
|
|
|
|
|
|
|
|
|
|
import { UpgradeConfig, proxyAdmin } from './proxy'; |
|
|
|
import { |
|
|
|
|
|
|
|
UpgradeConfig, |
|
|
|
|
|
|
|
isProxy, |
|
|
|
|
|
|
|
proxyAdmin, |
|
|
|
|
|
|
|
proxyConstructorArgs, |
|
|
|
|
|
|
|
proxyImplementation, |
|
|
|
|
|
|
|
} from './proxy'; |
|
|
|
import { ContractVerificationInput } from './verify/types'; |
|
|
|
import { ContractVerificationInput } from './verify/types'; |
|
|
|
import { getContractVerificationInput } from './verify/utils'; |
|
|
|
import { |
|
|
|
|
|
|
|
buildVerificationInput, |
|
|
|
|
|
|
|
getContractVerificationInput, |
|
|
|
|
|
|
|
} from './verify/utils'; |
|
|
|
|
|
|
|
|
|
|
|
export interface DeployerOptions { |
|
|
|
export interface DeployerOptions { |
|
|
|
logger?: Debugger; |
|
|
|
logger?: Debugger; |
|
|
@ -60,6 +69,7 @@ export abstract class HyperlaneDeployer< |
|
|
|
protected readonly multiProvider: MultiProvider, |
|
|
|
protected readonly multiProvider: MultiProvider, |
|
|
|
protected readonly factories: Factories, |
|
|
|
protected readonly factories: Factories, |
|
|
|
protected readonly options?: DeployerOptions, |
|
|
|
protected readonly options?: DeployerOptions, |
|
|
|
|
|
|
|
protected readonly recoverVerificationInputs = false, |
|
|
|
) { |
|
|
|
) { |
|
|
|
this.logger = options?.logger ?? debug('hyperlane:deployer'); |
|
|
|
this.logger = options?.logger ?? debug('hyperlane:deployer'); |
|
|
|
this.chainTimeoutMs = options?.chainTimeoutMs ?? 5 * 60 * 1000; // 5 minute timeout per chain
|
|
|
|
this.chainTimeoutMs = options?.chainTimeoutMs ?? 5 * 60 * 1000; // 5 minute timeout per chain
|
|
|
@ -266,21 +276,29 @@ export abstract class HyperlaneDeployer< |
|
|
|
): Promise<ReturnType<F['deploy']>> { |
|
|
|
): Promise<ReturnType<F['deploy']>> { |
|
|
|
const cachedContract = this.readCache(chain, factory, contractName); |
|
|
|
const cachedContract = this.readCache(chain, factory, contractName); |
|
|
|
if (cachedContract) { |
|
|
|
if (cachedContract) { |
|
|
|
|
|
|
|
if (this.recoverVerificationInputs) { |
|
|
|
|
|
|
|
const recoveredInputs = await this.recoverVerificationArtifacts( |
|
|
|
|
|
|
|
chain, |
|
|
|
|
|
|
|
contractName, |
|
|
|
|
|
|
|
cachedContract, |
|
|
|
|
|
|
|
constructorArgs, |
|
|
|
|
|
|
|
initializeArgs, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
this.addVerificationArtifacts(chain, recoveredInputs); |
|
|
|
|
|
|
|
} |
|
|
|
return cachedContract; |
|
|
|
return cachedContract; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const signer = this.multiProvider.getSigner(chain); |
|
|
|
|
|
|
|
const overrides = this.multiProvider.getTransactionOverrides(chain); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.logger(`Deploy ${contractName} on ${chain}`); |
|
|
|
this.logger(`Deploy ${contractName} on ${chain}`); |
|
|
|
const contract = await (factory |
|
|
|
const contract = await this.multiProvider.handleDeploy( |
|
|
|
.connect(signer) |
|
|
|
chain, |
|
|
|
.deploy(...constructorArgs, overrides) as ReturnType<F['deploy']>); |
|
|
|
factory, |
|
|
|
|
|
|
|
constructorArgs, |
|
|
|
await this.multiProvider.handleTx(chain, contract.deployTransaction); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (initializeArgs) { |
|
|
|
if (initializeArgs) { |
|
|
|
this.logger(`Initialize ${contractName} on ${chain}`); |
|
|
|
this.logger(`Initialize ${contractName} on ${chain}`); |
|
|
|
|
|
|
|
const overrides = this.multiProvider.getTransactionOverrides(chain); |
|
|
|
const initTx = await contract.initialize(...initializeArgs, overrides); |
|
|
|
const initTx = await contract.initialize(...initializeArgs, overrides); |
|
|
|
await this.multiProvider.handleTx(chain, initTx); |
|
|
|
await this.multiProvider.handleTx(chain, initTx); |
|
|
|
} |
|
|
|
} |
|
|
@ -391,19 +409,21 @@ export abstract class HyperlaneDeployer< |
|
|
|
proxyAdmin: string, |
|
|
|
proxyAdmin: string, |
|
|
|
initializeArgs?: Parameters<C['initialize']>, |
|
|
|
initializeArgs?: Parameters<C['initialize']>, |
|
|
|
): Promise<C> { |
|
|
|
): Promise<C> { |
|
|
|
const initData = initializeArgs |
|
|
|
const isProxied = await isProxy( |
|
|
|
? implementation.interface.encodeFunctionData( |
|
|
|
this.multiProvider.getProvider(chain), |
|
|
|
'initialize', |
|
|
|
implementation.address, |
|
|
|
initializeArgs, |
|
|
|
); |
|
|
|
) |
|
|
|
if (isProxied) { |
|
|
|
: '0x'; |
|
|
|
// if the implementation is already a proxy, do not deploy a new proxy
|
|
|
|
|
|
|
|
return implementation; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.logger(`Deploying transparent upgradable proxy`); |
|
|
|
this.logger(`Deploying transparent upgradable proxy`); |
|
|
|
const constructorArgs: [string, string, string] = [ |
|
|
|
const constructorArgs = proxyConstructorArgs( |
|
|
|
implementation.address, |
|
|
|
implementation, |
|
|
|
proxyAdmin, |
|
|
|
proxyAdmin, |
|
|
|
initData, |
|
|
|
initializeArgs, |
|
|
|
]; |
|
|
|
); |
|
|
|
const proxy = await this.deployContractFromFactory( |
|
|
|
const proxy = await this.deployContractFromFactory( |
|
|
|
chain, |
|
|
|
chain, |
|
|
|
new TransparentUpgradeableProxy__factory(), |
|
|
|
new TransparentUpgradeableProxy__factory(), |
|
|
@ -465,6 +485,52 @@ export abstract class HyperlaneDeployer< |
|
|
|
return undefined; |
|
|
|
return undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async recoverVerificationArtifacts<C extends ethers.Contract>( |
|
|
|
|
|
|
|
chain: ChainName, |
|
|
|
|
|
|
|
contractName: string, |
|
|
|
|
|
|
|
cachedContract: C, |
|
|
|
|
|
|
|
constructorArgs: Parameters<C['deploy']>, |
|
|
|
|
|
|
|
initializeArgs?: Parameters<C['initialize']>, |
|
|
|
|
|
|
|
): Promise<ContractVerificationInput[]> { |
|
|
|
|
|
|
|
const provider = this.multiProvider.getProvider(chain); |
|
|
|
|
|
|
|
const isProxied = await isProxy(provider, cachedContract.address); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let implementation: string; |
|
|
|
|
|
|
|
if (isProxied) { |
|
|
|
|
|
|
|
implementation = await proxyImplementation( |
|
|
|
|
|
|
|
provider, |
|
|
|
|
|
|
|
cachedContract.address, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
implementation = cachedContract.address; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const implementationInput = buildVerificationInput( |
|
|
|
|
|
|
|
contractName, |
|
|
|
|
|
|
|
implementation, |
|
|
|
|
|
|
|
cachedContract.interface.encodeDeploy(constructorArgs), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isProxied) { |
|
|
|
|
|
|
|
return [implementationInput]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const admin = await proxyAdmin(provider, cachedContract.address); |
|
|
|
|
|
|
|
const proxyArgs = proxyConstructorArgs( |
|
|
|
|
|
|
|
cachedContract.attach(implementation), |
|
|
|
|
|
|
|
admin, |
|
|
|
|
|
|
|
initializeArgs, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const proxyInput = buildVerificationInput( |
|
|
|
|
|
|
|
'TransparentUpgradeableProxy', |
|
|
|
|
|
|
|
cachedContract.address, |
|
|
|
|
|
|
|
TransparentUpgradeableProxy__factory.createInterface().encodeDeploy( |
|
|
|
|
|
|
|
proxyArgs, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return [implementationInput, proxyInput]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Deploys the Implementation and Proxy for a given contract |
|
|
|
* Deploys the Implementation and Proxy for a given contract |
|
|
|
* |
|
|
|
* |
|
|
@ -476,15 +542,6 @@ export abstract class HyperlaneDeployer< |
|
|
|
constructorArgs: Parameters<Factories[K]['deploy']>, |
|
|
|
constructorArgs: Parameters<Factories[K]['deploy']>, |
|
|
|
initializeArgs?: Parameters<HyperlaneContracts<Factories>[K]['initialize']>, |
|
|
|
initializeArgs?: Parameters<HyperlaneContracts<Factories>[K]['initialize']>, |
|
|
|
): Promise<HyperlaneContracts<Factories>[K]> { |
|
|
|
): Promise<HyperlaneContracts<Factories>[K]> { |
|
|
|
const cachedContract = this.readCache( |
|
|
|
|
|
|
|
chain, |
|
|
|
|
|
|
|
this.factories[contractName], |
|
|
|
|
|
|
|
contractName.toString(), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (cachedContract) { |
|
|
|
|
|
|
|
return cachedContract; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Try to initialize the implementation even though it may not be necessary
|
|
|
|
// Try to initialize the implementation even though it may not be necessary
|
|
|
|
const implementation = await this.deployContract( |
|
|
|
const implementation = await this.deployContract( |
|
|
|
chain, |
|
|
|
chain, |
|
|
|