Skip to content

Commit

Permalink
feat: decode evm script + pause prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
krogla committed Oct 23, 2023
1 parent b838209 commit d31d37f
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 32 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"ethereumjs-testrpc-sc": "^6.5.1-sc.1",
"ethereumjs-util": "^7.0.8",
"ethers": "^5.1.4",
"evm-script-decoder": "git+https://github.com/lidofinance/evm-script-decoder.git#v0.2.2",
"ganache": "=7.6.0",
"hardhat": "2.12.7",
"hardhat-contract-sizer": "^2.5.0",
Expand Down
96 changes: 67 additions & 29 deletions scripts/simpledvt/02-clone-nor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const chalk = require('chalk')
const { Contract } = require('ethers')
const { encodeCallScript } = require('@aragon/contract-helpers-test/src/aragon-os')
const { getEventArgument } = require('@aragon/contract-helpers-test')
const { EVMScriptDecoder, abiProviders } = require('evm-script-decoder')
const runOrWrapScript = require('../helpers/run-or-wrap-script')
const { log, yl, gr } = require('../helpers/log')
const { log, yl, gr, cy } = require('../helpers/log')
// const { saveCallTxData } = require('../helpers/tx-data')
const { resolveLatestVersion } = require('../components/apm')
const {
Expand All @@ -27,6 +28,8 @@ const {
STAKING_MODULE_MANAGE_ROLE,
REQUEST_BURN_SHARES_ROLE,
SIMPLE_DVT_IPFS_CID,
easyTrackABI,
_pause,
} = require('./helpers')
const { ETH, toBN } = require('../../test/helpers/utils')

Expand Down Expand Up @@ -67,8 +70,6 @@ async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid

log(`Using ENS:`, yl(state.ensAddress))
const ens = await artifacts.require('ENS').at(state.ensAddress)
const lidoLocatorAddress = readStateAppAddress(state, `lidoLocator`)
log(`Lido Locator:`, yl(lidoLocatorAddress))
log.splitter()

const srcAppFullName = `${srcAppName}.${state.lidoApmEnsName}`
Expand Down Expand Up @@ -111,7 +112,6 @@ async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid
treasuryFee = 500,
penaltyDelay,
easyTrackAddress,
easyTrackEVMScriptExecutor,
easyTrackFactories = {},
} = state[`app:${trgAppName}`].stakingRouterModuleParams
log(`Target SR Module name`, yl(moduleName))
Expand All @@ -134,7 +134,7 @@ async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid
return
}

// preload voting and stakingRouter addresses
const lidoLocatorAddress = readStateAppAddress(state, `lidoLocator`)
const votingAddress = readStateAppAddress(state, `app:${APP_NAMES.ARAGON_VOTING}`)
const tokenManagerAddress = readStateAppAddress(state, `app:${APP_NAMES.ARAGON_TOKEN_MANAGER}`)
const srAddress = readStateAppAddress(state, 'stakingRouter')
Expand All @@ -156,29 +156,34 @@ async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid
const burnerAddress = readStateAppAddress(state, `burner`)
const burner = await artifacts.require('Burner').at(burnerAddress)

const easytrackABI = [
{
inputs: [
{
internalType: 'address',
name: '_evmScriptFactory',
type: 'address',
},
{
internalType: 'bytes',
name: '_permissions',
type: 'bytes',
},
],
name: 'addEVMScriptFactory',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
]
log.splitter()
log(`DAO Kernel`, yl(kernelAddress))
log(`ACL`, yl(aclAddress))
log(`Voting`, yl(votingAddress))
log(`Token manager`, yl(tokenManagerAddress))
log(`LDO token`, yl(daoTokenAddress))
log(`Lido APM`, yl(state.lidoApmAddress))
log(`Staking Router`, yl(srAddress))
log(`Burner`, yl(burnerAddress))
log(`Lido Locator:`, yl(lidoLocatorAddress))

log.splitter()

// use ethers.js Contract instance
const easytrack = new Contract(easyTrackAddress, easytrackABI)
const easytrack = new Contract(easyTrackAddress, easyTrackABI).connect(ethers.provider)
const easyTrackEVMScriptExecutor = await easytrack.evmScriptExecutor()

log(`EasyTrack`, yl(easyTrackAddress))
log(`EasyTrack EVM Script Executor`, yl(easyTrackEVMScriptExecutor))

for (const f of Object.keys(easyTrackFactories)) {
log(`EasyTrack Factory <${cy(f)}>`, yl(easyTrackFactories[f]))
}

log.splitter()
await _pause()
log.splitter()

const evmScriptCalls = [
// create app repo
{
Expand Down Expand Up @@ -351,12 +356,45 @@ async function deploySimpleDVT({ web3, artifacts, trgAppName = APP_TRG, ipfsCid
calldata: await agent.contract.methods.execute(stakingRouter.address, 0, addModuleCallData).encodeABI(),
})

const evmScript = encodeCallScript(evmScriptCalls)

const evmScriptDecoder = new EVMScriptDecoder(
new abiProviders.Local({
[kernel.address]: kernel.abi,
[acl.address]: acl.abi,
[voting.address]: voting.abi,
[agent.address]: agent.abi,
[stakingRouter.address]: stakingRouter.abi,
[apmRegistry.address]: apmRegistry.abi,
[trgApp.address]: trgApp.abi,
[easytrack.address]: easyTrackABI,
})
)

const decodedEVMScript = await evmScriptDecoder.decodeEVMScript(evmScript)

log('Decoded voting script:')
for (const call of decodedEVMScript.calls) {
if (call.abi) {
const params = {}
const inputs = call.abi.inputs || []
for (let i = 0; i < inputs.length; ++i) {
params[inputs[i].name] = call.decodedCallData[i]
}
log({ contract: call.address, method: call.abi.name, params })
} else {
log(call)
}
}

log.splitter()
await _pause()
log.splitter()

const newVoteEvmScript = encodeCallScript([
{
to: voting.address,
calldata: await voting.contract.methods
.newVote(encodeCallScript(evmScriptCalls), voteDesc, false, false)
.encodeABI(),
calldata: await voting.contract.methods.newVote(evmScript, voteDesc, false, false).encodeABI(),
},
])

Expand Down
116 changes: 115 additions & 1 deletion scripts/simpledvt/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const readline = require('readline')
const { assert } = require('chai')
const { log } = require('../helpers/log')
const { log, rd, mg } = require('../helpers/log')

const KERNEL_APP_BASES_NAMESPACE = '0xf1f3eb40f5bc1ad1344716ced8b8a0431d840b5783aea1fd01786bc26f35ac0f'

Expand All @@ -11,6 +12,100 @@ const STAKING_MODULE_MANAGE_ROLE = '0x3105bcbf19d4417b73ae0e58d508a65ecf75665e46
const REQUEST_BURN_SHARES_ROLE = '0x4be29e0e4eb91f98f709d98803cba271592782e293b84a625e025cbb40197ba8'
const SIMPLE_DVT_IPFS_CID = 'QmaSSujHCGcnFuetAPGwVW5BegaMBvn5SCsgi3LSfvraSo'

const easyTrackABI = [
{
inputs: [],
name: 'evmScriptExecutor',
outputs: [{ internalType: 'contract IEVMScriptExecutor', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '_evmScriptFactory',
type: 'address',
},
{
internalType: 'bytes',
name: '_permissions',
type: 'bytes',
},
],
name: 'addEVMScriptFactory',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
name: 'evmScriptFactories',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: '', type: 'address' }],
name: 'evmScriptFactoryPermissions',
outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getEVMScriptFactories',
outputs: [{ internalType: 'address[]', name: '', type: 'address[]' }],
stateMutability: 'view',
type: 'function',
},

{
inputs: [{ internalType: 'address', name: '_maybeEVMScriptFactory', type: 'address' }],
name: 'isEVMScriptFactory',
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
stateMutability: 'view',
type: 'function',
},
]

const easyTrackEvmExecutorABI = [
{
inputs: [{ internalType: 'bytes', name: '_evmScript', type: 'bytes' }],
name: 'executeEVMScript',
outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
stateMutability: 'nonpayable',
type: 'function',
},
]

const easyTrackFactoryABI = [
{
inputs: [
{ internalType: 'address', name: '_creator', type: 'address' },
{ internalType: 'bytes', name: '_evmScriptCallData', type: 'bytes' },
],
name: 'createEVMScript',
outputs: [{ internalType: 'bytes', name: '', type: 'bytes' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'nodeOperatorsRegistry',
outputs: [{ internalType: 'contract INodeOperatorsRegistry', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'trustedCaller',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
]

async function getDeployer(web3, defaultDeployer) {
if (!defaultDeployer) {
const [firstAccount] = await web3.eth.getAccounts()
Expand Down Expand Up @@ -38,11 +133,27 @@ function _checkEq(a, b, descr = '') {
log.success(descr)
}

function _pause(query = mg('>>> Enter Y to continue, interrupt process otherwise:')) {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })

return new Promise((resolve) =>
rl.question(query, (ans) => {
rl.close()
if (ans !== 'y' && ans !== 'Y') {
console.error(rd('Process aborted'))
process.exit(1)
}
resolve()
})
)
}

module.exports = {
readStateAppAddress,
getDeployer,
getSignature,
_checkEq,
_pause,
KERNEL_APP_BASES_NAMESPACE,
MANAGE_SIGNING_KEYS,
MANAGE_NODE_OPERATOR_ROLE,
Expand All @@ -51,4 +162,7 @@ module.exports = {
STAKING_MODULE_MANAGE_ROLE,
REQUEST_BURN_SHARES_ROLE,
SIMPLE_DVT_IPFS_CID,
easyTrackABI,
easyTrackEvmExecutorABI,
easyTrackFactoryABI,
}
26 changes: 24 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/abi@npm:5.7.0, @ethersproject/abi@npm:^5.0.0-beta.146, @ethersproject/abi@npm:^5.0.9, @ethersproject/abi@npm:^5.7.0":
"@ethersproject/abi@npm:5.7.0, @ethersproject/abi@npm:^5.0.0-beta.146, @ethersproject/abi@npm:^5.0.7, @ethersproject/abi@npm:^5.0.9, @ethersproject/abi@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/abi@npm:5.7.0"
dependencies:
Expand Down Expand Up @@ -3765,6 +3765,7 @@ __metadata:
ethereumjs-testrpc-sc: ^6.5.1-sc.1
ethereumjs-util: ^7.0.8
ethers: ^5.1.4
evm-script-decoder: "git+https://github.com/lidofinance/evm-script-decoder.git#v0.2.2"
ganache: =7.6.0
hardhat: 2.12.7
hardhat-contract-sizer: ^2.5.0
Expand Down Expand Up @@ -7729,7 +7730,7 @@ __metadata:
languageName: node
linkType: hard

"bn.js@npm:^5.2.1":
"bn.js@npm:^5.2.0, bn.js@npm:^5.2.1":
version: 5.2.1
resolution: "bn.js@npm:5.2.1"
checksum: 4693b52187524b856422b133cb2168ab5d593981891cb213e0565f5355008539f3887291f69c5ae2b254743c6c8d062ab7b69983e19bd00060023517d0a7ca8b
Expand Down Expand Up @@ -13182,6 +13183,16 @@ __metadata:
languageName: node
linkType: hard

"evm-script-decoder@git+https://github.com/lidofinance/evm-script-decoder.git#v0.2.2":
version: 0.2.2
resolution: "evm-script-decoder@https://github.com/lidofinance/evm-script-decoder.git#commit=7bf9f89234e4504bf8246bdd3eb6cd43ad4c0709"
dependencies:
"@ethersproject/abi": ^5.0.7
keccak256: ^1.0.3
checksum: c1f9ca3c4cc0710e0a080493c6bac533611f0bd6ebb076c6928ced5fa82ab2782fce7d1ded250950b803f4be2c7a79315754bcd311d81a552e402c7b3a65916f
languageName: node
linkType: hard

"evp_bytestokey@npm:^1.0.0, evp_bytestokey@npm:^1.0.3":
version: 1.0.3
resolution: "evp_bytestokey@npm:1.0.3"
Expand Down Expand Up @@ -18187,6 +18198,17 @@ fsevents@~2.3.2:
languageName: node
linkType: hard

"keccak256@npm:^1.0.3":
version: 1.0.6
resolution: "keccak256@npm:1.0.6"
dependencies:
bn.js: ^5.2.0
buffer: ^6.0.3
keccak: ^3.0.2
checksum: 5f7649021b30167c545dcf937aab5c93a2bb612f62722fa102e53d5c529feb3e4e4ab11baf7a2e419bf8d3bcc90a00fa6822e3095017fce2873679f2469c34ab
languageName: node
linkType: hard

"keccak@npm:3.0.1, keccak@npm:^3.0.0":
version: 3.0.1
resolution: "keccak@npm:3.0.1"
Expand Down

0 comments on commit d31d37f

Please sign in to comment.