-
Notifications
You must be signed in to change notification settings - Fork 4
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
feature: scripts for fetching plan execution statuses #5
base: master
Are you sure you want to change the base?
Changes from 1 commit
31b5de0
ce24f31
daf06e7
23e4b28
7a8774b
e37ee56
5db40df
2ea1010
4f032ba
41ea82d
5843d92
f6e02c3
56872ae
c409944
e8f7944
6dd5ce3
a683b60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# project | ||
.env* | ||
|
||
# node | ||
node_modules/ | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Protego Scripts | ||
|
||
## Usage | ||
|
||
### 1. Install dependencies | ||
|
||
``` | ||
npm i | ||
``` | ||
|
||
### 2. Run scripts | ||
|
||
List the 20 most recent plans in `MCD_PAUSE` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that instead of fixing an arbitrary number of events to return, we could maybe let the user specify how many blocks they want to go in the past. However, that introduces one edge case: events for the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in f6e02c3 |
||
``` | ||
npm run list | ||
``` | ||
|
||
Full list of plans in `MCD_PAUSE` | ||
``` | ||
npm run list-all | ||
``` | ||
|
||
Pending plans in `MCD_PAUSE` | ||
``` | ||
npm run list-pending | ||
``` | ||
|
||
## Output | ||
|
||
``` | ||
╔════════════════════════════════════════════════════════════════════╤════════════════════════════════════════════╤════════════════════════════════════════════════════════════════════╤═══════════════════════════════════╤════════════╤════════════╗ | ||
║ HASH │ USR │ TAG │ FAX │ ETA │ STATUS ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0xafce2325ab2957ec8a85cbc9bc0f8e079f8ea73df2e07eeafaf7f3c79c04576c │ 0xb7fdC60f7497759e1c144a8cf2969B3B352c37F7 │ 0x7f06e43eb0c4a2e7aa90272bc257b5fc6247838ba2d8944095751fa10d9d7616 │ 0x61461954 │ 1711697219 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x3b3a337ff1df6e96cbd3633e40c2bb076fd04b1bbcf0a81a4c1dfebe06c63ef2 │ 0x9A09E438266f55dC4b3135CbfE1F491f96a13313 │ 0x94068fe76609e1472bc39801268135e6b841195826c64ae470c80585d2750fa1 │ 0x61461954 │ 1712569127 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x2b48073bf5814be9be04bb86077f5b10cf5c8119c17d5d52fda1121aca7e5e1c │ 0xE4768597ca81df6f2FD27945016b03E96a3a7E1D │ 0x06dbd46347fe80f471dc8e6dc30ead3411d21c4896671e3c8acf040557fee896 │ 0x61461954 │ 1713993803 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x271d6ce5a94bc0df848bd6f98b435fc6a80a1cd0270119f2b8fc0d2f8adaffe7 │ 0x45BbEAA4111b907c2bD1244701Ea34Df1d13B9a7 │ 0xdbf8118b76005c63d7aede2746c48bb738ba07995e019c33e52bd851a51d56bc │ 0x61461954 │ 1715198375 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0xfd391f7c694cf20870527de9427e7ac326ad133aced2a7c9e072a27d9057a621 │ 0x6A65D46645bC7C1aE4C95f5f00968e48aDd009C3 │ 0x8d56f5149ab50c0f290a4942cc692ce72111d4e98473f8f7ead1d0c4e37a1724 │ 0x61461954 │ 1716062519 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x2eb42ca4e054352eaa8ef09705925b3c12b4c0d1a59a050a20baa2b9d44396a8 │ 0x612938f231DFcd7F92181F11C9E0B575E7ed2Ec1 │ 0x25f5bbaef576d0cf62af933ec55a6bd468b65fa9902387040283da6bf88ea4a9 │ 0x61461954 │ 1717623383 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0xd37c72ea00f67c76b6cda8dc0dda0b1b6f825145079e9acd23bdbcfe00259a3e │ 0x6481e7443D321fFF02A9A7ae883DCd13FAb64Ef7 │ 0xf218b00aeb30403e97dbedd8542caf1a879c0e15796a20b5836cfadfe9a69b43 │ 0x61461954 │ 1718481719 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x9ca00512f5e87da33fa1fa1e4834581c8684ebd9091c7883355ea0ca959a78f2 │ 0x261da1Cdbd788642034288B6574d749198FDf75b │ 0x5e8fe783452994a42bbbe3b0edde5b9901ff6bd7561b680b42af92293206bb32 │ 0x61461954 │ 1719777527 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0xb8f4b59cbfe45ba425eb9c10c8a50bd1eb919325eefdf095c44369098fd21e59 │ 0x0871e28D09c29C419669D82901d53d60A649B36D │ 0xc8dec11fc102e8810674c4db724fb129a790f93767cf54b691cbe3d2d33dd3d8 │ 0x61461954 │ 1720383443 │ EXECUTED ║ | ||
╟────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────┼────────────────────────────────────────────────────────────────────┼───────────────────────────────────┼────────────┼────────────╢ | ||
║ 0x11e3af57c6821e4b4b45559c92f5c9da681f2b7d2d232f91d7b64aa14d317f6a │ 0xA13D7e21643bD46E2cC09E87cFB91c5B951Bd955 │ 0x041f68b86ef5961f3d578a7192a09f1980b42bcefa8fecb810816369420c1e0c │ 0x61461954 │ 1721070179 │ EXECUTED ║ | ||
╚════════════════════════════════════════════════════════════════════╧════════════════════════════════════════════╧════════════════════════════════════════════════════════════════════╧═══════════════════════════════════╧════════════╧════════════╝ | ||
``` | ||
|
||
The script outputs a table with the plans' details: | ||
- HASH: Hash of the plan | ||
- USR: Address of the Spell | ||
oddaf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- TAG: `extcodehash` from the address of the Spell | ||
oddaf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- FAX: `callcode` to be used when calling the Spell | ||
- ETA: Timestamp of earliest execution time | ||
- STATUS: Status of the plan: | ||
- PENDING: The plan has been plotted (scheduled) on Pause, and is pending execution | ||
- EXECUTED: The plan has already been executed | ||
- DROPPED: The plan was scheduled and subsequently dropped |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,146 @@ | ||||||
import { ethers } from 'ethers'; | ||||||
import { table } from 'table'; | ||||||
import yargs from 'yargs'; | ||||||
import { hideBin } from 'yargs/helpers'; | ||||||
import pauseABI from './pause_abi.json' with { type: 'json' }; | ||||||
|
||||||
const argv = yargs(hideBin(process.argv)) | ||||||
.option('all', { | ||||||
alias: 'a', | ||||||
type: 'boolean', | ||||||
description: 'Show all plans', | ||||||
default: false | ||||||
}) | ||||||
.option('pending', { | ||||||
alias: 'p', | ||||||
type: 'boolean', | ||||||
description: 'Show only pending plans', | ||||||
default: false | ||||||
}) | ||||||
.check(argv => { | ||||||
if (argv.all && argv.pending) { | ||||||
throw new Error("You cannot use --all and --pending together."); | ||||||
} | ||||||
return true; | ||||||
}) | ||||||
.help() | ||||||
.alias('help', 'h') | ||||||
.argv; | ||||||
|
||||||
const PLOT_TOPIC = "0x46d2fbbb00000000000000000000000000000000000000000000000000000000"; | ||||||
const EXEC_TOPIC = "0x168ccd6700000000000000000000000000000000000000000000000000000000"; | ||||||
const DROP_TOPIC = "0x162c7de300000000000000000000000000000000000000000000000000000000"; | ||||||
const MCD_PAUSE = "0xbE286431454714F511008713973d3B053A2d38f3"; | ||||||
|
||||||
const tableConfig = { | ||||||
columns: { | ||||||
0: { width: 66, wrapWord: true }, | ||||||
1: { width: 42, wrapWord: true }, | ||||||
2: { width: 66, wrapWord: true }, | ||||||
3: { width: 33, wrapWord: true }, | ||||||
4: { width: 10, wrapWord: true }, | ||||||
5: { width: 10, wrapWord: true }, | ||||||
6: { width: 10, wrapWord: true } | ||||||
amusingaxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
}; | ||||||
|
||||||
function getProvider() { | ||||||
const url = process.env.ETH_RPC_URL || "mainnet"; | ||||||
if (!process.env.ETH_RPC_URL) { | ||||||
console.warn("ETH_RPC_URL not set, falling back to a public RPC provider. For improved results set ETH_RPC_URL to a trusted node."); | ||||||
} | ||||||
return ethers.getDefaultProvider(url); | ||||||
} | ||||||
|
||||||
function decodeLogNote(log, contract) { | ||||||
const eventFragment = contract.interface.getEvent('LogNote'); | ||||||
return contract.interface.decodeEventLog(eventFragment, log.data, log.topics).toObject(); | ||||||
} | ||||||
|
||||||
function decodeCallParams(sig, fax, contract) { | ||||||
const functionFragment = contract.interface.getFunction(sig); | ||||||
return contract.interface.decodeFunctionData(functionFragment, fax).toObject(); | ||||||
} | ||||||
|
||||||
function hash(params) { | ||||||
const abiCoder = new ethers.AbiCoder(); | ||||||
const types = ["address", "bytes32", "bytes", "uint256"]; | ||||||
const encoded = abiCoder.encode(types, [params.usr, params.tag, params.fax, params.eta]); | ||||||
return ethers.keccak256(encoded); | ||||||
} | ||||||
|
||||||
async function getFilteredEvents(contract) { | ||||||
try { | ||||||
const events = await contract.queryFilter('*'); | ||||||
return events.filter(log => [PLOT_TOPIC, EXEC_TOPIC, DROP_TOPIC].includes(log.topics[0])); | ||||||
amusingaxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} catch (error) { | ||||||
console.error("Error fetching filtered events:", error); | ||||||
throw error; | ||||||
} | ||||||
} | ||||||
|
||||||
function processEvent(event, contract) { | ||||||
const decoded = decodeLogNote(event, contract); | ||||||
const decodedCall = decodeCallParams(event.topics[0].slice(0, 10), decoded.fax, contract); | ||||||
return { | ||||||
...event, | ||||||
decoded, | ||||||
decodedCall, | ||||||
planHash: hash(decodedCall) | ||||||
}; | ||||||
} | ||||||
|
||||||
function prepareTableData(events, contract) { | ||||||
const decodedEvents = events.map(event => processEvent(event, contract)); | ||||||
|
||||||
let tableData = [["HASH", "USR", "TAG", "FAX", "ETA", "STATUS"]]; | ||||||
const hashMap = new Map(); | ||||||
|
||||||
decodedEvents.forEach(event => { | ||||||
const planHash = event.planHash; | ||||||
|
||||||
if (event.topics[0] === PLOT_TOPIC) { | ||||||
const row = [planHash, event.decodedCall.usr, event.decodedCall.tag, event.decodedCall.fax.trim(), event.decodedCall.eta, "PENDING"]; | ||||||
tableData.push(row); | ||||||
hashMap.set(planHash, row); | ||||||
} else if (event.topics[0] === EXEC_TOPIC) { | ||||||
const row = hashMap.get(planHash); | ||||||
if (row) { | ||||||
row[5] = "EXECUTED"; | ||||||
} | ||||||
} else if (event.topics[0] === DROP_TOPIC) { | ||||||
const row = hashMap.get(planHash); | ||||||
if (row) { | ||||||
row[5] = "DROPPED"; | ||||||
} | ||||||
} | ||||||
}); | ||||||
|
||||||
return tableData; | ||||||
} | ||||||
amusingaxl marked this conversation as resolved.
Show resolved
Hide resolved
amusingaxl marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
async function main() { | ||||||
try { | ||||||
const provider = getProvider(); | ||||||
const pause = new ethers.Contract(MCD_PAUSE, pauseABI, provider); | ||||||
|
||||||
const events = await getFilteredEvents(pause); | ||||||
let tableData = prepareTableData(events, pause); | ||||||
|
||||||
if (!argv.all && !argv.pending) { | ||||||
tableData = tableData.length > 21 ? [tableData[0], ...tableData.slice(-20)] : tableData; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the suggestion about data sorting by newest values first is applied, this can be simplified as:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic was removed in favor of the fromBlock parameter: f6e02c3 |
||||||
} else if (argv.pending) { | ||||||
tableData = tableData.filter(row => row[6] === "pending" || row[0] === "HASH"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comparison will fail because of mismatching cases:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also in general, I would prefer to keep the presentation layer as simple as possible and do all filtering when data is being fetched. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
} | ||||||
|
||||||
if (tableData.length === 1) { | ||||||
console.log("No records to display."); | ||||||
} else { | ||||||
console.log(table(tableData, tableConfig)); | ||||||
} | ||||||
} catch (error) { | ||||||
console.error("An error occurred:", error); | ||||||
} | ||||||
} | ||||||
|
||||||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented in the README,
usr
usually refers to theDssSpellAction
for conforming spells, not to the spell itself.I believe the script should somehow return the associated spell address. I'm not entirely sure how to get that information, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I just noticed that
msg.sender
is logged as topic 1:https://vscode.blockscan.com/ethereum/0xbe286431454714f511008713973d3b053a2d38f3#L43
For conforming spells, this can be used to obtain the spell address.
Since it's not guaranteed, maybe the column should be named
SENDER
and the documentation should explain that this COULD be the spell address 🤷🏻♂️There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 5843d92