Skip to content

Commit

Permalink
Get ipfs url from build logs
Browse files Browse the repository at this point in the history
  • Loading branch information
noisekit committed Nov 17, 2023
1 parent 6c42d0c commit 560169c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ jobs:
--chain-id 84531 \
--provider-url https://base-goerli.infura.io/v3/$INFURA_API_KEY \
--write-script ./e2e/upgrade--base-goerli-andromeda.json \
--write-script-format json
--write-script-format json | tee ./e2e/cannon-build.log
yarn prettier --write ./e2e/upgrade--base-goerli-andromeda.json
- store_artifacts:
path: "./e2e/upgrade--base-goerli-andromeda.json"

- run:
name: "Generate deployments"
command: node e2e/fetch-local-deployment.js 84531 omnibus-base-goerli-andromeda.toml
command: node e2e/fetch-local-deployment.js ./e2e/cannon-build.log

- store_artifacts:
path: "./e2e/deployments"
Expand Down
52 changes: 28 additions & 24 deletions e2e/fetch-local-deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
const os = require('os');
const path = require('path');
const fs = require('fs/promises');
const toml = require('@iarna/toml');
const { ethers } = require('ethers');
const { LocalRegistry } = require('@usecannon/cli/dist/src/registry');
const { CliLoader } = require('@usecannon/cli/dist/src/loader');
const CANNON_DIRECTORY = path.join(os.homedir(), '.local', 'share', 'cannon');

Expand All @@ -15,14 +13,12 @@ const fgGreen = '\x1b[32m';
const fgYellow = '\x1b[33m';
const fgCyan = '\x1b[36m';

const [chainId, deploymentFile] = process.argv.slice(2);
if (!chainId || !deploymentFile) {
console.error(`${fgRed}ERROR: Expected 2 arguments${fgReset}`);
const [buildLog] = process.argv.slice(2);
if (!buildLog) {
console.error(`${fgRed}ERROR: Expected 1 argument${fgReset}`);
console.error(`Usage: ${fgGreen}node e2e/fetch-local-deployment.js ${fgCyan}buildLog${fgReset}`);
console.error(
`Usage: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}chainId ${fgCyan}deploymentFile${fgReset}`
);
console.error(
`Example: ${fgGreen}node e2e/fetch-local-deployment.js ${fgYellow}84531 ${fgCyan}omnibus-base-goerli-andromeda.toml${fgReset}`
`Example: ${fgGreen}node e2e/fetch-local-deployment.js ${fgCyan}e2e/cannon-build.log${fgReset}`
);
process.exit(1);
}
Expand All @@ -32,36 +28,40 @@ function readableAbi(abi) {
}

async function run() {
const config = await fs.readFile(deploymentFile, 'utf8');
const { name, version, setting } = toml.parse(config);
const preset = setting?.target_preset?.defaultValue ?? 'main';
console.log('Resolving Deployment Data URL from log', { buildLog });
const log = await fs.readFile(buildLog, 'utf8');

console.log('Resolving URL', {
packageRef: `${name}:${version}`,
variant: `${chainId}-${preset}`,
});
const localRegistry = new LocalRegistry(CANNON_DIRECTORY);
const url = await await localRegistry.getUrl(`${name}:${version}`, `${chainId}-${preset}`);
const [, url] = log.match(/Deployment Data\s*│\s*(ipfs:\/\/Qm\S+)/im) || [];
console.log(`Resolved URL:`, { url });

console.log('Fetching deployment state', { url });
const hash = CliLoader.getCacheHash(url);
console.log(`Resolved FileName hash:`, { hash });

const deployments = JSON.parse(
await fs.readFile(`${CANNON_DIRECTORY}/ipfs_cache/${CliLoader.getCacheHash(url)}.json`, 'utf8')
);

await fs.mkdir(`${__dirname}/deployments`, { recursive: true });

const snxAddress = setting?.snx_address?.defaultValue ?? ethers.constants.AddressZero;
await fs.writeFile(
`${__dirname}/deployments/snx.json`,
JSON.stringify({ address: snxAddress }, null, 2)
);
const meta = {
chainId: deployments.chainId,
name: deployments.def.name,
version: deployments.def.version,
generator: deployments.generator,
timestamp: deployments.timestamp,
miscUrl: deployments.miscUrl,
};
console.log('Generating deployments info for', meta);

const system = deployments.state['provision.system'].artifacts.imports.system;
console.log('Writing', 'deployments/CoreProxy.json', {
address: system.contracts.CoreProxy.address,
});
await fs.writeFile(
`${__dirname}/deployments/CoreProxy.json`,
JSON.stringify(
{
...meta,
address: system.contracts.CoreProxy.address,
abi: readableAbi(system.contracts.CoreProxy.abi),
},
Expand All @@ -75,10 +75,14 @@ async function run() {
deployments?.state?.[`provision.${provisionStep}`]?.artifacts?.imports?.[provisionStep];
if (fakeCollateral) {
const [, ticker] = fakeCollateral.contracts.MintableToken.constructorArgs;
console.log('Writing', `deployments/FakeCollateral${ticker}.json`, {
address: fakeCollateral.contracts.MintableToken.address,
});
await fs.writeFile(
`${__dirname}/deployments/FakeCollateral${ticker}.json`,
JSON.stringify(
{
...meta,
address: fakeCollateral.contracts.MintableToken.address,
abi: readableAbi(fakeCollateral.contracts.MintableToken.abi),
},
Expand Down

0 comments on commit 560169c

Please sign in to comment.