Skip to content
This repository has been archived by the owner on Oct 9, 2024. It is now read-only.

Commit

Permalink
feat: aavesome fork cli (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakulstra authored Aug 26, 2022
1 parent 23e5370 commit 55dd3cc
Show file tree
Hide file tree
Showing 15 changed files with 732 additions and 237 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TENDERLY_ACCESS_KEY=tenderly_secret
TENDERLY_ACCESS_TOKEN=tenderly_access_token
TENDERLY_PROJECT=tenderly_project
TENDERLY_USER=tenderly_user
TENDERLY_ACCOUNT=tenderly_account
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.env
.idea/
.idea/
*.tgz

dist
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.env
.idea/
*.tgz
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Aave fork cli

## Installation

```sh
npm i -g @bgd-labs/aave-fork-cli
```

## Setup env

The tooling relies on tenderly. Therefore you need to setup your console environment accordingly.

```sh
export TENDERLY_ACCESS_TOKEN=tenderly_access_token
export TENDERLY_PROJECT=tenderly_project
export TENDERLY_ACCOUNT=tenderly_account
```

To store the secrets across sessions you might want to add them to `.bashrc` or `.profile`.

## Usage

```sh
# help command - will also show short commands not listed here
aave-fork-cli --help

# create a fork
aave-fork-cli fork

# keep the fork alive forever
aave-fork-cli fork --keepAlive

# fork at a specific block (default is latest)
aave-fork-cli fork --block 15415636

# adjust the networkId of the created fork (defaults to 3030)
aave-fork-cli fork --forkNetworkId 42

# execute a pending proposal
aave-fork-cli fork --proposalId 95

# create a proposal with existing payload & execute
aave-fork-cli fork --payloadAddress 0x0...

# deploy a payload, create and execute the proposal
aave-fork-cli fork --artifact ./out/Contract.sol/Contract.json
```

## Local Development

```sh
npm run publish:local
```
24 changes: 24 additions & 0 deletions dist/index.js

Large diffs are not rendered by default.

136 changes: 136 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env node

import "dotenv/config";
import { Command } from "commander";
import { createFork, deleteFork, forkIdToForkParams } from "./src/tenderly";
import {
createProposal,
deployPayload,
passAndExecuteProposal,
} from "./src/governance";

interface Options {
forkId?: string;
forkNetworkId: string;
blockNumber?: string;
proposalId?: number;
payloadAddress?: string;
artifact?: string;
keepAlive?: boolean;
}

function getName(options: Options) {
if (options.proposalId) {
return `proposalId-${options.proposalId}`;
} else if (options.payloadAddress) {
return `payloadAddress-${options.payloadAddress}`;
} else if (options.artifact) {
return `artifact-${options.artifact}`;
}
return "vanilla-fork";
}

function listenForInterruptAndKill(forkId: string) {
console.log("warning: the fork will be deleted once this terminal is closed");
// keep process alive
process.stdin.resume();

// delete fork on exit
process.on("SIGINT", function () {
console.log("Caught interrupt signal");
deleteFork(forkId).then((d) => {
console.log("fork deleted");
process.exit(0);
});
});
}

const program = new Command();
program
.name("aave-fok-cli")
.description("CLI to create forks and work with governance")
.version("0.0.1");

program
.command("fork")
.description("Split a string into substrings and display as an array")
.option(
"-fId, --forkId <forkId>",
"reuse an existing fork instead of creating a new one"
)
.option("-b, --blockNumber <block>", "fork at a certain block")
.option(
"-fnId, --forkNetworkId <networkId>",
"the networkId for the fork",
"3030"
)
.option("-pi, --proposalId <proposalId>", "proposalId to be executed")
.option("-pa, --payloadAddress <address>", "payloadAddress to be executed")
.option(
"-a, --artifact <path>",
"path to be payload to be deployed and executed"
)
.option(
"-k, --keepAlive",
"with this option set the fork won't be deleted automatically"
)
.action(async function (options: Options) {
const alias = getName(options);
const forkId =
options.forkId ||
(await createFork({
alias,
forkNetworkId: options.forkNetworkId,
blockNumber: options.blockNumber,
}));
const fork = forkIdToForkParams({ forkId });

if (options.proposalId) {
await passAndExecuteProposal({
proposalId: options.proposalId,
provider: fork.provider,
});
} else if (options.payloadAddress) {
const proposalId = await createProposal({
payloadAddress: options.payloadAddress,
provider: fork.provider,
});
await passAndExecuteProposal({
proposalId: proposalId,
provider: fork.provider,
});
} else if (options.artifact) {
const payloadAddress = await deployPayload({
filePath: options.artifact,
provider: fork.provider,
});
const proposalId = await createProposal({
provider: fork.provider,
payloadAddress: payloadAddress,
});
await passAndExecuteProposal({
provider: fork.provider,
proposalId: proposalId,
});
}

console.log(
"To use this fork on the aave interface type the following commands in the console."
);
console.log("--------------");
console.log(`localStorage.setItem('forkEnabled', 'true');`);
console.log(`localStorage.setItem('forkBaseChainId', 1);`);
console.log(
`localStorage.setItem('forkNetworkId', ${options.forkNetworkId});`
);
console.log(`localStorage.setItem("forkRPCUrl", "${fork.forkUrl}");`);
console.log("--------------");

/**
* Don't delete forks that were created externally or set to stay alive
*/
if (!options.keepAlive && !options.forkId)
listenForInterruptAndKill(fork.forkId);
});

program.parse();
Loading

0 comments on commit 55dd3cc

Please sign in to comment.