├── .github └── workflows │ └── push-master.yml ├── .gitignore ├── README.md ├── babel.config.js ├── docs ├── README.md ├── ask │ ├── guides │ │ ├── architecture.md │ │ ├── ask-cli.md │ │ ├── ask-ink.md │ │ ├── cross-contract.md │ │ ├── decorators │ │ │ ├── contract-decorator.md │ │ │ ├── event-decorator.md │ │ │ └── overview.md │ │ ├── examples.md │ │ ├── global.md │ │ ├── mechanism.md │ │ └── types-storage │ │ │ ├── basic_types.md │ │ │ └── storage.md │ ├── img │ │ ├── ask-design.png │ │ ├── kv.svg │ │ ├── packed.svg │ │ └── spread.svg │ ├── intro │ │ ├── overview.md │ │ ├── quickstart.md │ │ └── why-ask.md │ └── reports │ │ ├── img │ │ ├── v0.1Report_call.png │ │ ├── v0.1Report_deploy.png │ │ ├── v0.1Report_deploy_result.png │ │ ├── v0.1Report_upload.png │ │ ├── v0.2PackedStorableArray.png │ │ ├── v0.2PackedStorableMap.png │ │ ├── v0.2SpreadStorableArray.png │ │ ├── v0.2SpreadStorableMap.png │ │ └── v0.2erc20.gif │ │ ├── v0.1Report.md │ │ ├── v0.2Report.md │ │ └── v0.3Report.md ├── contracts │ ├── imgs │ │ ├── language_1.jpg │ │ ├── language_2.jpg │ │ ├── model.jpg │ │ ├── overview_module.jpg │ │ └── wasm.jpg │ ├── introduction.md │ ├── language.md │ ├── model.md │ ├── overview.md │ └── wasm_first_step.md ├── elara │ ├── API.md │ ├── design.md │ ├── introduction.md │ ├── reports.md │ ├── reports │ │ ├── v0.1Report.md │ │ └── v0.2Report.md │ └── tutorial.md ├── europa │ ├── extensions │ │ └── custom-chain-extensions.md │ ├── guides │ │ ├── architecture.md │ │ ├── backtrace.md │ │ ├── contract-log.md │ │ ├── custom-rpcs.md │ │ ├── debug-example.md │ │ ├── implementation.md │ │ └── wasm-executor.md │ ├── imgs │ │ ├── add_exist.png │ │ ├── call_other_1.png │ │ ├── call_other_2.png │ │ ├── contract_call_contract.png │ │ ├── contract_error_message.png │ │ ├── contract_extrinsic.png │ │ ├── contract_wasmi.png │ │ ├── deployed_contract.png │ │ ├── europa-ui.png │ │ ├── europa_accounts.png │ │ ├── europa_contracts.png │ │ ├── europa_developer.png │ │ ├── europa_instance_function.png │ │ ├── europa_instances.png │ │ └── explorer.png │ ├── intro │ │ ├── europa-cli.md │ │ ├── europa-ui.md │ │ └── overview.md │ ├── reports.md │ └── reports │ │ ├── imgs │ │ ├── report3_contracts_codes.png │ │ ├── report3_contracts_instances.png │ │ ├── report3_explorer.png │ │ ├── report3_extrinsic_cross_call.png │ │ ├── report3_extrinsic_details.png │ │ ├── report3_extrinsic_state_1.png │ │ ├── report3_extrinsic_state_2.png │ │ ├── report3_extrinsic_wasm_err.png │ │ ├── report3_extrinsics_call.png │ │ ├── report3_instance_extrinsics.png │ │ ├── report3_instance_functions.png │ │ ├── report3_left.png │ │ └── report3_start.png │ │ ├── v0.1Report.md │ │ ├── v0.2Report.md │ │ └── v0.3Report.md ├── himalia │ ├── go-patract.md │ ├── introduction.md │ ├── py-patract.md │ ├── reports.md │ ├── reports │ │ └── v0.1Report.md │ └── tutorial.md ├── ink │ ├── call-contracts.md │ ├── cargo-contract.md │ ├── edsl-basic.md │ ├── framework.md │ ├── ink-solidity.md │ ├── introduction.md │ ├── trap.md │ └── tutorial.md ├── jupiter │ ├── contract.md │ ├── img │ │ ├── facet.png │ │ ├── jupiter-xcmp-1.png │ │ ├── jupiter-xcmp-2.png │ │ ├── jupiter-xcmp-3.png │ │ └── parastore.png │ ├── introduction.md │ ├── network.md │ ├── quickstart.md │ └── xcmp.md ├── metis │ ├── guides │ │ ├── access-control │ │ │ ├── access-control-enumerable.md │ │ │ ├── access-control.md │ │ │ └── ownable.md │ │ ├── extensions.md │ │ ├── governance │ │ │ └── timelock-controller.md │ │ ├── hook.md │ │ ├── imports.md │ │ ├── macros.md │ │ ├── security │ │ │ ├── pausable.md │ │ │ └── reentrancy-guard.md │ │ ├── tokens │ │ │ ├── erc1155.md │ │ │ ├── erc20.md │ │ │ ├── erc721.md │ │ │ └── erc777.md │ │ ├── tools │ │ │ └── erc165.md │ │ └── utilities │ │ │ └── escrow.md │ ├── intro │ │ ├── architecture.md │ │ ├── differences.md │ │ ├── motivation.md │ │ └── overview.md │ └── reports │ │ ├── M1Report.md │ │ └── reports.md ├── pallet-contracts │ └── introduction.md ├── patract │ ├── imgs │ │ └── overview.jpg │ └── introduction.md ├── redspot │ ├── advanced │ │ ├── multi-contract-compilation.md │ │ └── write-plugins.md │ ├── guides │ │ ├── configuration.md │ │ ├── console.md │ │ ├── docker.md │ │ ├── explorer.md │ │ ├── runtime-environment.md │ │ └── tasks.md │ ├── imgs │ │ ├── engprocess.jpg │ │ ├── explorer.png │ │ └── process.jpg │ ├── intro │ │ ├── installation.md │ │ ├── integrate.md │ │ ├── overview.md │ │ └── quick-start.md │ ├── plugin │ │ ├── image │ │ │ ├── 1.png │ │ │ ├── 10.png │ │ │ ├── 111.png │ │ │ ├── 12.png │ │ │ ├── 13.png │ │ │ ├── 14.png │ │ │ ├── 15.png │ │ │ ├── 16.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 8.png │ │ │ ├── 91.png │ │ │ ├── 9png.png │ │ │ └── gas.png │ │ ├── plugin.md │ │ ├── redspot-chai.md │ │ ├── redspot-decimals.md │ │ ├── redspot-explorer.md │ │ ├── redspot-gas-reporter.md │ │ ├── redspot-known-types.md │ │ └── redspot-patract.md │ ├── q-and-a.md │ └── reports │ │ ├── reports.md │ │ ├── v0.1Report.md │ │ ├── v0.2Report.md │ │ ├── v0.3Report.md │ │ └── v0.4Report.md ├── solang │ └── introduction.md └── zkmega │ ├── benchmark.md │ ├── contract.md │ ├── example.md │ ├── introduction.md │ ├── metis.md │ ├── reports.md │ ├── reports │ ├── v0.1Report.md │ └── v0.2Report.md │ └── tutorial.md ├── docusaurus.config.js ├── i18n └── en │ ├── code.json │ ├── docusaurus-plugin-content-docs │ ├── current.json │ └── current │ │ ├── README.md │ │ ├── ask │ │ ├── guides │ │ │ ├── architecture.md │ │ │ ├── ask-cli.md │ │ │ ├── ask-ink.md │ │ │ ├── cross-contract.md │ │ │ ├── decorators │ │ │ │ ├── contract-decorator.md │ │ │ │ ├── event-decorator.md │ │ │ │ └── overview.md │ │ │ ├── examples.md │ │ │ ├── global.md │ │ │ ├── mechanism.md │ │ │ └── types-storage │ │ │ │ ├── basic_types.md │ │ │ │ └── storage.md │ │ ├── img │ │ │ ├── ask-design.png │ │ │ ├── kv.svg │ │ │ ├── packed.svg │ │ │ └── spread.svg │ │ ├── intro │ │ │ ├── overview.md │ │ │ ├── quickstart.md │ │ │ └── why-ask.md │ │ └── reports │ │ │ ├── img │ │ │ ├── v0.1Report_call.png │ │ │ ├── v0.1Report_deploy.png │ │ │ ├── v0.1Report_deploy_result.png │ │ │ ├── v0.1Report_upload.png │ │ │ ├── v0.2PackedStorableArray.png │ │ │ ├── v0.2PackedStorableMap.png │ │ │ ├── v0.2SpreadStorableArray.png │ │ │ ├── v0.2SpreadStorableMap.png │ │ │ └── v0.2erc20.gif │ │ │ ├── v0.1Report.md │ │ │ ├── v0.2Report.md │ │ │ └── v0.3Report.md │ │ ├── contracts │ │ ├── imgs │ │ │ ├── engcontract_model_1.jpg │ │ │ ├── engcontracts_wasm_1.jpg │ │ │ ├── englanguage_2.jpg │ │ │ ├── engprocess.jpg │ │ │ ├── language_1.jpg │ │ │ ├── language_2.jpg │ │ │ ├── model.jpg │ │ │ ├── overview_module.jpg │ │ │ └── wasm.jpg │ │ ├── introduction.md │ │ ├── language.md │ │ ├── model.md │ │ ├── overview.md │ │ └── wasm_first_step.md │ │ ├── elara │ │ ├── API.md │ │ ├── design.md │ │ ├── introduction.md │ │ ├── reports.md │ │ ├── reports │ │ │ ├── v0.1Report.md │ │ │ └── v0.2Report.md │ │ └── tutorial.md │ │ ├── europa │ │ ├── extensions │ │ │ └── custom-chain-extensions.md │ │ ├── guides │ │ │ ├── architecture.md │ │ │ ├── backtrace.md │ │ │ ├── contract-log.md │ │ │ ├── custom-rpcs.md │ │ │ ├── debug-example.md │ │ │ ├── implementation.md │ │ │ └── wasm-executor.md │ │ ├── imgs │ │ │ ├── add_exist.png │ │ │ ├── call_other_1.png │ │ │ ├── call_other_2.png │ │ │ ├── contract_call_contract.png │ │ │ ├── contract_error_message.png │ │ │ ├── contract_extrinsic.png │ │ │ ├── contract_wasmi.png │ │ │ ├── deployed_contract.png │ │ │ ├── europa-ui.png │ │ │ ├── europa_accounts.png │ │ │ ├── europa_contracts.png │ │ │ ├── europa_developer.png │ │ │ ├── europa_instance_function.png │ │ │ ├── europa_instances.png │ │ │ └── explorer.png │ │ ├── intro │ │ │ ├── europa-cli.md │ │ │ ├── europa-ui.md │ │ │ └── overview.md │ │ ├── reports.md │ │ └── reports │ │ │ ├── imgs │ │ │ ├── report3_contracts_codes.png │ │ │ ├── report3_contracts_instances.png │ │ │ ├── report3_explorer.png │ │ │ ├── report3_extrinsic_cross_call.png │ │ │ ├── report3_extrinsic_details.png │ │ │ ├── report3_extrinsic_state_1.png │ │ │ ├── report3_extrinsic_state_2.png │ │ │ ├── report3_extrinsic_wasm_err.png │ │ │ ├── report3_extrinsics_call.png │ │ │ ├── report3_instance_extrinsics.png │ │ │ ├── report3_instance_functions.png │ │ │ ├── report3_left.png │ │ │ └── report3_start.png │ │ │ ├── v0.1Report.md │ │ │ ├── v0.2Report.md │ │ │ └── v0.3Report.md │ │ ├── himalia │ │ ├── go-patract.md │ │ ├── introduction.md │ │ ├── py-patract.md │ │ ├── reports.md │ │ ├── reports │ │ │ └── v0.1Report.md │ │ └── tutorial.md │ │ ├── ink │ │ ├── call-contracts.md │ │ ├── cargo-contract.md │ │ ├── edsl-basic.md │ │ ├── framework.md │ │ ├── ink-solidity.md │ │ ├── introduction.md │ │ ├── trap.md │ │ └── tutorial.md │ │ ├── jupiter │ │ ├── contract.md │ │ ├── img │ │ │ ├── facet.png │ │ │ ├── jupiter-xcmp-1.png │ │ │ ├── jupiter-xcmp-2.png │ │ │ ├── jupiter-xcmp-3.png │ │ │ └── parastore.png │ │ ├── introduction.md │ │ ├── network.md │ │ ├── quickstart.md │ │ └── xcmp.md │ │ ├── metis │ │ ├── guides │ │ │ ├── access-control │ │ │ │ ├── access-control-enumerable.md │ │ │ │ ├── access-control.md │ │ │ │ └── ownable.md │ │ │ ├── extensions.md │ │ │ ├── governance │ │ │ │ └── timelock-controller.md │ │ │ ├── hook.md │ │ │ ├── imports.md │ │ │ ├── macros.md │ │ │ ├── security │ │ │ │ ├── pausable.md │ │ │ │ └── reentrancy-guard.md │ │ │ ├── tokens │ │ │ │ ├── erc1155.md │ │ │ │ ├── erc20.md │ │ │ │ ├── erc721.md │ │ │ │ └── erc777.md │ │ │ ├── tools │ │ │ │ └── erc165.md │ │ │ └── utilities │ │ │ │ └── escrow.md │ │ ├── intro │ │ │ ├── architecture.md │ │ │ ├── differences.md │ │ │ ├── motivation.md │ │ │ └── overview.md │ │ └── reports │ │ │ ├── M1Report.md │ │ │ └── reports.md │ │ ├── pallet-contracts │ │ └── introduction.md │ │ ├── patract │ │ ├── imgs │ │ │ └── overview.jpg │ │ └── introduction.md │ │ ├── redspot │ │ ├── advanced │ │ │ ├── multi-contract-compilation.md │ │ │ └── write-plugins.md │ │ ├── guides │ │ │ ├── configuration.md │ │ │ ├── console.md │ │ │ ├── docker.md │ │ │ ├── explorer.md │ │ │ ├── runtime-environment.md │ │ │ └── tasks.md │ │ ├── imgs │ │ │ ├── engprocess.jpg │ │ │ ├── explorer.png │ │ │ └── process.jpg │ │ ├── intro │ │ │ ├── installation.md │ │ │ ├── integrate.md │ │ │ ├── overview.md │ │ │ └── quick-start.md │ │ ├── plugin │ │ │ ├── image │ │ │ │ ├── 1.png │ │ │ │ ├── 10.png │ │ │ │ ├── 111.png │ │ │ │ ├── 12.png │ │ │ │ ├── 13.png │ │ │ │ ├── 14.png │ │ │ │ ├── 15.png │ │ │ │ ├── 16.png │ │ │ │ ├── 2.png │ │ │ │ ├── 3.png │ │ │ │ ├── 8.png │ │ │ │ ├── 91.png │ │ │ │ ├── 9png.png │ │ │ │ └── gas.png │ │ │ ├── plugin.md │ │ │ ├── redspot-chai.md │ │ │ ├── redspot-decimals.md │ │ │ ├── redspot-explorer.md │ │ │ ├── redspot-gas-reporter.md │ │ │ ├── redspot-known-types.md │ │ │ └── redspot-patract.md │ │ ├── q-and-a.md │ │ └── reports │ │ │ ├── reports.md │ │ │ ├── v0.1Report.md │ │ │ ├── v0.2Report.md │ │ │ ├── v0.3Report.md │ │ │ └── v0.4Report.md │ │ ├── solang │ │ └── introduction.md │ │ └── zkmega │ │ ├── benchmark.md │ │ ├── contract.md │ │ ├── example.md │ │ ├── introduction.md │ │ ├── metis.md │ │ ├── reports.md │ │ ├── reports │ │ ├── v0.1Report.md │ │ └── v0.2Report.md │ │ └── tutorial.md │ └── docusaurus-theme-classic │ └── navbar.json ├── package.json ├── sidebars.ts ├── src └── css │ └── custom.css ├── static ├── .nojekyll └── img │ ├── favicon.png │ └── logo.svg ├── tsconfig.json ├── vercel.json └── yarn.lock /.github/workflows/push-master.yml: -------------------------------------------------------------------------------- 1 | name: Master 2 | on: 3 | push: 4 | branches: 5 | - master 6 | 7 | jobs: 8 | github_page: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | - name: Use Node.js 15.x 14 | uses: actions/setup-node@v1 15 | with: 16 | node-version: 15.x 17 | - run: yarn install 18 | - run: yarn build:gh_pages 19 | 20 | - name: Deploy 21 | uses: JamesIves/github-pages-deploy-action@4.1.0 22 | with: 23 | branch: gh-pages 24 | folder: build 25 | 26 | vercel: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - uses: actions/checkout@v2 30 | 31 | - name: Deploy Vercel 32 | uses: amondnet/vercel-action@v20 33 | with: 34 | vercel-token: ${{ secrets.VERCEL_TOKEN }} 35 | vercel-args: '--prod' 36 | vercel-org-id: ${{ secrets.VERCEL_ORG_ID}} 37 | vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID}} 38 | vercel-project-name: patra-store 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | .docusaurus 4 | 5 | .idea/ 6 | .vscode/ 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | or start with English 18 | 19 | ``` 20 | $ yarn start --locale en 21 | ``` 22 | 23 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 24 | 25 | ### Build 26 | 27 | ``` 28 | $ yarn build 29 | ``` 30 | 31 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 32 | 33 | ### Write translations 34 | 35 | ``` 36 | $ yarn write-translations --locale {language} 37 | ``` 38 | 39 | This command will generates translations in `i18n/{language}` folder. -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/ask/guides/architecture.md: -------------------------------------------------------------------------------- 1 | ## Architecutre 2 | 3 | ## Mechanism 4 | ### ink! - rust Macros 5 | The way how ask! is implmented is very similar to ink!. Ink utilizes rust Macros to server as an eDSL to write smart contracts. 6 | 7 | ### ask! - Assemblyscript Transform 8 | On the other hand, since Assemblyscrit is compiled statically, so code transformation cannot be done at runtime but must instead be performed at complied time. To enable this, the compiler frontend (asc) provides a mechanism to hook into the compilation process before, while and after the module is being compiled. By implementing a custom transform plugin for Assemblyscript, we make ask! to serve as an eDSL of assemblyscript. 9 | 10 | ### ask! - Decorators 11 | Since Typescript/AssemblyScript supports decorators, ask! chooses using decorators to achieve the same purpose as rust Macros. Ask! uses decorators to extend the Abstraction Syntax Tree to implement the internal logics with additional code. Using decorators can hide the complex logic of contract execution and interaction with `contract-pallet` to allow developers only focus on contract development alone. 12 | 13 | ## How compilation works in ask! 14 | ask! implements [transform](https://github.com/patractlabs/ask/tree/master/ts-packages/transform) to interview with Assemblyscript compilation process as follows: 15 | 16 | 17 | ![ask-design](../img/ask-design.png) 18 | -------------------------------------------------------------------------------- /docs/ask/guides/ask-cli.md: -------------------------------------------------------------------------------- 1 | # ask-cli 2 | 3 | ## Usage 4 | ```typescript 5 | npx pl-ask-cli xxx 6 | ``` 7 | 8 | ## init 9 | initialize a ask project with node packages and create directory structure 10 | ```bash 11 | npx pl-ask-cli init 12 | ``` 13 | Will create the directory structure like 14 | ``` 15 | project 16 | │ package-lock.json 17 | | 18 | └───node_modules 19 | │ 20 | └───contracts 21 | ``` 22 | ## compile 23 | ```bash 24 | npx pl-ask-cli compile source-file [--debug|--release] 25 | ``` 26 | By default, `npx pl-ask-cli compile` will compile in release mode. 27 | 28 | For example, `npx pl-ask-cli compile contracts/index.ts` will yield. 29 | ``` 30 | project 31 | │ package-lock.json 32 | | 33 | └───node_modules 34 | │ 35 | └───contracts 36 | │ ├── index.ts 37 | │ └── erc20.ts 38 | │ 39 | └───build 40 | │ ├── index.wasm 41 | │ └── metadata.json 42 | ``` 43 | For example, `npx pl-ask-cli compile contracts/index.ts --debug` will yield. 44 | ``` 45 | project 46 | │ package-lock.json 47 | | 48 | └───node_modules 49 | │ 50 | └───contracts 51 | │ ├── index.ts 52 | │ └── erc20.ts 53 | │ 54 | └───build 55 | │ └───extension 56 | │ │ ERC20.ts 57 | │ │ index.ts 58 | │ ├── index.wasm 59 | │ └── metadata.json 60 | │ └── index.wast 61 | ``` -------------------------------------------------------------------------------- /docs/ask/guides/ask-ink.md: -------------------------------------------------------------------------------- 1 | # Ask! vs ink! 2 | 3 | If you have written contracts ink!, you can grab ask! quickly by simply understand their differences. 4 | 5 | | | ink! | Ask! | 6 | | :--------------------------- | :-------------------------- | :------------------------------------ | 7 | | Language | Rust | AssemblyScript | 8 | | Overflow Protection | Enabled by default | None | 9 | | Constructor Functions | Multiple | Multiple | 10 | | Tooling | Anything that supports Rust | Anything that supports AssemblyScript | 11 | | Versioning | Semantic | Semantic | 12 | | Has metadata? | Yes | Yes | 13 | | Multi-File Project | Planned | Yes | 14 | | Storage Entries | Variable | Variable | 15 | | Has Interfaces? | Yes (Rust Traits) | Yes | 16 | | Has Inheritance? | No | Yes | 17 | | Support unit test? | Yes | No | 18 | | Support cross-contract calls | Not production ready | Yes | -------------------------------------------------------------------------------- /docs/ask/guides/cross-contract.md: -------------------------------------------------------------------------------- 1 | # Cross Contract Calling 2 | 3 | Assume that the following contract A already exists on the chain. 4 | ```typescript 5 | @contract 6 | class Libadd { 7 | constructor() {} 8 | 9 | @constructor 10 | default(): void {} 11 | 12 | @message(mutates = false) 13 | add(a: i32, b: i32): i32 { 14 | return a + b; 15 | } 16 | } 17 | ``` 18 | If you want to call the contract in contract B, you can declare a @dynamic class to describe its interface. 19 | ```typescript 20 | @dynamic 21 | export class Libadd { 22 | // Note that the method experience here will be covered by the actual code, this writing is mainly for compiling 23 | add(a: i32, b: i32): i32 { 24 | return 0; 25 | } 26 | } 27 | 28 | @contract 29 | class LibaddCaller { 30 | constructor() {} 31 | 32 | @constructor 33 | default(): void {} 34 | 35 | @message(mutates = false) 36 | callAddFromExternal(outAddress: AccountId, a: i32, b: i32): i32 { 37 | let outContract = new Libadd(outAddress); 38 | let val = outContract.add(a, b); 39 | return val; 40 | } 41 | } 42 | ``` 43 | outAddress here is the instance address of contract Libadd. 44 | 45 | This function can also call contracts written in other smart contract languages, such as ink!, as long as it follows the compatible metadata.json specification. -------------------------------------------------------------------------------- /docs/ask/guides/decorators/event-decorator.md: -------------------------------------------------------------------------------- 1 | # Event Decorators 2 | 3 | ## Class Decorator 4 | ### @event 5 | #### Usage 6 | Smart contracts can define events that can be emitted during contract execution, and third-party tools can use emitted events to query information about contract execution and status. Event fields must implement the Codec interface, they will be collected as event data, and the fields decorated by @topic will also serve as the index of the event. 7 | 8 | > `@event` class currently does not supports inheritence 9 | 10 | #### Example 11 | ```typescript 12 | @event 13 | class Transfer { 14 | @topic from: AccountId; 15 | @topic to: AccountId; 16 | 17 | value: u128; 18 | 19 | constructor(from: AccountId, to : AccountId, value: u128) { 20 | this.from = from; 21 | this.to = to; 22 | this.value = value; 23 | } 24 | } 25 | ``` 26 | 27 | ## Property Decorator 28 | ### @topic 29 | #### Usage 30 | - `@topic` can only be used underneath `@event` class 31 | - The property decorated with `@topic` will generate an additional topic index. 32 | - There is a limit to the number of indexes for each event (the default maximum is four). 33 | 34 | #### Example 35 | ```typescript 36 | @topic from: AccountId; 37 | ``` 38 | -------------------------------------------------------------------------------- /docs/ask/guides/decorators/overview.md: -------------------------------------------------------------------------------- 1 | # Decorators overview 2 | 3 | ask! provides a set of decorators to allow developers to code smart contract in Assemblyscirpt. eg.`@contract`. To further define the decorator's behavior during compilation, ask! introduces parameters within decorator. eg. `@message({"mutates": false})`. Currently, ask! has mainly two types of decorators: class decorators and syntax decorators. 4 | 5 | ## contract 6 | ### class: 7 | [`@contract`](./contract-decorator.md###@contract): marks this class as a contract 8 | 9 | [@dynamic](././contract-decorator.md###@dynamic): marks this class as an existing contract for cross contract call 10 | 11 | ### property: 12 | [`@state`](./contract-decorator.md###@state): marks this class property as state needs to be synced to blockchain 13 | 14 | ### method: 15 | [`@constructor`](./contract-decorator.md###@constructor): marks this method as constructor in instatiate a contract 16 | 17 | [`@message`](./contract-decorator.md###@message): marks this method as a public method in a smart contract 18 | 19 | ## event 20 | ### class 21 | [`@event`](./event-decorator.md###@event): marks this class as an event emitted during contract execution 22 | 23 | ### property: 24 | [`@topic`](./event-decorator.md###@topic): marks this class property as a topic and to be indexed 25 | 26 | ## metadata 27 | `@doc`: provide documentation for the information generated by metadata.json. It can add documentation comments for @contract/@event/@message/@constructor declarations. 28 | 29 | ```typescript 30 | @contract 31 | @doc(desc = "MyToken conract that implement erc20 contract") 32 | class MyToken { 33 | // ... 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /docs/ask/guides/examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | In our [examples](https://github.com/patractlabs/ask/tree/v0.3-review/examples) directory you find a number of examples written in ask!. 3 | 4 | We provide some samples written in Ask!: 5 | 6 | To build a single example navigate to the root of the example and run: 7 | ``` 8 | npx pl-ask-cli compile 9 | ``` 10 | 11 | * `flipper` : shows how to flip a boolean. 12 | * `incrementer` : shows how to load, modify and restore a state variable. 13 | * `crosscall` : shows how to do a cross call between contracts written in ink! and Ask!. 14 | * `erc20`: shows how to write an ERC20 contract with Ask!. 15 | * `erc721`: shows how to write an ERC721 contract with Ask!. 16 | * `composite`: shows how to store / reload composite data types. 17 | 18 | For example, `npx pl-ask-cli compile erc20/index.ts` will yield. 19 | ``` 20 | project 21 | │ package-lock.json 22 | | 23 | └───node_modules 24 | │ 25 | └───contracts 26 | │ ├── index.ts 27 | │ └── erc20.ts 28 | │ 29 | └───build 30 | │ ├── index.wasm 31 | │ └── metadata.json 32 | -------------------------------------------------------------------------------- /docs/ask/guides/global.md: -------------------------------------------------------------------------------- 1 | # Environment Variables 2 | Environment Variables are variables globally available in `@contract` class 3 | It's advised to use those variables under `@contructor` and `@message` methods 4 | 5 | ## block 6 | ### `block.timestamp (u64)` 7 | current block timestamp as seconds since unix epoch 8 | 9 | ### `block.number (u32)` 10 | current block number 11 | 12 | ## msg 13 | ### `msg.value (u128)` 14 | seal_value_transferred 15 | 16 | ### `msg.sender (AccountId)` 17 | sender of the message (current call) 18 | 19 | ### `msg.sig (u8)` 20 | first four bytes of the calldata (i.e. function identifier) 21 | 22 | ### `msg.data (u8)` 23 | complete calldata 24 | -------------------------------------------------------------------------------- /docs/ask/guides/types-storage/basic_types.md: -------------------------------------------------------------------------------- 1 | # Storage and data strucutures 2 | 3 | ## Basic Types 4 | Ask! provides its own data types implmenting scale codec corresponding to basic data types in [AssemblyScript](https://www.assemblyscript.org/) and standard library collections. 5 | 6 | | AssemblyScript | ask! |ask! convert | 7 | | ----------- | ----------- |----------- | 8 | | `bool` | `Bool` |true | 9 | | `i{8, 16, 32, 64, 128}` | `Int{8, 16, 32, 64, 128}` |true | 10 | | `u{8, 16, 32, 64, 128}` | `UInt{8, 16, 32, 64, 128}` |true | 11 | | `string(String)` | `ScaleString` |true | 12 | | `Array` | `ScaleArray` |false | 13 | | `Set` | `ScaleSet` |false | 14 | | `Map` | `ScaleMap` |false | 15 | 16 | 17 | 18 | When the basic assemblyscript types in the table above are used in the contract code (not including container types such as `Array`/`Set`/`Map`), Ask! It will be automatically converted to the corresponding Scale type (that is, automatic boxing/unboxing) for storage during compile time. 19 | 20 | ## Contract Parameter Types 21 | Contract Parameter Types are types defined to communicate Frame `pallet-contract` 22 | 23 | | Contract Parameter Types | ask! types | 24 | | ----------- | ----------- | 25 | | `AccountId` | `Array(32)` | 26 | | `Hash` | `Array(32)` | 27 | | `Balance` | `UInt128` | 28 | | `BlockNumber` | `UInt32` | 29 | 30 | You can customize them in `assembly/env/CustomTypes.ts` as long as the correct Codec is implementd. 31 | 32 | ## Usage 33 | ### storage 34 | You can import `Bool` via `ask-lang`. 35 | ```ts 36 | import { Bool } from 'ask-lang'; 37 | ``` 38 | If you need to store this data for blockchain storage 39 | ```typescript 40 | class Flipper { 41 | @state flag: Bool; 42 | } 43 | ``` 44 | 45 | You can also directly use `bool` and ask! will convert it automatically during compilation 46 | ```typescript 47 | class Flipper { 48 | @state flag: bool; 49 | } 50 | ``` 51 | ### Opt out of storage 52 | If you does not need to sync the data to blockchain storage but just declare it as a normal class property 53 | 54 | ```typescript 55 | class Flipper { 56 | @state flag: bool; 57 | flag1: bool; 58 | } 59 | ``` 60 | 61 | ## Lazy 62 | When a data is decorated with `@state`, it means it will sync with the blockchain database when its value gets changed which involves calling host function `seal_set_storage` or `seal_get_storage`. However, calling host function is expensive in terms of wasm performance. 63 | 64 | Therefore `@state` introduces lazy option as: `@state({"lazy": false})` While lazy is true, that means while a state variable gets changed multiple times in a contract call, only the last change will be synced to blockchain. 65 | 66 | By default, `lazy` is set to `true`. While lazy is false, then every change made to the state variable will be synced to blockchain. 67 | 68 | Basic principle of implmentation: For every state varible with lazy set as true, the setter function generated by compiler will only updates the value changed in memory; Meanwhile, compiler also creates a __commit__ function. If the state variables within this function ever gets changed before the contract call is done, the updated values will be synced to blockchain. 69 | 70 | -------------------------------------------------------------------------------- /docs/ask/img/ask-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/img/ask-design.png -------------------------------------------------------------------------------- /docs/ask/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | ask! is an Embedded Domain Specific Language (EDSL) to write WebAssembly based smart contracts using typescript. 3 | 4 | Unlike solidity, ask! is not a standalone languange but more like a assemblyscript "contract format" with customized `@message` decorator. Those decorators tell ask! compiler how the smart contract is define and further compiles them to WASM bytecode compatible with Substrate. 5 | 6 | ## Assemblyscript 7 | ask! is subset of Assemblyscript while Assemblyscript is a subset of Typescript syntax. Currently, a large group of developers are using Typescript since Typescript has relatively low learning curve. Therefore, Patract Labs optimistically believes with the introduction of ask!, we would see a good growth of contract developers in Substrate. 8 | 9 | ## ask! vs ink! 10 | | languange | ask! | ink! | 11 | | :--- | :----: | ---: | 12 | | eDSL | Typescript | rust | 13 | | annotation | decorator | macro | 14 | | cli | [ask-cli](https://github.com/patractlabs/ask-cli) | [cargo contract](https://github.com/paritytech/cargo-contract) | 15 | | abstraction | inheritence | trait | 16 | | data types | [AssemblyScript SCALE Codec](https://github.com/LimeChain/as-scale-codec) | [Parity SCALE Codec](https://github.com/paritytech/parity-scale-codec)| 17 | 18 | ## Reports 19 | - [v0.1Report](../reports/v0.1Report.md) 20 | - [v0.2Report](../reports/v0.2Report.md) 21 | - [v0.3Report](../reports/v0.3Report.md) -------------------------------------------------------------------------------- /docs/ask/intro/why-ask.md: -------------------------------------------------------------------------------- 1 | Why AssemblyScript for WASM Smart Contracts. 2 | ask! is not a new programming language but rather a subset of Aseemblyscript by utilizing decorators. 3 | 4 | - Being a variant of TypeScript makes it easy to compile to WebAssembly without learning a new language. 5 | - AssemblyScript is the most popular language for WASM besides C/CPP/Rust 6 | - AssemblyScript targets WebAssembly's feature set specifically, giving developers low-level control over their code. 7 | - Integrates with the existing JS ecosystem - no heavy toolchains to set up. Simply npm install it! 8 | - Small WASM size and high contract execution performance when comparing to Rust -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.1Report_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.1Report_call.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.1Report_deploy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.1Report_deploy.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.1Report_deploy_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.1Report_deploy_result.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.1Report_upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.1Report_upload.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.2PackedStorableArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.2PackedStorableArray.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.2PackedStorableMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.2PackedStorableMap.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.2SpreadStorableArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.2SpreadStorableArray.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.2SpreadStorableMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.2SpreadStorableMap.png -------------------------------------------------------------------------------- /docs/ask/reports/img/v0.2erc20.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/ask/reports/img/v0.2erc20.gif -------------------------------------------------------------------------------- /docs/contracts/imgs/language_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/contracts/imgs/language_1.jpg -------------------------------------------------------------------------------- /docs/contracts/imgs/language_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/contracts/imgs/language_2.jpg -------------------------------------------------------------------------------- /docs/contracts/imgs/model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/contracts/imgs/model.jpg -------------------------------------------------------------------------------- /docs/contracts/imgs/overview_module.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/contracts/imgs/overview_module.jpg -------------------------------------------------------------------------------- /docs/contracts/imgs/wasm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/contracts/imgs/wasm.jpg -------------------------------------------------------------------------------- /docs/contracts/introduction.md: -------------------------------------------------------------------------------- 1 | # Substrate 合约书 2 | 3 | ## 合约书概览 4 | 5 | 本书介绍了 Substrate 中与合约体系相关的一系列知识,由[Patract](https://patract.io/)主导编写,由[Aten](https://github.com/atenjin)负责维护。仓库地址位于[substrate-contracts-book](https://github.com/patractlabs/substrate-contracts-book),欢迎有志之士一起为本书做出贡献。 6 | 7 | 本书主要从以下三个方面进行阐述: 8 | 9 | * 运行合约的合约平台(模块) 10 | * 编写合约的语言 11 | * 协助合约开发的工具 12 | 13 | 其中由于`pallet-evm`(即EVM/Solidity体系的合约)在以太坊生态中已有比较丰富的资料,故不在本合约书中做重点讲解。而其他的合约体系,例如`pallet-actor`、`libra`移植合约平台等都处于早期的研究阶段,因此在本书中也不作重点讲解。 14 | 15 | 本书以`pallet-contracts`(即Wasm合约)作为主体进行介绍,内容主要包含: 16 | 17 | 运行合约的合约平台(模块) 18 | 19 | * pallet-contracts 20 | 21 | 编写合约的语言 22 | 23 | * ink! 24 | * Ask! 25 | * Solang 26 | 27 | 协助合约开发的工具 28 | 29 | * Redspot 30 | * Europa 31 | * Elara 32 | 33 | 为了让您更好的理解`pallet-contracts`模块与Wasm合约的运行方式,本书也会涉及Wasm和区块链合约模型的介绍。相信本书一定会让您有所收益。 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /docs/contracts/overview.md: -------------------------------------------------------------------------------- 1 | # 合约综述 2 | 3 | ## 背景信息 4 | 5 | 区块链运行合约的模型从本质上可以认为是区块链的环境(分布式共识系统)和能运行一段逻辑的平台,例如比特币的模型可以拆分为区块模型/PoW 和比特币脚本,以太坊的模型可以拆分为区块、状态模型/PoW和EVM,Substrate的模型可以拆分为区块、状态模型/Bft共识和Runtime。 6 | 7 | 因此一般来说,可以将区块链的模型拆分成: 8 | 9 | * 运行区块链的底层系统:提供分布式可信环境。 10 | * 链的业务逻辑:运行在可信环境中。 11 | 12 | 在区块链系统中,要求对相同的代码,相同的状态,执行的结果一定要一致。因此在提供链的业务逻辑这一层,为了保证执行结果的一致,要求整个运行环境不会因为运行节点的不一致(指不是同一个节点)而导致运行的结果不一致。为了保证这种特性,绝大部分区块链都会采用沙盒/虚拟机的模型,并在其基础上裁剪一些功能来实现。 13 | 14 | 运行合约的平台是一种链的业务逻辑,这种业务逻辑特殊在其上面可运行的代码是开放的,合约内容不受链本身控制。对于这种情况,更需要一种沙盒的环境来隔离各个合约之间的运行。 15 | 16 | ## 什么是沙盒 17 | 18 | 沙盒在计算机领域中的概念很广泛,虚拟机最容易模拟沙盒的环境。因此在区块链中,一般而言沙盒都会由一个虚拟机去运行。不同的链采用不同的虚拟机来运行合约的沙盒。 19 | 20 | * Ethereum 21 | 22 | Gavin Wood 写的黄皮书中提出了EVM的模型,创建了以太坊虚拟机(EVM)的概念并拟定了EVM的OP_CODE,之后设计了Solidity编译到OP_CODE,从而有了Ethereum的整个生态。相当于Ethereum处理区块链的合约沙盒模型,从零到一构建所有设施。因此Solidity的语法以及EVM能做的事和现在的区块链相比,就显得十分简陋,例如Solidity的语法、EVM的栈深限制等。但其作为先行者开创了区块链合约虚拟机模型的先河。 23 | 24 | * Fabric 25 | 26 | 作为联盟链,在使用场景上与公有链存在区别。Fabric提出链码的概念,并将链码运行在了Docker上。和EVM相比,Docker就是比较重的一种虚拟机。因此与EVM比较,Fabric的链码可以做到比Solidity更多的事,当然其运行的代价会相对高很多。 27 | 28 | * EOS 29 | 30 | EOS采用了Wasm作为合约的虚拟机,当时也是EOS的优势。相比于运行Solidity的EVM,EOS的Wasm虚拟机的运行效率高了许多,以C++作为编译到Wasm的语言也吸引了许多传统的开发者。EOS作为Wasm虚拟机的先行者,在当时已经体现出Wasm相对于EVM的优势,但由于其合约模型的设计的缺陷和当时环境的约束,以及EOS并非真正的去中心化系统,导致EOS并没有很好的展现出Wasm合约系统的能力。 31 | 32 | * Substrate 的`pallet-contracts` 33 | 34 | `pallet-contracts`采用Wasm虚拟机来运行合约,当前出于安全方面的考虑,只采用了`Wasmi`解释器来执行Wasm。但其合约模型与EVM的合约模型近似(详见下一章节)。Wasm虚拟机与EVM同样具有启动快,随用随丢的特性,具备高性能和高扩展性的同时又不像Docker、 JVM一样太过庞大。因此Wasm慢慢在浏览器环境以外的更多场景被采用,例如边缘计算、热更新等。所以当前越来越多的新区块链在需要一个沙盒环境时会将Wasm虚拟机作为主要方案。另一方面Wasm也具备从不同语言编译到Wasm的特性,例如Rust、Assemblyscript、C++等,从而吸引了各类开发者加入到合约开发过程中。 35 | 36 | * 其他 37 | 38 | 其他区块链为了完成这个沙盒的目标也会有各自的方案,有的联盟链采用了裁剪过的JVM,有的公链采用了`RISC-V`的虚拟机,有的链采用了从零设计一个虚拟机(例如libra)。这些方案各自有各自的需求与特性,但从模型上而言,无论什么方案,最终目标都是为了提供一个虚拟机环境以运行合约沙盒。 39 | 40 | ## 运行合约的沙盒 41 | 42 | 链的业务逻辑大部分会运行于沙盒的系统中,且运行合约这种业务逻辑更是需要沙盒进行隔离。而另一方面Substrate的runtime就是一个运行于Wasm中的沙盒环境,因此在Substrate的合约模块 43 | 44 | `pallet-evm`和`pallet-contracts`,就是需要在一个沙盒环境中运行另一个沙盒,如下图所示。 45 | 46 | ![](./imgs/overview_module.jpg) 47 | 48 | * 图左是以太坊模型,表示每运行一个合约,需要在链的平台上启动一个以太坊虚拟机去运行。 49 | * 图右是Substrate模型,Substrate链的业务逻辑在Wasm虚拟机中运行。 50 | 51 | `pallet-evm`:将以太坊的EVM编译到了Runtime Wasm当中,因此每运行一个合约实际上与以太坊一致,创建了一个以太坊虚拟机去运行。如果链是以Wasm形态运行,即是在Wasm虚拟机中生成了一个以太坊虚拟机去运行。 52 | 53 | `pallet-contracts`:Wasm合约使用Wasm虚拟机运行合约,与`pallet-evm`不同的是,如果链是以Wasm形态运行,Wasm合约的虚拟机是跳出当前Runtime Wasm虚拟机,重新创建了一个新的Wasm虚拟机运行。截止目前,Runtime的Wasm虚拟机推荐采用的是`Wasmtime`,而`pallet-contracts`只能采用`Wasmi`。`pallet-contracts`也可以使用`Wasmtime`执行,但是当前Parity认为`Wasmtime`不可控性比较大,因此暂时还未采用`Wasmtime`。当前他们有相关计划,也有原型代码来使用`Wasmtime`运行`pallet-contracts`的合约。 54 | 55 | > 注意,在substrate合并了提交[Remove dependency on sandboxing host functions #9592](https://github.com/paritytech/substrate/pull/9592)后,wasmi 在 Wasm 的执行环境下不再跳出当前 Wasm 执行器独立执行,而是视作一段正常的程序运行于当前的 Wasm 环境中。此时的运行模型就与 pallet-evm 是一致的,即在 Wasm 环境中运行了一个 Wasm 解释器,在该解释器中去执行 Wasm 代码。 56 | 57 | 总之在运行合约的过程中,大部分链都采用了一种沙盒的模型去运行合约。而对于EVM和 58 | 59 | `pallet-contracts`模型而言,每运行一个合约就会创建一个虚拟机。 60 | 61 | ## 更多信息 62 | 63 | Wasmtime是实现了JIT的Wasm虚拟机,而`Wasmi`是纯解释器型的Wasm虚拟机。从执行效率上来说,Wasmtime的执行效率比Wasmi高很多。 64 | -------------------------------------------------------------------------------- /docs/contracts/wasm_first_step.md: -------------------------------------------------------------------------------- 1 | # Wasm简要介绍 2 | 3 | ## Wasm与合约模型的关联 4 | ![](./imgs/wasm.jpg) 5 | -------------------------------------------------------------------------------- /docs/elara/design.md: -------------------------------------------------------------------------------- 1 | # 设计简述 2 | 3 | Elara有长期的开发迭代规划和运维目标,为的是能够支撑Polkadot生态开发者从万+级别到亿+级别的持续跃迁。Elara的核心是一套高性能、高可用和高扩展的分布式架构。与其他提供 Node API Service的项目有显著区别: 4 | 5 | 1. Elara的后端架构不是简单但低效的NodePool+LoadBalancer。这种方案无法承担大规模应用和流量的冲击,无法及时扩展,因为Node会成为体系中的显著瓶颈。而在Elara的架构中,只需要很少数量的Node提供基础数据源。Elara通过分布式架构的设计、多服务的融合以及对请求访问路径的极致优化,来支撑海量用户的访问。NodePool方案的短期开发成本较低,但长期服务用户的单位成本却极高。反过来,Elara在初期的技术成本投入较高,但长期可以极大降低服务用户的单位成本,同时还可以保障高服务质量。 6 | 7 | 2. Elara专注于为生态开发者提供极简的全功能体验。我们提供的是极其“薄薄”的一层服务,希望开发者感受不到Elara的存在。Elara提供的API服务不仅包括节点的所有功能,也包括了历史状态数据功能,还包括项目的请求统计仪表盘等功能,给开发者提供的服务能力远大于自己部署节点所提供的能力。所以,在这个目标之下,"一键节点部署"之类的功能就显得非常多余,开发者只应该专注于自己的业务应用。 8 | 9 | 3. Elara是一个开放的平台,秉持社区共建的原则。在接下来的版本迭代中,我们会陆续接入更多主网,还会建立一套Polkadot生态主链和平行链自动化接入的流程规范。 10 | 11 | 12 | 13 | 在整体设计上,Elara设计成微服务的架构体系,由多个可独立进行扩展的微服务组成。所有的微服务启动后都以独立进程运行,所以在将来可以对单独的微服务进行平行扩容、重构、替换实现等升级。其中用到`Redis`作为数据高速访问的存储容器,和使用`kafka`做架构解耦。将来可以很容易地在此设计的基础上,添加更多复杂的功能模块,让Elara发挥更强大的效果。 14 | 15 | Elara的核心架构大概如下所示 16 | 17 | ![elara](https://user-images.githubusercontent.com/21072025/111115173-35923280-859f-11eb-8172-737c07aab4e7.png) 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/elara/introduction.md: -------------------------------------------------------------------------------- 1 | # Elara 2 | 3 | 在Polkadot、Kusama或Parachain中,RPC是Dapp与网络交互的界面。随着Polkadot网络的不断扩展,会有越来越多的平行链上线,也会有越来越多的平行链支持智能合约功能。面对越来越多的平行链,开发者们为了与之交互需要搭建并维护多条链的节点RPC,这对于他们而言将是巨大的开发成本。 4 | 5 | 无论是面对开发者的开发测试需要,还是用户线上对Dapp的使用需求,方便便捷、快速稳定的网络接入能力都是必备条件之一。因此,为开发者们和普通用户提供统一简化的网络接入服务能力是服务Dapp开发者的必要支撑,也是Polkadot生态的基础设施。 6 | 7 | Elara的目标是构建一个类似Infura 的基础架构和网络公共接入服务,为开发者提供多链接入的统一接入层。 我们将创建一个普适的架构,可以很方便接入Polkadot、Kusama、各个平行链和各个substrate链,即专注于为Polkadot、Kusama服务,也保持扩展性,普惠整个Substrate生态。 8 | 9 | 另外,Elara将作为智能合约开发生态服务的一部分,在未来将与Patract Suite的其他组件进行整合,在合约开发环境支持、开发工具组件、合约部署和应用发布等方面进行全方位整合,简化应用基础架构,让开发者可以专注于构建上层应用。 10 | 11 | 当前,我们已经提供在线服务elara.patract.io .欢迎社区使用Elara: 12 | - 所有人都可以使用Elara提供的Polkadot和多个生态主网的公共共享RPC服务( 如wss://polkadot.elara.patract.io 和 https://polkadot.elara.patract.io ). 13 | - 开发者可以访问elara.patract.io获得免费接入多个网络的独占在线服务. 14 | 15 | 更多信息: 16 | 17 | Github: 18 | 19 | Homepage: 20 | 21 | Docs: 22 | 23 | ## Elara 议会提案报告 24 | 25 | - [v0.1Report](./reports/v0.1Report.md) 26 | - [v0.2Report](./reports/v0.2Report.md) 27 | -------------------------------------------------------------------------------- /docs/elara/reports.md: -------------------------------------------------------------------------------- 1 | # Elara议会提案报告 2 | 3 | 提案报告是Patract向Polkdaot/Kusama财政提交申请后,在结束汇报阶段提交评审的文档。每一期文档涵盖了本次提案中的设计思路,完成的主要内容。 4 | 5 | 报告代表着本次Patract团队的工作成果,同时也是很好的参考文档。 6 | 7 | 当前Elara的提案报告有如下内容: 8 | 9 | - [v0.1Report](./reports/v0.1Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | 12 | -------------------------------------------------------------------------------- /docs/elara/tutorial.md: -------------------------------------------------------------------------------- 1 | # Tutorial 2 | Elara的API需要有效的Project Endpoint包含在您的请求中。此标识符应附加到请求URL。 3 | 4 | ## 获取YOUR-PROJECT-ENDPOINT 5 | 1.使用您的github帐户登录[Elara官方网站](https://elara.patract.io/) 6 | 7 | 2.进入[Elara Dashboard](https://elara.patract.io/#/dashboard/console),单击以选中左侧边栏中的主链。 8 | 9 | 3.单击右上角的“创建新项目”按钮,在弹出对话框中输入“ PROJECT-NAME”,然后单击“确定”。如果一切正常,您将看到一条消息,说明该项目已成功创建。 10 | 11 | 4.在项目列表中,单击项目以进入项目详细信息页面 12 | -有一列信息显示“ PID”,一串长度为32的字符和数字,即项目的“ YOUR-PROJECT-ID” 13 | -有一列显示“ ENDPOINTS”的信息,包括访问ENDPOINT的“ https”和“ wss”。那就是项目的“ YOUR-PROJECT-ENDPOINT” 14 | 15 | 16 | 17 | ## 发出请求 18 | 19 | 使用这些ENDPOINT之一作为您的客户端程序的Provider。 20 | 21 | 22 | *注意:请务必将YOUR-PROJECT-ENDPOINT替换为Elara仪表板中的Project Endpoint * 23 | 24 | - 方法1:curl发送HTTP请求: 25 | ``` 26 | #curl http 27 | curl --location --request POST 'https://YOUR-PROJECT-ENDPOINT' \ 28 | --header 'Content-Type: application/json' \ 29 | --data-raw '{ 30 | "id":1, 31 | "jsonrpc":"2.0", 32 | "method":"chain_getBlock", 33 | "params":[] 34 | }' 35 | ``` 36 | 37 | - 方法2:使用wscat发送websocket请求: 38 | ``` 39 | parachain@ubuntu:~/elara$ wscat -c wss://YOUR-PROJECT-ENDPOINT 40 | Connected (press CTRL+C to quit) 41 | > {"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]} 42 | < {"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x280402000b901ac96e7601"],"header":{"digest":{"logs":["0x066175726120dfcdf90f00000000","0x05617572610101acb2a4725f0f8945593cea6aa6ef70df2a8fd4a2c4eb1c0d1bf51828f26e371f897473113541f9c0d9f94e51471a3d685a86866a12133ea012d2777bb9709589"]},"extrinsicsRoot":"0xcca5112546305b07d904c2aa26155dffe6c66de043708e1ac89e57609fbcc6d1","number":"0x17922","parentHash":"0xdb798a19707ef9085b97d0b00854c613ae4abdb560e2ea1164f2e7bbfbc288a1","stateRoot":"0xdc575fe975067ded933020df9035db0e496143e6b9a062a4313fd1f6e9d02922"}},"justification":null},"id":1} 43 | > 44 | ``` 45 | 46 | - 方法3:使用SDK 47 | 48 | 您可以参考polkadot-js,使用以下类似代码通过Https或Websocket访问节点: 49 | ``` 50 | const { ApiPromise, WsProvider } = require('@polkadot/api'); 51 | const { HttpProvider } = require('@polkadot/rpc-provider'); 52 | 53 | (async function () { 54 | // Http 55 | const httpProvider = new HttpProvider('https://YOUR-PROJECT-ENDPOINT') 56 | const hash = await httpProvider.send('chain_getBlockHash', []) 57 | console.log('latest block Hash', hash) 58 | 59 | // Websocket 60 | const wsProvider = new WsProvider('wss://YOUR-PROJECT-ENDPOINT') 61 | const api = await ApiPromise.create({ provider: wsProvider }) 62 | //Do something 63 | 64 | })() 65 | ``` 66 | 67 | 请务必注意,JSON-RPC请求与传输无关,可以通过HTTPS,Websockets发出相同的请求。 68 | -------------------------------------------------------------------------------- /docs/europa/guides/architecture.md: -------------------------------------------------------------------------------- 1 | # Architeture 2 | ## Another Substrate Implementation 3 | 4 | Europa sandbox framework is another implementation for [Substrate client](https://github.com/paritytech/substrate/tree/master/client).That means all substrate runtime could integrate with Europa client directly. 5 | 6 | ## No consensus, only producing blocks on need 7 | 8 | Europa focuses on contract development regardless which consensus protocol is running, so that we remove all components about consensus. Thus, we use `sc-consensus-manual-seal` crate to produce block. This crate is well abstracted with no need to fork. We just modify the part of commands stream for `manual-seal`. The async stream could receive information from different place (e.g. transaction pool, RPC and others) to drive seal-engine to produce blocks only when receiving extrinsics. 9 | 10 | ## Removed Wasm for Runtime 11 | 12 | As a sandbox designs for debugging during contract development, we remove all Wasm components as Wasm may cause many problems during debugging. Since we need to extend many features for low level libraries, if the runtime is compiled to Wasm for execution, we might encounter many unexpected problems. Also, as a local sandbox, we do not need the features brought by Wasm runtime such as non hard fork software update. 13 | 14 | *Europa runtime should remove `build.rs` in runtime crate and remove `[build-dependencies]` in runtime crate (cargo.toml file).* 15 | 16 | ## State KV to trace block state changes 17 | 18 | In Substrate, we can check the current blockchain states but not the state modifications. However, the developers are concerned mostly about the state changes when new blocks get mined. So that, they can check whether the changes match their expectations for debugging. 19 | 20 | Thus, in europa sandbox, we store the mapping of blockhash and state kvs in the state-kv database, so that developers could export the state changes to look up the details. 21 | 22 | ## `pallet-contracts` Modification 23 | * Modification on the `pallet contracts` layer: By adding trace during the execution of the contract in `pallet contracts`, the information in the contract layer is recorded, and the calling structure of the contract is recorded. The error message during Wasm execution is also enhanced. 24 | * Modification on the `wasmi` layer: We have provided the backtrace function of recording wasm execution for `wasmi`, and provided support for `parity-wasm`, `pwasm-utils`, and `cargo-contract` during wasm processing of the contract contains the function of the name section. 25 | * Contract logging function: Use the function of `ChainExtensions` to realize the library for printing the `log` in the contract. Check [Custom ChainExtensions](../extensions/custom-chain-extensions.md) for more details. 26 | 27 | Check [Contract Pallet Implementation](./implementation.md) for implemention details. 28 | -------------------------------------------------------------------------------- /docs/europa/guides/wasm-executor.md: -------------------------------------------------------------------------------- 1 | # Europa Wasm executor 2 | 3 | TODO: Not completed 4 | 5 | Europa offers different Wasm actuators to execute contracts. Currently `wasmi` and `wasmtime` are provided. -------------------------------------------------------------------------------- /docs/europa/imgs/add_exist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/add_exist.png -------------------------------------------------------------------------------- /docs/europa/imgs/call_other_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/call_other_1.png -------------------------------------------------------------------------------- /docs/europa/imgs/call_other_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/call_other_2.png -------------------------------------------------------------------------------- /docs/europa/imgs/contract_call_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/contract_call_contract.png -------------------------------------------------------------------------------- /docs/europa/imgs/contract_error_message.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/contract_error_message.png -------------------------------------------------------------------------------- /docs/europa/imgs/contract_extrinsic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/contract_extrinsic.png -------------------------------------------------------------------------------- /docs/europa/imgs/contract_wasmi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/contract_wasmi.png -------------------------------------------------------------------------------- /docs/europa/imgs/deployed_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/deployed_contract.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa-ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa-ui.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa_accounts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa_accounts.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa_contracts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa_contracts.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa_developer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa_developer.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa_instance_function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa_instance_function.png -------------------------------------------------------------------------------- /docs/europa/imgs/europa_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/europa_instances.png -------------------------------------------------------------------------------- /docs/europa/imgs/explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/imgs/explorer.png -------------------------------------------------------------------------------- /docs/europa/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Europa Overview 2 | 3 |
4 | 5 |
6 | 7 | Europa is a private test blockchain based on Substrate to help Runtime Pallet and `pallet-contracts` development. It modifies the native Substrate chain by removing unnecessary components such as Wasm execution and p2p while adding some great features to help developers get more insights of the contract execution details 8 | 9 | ## How does it work 10 | Europa runs as standalone daemon to serve JSON-RPC and Websocket requests. By default, it only mines a block every time it receive extrinsics. Extrinsic, by definition, means state changes that come from the outside the blockchain node itself. For example, a transaction is an extrinsic. Europa is a fork of substrate blockchain with handy modifications, so theoretically, runtime pallets and contracts developed through Europa will work on all substrate based chains as well. 11 | Check [Architectures](../guides/architecture.md) for more insights. 12 | 13 | ## Why use it? 14 | 1. Europa is an implementation of [substrate](https://github.com/paritytech/substrate), while Substrate is a modular framework that enables developers to create purpose-built blockchains by composing custom or pre-built components. For example, Polkadot, Kusama and other parachains are all based on substrate. 15 | 2. Producing a block only when receiving new extrinsics. Developers won't have to wait for block production or deal with redundent blocks. 16 | 3. Removing all wasm execution, only native runtime is kept for execution. By default, substrate support both wasm execution and native execution. Native execution is prprioritized to be used but wasm execution brings hard fork to chain without updating the node software. However, wasm execution makes the code harder to debug. 17 | 4. Additional database entry called `state-kv` to record the state changes. Developers can use RPC calls to fetch those state changes. `state-kv` can also be feteched through cli `europa state-kv ` 18 | 5. Custom RPC calls: 19 | - `europa_forwardToHeight`: forward the blockheight to certain block height with empty blocks 20 | - `europa_backwardToHeight`: revert the blockchain back to certain heights and remove states of reverted blocks 21 | - `europa_modifiedStateKvs`: retrive the cached state changes 22 | 6. Allow developers to swtich between multiple workspace for better dev environment isolation. 23 | 7. Europa also ships with Europa UI and compiled binary release. 24 | -------------------------------------------------------------------------------- /docs/europa/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Europa proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Europa proposal report has the following content: 8 | 9 | - [v0.1Report](./reports/v0.2Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | - [v0.3Report](./reports/v0.3Report.md) 12 | 13 | -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_contracts_codes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_contracts_codes.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_contracts_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_contracts_instances.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_explorer.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsic_cross_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsic_cross_call.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsic_details.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsic_details.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsic_state_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsic_state_1.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsic_state_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsic_state_2.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsic_wasm_err.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsic_wasm_err.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_extrinsics_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_extrinsics_call.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_instance_extrinsics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_instance_extrinsics.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_instance_functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_instance_functions.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_left.png -------------------------------------------------------------------------------- /docs/europa/reports/imgs/report3_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/europa/reports/imgs/report3_start.png -------------------------------------------------------------------------------- /docs/himalia/introduction.md: -------------------------------------------------------------------------------- 1 | # Himalia 2 | 3 | Himalia 是 Patract 构建的一系列不同语言的访问链`pallet-contracts`合约模块的sdk库的总称。对于Substrate而言,已经存在了一些面向不同语言的访问链的sdk。但是由于`pallet-contracts`模块的特殊性,需要继续构建基于访问链的sdk上的访问合约模块的sdk。其特殊性主要表现在: 4 | 5 | * 合约的部署与调用(包含rpc调用与交易调用)需要依据合约的metadata.json(类似于Solidity的abi文件)提供的信息组装参数的顺序的与编码,而链的metadata只能告知链的sdk该链上存在合约模块的`instantiate`,`call`等方法,不可能告知某个合约的调用参数的信息。因此对于合约,需要构建能解析并支持合约metadata的功能。 6 | * 合约的Event也需要依据合约的metadata.json进行解析。因此若使用链的sdk,只能监听到出现了合约模块的event,但是却无法解析出event中的内容。因此需要提供合约的sdk支持event的监听。 7 | * 合约的状态(存储)位于子树,且其key的编码与分配方式与runtime不一致。合约存储的key的编码分配方式与该合约所使用的合约语言框架有关(例如Ask!的实现有可能与ink!不一样),因此需要针对不同的合约语言框架实现对应的存储解析方式。同时这个解析过程也十分依赖合约本身提供的metadata。 8 | * 合约的开发者为广大的项目方,而链的开发者大部分情况下为开发链的项目方。因此在管理私钥的场景方面会出现比较大的区别。很多情况下与链高权限相关的私钥管理为节点自身,数量比较少且门槛高,或者很多情况下都依托于多签或者投票控制。而合约的开发者很广泛,后台安全管理质量参差不齐,另一方面很多合约都只有一个私钥进行控制。因此在对于合约模块的调用上,在私钥管理方面更需要一个高安全低门槛的解决方案。因此合约sdk可以在这些场景上做特殊处理,以减少合约开发者安全管理的门槛。 9 | 10 | 因此 Himalia 是有十分重要的存在理由的。Himalia的定位类似于 Ethereum 生态里的 Web3J, Web3py 等等。 11 | 12 | ## 项目仓库地址 13 | 14 | 当前 Himalia 提供的不同语言的合约sdk有如下版本: 15 | 16 | * go: https://github.com/patractlabs/go-patract 17 | 18 | * python: https://github.com/patractlabs/py-patract 19 | 20 | * java: 还未实现 21 | 22 | * c#(.net): 还未实现 23 | 24 | ## Himalia议会提案报告 25 | 26 | - [v0.1&v0.2Report](./reports/v0.1Report.md) 27 | -------------------------------------------------------------------------------- /docs/himalia/reports.md: -------------------------------------------------------------------------------- 1 | # Himalia议会提案报告 2 | 3 | 提案报告是Patract向Polkdaot/Kusama财政提交申请后,在结束汇报阶段提交评审的文档。每一期文档涵盖了本次提案中的设计思路,完成的主要内容。 4 | 5 | 报告代表着本次Patract团队的工作成果,同时也是很好的参考文档。 6 | 7 | 当前Himalia的提案报告有如下内容: 8 | 9 | - [v0.1&v0.2Report](./reports/v0.1Report.md) 10 | 11 | -------------------------------------------------------------------------------- /docs/ink/call-contracts.md: -------------------------------------------------------------------------------- 1 | # ink! 跨合约调用 2 | -------------------------------------------------------------------------------- /docs/ink/cargo-contract.md: -------------------------------------------------------------------------------- 1 | # cargo-contract 2 | -------------------------------------------------------------------------------- /docs/ink/framework.md: -------------------------------------------------------------------------------- 1 | # ink! 框架 2 | 3 | ink!的所有主体功能都实现于 [`ink/crates`](https://github.com/paritytech/ink/tree/master/crates) 目录下: 4 | 5 | * crates: 6 | * allocator:与Wasm相关,定义allocator,开发者绝大部分情况下无需关心 7 | * env:提供和链相交互的组件,总结来说就是和链相关的部分都会放在这里,包含 8 | * host function 部分 9 | * 部分需要导入的类型、trait定义 10 | * event 的topic 11 | * lang:eDSL过程宏的定义组件,合约的规范由这个地方决定 12 | * metadata:生成metadata的组件 13 | * prelude:合约编写过程中需要预先导入的包,包含一些标准库 14 | * primitives:操作状态存储的指针,开发者绝大部分情况下无需关心 15 | * storage:提供链存储的分配模型以及提供一些预定义好的存储集合类型 -------------------------------------------------------------------------------- /docs/ink/ink-solidity.md: -------------------------------------------------------------------------------- 1 | # ink! 与solidity的对比 2 | -------------------------------------------------------------------------------- /docs/ink/introduction.md: -------------------------------------------------------------------------------- 1 | # ink 2 | 3 | ink! is an eDSL to write WebAssembly based smart contracts using the Rust programming language. The compilation target are blockchains built on the Substrate framework. 4 | 5 | ink! 是 parity 官方编写的,可以提供一种 eDSL 的方式编写 Rust 合约,并编译为 Wasm 运行于 Contracts Pallet 模块上。 6 | 7 | 虽然 ink!自称为一种写合约的 eDSL,但是笔者更倾向于认为 ink!是使用 Rust 语言编写符合能满足 Contracts Pallet 运行的合约框架。 8 | 9 | 例如对于 EVM 而言,若把 EVM 的指令集看做一种规范(EVM 的指令集已经包含了 EVM 合约模型的信息),那么只要能编译到 EVM 指令集的语言都可以称为能运行在 EVM 上的合约语言,例如: 10 | 11 | - Solidity 12 | - Vyper 13 | 14 | 而 ink!这里同理。Contracts Pallet 要求是能满足运行 Contracts Pallet 合约模型的 Wasm 代码,因此任何能编译成满足这个 Wasm 合约模型的框架/语言/库都可以称为 Contracts Pallet 的合约语言。 15 | 16 | ink!就是使用 Rust 语言,并在此基础上通过 Rust 的**卫生宏系统**设计了一套 eDSL,并使用该 eDSL 编写能满足 Contracts Pallet 要求的 Rust 代码。除 eDSL 之外,ink!还提供了适用于合约模型的**存储集合类型**,生成 Metadata(对应于 Solidity 的 ABI)等工具库。 17 | 18 | ink!的官方文档见: 19 | 20 | - [ink! Concepts](https://substrate.dev/docs/en/knowledgebase/smart-contracts/ink-fundamentals) 21 | - [ink! Smart Contracts Tutorial](https://substrate.dev/substrate-contracts-workshop/#/) 22 | - [ink! Documentation Portal](https://paritytech.github.io/ink-docs/) 23 | 24 | ## ink! 到 Contracts pallet 的过程 25 | 26 | parity 官方文档中提供了示例图: 27 | ![https://paritytech.github.io/ink-docs/how-it-works](https://paritytech.github.io/ink-docs/img/how-it-works.svg) 28 | 29 | 由此图可知,编写 ink!合约并部署的过程需要 30 | 31 | - ink! 依赖库:提供 ink!的 eDSL 框架以及提供相应的依赖组件 32 | - cargo-contract: 编译 ink!合约的工具 33 | - SDK:与链交互并将合约部署到链上的 SDK,parity 官方主要提供了`polkadot.js`,Patract 提供了 Himalia 工具包,包含`go`,`java`,`python`,`C#`的 SDK 34 | 35 | 本章节将主要介绍 ink!以及`cargo-contract`的信息,关于 SDK 的信息放在后续章节介绍。 36 | -------------------------------------------------------------------------------- /docs/ink/trap.md: -------------------------------------------------------------------------------- 1 | # ink! 当前的坑 2 | -------------------------------------------------------------------------------- /docs/ink/tutorial.md: -------------------------------------------------------------------------------- 1 | # ink! tutorial 2 | 3 | TODO -------------------------------------------------------------------------------- /docs/jupiter/contract.md: -------------------------------------------------------------------------------- 1 | 2 | ## 合约 3 | 4 | 当前 Jupiter PoA 测试网 和 Jupiter 部署的合约有: 5 | 6 | - 稳定币:USDT、jBTC、jETH 7 | - patramaker:DAI 8 | - patrapixel 9 | - patraswap 10 | 11 | 合约的具体实现,可以参考项目:[store-contracts](https://github.com/patractlabs/store-contracts),部署工具采用 [redspot](https://github.com/patractlabs/redspot)。 12 | 13 | ## 网络切换 14 | 15 | 当前 Jupiter PoA 和 Jupiter 分为不同的网络,一个是独立的测试网,一个是平行链版本,除此之外,其他功能和操作都一样。 16 | 17 | Jupiter PoA 的首页登录 [patrastore](https://patrastore.io/) 18 | 19 | 从 Jupiter PoA 切换网络到 Jupiter: 20 | 21 | ![parastore](./img/parastore.png) 22 | 23 | 同理,也可以从 Jupiter 要切换到 Jupiter PoA。 24 | 25 | ## 水龙头 26 | 27 | 点击《账户》-《Faucet》领取测试币 28 | 29 | ![parastore](./img/facet.png) 30 | 31 | 等待片刻,检查账户收到代币后,就可以回到首页测试已经部署好的合约。 -------------------------------------------------------------------------------- /docs/jupiter/img/facet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/jupiter/img/facet.png -------------------------------------------------------------------------------- /docs/jupiter/img/jupiter-xcmp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/jupiter/img/jupiter-xcmp-1.png -------------------------------------------------------------------------------- /docs/jupiter/img/jupiter-xcmp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/jupiter/img/jupiter-xcmp-2.png -------------------------------------------------------------------------------- /docs/jupiter/img/jupiter-xcmp-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/jupiter/img/jupiter-xcmp-3.png -------------------------------------------------------------------------------- /docs/jupiter/img/parastore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/jupiter/img/parastore.png -------------------------------------------------------------------------------- /docs/jupiter/introduction.md: -------------------------------------------------------------------------------- 1 | # Jupiter 测试网 2 | 3 | ## 介绍 4 | 5 | Jupiter 是由 Patract 维护,包含 Patract 合约设计规范并兼容最新 pallet-contracts 模块的**合约测试网**。Jupiter 有三类节点,分别是: 6 | 7 | - 适用于速测试合约功能的 `jupiter-dev` **本地节点**。 8 | - 独立运行对外提供最新合约功能的 `jupiter-prep` **独立测试网**。 9 | - 运行于中继链并提供稳定合约功能的 `jupiter` **平行链测试网**。 10 | 11 | 三个区块链网络的关键配置基本相同,例如合约计费,区块资源大小等。具体的配置详见 [Jupiter 网络](./network.md)。 12 | 13 | Jupiter 的项目地址是 [https://github.com/patractlabs/jupiter](https://github.com/patractlabs/jupiter)。 14 | 15 | 正常编译后,在编译产物目录中将会出现三个可执行性文件: `jupiter-dev`, `jupiter-prep` 和 `jupiter`。 16 | 17 | 在上面链接的仓库中,三个网络对应的节点实现分别是: 18 | 19 | - 目录 `bin/node-dev`:本地开发模式,有交易即立即触发,方便合约开发者快速测试。 20 | - 目录 `bin/node-prep`:独立链测试网模式,采用 Babe 作为出块算法,PoA 指定验证人,支持合约部署,调用。 21 | - 目录 `bin/node`:平行链测试网模式,采用 Aura 作为收集人选择算法,PoA指定验证人,支持合约部署,调用。 22 | 23 | 对应的 Runtime 实现分别是: 24 | 25 | - 目录 `runtime/jupiter-dev` 26 | - 目录 `runtime/jupiter-prep` 27 | - 目录 `runtime/jupiter` 28 | 29 | > 注:针对第三种平行链模式,由于目前中继链(比如 Westend)不支持 Sandbox HostFunction,我们自己运行了一个支持 Sandbox HostFunction 的 Westend 测试网来运行 Jupiter 平行链。后续一旦中继链支持了 Sandbox HostFunction,Jupiter 平行链会切换到官方的 Westend 上。 30 | 31 | ## ChangeLog 32 | 33 | - 1.0.0: Jupiter PoA 网络正式发布,包含jupiter-prep 及 jupiter-dev 34 | - 1.0.1: 设置 Jupiter PoA 的 ss58prefix 为 26,今后Jupiter沿用 26 作为地址的ss58prefix 35 | - 1.0.2: 支持 ZK、随机数 36 | - 1.0.3: 增加平行链,支持 XCMP 跨链转账 37 | 38 | ## Contract 39 | 40 | **Patract's FRAME contracts pallet (We will name it as pallet-patracts in future)** 41 | 42 | **当前合约使用官方的 pallet-contracts,未来我们会迁移到自己的合约模块上。** 43 | 44 | Patract 的 `FRAME contracts pallet` 通过 ChainExtension 为合约提供了一些增强的特性,并且包含一些兼容性的修改: 45 | 46 | - ChainExtension 47 | - [ ] 支持合约日志,参考连接:[ink-log](https://github.com/patractlabs/ink-log) 48 | - [x] 支持 Zero-Knowledge,参考连接:[PIP-101](https://github.com/patractlabs/PIPs/blob/main/PIPs/pip-101.md) 49 | - pallet-patracts 50 | - 目前暂时没有新特性 51 | 52 | 我们约定如下概念: 53 | 54 | - `src pallet-contract`:substrate 官方的 pallet-contract 模块 55 | - `modified pallet-contracts`:Patract 从官方 fork 出来的修改,位于 vendor 目录下 56 | 57 | 这两种 pallet_contract 对合约功能的支持: 58 | 59 | - `src pallet-contract`:支持 Patract 的 `ChainExtension` 60 | - `modified pallet-contracts`:支持 Patract 的 `ChainExtension`,以及 Patract 对 pallet-contract 的修改 61 | 62 | > 注1:Patract 集成合约模块,可以参考 [patracts](https://github.com/patractlabs/patracts) 63 | 64 | > 注2:Zero-Knowledge 的相关文档也可以参考:[zkmega](/zkmega/tutorial) 65 | 66 | -------------------------------------------------------------------------------- /docs/jupiter/quickstart.md: -------------------------------------------------------------------------------- 1 | ## 编译 2 | 3 | ```shell 4 | git clone --recurse-submodules https://github.com/patractlabs/jupiter.git 5 | cd jupiter 6 | cargo build --release 7 | ``` 8 | 9 | 由于目前 jupiter 中有三种模式,所以不同模式对应了不同的二进制执行文件,上面在编译完成后,在 target/release 下会生成三种二进制文件: 10 | 11 | - target/release/jupiter-dev 12 | - target/release/jupiter-prep 13 | - target/release/jupiter 14 | 15 | ## 运行 16 | 17 | ### jupiter-dev 18 | 19 | 运行本地模式: 20 | 21 | ``` 22 | ./jupiter-prep --dev --execution=NativeElseWasm --tmp 23 | ``` 24 | 25 | ### jupiter-prep 26 | 27 | jupiter-prep 也支持先在本地进行测试: 28 | 29 | ``` 30 | # start first node 31 | ./jupiter-prep --chain=jupiter-poa-local --alice --execution=NativeElseWasm --tmp 32 | 33 | # start second node 34 | ./jupiter-prep --chain=jupiter-poa-local --bob --execution=NativeElseWasm --tmp 35 | ``` 36 | 37 | 外部节点也可以作为同步节点加入到 Jupiter PoA 独立测试网: 38 | 39 | ``` 40 | ./jupiter-prep --chain=jupiter-poa --pruning=archive --execution=NativeElseWasm 41 | ``` 42 | 43 | ### jupiter 44 | 45 | 当前 jupiter 平行链仅支持作为同步节点加入到 Jupiter 测试网: 46 | 47 | ``` 48 | ./jupiter --chain ./jupiter-westend-098.json --execution wasm --wasm-execution=compiled --force-authoring --parachain-id=2000 --tmp \ 49 | --chain ./westend-098.json --no-beefy --execution wasm --wasm-execution=compiled --tmp \ 50 | --bootnodes /dns/ws.patract-westend.patract.cn/tcp/30333/p2p/12D3KooWHfn9r5cLyVQRuLin1wsB3KUiVaMWPnnpFd7Hhff6rhUX 51 | ``` 52 | 53 | > 注:如果需要在本地进行测试,可以修改 [jupiter-dev](https://github.com/patractlabs/jupiter/blob/master/bin/node/cli/src/command.rs#L28-L31),并参考这里的[运行步骤](https://github.com/patractlabs/jupiter/blob/master/README.md#421-start-local-test-mode-jupiter-parachain) 54 | 55 | -------------------------------------------------------------------------------- /docs/jupiter/xcmp.md: -------------------------------------------------------------------------------- 1 | # 跨链转账 2 | 3 | 跨链转账功能仅限于 Patract 的私有 Westend 中继链 和 Jupiter 平行链之间,当前的跨链转账包括: 4 | 5 | - 中继链 Westend 转账 WND(中继链的原生代币)给平行链 Jupiter 6 | - 平行链 Jupiter 转账 WND(中继链的原生代币)给中继链 Westend 7 | 8 | 跨链转账有两种模块:teleport、reserver transfer,当前建议使用的是 reserve transfer。 9 | 10 | ## 中继链转账到平行链 11 | 12 | 在 Patract 的私有中继链 Westend 上,选择“交易”、“xcmPallet”模块,按照下图转账到平行链: 13 | 14 | ![relay-to-para](img/jupiter-xcmp-1.png) 15 | 16 | > 注意:当前 Patract 的私有中继链 Westend 暂时还没有水龙头,后续会添加此功能。 17 | 18 | 等待交易被打包后,检查中继链的转账发起方账户余额减少,同时平行链的转账接收方账户余额增加了。上面的示例中中继链转账了 1000 WND 给平行链, 19 | 对应的平行链中增加了约 1000 WND。 20 | 21 | ![para-amount](img/jupiter-xcmp-2.png) 22 | 23 | ## 平行链转账到中继链 24 | 25 | 平行链转账到中继链的实现,当前使用了 [orml_xtokens](https://github.com/open-web3-stack/open-runtime-module-library) 组件。 26 | 27 | 在 Jupiter 平行链上,选择“交易”、“xTokens”,按照下图转账到中继链: 28 | 29 | ![relay-to-para](img/jupiter-xcmp-3.png) 30 | 31 | 等待交易被打包后,检查平行链的转账发起方账户余额减少,同时中继链的转账接收方账户余额增加了。 -------------------------------------------------------------------------------- /docs/metis/guides/extensions.md: -------------------------------------------------------------------------------- 1 | # Extending Metis 2 | Such components can extend their functions by inheriting other components, such as an ERC20 component with the function of destroying tokens: 3 | 4 | ```rust 5 | pub trait Impl: erc20::Impl 6 | where 7 | E: Env, 8 | { 9 | fn _burn(&mut self, account: &E::AccountId, amount: E::Balance) -> Result<()> { 10 | //... 11 | } 12 | 13 | fn burn(&mut self, amount: E::Balance) -> Result<()> { 14 | self._burn(&Self::caller(), amount) 15 | } 16 | 17 | fn burn_from(&mut self, account: &E::AccountId, amount: E::Balance) -> Result<()> { 18 | //... 19 | } 20 | } 21 | ``` 22 | 23 | Based on metis, we can implement various contract combination modes implemented by Solidity through inheritance under limited intent, and at the same time, with the help of rust's zero-cost abstraction, these abstractions will not bring additional performance consumption. -------------------------------------------------------------------------------- /docs/metis/guides/hook.md: -------------------------------------------------------------------------------- 1 | # Hooks 2 | 3 | ## Why using hook 4 | Sometimes, in order to extend a parent contract you will need to override multiple related functions, which leads to code duplication and errors 5 | 6 | For example, consider implementing safe ERC20 transfers in the style of IERC721Receiver. You may think overriding transfer and transferFrom would be enough, but what about _transfer and _mint? To prevent you from having to deal with these details, Metis uses Function Hooks. 7 | 8 | Hooks are simply functions that are called before or after some action takes place. They provide a centralized point to hook into and extend the original behavior. 9 | 10 | In some component, the hook has a default implementation: 11 | 12 | ```rust 13 | /// @dev Hook that is called before any token transfer. This includes 14 | /// calls to {send}, {transfer}, {operatorSend}, minting and burning. 15 | /// 16 | /// Calling conditions: 17 | /// 18 | /// - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 19 | /// will be to transferred to `to`. 20 | /// - when `from` is zero, `amount` tokens will be minted for `to`. 21 | /// - when `to` is zero, `amount` of ``from``'s tokens will be burned. 22 | /// - `from` and `to` are never both zero. 23 | /// 24 | /// To learn more about hooks, 25 | /// head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 26 | fn _before_token_transfer( 27 | &mut self, 28 | _operator: &E::AccountId, 29 | _from: &Option<&E::AccountId>, 30 | _to: &Option<&E::AccountId>, 31 | _amount: &E::Balance, 32 | ) -> Result<()> { 33 | Ok(()) 34 | } 35 | ``` 36 | 37 | The hook will call by component functions, user can define it, a normal example is Pausable ERC20 component: 38 | 39 | ```rust 40 | fn before_token_transfer( 41 | &mut self, 42 | _from: &E::AccountId, 43 | _to: &E::AccountId, 44 | _amount: E::Balance, 45 | ) -> Result<()> { 46 | metis_pausable::Impl::::ensure_not_paused(self); 47 | 48 | Ok(()) 49 | } 50 | ``` 51 | 52 | The Pausable ERC20 component is extend the erc20 component, which implements the hook. You can find this hooks get called here: 53 | 54 | ```rust 55 | fn _transfer_from_to( 56 | &mut self, 57 | sender: E::AccountId, 58 | recipient: E::AccountId, 59 | amount: E::Balance, 60 | ) -> Result<()> { 61 | let null_account = E::AccountId::default(); 62 | 63 | if sender == null_account || recipient == null_account { 64 | return Err(Error::AccountIsZero) 65 | } 66 | 67 | self._before_token_transfer(&sender, &recipient, &amount)?; 68 | xxxxx 69 | } 70 | ``` -------------------------------------------------------------------------------- /docs/metis/guides/imports.md: -------------------------------------------------------------------------------- 1 | # Use Metis components 2 | 3 | !> Warnning: We can redefine the name of metis component, but we should keep in mind that all component names should be changed after import. 4 | 5 | **Note** this: 6 | 7 | ```rust 8 | use metis_component_xxx1 as xxx1; 9 | ``` 10 | 11 | if we use the `xxx1` be the alias of the `metis_component_xxx1`, so the all tag of components should be `xxx1`: 12 | 13 | - The `import` marco for contract 14 | - The name of item in contract struct type 15 | - The `metis` marco for event 16 | 17 | For example: 18 | 19 | ```rust 20 | pub mod contract { 21 | // use the component: xxx1 and xxx2 22 | use metis_component_xxx1 as xxx1; 23 | 24 | ... 25 | 26 | #[ink(storage)] 27 | #[import(xxx1)] // The `import` marco for contract, should be xxx1 28 | pub struct Contract { 29 | // The name of item in contract struct type, should be xxx1 30 | xxx1: xxx1::Data, 31 | } 32 | 33 | ... 34 | 35 | #[ink(event)] 36 | #[metis(xxx1)] // The `metis` marco for event 37 | pub struct OwnershipTransferred { 38 | } 39 | 40 | ... 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /docs/metis/guides/macros.md: -------------------------------------------------------------------------------- 1 | # Marcos 2 | The Metis have implemented the following marcos for components development: 3 | 4 | - `contract` : to define the contract following metis contract standard. 5 | - `import` : to generate code to implement the components. 6 | - `metis` : to define the metis component. 7 | - `stub` : to implement stub in metis. 8 | - `reentrancy_guard` : helper macro for the reentrancy_guard component. 9 | - `supports` : helper macro for the ERC165 supports api. 10 | - `hash` : to calculate the hash of a string during compilation. 11 | - `selector_id` : to calculate the selector_id of a message. -------------------------------------------------------------------------------- /docs/metis/guides/security/reentrancy-guard.md: -------------------------------------------------------------------------------- 1 | # Reentrancy Guard 2 | 3 | Contract component that helps prevent reentrant calls to a function. 4 | 5 | ## Dependency 6 | ```rust 7 | metis_reentrancy_guard = { git = "https://github.com/patractlabs/metis", default-features = false } 8 | ``` 9 | 10 | ## Storage 11 | 12 | In most cases, developer not need to consider the storage of reentrancy guard. 13 | 14 | ```rust 15 | const _NOT_ENTERED: u8 = 1; 16 | const _ENTERED: u8 = 2; 17 | 18 | /// The Data of pausable component 19 | #[cfg_attr(feature = "std", derive(::ink_storage::traits::StorageLayout))] 20 | #[derive(Debug)] 21 | pub struct Data { 22 | /// is contract current paused 23 | status: Lazy, 24 | 25 | key: ink_primitives::Key, 26 | } 27 | ``` 28 | 29 | Note the `key` in module, in `ink!`, all storage will flush to storage after the end of message proccess, 30 | so if contract only modifies `status`, the reentrancy_guard will not work: 31 | 32 | ```rust 33 | /// set current status to entered 34 | pub fn set_entered(&mut self) { 35 | Lazy::set(&mut self.status, _ENTERED); 36 | self.flush() // flush to storage 37 | } 38 | 39 | /// set current status to not entered 40 | pub fn set_not_entered(&mut self) { 41 | Lazy::set(&mut self.status, _NOT_ENTERED); 42 | self.flush() // flush to storage 43 | } 44 | ``` 45 | 46 | ## Internal Function 47 | 48 | There is some internal function for reentrancy_guard, the marco will check it automatically: 49 | 50 | ```rust 51 | #[ink(message)] 52 | #[metis_lang::reentrancy_guard] 53 | pub fn function_can_not_reentrancy(&mut self) { 54 | self._check_nonreentrant(); 55 | self._set_entered(); 56 | 57 | // logics 58 | 59 | self._set_not_entered(); 60 | } 61 | ``` 62 | 63 | the functions: 64 | 65 | - `_check_nonreentrant` : check if the current status is `_NOT_ENTERED` 66 | ```rust 67 | fn _check_nonreentrant(&self) { 68 | assert!(!self.get().is_entered(), "ReentrancyGuard: reentrant call"); 69 | } 70 | ``` 71 | - `_set_entered` : set current status to `_ENTERED` 72 | ```rust 73 | fn _set_entered(&mut self) { 74 | self.get_mut().set_entered(); 75 | } 76 | ``` 77 | - `_set_not_entered` : set current status to `_NOT_ENTERED` 78 | ```rust 79 | fn _set_not_entered(&mut self) { 80 | self.get_mut().set_not_entered(); 81 | } 82 | ``` 83 | ## Usage Example 84 | 85 | To use `reentrant_guard` component, first is import the component: 86 | 87 | ```rust 88 | use metis_lang::{ 89 | import, 90 | metis, 91 | }; 92 | 93 | use metis_reentrancy_guard as reentrancy_guard; 94 | 95 | #[ink(storage)] 96 | #[import(reentrancy_guard)] 97 | pub struct Contracts { 98 | reentrancy_guard: reentrancy_guard::Data, 99 | 100 | // others 101 | } 102 | ``` 103 | 104 | To use reentrancy guard, we can use a marco to check, it like the modifier in solidity: 105 | 106 | ```rust 107 | #[ink(message)] 108 | #[metis_lang::reentrancy_guard] 109 | pub fn function_can_not_reentrancy(&mut self) { 110 | // logics 111 | } 112 | ``` -------------------------------------------------------------------------------- /docs/metis/intro/motivation.md: -------------------------------------------------------------------------------- 1 | # Motivation 2 | 3 | ## Current Problems with ink! development 4 | At present, contract-based developers mainly face the following problems: 5 | 6 | - Lack of reliable implementation of common contracts (such as ERC20) 7 | - It is difficult to achieve contract combination and expansion similar to the Solidity inheritance mechanism 8 | - Lack of a series of reliable public components to implement contracts 9 | - Lack of experience accumulation and model summary based on ink! development contracts 10 | 11 | The problems listed above have severely restricted the ink!-based contract development. Metis will solve these problems while avoiding the existing problems in Solidityd and OpenZepplin. 12 | 13 | 14 | ## Design philosophies 15 | 16 | We believe that in the Wasm contract ecosystem, a development library similar to Openzeppelin-contracts is very necessary. This is Metis. For the sake of simplicity and readability, the patterns and meta-language provided by this library should be as consistent with Openzeppelin-contracts as possible, so as to reduce the burden on developers and effectively absorb the experience accumulated in the Solidity ecosystem. 17 | 18 | But Wasm contract development based on ink! is very different from the EVM contract development based on Solidity. Wasm's mature system support allows developers to use a variety of different languages and tools to develop smart contracts. Based on these mature or rapid iteration platforms, developers can enjoy a large number of underlying facilities support and development experience accumulation, but different languages and tools often have different considerations and trade-offs. This means that developers will use completely different codes to express the same mechanism and design, which will bring huge communication costs and mental burdens to the community. 19 | 20 | Faced with such problems, we need to summarize and accumulate the implementation model in the development of smart contracts. This idea was introduced in the book "Implementation Patterns" by Kent Beck. The purpose of summarizing the implementation mode is to clearly and accurately express the developer's intentions and ideas through these clear patterns, so that "code that others can understand" can be implemented. In contract development, this idea is very important. 21 | 22 | From Openzeppelin-contracts, we can see that it summarizes several implementation models in the development of smart contracts, such as the "contract expansion model" based on the Solidity inheritance grammar. These implementation models are valuable experience accumulated in the Solidity ecology. Of course, different languages have different ways of practicing these modes. Metis will implement these modes and provide corresponding support on different platforms. For example, in Rust, it is obvious that you cannot directly use inheritance to implement contract expansion. For this, Metis will provide code implementation examples and provide a series of help libraries to reduce the developer's mental cost. 23 | 24 | Metis will be more than just a Wasm contract standard library. We hope that through the practice of Metis, we can fully inherit and absorb previous contract development experience while exploring the best practices of Wasm contract development. 25 | -------------------------------------------------------------------------------- /docs/metis/reports/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Metis proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Metis proposal report has the following content: 8 | 9 | - [M1Report](./M1Report.md) 10 | -------------------------------------------------------------------------------- /docs/pallet-contracts/introduction.md: -------------------------------------------------------------------------------- 1 | # pallet-contracts 合约模块 2 | 3 | `pallet-contracts`合约模块, 一般称呼为[“Contracts Pallet”](https://substrate.dev/docs/en/knowledgebase/smart-contracts/contracts-pallet) 或者 “FRAME Contracts pallet”,又或者称呼为“Substrate Smart Contracts”,是parity官方研发的Wasm合约模块。 4 | 5 | 依据Substrate knowledgebase的介绍,Contracts Pallet具备如下特性: 6 | * Are inherently safer to the network. 7 | * Have built in economic incentives against abuse. 8 | * Have computational overhead to support graceful failures in logic. 9 | * Have a lower bar to entry for development. 10 | * Enable fast pace community interaction through a playground to write new logic. -------------------------------------------------------------------------------- /docs/patract/imgs/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/patract/imgs/overview.jpg -------------------------------------------------------------------------------- /docs/patract/introduction.md: -------------------------------------------------------------------------------- 1 | # Patract 2 | 3 | ![overview](./imgs/overview.jpg) 4 | 5 | Patract 做的东西具体包括: 6 | 7 | * 在开发者端: 8 | 9 | * Jupiter:独立的智能合约测试网,提供给合约开发者测试合约链的环境。 10 | * Ask!:AssemblyScript 版的 Ink! 合约框架,吸引 TS/JS 的开发者,给不愿意使用 rust 的合约开发者另一个选择。 11 | * Redspot:Wasm 合约开发工作流和脚手架:对标 Ethereum 生态中的 Tuffle/Redhat,让合约开发项目化,自动化的工具。Redspot 采用插件化设计,运行开发者添加自己设计的插件丰富 Redspot 的功能。 12 | * Europa:Runtime 和合约运行沙盒:对标 Ethereum 生态中的 EthereumJS/Ganache,给合约开发者提供了丰富的调试信息,便于快速开发合约。 13 | * Elara:实时和可扩展的波卡 API:对标 Ethereum 中的 Infura,给合约项目方提供节点的 Endpoint,不用自行搭建节点获取数据。 14 | * Megaclite:零知识证明的底层支持:在 Jupiter/Patract 链中提供零知识原语支持,可以允许项目方设计 zkRollup 或其他零知识相关合约。 15 | * Metis:Ink! 合约标准库:对标 Ethereum 中的 openzeppelin-contracts,给合约开发者提供可复用的轮子,不必从零开始编写合约代码。 16 | * Himalia:多语言合约 SDK:对标 Ethereum 中的 Web3J,Web3Py 等 SDK,给合约项目方提供不同语言的环境,丰富的接口与合约进行交互。 17 | -------------------------------------------------------------------------------- /docs/redspot/advanced/multi-contract-compilation.md: -------------------------------------------------------------------------------- 1 | # Cross compile multiple contracts 2 | Redspot also support development of multiple wasm smart contracts that calls the function of another contract -------------------------------------------------------------------------------- /docs/redspot/advanced/write-plugins.md: -------------------------------------------------------------------------------- 1 | # Write new plugins 2 | 3 | You can also write your own ad hoc plugins. We will include a tutorial on how to write your own plugin in the future. -------------------------------------------------------------------------------- /docs/redspot/guides/docker.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | In Redspot v0.4, we added support for using docker to compile contracts. This will ensure that the compiled wasm code being consistent across different platforms. 3 | 4 | Currently, will use [redspot/contract](https://github.com/patractlabs/docker-images/tree/master/contract) docker to compile and run the testnet. It is modified on the basis of [contract docker image](https://github.com/paritytech/scripts/blob/master/dockerfiles/contracts-ci-linux/Dockerfile) provided by Parity Tech. 5 | 6 | ### TestNet 7 | 8 | If the machine has a Docker environment. A testnet can be run by Docker. The canvas testnet is currently built-in. 9 | 10 | You can run the testnet with the following command. 11 | 12 | ```bash 13 | $ npx redspot testnet 14 | ``` 15 | This equivelent of running 16 | ```bash 17 | $ docker run -p 9944:9944 --rm redspot/contract /bin/bash -c "canvas --tmp --dev --ws-port=9944 --ws-external" 18 | ``` 19 | 20 | To modify the default running command, add the `command ` parameter. 21 | 22 | ```bash 23 | $ npx redspot testnet --command 'docker run -p 9945:9944 --rm redspot/contract /bin/bash -c "canvas --tmp --dev --ws-port=9944 --ws-external"' 24 | ``` 25 | 26 | Or modify the redspot.config file. 27 | 28 | ```typescript 29 | docker: { 30 | sudo: false, 31 | runTestnet: 32 | "docker run -p 9944:9944 --rm redspot/contract /bin/bash -c 'canvas --rpc-cors all --tmp --dev --ws-port=9944 --ws-external'", 33 | } 34 | ``` 35 | 36 | ### Compile on docker 37 | Currently Redspot only supports ink! contract docker compilation, to configure the docker env, modify the docker entry in `redspot.config.ts` 38 | 39 | ```typescript 40 | docker: { 41 | sudo: false, 42 | runTestnet: 43 | "docker run -p 9944:9944 --rm redspot/contract /bin/bash -c 'canvas --rpc-cors all --tmp --dev --ws-port=9944 --ws-external'", 44 | } 45 | ``` 46 | Before running the compile command, make sure that Docker is installed on the machine. Run the following command. 47 | 48 | ```bash 49 | $ npx redspot compile --docker true 50 | ``` 51 | 52 | **Note** When using Docker to compile, it may be affected by the network environment. For example, China requires a VPN proxy, which will cause the compilation time to be too long. If you use`ctrl+c`to exit the current compilation command halfway, the Docker container will not automatically stop deleting. 53 | 54 | **Note** If you encounter permission errors, please set `docker.sudo ` in the redspot.config file to true. This will use sudo to run Docker . Or refer to [the official Docker documentation](https://docs.docker.com/engine/install/linux-postinstall/) to configure permissions. -------------------------------------------------------------------------------- /docs/redspot/imgs/engprocess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/imgs/engprocess.jpg -------------------------------------------------------------------------------- /docs/redspot/imgs/explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/imgs/explorer.png -------------------------------------------------------------------------------- /docs/redspot/imgs/process.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/imgs/process.jpg -------------------------------------------------------------------------------- /docs/redspot/intro/installation.md: -------------------------------------------------------------------------------- 1 | # Setup Enviroment 2 | ## Prerequisites 3 | Please follow the guide on [ink!](https://substrate.dev/substrate-contracts-workshop/#/0/setup) to setup **rust**, **cargo** and **cargo-contracts** 4 | 5 | Please follow the guide on [Nodejs](https://nodejs.org/) to install node and npm 6 | 7 | Install NPX 8 | ``` 9 | sudo npm install -g npx 10 | ``` 11 | ## Setup Local Test Node 12 | You will need blockchain node based on substrate with Contracts pallet module to deploy the contracts and test them. 13 | 14 | ***What is substrate*** 15 | 16 | Substrate is the blockchain framework to help developers craft their own blockchain faster, easier and safer. 17 | 18 | ***What is pallet-contracts*** 19 | 20 | The FRAME Contracts pallet is a module within substrate that provides functionality for a Substrate runtime to deploy and execute WebAssembly Smart Contracts. 21 | 22 | 23 | * [**Canvas**](https://github.com/paritytech/canvas-node) (test node by substrate) 24 | ``` 25 | cargo install canvas-node --git https://github.com/paritytech/canvas-node.git --tag v0.1.9 --force --locked 26 | ``` 27 | Start **Canvas** 28 | ``` 29 | canvas --dev --tmp 30 | ``` 31 | * [**Europa**](../../europa/intro/overview.md) (Patract modification) 32 | ``` 33 | cargo install europa --git=https://github.com/patractlabs/europa.git --force --locked 34 | ``` 35 | Start **Europa** 36 | ``` 37 | europa --tmp 38 | ``` 39 | 40 | ## Install Redspot 41 | Redspot supports `npx`, so you don't have to install Redspot locally. 42 | To start your first Redspot project using Redspot built-in templates, check [Quick Start](./quick-start) 43 | -------------------------------------------------------------------------------- /docs/redspot/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Overview​ 2 | Redspot is a development environment to compile, deploy, and debug wasm smart contract for substrate based chains. Redspot helps developers manage and automate the repeating steps during the process of writing smart contracts and dApps.Redspot is a development environment to compile, deploy, and debug wasm smart contract for substrate based chains. Similar to the architectures of Hardhat, Redspot is built upon Tasks and Plugins. 3 | 4 | ## Multi Languages Support 5 | Redspot currently supports compilation of Ink! and will support Ask! in the future. 6 | 7 | ## Tasks 8 | 9 | Every time you run Redspot from the terminal, you are running tasks. For example, executing the `npx redspot compile` command is to run the compilation task. To view the tasks currently available in the project, run the `npx redspot` command. You can view the help information of any task by running `npx redspot help [task]`. 10 | 11 | ## Plugins 12 | 13 | Redspot installs some plug-ins by default. As a developer, you're flexible to install any plugins, write new plugins and override existing plugins. 14 | 15 | ## More information 16 | Redspot developed from a hardhat fork based on the MIT protocol, and removed parts related to Ethereum on its basis, and added functions related to Substrate and pallet-contracts modules. In the near future, Redspot will build more functions based on the core of hardhat. -------------------------------------------------------------------------------- /docs/redspot/plugin/image/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/1.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/10.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/111.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/111.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/12.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/13.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/14.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/15.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/16.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/2.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/3.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/8.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/91.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/91.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/9png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/9png.png -------------------------------------------------------------------------------- /docs/redspot/plugin/image/gas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/docs/redspot/plugin/image/gas.png -------------------------------------------------------------------------------- /docs/redspot/plugin/plugin.md: -------------------------------------------------------------------------------- 1 | # Plug-in 2 | 3 | ## What 4 | 5 | The core functions of Redspot include Redspot runtime environment, compiling contracts, running tests and running scripts. Other functions, such as the test suite with the contract, contract interaction, access to the contract, and configuration of different chains, are all provided by the plug-in, and you can choose the plug-ins according to your needs. 6 | 7 | ## Installation 8 | The way to introduce a plug-in is very simple, add it as a dependency of npm in `package.json`, and then add it in `redspot.config.ts`. The example is as follows. 9 | 10 | ```typescript 11 | import { RedspotUserConfig } from 'redspot/types'; 12 | import '@redspot/patract'; // introduce the @redspot/patract plugin 13 | import '@redspot/chai'; // import @redspot/chai plugin 14 | export default { 15 | ... 16 | } as RedspotUserConfig; 17 | ``` 18 | You can also manually install it, for example 19 | 20 | ```bash 21 | $ yarn add @redspot/chai 22 | ``` 23 | 24 | Add this to your `redspot.config.ts`: 25 | ```typescript 26 | import '@redspot/chai' 27 | ``` 28 | 29 | The following plug-ins are now included. 30 | 31 | * [@redspot/chai](./redspot-chai) 32 | * [@redspot/decimals](./redspot-decimals) 33 | * [@redspot/explorer](./redspot-explorer) 34 | * [@redspot/gas-reporter](./redspot-gas-reporter) 35 | * [@redspot/known-types](./redspot-known-types) 36 | * [@redspot/patract](./redspot-patract) 37 | 38 | -------------------------------------------------------------------------------- /docs/redspot/plugin/redspot-chai.md: -------------------------------------------------------------------------------- 1 | # @redspot_chai plug-in 2 | 3 | ## What 4 | 5 | The plug-in provides a set of matchers that are easy to write contract test cases, and the design is inspired by [waffle](https://ethereum-waffle.readthedocs.io/en/latest/matchers.html). 6 | 7 | ## Installation 8 | ```bash 9 | $ yarn add @redspot/chai 10 | ``` 11 | Add this to your `redspot.config.ts`: 12 | ```typescript 13 | import '@redspot/chai' 14 | ``` 15 | ## Usages: 16 | 17 | ### `equal` 18 | 19 | The @redspot/chai plug-in will modify the default equal matching method. The default equal does not support matching objects,but @redspot/chai plugin can. 20 | 21 | ```typescript 22 | expect(new BN(1000)).to.equal(1000); // true 23 | expect(AccountId).to.equal('5Gdjkw....'); // true 24 | expect(Uint8Array([1, 2, 3])).to.equal('0x010203'); // true 25 | ``` 26 | 27 | * For the BN type, equal will call `new BN(expected).eq(actual)` and judge whether it is equal. 28 | * For the types defined in Polkadot.js, equal will call `Type.eq(actual)` and judge whether they are equal. 29 | * For uint8Array type, equal will convert them to hexadecimal, and then judge whether they are equal. 30 | * For other types, the default judgment method is used to judge whether they are equal. 31 | 32 | ### `changeTokenBalance` 33 | 34 | The matcher can detect changes in the balance of erc20, and internally calls the balanceOf interface to determine the balance. Since the interface for obtaining balance of erc20-trait is `baseErc20, balanceOf`,`changeTokenBalance` is not applicable to erc20-trait. 35 | 36 | ```typescript 37 | await expect(() => 38 | contract.tx.transfer(receiver.address, 7) 39 | ).to.changeTokenBalance(contract, receiver, 7); 40 | await expect(() => 41 | contract.tx.transfer(receiver.address, 7) 42 | ).to.changeTokenBalances(contract, [contract.signer, receiver], [-7, 7]); 43 | ``` 44 | 45 | ### `emit` 46 | 47 | The matcher can detect whether the contract emits an event. Here is an example: 48 | 49 | * Detect whether a Transfer event is emitted 50 | ```typescript 51 | await expect(contract.tx.transfer(receiver.address, 7)).to.emit( 52 | contract, 53 | 'Transfer' 54 | ); 55 | ``` 56 | 57 | * Detect whether the event contains the specified parameters 58 | ```typescript 59 | await expect(contract.tx.transfer(receiver.address, 7)) 60 | .to.emit(contract, 'Transfer') 61 | .withArgs(sender.address, receiver.address, 7); 62 | ``` 63 | 64 | * Don't expect to emit events 65 | ```typescript 66 | await expect( 67 | contract.tx.transfer(sender.address, 7, { 68 | signer: emptyAccount 69 | }) 70 | ).to.not.emit(contract, 'Transfer'); 71 | ``` 72 | 73 | -------------------------------------------------------------------------------- /docs/redspot/plugin/redspot-decimals.md: -------------------------------------------------------------------------------- 1 | # @redspot_decimals plug-in 2 | 3 | ## What 4 | 5 | @redspot/decimals is a plug-in that can automatically convert number precision, for example, it can convert 1 DOT to 10000000000. 6 | 7 | Fixed decimal 8 | 9 | * `1 DOT`=>`10 ** 10` 10 | * `1 KSM`=>`10 ** 12` 11 | 12 | Obtain the tokenDecimal of the chain automatically 13 | 14 | * `1 UNIT`=>`10 ** tokenDecimal` 15 | 16 | ## Installation 17 | ```bash 18 | $ yarn add @redspot/decimals 19 | ``` 20 | Add this to your `redspot.config.ts`: 21 | ```typescript 22 | import '@redspot/decimals' 23 | ``` 24 | 25 | ## Usages 26 | 27 | * Used when deploying contracts 28 | ```typescript 29 | const contract = await contractFactory.deployed('new', '10000', { 30 | gasLimit: '400000000000', 31 | value: '10000 UNIT' 32 | }); 33 | ``` 34 | 35 | * Use in transfer 36 | ```typescript 37 | import { network } from 'redspot'; 38 | const { api } = network; 39 | async function run() { 40 | await api.isReady; 41 | api.tx.balances.transfer(address, '1 UNIT') 42 | } 43 | ``` 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /docs/redspot/plugin/redspot-explorer.md: -------------------------------------------------------------------------------- 1 | # @redspot_explorer plug-in 2 | 3 | ## What 4 | 5 | The purpose of this plugin is to replace polkadot apps and canvas-ui during contract development. 6 | 7 | ## Installation 8 | 9 | ``` 10 | $ yarn add @redspot/explorer 11 | ``` 12 | Add this to your `redspot.config.ts`: 13 | ```typescript 14 | import "@redspot/explorer" 15 | ``` 16 | 17 | ## Usage 18 | Run edspot explorer. 19 | ```bash 20 | npx redspot explorer 21 | ``` 22 | 23 | **Note** When running redspot explorer, a service will be started locally, please do not terminate the process. And, every time redspot.config changes, please restart the service manually. 24 | 25 | Open the [default website](http://127.0.0.1:8011) 26 | 27 | For detailed usages, please refer [Redspot Explorer](../guides/explorer.md) -------------------------------------------------------------------------------- /docs/redspot/plugin/redspot-gas-reporter.md: -------------------------------------------------------------------------------- 1 | # @redspot_gas-reporter plug-in 2 | 3 | ## What 4 | 5 | The plug-in will print out the gas usage of the transaction of the called contract when the test is completed. 6 | 7 | ![](./image/gas.png) 8 | 9 | ## Installation 10 | ``` 11 | $ yarn add @redspot/gas-reporter 12 | ``` 13 | Add this to your `redspot.config.ts`: 14 | ```typescript 15 | import '@redspot/gas-reporter' 16 | ``` 17 | 18 | ## Usages 19 | 20 | Once you have imported this plugin in `redspot.config.ts`, it will automatically print out gas usage of the transaction of the called contract when the test is completed 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /docs/redspot/plugin/redspot-known-types.md: -------------------------------------------------------------------------------- 1 | # @redspot_known-types plug-in 2 | 3 | ## What 4 | 5 | Redspot known types is a plug-in that can automatically add known types of chains. In polkadot, adding types is very troublesome, must be added manually, and cannot be automatically generated, and sometimes also has to deal with the compatibility of different chain versions. The appearance of the redspot known types plugin is to solve the problem of different types of chains. 6 | 7 | Most chains have submitted types on polkadot apps, and all types definitions are in the npm package `@polkadot/apps-config`. We will partially quote the types definitions in `@polkadot/apps-config`. But`@polkadot/apps-config` lacks the type definition of the development environment, we will manually supplement this part. Currently supported chains are Canvas, Jupiter, Europa, Edgeware, Plasm and Clover. 8 | 9 | ## Installation 10 | ``` 11 | $ yarn add @redspot/known-types 12 | ``` 13 | Add this to your `redspot.config.ts`: 14 | ```typescript 15 | import "@redspot/known-types" 16 | ``` 17 | 18 | ## Usages 19 | Try to connect to the network of Canvas, Jupiter, Europa and other chains without adding additional type configuration, `@redspot/known-types` will configure them automatically 20 | 21 | -------------------------------------------------------------------------------- /docs/redspot/reports/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Redspot proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Redspot proposal report has the following content: 8 | 9 | - [v0.1Report](./v0.1Report.md) 10 | - [v0.2Report](./v0.2Report.md) 11 | - [v0.3Report](./v0.3Report.md) 12 | - [v0.4Report](./v0.4Report.md) 13 | -------------------------------------------------------------------------------- /docs/solang/introduction.md: -------------------------------------------------------------------------------- 1 | # Solang 2 | -------------------------------------------------------------------------------- /docs/zkmega/contract.md: -------------------------------------------------------------------------------- 1 | # Contract 2 | 3 | > Currently we (Patract) support zkMega in testnet Jupiter ([https://github.com/patractlabs/jupiter](https://github.com/patractlabs/jupiter)) and contract debug 4 | > sandbox Europa ([https://github.com/patractlabs/europa](https://github.com/patractlabs/europa)). And any substrate based chain which uses `pallet-contracts` v3.0.0 could integrate zkMega. 5 | > 6 | > if the `pallet-contracts` Wasm contract chain use zkMega, then the following contract could run normally in those chain. 7 | 8 | ## Example 9 | 10 | TODO this example is wrong for current version! 11 | 12 | ```rust,ignore 13 | #![cfg_attr(not(feature = "std"), no_std)] 14 | 15 | #[ink::contract] 16 | mod altbn128 { 17 | use ink_env::zk_snarks::AltBn128; 18 | use ink_prelude::string::String; 19 | 20 | #[ink(storage)] 21 | pub struct Altbn128 { 22 | value: String, 23 | } 24 | 25 | impl Altbn128 { 26 | #[ink(constructor)] 27 | pub fn new(init_value: String) -> Self { 28 | Self { value: init_value } 29 | } 30 | 31 | #[ink(constructor)] 32 | pub fn default() -> Self { 33 | Self::new("hello, world".into()) 34 | } 35 | 36 | #[ink(message)] 37 | pub fn bn_256_add(&mut self) { 38 | let mut result = [0; 64]; 39 | ink_env::inflect_add::(&[], &[], &mut result); 40 | self.value = ink_prelude::format!("0x{:x?}", result); 41 | } 42 | 43 | #[ink(message)] 44 | pub fn get(&self) -> String { 45 | ink_prelude::format!("{}", &self.value) 46 | } 47 | } 48 | } 49 | ``` 50 | 51 | [paritytech/substrate]: https://github.com/paritytech/substrate.git 52 | [patractlabs/jupiter]: https://github.com/paritytech/jupiter.git 53 | -------------------------------------------------------------------------------- /docs/zkmega/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | ## Call curves in ink! 4 | 5 | | curve | add | mul | pairing | 6 | |------------|------------|------------|------------| 7 | | bls12\_377 | 0x01000000 | 0x01000001 | 0x01000002 | 8 | | bls12\_381 | 0x01000010 | 0x01000011 | 0x01000012 | 9 | | bn254 | 0x01000020 | 0x01000021 | 0x01000022 | 10 | | bw6\_761 | 0x01000030 | 0x01000031 | 0x01000032 | 11 | 12 | ```rust 13 | let result = ink_env::call_chain_extension(func_id, &Vec::from(input))? 14 | ``` 15 | 16 | 17 | ## MIMC 18 | 19 | ```rust 20 | use zkp_u256::{U256, Zero}; 21 | use merkle_tree::mimc::{mimc,mimc_with_key} 22 | let message = U256::from_decimal_str("49").unwrap(); 23 | let in_key = U256::zero(); 24 | assert_eq!( 25 | mimc(b"1"), 26 | mimc_with_key(vec![&message], &in_key) 27 | ); 28 | ``` 29 | 30 | 31 | ## Merkle Tree 32 | 33 | ```rust 34 | use merkle_tree::MerkleTree; 35 | let mut mt = MerkleTree::default(); 36 | let message = b"49"; 37 | let (leaf, index) = mt.insert(message).unwrap(); 38 | assert_eq!(mt.update(), mt.get_root()); 39 | let merkle_proof = mt.get_proof(index); 40 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 41 | 42 | let message = b"50"; 43 | let (leaf, index) = mt.insert(message).unwrap(); 44 | assert_eq!(mt.update(), mt.get_root()); 45 | let merkle_proof = mt.get_proof(index); 46 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 47 | 48 | let message = b"51"; 49 | let (leaf, index) = mt.insert(message).unwrap(); 50 | assert_eq!(mt.update(), mt.get_root()); 51 | let merkle_proof = mt.get_proof(index); 52 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 53 | ``` 54 | 55 | ## EDDSA 56 | 57 | > TODO 58 | -------------------------------------------------------------------------------- /docs/zkmega/metis.md: -------------------------------------------------------------------------------- 1 | # Metis 2 | 3 | > TODO 4 | -------------------------------------------------------------------------------- /docs/zkmega/reports.md: -------------------------------------------------------------------------------- 1 | # zkMega议会提案报告 2 | 3 | 提案报告是Patract向Polkdaot/Kusama财政提交申请后,在结束汇报阶段提交评审的文档。每一期文档涵盖了本次提案中的设计思路,完成的主要内容。 4 | 5 | 报告代表着本次Patract团队的工作成果,同时也是很好的参考文档。 6 | 7 | 当前zkMega的提案报告有如下内容: 8 | 9 | - [v0.1Report](./reports/v0.1Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | 12 | -------------------------------------------------------------------------------- /docs/zkmega/tutorial.md: -------------------------------------------------------------------------------- 1 | # tutorial 2 | 3 | ## 基于 Substrate 的链引入 zkMega 的零知识原语 4 | 5 | 具备`pallet-contracts`的链集成 zkMega 可以参照 Jupiter 的集成方式: [https://github.com/patractlabs/jupiter/blob/master/primitives/chain-extension/src/lib.rs](https://github.com/patractlabs/jupiter/blob/master/primitives/chain-extension/src/lib.rs) 6 | 7 | 其主要步骤主要分为以下几步: 8 | 9 | 1. 设计一个实现于 `ChainExtension` 的结构体 10 | 2. 在`ChainExtension`的`call`的实现中判断 `func_id` 的范围,按照 [PIP-101](https://github.com/patractlabs/PIPs/blob/main/PIPs/pip-101.md) 中的描述,当前使用 zkMega 需要的范围为 `0x01000000..=0x010000ff`。因此可以在实现中引入: 11 | 12 | ```rust 13 | match func_id { 14 | // 0x01000000-0x010000ff Patract ZKP Support 15 | 0x01000000..=0x010000ff => { 16 | 17 | } 18 | } 19 | ``` 20 | 21 | 3. 然后在 `0x01000000..=0x010000ff` 的代码块中引入 gas 计费的方式。不同的链可能会对 zkMega 调用的方法设计不同的计费方式。在Jupiter的案例中仅最简单的设计了一个固定消耗gas的方式: 22 | 23 | ```rust 24 | let simple_weight = match func_id & 0x01 { 25 | 0 => 100_000, // add, In ethereum: 500 26 | 1 => 8_000_000, // 80x then add, In ethereum: 40000 27 | 2 => {/* ...*/ } 28 | _ => return Err(DispatchError::Other("Unimplemented Patract ZKP func_id")); 29 | }; 30 | env.charge_weight(simple_weight)?; 31 | ``` 32 | 33 | 4. 根据链自身需要 Native 的调用还是 Wasm 的调用进行不同的实现: 34 | 35 | 例如如果该链只想支持 Wasm 的调用,则使用如下方式: 36 | 37 | ```rust 38 | zkmega_arkworks::call(&func_id, &input); 39 | ``` 40 | 41 | 若该链希望将调用放到 Native 上执行,则可以类似于Jupiter一致,设计 `runtime_inferface` 包裹`zkmega_arkworks::call` 的调用,将调用过程放到 std 下编译。然后在 `ChainExtensions`的实现中调用 `runtime_interface` 导出的方法即可。 42 | 43 | ## 合约中调用 zkMega 的零知识原语的接口 44 | 45 | 合约中使用 zkMega 就比较简单。首先在合约依赖中引入`megaclite-arkworks` 46 | 47 | ```toml 48 | [dependencies] 49 | megaclite-arkworks = { git = "https://github.com/patractlabs/zkmega", features = [ "ink" ], default-features = false } 50 | ``` 51 | 52 | 请注意引入 zkMega 库的时候需要使用 `ink` feature。 53 | 54 | 之后在合约里即可以使用 zkMega 提供的方法: 55 | 56 | ```rust 57 | megaclite_arkworks::verify(...); 58 | ``` 59 | 60 | 如果是比较底层的调用,则可以直接通过`call`来调用: 61 | 62 | ```rust 63 | let func_id = /*id defined in PIP-101*/ 64 | megaclite_arkworks::verify(func_id, ...); 65 | ``` 66 | -------------------------------------------------------------------------------- /docusaurus.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('@docusaurus/types').DocusaurusConfig} */ 2 | module.exports = { 3 | title: 'Substrate Contracts Book', 4 | tagline: 'Substrate Contracts Book', 5 | url: 'https://docs.patract.io', 6 | baseUrl: process.env.BASE_PATH || '/', 7 | onBrokenLinks: 'throw', 8 | onBrokenMarkdownLinks: 'warn', 9 | favicon: 'img/favicon.png', 10 | organizationName: 'patractlabs', // Usually your GitHub org/user name. 11 | projectName: 'substrate-contracts-book', // Usually your repo name. 12 | i18n: { 13 | defaultLocale: 'zh', 14 | locales: ['zh', 'en'] 15 | }, 16 | themeConfig: { 17 | prism: { 18 | additionalLanguages: ['rust'], 19 | }, 20 | navbar: { 21 | logo: { 22 | alt: 'Substrate Contracts Book', 23 | src: 'img/logo.svg', 24 | }, 25 | items: [ 26 | { 27 | href: 'https://www.patract.io', 28 | label: '主页', 29 | position: 'left', 30 | }, 31 | { 32 | href: 'https://blog.patract.io', 33 | label: '博客', 34 | position: 'left', 35 | }, 36 | // right 37 | { 38 | href: 'https://github.com/patractlabs/substrate-contracts-book', 39 | label: 'GitHub', 40 | position: 'right', 41 | }, 42 | { 43 | type: 'localeDropdown', 44 | position: 'right', 45 | // dropdownItemsAfter: [ 46 | // { 47 | // href: 'https://github.com/patractlabs/substrate-contracts-book', 48 | // label: 'Help Us Translate', 49 | // }, 50 | // ], 51 | }, 52 | ], 53 | }, 54 | // footer: {}, 55 | }, 56 | presets: [ 57 | [ 58 | '@docusaurus/preset-classic', 59 | { 60 | docs: { 61 | routeBasePath: '/', 62 | sidebarPath: require.resolve('./sidebars.ts'), 63 | editUrl: 64 | 'https://github.com/patractlabs/substrate-contracts-book/edit/master', 65 | }, 66 | theme: { 67 | customCss: require.resolve('./src/css/custom.css'), 68 | }, 69 | }, 70 | ] 71 | ], 72 | }; 73 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current.json: -------------------------------------------------------------------------------- 1 | { 2 | "version.label": { 3 | "message": "Next", 4 | "description": "The label for version current" 5 | }, 6 | "sidebar.docs.category.介绍": { 7 | "message": "Introduction", 8 | "description": "The label for category 介绍 in sidebar docs" 9 | }, 10 | "sidebar.docs.category.ink!": { 11 | "message": "ink!", 12 | "description": "The label for category ink! in sidebar docs" 13 | }, 14 | "sidebar.docs.category.ask!": { 15 | "message": "ask!", 16 | "description": "The label for category ask! in sidebar docs" 17 | }, 18 | "sidebar.docs.category.Reports": { 19 | "message": "Reports", 20 | "description": "The label for category Reports in sidebar docs" 21 | }, 22 | "sidebar.docs.category.Redspot": { 23 | "message": "Redspot", 24 | "description": "The label for category Redspot in sidebar docs" 25 | }, 26 | "sidebar.docs.category.Plugin": { 27 | "message": "Plugin", 28 | "description": "The label for category Plugin in sidebar docs" 29 | }, 30 | "sidebar.docs.category.Europa": { 31 | "message": "Europa", 32 | "description": "The label for category Europa in sidebar docs" 33 | }, 34 | "sidebar.docs.category.zkMega": { 35 | "message": "zkMega", 36 | "description": "The label for category zkMega in sidebar docs" 37 | }, 38 | "sidebar.docs.category.Himalia": { 39 | "message": "Himalia", 40 | "description": "The label for category Himalia in sidebar docs" 41 | }, 42 | "sidebar.docs.category.Metis": { 43 | "message": "Metis", 44 | "description": "The label for category Metis in sidebar docs" 45 | }, 46 | "sidebar.docs.category.Elara": { 47 | "message": "Elara", 48 | "description": "The label for category Elara in sidebar docs" 49 | }, 50 | "sidebar.docs.category.Jupiter": { 51 | "message": "Jupiter", 52 | "description": "The label for category Jupiter in sidebar docs" 53 | }, 54 | "sidebar.docs.category.PatraStore": { 55 | "message": "PatraStore", 56 | "description": "The label for category PatraStore in sidebar docs" 57 | } 58 | } -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/architecture.md: -------------------------------------------------------------------------------- 1 | ## Architecutre 2 | 3 | ## Mechanism 4 | ### ink! - rust Macros 5 | The way how ask! is implmented is very similar to ink!. Ink utilizes rust Macros to server as an eDSL to write smart contracts. 6 | 7 | ### ask! - Assemblyscript Transform 8 | On the other hand, since Assemblyscrit is compiled statically, so code transformation cannot be done at runtime but must instead be performed at complied time. To enable this, the compiler frontend (asc) provides a mechanism to hook into the compilation process before, while and after the module is being compiled. By implementing a custom transform plugin for Assemblyscript, we make ask! to serve as an eDSL of assemblyscript. 9 | 10 | ### ask! - Decorators 11 | Since Typescript/AssemblyScript supports decorators, ask! chooses using decorators to achieve the same purpose as rust Macros. Ask! uses decorators to extend the Abstraction Syntax Tree to implement the internal logics with additional code. Using decorators can hide the complex logic of contract execution and interaction with `contract-pallet` to allow developers only focus on contract development alone. 12 | 13 | ## How compilation works in ask! 14 | ask! implements [transform](https://github.com/patractlabs/ask/tree/master/ts-packages/transform) to interview with Assemblyscript compilation process as follows: 15 | 16 | 17 | ![ask-design](../img/ask-design.png) 18 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/ask-cli.md: -------------------------------------------------------------------------------- 1 | # ask-cli 2 | 3 | ## Usage 4 | ```typescript 5 | npx pl-ask-cli xxx 6 | ``` 7 | 8 | ## init 9 | initialize a ask project with node packages and create directory structure 10 | ```bash 11 | npx pl-ask-cli init 12 | ``` 13 | Will create the directory structure like 14 | ``` 15 | project 16 | │ package-lock.json 17 | | 18 | └───node_modules 19 | │ 20 | └───contracts 21 | ``` 22 | ## compile 23 | ```bash 24 | npx pl-ask-cli compile source-file [--debug|--release] 25 | ``` 26 | By default, `npx pl-ask-cli compile` will compile in release mode. 27 | 28 | For example, `npx pl-ask-cli compile contracts/index.ts` will yield. 29 | ``` 30 | project 31 | │ package-lock.json 32 | | 33 | └───node_modules 34 | │ 35 | └───contracts 36 | │ ├── index.ts 37 | │ └── erc20.ts 38 | │ 39 | └───build 40 | │ ├── index.wasm 41 | │ └── metadata.json 42 | ``` 43 | For example, `npx pl-ask-cli compile contracts/index.ts --debug` will yield. 44 | ``` 45 | project 46 | │ package-lock.json 47 | | 48 | └───node_modules 49 | │ 50 | └───contracts 51 | │ ├── index.ts 52 | │ └── erc20.ts 53 | │ 54 | └───build 55 | │ └───extension 56 | │ │ ERC20.ts 57 | │ │ index.ts 58 | │ ├── index.wasm 59 | │ └── metadata.json 60 | │ └── index.wast 61 | ``` -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/ask-ink.md: -------------------------------------------------------------------------------- 1 | # Ask! vs ink! 2 | 3 | If you have written contracts ink!, you can grab ask! quickly by simply understand their differences. 4 | 5 | | | ink! | Ask! | 6 | | :--------------------------- | :-------------------------- | :------------------------------------ | 7 | | Language | Rust | AssemblyScript | 8 | | Overflow Protection | Enabled by default | None | 9 | | Constructor Functions | Multiple | Multiple | 10 | | Tooling | Anything that supports Rust | Anything that supports AssemblyScript | 11 | | Versioning | Semantic | Semantic | 12 | | Has metadata? | Yes | Yes | 13 | | Multi-File Project | Planned | Yes | 14 | | Storage Entries | Variable | Variable | 15 | | Has Interfaces? | Yes (Rust Traits) | Yes | 16 | | Has Inheritance? | No | Yes | 17 | | Support unit test? | Yes | No | 18 | | Support cross-contract calls | Not production ready | Yes | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/cross-contract.md: -------------------------------------------------------------------------------- 1 | # Cross Contract Calling 2 | 3 | Assume that the following contract A already exists on the chain. 4 | ```typescript 5 | @contract 6 | class Libadd { 7 | constructor() {} 8 | 9 | @constructor 10 | default(): void {} 11 | 12 | @message(mutates = false) 13 | add(a: i32, b: i32): i32 { 14 | return a + b; 15 | } 16 | } 17 | ``` 18 | If you want to call the contract in contract B, you can declare a @dynamic class to describe its interface. 19 | ```typescript 20 | @dynamic 21 | export class Libadd { 22 | // Note that the method experience here will be covered by the actual code, this writing is mainly for compiling 23 | add(a: i32, b: i32): i32 { 24 | return 0; 25 | } 26 | } 27 | 28 | @contract 29 | class LibaddCaller { 30 | constructor() {} 31 | 32 | @constructor 33 | default(): void {} 34 | 35 | @message(mutates = false) 36 | callAddFromExternal(outAddress: AccountId, a: i32, b: i32): i32 { 37 | let outContract = new Libadd(outAddress); 38 | let val = outContract.add(a, b); 39 | return val; 40 | } 41 | } 42 | ``` 43 | outAddress here is the instance address of contract Libadd. 44 | 45 | This function can also call contracts written in other smart contract languages, such as ink!, as long as it follows the compatible metadata.json specification. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/decorators/event-decorator.md: -------------------------------------------------------------------------------- 1 | # Event Decorators 2 | 3 | ## Class Decorator 4 | ### @event 5 | #### Usage 6 | Smart contracts can define events that can be emitted during contract execution, and third-party tools can use emitted events to query information about contract execution and status. Event fields must implement the Codec interface, they will be collected as event data, and the fields decorated by @topic will also serve as the index of the event. 7 | 8 | > `@event` class currently does not supports inheritence 9 | 10 | #### Example 11 | ```typescript 12 | @event 13 | class Transfer { 14 | @topic from: AccountId; 15 | @topic to: AccountId; 16 | 17 | value: u128; 18 | 19 | constructor(from: AccountId, to : AccountId, value: u128) { 20 | this.from = from; 21 | this.to = to; 22 | this.value = value; 23 | } 24 | } 25 | ``` 26 | 27 | ## Property Decorator 28 | ### @topic 29 | #### Usage 30 | - `@topic` can only be used underneath `@event` class 31 | - The property decorated with `@topic` will generate an additional topic index. 32 | - There is a limit to the number of indexes for each event (the default maximum is four). 33 | 34 | #### Example 35 | ```typescript 36 | @topic from: AccountId; 37 | ``` 38 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/decorators/overview.md: -------------------------------------------------------------------------------- 1 | # Decorators overview 2 | 3 | ask! provides a set of decorators to allow developers to code smart contract in Assemblyscirpt. eg.`@contract`. To further define the decorator's behavior during compilation, ask! introduces parameters within decorator. eg. `@message({"mutates": false})`. Currently, ask! has mainly two types of decorators: class decorators and syntax decorators. 4 | 5 | ## contract 6 | ### class: 7 | [`@contract`](./contract-decorator.md###@contract): marks this class as a contract 8 | 9 | [@dynamic](././contract-decorator.md###@dynamic): marks this class as an existing contract for cross contract call 10 | 11 | ### property: 12 | [`@state`](./contract-decorator.md###@state): marks this class property as state needs to be synced to blockchain 13 | 14 | ### method: 15 | [`@constructor`](./contract-decorator.md###@constructor): marks this method as constructor in instatiate a contract 16 | 17 | [`@message`](./contract-decorator.md###@message): marks this method as a public method in a smart contract 18 | 19 | ## event 20 | ### class 21 | [`@event`](./event-decorator.md###@event): marks this class as an event emitted during contract execution 22 | 23 | ### property: 24 | [`@topic`](./event-decorator.md###@topic): marks this class property as a topic and to be indexed 25 | 26 | ## metadata 27 | `@doc`: provide documentation for the information generated by metadata.json. It can add documentation comments for @contract/@event/@message/@constructor declarations. 28 | 29 | ```typescript 30 | @contract 31 | @doc(desc = "MyToken conract that implement erc20 contract") 32 | class MyToken { 33 | // ... 34 | } 35 | ``` 36 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | In our [examples](https://github.com/patractlabs/ask/tree/v0.3-review/examples) directory you find a number of examples written in ask!. 3 | 4 | We provide some samples written in Ask!: 5 | 6 | To build a single example navigate to the root of the example and run: 7 | ``` 8 | npx pl-ask-cli compile 9 | ``` 10 | 11 | * `flipper` : shows how to flip a boolean. 12 | * `incrementer` : shows how to load, modify and restore a state variable. 13 | * `crosscall` : shows how to do a cross call between contracts written in ink! and Ask!. 14 | * `erc20`: shows how to write an ERC20 contract with Ask!. 15 | * `erc721`: shows how to write an ERC721 contract with Ask!. 16 | * `composite`: shows how to store / reload composite data types. 17 | 18 | For example, `npx pl-ask-cli compile erc20/index.ts` will yield. 19 | ``` 20 | project 21 | │ package-lock.json 22 | | 23 | └───node_modules 24 | │ 25 | └───contracts 26 | │ ├── index.ts 27 | │ └── erc20.ts 28 | │ 29 | └───build 30 | │ ├── index.wasm 31 | │ └── metadata.json 32 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/global.md: -------------------------------------------------------------------------------- 1 | # Environment Variables 2 | Environment Variables are variables globally available in `@contract` class 3 | It's advised to use those variables under `@contructor` and `@message` methods 4 | 5 | ## block 6 | ### `block.timestamp (u64)` 7 | current block timestamp as seconds since unix epoch 8 | 9 | ### `block.number (u32)` 10 | current block number 11 | 12 | ## msg 13 | ### `msg.value (u128)` 14 | seal_value_transferred 15 | 16 | ### `msg.sender (AccountId)` 17 | sender of the message (current call) 18 | 19 | ### `msg.sig (u8)` 20 | first four bytes of the calldata (i.e. function identifier) 21 | 22 | ### `msg.data (u8)` 23 | complete calldata 24 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/guides/types-storage/basic_types.md: -------------------------------------------------------------------------------- 1 | # Storage and data strucutures 2 | 3 | ## Basic Types 4 | Ask! provides its own data types implmenting scale codec corresponding to basic data types in [AssemblyScript](https://www.assemblyscript.org/) and standard library collections. 5 | 6 | | AssemblyScript | ask! |ask! convert | 7 | | ----------- | ----------- |----------- | 8 | | `bool` | `Bool` |true | 9 | | `i{8, 16, 32, 64, 128}` | `Int{8, 16, 32, 64, 128}` |true | 10 | | `u{8, 16, 32, 64, 128}` | `UInt{8, 16, 32, 64, 128}` |true | 11 | | `string(String)` | `ScaleString` |true | 12 | | `Array` | `ScaleArray` |false | 13 | | `Set` | `ScaleSet` |false | 14 | | `Map` | `ScaleMap` |false | 15 | 16 | 17 | 18 | When the basic assemblyscript types in the table above are used in the contract code (not including container types such as `Array`/`Set`/`Map`), Ask! It will be automatically converted to the corresponding Scale type (that is, automatic boxing/unboxing) for storage during compile time. 19 | 20 | ## Contract Parameter Types 21 | Contract Parameter Types are types defined to communicate Frame `pallet-contract` 22 | 23 | | Contract Parameter Types | ask! types | 24 | | ----------- | ----------- | 25 | | `AccountId` | `Array(32)` | 26 | | `Hash` | `Array(32)` | 27 | | `Balance` | `UInt128` | 28 | | `BlockNumber` | `UInt32` | 29 | 30 | You can customize them in `assembly/env/CustomTypes.ts` as long as the correct Codec is implementd. 31 | 32 | ## Usage 33 | ### storage 34 | You can import `Bool` via `ask-lang`. 35 | ```ts 36 | import { Bool } from 'ask-lang'; 37 | ``` 38 | If you need to store this data for blockchain storage 39 | ```typescript 40 | class Flipper { 41 | @state flag: Bool; 42 | } 43 | ``` 44 | 45 | You can also directly use `bool` and ask! will convert it automatically during compilation 46 | ```typescript 47 | class Flipper { 48 | @state flag: bool; 49 | } 50 | ``` 51 | ### Opt out of storage 52 | If you does not need to sync the data to blockchain storage but just declare it as a normal class property 53 | 54 | ```typescript 55 | class Flipper { 56 | @state flag: bool; 57 | flag1: bool; 58 | } 59 | ``` 60 | 61 | ## Lazy 62 | When a data is decorated with `@state`, it means it will sync with the blockchain database when its value gets changed which involves calling host function `seal_set_storage` or `seal_get_storage`. However, calling host function is expensive in terms of wasm performance. 63 | 64 | Therefore `@state` introduces lazy option as: `@state({"lazy": false})` While lazy is true, that means while a state variable gets changed multiple times in a contract call, only the last change will be synced to blockchain. 65 | 66 | By default, `lazy` is set to `true`. While lazy is false, then every change made to the state variable will be synced to blockchain. 67 | 68 | Basic principle of implmentation: For every state varible with lazy set as true, the setter function generated by compiler will only updates the value changed in memory; Meanwhile, compiler also creates a __commit__ function. If the state variables within this function ever gets changed before the contract call is done, the updated values will be synced to blockchain. 69 | 70 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/img/ask-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/img/ask-design.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | ask! is an Embedded Domain Specific Language (EDSL) to write WebAssembly based smart contracts using typescript. 3 | 4 | Unlike solidity, ask! is not a standalone languange but more like a assemblyscript "contract format" with customized `@message` decorator. Those decorators tell ask! compiler how the smart contract is define and further compiles them to WASM bytecode compatible with Substrate. 5 | 6 | ## Assemblyscirpt 7 | ask! is subset of Assemblyscrip while Assemblyscript is a subset of Typescript syntax. Currently, a large group of developers are using Typescript since Typescript has relatively low learning curve. Therefore, Patract Labs optmisticly believes with the introduction of ask!, we would see a good growth of contract developers in Substrate. 8 | 9 | ## ask! vs ink! 10 | | languange | ask! | ink! | 11 | | :--- | :----: | ---: | 12 | | eDSL | Typescript | rust | 13 | | annotation | decorator | macro | 14 | | cli | [ask-cli](https://github.com/patractlabs/ask-cli) | [cargo contract](https://github.com/paritytech/cargo-contract) | 15 | | abstraction | inheritence | trait | 16 | | data types | [AssemblyScript SCALE Codec](https://github.com/LimeChain/as-scale-codec) | [Parity SCALE Codec](https://github.com/paritytech/parity-scale-codec)| 17 | 18 | ## Reports 19 | - [v0.1Report](../reports/v0.1Report.md) 20 | - [v0.2Report](../reports/v0.2Report.md) 21 | - [v0.3Report](../reports/v0.3Report.md) -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/intro/why-ask.md: -------------------------------------------------------------------------------- 1 | Why AssemblyScript for WASM Smart Contracts. 2 | ask! is not a new programming language but rather a subset of Aseemblyscript by utilizing decorators. 3 | 4 | - Being a variant of TypeScript makes it easy to compile to WebAssembly without learning a new language. 5 | - AssemblyScript is the most popular language for WASM besides C/CPP/Rust 6 | - AssemblyScript targets WebAssembly's feature set specifically, giving developers low-level control over their code. 7 | - Integrates with the existing JS ecosystem - no heavy toolchains to set up. Simply npm install it! 8 | - Small WASM size and high contract execution performance when comparing to Rust -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_call.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_deploy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_deploy.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_deploy_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_deploy_result.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_upload.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.1Report_upload.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2PackedStorableArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2PackedStorableArray.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2PackedStorableMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2PackedStorableMap.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2SpreadStorableArray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2SpreadStorableArray.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2SpreadStorableMap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2SpreadStorableMap.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2erc20.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/ask/reports/img/v0.2erc20.gif -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engcontract_model_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engcontract_model_1.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engcontracts_wasm_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engcontracts_wasm_1.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/englanguage_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/englanguage_2.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engprocess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/engprocess.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/language_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/language_1.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/language_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/language_2.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/model.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/model.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/overview_module.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/overview_module.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/wasm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/contracts/imgs/wasm.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/introduction.md: -------------------------------------------------------------------------------- 1 | # Substrate contract 2 | 3 | ## Contract overview 4 | 5 | This book introduces a series of knowledge related to the contract system in Substrate. It is written by [Patract](https://patract.io/) and maintained by [Aten](https://github.com/atenjin). The repository address is located in [substrate-contracts-book](https://github.com/patractlabs/substrate-contracts-book), and we welcome you to contribute to this book. 6 | 7 | This book mainly elaborates from the following three aspects. 8 | 9 | * Contract platform (module) for running contracts 10 | * Language for writing contracts 11 | * Tools to assist contract development 12 | 13 | Among them,`pallet-evm`(that is, the contract of the EVM/Solidity system) has relatively rich information in the Ethereum ecosystem, so I will not focus on it in this contract book. Other contract systems, such as `pallet-actor`,`libra` transplantation contract platform, , are in the early stage of research, so they will not be explained in this book. 14 | 15 | This book introduces pallet-contracts (Wasm contracts) as the main body, and the content mainly includes: 16 | 17 | Contract platform (module) to run the contract 18 | 19 | * pallet-contracts 20 | 21 | Language for writing contracts 22 | 23 | * ink! 24 | * Ask! 25 | * Solang 26 | 27 | Tools to assist in contract development 28 | 29 | * Redspot 30 | * Europa 31 | * Elara 32 | 33 | In order to give you a better understanding of how the pallet-contracts module and Wasm contracts operate, this book will also involve an introduction to Wasm and the blockchain contract model. I believe this book will definitely benefit you. 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/contracts/wasm_first_step.md: -------------------------------------------------------------------------------- 1 | # Brief introduction of Wasm 2 | 3 | ## The association between Wasm and contract model 4 | ![](./imgs/engcontracts_wasm_1.jpg) 5 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/elara/design.md: -------------------------------------------------------------------------------- 1 | # Design Brief 2 | 3 | Elara has long-term development iteration planning and operation and maintenance goals, in order to be able to support the continuous transition of Polkadot ecological developers from the 10,000+ level to the 100 million+ level. The core of Elara is a set of high-performance, high-availability and high-scalability distributed architecture. It is significantly different from other projects that provide Node API Service: 4 | 5 | 1. Elara's back-end architecture is not a simple but inefficient NodePool+LoadBalancer. This solution cannot bear the impact of large-scale applications and traffic, and cannot be expanded in time, because Node will become a significant bottleneck in the system. In Elara's architecture, only a small number of Nodes are required to provide basic data sources. Elara supports the access of a large number of users through the design of distributed architecture, the integration of multiple services, and the ultimate optimization of request access paths. The short-term development cost of the NodePool solution is low, but the unit cost of long-term service to users is extremely high. Conversely, Elara’s initial investment in technology costs is relatively high, but in the long term it can greatly reduce the unit cost of serving users, while also ensuring high service quality. 6 | 7 | 2. Elara focuses on providing a minimalist full-featured experience for ecological developers. What we provide is an extremely "thin" layer of service, and we hope that developers will not feel the existence of Elara. The API service provided by Elara not only includes all the functions of the node, but also includes the historical status data function, but also includes the project's request statistics dashboard and other functions. The service capabilities provided to developers are far greater than the capabilities provided by the deployment of nodes by themselves. Therefore, under this goal, functions such as "one-click node deployment" are very redundant, and developers should only focus on their own business applications. 8 | 9 | 3. Elara is an open platform, upholding the principle of community building. In the next iteration of the version, we will continue to access more mainnets and establish a set of process specifications for the automatic access of the Polkadot ecological main chain and parachain. 10 | 11 | 12 | 13 | In terms of overall design, Elara is designed as a microservice architecture system consisting of multiple microservices that can be independently extended. All microservices run as independent processes after they are started, so in the future, individual microservices can be upgraded in parallel, such as expansion, reconstruction, replacement implementation, and so on. Among them, `Redis` is used as a storage container for high-speed data access, and is decoupled from the use of `kafka` for architecture. In the future, it will be easy to add more complex functional modules based on this design to let Elara play a more powerful effect. 14 | 15 | The core architecture of Elara is roughly as follows 16 | 17 | ![elara](https://user-images.githubusercontent.com/21072025/111115173-35923280-859f-11eb-8172-737c07aab4e7.png) -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/elara/introduction.md: -------------------------------------------------------------------------------- 1 | # Elara 2 | 3 | In Polkadot, Kusama or Parachain, RPC is the interface between Dapp and the network. As the Polkadot network continues to expand, more and more parachains will be online, and more and more parachains will support smart contract functions. Faced with more and more parallel chains, developers need to build and maintain multiple chain node RPCs in order to interact with them, which will be a huge development cost for them. 4 | 5 | Whether it is facing the development and testing needs of developers, or users' online Dapp usage needs, convenient, convenient, fast and stable network access is one of the necessary conditions. Therefore, providing developers and ordinary users with a unified and simplified network access service capability is a necessary support for serving Dapp developers, and it is also the infrastructure of the Polkadot ecosystem. 6 | 7 | Elara's goal is to build an infrastructure and network public access service similar to Infura, to provide developers with a unified access layer with multiple connections. We will create a universal architecture that can easily access Polkadot, Kusama, various parachains and various substrate chains, that is, focus on serving Polkadot and Kusama, while maintaining scalability, and benefiting the entire Substrate ecosystem. 8 | 9 | In addition, as part of the smart contract development ecosystem service, Elara will be integrated with other components of the Patract Suite in the future, and will be fully integrated in terms of contract development environment support, development tool components, contract deployment and application release, and simplify the application foundation. Architecture allows developers to focus on building upper-level applications. 10 | 11 | Currently, we have provided online service elara.patract.io. The community is welcome to use Elara: 12 | -Everyone can use Polkadot provided by Elara and the public shared RPC services of multiple ecological mainnets (such as wss://polkadot.elara.patract.io and https://polkadot.elara.patract.io). 13 | -Developers can visit elara.patract.io to obtain exclusive online services with free access to multiple networks. 14 | 15 | More information: 16 | 17 | Github: 18 | 19 | Homepage: 20 | 21 | Docs: 22 | 23 | ## Report for Elara proposals 24 | 25 | - [v0.1Report](./reports/v0.1Report.md) 26 | - [v0.2Report](./reports/v0.2Report.md) -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/elara/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Elara proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Elara proposal report has the following content: 8 | 9 | - [v0.1Report](./reports/v0.1Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | 12 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/elara/tutorial.md: -------------------------------------------------------------------------------- 1 | # Tutorial 2 | Elara's API requires a valid Project Endpoint to be included in your request. This identifier should be appended to the request URL. 3 | 4 | ## Get YOUR-PROJECT-ENDPOINT 5 | 1. Use your github account to log in [Elara official website](https://elara.patract.io/) 6 | 7 | 2. Enter [Elara Dashboard](https://elara.patract.io/#/dashboard/console), click to select the main chain in the left sidebar. 8 | 9 | 3. Click the "Create New Project" button in the upper right corner, enter "PROJECT-NAME" in the pop-up dialog box, and then click "OK". If everything is ok, you will see a message stating that the project has been successfully created. 10 | 11 | 4. In the project list, click the project to enter the project details page 12 | -There is a list of information showing "PID", a string of characters and numbers with a length of 32, which is the "YOUR-PROJECT-ID" of the project 13 | -There is a column that displays "ENDPOINTS" information, including "https" and "wss" for accessing ENDPOINT. That is the "YOUR-PROJECT-ENDPOINT" of the project 14 | 15 | 16 | 17 | ## Make a request 18 | 19 | Use one of these ENDPOINT as the provider of your client program. 20 | 21 | *Note: Please be sure to replace YOUR-PROJECT-ENDPOINT with Project Endpoint in the Elara dashboard* 22 | 23 | - Method 1: curl sends an HTTP request: 24 | ```bash 25 | #curl http 26 | curl --location --request POST'https://YOUR-PROJECT-ENDPOINT' \ 27 | --header'Content-Type: application/json' \ 28 | --data-raw'{ 29 | "id":1, 30 | "jsonrpc":"2.0", 31 | "method":"chain_getBlock", 32 | "params":[] 33 | }' 34 | ``` 35 | 36 | - Method 2: Use wscat to send websocket request: 37 | ``` 38 | parachain@ubuntu:~/elara$ wscat -c wss://YOUR-PROJECT-ENDPOINT 39 | Connected (press CTRL+C to quit) 40 | > {"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]} 41 | <{"jsonrpc":"2.0","result":{"block":{"extrinsics":["0x280402000b901ac96e7601"],"header":{"digest":{"logs":["0x066175726120dfcdf90f00000000"," 0x05617572610101acb2a4725f0f8945593cea6aa6ef70df2a8fd4a2c4eb1c0d1bf51828f26e371f897473113541f9c0d9f94e51471a3d685a86866a12133ea012d2777bb9709589 "]}," extrinsicsRoot ":" 0xcca5112546305b07d904c2aa26155dffe6c66de043708e1ac89e57609fbcc6d1 "," number ":" 0x17922 "," parentHash ":" 0xdb798a19707ef9085b97d0b00854c613ae4abdb560e2ea1164f2e7bbfbc288a1 "," stateRoot ":" 0xdc575fe975067ded933020df9035db0e496143e6b9a062a4313fd1f6e9d02922 "}}," justification ": null}," id ": 1} 42 | > 43 | ``` 44 | 45 | - Method 3: Use SDK 46 | 47 | You can refer to polkadot-js and use the following similar code to access the node through Https or Websocket: 48 | ```javascript 49 | const {ApiPromise, WsProvider} = require('@polkadot/api'); 50 | const {HttpProvider} = require('@polkadot/rpc-provider'); 51 | 52 | (async function () { 53 | // Http 54 | const httpProvider = new HttpProvider('https://YOUR-PROJECT-ENDPOINT') 55 | const hash = await httpProvider.send('chain_getBlockHash', []) 56 | console.log('latest block Hash', hash) 57 | 58 | // Websocket 59 | const wsProvider = new WsProvider('wss://YOUR-PROJECT-ENDPOINT') 60 | const api = await ApiPromise.create({ provider: wsProvider }) 61 | //Do something 62 | 63 | })() 64 | ``` 65 | 66 | It is important to note that JSON-RPC requests have nothing to do with transmission, and the same request can be made via HTTPS and Websockets. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/guides/architecture.md: -------------------------------------------------------------------------------- 1 | # Architeture 2 | ## Another Substrate Implementation 3 | 4 | Europa sandbox framework is another implementation for [Substrate client](https://github.com/paritytech/substrate/tree/master/client).That means all substrate runtime could integrate with Europa client directly. 5 | 6 | ## No consensus, only producing blocks on need 7 | 8 | Europa focuses on contract development regardless which consensus protocol is running, so that we remove all components about consensus. Thus, we use `sc-consensus-manual-seal` crate to produce block. This crate is well abstracted with no need to fork. We just modify the part of commands stream for `manual-seal`. The async stream could receive information from different place (e.g. transaction pool, RPC and others) to drive seal-engine to produce blocks only when receiving extrinsics. 9 | 10 | ## Removed Wasm for Runtime 11 | 12 | As a sandbox designs for debugging during contract development, we remove all Wasm components as Wasm may cause many problems during debugging. Since we need to extend many features for low level libraries, if the runtime is compiled to Wasm for execution, we might encounter many unexpected problems. Also, as a local sandbox, we do not need the features brought by Wasm runtime such as non hard fork software update. 13 | 14 | *Europa runtime should remove `build.rs` in runtime crate and remove `[build-dependencies]` in runtime crate (cargo.toml file).* 15 | 16 | ## State KV to trace block state changes 17 | 18 | In Substrate, we can check the current blockchain states but not the state modifications. However, the developers are concerned mostly about the state changes when new blocks get mined. So that, they can check whether the changes match their expectations for debugging. 19 | 20 | Thus, in europa sandbox, we store the mapping of blockhash and state kvs in the state-kv database, so that developers could export the state changes to look up the details. 21 | 22 | ## `pallet-contracts` Modification 23 | * Modification on the `pallet contracts` layer: By adding trace during the execution of the contract in `pallet contracts`, the information in the contract layer is recorded, and the calling structure of the contract is recorded. The error message during Wasm execution is also enhanced. 24 | * Modification on the `wasmi` layer: We have provided the backtrace function of recording wasm execution for `wasmi`, and provided support for `parity-wasm`, `pwasm-utils`, and `cargo-contract` during wasm processing of the contract contains the function of the name section. 25 | * Contract logging function: Use the function of `ChainExtensions` to realize the library for printing the `log` in the contract. Check [Custom ChainExtensions](../extensions/custom-chain-extensions.md) for more details. 26 | 27 | Check [Contract Pallet Implementation](./implementation.md) for implemention details. 28 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/guides/wasm-executor.md: -------------------------------------------------------------------------------- 1 | # Europa Wasm executor 2 | 3 | TODO: Not completed 4 | 5 | Europa offers different Wasm actuators to execute contracts. Currently `wasmi` and `wasmtime` are provided. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/add_exist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/add_exist.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/call_other_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/call_other_1.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/call_other_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/call_other_2.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_call_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_call_contract.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_error_message.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_error_message.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_extrinsic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_extrinsic.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_wasmi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/contract_wasmi.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/deployed_contract.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/deployed_contract.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa-ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa-ui.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_accounts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_accounts.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_contracts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_contracts.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_developer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_developer.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_instance_function.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_instance_function.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/europa_instances.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/imgs/explorer.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Europa Overview 2 | 3 |
4 | 5 |
6 | 7 | Europa is a private test blockchain based on Substrate to help Runtime Pallet and `pallet-contracts` development. It modifies the native Substrate chain by removing unnecessary components such as Wasm execution and p2p while adding some great features to help developers get more insights of the contract execution details 8 | 9 | ## How does it work 10 | Europa runs as standalone daemon to serve JSON-RPC and Websocket requests. By default, it only mines a block every time it receive extrinsics. Extrinsic, by definition, means state changes that come from the outside the blockchain node itself. For example, a transaction is an extrinsic. Europa is a fork of substrate blockchain with handy modifications, so theoretically, runtime pallets and contracts developed through Europa will work on all substrate based chains as well. 11 | Check [Architectures](../guides/architecture.md) for more insights. 12 | 13 | ## Why use it? 14 | 1. Europa is an implementation of [substrate](https://github.com/paritytech/substrate), while Substrate is a modular framework that enables developers to create purpose-built blockchains by composing custom or pre-built components. For example, Polkadot, Kusama and other parachains are all based on substrate. 15 | 2. Producing a block only when receiving new extrinsics. Developers won't have to wait for block production or deal with redundent blocks. 16 | 3. Removing all wasm execution, only native runtime is kept for execution. By default, substrate support both wasm execution and native execution. Native execution is prprioritized to be used but wasm execution brings hard fork to chain without updating the node software. However, wasm execution makes the code harder to debug. 17 | 4. Additional database entry called `state-kv` to record the state changes. Developers can use RPC calls to fetch those state changes. `state-kv` can also be feteched through cli `europa state-kv ` 18 | 5. Custom RPC calls: 19 | - `europa_forwardToHeight`: forward the blockheight to certain block height with empty blocks 20 | - `europa_backwardToHeight`: revert the blockchain back to certain heights and remove states of reverted blocks 21 | - `europa_modifiedStateKvs`: retrive the cached state changes 22 | 6. Allow developers to swtich between multiple workspace for better dev environment isolation. 23 | 7. Europa also ships with Europa UI and compiled binary release. 24 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Europa proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Europa proposal report has the following content: 8 | 9 | - [v0.1Report](./reports/v0.2Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | - [v0.3Report](./reports/v0.3Report.md) 12 | 13 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_contracts_codes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_contracts_codes.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_contracts_instances.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_contracts_instances.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_explorer.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_cross_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_cross_call.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_details.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_details.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_state_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_state_1.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_state_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_state_2.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_wasm_err.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsic_wasm_err.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsics_call.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_extrinsics_call.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_instance_extrinsics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_instance_extrinsics.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_instance_functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_instance_functions.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_left.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/europa/reports/imgs/report3_start.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/himalia/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Himalia proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Himalia proposal report has the following content: 8 | 9 | - [v0.1&v0.2Report](./reports/v0.1Report.md) 10 | 11 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/call-contracts.md: -------------------------------------------------------------------------------- 1 | # Cross-call for ink! 2 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/cargo-contract.md: -------------------------------------------------------------------------------- 1 | # cargo-contract 2 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/framework.md: -------------------------------------------------------------------------------- 1 | # ink! Framework 2 | 3 | All the main functions of ink! are implemented in the [`ink/crates`](https://github.com/paritytech/ink/tree/master/crates) directory: 4 | 5 | * crates: 6 | * allocator: related to Wasm, define allocator, developers do not need to care in most cases 7 | * env: Provides components that interact with the chain. In summary, the parts related to the chain will be placed here, including 8 | * host function part 9 | * Some types and trait definitions that need to be imported 10 | * topic of event 11 | * lang: The definition component of the eDSL process macro, the contract specification is determined by this place 12 | * metadata: components that generate metadata 13 | * prelude: A package that needs to be imported in advance during the contract writing process, including some standard libraries 14 | * primitives: pointers to operating state storage, developers do not need to care in most cases 15 | * storage: provide chain storage allocation model and provide some predefined storage collection types -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/ink-solidity.md: -------------------------------------------------------------------------------- 1 | # Compare ink! and solidity 2 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/introduction.md: -------------------------------------------------------------------------------- 1 | # ink 2 | 3 | ink! is an eDSL to write WebAssembly based smart contracts using the Rust programming language. The compilation target are blockchains built on the Substrate framework. 4 | 5 | Although ink! claims to be a kind of eDSL for writing contracts, I prefer to think that ink! is a contract framework written in Rust language that meets the requirements of Contracts Pallet. 6 | 7 | For example, for EVM, if the instruction set of the EVM is regarded as a specification (the instruction set of the EVM already contains the information of the EVM contract model), then as long as the language can be compiled into the instruction set of the EVM, it can be said to be able to run on the EVM Contract language on the Internet, for example: 8 | 9 | - Solidity 10 | - Vyper 11 | 12 | And ink! Same here. Contracts Pallet requires Wasm code that can run the Contracts Pallet contract model, so any framework/language/library that can be compiled to meet this Wasm contract model can be called Contracts Pallet's contract language. 13 | 14 | ink! is to use the Rust language, and on this basis, design a set of eDSL through Rust's **hygienic macro system**, and use this eDSL to write Rust code that meets the requirements of Contracts Pallet. In addition to eDSL, ink! also provides a **storage collection type** suitable for contract models, generating Metadata (corresponding to Solidity's ABI) and other tool libraries. 15 | 16 | See the official documentation of ink!: 17 | 18 | - [ink! Concepts](https://substrate.dev/docs/en/knowledgebase/smart-contracts/ink-fundamentals) 19 | - [ink! Smart Contracts Tutorial](https://substrate.dev/substrate-contracts-workshop/#/) 20 | - [ink! Documentation Portal](https://paritytech.github.io/ink-docs/) 21 | 22 | ## ink! The process to the Contracts pallet 23 | 24 | An example image is provided in the official parity document: 25 | ![https://paritytech.github.io/ink-docs/how-it-works](https://paritytech.github.io/ink-docs/img/how-it-works.svg) 26 | 27 | From this figure, we can see that the process of writing and deploying the ink! contract requires 28 | 29 | - ink! dependent library: provide ink! eDSL framework and provide corresponding dependent components 30 | - cargo-contract: tool for compiling ink! contract 31 | - SDK: SDK that interacts with the chain and deploys the contract to the chain. The official parity mainly provides `polkadot.js`, and Patract provides the Himalia toolkit, including `go`, `java`, `python`, `C#` SDK 32 | 33 | This chapter will mainly introduce ink! and `cargo-contract` information, and the information about SDK will be introduced in the following chapters. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/trap.md: -------------------------------------------------------------------------------- 1 | # Current problem for ink! 2 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/ink/tutorial.md: -------------------------------------------------------------------------------- 1 | # ink! tutorial 2 | 3 | TODO -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/contract.md: -------------------------------------------------------------------------------- 1 | ## Contract 2 | 3 | current deployed contract on Jupiter PoA and Jupiter: 4 | 5 | - stable-coin:USDT、jBTC、jETH 6 | - patramaker:DAI 7 | - patrapixel: 8 | - patraswap: 9 | 10 | For contract detail, You can refer to [store-contracts](https://github.com/patractlabs/store-contracts),and you can deploy contract by [redspot](https://github.com/patractlabs/redspot). 11 | 12 | ## Network switch 13 | 14 | open [patrastore](https://patrastore.io/),switch network to Jupiter Para: 15 | 16 | ![parastore](./img/parastore.png) 17 | 18 | and you can also switch back to Jupiter PoA network. 19 | ## Faucet 20 | 21 | Then Click Account - Faucet to get some test coin: 22 | 23 | ![parastore](./img/facet.png) 24 | 25 | After wait awhile, make sure you get the test coin, then you can go to home page and test our own pre-deployed contracts. 26 | 27 | Have fun. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/facet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/facet.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-1.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-2.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/jupiter-xcmp-3.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/parastore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/jupiter/img/parastore.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/quickstart.md: -------------------------------------------------------------------------------- 1 | ## Compile 2 | 3 | ```shell 4 | git clone --recurse-submodules https://github.com/patractlabs/jupiter.git 5 | cd jupiter 6 | cargo build --release 7 | ``` 8 | 9 | After compiled, there're three binary execution file in the directory target/release: 10 | 11 | - target/release/jupiter-dev 12 | - target/release/jupiter-prep 13 | - target/release/jupiter 14 | 15 | ## Run 16 | 17 | ### jupiter-dev 18 | 19 | running in local develop mode: 20 | 21 | ``` 22 | ./jupiter-prep --dev --execution=NativeElseWasm --tmp 23 | ``` 24 | 25 | ### jupiter-prep 26 | 27 | jupiter-prep also support local test mode: 28 | 29 | ``` 30 | # start first node 31 | ./jupiter-prep --chain=jupiter-poa-local --alice --execution=NativeElseWasm --tmp 32 | 33 | # start second node 34 | ./jupiter-prep --chain=jupiter-poa-local --bob --execution=NativeElseWasm --tmp 35 | ``` 36 | 37 | The outside node can also join Jupiter PoA testnet as sync node: 38 | 39 | ``` 40 | ./jupiter-prep --chain=jupiter-poa --pruning=archive --execution=NativeElseWasm 41 | ``` 42 | 43 | ### jupiter 44 | 45 | Currently, outside node can join Jupiter testnet as sync node: 46 | 47 | ``` 48 | ./jupiter --chain ./jupiter-westend-098.json --execution wasm --wasm-execution=compiled --force-authoring --parachain-id=2000 --tmp \ 49 | --chain ./westend-098.json --no-beefy --execution wasm --wasm-execution=compiled --tmp \ 50 | --bootnodes /dns/ws.patract-westend.patract.cn/tcp/30333/p2p/12D3KooWHfn9r5cLyVQRuLin1wsB3KUiVaMWPnnpFd7Hhff6rhUX 51 | ``` 52 | 53 | > Note: If you want to do in local mode, you have to modify [jupiter-dev](https://github.com/patractlabs/jupiter/blob/master/bin/node/cli/src/command.rs#L28-L31), and then refer to [steps here](https://github.com/patractlabs/jupiter/blob/master/README.md#421-start-local-test-mode-jupiter-parachain) 54 | 55 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/jupiter/xcmp.md: -------------------------------------------------------------------------------- 1 | # XCMP Transfer 2 | 3 | XCMP only limit to Patract own Westend relaychain and Jupiter parachain, current xcmp function include: 4 | 5 | - Relaychain Westend transfer WND(Relaychain native currency) to Parachain Jupiter 6 | - Parachain Jupiter transferWND(Relaychain native currency) to Relaychain Westend 7 | 8 | XCMP has two transfer model: teleport、reserver transfer, current we suggest use reserve transfer model. 9 | 10 | ## Relaychain transfer to Parachain 11 | 12 | In Patract own Westend, issue an extrinsic as follows: 13 | 14 | ![relay-to-para](img/jupiter-xcmp-1.png) 15 | 16 | > Note: we did't support facet for Patract own Westend for now, we'll add this soon. 17 | 18 | After extrinsic success, check the balance of relaychain account is withdraw, and the balance of parachain account is deposit. 19 | for example, relaychain transfer 1000 WND to parachain, so the relaychain account decrease 1000 WND, and parachain account increase nealy 1000 WND. 20 | 21 | ![para-amount](img/jupiter-xcmp-2.png) 22 | 23 | ## Parachain transfer to Relaychain 24 | 25 | We use [orml_xtokens](https://github.com/open-web3-stack/open-runtime-module-library) to simplify transfer from parachain to relaychain. 26 | 27 | In Jupiter parachain, issue an extrinsic as follows: 28 | 29 | ![relay-to-para](img/jupiter-xcmp-3.png) 30 | 31 | After extrinsic success, check the the balance of relaychain account is deposit, and the balance of parachain account is withdraw. 32 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/guides/extensions.md: -------------------------------------------------------------------------------- 1 | # Extending Metis 2 | Such components can extend their functions by inheriting other components, such as an ERC20 component with the function of destroying tokens: 3 | 4 | ```rust 5 | pub trait Impl: erc20::Impl 6 | where 7 | E: Env, 8 | { 9 | fn _burn(&mut self, account: &E::AccountId, amount: E::Balance) -> Result<()> { 10 | //... 11 | } 12 | 13 | fn burn(&mut self, amount: E::Balance) -> Result<()> { 14 | self._burn(&Self::caller(), amount) 15 | } 16 | 17 | fn burn_from(&mut self, account: &E::AccountId, amount: E::Balance) -> Result<()> { 18 | //... 19 | } 20 | } 21 | ``` 22 | 23 | Based on metis, we can implement various contract combination modes implemented by Solidity through inheritance under limited intent, and at the same time, with the help of rust's zero-cost abstraction, these abstractions will not bring additional performance consumption. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/guides/hook.md: -------------------------------------------------------------------------------- 1 | # Hooks 2 | 3 | ## Why using hook 4 | Sometimes, in order to extend a parent contract you will need to override multiple related functions, which leads to code duplication and errors 5 | 6 | For example, consider implementing safe ERC20 transfers in the style of IERC721Receiver. You may think overriding transfer and transferFrom would be enough, but what about _transfer and _mint? To prevent you from having to deal with these details, Metis uses Function Hooks. 7 | 8 | Hooks are simply functions that are called before or after some action takes place. They provide a centralized point to hook into and extend the original behavior. 9 | 10 | In some component, the hook has a default implementation: 11 | 12 | ```rust 13 | /// @dev Hook that is called before any token transfer. This includes 14 | /// calls to {send}, {transfer}, {operatorSend}, minting and burning. 15 | /// 16 | /// Calling conditions: 17 | /// 18 | /// - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 19 | /// will be to transferred to `to`. 20 | /// - when `from` is zero, `amount` tokens will be minted for `to`. 21 | /// - when `to` is zero, `amount` of ``from``'s tokens will be burned. 22 | /// - `from` and `to` are never both zero. 23 | /// 24 | /// To learn more about hooks, 25 | /// head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 26 | fn _before_token_transfer( 27 | &mut self, 28 | _operator: &E::AccountId, 29 | _from: &Option<&E::AccountId>, 30 | _to: &Option<&E::AccountId>, 31 | _amount: &E::Balance, 32 | ) -> Result<()> { 33 | Ok(()) 34 | } 35 | ``` 36 | 37 | The hook will call by component functions, user can define it, a normal example is Pausable ERC20 component: 38 | 39 | ```rust 40 | fn before_token_transfer( 41 | &mut self, 42 | _from: &E::AccountId, 43 | _to: &E::AccountId, 44 | _amount: E::Balance, 45 | ) -> Result<()> { 46 | metis_pausable::Impl::::ensure_not_paused(self); 47 | 48 | Ok(()) 49 | } 50 | ``` 51 | 52 | The Pausable ERC20 component is extend the erc20 component, which implements the hook. You can find this hooks get called here: 53 | 54 | ```rust 55 | fn _transfer_from_to( 56 | &mut self, 57 | sender: E::AccountId, 58 | recipient: E::AccountId, 59 | amount: E::Balance, 60 | ) -> Result<()> { 61 | let null_account = E::AccountId::default(); 62 | 63 | if sender == null_account || recipient == null_account { 64 | return Err(Error::AccountIsZero) 65 | } 66 | 67 | self._before_token_transfer(&sender, &recipient, &amount)?; 68 | xxxxx 69 | } 70 | ``` -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/guides/imports.md: -------------------------------------------------------------------------------- 1 | # Use Metis components 2 | 3 | !> Warnning: We can redefine the name of metis component, but we should keep in mind that all component names should be changed after import. 4 | 5 | **Note** this: 6 | 7 | ```rust 8 | use metis_component_xxx1 as xxx1; 9 | ``` 10 | 11 | if we use the `xxx1` be the alias of the `metis_component_xxx1`, so the all tag of components should be `xxx1`: 12 | 13 | - The `import` marco for contract 14 | - The name of item in contract struct type 15 | - The `metis` marco for event 16 | 17 | For example: 18 | 19 | ```rust 20 | pub mod contract { 21 | // use the component: xxx1 and xxx2 22 | use metis_component_xxx1 as xxx1; 23 | 24 | ... 25 | 26 | #[ink(storage)] 27 | #[import(xxx1)] // The `import` marco for contract, should be xxx1 28 | pub struct Contract { 29 | // The name of item in contract struct type, should be xxx1 30 | xxx1: xxx1::Data, 31 | } 32 | 33 | ... 34 | 35 | #[ink(event)] 36 | #[metis(xxx1)] // The `metis` marco for event 37 | pub struct OwnershipTransferred { 38 | } 39 | 40 | ... 41 | } 42 | ``` 43 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/guides/macros.md: -------------------------------------------------------------------------------- 1 | # Marcos 2 | The Metis have implemented the following marcos for components development: 3 | 4 | - `contract` : to define the contract following metis contract standard. 5 | - `import` : to generate code to implement the components. 6 | - `metis` : to define the metis component. 7 | - `stub` : to implement stub in metis. 8 | - `reentrancy_guard` : helper macro for the reentrancy_guard component. 9 | - `supports` : helper macro for the ERC165 supports api. 10 | - `hash` : to calculate the hash of a string during compilation. 11 | - `selector_id` : to calculate the selector_id of a message. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/guides/security/reentrancy-guard.md: -------------------------------------------------------------------------------- 1 | # Reentrancy Guard 2 | 3 | Contract component that helps prevent reentrant calls to a function. 4 | 5 | ## Dependency 6 | ```rust 7 | metis_reentrancy_guard = { git = "https://github.com/patractlabs/metis", default-features = false } 8 | ``` 9 | 10 | ## Storage 11 | 12 | In most cases, developer not need to consider the storage of reentrancy guard. 13 | 14 | ```rust 15 | const _NOT_ENTERED: u8 = 1; 16 | const _ENTERED: u8 = 2; 17 | 18 | /// The Data of pausable component 19 | #[cfg_attr(feature = "std", derive(::ink_storage::traits::StorageLayout))] 20 | #[derive(Debug)] 21 | pub struct Data { 22 | /// is contract current paused 23 | status: Lazy, 24 | 25 | key: ink_primitives::Key, 26 | } 27 | ``` 28 | 29 | Note the `key` in module, in `ink!`, all storage will flush to storage after the end of message proccess, 30 | so if contract only modifies `status`, the reentrancy_guard will not work: 31 | 32 | ```rust 33 | /// set current status to entered 34 | pub fn set_entered(&mut self) { 35 | Lazy::set(&mut self.status, _ENTERED); 36 | self.flush() // flush to storage 37 | } 38 | 39 | /// set current status to not entered 40 | pub fn set_not_entered(&mut self) { 41 | Lazy::set(&mut self.status, _NOT_ENTERED); 42 | self.flush() // flush to storage 43 | } 44 | ``` 45 | 46 | ## Internal Function 47 | 48 | There is some internal function for reentrancy_guard, the marco will check it automatically: 49 | 50 | ```rust 51 | #[ink(message)] 52 | #[metis_lang::reentrancy_guard] 53 | pub fn function_can_not_reentrancy(&mut self) { 54 | self._check_nonreentrant(); 55 | self._set_entered(); 56 | 57 | // logics 58 | 59 | self._set_not_entered(); 60 | } 61 | ``` 62 | 63 | the functions: 64 | 65 | - `_check_nonreentrant` : check if the current status is `_NOT_ENTERED` 66 | ```rust 67 | fn _check_nonreentrant(&self) { 68 | assert!(!self.get().is_entered(), "ReentrancyGuard: reentrant call"); 69 | } 70 | ``` 71 | - `_set_entered` : set current status to `_ENTERED` 72 | ```rust 73 | fn _set_entered(&mut self) { 74 | self.get_mut().set_entered(); 75 | } 76 | ``` 77 | - `_set_not_entered` : set current status to `_NOT_ENTERED` 78 | ```rust 79 | fn _set_not_entered(&mut self) { 80 | self.get_mut().set_not_entered(); 81 | } 82 | ``` 83 | ## Usage Example 84 | 85 | To use `reentrant_guard` component, first is import the component: 86 | 87 | ```rust 88 | use metis_lang::{ 89 | import, 90 | metis, 91 | }; 92 | 93 | use metis_reentrancy_guard as reentrancy_guard; 94 | 95 | #[ink(storage)] 96 | #[import(reentrancy_guard)] 97 | pub struct Contracts { 98 | reentrancy_guard: reentrancy_guard::Data, 99 | 100 | // others 101 | } 102 | ``` 103 | 104 | To use reentrancy guard, we can use a marco to check, it like the modifier in solidity: 105 | 106 | ```rust 107 | #[ink(message)] 108 | #[metis_lang::reentrancy_guard] 109 | pub fn function_can_not_reentrancy(&mut self) { 110 | // logics 111 | } 112 | ``` -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/intro/motivation.md: -------------------------------------------------------------------------------- 1 | # Motivation 2 | 3 | ## Current Problems with ink! development 4 | At present, contract-based developers mainly face the following problems: 5 | 6 | - Lack of reliable implementation of common contracts (such as ERC20) 7 | - It is difficult to achieve contract combination and expansion similar to the Solidity inheritance mechanism 8 | - Lack of a series of reliable public components to implement contracts 9 | - Lack of experience accumulation and model summary based on ink! development contracts 10 | 11 | The problems listed above have severely restricted the ink!-based contract development. Metis will solve these problems while avoiding the existing problems in Solidityd and OpenZepplin. 12 | 13 | 14 | ## Design philosophies 15 | 16 | We believe that in the Wasm contract ecosystem, a development library similar to Openzeppelin-contracts is very necessary. This is Metis. For the sake of simplicity and readability, the patterns and meta-language provided by this library should be as consistent with Openzeppelin-contracts as possible, so as to reduce the burden on developers and effectively absorb the experience accumulated in the Solidity ecosystem. 17 | 18 | But Wasm contract development based on ink! is very different from the EVM contract development based on Solidity. Wasm's mature system support allows developers to use a variety of different languages and tools to develop smart contracts. Based on these mature or rapid iteration platforms, developers can enjoy a large number of underlying facilities support and development experience accumulation, but different languages and tools often have different considerations and trade-offs. This means that developers will use completely different codes to express the same mechanism and design, which will bring huge communication costs and mental burdens to the community. 19 | 20 | Faced with such problems, we need to summarize and accumulate the implementation model in the development of smart contracts. This idea was introduced in the book "Implementation Patterns" by Kent Beck. The purpose of summarizing the implementation mode is to clearly and accurately express the developer's intentions and ideas through these clear patterns, so that "code that others can understand" can be implemented. In contract development, this idea is very important. 21 | 22 | From Openzeppelin-contracts, we can see that it summarizes several implementation models in the development of smart contracts, such as the "contract expansion model" based on the Solidity inheritance grammar. These implementation models are valuable experience accumulated in the Solidity ecology. Of course, different languages have different ways of practicing these modes. Metis will implement these modes and provide corresponding support on different platforms. For example, in Rust, it is obvious that you cannot directly use inheritance to implement contract expansion. For this, Metis will provide code implementation examples and provide a series of help libraries to reduce the developer's mental cost. 23 | 24 | Metis will be more than just a Wasm contract standard library. We hope that through the practice of Metis, we can fully inherit and absorb previous contract development experience while exploring the best practices of Wasm contract development. 25 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/metis/reports/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Metis proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Metis proposal report has the following content: 8 | 9 | - [M1Report](./M1Report.md) 10 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/pallet-contracts/introduction.md: -------------------------------------------------------------------------------- 1 | # pallet-contracts 合约模块 2 | 3 | `pallet-contracts`合约模块, 一般称呼为[“Contracts Pallet”](https://substrate.dev/docs/en/knowledgebase/smart-contracts/contracts-pallet) 或者 “FRAME Contracts pallet”,又或者称呼为“Substrate Smart Contracts”,是parity官方研发的Wasm合约模块。 4 | 5 | 依据Substrate knowledgebase的介绍,Contracts Pallet具备如下特性: 6 | * Are inherently safer to the network. 7 | * Have built in economic incentives against abuse. 8 | * Have computational overhead to support graceful failures in logic. 9 | * Have a lower bar to entry for development. 10 | * Enable fast pace community interaction through a playground to write new logic. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/patract/imgs/overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/patract/imgs/overview.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/patract/introduction.md: -------------------------------------------------------------------------------- 1 | # Patract 2 | 3 | ![overview](./imgs/overview.jpg) 4 | 5 | Patract 做的东西具体包括: 6 | 7 | * 在开发者端: 8 | 9 | * Jupiter:独立的智能合约测试网,提供给合约开发者测试合约链的环境。 10 | * Ask!:AssemblyScript 版的 Ink! 合约框架,吸引 TS/JS 的开发者,给不愿意使用 rust 的合约开发者另一个选择。 11 | * Redspot:Wasm 合约开发工作流和脚手架:对标 Ethereum 生态中的 Tuffle/Redhat,让合约开发项目化,自动化的工具。Redspot 采用插件化设计,运行开发者添加自己设计的插件丰富 Redspot 的功能。 12 | * Europa:Runtime 和合约运行沙盒:对标 Ethereum 生态中的 EthereumJS/Ganache,给合约开发者提供了丰富的调试信息,便于快速开发合约。 13 | * Elara:实时和可扩展的波卡 API:对标 Ethereum 中的 Infura,给合约项目方提供节点的 Endpoint,不用自行搭建节点获取数据。 14 | * Megaclite:零知识证明的底层支持:在 Jupiter/Patract 链中提供零知识原语支持,可以允许项目方设计 zkRollup 或其他零知识相关合约。 15 | * Metis:Ink! 合约标准库:对标 Ethereum 中的 openzeppelin-contracts,给合约开发者提供可复用的轮子,不必从零开始编写合约代码。 16 | * Himalia:多语言合约 SDK:对标 Ethereum 中的 Web3J,Web3Py 等 SDK,给合约项目方提供不同语言的环境,丰富的接口与合约进行交互。 17 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/advanced/multi-contract-compilation.md: -------------------------------------------------------------------------------- 1 | # Compile across multiple contracts 2 | Redspot also supports development of multiple wasm smart contracts that calls the function of another contract -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/advanced/write-plugins.md: -------------------------------------------------------------------------------- 1 | # Write new plugins 2 | 3 | You can also write your own ad hoc plugins. We will include a tutorial on how to write your own plugin in the future. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/guides/docker.md: -------------------------------------------------------------------------------- 1 | # Docker 2 | In Redspot v0.4, we added support for using docker to compile contracts. This will ensure that the compiled wasm code being consistent across different platforms. 3 | 4 | Currently, will use [redspot/contract](https://github.com/patractlabs/docker-images/tree/master/contract) docker to compile and run the testnet. It is modified on the basis of [contract docker image](https://github.com/paritytech/scripts/blob/master/dockerfiles/contracts-ci-linux/Dockerfile) provided by Parity Tech. 5 | 6 | ### TestNet 7 | 8 | If the machine has a Docker environment. A testnet can be run by Docker. The canvas testnet is currently built-in. 9 | 10 | You can run the testnet with the following command. 11 | 12 | ```bash 13 | $ npx redspot testnet 14 | ``` 15 | This equivelent of running 16 | ```bash 17 | $ docker run -p 9944:9944 --rm redspot/contract /bin/bash -c "canvas --tmp --dev --ws-port=9944 --ws-external" 18 | ``` 19 | 20 | To modify the default running command, add the `command ` parameter. 21 | 22 | ```bash 23 | $ npx redspot testnet --command 'docker run -p 9945:9944 --rm redspot/contract /bin/bash -c "canvas --tmp --dev --ws-port=9944 --ws-external"' 24 | ``` 25 | 26 | Or modify the redspot.config file. 27 | 28 | ```typescript 29 | docker: { 30 | sudo: false, 31 | runTestnet: 32 | "docker run -p 9944:9944 --rm redspot/contract /bin/bash -c 'canvas --rpc-cors all --tmp --dev --ws-port=9944 --ws-external'", 33 | } 34 | ``` 35 | 36 | ### Compile on docker 37 | Currently Redspot only supports ink! contract docker compilation, to configure the docker env, modify the docker entry in `redspot.config.ts` 38 | 39 | ```typescript 40 | docker: { 41 | sudo: false, 42 | runTestnet: 43 | "docker run -p 9944:9944 --rm redspot/contract /bin/bash -c 'canvas --rpc-cors all --tmp --dev --ws-port=9944 --ws-external'", 44 | } 45 | ``` 46 | Before running the compile command, make sure that Docker is installed on the machine. Run the following command. 47 | 48 | ```bash 49 | $ npx redspot compile --docker true 50 | ``` 51 | 52 | **Note** When using Docker to compile, it may be affected by the network environment. For example, China requires a VPN proxy, which will cause the compilation time to be too long. If you use`ctrl+c`to exit the current compilation command halfway, the Docker container will not automatically stop deleting. 53 | 54 | **Note** If you encounter permission errors, please set `docker.sudo ` in the redspot.config file to true. This will use sudo to run Docker . Or refer to [the official Docker documentation](https://docs.docker.com/engine/install/linux-postinstall/) to configure permissions. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/engprocess.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/engprocess.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/explorer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/explorer.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/process.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/imgs/process.jpg -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/intro/installation.md: -------------------------------------------------------------------------------- 1 | # Setup Enviroment 2 | ## Prerequisites 3 | Please follow the guide on [ink!](https://substrate.dev/substrate-contracts-workshop/#/0/setup) to setup **rust**, **cargo** and **cargo-contracts** 4 | 5 | Please follow the guide on [Nodejs](https://nodejs.org/) to install node and npm 6 | 7 | Install NPX 8 | ``` 9 | sudo npm install -g npx 10 | ``` 11 | ## Setup Local Test Node 12 | You will need blockchain node based on substrate with Contracts pallet module to deploy the contracts and test them. 13 | 14 | ***What is substrate*** 15 | 16 | Substrate is the blockchain framework to help developers craft their own blockchain faster, easier and safer. 17 | 18 | ***What is pallet-contracts*** 19 | 20 | The FRAME Contracts pallet is a module within substrate that provides functionality for a Substrate runtime to deploy and execute WebAssembly Smart Contracts. 21 | 22 | 23 | * [**Canvas**](https://github.com/paritytech/canvas-node) (test node by substrate) 24 | ``` 25 | cargo install canvas-node --git https://github.com/paritytech/canvas-node.git --tag v0.1.9 --force --locked 26 | ``` 27 | Start **Canvas** 28 | ``` 29 | canvas --dev --tmp 30 | ``` 31 | * [**Europa**](../../europa/intro/overview.md) (Patract modification) 32 | ``` 33 | cargo install europa --git=https://github.com/patractlabs/europa.git --force --locked 34 | ``` 35 | Start **Europa** 36 | ``` 37 | europa --tmp 38 | ``` 39 | 40 | ## Install Redspot 41 | Redspot supports `npx`, so you don't have to install Redspot locally. 42 | To start your first Redspot project using Redspot built-in templates, check [Quick Start](./quick-start) 43 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/intro/overview.md: -------------------------------------------------------------------------------- 1 | # Overview​ 2 | Redspot is a development environment to compile, deploy, and debug wasm smart contract for substrate based chains. Redspot helps developers manage and automate the repeating steps during the process of writing smart contracts and dApps.Redspot is a development environment to compile, deploy, and debug wasm smart contract for substrate based chains. Similar to the architectures of Hardhat, Redspot is built upon Tasks and Plugins. 3 | 4 | ## Multi Languages Support 5 | Redspot currently supports compilation of Ink! and will support Ask! in the future. 6 | 7 | ## Tasks 8 | 9 | Every time you run Redspot from the terminal, you are running tasks. For example, executing the `npx redspot compile` command is to run the compilation task. To view the tasks currently available in the project, run the `npx redspot` command. You can view the help information of any task by running `npx redspot help [task]`. 10 | 11 | ## Plugins 12 | 13 | Redspot installs some plug-ins by default. As a developer, you're flexible to install any plugins, write new plugins and override existing plugins. 14 | 15 | ## More information 16 | Redspot developed from a hardhat fork based on the MIT protocol, and removed parts related to Ethereum on its basis, and added functions related to Substrate and pallet-contracts modules. In the near future, Redspot will build more functions based on the core of hardhat. -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/1.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/10.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/111.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/111.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/12.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/13.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/14.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/15.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/16.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/2.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/3.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/8.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/91.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/91.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/9png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/9png.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/gas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/image/gas.png -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/plugin.md: -------------------------------------------------------------------------------- 1 | # Plug-in 2 | 3 | ## What 4 | 5 | The core functions of Redspot include Redspot runtime environment, compiling contracts, running tests and running scripts. Other functions, such as the test suite with the contract, contract interaction, access to the contract, and configuration of different chains, are all provided by the plug-in, and you can choose the plug-ins according to your needs. 6 | 7 | ## Installation 8 | The way to introduce a plug-in is very simple, add it as a dependency of npm in `package.json`, and then add it in `redspot.config.ts`. The example is as follows. 9 | 10 | ```typescript 11 | import { RedspotUserConfig } from 'redspot/types'; 12 | import '@redspot/patract'; // introduce the @redspot/patract plugin 13 | import '@redspot/chai'; // import @redspot/chai plugin 14 | export default { 15 | ... 16 | } as RedspotUserConfig; 17 | ``` 18 | You can also manually install it, for example 19 | 20 | ```bash 21 | $ yarn add @redspot/chai 22 | ``` 23 | 24 | Add this to your `redspot.config.ts`: 25 | ```typescript 26 | import '@redspot/chai' 27 | ``` 28 | 29 | The following plug-ins are now included. 30 | 31 | * [@redspot/chai](./redspot-chai) 32 | * [@redspot/decimals](./redspot-decimals) 33 | * [@redspot/explorer](./redspot-explorer) 34 | * [@redspot/gas-reporter](./redspot-gas-reporter) 35 | * [@redspot/known-types](./redspot-known-types) 36 | * [@redspot/patract](./redspot-patract) 37 | 38 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/redspot-chai.md: -------------------------------------------------------------------------------- 1 | # @redspot_chai plug-in 2 | 3 | ## What 4 | 5 | The plug-in provides a set of matchers that are easy to write contract test cases, and the design is inspired by [waffle](https://ethereum-waffle.readthedocs.io/en/latest/matchers.html). 6 | 7 | ## Installation 8 | ```bash 9 | $ yarn add @redspot/chai 10 | ``` 11 | Add this to your `redspot.config.ts`: 12 | ```typescript 13 | import '@redspot/chai' 14 | ``` 15 | ## Usages: 16 | 17 | ### `equal` 18 | 19 | The @redspot/chai plug-in will modify the default equal matching method. The default equal does not support matching objects,but @redspot/chai plugin can. 20 | 21 | ```typescript 22 | expect(new BN(1000)).to.equal(1000); // true 23 | expect(AccountId).to.equal('5Gdjkw....'); // true 24 | expect(Uint8Array([1, 2, 3])).to.equal('0x010203'); // true 25 | ``` 26 | 27 | * For the BN type, equal will call `new BN(expected).eq(actual)` and judge whether it is equal. 28 | * For the types defined in Polkadot.js, equal will call `Type.eq(actual)` and judge whether they are equal. 29 | * For uint8Array type, equal will convert them to hexadecimal, and then judge whether they are equal. 30 | * For other types, the default judgment method is used to judge whether they are equal. 31 | 32 | ### `changeTokenBalance` 33 | 34 | The matcher can detect changes in the balance of erc20, and internally calls the balanceOf interface to determine the balance. Since the interface for obtaining balance of erc20-trait is `baseErc20, balanceOf`,`changeTokenBalance` is not applicable to erc20-trait. 35 | 36 | ```typescript 37 | await expect(() => 38 | contract.tx.transfer(receiver.address, 7) 39 | ).to.changeTokenBalance(contract, receiver, 7); 40 | await expect(() => 41 | contract.tx.transfer(receiver.address, 7) 42 | ).to.changeTokenBalances(contract, [contract.signer, receiver], [-7, 7]); 43 | ``` 44 | 45 | ### `emit` 46 | 47 | The matcher can detect whether the contract emits an event. Here is an example: 48 | 49 | * Detect whether a Transfer event is emitted 50 | ```typescript 51 | await expect(contract.tx.transfer(receiver.address, 7)).to.emit( 52 | contract, 53 | 'Transfer' 54 | ); 55 | ``` 56 | 57 | * Detect whether the event contains the specified parameters 58 | ```typescript 59 | await expect(contract.tx.transfer(receiver.address, 7)) 60 | .to.emit(contract, 'Transfer') 61 | .withArgs(sender.address, receiver.address, 7); 62 | ``` 63 | 64 | * Don't expect to emit events 65 | ```typescript 66 | await expect( 67 | contract.tx.transfer(sender.address, 7, { 68 | signer: emptyAccount 69 | }) 70 | ).to.not.emit(contract, 'Transfer'); 71 | ``` 72 | 73 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/redspot-decimals.md: -------------------------------------------------------------------------------- 1 | # @redspot_decimals plug-in 2 | 3 | ## What 4 | 5 | @redspot/decimals is a plug-in that can automatically convert number precision, for example, it can convert 1 DOT to 10000000000. 6 | 7 | Fixed decimal 8 | 9 | * `1 DOT`=>`10 ** 10` 10 | * `1 KSM`=>`10 ** 12` 11 | 12 | Obtain the tokenDecimal of the chain automatically 13 | 14 | * `1 UNIT`=>`10 ** tokenDecimal` 15 | 16 | ## Installation 17 | ```bash 18 | $ yarn add @redspot/decimals 19 | ``` 20 | Add this to your `redspot.config.ts`: 21 | ```typescript 22 | import '@redspot/decimals' 23 | ``` 24 | 25 | ## Usages 26 | 27 | * Used when deploying contracts 28 | ```typescript 29 | const contract = await contractFactory.deployed('new', '10000', { 30 | gasLimit: '400000000000', 31 | value: '10000 UNIT' 32 | }); 33 | ``` 34 | 35 | * Use in transfer 36 | ```typescript 37 | import { network } from 'redspot'; 38 | const { api } = network; 39 | async function run() { 40 | await api.isReady; 41 | api.tx.balances.transfer(address, '1 UNIT') 42 | } 43 | ``` 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/redspot-explorer.md: -------------------------------------------------------------------------------- 1 | # @redspot_explorer plug-in 2 | 3 | ## What 4 | 5 | The purpose of this plugin is to replace polkadot apps and canvas-ui during contract development. 6 | 7 | ## Installation 8 | 9 | ``` 10 | $ yarn add @redspot/explorer 11 | ``` 12 | Add this to your `redspot.config.ts`: 13 | ```typescript 14 | import "@redspot/explorer" 15 | ``` 16 | 17 | ## Usage 18 | Run edspot explorer. 19 | ```bash 20 | npx redspot explorer 21 | ``` 22 | 23 | **Note** When running redspot explorer, a service will be started locally, please do not terminate the process. And, every time redspot.config changes, please restart the service manually. 24 | 25 | Open the [default website](http://127.0.0.1:8011) 26 | 27 | For detailed usages, please refer [Redspot Explorer](../guides/explorer.md) -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/redspot-gas-reporter.md: -------------------------------------------------------------------------------- 1 | # @redspot_gas-reporter plug-in 2 | 3 | ## What 4 | 5 | The plug-in will print out the gas usage of the transaction of the called contract when the test is completed. 6 | 7 | ![](./image/gas.png) 8 | 9 | ## Installation 10 | ``` 11 | $ yarn add @redspot/gas-reporter 12 | ``` 13 | Add this to your `redspot.config.ts`: 14 | ```typescript 15 | import '@redspot/gas-reporter' 16 | ``` 17 | 18 | ## Usages 19 | 20 | Once you have imported this plugin in `redspot.config.ts`, it will automatically print out gas usage of the transaction of the called contract when the test is completed 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/plugin/redspot-known-types.md: -------------------------------------------------------------------------------- 1 | # @redspot_known-types plug-in 2 | 3 | ## What 4 | 5 | Redspot known types is a plug-in that can automatically add known types of chains. In polkadot, adding types is very troublesome, must be added manually, and cannot be automatically generated, and sometimes also has to deal with the compatibility of different chain versions. The appearance of the redspot known types plugin is to solve the problem of different types of chains. 6 | 7 | Most chains have submitted types on polkadot apps, and all types definitions are in the npm package `@polkadot/apps-config`. We will partially quote the types definitions in `@polkadot/apps-config`. But`@polkadot/apps-config` lacks the type definition of the development environment, we will manually supplement this part. Currently supported chains are Canvas, Jupiter, Europa, Edgeware, Plasm and Clover. 8 | 9 | ## Installation 10 | ``` 11 | $ yarn add @redspot/known-types 12 | ``` 13 | Add this to your `redspot.config.ts`: 14 | ```typescript 15 | import "@redspot/known-types" 16 | ``` 17 | 18 | ## Usages 19 | Try to connect to the network of Canvas, Jupiter, Europa and other chains without adding additional type configuration, `@redspot/known-types` will configure them automatically 20 | 21 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/redspot/reports/reports.md: -------------------------------------------------------------------------------- 1 | # Report for Redspot proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current Redspot proposal report has the following content: 8 | 9 | - [v0.1Report](./v0.1Report.md) 10 | - [v0.2Report](./v0.2Report.md) 11 | - [v0.3Report](./v0.3Report.md) 12 | - [v0.4Report](./v0.4Report.md) 13 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/solang/introduction.md: -------------------------------------------------------------------------------- 1 | # Solang 2 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/zkmega/contract.md: -------------------------------------------------------------------------------- 1 | # Contract 2 | 3 | > Currently we (Patract) support zkMega in testnet Jupiter ([https://github.com/patractlabs/jupiter](https://github.com/patractlabs/jupiter)) and contract debug 4 | > sandbox Europa ([https://github.com/patractlabs/europa](https://github.com/patractlabs/europa)). And any substrate based chain which uses `pallet-contracts` v3.0.0 could integrate zkMega. 5 | > 6 | > if the `pallet-contracts` Wasm contract chain use zkMega, then the following contract could run normally in those chain. 7 | 8 | ## Example 9 | 10 | TODO this example is wrong for current version! 11 | 12 | ```rust,ignore 13 | #![cfg_attr(not(feature = "std"), no_std)] 14 | 15 | #[ink::contract] 16 | mod altbn128 { 17 | use ink_env::zk_snarks::AltBn128; 18 | use ink_prelude::string::String; 19 | 20 | #[ink(storage)] 21 | pub struct Altbn128 { 22 | value: String, 23 | } 24 | 25 | impl Altbn128 { 26 | #[ink(constructor)] 27 | pub fn new(init_value: String) -> Self { 28 | Self { value: init_value } 29 | } 30 | 31 | #[ink(constructor)] 32 | pub fn default() -> Self { 33 | Self::new("hello, world".into()) 34 | } 35 | 36 | #[ink(message)] 37 | pub fn bn_256_add(&mut self) { 38 | let mut result = [0; 64]; 39 | ink_env::inflect_add::(&[], &[], &mut result); 40 | self.value = ink_prelude::format!("0x{:x?}", result); 41 | } 42 | 43 | #[ink(message)] 44 | pub fn get(&self) -> String { 45 | ink_prelude::format!("{}", &self.value) 46 | } 47 | } 48 | } 49 | ``` 50 | 51 | [paritytech/substrate]: https://github.com/paritytech/substrate.git 52 | [patractlabs/jupiter]: https://github.com/paritytech/jupiter.git 53 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/zkmega/example.md: -------------------------------------------------------------------------------- 1 | # Example 2 | 3 | ## Call curves in ink! 4 | 5 | | curve | add | mul | pairing | 6 | |------------|------------|------------|------------| 7 | | bls12\_377 | 0x01000000 | 0x01000001 | 0x01000002 | 8 | | bls12\_381 | 0x01000010 | 0x01000011 | 0x01000012 | 9 | | bn254 | 0x01000020 | 0x01000021 | 0x01000022 | 10 | | bw6\_761 | 0x01000030 | 0x01000031 | 0x01000032 | 11 | 12 | ```rust 13 | let result = ink_env::call_chain_extension(func_id, &Vec::from(input))? 14 | ``` 15 | 16 | 17 | ## MIMC 18 | 19 | ```rust 20 | use zkp_u256::{U256, Zero}; 21 | use merkle_tree::mimc::{mimc,mimc_with_key} 22 | let message = U256::from_decimal_str("49").unwrap(); 23 | let in_key = U256::zero(); 24 | assert_eq!( 25 | mimc(b"1"), 26 | mimc_with_key(vec![&message], &in_key) 27 | ); 28 | ``` 29 | 30 | 31 | ## Merkle Tree 32 | 33 | ```rust 34 | use merkle_tree::MerkleTree; 35 | let mut mt = MerkleTree::default(); 36 | let message = b"49"; 37 | let (leaf, index) = mt.insert(message).unwrap(); 38 | assert_eq!(mt.update(), mt.get_root()); 39 | let merkle_proof = mt.get_proof(index); 40 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 41 | 42 | let message = b"50"; 43 | let (leaf, index) = mt.insert(message).unwrap(); 44 | assert_eq!(mt.update(), mt.get_root()); 45 | let merkle_proof = mt.get_proof(index); 46 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 47 | 48 | let message = b"51"; 49 | let (leaf, index) = mt.insert(message).unwrap(); 50 | assert_eq!(mt.update(), mt.get_root()); 51 | let merkle_proof = mt.get_proof(index); 52 | assert!(mt.verify_merkle_proof(leaf, merkle_proof, index)); 53 | ``` 54 | 55 | ## EDDSA 56 | 57 | > TODO 58 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/zkmega/metis.md: -------------------------------------------------------------------------------- 1 | # Metis 2 | 3 | > TODO 4 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/zkmega/reports.md: -------------------------------------------------------------------------------- 1 | # Report for zkMega proposals 2 | 3 | The proposal report is a document submitted for review at the end of the reporting stage after Patract submitted an application to Polkdaot/Kusama Finance. Each issue of the document covers the design ideas and main content completed in this proposal. 4 | 5 | The report represents the work results of the Patract team this time, and it is also a good reference document. 6 | 7 | The current zkMega proposal report has the following content: 8 | 9 | - [v0.1Report](./reports/v0.1Report.md) 10 | - [v0.2Report](./reports/v0.2Report.md) 11 | 12 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-plugin-content-docs/current/zkmega/tutorial.md: -------------------------------------------------------------------------------- 1 | # tutorial 2 | 3 | ## The chain based on Substrate introduces  zkMega's zero-knowledge primitives 4 | 5 | The chain integration zkMega with `pallet-contracts` can refer to Jupiter's integration method: [https://github.com/patractlabs/jupiter/blob/master/primitives/chain-extension/src/lib.rs](https:/ /github.com/patractlabs/jupiter/blob/master/primitives/chain-extension/src/lib.rs) 6 | 7 | The main steps are mainly divided into the following steps: 8 | 9 | 1. Design a structure implemented in `ChainExtension` 10 | 2. Determine the range of `func_id` in the implementation of `call` of `ChainExtension`, according to [PIP-101](https://github.com/patractlabs/PIPs/blob/main/PIPs/pip-101.md ), the current range required to use zkMega is `0x01000000..=0x010000ff`. Therefore, it can be introduced in the implementation: 11 | 12 | ```rust 13 | match func_id { 14 | // 0x01000000-0x010000ff Patract ZKP Support 15 | 0x01000000..=0x010000ff => { 16 | 17 | } 18 | } 19 | ``` 20 | 21 | 3. Then introduce the gas billing method in the code block of `0x01000000..=0x010000ff`. Different chains may design different billing methods for the methods called by zkMega. In Jupiter's case, only the simplest way to design a fixed consumption of gas: 22 | 23 | ```rust 24 | let simple_weight = match func_id & 0x01 { 25 | 0 => 100_000, // add, In ethereum: 500 26 | 1 => 8_000_000, // 80x then add, In ethereum: 40000 27 | 2 => {/* ...*/ } 28 | _ => return Err(DispatchError::Other("Unimplemented Patract ZKP func_id")); 29 | }; 30 | env.charge_weight(simple_weight)?; 31 | ``` 32 | 33 | 4. Implement different implementations according to whether the chain itself needs Native call or Wasm call: 34 | 35 | For example, if the chain only wants to support Wasm calls, use the following method: 36 | 37 | ```rust 38 | zkmega_arkworks::call(&func_id, &input); 39 | ``` 40 | 41 | If the chain wants to execute the call on Native, it can be similar to Jupiter, design `runtime_inferface` to wrap the call of `zkmega_arkworks::call`, and put the call process under std to compile. Then call the method exported by `runtime_interface` in the implementation of `ChainExtensions`. 42 | 43 | ## The interface for calling zkMega's zero-knowledge primitives in the contract 44 | 45 | It is relatively simple to use zkMega in the contract. First introduce `megaclite-arkworks` in contract dependencies 46 | 47 | ```toml 48 | [dependencies] 49 | megaclite-arkworks = { git = "https://github.com/patractlabs/zkmega", features = [ "ink" ], default-features = false } 50 | ``` 51 | 52 | Please note that you need to use the `ink` feature when importing the zkMega library. 53 | 54 | Then you can use the methods provided by zkMega in the contract: 55 | 56 | ```rust 57 | megaclite_arkworks::verify(...); 58 | ``` 59 | 60 | If it is a relatively low-level call, you can call it directly through `call`: 61 | 62 | ```rust 63 | let func_id = /*id defined in PIP-101*/ 64 | megaclite_arkworks::verify(func_id, ...); 65 | ``` 66 | -------------------------------------------------------------------------------- /i18n/en/docusaurus-theme-classic/navbar.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": { 3 | "message": "My Site", 4 | "description": "The title in the navbar" 5 | }, 6 | "item.label.GitHub": { 7 | "message": "GitHub", 8 | "description": "Navbar item with label GitHub" 9 | }, 10 | "item.label.主页": { 11 | "message": "Home", 12 | "description": "Navbar item with label 主页" 13 | }, 14 | "item.label.博客": { 15 | "message": "Blog", 16 | "description": "Navbar item with label 博客" 17 | } 18 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "substrate-contracts-book", 3 | "version": "1.0.0", 4 | "description": "Substrate Contracts Book", 5 | "main": "index.js", 6 | "repository": "https://github.com/patractlabs/substrate-contracts-book.git", 7 | "author": "patractlabs", 8 | "license": "MIT", 9 | "scripts": { 10 | "docusaurus": "docusaurus", 11 | "start": "docusaurus start", 12 | "build": "docusaurus build", 13 | "build:gh_pages": "BASE_PATH=/substrate-contracts-book/ docusaurus build", 14 | "swizzle": "docusaurus swizzle", 15 | "deploy": "docusaurus deploy", 16 | "clear": "docusaurus clear", 17 | "serve": "docusaurus serve", 18 | "write-translations": "docusaurus write-translations", 19 | "write-heading-ids": "docusaurus write-heading-ids" 20 | }, 21 | "dependencies": { 22 | "@docusaurus/core": "2.0.0-beta.4", 23 | "@docusaurus/preset-classic": "2.0.0-beta.4", 24 | "@mdx-js/react": "^1.6.21", 25 | "@svgr/webpack": "^5.5.0", 26 | "clsx": "^1.1.1", 27 | "file-loader": "^6.2.0", 28 | "react": "^17.0.1", 29 | "react-dom": "^17.0.1", 30 | "url-loader": "^4.1.1" 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | }, 44 | "devDependencies": { 45 | "@docusaurus/module-type-aliases": "^2.0.0-beta.4", 46 | "@tsconfig/docusaurus": "^1.0.2", 47 | "@types/react": "^17.0.15", 48 | "@types/react-helmet": "^6.1.2", 49 | "@types/react-router-dom": "^5.1.8", 50 | "typescript": "^4.3.5" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/css/custom.css: -------------------------------------------------------------------------------- 1 | :root { 2 | --ifm-color-primary: #ff3043; 3 | --ifm-color-primary-dark: #ff1227; 4 | --ifm-color-primary-darker: #ff031a; 5 | --ifm-color-primary-darkest: #d40013; 6 | --ifm-color-primary-light: #ff4e5f; 7 | --ifm-color-primary-lighter: #ff5d6c; 8 | --ifm-color-primary-lightest: #ff8b96; 9 | --ifm-code-font-size: 90%; 10 | --ifm-font-family-base: "-apple-system", BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 11 | --ifm-heading-font-weight: 400; 12 | --ifm-global-shadow-lw: transparent; 13 | --ifm-toc-border-color: transparent; 14 | } 15 | -------------------------------------------------------------------------------- /static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/static/.nojekyll -------------------------------------------------------------------------------- /static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/patractlabs/substrate-contracts-book/5e4fc4e4ff8a33c546add86a262d6cbf3f8e2a81/static/img/favicon.png -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/docusaurus/tsconfig.json", 3 | "include": ["src/"] 4 | } 5 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "github": { 4 | "enabled": false 5 | } 6 | } 7 | --------------------------------------------------------------------------------