Skip to content

Commit

Permalink
respond to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed May 21, 2024
1 parent 25af873 commit eb46746
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 46 deletions.
34 changes: 22 additions & 12 deletions specs/contracts.spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@
# {{name}} is replaced with one of the following, whichever matches first
# - the deployed contract address whose name matches `name` (not factoryName)
# - variables of the running chain, e.g. {{chain.chainName}}, {{chain.chainId}}
# - deployment factory names from written deployment files
# NOTE: order of the contracts matters, as some contracts depend on others
# contracts with no deps should be placed before those with deps
# deployer: must be a valid name in accountRegistry; default to 'default' if not specified

## The following arguments can be specified in contracts spec:
# name: name of key that will be stored in the contract registry
# deployer: must be # name of key that will be stored in the contract registry a valid name in accountRegistry; default to 'default' if not specified
# description: description to be stored in the contract registry
# factoryName: the name of the typechain factory used to deploy the contract
# deployer: deployer key, should correspond to either a private key or one that can be looked up in the evm.accounts.yaml
# libraries: if a contract depends on libraries, the location of the library file & the deployed library address can be specified here, as an array with 2 elements
# deployArgs: The arguments that will be called in the contract constructor. Note: if $INITARGS is passed in as an argument, it will be abi.encode the arguments passed to the init paramater
# init: any arguments that need to be abi encoded (e.g. for calling upgradeToAndCall for ERC1967Proxy). These will be rendered in the place of $INITARGS


- name: LightClient
description: 'DummyLightClient'
factoryName: 'DummyLightClient'
deployer: 'KEY_POLYMER'
description: 'DummyLightClient'
factoryName: 'DummyLightClient'
deployer: 'KEY_POLYMER'

- name: Ibc
description: 'IBC library'
Expand All @@ -24,19 +35,19 @@
- name: Dispatcher
description: 'IBC Core contract'
factoryName: 'Dispatcher'
libraries:
libraries:
- name: 'contracts/libs/Ibc.sol:Ibc'
address: '{{Ibc}}'
deployer: 'KEY_POLYMER'

- name: DispatcherProxy
description: 'Dispatcher proxy contract'
factoryName: 'ERC1967Proxy'
deployArgs:
deployArgs:
- '{{Dispatcher}}'
- '$INITARGS'
- '$INITARGS'
init:
signature: 'initialize(string,address)'
signature: 'initialize(string)'
args:
- 'polyibc.{{chain.chainName}}.'
deployer: 'KEY_POLYMER'
Expand All @@ -46,28 +57,27 @@
factoryName: 'UniversalChannelHandler'
deployer: 'KEY_POLYMER'
libraries:
- name: 'contracts/libs/Ibc.sol:IbcUtils'
- name: 'contracts/libs/IbcUtils.sol:IbcUtils'
address: '{{IbcUtils}}'

- name: UCProxy
description: 'Universal Chanel IBC-middleware proxy'
factoryName: 'ERC1967Proxy'
deployer: 'KEY_POLYMER'
deployArgs:
- '{{UC}}'
- '$INITARGS'
init:
signature: 'initialize(address)'
args:
- '{{DispatcherProxy}}'
deployer: 'KEY_POLYMER'

# dApp contracts for testing and as examples

- name: Mars
description: 'Mars contract directly owns a IBC channel'
deployArgs:
- '{{DispatcherProxy}}'
deployer: 'KEY_POLYMER'
deployer: 'KEY_POLYMER'

- name: Earth
description: 'Earth contract uses shared universal channel'
Expand Down
32 changes: 21 additions & 11 deletions specs/upgrade.spec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# spec for deploying contracts
# {{name}} is replaced with one of the following, whichever matches first
# This file contains a sample spec for sending Txs to contracts.
# This spec can be used for sending any tx to a contract, including proxy upgrades, calling setters, transferring ownership, etc.
# similar to in contract specs, {{name}} is replaced with one of the following, whichever matches first
# - the deployed contract address whose name matches `name` (not factoryName)
# - variables of the running chain, e.g. {{chain.chainName}}, {{chain.chainId}}
# NOTE: order of the contracts matters, as some contracts depend on others
# contracts with no deps should be placed before those with deps
# - deployment factory names from written deployment files
# NOTE: order of the txs matters, as some txs might depend on others
# deployer: must be a valid name in accountRegistry; default to 'default' if not specified

# call on a given factoryname
- name: DispatcherUpgradeII
description: 'Upgrade for dispatcher contract'
deployer: 'KEY_POLYMER' # can be set in the accounts.yaml
signature: "upgradeTo(address)"
factoryName: "Dispatcher"
args:
## The following arguments can be specified in contracts spec:
# name: name of entry that will be stored in tx registry
# description: description in tx registry
# factoryName: factory to use to read abi to send tx
# deployer: can be set in the accounts.yaml
# address: address of contract to call method on
# signature: signature of method to call for this tx
# args: args to make the function call with, need to be compatible with the signature

- name: DispatcherUpgrade
description: 'UUPS Upgrade for dispatcher contract implementation'
deployer: 'KEY_POLYMER'
signature: "upgradeTo(address)"
address: '{{DispatcherProxy}}'
factoryName: "Dispatcher"
args:
- '{{Dispatcher}}'
18 changes: 13 additions & 5 deletions src/scripts/deploy-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import {
} from "..";

import { getMainLogger } from "../utils/cli";
import { DEFAULT_RPC_URL } from "../utils/constants";
import {
ACCOUNTS_SPECS_PATH,
DEFAULT_CHAIN_ID,
DEFAULT_RPC_URL,
DEPLOY_SPECS_PATH,
} from "../utils/constants";

// can either parse
const accountConfigFromYaml = {
name: "local",
registry: parseObjFromFile("specs/evm.accounts.yaml"),
registry: parseObjFromFile(ACCOUNTS_SPECS_PATH),
};

// Or can parse it form the env
Expand All @@ -31,14 +36,15 @@ const accountConfig = {

const accounts = AccountRegistry.loadMultiple([accountConfig]);
const contracts = ContractRegistryLoader.loadSingle(
parseObjFromFile("specs/contracts.spec.yaml")
parseObjFromFile(DEPLOY_SPECS_PATH)
);
console.log(`reading from deploy path: ${DEPLOY_SPECS_PATH}`);

const chain: Chain = {
rpc: process.env.RPC_URL ? process.env.RPC_URL : DEFAULT_RPC_URL,
chainId: process.env.DEPLOYMENT_CHAIN_ID
? parseInt(process.env.DEPLOYMENT_CHAIN_ID)
: 31337,
: DEFAULT_CHAIN_ID,
chainName: process.env.CHAIN_NAME ? process.env.CHAIN_NAME : "local",
vmType: "evm",
description: "local chain",
Expand All @@ -49,5 +55,7 @@ deployToChain(
accounts.mustGet(chain.chainName),
contracts.subset(),
getMainLogger(),
false
false,
false,
true
);
11 changes: 8 additions & 3 deletions src/scripts/upgrade-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import { loadTxRegistry } from "../evm/schemas/tx";
import { sendTxToChain } from "../tx";

import { getOutputLogger } from "../utils/cli";
import { DEFAULT_CHAIN_ID, DEFAULT_RPC_URL } from "../utils/constants";
import {
ACCOUNTS_SPECS_PATH,
DEFAULT_CHAIN_ID,
DEFAULT_RPC_URL,
UPGRADE_SPECS_PATH,
} from "../utils/constants";

// can either parse
const accountConfigFromYaml = {
name: "local",
registry: parseObjFromFile("specs/evm.accounts.yaml"),
registry: parseObjFromFile(ACCOUNTS_SPECS_PATH),
};

// Or can parse it form the env
Expand All @@ -31,7 +36,7 @@ const accountConfig = {
};

const accounts = AccountRegistry.loadMultiple([accountConfig]);
const upgradeTxs = loadTxRegistry(parseObjFromFile("specs/upgrade.spec.yaml"));
const upgradeTxs = loadTxRegistry(parseObjFromFile(UPGRADE_SPECS_PATH));

const chain: Chain = {
rpc: process.env.RPC_URL ? process.env.RPC_URL : DEFAULT_RPC_URL,
Expand Down
4 changes: 2 additions & 2 deletions src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export async function sendTxToChain(
});

// @ts-ignore
const env = { ...existingContractAddresses, chain };
let env = { ...existingContractAddresses, chain };
env = await readDeploymentFilesIntoEnv(env);

const eachTx = async (tx: ReturnType<TxRegistry["mustGet"]>) => {
try {
Expand All @@ -72,7 +73,6 @@ export async function sendTxToChain(
const deployer = accountRegistry.mustGet(
tx.deployer ? tx.deployer : DEFAULT_DEPLOYER
);

const deployedContractAddress = renderArgs([tx.address], "", env)[0];

const ethersContract = new ethers.Contract(
Expand Down
36 changes: 31 additions & 5 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import path from "path";

// Defaults
export const DEFAULT_DEPLOYER = "default";
export const DEFAULT_RPC_URL = "http://127.0.0.1:8545";
export const DEFAULT_CHAIN_ID = 31337;
import path from "path";
const MODULE_ROOT_PATH = "./node_modules/@open-ibc/vibc-core-smart-contracts/";

const DEFAULT_ARTIFACTS_PATH = path.join(MODULE_ROOT_PATH, "out");
const DEFAULT_DEPLOYMENTS_PATH = "./deployments";
const DEFAULT_SPECS_PATH = path.join(MODULE_ROOT_PATH, "./specs");

// The path where we access artifacts for already deployed contracts
export const ARTIFACTS_PATH = process.env.ARTIFACTS_PATH
? process.env.ARTIFACTS_PATH
: "./node_modules/@open-ibc/vibc-core-smart-contracts"; // Used for importing both
export const BASE_OUT_PATH = process.env.DEPLOYMENTS_PATH
: DEFAULT_ARTIFACTS_PATH; // Used for importing both

// The path where we save deployments
export const DEPLOYMENTS_PATH = process.env.DEPLOYMENTS_PATH
? process.env.DEPLOYMENTS_PATH
: ARTIFACTS_PATH;
export const BASE_DEPLOYMENTS_PATH = path.join(BASE_OUT_PATH, "deployments");
: DEFAULT_DEPLOYMENTS_PATH;

const SPECS_BASE_PATH = process.env.SPECS_BASE_PATH
? process.env.SPECS_BASE_PATH
: DEFAULT_SPECS_PATH;

export const DEPLOY_SPECS_PATH = process.env.DEPLOY_SPECS_PATH
? process.env.DEPLOY_SPECS_PATH
: path.join(SPECS_BASE_PATH, "contracts.spec.yaml");

export const UPGRADE_SPECS_PATH = process.env.UPGRADE_SPECS_PATH
? process.env.UPGRADE_SPECS_PATH
: path.join(SPECS_BASE_PATH, "upgrade.spec.yaml");

export const ACCOUNTS_SPECS_PATH = process.env.ACCOUNTS_SPECS_PATH
? process.env.ACCOUNTS_SPECS_PATH
: path.join(SPECS_BASE_PATH, "evm.accounts.yaml");
16 changes: 8 additions & 8 deletions src/utils/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import nunjucks from "nunjucks";
import assert from "assert";
import { ProcessPromise } from "zx";
import { Chain } from "../evm/chain";
import { BASE_DEPLOYMENTS_PATH, ARTIFACTS_PATH } from "./constants";
import { DEPLOYMENTS_PATH, ARTIFACTS_PATH } from "./constants";

export interface StringToStringMap {
[key: string]: string | null | undefined;
Expand Down Expand Up @@ -148,7 +148,6 @@ export function toEnvVarName(e: string) {
async function readMetadata(factoryName: string) {
const filePath = path.join(
ARTIFACTS_PATH,
"out",
`${factoryName}.sol`,
`${factoryName}.json`
);
Expand Down Expand Up @@ -177,8 +176,8 @@ export async function writeDeployedContractToFile(
deployedContract.name,
chain.chainId
);
const fullPath = path.join(BASE_DEPLOYMENTS_PATH, deployFileName);
await createFolderIfNeeded(BASE_DEPLOYMENTS_PATH);
const fullPath = path.join(DEPLOYMENTS_PATH, deployFileName);
await createFolderIfNeeded(DEPLOYMENTS_PATH);
// get metadata from contract./
const metadata = await readMetadata(deployedContract.factory);
deployedContract.metadata = metadata;
Expand All @@ -193,18 +192,19 @@ export async function writeDeployedContractToFile(
}

export async function readDeploymentFilesIntoEnv(env: any) {
await createFolderIfNeeded(BASE_DEPLOYMENTS_PATH);
await createFolderIfNeeded(DEPLOYMENTS_PATH);
let files: any[] = [];
try {
files = await fsAsync.readdir(BASE_DEPLOYMENTS_PATH);
files = await fsAsync.readdir(DEPLOYMENTS_PATH);
} catch (e) {
console.log(`no files to read from`);
return env;
}
for (const file of files) {
if (file.endsWith(".json")) {
try {
const data = JSON.parse(
fs.readFileSync(path.join(BASE_DEPLOYMENTS_PATH, file), "utf8")
fs.readFileSync(path.join(DEPLOYMENTS_PATH, file), "utf8")
);
env[data.name] = data.address;
} catch (e) {
Expand All @@ -220,7 +220,7 @@ export async function readFromDeploymentFile(
chain: Chain
) {
const filePath = path.join(
BASE_DEPLOYMENTS_PATH,
DEPLOYMENTS_PATH,
contractNameToDeployFile(deploymentName, chain.chainId)
);
try {
Expand Down

0 comments on commit eb46746

Please sign in to comment.