@1hive/evmcrispr 中文文档教程

发布于 3年前 浏览 33 更新于 3年前

EVMcrispr

覆盖状态docs

EVMcrispr 仍在积极开发中,其 API 可能会更改,直到达到 1.0。

一个用于基于 Aragon 的 DAO 的 TypeScript 库,它允许您将一系列操作编码为 EVM 脚本,该脚本可以发送到转发器应用

操作可以被认为是 DAO 内的某个实体执行的事件,例如安装应用程序、授予或撤销权限、铸造令牌、提取资金等。

Documentation

查看 文档 以获得对 API 的深入解释。

How does it work?

EVMcrispr 提供了两种主要方法来创建包含动作的 EVM 脚本:encode()forward()(此方法对动作进行编码并在之后转发)。

这两种方法都接收两个参数:一组编码的动作和一组用于转发上述动作的转发器应用程序。

该库公开了一系列方法,允许您对不同的操作进行编码,例如安装应用程序、撤销权限等。我们的想法是在 encode()forward 中调用这些方法() 构建脚本。 下面是一个示例:

await evmcrispr.forward(
  [
    evmcrispr.install(app, params),
    evmcrispr.grantPermissions([permission1, permission2, permission3]),
    evmcrispr.revoke(permission, removeManager),
    // ...
  ],
  // forwarder apps path.
  [forwarder1, forwarder2]
);

可以使用 evmcl 模板对相同的 EVM 脚本进行编码:

await evmcripsr.forward(
  evmcl`
    install ${app} ${param1} ${param2}
    grant ${entity1} ${app1} ${role1} ${permissionManager}
    grant ${entity2} ${app2} ${role1} ${permissionManager}
    grant ${entity3} ${app3} ${role3} ${permissionManager}
    revoke ${entity4} ${app4} ${role4} ${removeManager}
  `, // ...
  [forwarder1, forwarder2]
);

为了方便 EVM 脚本的创建,您可以使用 identifiers 引用 DAO 应用程序而不是直接使用合约地址。

您可以在下面找到一个完整的示例:

await evmcrispr.forward(
  evmcl`
    install wrapped-hooked-token-manager.open:membership-tm ${token} false 0
    install voting:membership-voting ${token} ${suppPct} ${minQuorumPct} ${voteTime}
    grant ANY_ENTITY voting:membership-voting CREATE_VOTES_ROLE
    grant voting:membership-voting wrapped-hooked-token-manager.open:membership-tm MINT_ROLE
    grant voting:membership-voting wrapped-hooked-token-manager.open:membership-tm BURN_ROLE
    exec wrapped-hooked-token-manager.open:membership-tm mint ${address} 2e18
  `,
  ["token-manager:1", "voting"]
);

Set up

  1. Add the following dependency to your project:
   yarn add @1hive/evmcrispr
  1. Import the EVMcrispr class and the evmcl template:
   import { EVMcrispr, evmcl } from '@1hive/evmcrispr'
  1. Create a new EVMcrispr by using the static method crate(). It receives an ether's Signer object and the DAO address to connect to:
   const evmcrispr = await EVMcrispr.create(signer, daoAddress);
  1. Use the EVMcrispr's encode or forward functions to pass an array of actions, or an evmcl script.

Parametric permission utils

以下实用程序可用于对复杂的权限参数进行编码:

  • arg(i): Can be used to compare the ith parameter with a given value.
  • oracle(address): Can be used to check the output of an external contract
  • blocknumber: Can be used to compare a given value with the block number.
  • timestamp: Can be used to compare a given value with the block timestamp.
  • not(param): Can be used to negate a parameter.
  • and(param1, param2): Can be used to compose two parameters with the AND logical function.
  • or(param1, param2): Same as previous one with the OR logical function.
  • xor(param1, param2): Same as the previous one with the XOR logical function.
  • iif(param).then(param).else(param): Ternary operator for more complex logic expressions.

它们可以在 grant(entity, app, role, params) 函数的第四个参数中使用。

Other examples

您可以在下面找到一些使用 EVMcrispr 的脚本示例:

Contributing

我们欢迎社区贡献!

请查看我们未解决的问题以开始使用。

EVMcrispr

Coverage Statusdocs

EVMcrispr is still in active development and its API might change until it reaches 1.0.

A TypeScript library for Aragon-based DAOs that allows you to encode a series of actions into an EVM script that can be sent to forwarder apps.

Actions can be thought of as events performed by some entity inside a DAO such as installing apps, granting or revoking permissions, minting tokens, withdrawing funds, etc.

Documentation

Check out the documentation for an in-depth explanation of the API.

How does it work?

EVMcrispr offers two main methods to create EVM scripts containing actions: encode() and forward() (this one encodes the actions and forwards it afterwards).

Both methods receive two parameters: a group of the encoded actions and a group of forwarder apps used to forward the aforementioned actions.

The library exposes a series of methods that allows you to encode different actions such as installing an app, revoking a permission, etc. The idea is to invoke these methods inside an encode() or forward() to build the script. Here is an example of it:

await evmcrispr.forward(
  [
    evmcrispr.install(app, params),
    evmcrispr.grantPermissions([permission1, permission2, permission3]),
    evmcrispr.revoke(permission, removeManager),
    // ...
  ],
  // forwarder apps path.
  [forwarder1, forwarder2]
);

The same EVMscript can be encoded using the evmcl template:

await evmcripsr.forward(
  evmcl`
    install ${app} ${param1} ${param2}
    grant ${entity1} ${app1} ${role1} ${permissionManager}
    grant ${entity2} ${app2} ${role1} ${permissionManager}
    grant ${entity3} ${app3} ${role3} ${permissionManager}
    revoke ${entity4} ${app4} ${role4} ${removeManager}
  `, // ...
  [forwarder1, forwarder2]
);

To facilitate the EVM script creation, you can use identifiers to reference DAO apps instead of using the contract address directly.

Below you can find a full example:

await evmcrispr.forward(
  evmcl`
    install wrapped-hooked-token-manager.open:membership-tm ${token} false 0
    install voting:membership-voting ${token} ${suppPct} ${minQuorumPct} ${voteTime}
    grant ANY_ENTITY voting:membership-voting CREATE_VOTES_ROLE
    grant voting:membership-voting wrapped-hooked-token-manager.open:membership-tm MINT_ROLE
    grant voting:membership-voting wrapped-hooked-token-manager.open:membership-tm BURN_ROLE
    exec wrapped-hooked-token-manager.open:membership-tm mint ${address} 2e18
  `,
  ["token-manager:1", "voting"]
);

Set up

  1. Add the following dependency to your project:
   yarn add @1hive/evmcrispr
  1. Import the EVMcrispr class and the evmcl template:
   import { EVMcrispr, evmcl } from '@1hive/evmcrispr'
  1. Create a new EVMcrispr by using the static method crate(). It receives an ether's Signer object and the DAO address to connect to:
   const evmcrispr = await EVMcrispr.create(signer, daoAddress);
  1. Use the EVMcrispr's encode or forward functions to pass an array of actions, or an evmcl script.

Parametric permission utils

The following utils can be used to encode complex permission parameters:

  • arg(i): Can be used to compare the ith parameter with a given value.
  • oracle(address): Can be used to check the output of an external contract
  • blocknumber: Can be used to compare a given value with the block number.
  • timestamp: Can be used to compare a given value with the block timestamp.
  • not(param): Can be used to negate a parameter.
  • and(param1, param2): Can be used to compose two parameters with the AND logical function.
  • or(param1, param2): Same as previous one with the OR logical function.
  • xor(param1, param2): Same as the previous one with the XOR logical function.
  • iif(param).then(param).else(param): Ternary operator for more complex logic expressions.

They can be used within the forth parameter of grant(entity, app, role, params) function.

Other examples

Below you can find some script examples that use EVMcrispr:

Contributing

We welcome community contributions!

Please check out our open Issues to get started.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文