Patract’s treasury proposal for Redspot v0.4 (Wasm contract scaffold)

3yrs ago
0 Comments

Redspot is one of Patract's Wasm contract development tool suite. Redspot's goal is to standardize the contract development process, hide the underlying compilation details of the contract, and combine the sandbox, library, API, SDK and other plugins to create a one-stop smooth contract development process. Patract had finished 3 proposals for Redspot at 4 months ago, the latest one is for v0.3 at treasury #23, and the report is at post #207 . We also had followed up the changes of Pallet-Contracts and ink! during the last 4 months.

There are also many parachain teams already in use of Redspot, including Acala, Plasm, Litentry, OpenSquare etc. At the ParityAsia Hackathon, the inkBridge and SkyePass all used Patract suite (Redspot, Europa, PatraStore, etc.) to develop Wasm contract DApps from zero and win the 2nd and 3rd prizes.

Summary of Redspot’s Future Plan (old):

  • v0.1(finished): Build core functions based on Truffle framework
  • v0.2(finished): Migrate to Hardhat framework to enhance the extensibility of plugins and add some features to provide a smoother development workflow
  • v0.3(finished): Promote Redspot and allow more contract developers to participate. Combine the features of Substrate to add various plug-ins, such as Waffle, Jupiter, Gas report.
  • v0.4: Provide Typescript type support for contracts (similar to Typechain), integrate multi-language SDK, etc.

In the old design of the v0.4, the plan we expected is no longer suitable for the recent situation:

  1. Typescript support for contracts: After discussing with Jacob (api-contract in polkadot.js is going to support Typescript), we believe that its importance is not high and does not affect the current use, so the support for contract Typescript is placed after api-contract supports this function.

  2. Integrate multi-language SDK: Since pallet-contracts changed the interfaces in 3.0.0 and the recent changes are huge, the Himalia project of Patract’s multi-lang SDKs currently has only the Go version to catch up with the latest changes, and the python version is not updated in time. Moreover, the java version and .NET version have not been launched yet, so the multi-lang SDKs are not yet fully prepared, so they are temporarily unable to be integrated into Redspot in this version.

Summary of Redspot’s v0.4 Plan (new):

  1. Support multi-contract: In the recent updates of ink! and cargo-contracts, multi-contracts can finally be compiled normally. Therefore, Redspot will revise its support system for multiple contracts.
  2. Support docker compilation: Because of the current different environments, Wasm compilation results will be inconsistent (for example, Substrate's Runtime uses srtool to solve this problem). On the other hand, It may be difficult to build a compilation environment under different operating systems (such as Windows), so supporting docker can solve many environmental problems.
  3. Support web interface: Although Redspot is basically a command line tool, it is not very attractive to programmers who are just getting started. Therefore, Redspot plans to introduce a contract deployment and operation interface similar to Canvas-UI, and add rich functions to this interface, strengthen the contract-related attributes in product design, and visualize some Redspot functions. And this interface can also add additional functions such as calling the polkadot{.js} extension for transaction signing (the browser extension cannot be called in the Redspot command line).
  4. Add some other plugins to enrich the Redspot ecosystem, such as support for chain types, plugins for monitoring file changes, and so on.

Detailed design of v0.4:

1. Multi-contract support

The problem of ink! and cargo-contracts compiling multiple contracts has been corrected after the submission of Cargo-contract PR#199. Therefore, Redspot can restart the supports for multi-contract compilation (Redspot once supported the multi-contract organization structure to a certain extent, but was stopped due to the inability to compile)

Redspot's multi-contract support will start from the following aspects:

  1. Multi-contract indexing and identification of document structure.
  2. redspot.config.ts supports configuration by file index.
  3. Judgment and sorting of compilation results (including the processing of compilation result of the contracts with same name)
  4. Support the use of multiple languages for mixed compile

Redspot will automatically find all contract files in this directory through the configured search directory. Then compile through the configured compile tool, and finally all compile results will be output to the artifacts directory. At the same time, a buildInfo file will be generated, which records the project directory structure before compilation.

2. docker compilation support

Supporting the invocation of docker in Redspot can solve many problems related to environment setup. For related discussions, see cargo-contract issue #188 and cargo-contract issue #184, submitted by us. Therefore, when we noticed that the cargo-contracts dockerfile appeared in the CI of scripts, we can add related functions for Redspot about calling docker.

Redspot will detect whether there is an existing docker environment. And automatically pull the docker image of the specified version. On the other hand, Redspot will maintain a docker image as the default testnet.

3. Web interface support

Since the main functions of Redspot have been relatively complete, the follow-up of Redspot will do more easy-to-use development on the product. For example, providing a contract-related UI interface to Redspot can make it easier for beginners to get started with the contract development process. On the other hand, there are some functions in Redspot that need to evoke the browser to participate in the corresponding operation (for example, call the polkadot{.js} extension to sign).

Although parity has provided Canvas UI and Developer-Contracts in https://polkadot.js.org/apps , these two cannot reach our demand in terms of the specialization of the contract part. For example, Canvas-ui provides a more intuitive contract operation interface, but it does not has chain-related display information. Although apps has a more comprehensive information display, the contract call part is stronger than canvas-ui, but regardless of canvas-ui or apps are still lacking in contract-related functions, such as scanning and recording existing contracts, parsing contract parameters, and associating with the secret key in the Redspot configuration, and so on.

On the other hand, like Truffle, Redspot will also be designed to be used in a production environment to deploy contracts, so Redspot needs to provide a secure way to sign transactions. For example, hardware wallets such as ledger and parity-signer can be used in the future to deploy and call contract transaction signing. In this way, developers can firstly uses a configuration similar to development, configures the test key to test the contract in the test environment, then switches to production environment, configures the key of the production environment to deploy the contract. In order to take care of all environments, we think that calling the browser to interact is a better method. So this time we try to integrate the call of polkadot{.js} extension.

In summary, Redspot's web interface will provide beginners with a wealth of information to start contract operations, and also integrate some operations that cannot be handled in the cli environment:

  1. The interface will contain basic information such as chain blocks, transactions, events, etc., and the contract operation interface is similar to Canvas-UI.
  2. The web will scan or record (different strategies according to different chains) existing contracts, and read the Redspot config environment to associate with the existing keys
  3. The web interface will display detailed information related to contract operations on the contract interface, such as gas, selector, parameter content, etc. in a contract call
  4. The web interface will visualize some operations of Redspot, such as introducing Redspot's console interface to display the log of the executed operation, or it can display test and script information, and call and execute it through the interface.
  5. When the security key is configured in Redspot's config, the web interface will need to call polkadot{.js} to sign the transaction.
  6. Support the storage query of the contract.
  7. The latest local compilation result will be uploaded automatically. It is convenient to deploy and call contracts manually.

4. Add some other plugins

4.1. Redspot-watcher

Currently Redspot executes commands such as redspot test, redspot console, etc. to check whether the contract file is modified when it is executed. Therefore, the developer needs to judge whether the contract needs to be compiled and add the --no-compiled command to inform redspot that the contract does not need to be compiled for this execution. Therefore, after the introduction of redspot-watcher, before calling the redspot runtime to execute, the redspot-watcher can determine whether there are file changes, so as to determine whether the compilation process needs to be invoked.

redspot-watcher will modify redspot's test, run and console commands. Before each run, the file hash will be calculated and stored in the buildinfo file, and then compared with the previous file hash. If there is no change, the compilation will be skipped.

4.2. Balances decimal plugin

In web3.js, you can use methods such as 1 ETH to replace inputs like 10000...000. This human-readable approach can greatly reduce the probability of making mistakes when developer write scripts and tests. However, because the precision of Ethereum is fixed, and when Substrate introduces pallet-contracts, the precision is determined by this chain, so the plug-in is not a static conversion, but needs to get the relevant information of the chain (decimal, symbol ) to be converted.

Therefore, the plug-in will eventually achieve functions similar to the following:

  • '1 DOT' = '10000000000'
  • '1 KSM' = '1000000000000'
  • '1 nano’ = ’10^-9 DOT'

4.3. default blockchain types plugin

Since Substrate has not yet integrated scale-info, each chain provides types to support the parsing of polkadot.js. Currently, Redspot requires developers to fill in the type information in redspot.config.ts, which causes some troubles for developers. This plug-in obtains the types of different chains that already exist in apps, provides it to polkadot.js by default, and allows developers to override the form in redspot.config.ts, so that in most cases, developers do not need to worry about the need of providing polkadot.js the types.

We will discuss with polkadot apps and hope to release the @polkadot/apps-config package. Then all types provided in this package will be registered. We will also process the known contract chains with wasm functions. Maintain the types of their test chain. In this way, as long as the chain’s specversion is correctly set, there is no need to worry about the version.

Detailed timeline of v0.4(5 weeks)

  • Week 1: Implement docker support (3 developers)

    • can specify docker image as a node.
    • can specify docker image as the contract compiler.
  • Week 2: Support multi-contract compilation and redspot-watcher plugin (3 developers)

    • Multi-contract compilation is possible
    • The compiled product can maintain the directory structure
    • Can detect whether the contract file has been modified, and skip the compilation if there is no modification
  • Week 3-4: Web interface design and development (3 developers * 2 weeks + 1 designer * 1 week)

    • can browse to view contract events
    • You can query the storage of the contract
    • Can automatically upload local wasm and metadata files
    • Automatically inject locally configured accounts
    • Can call contracts and deploy contracts
  • week 5: Develop balances decimal plugin and default blockchain types plugin (3 developers)

    • The amount can be passed in in a human-readable way.
    • In most cases, there is no need for developers to pass in types.

Cost of v0.4 (1 designer * week + 15 developers * weeks)

  • Operating activities: $3200 ( Rent and Devices: $200 per developer * week )
  • Employee payments: $30000 ($1500/$1900 per designer/developer * week)
  • Total Cost: $33200 and monthly average: $36 / DOT
  • Treasury Proposal: 922 DOT

How to verify v0.4: Github library

  • Multi-contract support: able to compile the delegator contract in ink/example and the multi-contracts contract project provided by redspot
  • Support docker compilation: redspot can automatically pull and run the docker image containing cargo-contract component under the user's choice to compile the contract. The compiled structure can be moved to the artifacts directory, and the file permissions are correct.
  • Redspot's web interface:
    1. Display the information and contract interface of the connected node
    2. When a contract is deployed, the contract information and related transactions will be recorded. And can be associated with the deployer. For Europa, it can directly scan the deployed contracts and associate relevant information.
    3. Display detailed contract operation information
    4. The information that Redspot originally displayed on the command line can be displayed in the web interface, and redspot test cases can be called and executed from the web interface.
    5. Able to call the polkadot.js extension to sign Redspot transactions.
  • Other plug-ins
    • redspot-watcher: When the file is not edited, the contract will not be compiled if the relevant commands are re-executed. When the file is compiled, the compilation process will be called when re-executed
    • Balances decimal plug-in: Use canvas, Jupiter and Europa to test, respectively test 1 Unit, 1 DOT, etc.
    • default blockchain types: Connect Canvas-node and Jupiter. You no longer need to fill in types and you can send transactions normally.
Up
Comments
No comments here