Death to AllConfigs (#28)

* Death to AllConfigs
pull/29/head
Asa Oines 3 years ago committed by GitHub
parent 49f930acf7
commit 47bc925aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      typescript/optics-deploy/scripts/dev/agentConfig.ts
  2. 37
      typescript/optics-deploy/scripts/dev/check-deploy.ts
  3. 32
      typescript/optics-deploy/scripts/dev/update-optics-provider.ts
  4. 16
      typescript/optics-deploy/scripts/mainnet-community/update-optics-provider.ts
  5. 8
      typescript/optics-deploy/scripts/mainnet/agentConfig.ts
  6. 28
      typescript/optics-deploy/scripts/mainnet/update-optics-provider.ts
  7. 4
      typescript/optics-deploy/scripts/staging-community/agentConfig.ts
  8. 30
      typescript/optics-deploy/scripts/staging-community/update-optics-provider.ts
  9. 14
      typescript/optics-deploy/scripts/staging/update-optics-provider.ts
  10. 12
      typescript/optics-deploy/src/bridge/BridgeDeploy.ts
  11. 8
      typescript/optics-deploy/src/checks.ts
  12. 14
      typescript/optics-deploy/src/config.ts
  13. 12
      typescript/optics-deploy/src/core/CoreDeploy.ts
  14. 26
      typescript/optics-deploy/src/provider.ts
  15. 1
      typescript/optics-deploy/tsconfig.json

@ -16,6 +16,8 @@ export const configs: AgentChainConfigs = {
fuji: fuji.chainJson fuji: fuji.chainJson
} }
export const networks = [alfajores, kovan, gorli, fuji, mumbai];
// Environment specific config // Environment specific config
export const agentConfig: AgentConfig = { export const agentConfig: AgentConfig = {
environment: 'dev', environment: 'dev',

@ -1,32 +1,31 @@
import * as alfajores from '../../config/testnets/alfajores'; import * as alfajores from '../../config/testnets/alfajores';
import * as kovan from '../../config/testnets/kovan'; import {
import * as gorli from '../../config/testnets/gorli'; checkCoreDeploys,
import * as fuji from '../../config/testnets/fuji'; InvariantViolationCollector,
import * as mumbai from '../../config/testnets/mumbai'; } from '../../src/checks';
import { checkCoreDeploys, InvariantViolationCollector } from '../../src/checks'; import { configPath, networks } from './agentConfig';
import { makeAllConfigs } from '../../src/config'; import { makeCoreDeploys } from '../../src/core/CoreDeploy';
import { configPath } from './agentConfig';
const governorDomain = alfajores.chain.domain; const governorDomain = alfajores.chain.domain;
const coreDeploys = makeCoreDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.devConfig,
);
async function check() { async function check() {
const invariantViolationCollector = new InvariantViolationCollector() const invariantViolationCollector = new InvariantViolationCollector();
await checkCoreDeploys( await checkCoreDeploys(
configPath, coreDeploys,
await Promise.all([
makeAllConfigs(alfajores, (_) => _.devConfig),
makeAllConfigs(kovan, (_) => _.devConfig),
makeAllConfigs(gorli, (_) => _.devConfig),
makeAllConfigs(fuji, (_) => _.devConfig),
makeAllConfigs(mumbai, (_) => _.devConfig),
]),
governorDomain, governorDomain,
invariantViolationCollector.handleViolation invariantViolationCollector.handleViolation,
); );
if (invariantViolationCollector.violations.length > 0) { if (invariantViolationCollector.violations.length > 0) {
console.error(`Invariant violations were found`) console.error(`Invariant violations were found`);
console.log(invariantViolationCollector.violations) console.log(invariantViolationCollector.violations);
} }
} }

@ -1,18 +1,18 @@
import * as alfajores from '../../config/testnets/alfajores';
import * as kovan from '../../config/testnets/kovan';
import * as gorli from '../../config/testnets/gorli';
import * as fuji from '../../config/testnets/fuji';
import * as mumbai from '../../config/testnets/mumbai';
import { updateProviderDomain } from '../../src/provider'; import { updateProviderDomain } from '../../src/provider';
import { configPath } from './agentConfig'; import { configPath, networks } from './agentConfig';
import { makeAllConfigs } from '../../src/config'; import { makeCoreDeploys } from '../../src/core/CoreDeploy';
import { makeBridgeDeploys } from '../../src/bridge/BridgeDeploy';
updateProviderDomain('dev', configPath, [
makeAllConfigs(alfajores, (_) => _.devConfig),
makeAllConfigs(kovan, (_) => _.devConfig),
makeAllConfigs(gorli, (_) => _.devConfig),
makeAllConfigs(fuji, (_) => _.devConfig),
makeAllConfigs(mumbai, (_) => _.devConfig),
]);
const coreDeploys = makeCoreDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.devConfig,
);
const bridgeDeploys = makeBridgeDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.bridgeConfig,
);
updateProviderDomain('dev', coreDeploys, bridgeDeploys);

@ -1,16 +0,0 @@
import * as celo from '../../config/mainnets/celo';
import * as ethereum from '../../config/mainnets/ethereum';
import * as avalanche from '../../config/mainnets/avalanche';
import * as polygon from '../../config/mainnets/polygon';
import { updateProviderDomain } from '../../src/provider';
import { makeAllConfigs } from '../../src/config';
const configPath = '../../rust/config/production-community';
updateProviderDomain('mainnetCommunity', configPath, [
makeAllConfigs(celo, (_) => _.config),
makeAllConfigs(ethereum, (_) => _.config),
makeAllConfigs(avalanche, (_) => _.config),
makeAllConfigs(polygon, (_) => _.config),
]);

@ -0,0 +1,8 @@
import * as celo from '../../config/mainnets/celo';
import * as ethereum from '../../config/mainnets/ethereum';
import * as polygon from '../../config/mainnets/polygon';
import * as avalanche from '../../config/mainnets/avalanche';
const configDirectory = 'production-community'
export const configPath = `../../rust/config/${configDirectory}`;
export const networks = [celo, polygon, avalanche, ethereum];

@ -1,14 +1,18 @@
import * as celo from '../../config/mainnets/celo';
import * as ethereum from '../../config/mainnets/ethereum';
import * as polygon from '../../config/mainnets/polygon';
import { updateProviderDomain } from '../../src/provider'; import { updateProviderDomain } from '../../src/provider';
import { makeAllConfigs } from '../../src/config'; import { makeCoreDeploys } from '../../src/core/CoreDeploy';
import { makeBridgeDeploys } from '../../src/bridge/BridgeDeploy';
import { configPath, networks } from './agentConfig';
const configPath = '../../rust/config/mainnet';
updateProviderDomain('mainnet', configPath, [
makeAllConfigs(ethereum, (_) => _.config),
makeAllConfigs(polygon, (_) => _.config),
makeAllConfigs(celo, (_) => _.config),
]);
const coreDeploys = makeCoreDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.config,
);
const bridgeDeploys = makeBridgeDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.bridgeConfig,
);
updateProviderDomain('mainnetCommunity', coreDeploys, bridgeDeploys);

@ -13,6 +13,10 @@ export const configs: AgentChainConfigs = {
ropsten: ropsten.chainJson ropsten: ropsten.chainJson
} }
export const configPath = '../../rust/config/staging-community';
export const networks = [alfajores, ropsten, kovan, gorli]
// Environment specific config // Environment specific config
export const agentConfig: AgentConfig = { export const agentConfig: AgentConfig = {
environment: 'staging-community', environment: 'staging-community',

@ -1,16 +1,20 @@
import * as alfajores from '../../config/testnets/alfajores';
import * as kovan from '../../config/testnets/kovan';
import * as gorli from '../../config/testnets/gorli';
import * as ropsten from '../../config/testnets/ropsten';
import { updateProviderDomain } from '../../src/provider';
import { makeAllConfigs } from '../../src/config';
import { updateProviderDomain } from '../../src/provider';
import { makeCoreDeploys } from '../../src/core/CoreDeploy';
import { makeBridgeDeploys } from '../../src/bridge/BridgeDeploy';
import { configPath, networks } from './agentConfig';
const configPath = '../../rust/config/staging-community'; const coreDeploys = makeCoreDeploys(
updateProviderDomain('stagingCommunity', configPath, [ configPath,
makeAllConfigs(alfajores, (_) => _.devConfig), networks,
makeAllConfigs(ropsten, (_) => _.devConfig), (_) => _.chain,
makeAllConfigs(kovan, (_) => _.devConfig), (_) => _.stagingCommunityConfig,
makeAllConfigs(gorli, (_) => _.devConfig), );
]); const bridgeDeploys = makeBridgeDeploys(
configPath,
networks,
(_) => _.chain,
(_) => _.bridgeConfig,
);
updateProviderDomain('mainnet', coreDeploys, bridgeDeploys);

@ -1,14 +0,0 @@
import * as alfajores from '../../config/testnets/alfajores';
import * as kovan from '../../config/testnets/kovan';
import * as rinkeby from '../../config/testnets/rinkeby';
import { updateProviderDomain } from '../../src/provider';
import { makeAllConfigs } from '../../src/config';
const configPath = '../../rust/config/staging';
updateProviderDomain('staging', configPath, [
makeAllConfigs(alfajores, (_) => _.devConfig),
makeAllConfigs(kovan, (_) => _.devConfig),
makeAllConfigs(rinkeby, (_) => _.devConfig),
]);

@ -50,3 +50,15 @@ export class BridgeDeploy extends Deploy<BridgeContracts> {
return deploy return deploy
} }
} }
// The accessors is necessary as a network may have multiple bridge/chain configs
export function makeBridgeDeploys<V>(
directory: string,
data: V[],
chainAccessor: (data: V) => Chain,
bridgeConfigAccessor: (data: V) => BridgeConfig
): BridgeDeploy[] {
return data.map(
(d: V) => BridgeDeploy.fromDirectory(directory, chainAccessor(d), bridgeConfigAccessor(d))
);
}

@ -1,18 +1,12 @@
import { CoreDeploy } from './core/CoreDeploy'; import { CoreDeploy } from './core/CoreDeploy';
import { checkCoreDeploy } from './core/checks'; import { checkCoreDeploy } from './core/checks';
import { AllConfigs } from './config';
import { UpgradeBeacon, UpgradeBeaconController } from '@optics-xyz/ts-interface/dist/optics-core'; import { UpgradeBeacon, UpgradeBeaconController } from '@optics-xyz/ts-interface/dist/optics-core';
export async function checkCoreDeploys( export async function checkCoreDeploys(
coreDirectory: string, coreDeploys: CoreDeploy[],
configs: AllConfigs[],
governorDomain: number, governorDomain: number,
invariantViolationHandler: InvariantViolationHandler invariantViolationHandler: InvariantViolationHandler
) { ) {
const coreDeploys = configs.map(
(_) => CoreDeploy.fromDirectory(coreDirectory, _.chain, _.coreConfig),
);
const checkDeploy = async (deploy: CoreDeploy) => { const checkDeploy = async (deploy: CoreDeploy) => {
const remoteDomains = coreDeploys.filter(_ => _.chain.domain !== deploy.chain.domain).map(_ => _.chain.domain) const remoteDomains = coreDeploys.filter(_ => _.chain.domain !== deploy.chain.domain).map(_ => _.chain.domain)

@ -1,14 +0,0 @@
import { BridgeConfig } from './bridge/BridgeDeploy';
import { CoreConfig } from './core/CoreDeploy';
import { Chain } from './chain';
export interface AllConfigs {
chain: Chain;
coreConfig: CoreConfig;
bridgeConfig: BridgeConfig;
}
// The accessor is necessary as a network may have multiple core configs
export function makeAllConfigs<V>(data: V, coreConfigAccessor: (data: V) => CoreConfig) {
return { ...data, coreConfig: coreConfigAccessor(data) };
}

@ -154,3 +154,15 @@ export class CoreDeploy extends Deploy<CoreContracts> {
return deploy return deploy
} }
} }
// The accessors is necessary as a network may have multiple core configs
export function makeCoreDeploys<V>(
directory: string,
data: V[],
chainAccessor: (data: V) => Chain,
coreConfigAccessor: (data: V) => CoreConfig
): CoreDeploy[] {
return data.map(
(d: V) => CoreDeploy.fromDirectory(directory, chainAccessor(d), coreConfigAccessor(d))
);
}

@ -2,29 +2,19 @@ import { BridgeDeploy } from './bridge/BridgeDeploy';
import { CoreDeploy } from './core/CoreDeploy'; import { CoreDeploy } from './core/CoreDeploy';
import { writeFileSync } from 'fs'; import { writeFileSync } from 'fs';
import { resolve } from 'path'; import { resolve } from 'path';
import { AllConfigs } from './config';
export function updateProviderDomain( export function updateProviderDomain(
environment: string, environment: string,
directory: string, coreDeploys: CoreDeploy[],
configs: AllConfigs[], bridgeDeploys: BridgeDeploy[],
) { ) {
let ret = "import { OpticsDomain } from './domain';\n" let ret = "import { OpticsDomain } from './domain';\n"
const coreDeploys = configs.map( coreDeploys.forEach((coreDeploy: CoreDeploy, i: number) => {
(_) => CoreDeploy.fromDirectory(directory, _.chain, _.coreConfig),
);
const bridgeDeploys = configs.map(
(_) => BridgeDeploy.fromDirectory(directory, _.chain, _.bridgeConfig),
);
for (let i = 0; i < configs.length; i++) {
const config = configs[i];
const bridgeDeploy = bridgeDeploys[i]; const bridgeDeploy = bridgeDeploys[i];
const coreDeploy = coreDeploys[i];
ret += ` ret += `
export const ${config.chain.name}: OpticsDomain = { export const ${coreDeploy.chain.name}: OpticsDomain = {
name: '${config.chain.name}', name: '${coreDeploy.chain.name}',
id: ${config.chain.domain}, id: ${coreDeploy.chain.domain},
bridgeRouter: '${bridgeDeploy.contracts.bridgeRouter!.proxy.address}',${!!bridgeDeploy.contracts.ethHelper ? `\n ethHelper: '${bridgeDeploy.contracts.ethHelper?.address}',` : ''} bridgeRouter: '${bridgeDeploy.contracts.bridgeRouter!.proxy.address}',${!!bridgeDeploy.contracts.ethHelper ? `\n ethHelper: '${bridgeDeploy.contracts.ethHelper?.address}',` : ''}
home: '${coreDeploy.contracts.home!.proxy.address}', home: '${coreDeploy.contracts.home!.proxy.address}',
governanceRouter: '${coreDeploy.contracts.governance!.proxy.address}', governanceRouter: '${coreDeploy.contracts.governance!.proxy.address}',
@ -36,8 +26,8 @@ ${Object.keys(coreDeploy.contracts.replicas)
).join('\n')} ).join('\n')}
], ],
};\n` };\n`
} })
ret += `\nexport const ${environment}Domains = [${configs.map(_ => _.chain.name).join(', ')}];` ret += `\nexport const ${environment}Domains = [${coreDeploys.map(_ => _.chain.name).join(', ')}];`
writeFileSync(resolve(__dirname, `../../optics-provider/src/optics/domains/${environment}.ts`), ret) writeFileSync(resolve(__dirname, `../../optics-provider/src/optics/domains/${environment}.ts`), ret)
} }

@ -12,6 +12,7 @@
"./scripts/alfajoresKovan/*.ts", "./scripts/alfajoresKovan/*.ts",
"./scripts/fourTestnets/*.ts", "./scripts/fourTestnets/*.ts",
"./scripts/mainnet/*.ts", "./scripts/mainnet/*.ts",
"./scripts/dev/*.ts",
"./scripts/threeTestnets/*.ts", "./scripts/threeTestnets/*.ts",
"./src/*.ts", "./src/*.ts",
"./src/core/*.ts", "./src/core/*.ts",

Loading…
Cancel
Save