This repository has been archived by the owner on Oct 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
732 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
node_modules | ||
.env | ||
.idea/ | ||
.idea/ | ||
*.tgz | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.env | ||
.idea/ | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.