@abrandec/protocol-monorepo-upgradeable 中文文档教程

发布于 3年前 浏览 17 项目主页 更新于 3年前

Welcome to @superfluid-finance/ethereum-contracts ????

超流体协议的以太坊合约实施

Homepage

Superfluid App

Docs

Usage

如果您正在使用部署的合约(goerli 或主网)构建 dapp,那么您应该改用 @superfluid-finance/js -sdk

如果你正在构建一个使用 Superfluid 协议的智能合约, 甚至您自己的 SuperApp,那就太好了! 这绝对是个好地方。

Installation

$ yarn add @superfluid-finance/ethereum-contracts

Smart Contract

可以像这样将合约导入到您的 .sol 文件中:

import { IConstantFlowAgreementV1 } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/agreements/IConstantFlowAgreementV1.sol";

Writing Test

为了编写测试,您可以使用部署脚本来部署所有必要的合约。 目前他们只适用于 web3.js, 我们正在努力在未来支持其他框架。

const deployFramework = require("@superfluid-finance/ethereum-contracts/scripts/deploy-framework");
const deployTestToken = require("@superfluid-finance/ethereum-contracts/scripts/deploy-test-token");
const deploySuperToken = require("@superfluid-finance/ethereum-contracts/scripts/deploy-super-token");

contract("My Test", accounts => {
    const [admin, bob, carol, dan] = accounts;

    before(async () => {
        await deployFramework(errorHandler, {
            web3,
            from: admin
        });
    });

    beforeEach(async function() {
        await deployTestToken(errorHandler, [":", "fDAI"], {
            web3,
            from: admin
        });
        await deploySuperToken(errorHandler, [":", "fDAI"], {
            web3,
            from: admin
        });
    });

要与协议交互,您应该考虑使用 @superfluid-finance/js-sdk。 这是一个快速入门示例:

const SuperfluidSDK = require("@superfluid-finance/js-sdk");

let sf;
let daix;

beforeEach(async () => {
    await deployTestToken(errorHandler, [":", "fDAI"], {
        web3,
        from: admin,
    });
    await deploySuperToken(errorHandler, [":", "fDAI"], {
        web3,
        from: admin,
    });

    sf = new SuperfluidSDK.Framework({
        web3,
        version: "test",
        tokens: ["fDAI"],
    });
    await sf.initialize();

    daix = sf.tokens.fDAIx;

    // Create user objects
    admin = sf.user({ address: adminAddress, token: daix.address });
    alice = sf.user({ address: aliceAddress, token: daix.address });
});

太棒了,既然您已经掌握了基础知识,请查看 示例文件夹

Deploying Superfluid Protocol

Local

部署到你本地的ganache环境:

DISABLE_NATIVE_TRUFFLE=true truffle --network ganache exec "node_modules/@superfluid-finance/ethereum-contracts/scripts/deploy-test-environment.js"

Public

如果你想部署到公共网络:

NEW_TEST_RESOLVER=1 DISABLE_NATIVE_TRUFFLE=true truffle --network goerli exec "node_modules/@superfluid-finance/ethereum-contracts/scripts/deploy-test-environment.js"

注意NEW_TEST_RESOLVER=1,这是为了避免使用官方解析器地址。 这样做 命令完成后,您应该会看到:

...
======== Super token deployed ========
=============== TEST ENVIRONMENT RESOLVER ======================
export TEST_RESOLVER_ADDRESS=0x43098b8d85Fe90eCE6B055e135759B558d2c0224

运行导出命令以将 TESTRESOLVERADDRESS 保存到您的本地环境。 每当您运行其他测试/脚本时,这将是用于查找 SF 框架合约的地址。

Examples

我们创建了一些此处的示例。 这样你就不必开始一切 从头开始。 克隆一个项目,修改并播放!

Troubleshooting

要记住的一件事是,Superfluid 依赖于持久的 1820 注册合约。 这必须在您可以与协议交互之前部署。 如果您遵循使用部署脚本的示例,则无需担心。

如果您想查看手动部署合约的示例,请查看 scripts 文件夹

如果您好奇,或者真的想偷懒,您可能需要手动部署注册表。 下面是如何将 1820 合约部署到本地 Ganache 的示例。 (阅读更多关于 EIP 1820 伪内省注册合约

# Start Ganache on 127.0.0.1:8545
ganache-cli

# Build the contracts + prepare the SDK
yarn build

# Deploy the 1820 contract
cd packages/ethereum-contracts
npx truffle exec scripts/deploy-erc1820.js --network ganache

# Now you can run tests and interact with the protocol
yarn test

Contributing

Setup Development Environment

  1. Install dependencies
yarn install
  1. Setup your own .env file from .env.template

Testing

有两个主要的测试套件

  • Contracts (test/contracts.test.js) tests the contracts Each contracts test suite is named as test/{Type}/{ContractName}.test.js.
  • Deployment (test/deployment.test.js) tests the deployment script
yarn test

:执行时间很长,您可能想使用 MochaJS 的 exclusive tests 功能来仅隔离您想要的测试。 例如:

# Only run deployment.test.js
nodemon -x npx truffle test ./test/contracts/superfluid/Superfluid.test.js

Show your support

如果这个项目对你有帮助,请给一个⭐️!


此 README 由 readme-md-generator 使用 ❤️ 生成

Welcome to @superfluid-finance/ethereum-contracts ????

Ethereum contracts implementation for the Superfluid Protocol

???? Homepage

Superfluid App

???? Docs

Usage

If you're building a dapp using the deployed contracts (goerli or mainnet) then you should instead use @superfluid-finance/js-sdk.

If you're building a smart contract that uses Superfluid protocol, or even your own SuperApp, then great! This is definitely the place to be.

Installation

$ yarn add @superfluid-finance/ethereum-contracts

Smart Contract

The contracts can be imported into your .sol file like this:

import { IConstantFlowAgreementV1 } from "@superfluid-finance/ethereum-contracts/contracts/interfaces/agreements/IConstantFlowAgreementV1.sol";

Writing Test

For writing tests, you can use the the deployment scripts to deploy all the necessary contracts. Currently they only works with web3.js, we are working on to support to other frameworks in the future.

const deployFramework = require("@superfluid-finance/ethereum-contracts/scripts/deploy-framework");
const deployTestToken = require("@superfluid-finance/ethereum-contracts/scripts/deploy-test-token");
const deploySuperToken = require("@superfluid-finance/ethereum-contracts/scripts/deploy-super-token");

contract("My Test", accounts => {
    const [admin, bob, carol, dan] = accounts;

    before(async () => {
        await deployFramework(errorHandler, {
            web3,
            from: admin
        });
    });

    beforeEach(async function() {
        await deployTestToken(errorHandler, [":", "fDAI"], {
            web3,
            from: admin
        });
        await deploySuperToken(errorHandler, [":", "fDAI"], {
            web3,
            from: admin
        });
    });

To interact with the protocol, you should consider to use the @superfluid-finance/js-sdk. Here is a quick-start example:

const SuperfluidSDK = require("@superfluid-finance/js-sdk");

let sf;
let daix;

beforeEach(async () => {
    await deployTestToken(errorHandler, [":", "fDAI"], {
        web3,
        from: admin,
    });
    await deploySuperToken(errorHandler, [":", "fDAI"], {
        web3,
        from: admin,
    });

    sf = new SuperfluidSDK.Framework({
        web3,
        version: "test",
        tokens: ["fDAI"],
    });
    await sf.initialize();

    daix = sf.tokens.fDAIx;

    // Create user objects
    admin = sf.user({ address: adminAddress, token: daix.address });
    alice = sf.user({ address: aliceAddress, token: daix.address });
});

Awesome, now that you have the basics, check out the apps over in the examples folder.

Deploying Superfluid Protocol

Local

To deploy to your local ganache environment:

DISABLE_NATIVE_TRUFFLE=true truffle --network ganache exec "node_modules/@superfluid-finance/ethereum-contracts/scripts/deploy-test-environment.js"

Public

If you want to deploy to a public network:

NEW_TEST_RESOLVER=1 DISABLE_NATIVE_TRUFFLE=true truffle --network goerli exec "node_modules/@superfluid-finance/ethereum-contracts/scripts/deploy-test-environment.js"

Note NEW_TEST_RESOLVER=1, it is to avoid using the official resolver address. Doing so after the command finishes, you should see:

...
======== Super token deployed ========
=============== TEST ENVIRONMENT RESOLVER ======================
export TEST_RESOLVER_ADDRESS=0x43098b8d85Fe90eCE6B055e135759B558d2c0224

Run the export command to save TESTRESOLVERADDRESS to your local environment. Whenever you run additional tests/scripts this will be the address used to find the SF Framework contracts.

Examples

We created a few examples here. So that you don't have to start everything from the scratch. Clone a project, modify and play!

Troubleshooting

One thing to keep in mind is that Superfluid relies on a persistent 1820 registry contract. This must be deployed before you can interact with the protocol. If you follow the examples using the deployment scripts, you don't need to worry about it.

If you want to see examples for manually deploying contracts, check out the scripts folder.

In case your curious, or really hacking away, you might want to deploy the registry manually. Here is an example for how to deploy the 1820 contract to a local Ganache. (read more about EIP 1820 Pseudo-introspection Registry Contract)

# Start Ganache on 127.0.0.1:8545
ganache-cli

# Build the contracts + prepare the SDK
yarn build

# Deploy the 1820 contract
cd packages/ethereum-contracts
npx truffle exec scripts/deploy-erc1820.js --network ganache

# Now you can run tests and interact with the protocol
yarn test

Contributing

Setup Development Environment

  1. Install dependencies
yarn install
  1. Setup your own .env file from .env.template

Testing

There are two major test suite:

  • Contracts (test/contracts.test.js) tests the contracts Each contracts test suite is named as test/{Type}/{ContractName}.test.js.
  • Deployment (test/deployment.test.js) tests the deployment script
yarn test

Since testing can take a long time to execute, you may want to use the execlusive tests feature from MochaJS to isolate only the test you want. For example:

# Only run deployment.test.js
nodemon -x npx truffle test ./test/contracts/superfluid/Superfluid.test.js

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

更多

友情链接

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