-
Notifications
You must be signed in to change notification settings - Fork 4
Encode command for Protego CLI #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
d086221
feat: add encode CLI command
oddaf 0978077
feat: encode
oddaf ba76403
chore: update table header
oddaf 28f8341
chore: update cli readme
oddaf 02eff26
chore: formatting
oddaf 66a00b7
fix: fix evm version to avoid conflicts in fork tests
oddaf 1db9c2d
refactor: list command (no longer default)
oddaf dac05a8
Apply suggestions from code review
oddaf a12ec20
Merge branch 'feat/cli-encode' of https://github.com/makerdao/protego…
oddaf 808db10
refactor: use createJson on encode command
oddaf 4742b37
refactor: move no records to display msg to cli functions
oddaf e8865a4
refactor: project structure
oddaf da52695
chore: readme
oddaf 1d69622
chore: formatting
oddaf 35913b8
refactor: global options
oddaf 1621108
chore: formatting
oddaf 5ac801e
refactor: remove npm scripts
oddaf 515e393
chore: update readme
oddaf 12ab27d
fix: restore test script
oddaf 074b5ac
refactor: add guy to encode command prompt
oddaf dfbb0d9
feat: readable date/time for ETA
oddaf 54beb18
refactor: format hex on encode command
oddaf b899de3
chore: update readme
oddaf 55149b7
fix: guy in cli encode command
oddaf c1c881b
refactor: display timestamp on table along with readable date
oddaf 60704ca
refactor: format hex strings on list command table (cli)
oddaf 1f83dcf
refactor: use short year
oddaf f995105
refactor: improve date formatting
oddaf be7d555
chore: Improve cli readme
oddaf 888a6ab
refactor: JSON loading without experimental features
oddaf 7de943b
refactor: Encode command description
oddaf 6cfc040
Apply suggestions from code review
oddaf 12d6d63
refactor: move loadJson right after createJson
oddaf 85d404a
Update cli/package.json
oddaf e4f4c49
update docs for sky-ecosystem npm org
oddaf 4818fe3
chore: bump npm version (minor)
oddaf 511685c
Update cli/list.js
oddaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,69 @@ | ||
| import chalk from "chalk"; | ||
| import { ethers } from "ethers"; | ||
| import prompts from "prompts"; | ||
| import { fetchPausePlans } from "./fetchPausePlans.js"; | ||
| import defaults from "./defaults.js"; | ||
| import { ttyOnlySpinner, createJson, formatDate, formatHex } from "./utils.js"; | ||
|
|
||
| /** | ||
| * Runs the CLI Encode command | ||
| * @param {object} localOptions Command options (currently unused) | ||
| * @param {import("commander").Command} command Commander command object | ||
| * @returns {Promise<void>} | ||
| */ | ||
| export async function encode(localOptions, command) { | ||
| const { rpcUrl, fromBlock, pauseAddress } = command.optsWithGlobals(); | ||
|
|
||
| if (rpcUrl === defaults.RPC_URL) { | ||
| console.warn( | ||
| chalk.yellow( | ||
| `🟡 WARNING: Falling back to a public provider: ${rpcUrl}. For a better experience, set a custom RPC URL with the --rpc-url <rpc-url> option or the ETH_RPC_URL env variable.`, | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| const spinner = ttyOnlySpinner().start("Fetching pending pause plans..."); | ||
|
|
||
| try { | ||
| const pause = new ethers.Contract( | ||
| pauseAddress, | ||
| defaults.MCD_PAUSE_ABI, | ||
| ethers.getDefaultProvider(rpcUrl), | ||
| ); | ||
|
|
||
| const plans = await fetchPausePlans(pause, { | ||
| fromBlock, | ||
| status: "PENDING", | ||
| }); | ||
| spinner.success("Done!"); | ||
|
|
||
| if (plans.length === 0) { | ||
| console.log(chalk.yellow("No pending spells found to encode.")); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const response = await prompts([ | ||
| { | ||
| type: "multiselect", | ||
| name: "plans", | ||
| message: | ||
| "Select spells to be encoded for `drop(Plan[] calldata _plans)`", | ||
| choices: plans.map((plan) => ({ | ||
| title: `guy: ${formatHex(plan.guy)} | hash: ${formatHex(plan.hash)} | usr: ${formatHex(plan.usr)} | eta: ${plan.eta} (${formatDate(plan.eta)} UTC)`, | ||
| value: plan.hash, | ||
| })), | ||
| }, | ||
| ]); | ||
|
|
||
| const selectedPlans = plans | ||
| .filter((plan) => response.plans.includes(plan.hash)) | ||
| .map((plan) => [plan.usr, plan.tag, plan.fax, plan.eta.toString()]); | ||
|
|
||
| console.log("\nEncoded plans:"); | ||
| console.log(chalk.green(createJson(selectedPlans))); | ||
| } catch (error) { | ||
| spinner.error("Failed!"); | ||
| console.error(chalk.red("An error occurred:", error)); | ||
| process.exit(1); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.