v0.7.0
v0.7.0 - Branchy Syntax
This version comprises a complete refactoring and restructuring of the library.
Embrace modularity. The evmcl command language (which is now called cas11) has been converted into a formal fully-fledged DSL (Domain-specific Language) comprise of composable and independent parser combinators that receive the raw cas11 script and produce the nodes of a AST (Abstract Syntax Tree) which will be later on processed by an interpreter (the evmcrispr).
The different commands and helpers have been moved to separated encapsulated modules following the separation of concerns principle. In this way, new web3 protocols can be supported and integrated more easily.
How to use
import { EVMcrispr, parseScript } from '@1hive/evmcrispr';
async function main() {
const { ast, errors } = parseScript(script);
if (errors.length) {
// handle errors
} else {
const evmcrispr = new EVMcrispr(ast, ethersSigner)
const actions = await evmcrispr.interpret();
// execute actions
}
}
New features
-
New
switch <network name or id>
command that allows you to dynamically switch the chain. -
New
load <module> [as <alias>]
command that allows you to import the modules containing a set of commands and helpers. At the moment, there are two modules:std
: the core module which is not required to import. It contains the following:- Commands:
load
,exec
andset
andswitch
. - Helpers:
@date
,@get
,@id
,@ipfs
,@me
,@token
and@token.balance
.
- Commands:
aragonos
: Aragon module that contains the following:- Commands:
act
,connect
,forward
,grant
,install
,new-dao
,new-token
,revoke
andupgrade
- Helpers:
@aragonEns
.
- Commands:
When loading a module, you have access to all its commands and helpers. In the case of commands, you need to prefix the module name in order to use them.
Also, it's not necessary to prefix the commands of a specific module when they're used inside a block expression of a command of the same module.
Here's an example where we use thearagonos
module to better understand these concepts:load aragonos as ar ar:connect 1hive token-manager voting ( install agent:new grant voting token-manager ISSUE_ROLE voting )
Note an alias (in this case "ar") has been set for the module. In order to use the
connect
command, we need to prefix it.
Also note that thearagonos
commands inside theconnect
block scope aren't prefixed. -
New call operator
<contractAddress>::<method>(<args>)
to call read-only contract functions. Example:load aragonos as ar ar:connect myDAO ( set $var1 token-manager exec token-manager::token() transfer(address,uint256) vault 2500e18 exec $var1::token() transfer(address,uint256) vault 2500e18 set $var2 @token(DAI)::decimals() )
It also supports chainable calls. Here's an example:
load aragonos as ar ar:connect myDAO ( set $var1 token-manager::token()::decimals() )
At the moment it only supports calls to functions that return primitive data types.
-
@calc()
helper has been deprecated in favor of native arithmetic expression operations that support priority parenthesis. Example:set $var1 (@token.balance(DAI, @me) * (5 - myContract::aMethodReturningNumber()))
. -
Complete support of nested expression structures (e.g. arrays, block command expressions, call expressions, helper expressions, etc).
-
Support of nested
connect
commands that allow you to define DAO-to-DAO operations scripts and have access to different organizations' apps inside a scope.
You can reference a different DAO's app by their name, address or nesting index. The format would be as follow:_<dao>:<app-identifier>
.
Example:load aragonos as ar ar:connect mainDAO ( ar:connect subDAO tollgate token-manager voting ( # It grants mainDAO's voting app permissions to create votes in # subDAO's voting app. grant _mainDAO:voting voting CREATE_VOTES_ROLE # Here the nesting index "_1" is the same as "_myDAO". grant _1:voting token-manager MINT_ROLE ) )
-
The
forward <...path> ( <...commands> )
command is back. It allows you to customize the forward path by not having to define it in theconnect
command. This can be helpful when creating scripts that will be sent through a forwarding path composed of apps from different DAOs. Example:load aragonos as ar ar:connect mainDAO ( ar:connect committeeDAO ( forward _mainDAO:token-manager token-manager ( ... ) ) )
-
Option arguments can now be used in-between commands. Example
my-command --anOpt 1e18 anotherArg --anotherOpt 1e18 anotherArg
. -
Improved error handling logic that displays the location (line and column number) and type of the failed expression along with the error message.
-
Parser combinators implement error recovering logic which allows them to scan the whole script looking for the maximum number of syntax errors.