From ee17c5fe6af024cf049103fb38dcc6595ed1b338 Mon Sep 17 00:00:00 2001 From: James Prestwich <10149425+prestwich@users.noreply.github.com> Date: Mon, 16 Aug 2021 04:19:42 -0700 Subject: [PATCH] feature: deploy core can distinguish between dev/prod/staging (#569) * feature: deploy core can distinguish between dev/prod/staging * feature: default to dev env if not set --- typescript/optics-deploy/config/alfajores.ts | 12 +++++++++++- typescript/optics-deploy/config/kovan.ts | 12 +++++++++++- typescript/optics-deploy/scripts/alfajoresKovan.ts | 12 ++++++++++-- typescript/optics-deploy/src/chain.ts | 14 ++++++++++++++ typescript/optics-deploy/src/core/CoreDeploy.ts | 10 +++++++++- typescript/optics-tests/test/testChain.ts | 1 + 6 files changed, 56 insertions(+), 5 deletions(-) diff --git a/typescript/optics-deploy/config/alfajores.ts b/typescript/optics-deploy/config/alfajores.ts index a7e568ed2..1a9795eb9 100644 --- a/typescript/optics-deploy/config/alfajores.ts +++ b/typescript/optics-deploy/config/alfajores.ts @@ -13,7 +13,8 @@ export const chainJson: ChainJson = { export const chain = toChain(chainJson); -export const config: CoreConfig = { +export const devConfig: CoreConfig = { + environment: 'dev', updater: '0x4177372FD9581ceb2367e0Ce84adC5DAD9DF8D55', watchers: ['0x20aC2FD664bA5406A7262967C34107e708dCb18E'], recoveryManager: '0x24F6c874F56533d9a1422e85e5C7A806ED11c036', @@ -21,4 +22,13 @@ export const config: CoreConfig = { recoveryTimelock: 180, }; +export const stagingConfig: CoreConfig = { + environment: 'staging', + updater: '0x201dd86063Dc251cA5a576d1b7365C38e5fB4CD5', + watchers: ['0x22B2855635154Baa41C306BcA979C8c9a077A180'], + recoveryManager: '0x24F6c874F56533d9a1422e85e5C7A806ED11c036', + optimisticSeconds: 10, + recoveryTimelock: 180, +}; + export const bridgeConfig: BridgeConfig = {}; diff --git a/typescript/optics-deploy/config/kovan.ts b/typescript/optics-deploy/config/kovan.ts index 4d905aa8a..5881f7f55 100644 --- a/typescript/optics-deploy/config/kovan.ts +++ b/typescript/optics-deploy/config/kovan.ts @@ -17,7 +17,8 @@ const chainJson: ChainJson = { export const chain = toChain(chainJson); -export const config: CoreConfig = { +export const devConfig: CoreConfig = { + environment: 'dev', updater: '0x4177372FD9581ceb2367e0Ce84adC5DAD9DF8D55', optimisticSeconds: 10, watchers: ['0x20aC2FD664bA5406A7262967C34107e708dCb18E'], @@ -25,6 +26,15 @@ export const config: CoreConfig = { recoveryManager: '0x24F6c874F56533d9a1422e85e5C7A806ED11c036', }; +export const stagingConfig: CoreConfig = { + environment: 'staging', + updater: '0x201dd86063Dc251cA5a576d1b7365C38e5fB4CD5', + watchers: ['0x22B2855635154Baa41C306BcA979C8c9a077A180'], + recoveryManager: '0x24F6c874F56533d9a1422e85e5C7A806ED11c036', + optimisticSeconds: 10, + recoveryTimelock: 180, +}; + export const bridgeConfig: BridgeConfig = { weth: '0xd0a1e359811322d97991e03f863a0c30c2cf029c', }; diff --git a/typescript/optics-deploy/scripts/alfajoresKovan.ts b/typescript/optics-deploy/scripts/alfajoresKovan.ts index d60d3c43c..28e9ed6cc 100644 --- a/typescript/optics-deploy/scripts/alfajoresKovan.ts +++ b/typescript/optics-deploy/scripts/alfajoresKovan.ts @@ -2,8 +2,16 @@ import { deployTwoChains } from '../src/core'; import * as alfajores from '../config/alfajores'; import * as kovan from '../config/kovan'; import { CoreDeploy } from '../src/core/CoreDeploy'; +import { deployEnvironment } from '../src/chain'; -const alfaDeploy = new CoreDeploy(alfajores.chain, alfajores.config); -const kovanDeploy = new CoreDeploy(kovan.chain, kovan.config); +let environment = deployEnvironment(); + +let alfaConfig = + environment === 'staging' ? alfajores.stagingConfig : alfajores.devConfig; +let kovanConfig = + environment === 'staging' ? kovan.stagingConfig : kovan.devConfig; + +const alfaDeploy = new CoreDeploy(alfajores.chain, alfaConfig); +const kovanDeploy = new CoreDeploy(kovan.chain, kovanConfig); deployTwoChains(alfaDeploy, kovanDeploy); diff --git a/typescript/optics-deploy/src/chain.ts b/typescript/optics-deploy/src/chain.ts index cd8f2c674..d72e4b3f0 100644 --- a/typescript/optics-deploy/src/chain.ts +++ b/typescript/optics-deploy/src/chain.ts @@ -3,6 +3,8 @@ import { BigNumber } from 'ethers'; import { NonceManager } from '@ethersproject/experimental'; import { ProxyAddresses } from './proxyUtils'; +export type DeployEnvironment = 'dev' | 'staging' | 'prod'; + export type CoreContractDeployOutput = { upgradeBeaconController: string; xAppConnectionManager: string; @@ -31,6 +33,18 @@ export type Chain = { domain: number; }; +export function deployEnvironment(): DeployEnvironment { + const e = process.env.OPTICS_DEPLOY_ENVIRONMENT; + + if (e === 'staging') { + return 'staging'; + } else if (e === 'prod') { + return 'prod'; + } + + return 'dev'; +} + export function toChain(config: ChainJson): Chain { const provider = new ethers.providers.JsonRpcProvider(config.rpc); const signer = new ethers.Wallet(config.deployerKey!, provider); diff --git a/typescript/optics-deploy/src/core/CoreDeploy.ts b/typescript/optics-deploy/src/core/CoreDeploy.ts index 9fe88ee81..63bc98f4e 100644 --- a/typescript/optics-deploy/src/core/CoreDeploy.ts +++ b/typescript/optics-deploy/src/core/CoreDeploy.ts @@ -1,8 +1,15 @@ -import { Chain, ChainJson, RustConfig, toChain } from '../chain'; +import { + Chain, + ChainJson, + DeployEnvironment, + RustConfig, + toChain, +} from '../chain'; import { CoreContracts } from './CoreContracts'; import { Deploy } from '../deploy'; export type CoreConfig = { + environment: DeployEnvironment; updater: string; recoveryTimelock: number; recoveryManager: string; @@ -27,6 +34,7 @@ export class CoreDeploy extends Deploy { return [ chain, { + environment: config.environment, updater: config.updater, watchers: config.watchers ?? [], recoveryManager: config.recoveryManager, diff --git a/typescript/optics-tests/test/testChain.ts b/typescript/optics-tests/test/testChain.ts index c86568550..e67ad25bc 100644 --- a/typescript/optics-tests/test/testChain.ts +++ b/typescript/optics-tests/test/testChain.ts @@ -29,6 +29,7 @@ export async function getTestChain( }, }, { + environment: 'dev', recoveryTimelock: 1, recoveryManager: recoveryManager || ethers.constants.AddressZero, updater,