├── .dockerignore ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── pull_request_template.md ├── actions │ └── install_toolchain │ │ └── action.yml └── workflows │ ├── check.yml │ ├── compile-check.yml │ ├── docker-build-push.yml │ ├── e2e-docker-build-push.yml │ ├── pr.yml │ ├── release.yml │ ├── tangle-e2e-docker-build-push.yml │ └── test.yml ├── .gitignore ├── .release-please-manifest.json ├── Cargo.lock ├── Cargo.toml ├── Dockerfile ├── Dockerfile_e2e ├── Dockerfile_subbridge_e2e ├── Dockerfile_tangle_standalone_e2e ├── Dockerfile_xcm_e2e ├── LICENSE ├── Makefile ├── README.md ├── access-segregator ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── benchmarking.rs │ ├── lib.rs │ ├── mock.rs │ └── weights.rs ├── basic-fee-handler ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── benchmarking.rs │ ├── lib.rs │ ├── mock.rs │ └── weights.rs ├── bridge-forwarder ├── Cargo.toml └── src │ ├── lib.rs │ ├── mock.rs │ └── xcm_asset_transactor.rs ├── bridge ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── benchmarking.rs │ ├── eip712.rs │ ├── encode.rs │ ├── lib.rs │ ├── migration.rs │ ├── mock.rs │ └── weights.rs ├── deny.toml ├── diagram.png ├── docs ├── Fees.md ├── Home.md └── resources │ └── dynamic-fees-substrate.png ├── dynamic-fee-handler └── .keep ├── fee-handler-router ├── CHANGELOG.md ├── Cargo.toml └── src │ ├── benchmarking.rs │ ├── lib.rs │ ├── mock.rs │ └── weights.rs ├── parachain-info ├── Cargo.toml └── src │ └── lib.rs ├── percentage-fee-handler ├── Cargo.toml └── src │ ├── benchmarking.rs │ ├── lib.rs │ ├── mock.rs │ └── weights.rs ├── release-please-config.json ├── rpc ├── CHANGELOG.md ├── Cargo.toml └── src │ └── lib.rs ├── runtime-api ├── CHANGELOG.md ├── Cargo.toml └── src │ └── lib.rs ├── rust-toolchain ├── rustfmt.toml ├── scripts ├── e2e_setup.sh ├── header.txt ├── phala-subbridge │ ├── e2e_setup.sh │ └── khala-e2e.config.json ├── standalone │ ├── execute_proposal_test.js │ ├── package.json │ ├── setup.js │ └── util.js ├── tangle │ └── e2e_setup.sh ├── xcm │ ├── e2e_tests.js │ ├── package.json │ ├── setup.js │ └── util.js └── xcm_e2e_setup.sh ├── substrate-node ├── parachain │ ├── node │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ │ ├── chain_spec.rs │ │ │ ├── cli.rs │ │ │ ├── command.rs │ │ │ ├── main.rs │ │ │ ├── rpc.rs │ │ │ └── service.rs │ └── runtime │ │ ├── Cargo.toml │ │ ├── build.rs │ │ └── src │ │ ├── lib.rs │ │ ├── weights │ │ ├── block_weights.rs │ │ ├── extrinsic_weights.rs │ │ ├── mod.rs │ │ ├── paritydb_weights.rs │ │ └── rocksdb_weights.rs │ │ └── xcm_config.rs └── standalone │ ├── node │ ├── Cargo.toml │ ├── build.rs │ └── src │ │ ├── benchmarking.rs │ │ ├── chain_spec.rs │ │ ├── cli.rs │ │ ├── command.rs │ │ ├── main.rs │ │ ├── rpc.rs │ │ └── service.rs │ └── runtime │ ├── Cargo.toml │ ├── build.rs │ └── src │ └── lib.rs ├── traits ├── CHANGELOG.md ├── Cargo.toml └── src │ └── lib.rs ├── xcm-bridge ├── Cargo.toml └── src │ ├── lib.rs │ └── mock │ ├── mod.rs │ ├── para.rs │ └── relay.rs └── zombienet ├── bridge_hub_rococo_local_network.toml ├── local_zombienet.toml └── scripts └── zombienet_prepare.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | **/target 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | indent_style=tab 4 | indent_size=tab 5 | tab_width=4 6 | end_of_line=lf 7 | charset=utf-8 8 | trim_trailing_whitespace=true 9 | max_line_length=100 10 | insert_final_newline=true 11 | 12 | [*.md] 13 | max_line_length=80 14 | indent_style=space 15 | indent_size=2 16 | 17 | [*.yml] 18 | indent_style=space 19 | indent_size=2 20 | tab_width=8 21 | end_of_line=lf 22 | 23 | [*.sh] 24 | indent_style=space 25 | indent_size=2 26 | tab_width=8 27 | end_of_line=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | 9 | 10 | 11 | 12 | ## Short Context 13 | 14 | 15 | 16 | ## Preconditions 17 | 22 | 1. 23 | 2. 24 | 25 | ## Steps to Reproduce 26 | 27 | 28 | 29 | 33 | 1. 34 | 2. 35 | 3. 36 | 4. 37 | 38 | ## Expected Behavior 39 | 40 | 41 | 42 | 43 | ## Actual Behavior 44 | 45 | 46 | 47 | 48 | ## Possible Solution (optional) 49 | 50 | 51 | 52 | 53 | ## Version 54 | 55 | Sygma commit (or docker tag): 56 | sygma-solidity version: 57 | sygma-substrate version: 58 | Go version: -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | 7 | ## Related Issue Or Context 8 | 9 | 10 | 11 | 12 | 13 | Closes: # 14 | 15 | ## How Has This Been Tested? Testing details. 16 | 17 | 18 | 19 | 20 | 21 | ## Types of changes 22 | 23 | 24 | 25 | - [ ] Bug fix (non-breaking change which fixes an issue) 26 | - [ ] New feature (non-breaking change which adds functionality) 27 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 28 | - [ ] Documentation 29 | 30 | ## Checklist: 31 | 32 | 33 | 34 | 35 | - [ ] I have commented my code, particularly in hard-to-understand areas. 36 | - [ ] I have ensured that all acceptance criteria (or expected behavior) from issue are met 37 | - [ ] I have updated the documentation locally and in sygma-docs. 38 | - [ ] I have added tests to cover my changes. 39 | - [ ] I have ensured that all the checks are passing and green, I've signed the CLA bot -------------------------------------------------------------------------------- /.github/actions/install_toolchain/action.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: "Install toolchains" 5 | description: "Install toolchains" 6 | runs: 7 | using: "composite" 8 | steps: 9 | - name: Install latest nightly 10 | uses: actions-rs/toolchain@v1 11 | with: 12 | toolchain: 1.79.0 13 | override: true 14 | target: wasm32-unknown-unknown 15 | components: rustfmt 16 | - run: sudo apt update && sudo apt-get install build-essential cmake pkg-config libssl-dev git llvm clang libclang-dev protobuf-compiler -y 17 | shell: bash 18 | -------------------------------------------------------------------------------- /.github/workflows/check.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Format, linter, license check 5 | 6 | on: 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | CARGO_TERM_COLOR: always 16 | 17 | jobs: 18 | cargo-fmt: 19 | name: Run cargo fmt 20 | runs-on: ubuntu-20.04 21 | steps: 22 | - uses: actions/checkout@v3 23 | with: 24 | submodules: "true" 25 | - uses: ./.github/actions/install_toolchain 26 | - name: Install rustfmt 27 | run: rustup component add rustfmt 28 | - name: Run cargo fmt 29 | run: cargo fmt --all -- --check 30 | 31 | cargo-clippy: 32 | name: Run cargo clippy 33 | runs-on: ubuntu-20.04 34 | steps: 35 | - uses: actions/checkout@v3 36 | with: 37 | submodules: "true" 38 | - uses: ./.github/actions/install_toolchain 39 | - name: Install clippy 40 | run: rustup component add clippy 41 | - name: Run cargo clippy for pallets 42 | run: cargo clippy --all-targets -- -D warnings 43 | 44 | cargo-deny: 45 | name: Run cargo deny check licenses 46 | runs-on: ubuntu-20.04 47 | steps: 48 | - uses: actions/checkout@v3 49 | with: 50 | submodules: "true" 51 | - uses: ./.github/actions/install_toolchain 52 | - name: Install cargo deny 53 | run: cargo install --locked cargo-deny 54 | - name: Run cargo deny checks for pallets 55 | run: cargo-deny check licenses 56 | 57 | 58 | -------------------------------------------------------------------------------- /.github/workflows/compile-check.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Compile check 5 | 6 | on: 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | push: 10 | branches: 11 | - main 12 | 13 | concurrency: 14 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 15 | cancel-in-progress: true 16 | 17 | env: 18 | CARGO_TERM_COLOR: always 19 | 20 | jobs: 21 | cargo-check: 22 | name: Run cargo check for compile 23 | runs-on: ubuntu-20.04 24 | steps: 25 | - uses: actions/checkout@v3 26 | with: 27 | submodules: "true" 28 | - uses: ./.github/actions/install_toolchain 29 | - name: Run cargo check 30 | run: cargo check 31 | -------------------------------------------------------------------------------- /.github/workflows/docker-build-push.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Build and publish Docker image 5 | 6 | on: 7 | release: 8 | types: [published] 9 | 10 | env: 11 | REGISTRY: ghcr.io 12 | IMAGE_NAME: ${{ github.repository }} 13 | 14 | jobs: 15 | push_to_registry: 16 | name: Push Docker image to GitHub Container Registry 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Check out the repo 20 | uses: actions/checkout@v3 21 | 22 | - name: Prepare 23 | id: prep 24 | run: | 25 | # creates local variable of docker image 26 | 27 | # creates local variable of commit hash that triggered workflow 28 | COMMIT_HASH=$(echo $GITHUB_SHA | head -c7) 29 | 30 | # creates local variable to hold docker images 31 | TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${COMMIT_HASH},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" 32 | 33 | # check if branch/tag that triggered workflow was from tags 34 | if [[ $GITHUB_REF == refs/tags/* ]]; then 35 | 36 | # set version 37 | VERSION=${GITHUB_REF#refs/tags/} 38 | 39 | # append version to tags 40 | TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${VERSION}" 41 | 42 | fi 43 | 44 | # sets output of step 45 | echo ::set-output name=tags::${TAGS} 46 | 47 | - name: Set up QEMU 48 | uses: docker/setup-qemu-action@v2 49 | 50 | - name: Set up Docker Buildx 51 | uses: docker/setup-buildx-action@v2 52 | 53 | - name: Log in to Docker Hub 54 | uses: docker/login-action@v2 55 | with: 56 | registry: ${{ env.REGISTRY }} 57 | username: ${{ github.actor }} 58 | password: ${{ secrets.GITHUB_TOKEN }} 59 | 60 | - name: Build and push 61 | id: docker_build 62 | uses: docker/build-push-action@v3 63 | with: 64 | context: . 65 | push: true 66 | tags: ${{ steps.prep.outputs.tags }} 67 | 68 | - name: Image digest 69 | run: echo ${{ steps.docker_build.outputs.digest }} 70 | -------------------------------------------------------------------------------- /.github/workflows/e2e-docker-build-push.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Build and publish E2E Docker image 5 | 6 | on: 7 | push: 8 | branches: 9 | - main 10 | 11 | env: 12 | REGISTRY: ghcr.io 13 | IMAGE_NAME: ${{ github.repository }} 14 | 15 | jobs: 16 | push_e2e_to_registry: 17 | name: Push E2E Docker image to GitHub Container Registry 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Check out the repo 21 | uses: actions/checkout@v3 22 | with: 23 | submodules: "true" 24 | - uses: ./.github/actions/install_toolchain 25 | 26 | - name: Prepare 27 | id: prep 28 | run: | 29 | # creates local variable of docker image 30 | 31 | # creates local variable of commit hash that triggered workflow 32 | COMMIT_HASH=$(echo $GITHUB_SHA | head -c7) 33 | 34 | # creates local variable to hold docker images 35 | TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${COMMIT_HASH},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:e2e-latest" 36 | 37 | # check if branch/tag that triggered workflow was from tags 38 | if [[ $GITHUB_REF == refs/tags/* ]]; then 39 | 40 | # set version 41 | VERSION=${GITHUB_REF#refs/tags/} 42 | 43 | # append version and e2e testing name to tags 44 | TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:e2e-${VERSION}" 45 | 46 | fi 47 | 48 | # sets output of step 49 | echo ::set-output name=tags::${TAGS} 50 | 51 | - name: Set up QEMU 52 | uses: docker/setup-qemu-action@v2 53 | 54 | - name: Set up Docker Buildx 55 | uses: docker/setup-buildx-action@v2 56 | 57 | - name: Log in to Docker Hub 58 | uses: docker/login-action@v2 59 | with: 60 | registry: ${{ env.REGISTRY }} 61 | username: ${{ github.actor }} 62 | password: ${{ secrets.GITHUB_TOKEN }} 63 | 64 | - name: Build and push 65 | id: docker_build 66 | uses: docker/build-push-action@v3 67 | with: 68 | context: . 69 | push: true 70 | file: ./Dockerfile_e2e 71 | build-args: mpc_address=${{ env.MPCADDR }} 72 | tags: ${{ steps.prep.outputs.tags }} 73 | 74 | - name: Image digest 75 | run: echo ${{ steps.docker_build.outputs.digest }} 76 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | on: [pull_request] 5 | name: "Semantic PR" 6 | 7 | jobs: 8 | validation: 9 | name: Validate PR title 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: amannn/action-semantic-pull-request@v4 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 15 | with: 16 | types: | 17 | fix 18 | feat 19 | chore 20 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Create Sygma substrate pallet release 5 | 6 | on: 7 | push: 8 | branches: 9 | - main 10 | jobs: 11 | release-please: 12 | name: release 13 | runs-on: ubuntu-latest 14 | if: github.event_name == 'push' && github.ref == 'refs/heads/main' 15 | steps: 16 | 17 | - uses: actions/checkout@v2 18 | - uses: google-github-actions/release-please-action@v3 19 | id: release 20 | with: 21 | token: ${{ secrets.RELEASE_TOKEN }} 22 | command: manifest 23 | default-branch: main 24 | -------------------------------------------------------------------------------- /.github/workflows/tangle-e2e-docker-build-push.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Build and publish E2E Docker image with Tangle standalone chain node 5 | 6 | on: 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | 10 | env: 11 | REGISTRY: ghcr.io 12 | IMAGE_NAME: ${{ github.repository }} 13 | 14 | jobs: 15 | push_e2e_to_registry: 16 | name: Push E2E Docker image with Tangle standalone chain node to GitHub Container Registry 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Check out the repo 20 | uses: actions/checkout@v3 21 | with: 22 | submodules: "true" 23 | - uses: ./.github/actions/install_toolchain 24 | 25 | - name: Prepare 26 | id: prep 27 | run: | 28 | # creates local variable of docker image 29 | 30 | # creates local variable of commit hash that triggered workflow 31 | COMMIT_HASH=$(echo $GITHUB_SHA | head -c7) 32 | 33 | # creates local variable to hold docker images 34 | TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${COMMIT_HASH},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:e2e-latest" 35 | 36 | # check if branch/tag that triggered workflow was from tags 37 | if [[ $GITHUB_REF == refs/tags/* ]]; then 38 | 39 | # set version 40 | VERSION=${GITHUB_REF#refs/tags/} 41 | 42 | # append version and e2e testing name to tags 43 | TAGS="${TAGS},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:e2e-${VERSION}" 44 | 45 | fi 46 | 47 | # sets output of step 48 | echo ::set-output name=tags::${TAGS} 49 | 50 | - name: Remove unnecessary files 51 | run: | 52 | sudo rm -rf /usr/share/dotnet 53 | sudo rm -rf "$AGENT_TOOLSDIRECTORY" 54 | 55 | - name: Set up QEMU 56 | uses: docker/setup-qemu-action@v2 57 | 58 | - name: Set up Docker Buildx 59 | uses: docker/setup-buildx-action@v2 60 | 61 | - name: Log in to Docker Hub 62 | uses: docker/login-action@v2 63 | with: 64 | registry: ${{ env.REGISTRY }} 65 | username: ${{ github.actor }} 66 | password: ${{ secrets.GITHUB_TOKEN }} 67 | 68 | - name: Build and push 69 | id: docker_build 70 | uses: docker/build-push-action@v3 71 | with: 72 | context: . 73 | push: true 74 | file: ./Dockerfile_tangle_standalone_e2e 75 | build-args: mpc_address=${{ env.MPCADDR }} 76 | tags: ${{ steps.prep.outputs.tags }} 77 | 78 | - name: Image digest 79 | run: echo ${{ steps.docker_build.outputs.digest }} 80 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | name: Test 5 | 6 | on: 7 | pull_request: 8 | types: [opened, synchronize, reopened] 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} 12 | cancel-in-progress: true 13 | 14 | env: 15 | CARGO_TERM_COLOR: always 16 | 17 | jobs: 18 | cargo-test: 19 | name: Run cargo test 20 | runs-on: ubuntu-22.04 21 | steps: 22 | - name: Maximize build space 23 | uses: easimon/maximize-build-space@master # https://github.com/easimon/maximize-build-space 24 | with: 25 | root-reserve-mb: 4096 26 | temp-reserve-mb: 1024 27 | swap-size-mb: 8192 28 | remove-dotnet: "true" 29 | remove-android: "true" 30 | remove-haskell: "true" 31 | - uses: actions/checkout@v3 32 | with: 33 | submodules: "true" 34 | - uses: ./.github/actions/install_toolchain 35 | - name: Run cargo test 36 | uses: actions-rs/cargo@v1 37 | with: 38 | command: test 39 | args: --workspace 40 | - name: Show disk usage 41 | if: always() 42 | run: df -h 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | **/node_modules 4 | **/package-lock.json 5 | 6 | /target 7 | /db 8 | *.log 9 | chain-spec.json 10 | 11 | .idea 12 | 13 | .env 14 | 15 | polkadot 16 | polkadot-execute-worker 17 | polkadot-prepare-worker 18 | zombienet 19 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | {"access-segregator":"0.2.0","basic-fee-handler":"0.3.0","bridge":"0.3.0","fee-handler-router":"0.3.0","rpc":"0.2.1","runtime-api":"0.2.1","traits":"0.2.0","substrate-node/node":"4.0.3-dev","substrate-node/runtime":"4.0.3-dev"} 2 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | 4 | members = [ 5 | "access-segregator", 6 | "basic-fee-handler", 7 | "percentage-fee-handler", 8 | "bridge", 9 | "fee-handler-router", 10 | "traits", 11 | "runtime-api", 12 | "rpc", 13 | "substrate-node/parachain/node", 14 | "substrate-node/parachain/runtime", 15 | "substrate-node/standalone/node", 16 | "substrate-node/standalone/runtime", 17 | "parachain-info", 18 | "bridge-forwarder", 19 | "xcm-bridge" 20 | ] 21 | 22 | exclude = [ 23 | 24 | ] 25 | 26 | [profile.release] 27 | panic = "unwind" 28 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | FROM --platform=linux/amd64 paritytech/ci-linux:production as builder 5 | 6 | WORKDIR /code 7 | COPY . . 8 | RUN cargo build --release 9 | 10 | FROM --platform=linux/amd64 ubuntu:20.04 11 | WORKDIR /node 12 | 13 | # Copy the node binary. 14 | COPY --from=builder /code/target/release/standalone-node-template . 15 | 16 | # Install root certs, see: https://github.com/paritytech/substrate/issues/9984 17 | RUN apt update && \ 18 | apt install -y ca-certificates && \ 19 | update-ca-certificates && \ 20 | apt remove ca-certificates -y && \ 21 | rm -rf /var/lib/apt/lists/* 22 | 23 | # JSON-RPC WS server 24 | EXPOSE 9944 25 | # JSON-RPC HTTP server 26 | EXPOSE 9933 27 | 28 | ENTRYPOINT ["./standalone-node-template"] -------------------------------------------------------------------------------- /Dockerfile_e2e: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | FROM --platform=linux/amd64 paritytech/ci-linux:production as builder 5 | 6 | WORKDIR /code 7 | COPY . . 8 | RUN cargo build --release 9 | 10 | FROM --platform=linux/amd64 node:18.14.2 11 | WORKDIR /node 12 | 13 | # Copy the node binary. 14 | COPY --from=builder /code/target/release/standalone-node-template . 15 | 16 | # setup and launch script 17 | COPY --from=builder /code/scripts/ ./scripts 18 | RUN chmod +x ./scripts/e2e_setup.sh 19 | 20 | # Install root certs, see: https://github.com/paritytech/substrate/issues/9984 21 | RUN apt update && \ 22 | apt install -y ca-certificates && \ 23 | update-ca-certificates && \ 24 | apt remove ca-certificates -y && \ 25 | rm -rf /var/lib/apt/lists/* 26 | 27 | # JSON-RPC WS server 28 | EXPOSE 9944 29 | # JSON-RPC HTTP server 30 | EXPOSE 9933 31 | 32 | ARG mpc_address 33 | ENV MPCADDR $mpc_address 34 | 35 | RUN ["./scripts/e2e_setup.sh"] 36 | 37 | ENTRYPOINT ["./standalone-node-template", "--dev", "--rpc-external", "--base-path", "./db/"] 38 | -------------------------------------------------------------------------------- /Dockerfile_subbridge_e2e: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | FROM --platform=linux/amd64 paritytech/ci-linux:production as builder 5 | 6 | WORKDIR /code 7 | 8 | COPY ./scripts/phala-subbridge/khala-e2e.config.json . 9 | 10 | # build khala-parachain 11 | RUN git clone https://github.com/Phala-Network/khala-parachain.git ./khala-parachain 12 | WORKDIR /code/khala-parachain 13 | RUN git checkout main 14 | RUN cargo build --release --features=all-runtimes 15 | RUN cp ./target/release/khala-node ./polkadot-launch/bin/ 16 | 17 | # grab the prebuild polkadot relay chain binary 18 | WORKDIR /code 19 | RUN apt-get update \ 20 | && apt-get install -y wget 21 | RUN wget https://github.com/paritytech/polkadot/releases/download/v0.9.37/polkadot 22 | RUN mv polkadot ./khala-parachain/polkadot-launch/bin/ 23 | 24 | # grant execution permission 25 | RUN chmod +x ./khala-parachain/polkadot-launch/bin/polkadot 26 | RUN chmod +x ./khala-parachain/polkadot-launch/bin/khala-node 27 | 28 | # copy the config file 29 | RUN mv khala-e2e.config.json ./khala-parachain/polkadot-launch/ 30 | 31 | FROM --platform=linux/amd64 node:18.14.2 32 | 33 | WORKDIR /node 34 | 35 | COPY --from=builder /code/khala-parachain/polkadot-launch ./polkadot-launch/ 36 | COPY --from=builder /code/khala-parachain/scripts/js/setup_sygma.js ./polkadot-launch/scripts/ 37 | COPY --from=builder /code/khala-parachain/scripts/js/package.json ./polkadot-launch/scripts/ 38 | 39 | # yarn install 40 | WORKDIR /node/polkadot-launch 41 | RUN yarn 42 | 43 | # setup and launch 44 | WORKDIR /node/polkadot-launch/scripts 45 | COPY scripts/phala-subbridge/e2e_setup.sh . 46 | RUN chmod +x ./e2e_setup.sh 47 | 48 | WORKDIR /node/polkadot-launch 49 | 50 | # JSON-RPC WS server 51 | EXPOSE 9944 52 | # JSON-RPC HTTP server 53 | EXPOSE 9933 54 | 55 | RUN ["./scripts/e2e_setup.sh"] 56 | 57 | ENTRYPOINT ["yarn", "start", "khala-e2e.config.json"] 58 | 59 | -------------------------------------------------------------------------------- /Dockerfile_tangle_standalone_e2e: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | FROM --platform=linux/amd64 paritytech/ci-linux:production as builder 5 | 6 | WORKDIR /code 7 | 8 | COPY ./scripts/tangle . 9 | 10 | # build 11 | RUN git clone https://github.com/webb-tools/tangle.git ./tangle 12 | WORKDIR /code/tangle 13 | RUN git checkout sygma/polkadot-version-upgrade 14 | RUN cargo build --release --features testnet 15 | 16 | FROM --platform=linux/amd64 node:18.14.2 17 | WORKDIR /tangle 18 | 19 | RUN apt update && apt install lsof 20 | 21 | # Copy the node binary. 22 | # /tangle/scripts 23 | # /tangle/target/release/tangle 24 | # /tangle/.git 25 | COPY --from=builder /code/tangle/scripts ./scripts 26 | COPY --from=builder /code/tangle/target/release/tangle ./target/release/tangle 27 | COPY --from=builder /code/tangle/.git ./.git 28 | 29 | # /tangle/e2e_setup.sh 30 | COPY --from=builder /code/e2e_setup.sh . 31 | RUN chmod +x ./e2e_setup.sh 32 | 33 | # Install root certs, see: https://github.com/paritytech/substrate/issues/9984 34 | RUN apt update && \ 35 | apt install -y ca-certificates && \ 36 | update-ca-certificates && \ 37 | apt remove ca-certificates -y && \ 38 | rm -rf /var/lib/apt/lists/* 39 | 40 | # JSON-RPC WS server 41 | EXPOSE 9944 42 | # JSON-RPC HTTP server 43 | EXPOSE 9933 44 | 45 | ARG mpc_address 46 | ENV MPCADDR $mpc_address 47 | 48 | WORKDIR /tangle 49 | RUN ["./e2e_setup.sh"] 50 | 51 | ENTRYPOINT ["./scripts/run-standalone-local.sh"] 52 | -------------------------------------------------------------------------------- /Dockerfile_xcm_e2e: -------------------------------------------------------------------------------- 1 | # The Licensed Work is (c) 2022 Sygma 2 | # SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | FROM --platform=linux/amd64 paritytech/ci-linux:production as builder 5 | 6 | WORKDIR /code 7 | 8 | # git config setup 9 | RUN git config --global http.postBuffer 1048576000 10 | RUN git config --global https.postBuffer 1048576000 11 | RUN git config --global http.sslBackend gnutls 12 | 13 | # clone polkadot-sdk with demo integration branch 14 | # this demo integration branch is based on v1.2.0 of polkadot-sdk 15 | RUN git clone https://github.com/freddyli7/polkadot-sdk.git ./polkadot-sdk 16 | WORKDIR /code/polkadot-sdk 17 | RUN git checkout sygma/pallets-integration 18 | 19 | WORKDIR /code 20 | 21 | # download zombienet binary 22 | RUN apt-get update \ 23 | && apt-get install -y wget 24 | RUN wget https://github.com/paritytech/zombienet/releases/download/v1.3.94/zombienet-linux-x64 25 | RUN mv zombienet-linux-x64 ./polkadot-sdk/local-test/zombienet 26 | RUN chmod +x ./polkadot-sdk/local-test/zombienet 27 | 28 | # install rust toolchain 29 | RUN rustup toolchain install 1.74.0 30 | RUN rustup default 1.74.0 31 | RUN rustc --version 32 | RUN rustup target add wasm32-unknown-unknown --toolchain 1.74.0 33 | 34 | # build the polkdaot binary and parachain binary 35 | WORKDIR /code/polkadot-sdk 36 | 37 | ARG CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG=true 38 | RUN cargo build --release -p polkadot-parachain-bin 39 | RUN cargo build --release -p polkadot 40 | 41 | FROM --platform=linux/amd64 node:18.14.2 42 | 43 | WORKDIR /scripts 44 | 45 | COPY --from=builder /code/polkadot-sdk/target ./polkadot-sdk/target 46 | COPY --from=builder /code/polkadot-sdk/local-test ./polkadot-sdk/local-test 47 | 48 | # setup script 49 | COPY ./scripts/xcm/ ./xcm 50 | COPY ./scripts/xcm_e2e_setup.sh . 51 | RUN chmod +x ./xcm_e2e_setup.sh 52 | 53 | # Install root certs, see: https://github.com/paritytech/substrate/issues/9984 54 | RUN apt update && \ 55 | apt install -y ca-certificates && \ 56 | update-ca-certificates && \ 57 | apt remove ca-certificates -y && \ 58 | rm -rf /var/lib/apt/lists/* 59 | 60 | # JSON-RPC WS server 61 | # relaychain 62 | EXPOSE 9943 63 | # Asset hub 64 | EXPOSE 9910 65 | # Bridge hub 66 | EXPOSE 8943 67 | 68 | # JSON-RPC HTTP server 69 | # relaychain 70 | EXPOSE 9933 71 | # Asset hub 72 | EXPOSE 9911 73 | # Bridge hub 74 | EXPOSE 8933 75 | 76 | ARG mpc_address 77 | ENV MPCADDR $mpc_address 78 | 79 | RUN ["./xcm_e2e_setup.sh"] 80 | 81 | WORKDIR /scripts/polkadot-sdk/local-test 82 | 83 | ENTRYPOINT ["./zombienet", "spawn", "--provider", "native", "./bridge_hub_rococo_local_network.toml", "-d", "./db"] 84 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # run cargo clippy and cargo fmt 2 | lint: fmt 3 | cargo fmt --all --check 4 | cargo clippy --all-targets -- -D warnings 5 | 6 | # run cargo fmt 7 | fmt: 8 | cargo fmt --all 9 | 10 | # run unit test 11 | test: 12 | cargo test 13 | 14 | # run unit test with benchmark 15 | test-benchmark: 16 | cargo test --features runtime-benchmarks 17 | 18 | # license-check Checks for missing license crates 19 | license-check: 20 | @echo " > \033[Checking for license headers...\033[0m " 21 | cargo-deny -L error check license 22 | 23 | ############################## Local node ############################ 24 | 25 | # build the binaries locally 26 | # this will build both standalone node binary and the parachain node binary 27 | build: 28 | cargo build --release 29 | 30 | # build the binaries locally with benchmark 31 | # this will build both standalone node binary and the parachain node binary 32 | build-benchmark: 33 | cargo build --release --features runtime-benchmarks 34 | 35 | # launch the standalone node in dev mode 36 | start-dev: 37 | ./target/release/standalone-node-template --dev --rpc-external 38 | 39 | # run setup js script to setup the local substrate node 40 | # substrate node is required, run make start-dev first 41 | run-setup: 42 | node ./scripts/standalone/setup.js 43 | 44 | # build-docker-image builds the docker image without setup the chain 45 | build-docker-image: 46 | docker build -t sygma-substrate-pallet . 47 | 48 | # start-docker-image launches the docker image without setup the chain 49 | start-docker-image: 50 | docker run -p 9944:9944 -it sygma-substrate-pallet --dev --rpc-external 51 | 52 | ############################## E2E test image ########################### 53 | 54 | # build-e2e-test-docker-image builds the e2e test docker image 55 | build-e2e-test-docker-image: 56 | @echo "\033[92m ==> building the e2e test docker image, dockerfile in use: Dockerfile_e2e \033[0m" 57 | @echo "\033[92m ==> mpc address in env var: $(MPCADDR) \033[0m" 58 | 59 | docker build --file ./Dockerfile_e2e -t sygma_substrate_pallets_e2e_preconfigured --build-arg mpc_address=$(MPCADDR) . 60 | 61 | # run the preconfigured e2e docker image 62 | start-e2e-test-docker-image: 63 | docker run -p 9944:9944 -it sygma_substrate_pallets_e2e_preconfigured 64 | 65 | ##################### Phala subbridge integration node E2E test image ################## 66 | 67 | # build-subbridge-e2e-test-image builds the phala subbridge integrated sygma pallet e2e test docker image 68 | # this e2e image is a relay chain + phala parachain with sygma pallets simulation env 69 | build-subbridge-e2e-test-docker-image: 70 | @echo "\033[92m ==> building the subbridge e2e test docker image, dockerfile in use: Dockerfile_subbridge_e2e \033[0m" 71 | 72 | docker build --file ./Dockerfile_subbridge_e2e -t sygma_substrate_pallets_subbridge_e2e_preconfigured . 73 | 74 | # run the preconfigured e2e subbridge docker image 75 | start-subbridge-e2e-test-docker-image: 76 | docker run -p 9944:9944 -it sygma_substrate_pallets_subbridge_e2e_preconfigured 77 | 78 | ##################### Zombienet ################## 79 | 80 | # prepare parachain-node binary and polkadot-sdk binary 81 | build-zombienet: build 82 | ./zombienet/scripts/zombienet_prepare.sh 83 | 84 | # launch the parachain node in local zombienet with relay chain and parachain 85 | start-zombienet: 86 | ./zombienet/zombienet spawn -p native ./zombienet/local_zombienet.toml 87 | 88 | ##################### XCM E2E test image ################## 89 | 90 | # build a docker image with all sygma features integrated in Bridge hub parachain 91 | # this will also launch Asset hub parachain with Rococo relaychain by zombienet and then run xcm e2e setup script 92 | build-xcm-e2e-test-docker-image: 93 | @echo "\033[92m ==> building the xcm e2e test docker image, dockerfile in use: Dockerfile_xcm_e2e \033[0m" 94 | @echo "\033[92m ==> this cmd will take env var MPCADDR when building the image, if not provided, you can still manually set it up via sygma bridge pallet extrinsic after launching \033[0m" 95 | @echo "\033[92m ==> mpc address in env var: $(MPCADDR) \033[0m" 96 | 97 | docker build --file ./Dockerfile_xcm_e2e -t sygma_substrate_pallets_xcm_e2e_preconfigured --build-arg mpc_address=$(MPCADDR) . 98 | 99 | # run the preconfigured xcm e2e docker image 100 | # this will launch preconfigured zombienet with Rococo relaychain, Asset hub parachain, Bridge hub parachain(sygma pallets integrated) 101 | start-xcm-e2e-test-docker-image: 102 | docker run --platform linux/amd64 -p 9943:9943 -p 9910:9910 -p 8943:8943 -it sygma_substrate_pallets_xcm_e2e_preconfigured 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sygma-Substrate-Pallets 2 | 3 | This repo contains several substrate pallet implementation for Sygma protocol. 4 | 5 | ## About Sygma 6 | 7 | [Sygma](https://buildwithsygma.com/) is a multi-purpose interoperability layer that supports developers in building cross-chain dApps. 8 | 9 | ## Build & Test 10 | 11 | - Build locally 12 | 13 | ```sh 14 | $ make build 15 | ``` 16 | 17 | - Build docker image 18 | 19 | ```sh 20 | $ docker build -t sygma-substrate-pallet . 21 | ``` 22 | 23 | - Run unit tests 24 | 25 | ```sh 26 | $ make test 27 | ``` 28 | 29 | - Run local testnet with Sygma protocol integrated 30 | 31 | ```sh 32 | $ make start-dev 33 | ``` 34 | 35 | - Run docker container as local testnet 36 | 37 | ```sh 38 | $ docker run -p 9944:9944 -it sygma-substrate-pallet --dev --rpc-external 39 | ``` 40 | 41 | ## Interact via Polkadot JS App 42 | Explore testnet at [127.0.0.1:9944](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer) 43 | 44 | ## Wiki 45 | 46 | In the substrate pallet, there are few concepts that are significantly important yet confusing, thus, in this 47 | section, we are going to make some clarification and explanation. 48 | 49 | ### MultiLocation 50 | `MultiLocation` is a substrate type. It is introduced by XCM, and it is used to identify any single entity location that exists within the world of Polkadot consensus. 51 | `MultiLocation` always expresses a **relative** location to the **current location**. Practically, `MultiLocations` are used to identify places to send XCM messages. 52 | In Sygma pallets, it is used to identify the destination when depositing, the deposit extrinsic signature is shown below: 53 | ```rust 54 | pub fn deposit(origin: OriginFor, asset: MultiAsset, dest: MultiLocation) -> DispatchResult 55 | ``` 56 | `dest: MultiLocation` here is able to include any customized data in any desired layer. The logic to extract the detail is depending on the trait `ExtractDestinationData` implementation 57 | 58 | `ExtractDestinationData` trait currently has only one method `extract_dest`, and the current implementation takes a `MultiLocation` and extracts both recipient address as `Vec` and dest domainID as `DomainID` 59 | ```rust 60 | pub trait ExtractDestinationData { 61 | fn extract_dest(dest: &MultiLocation) -> Option<(Vec, DomainID)>; 62 | } 63 | ``` 64 | 65 | As a developer who needs to construct `dest: MultiLocation` and then call `deposit`, you need to know how this MultiLocation is structured, for example: 66 | ``` 67 | (parents: 0, interior: X2(GeneralKey("ethereum recipient"), GeneralIndex(destDomainID))) 68 | ``` 69 | 70 | *** 71 | 72 | ### MultiAsset 73 | `MultiAsset` is also a substrate type. Asset can be divided into different types from different point of view, such as fungible and non-fungible assets, 74 | native asset and foreign asset ,etc. `MultiAsset` is the concept to handler multiple assets in the Polkadot world. 75 | In sygma pallets, `MultiAsset` is used to identify the asset no matter its location and fungibility. Below is the definition of `MultiAsset`: 76 | ```rust 77 | pub struct MultiAsset { 78 | pub id: AssetId, 79 | pub fun: Fungibility, 80 | } 81 | ``` 82 | the `AssetID` and `Fungibility` type are defined as: 83 | ```rust 84 | pub enum AssetId { 85 | Concrete(MultiLocation), 86 | Abstract(Vec), 87 | } 88 | 89 | pub enum Fungibility { 90 | Fungible(#[codec(compact)] u128), 91 | NonFungible(AssetInstance), 92 | } 93 | ``` 94 | the assetID is a `MultiLocation` and fungibility contains `u128` which is the asset amount if it's a fungible asset. 95 | 96 | As a developer who needs to construct `asset: MultiAsset` and then call `deposit`, you need to know how this MultiAsset is structured, for example, the fungible testing asset USDC can be constructed like: 97 | ```rust 98 | ( 99 | Concrete( 100 | MultiLocation::new(1, X3(Parachain(2004), GeneralKey("sygma"), GeneralKey("usdc"))) 101 | ), 102 | Fungible(amount) 103 | ) 104 | ``` 105 | 106 | *** 107 | 108 | ### DomainID & ChainID 109 | In sygma pallets, multiple destination domain is supported in one single pallet instance. There are DestDomain management extrinsics to register/unregister domainID with its corresponding ChainID. 110 | This information is stored in the chain storage: 111 | ```rust 112 | pub type DestChainIds = StorageMap<_, Twox64Concat, DomainID, ChainID>; 113 | ``` 114 | 115 | ChainID is not explicitly used in the pallet logic, but they are registered with DomainID. By querying the getter method of `dest_chain_ids`, it would be easy to find out which domainID is binding with which chainID. 116 | 117 | *** 118 | 119 | ### ResourceID 120 | ResourceID the identifier of the asset in sygma system. To link it with XCM asset, there is `ResourcePairs` defined in the runtime which is the mapping between `AssetId` and `ResourceID`. 121 | ```rust 122 | type ResourcePairs: Get>; 123 | ``` 124 | As mentioned in the `MultiAsset` section, the `AssetId` contains the asset's MultiLocation, so that one asset with its `MultiLocation` is able to link with `ResouceID`, 125 | 126 | *** 127 | 128 | ### AssetId of u32 vs AssetId of XCM 129 | **AssetID of u32**: When creating an asset in substrate, a `u32` number has to be assigned as the `assetID` and this number will be displayed in the assets 130 | page on Polkadot JS App. This `assetID` is used when transferring this asset between different accounts within the parachain. It is normally used 131 | in `assets` pallet. 132 | 133 | **AssetID of xcm**: This is the xcm type of AssetID. It is the first parameter of `MultiAsset`. In Sygma pallets, it has an alise as `XcmAssetId`. `XcmAssetId` is the asset identifier within the entire Polkdaot world, 134 | because under the hood, it is a `MultiLocation`(see definition above). 135 | 136 | It is also important to understand the relationship between an `asset`, the `u32 assetID`, the `XcmAssetID`, the `MultiLocation` of the asset, the basic fee associated with the asset, 137 | and how the asset is binding with a `ResourceID`: 138 | 139 | ![img.png](diagram.png) 140 | In Sygma pallets, `u32` AssetID is binding with Asset MultiLocation by the implementation of `SimpleForeignAssetConverter` struct, it implements the `xcm-exectuor::Convert` trait. Since `XcmAssetID` contains the Asset MultiLocation, it can now associate with basic fee together with the fee amount(`u128`). 141 | Similarly, Asset MultiLocation can also map with `ResouceID` in the `ResourcePairs: Vec<(XcmAssetId, ResourceId)>`. 142 | In summary, `MultiLocation` of an `Asset` is the key in this relationship. 143 | 144 | Please note, `AssetID` does not necessarily have to be `u32`, it could be defined as `u8` or `u128`, etc. as well. In Sygma pallet, we defined it as `u32` for the demo purpose because 145 | sygma pallets use `pallet-assets` to manage foreign assets in the demo runtime. Other substrate chain developers could config their own implementation, for example, some parachains use `orml` token, 146 | which will have its own concept. 147 | 148 | *** 149 | 150 | ### SCALE codec in substrate 151 | When sending and receiving over the network, substrate uses an encoding and decoding program called SCALE codec. The SCALE codec is not self-describing. It assumes the decoding context has all type knowledge about the encoded data. In general, each data type has its own rule when encoding by SCALE, so when decoding, they will follow their own rule based on its data type. 152 | 153 | It is **not** recommended to do the manual decoding; however, it is important to understand the underline mechanism. 154 | 155 | The substrate reference table for this `encoding/decoding` rules can be found [here](https://docs.substrate.io/reference/scale-codec/). 156 | 157 | There are other language lib that has implemented SCALE codec can be used when interacting with substrate node which can also be found in the link above. 158 | -------------------------------------------------------------------------------- /access-segregator/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-access-segregator-v0.1.0...sygma-access-segregator-v0.2.0) (2023-05-11) 4 | 5 | 6 | ### Features 7 | 8 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 9 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 10 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * avoid without storage info macro ([#99](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/99)) ([abd6db1](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abd6db1c00940de65a71a50232962bc943e0aa39)) 16 | * Set extrinsic weight based on benchmarking ([#100](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/100)) ([d52594c](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d52594caecdd95ef9e259e1b31dc340d9059d41e)) 17 | 18 | ## 0.1.0 (2023-03-01) 19 | 20 | 21 | ### Features 22 | 23 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 24 | -------------------------------------------------------------------------------- /access-segregator/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-access-segregator" 3 | version = "0.2.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | 11 | # Substrate 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, optional = true } 15 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | 17 | [dev-dependencies] 18 | # Substrate 19 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 20 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 21 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 22 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 23 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 24 | 25 | [features] 26 | default = ["std"] 27 | std = [ 28 | "codec/std", 29 | "scale-info/std", 30 | "frame-support/std", 31 | "frame-system/std", 32 | "frame-benchmarking/std", 33 | "sp-std/std", 34 | ] 35 | runtime-benchmarks = [ 36 | 'frame-benchmarking', 37 | 'frame-support/runtime-benchmarks', 38 | 'frame-system/runtime-benchmarks', 39 | ] 40 | try-runtime = ["frame-support/try-runtime"] 41 | -------------------------------------------------------------------------------- /access-segregator/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Sygma access-segreator pallet benchmarking. 5 | 6 | #![cfg(feature = "runtime-benchmarks")] 7 | use super::*; 8 | use frame_benchmarking::v2::*; 9 | use frame_system::RawOrigin as SystemOrigin; 10 | 11 | use sp_std::vec; 12 | 13 | #[benchmarks] 14 | mod benchmarks { 15 | use super::*; 16 | 17 | #[benchmark] 18 | fn grant_access() { 19 | let caller: ::AccountId = whitelisted_caller(); 20 | 21 | #[extrinsic_call] 22 | grant_access(SystemOrigin::Root, 100, b"grant_access".to_vec(), caller.clone()); 23 | 24 | assert_eq!( 25 | ExtrinsicAccess::::get(&(100, b"grant_access".to_vec())), 26 | Some(caller).into(), 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /access-segregator/src/mock.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use frame_support::{ 5 | pallet_prelude::ConstU32, 6 | parameter_types, 7 | sp_runtime::{ 8 | testing::H256, 9 | traits::{BlakeTwo256, IdentityLookup}, 10 | AccountId32, BuildStorage, Perbill, 11 | }, 12 | }; 13 | use frame_system::{self as system, EnsureRoot}; 14 | 15 | use crate as sygma_access_segregator; 16 | 17 | type Block = frame_system::mocking::MockBlock; 18 | 19 | pub(crate) type Balance = u128; 20 | 21 | pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); 22 | pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); 23 | pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]); 24 | 25 | frame_support::construct_runtime!( 26 | pub enum Test { 27 | System: frame_system, 28 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 29 | AccessSegregator: sygma_access_segregator::{Pallet, Call, Storage, Event} = 2, 30 | } 31 | ); 32 | 33 | parameter_types! { 34 | pub const BlockHashCount: u64 = 250; 35 | pub const MaximumBlockLength: u32 = 2 * 1024; 36 | pub const AvailableBlockRatio: Perbill = Perbill::one(); 37 | pub const MaxLocks: u32 = 100; 38 | pub const MinimumPeriod: u64 = 1; 39 | } 40 | 41 | impl frame_system::Config for Test { 42 | type BaseCallFilter = frame_support::traits::Everything; 43 | type Block = Block; 44 | type BlockWeights = (); 45 | type BlockLength = (); 46 | type RuntimeOrigin = RuntimeOrigin; 47 | type RuntimeCall = RuntimeCall; 48 | type Nonce = u64; 49 | type Hash = H256; 50 | type Hashing = BlakeTwo256; 51 | type AccountId = AccountId32; 52 | type Lookup = IdentityLookup; 53 | type RuntimeEvent = RuntimeEvent; 54 | type BlockHashCount = BlockHashCount; 55 | type DbWeight = (); 56 | type Version = (); 57 | type PalletInfo = PalletInfo; 58 | type AccountData = pallet_balances::AccountData; 59 | type OnNewAccount = (); 60 | type OnKilledAccount = (); 61 | type SystemWeightInfo = (); 62 | type SS58Prefix = (); 63 | type OnSetCode = (); 64 | type MaxConsumers = ConstU32<2>; 65 | } 66 | 67 | parameter_types! { 68 | pub const ExistentialDeposit: Balance = 1; 69 | } 70 | 71 | impl pallet_balances::Config for Test { 72 | type Balance = Balance; 73 | type DustRemoval = (); 74 | type RuntimeEvent = RuntimeEvent; 75 | type ExistentialDeposit = ExistentialDeposit; 76 | type AccountStore = System; 77 | type WeightInfo = (); 78 | type MaxLocks = (); 79 | type MaxReserves = (); 80 | type ReserveIdentifier = [u8; 8]; 81 | type FreezeIdentifier = (); 82 | type MaxFreezes = (); 83 | type RuntimeHoldReason = (); 84 | type MaxHolds = (); 85 | } 86 | 87 | parameter_types! { 88 | // Make sure put same value with `construct_runtime` 89 | pub const PalletIndex: u8 = 2; 90 | pub RegisteredExtrinsics: Vec<(u8, Vec)> = [ 91 | (PalletIndex::get(), b"grant_access".to_vec()), 92 | (PalletIndex::get(), b"unknown_extrinsic".to_vec()), 93 | (PalletIndex::get(), b"unknown_extrinsic2".to_vec()), 94 | ].to_vec(); 95 | } 96 | 97 | impl sygma_access_segregator::Config for Test { 98 | type RuntimeEvent = RuntimeEvent; 99 | type BridgeCommitteeOrigin = EnsureRoot; 100 | type PalletIndex = PalletIndex; 101 | type Extrinsics = RegisteredExtrinsics; 102 | type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo; 103 | } 104 | 105 | pub fn new_test_ext() -> sp_io::TestExternalities { 106 | let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 107 | let mut ext = sp_io::TestExternalities::new(t); 108 | ext.execute_with(|| System::set_block_number(1)); 109 | ext 110 | } 111 | 112 | // Checks events against the latest. A contiguous set of events must be provided. They must 113 | // include the most recent event, but do not have to include every past event. 114 | pub fn assert_events(mut expected: Vec) { 115 | let mut actual: Vec = 116 | system::Pallet::::events().iter().map(|e| e.event.clone()).collect(); 117 | 118 | expected.reverse(); 119 | 120 | for evt in expected { 121 | let next = actual.pop().expect("event expected"); 122 | assert_eq!(next, evt, "Events don't match"); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /access-segregator/src/weights.rs: -------------------------------------------------------------------------------- 1 | 2 | //! Autogenerated weights for `sygma_access_segregator` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 5 | //! DATE: 2023-04-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 6 | //! WORST CASE MAP SIZE: `1000000` 7 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 8 | 9 | // Executed Command: 10 | // ./target/release/standalone-node-template 11 | // benchmark 12 | // pallet 13 | // --chain 14 | // dev 15 | // --execution=wasm 16 | // --wasm-execution=compiled 17 | // --pallet 18 | // sygma_access_segregator 19 | // --extrinsic 20 | // * 21 | // --steps 22 | // 50 23 | // --repeat 24 | // 20 25 | // --output 26 | // access_weight.rs 27 | 28 | #![cfg_attr(rustfmt, rustfmt_skip)] 29 | #![allow(unused_parens)] 30 | #![allow(unused_imports)] 31 | 32 | use frame_support::{traits::Get, weights::Weight}; 33 | use sp_std::marker::PhantomData; 34 | 35 | /// Weight functions for `sygma_access_segregator`. 36 | pub struct SygmaWeightInfo(PhantomData); 37 | impl super::WeightInfo for SygmaWeightInfo { 38 | /// Storage: SygmaAccessSegregator ExtrinsicAccess (r:0 w:1) 39 | /// Proof Skipped: SygmaAccessSegregator ExtrinsicAccess (max_values: None, max_size: None, mode: Measured) 40 | fn grant_access() -> Weight { 41 | // Proof Size summary in bytes: 42 | // Measured: `0` 43 | // Estimated: `0` 44 | // Minimum execution time: 9_000_000 picoseconds. 45 | Weight::from_parts(9_000_000, 0) 46 | .saturating_add(Weight::from_parts(0, 0)) 47 | .saturating_add(T::DbWeight::get().writes(1)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /basic-fee-handler/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.3.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-basic-feehandler-v0.2.0...sygma-basic-feehandler-v0.3.0) (2023-05-24) 4 | 5 | 6 | ### Features 7 | 8 | * Remove BridgeCommitteeOrigin from some pallets' config ([#104](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/104)) ([abfe1ff](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abfe1ffdf1d992d33be4cad9374bd5be92b87343)) 9 | 10 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-basic-feehandler-v0.1.0...sygma-basic-feehandler-v0.2.0) (2023-05-11) 11 | 12 | 13 | ### Features 14 | 15 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 16 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 17 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * avoid without storage info macro ([#99](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/99)) ([abd6db1](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abd6db1c00940de65a71a50232962bc943e0aa39)) 23 | * Set extrinsic weight based on benchmarking ([#100](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/100)) ([d52594c](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d52594caecdd95ef9e259e1b31dc340d9059d41e)) 24 | 25 | ## 0.1.0 (2023-03-01) 26 | 27 | 28 | ### Features 29 | 30 | * Impl fee handler router ([#43](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/43)) ([efb6818](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/efb6818e7558b7142aa1954b90f32397ad87f4f6)) 31 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 32 | -------------------------------------------------------------------------------- /basic-fee-handler/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-basic-feehandler" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | 11 | # Substrate 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, optional = true } 15 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | 17 | # Polkadot 18 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 20 | 21 | # Local 22 | sygma-traits = { path = "../traits", default-features = false } 23 | sygma-access-segregator = { path = "../access-segregator", default-features = false } 24 | 25 | [dev-dependencies] 26 | # Substrate 27 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 28 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 29 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 30 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 31 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 32 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 33 | 34 | [features] 35 | default = ["std"] 36 | std = [ 37 | "codec/std", 38 | "scale-info/std", 39 | "frame-support/std", 40 | "frame-system/std", 41 | "frame-benchmarking/std", 42 | "sp-std/std", 43 | "xcm/std", 44 | "xcm-builder/std", 45 | "sygma-traits/std", 46 | "sygma-access-segregator/std", 47 | ] 48 | runtime-benchmarks = [ 49 | 'frame-benchmarking', 50 | 'frame-support/runtime-benchmarks', 51 | 'frame-system/runtime-benchmarks', 52 | ] 53 | try-runtime = ["frame-support/try-runtime"] 54 | -------------------------------------------------------------------------------- /basic-fee-handler/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Sygma basic-fee-handler pallet benchmarking. 5 | 6 | #![cfg(feature = "runtime-benchmarks")] 7 | use super::*; 8 | use frame_benchmarking::v2::*; 9 | use frame_system::RawOrigin as SystemOrigin; 10 | 11 | use sp_std::vec; 12 | use sygma_traits::DomainID; 13 | use xcm::latest::prelude::*; 14 | 15 | #[benchmarks] 16 | mod benchmarks { 17 | use super::*; 18 | 19 | #[benchmark] 20 | fn set_fee() { 21 | let dest_domain_id: DomainID = 1; 22 | let native_location: MultiLocation = MultiLocation::here(); 23 | let fee = 1_000_000_000_000u128; // 1 with 12 decimals 24 | 25 | #[extrinsic_call] 26 | set_fee(SystemOrigin::Root, dest_domain_id, Box::new(native_location.clone().into()), fee); 27 | 28 | assert_eq!(AssetFees::::get(&(dest_domain_id, native_location.into())), Some(fee),); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /basic-fee-handler/src/lib.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #![cfg_attr(not(feature = "std"), no_std)] 5 | 6 | pub use self::pallet::*; 7 | 8 | #[cfg(feature = "runtime-benchmarks")] 9 | mod benchmarking; 10 | pub mod weights; 11 | pub use weights::*; 12 | 13 | #[cfg(test)] 14 | mod mock; 15 | 16 | #[allow(unused_variables)] 17 | #[allow(clippy::large_enum_variant)] 18 | #[frame_support::pallet] 19 | pub mod pallet { 20 | use frame_support::{dispatch::DispatchResult, pallet_prelude::*, traits::StorageVersion}; 21 | use frame_system::pallet_prelude::*; 22 | use sp_std::boxed::Box; 23 | use sygma_traits::{DomainID, FeeHandler}; 24 | use xcm::latest::{AssetId, MultiAsset}; 25 | 26 | const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); 27 | 28 | /// Mapping fungible asset id to corresponding fee amount 29 | #[pallet::storage] 30 | #[pallet::getter(fn asset_fees)] 31 | pub type AssetFees = StorageMap<_, Twox64Concat, (DomainID, AssetId), u128>; 32 | 33 | pub trait WeightInfo { 34 | fn set_fee() -> Weight; 35 | } 36 | 37 | #[pallet::pallet] 38 | #[pallet::storage_version(STORAGE_VERSION)] 39 | pub struct Pallet(_); 40 | 41 | #[pallet::config] 42 | pub trait Config: frame_system::Config + sygma_access_segregator::Config { 43 | type RuntimeEvent: From> + IsType<::RuntimeEvent>; 44 | 45 | /// Current pallet index defined in runtime 46 | type PalletIndex: Get; 47 | 48 | /// Type representing the weight of this pallet 49 | type WeightInfo: WeightInfo; 50 | } 51 | 52 | #[pallet::event] 53 | #[pallet::generate_deposit(pub (super) fn deposit_event)] 54 | pub enum Event { 55 | /// Fee set for a specific asset 56 | /// args: [domain, asset, amount] 57 | FeeSet { domain: DomainID, asset: AssetId, amount: u128 }, 58 | } 59 | 60 | #[pallet::error] 61 | pub enum Error { 62 | /// Function unimplemented 63 | Unimplemented, 64 | /// Account has not gained access permission 65 | AccessDenied, 66 | } 67 | 68 | #[pallet::call] 69 | impl Pallet { 70 | /// Set bridge fee for a specific asset 71 | #[pallet::call_index(0)] 72 | #[pallet::weight(::WeightInfo::set_fee())] 73 | pub fn set_fee( 74 | origin: OriginFor, 75 | domain: DomainID, 76 | asset: Box, 77 | amount: u128, 78 | ) -> DispatchResult { 79 | let asset: AssetId = *asset; 80 | ensure!( 81 | >::has_access( 82 | ::PalletIndex::get(), 83 | b"set_fee".to_vec(), 84 | origin 85 | ), 86 | Error::::AccessDenied 87 | ); 88 | 89 | // Update asset fee 90 | AssetFees::::insert((domain, &asset), amount); 91 | 92 | // Emit FeeSet event 93 | Self::deposit_event(Event::FeeSet { domain, asset, amount }); 94 | Ok(()) 95 | } 96 | } 97 | 98 | impl FeeHandler for Pallet { 99 | fn get_fee(domain: DomainID, asset: MultiAsset) -> Option { 100 | AssetFees::::get((domain, &asset.id)) 101 | } 102 | } 103 | 104 | #[cfg(test)] 105 | mod test { 106 | use crate as basic_fee_handler; 107 | use crate::{AssetFees, Event as BasicFeeHandlerEvent}; 108 | use basic_fee_handler::mock::{ 109 | assert_events, new_test_ext, AccessSegregator, BasicFeeHandler, FeeHandlerPalletIndex, 110 | RuntimeEvent as Event, RuntimeOrigin as Origin, Test, ALICE, 111 | }; 112 | use frame_support::{assert_noop, assert_ok}; 113 | use sp_std::boxed::Box; 114 | use sygma_traits::DomainID; 115 | use xcm::latest::{prelude::*, MultiLocation}; 116 | 117 | #[test] 118 | fn set_get_fee() { 119 | new_test_ext().execute_with(|| { 120 | let dest_domain_id: DomainID = 0; 121 | let another_dest_domain_id: DomainID = 1; 122 | let asset_id_a = Concrete(MultiLocation::new(1, Here)); 123 | let amount_a = 100u128; 124 | 125 | let asset_id_b = Concrete(MultiLocation::new(2, Here)); 126 | let amount_b = 101u128; 127 | 128 | // set fee 100 with assetId asset_id_a for one domain 129 | assert_ok!(BasicFeeHandler::set_fee( 130 | Origin::root(), 131 | dest_domain_id, 132 | Box::new(asset_id_a), 133 | amount_a 134 | )); 135 | // set fee 200 with assetId asset_id_a for another domain 136 | assert_ok!(BasicFeeHandler::set_fee( 137 | Origin::root(), 138 | another_dest_domain_id, 139 | Box::new(asset_id_a), 140 | amount_a * 2 141 | )); 142 | assert_eq!(AssetFees::::get((dest_domain_id, asset_id_a)).unwrap(), amount_a); 143 | assert_eq!( 144 | AssetFees::::get((another_dest_domain_id, asset_id_a)).unwrap(), 145 | amount_a * 2 146 | ); 147 | 148 | // set fee 101 with assetId asset_id_b 149 | assert_ok!(BasicFeeHandler::set_fee( 150 | Origin::root(), 151 | dest_domain_id, 152 | Box::new(asset_id_b), 153 | amount_b 154 | )); 155 | assert_eq!(AssetFees::::get((dest_domain_id, asset_id_b)).unwrap(), amount_b); 156 | 157 | // fee of asset_id_a should not be equal to amount_b 158 | assert_ne!(AssetFees::::get((dest_domain_id, asset_id_a)).unwrap(), amount_b); 159 | 160 | // fee of asset_id_b should not be equal to amount_a 161 | assert_ne!(AssetFees::::get((dest_domain_id, asset_id_b)).unwrap(), amount_a); 162 | 163 | // permission test: unauthorized account should not be able to set fee 164 | let unauthorized_account = Origin::from(Some(ALICE)); 165 | assert_noop!( 166 | BasicFeeHandler::set_fee( 167 | unauthorized_account, 168 | dest_domain_id, 169 | Box::new(asset_id_a), 170 | amount_a 171 | ), 172 | basic_fee_handler::Error::::AccessDenied 173 | ); 174 | 175 | assert_events(vec![ 176 | Event::BasicFeeHandler(BasicFeeHandlerEvent::FeeSet { 177 | domain: dest_domain_id, 178 | asset: asset_id_a, 179 | amount: amount_a, 180 | }), 181 | Event::BasicFeeHandler(BasicFeeHandlerEvent::FeeSet { 182 | domain: another_dest_domain_id, 183 | asset: asset_id_a, 184 | amount: amount_a * 2, 185 | }), 186 | Event::BasicFeeHandler(BasicFeeHandlerEvent::FeeSet { 187 | domain: dest_domain_id, 188 | asset: asset_id_b, 189 | amount: amount_b, 190 | }), 191 | ]); 192 | }) 193 | } 194 | 195 | #[test] 196 | fn access_control() { 197 | new_test_ext().execute_with(|| { 198 | let dest_domain_id: DomainID = 0; 199 | let asset_id = Concrete(MultiLocation::new(0, Here)); 200 | 201 | assert_ok!(BasicFeeHandler::set_fee( 202 | Origin::root(), 203 | dest_domain_id, 204 | Box::new(asset_id), 205 | 100 206 | ),); 207 | assert_noop!( 208 | BasicFeeHandler::set_fee( 209 | Some(ALICE).into(), 210 | dest_domain_id, 211 | Box::new(asset_id), 212 | 200 213 | ), 214 | basic_fee_handler::Error::::AccessDenied 215 | ); 216 | // (FeeHandlerPalletIndex:get(), b"set_fee") indicates extrinsic: `set_fee` of this 217 | // pallet 218 | assert!(!AccessSegregator::has_access( 219 | FeeHandlerPalletIndex::get(), 220 | b"set_fee".to_vec(), 221 | Some(ALICE).into() 222 | )); 223 | assert_ok!(AccessSegregator::grant_access( 224 | Origin::root(), 225 | FeeHandlerPalletIndex::get(), 226 | b"set_fee".to_vec(), 227 | ALICE 228 | )); 229 | assert!(AccessSegregator::has_access( 230 | FeeHandlerPalletIndex::get(), 231 | b"set_fee".to_vec(), 232 | Some(ALICE).into() 233 | )); 234 | assert_ok!(BasicFeeHandler::set_fee( 235 | Some(ALICE).into(), 236 | dest_domain_id, 237 | Box::new(asset_id), 238 | 200 239 | ),); 240 | assert_eq!(AssetFees::::get((dest_domain_id, asset_id)).unwrap(), 200); 241 | }) 242 | } 243 | } 244 | } 245 | -------------------------------------------------------------------------------- /basic-fee-handler/src/mock.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use frame_support::{ 5 | pallet_prelude::ConstU32, 6 | parameter_types, 7 | sp_runtime::{ 8 | testing::H256, 9 | traits::{BlakeTwo256, IdentityLookup}, 10 | AccountId32, BuildStorage, Perbill, 11 | }, 12 | traits::{AsEnsureOriginWithArg, ConstU128}, 13 | }; 14 | use frame_system::{self as system, EnsureRoot, EnsureSigned}; 15 | 16 | use crate as basic_fee_handler; 17 | 18 | type Block = frame_system::mocking::MockBlock; 19 | 20 | pub(crate) type Balance = u128; 21 | 22 | pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); 23 | 24 | frame_support::construct_runtime!( 25 | pub enum Test { 26 | System: frame_system, 27 | Assets: pallet_assets::{Pallet, Call, Storage, Event}, 28 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 29 | AccessSegregator: sygma_access_segregator::{Pallet, Call, Storage, Event} = 3, 30 | BasicFeeHandler: basic_fee_handler::{Pallet, Call, Storage, Event} = 4, 31 | } 32 | ); 33 | 34 | parameter_types! { 35 | pub const BlockHashCount: u64 = 250; 36 | pub const MaximumBlockLength: u32 = 2 * 1024; 37 | pub const AvailableBlockRatio: Perbill = Perbill::one(); 38 | pub const MaxLocks: u32 = 100; 39 | pub const MinimumPeriod: u64 = 1; 40 | } 41 | 42 | impl frame_system::Config for Test { 43 | type BaseCallFilter = frame_support::traits::Everything; 44 | type Block = Block; 45 | type BlockWeights = (); 46 | type BlockLength = (); 47 | type RuntimeOrigin = RuntimeOrigin; 48 | type RuntimeCall = RuntimeCall; 49 | type Nonce = u64; 50 | type Hash = H256; 51 | type Hashing = BlakeTwo256; 52 | type AccountId = AccountId32; 53 | type Lookup = IdentityLookup; 54 | type RuntimeEvent = RuntimeEvent; 55 | type BlockHashCount = BlockHashCount; 56 | type DbWeight = (); 57 | type Version = (); 58 | type PalletInfo = PalletInfo; 59 | type AccountData = pallet_balances::AccountData; 60 | type OnNewAccount = (); 61 | type OnKilledAccount = (); 62 | type SystemWeightInfo = (); 63 | type SS58Prefix = (); 64 | type OnSetCode = (); 65 | type MaxConsumers = ConstU32<2>; 66 | } 67 | 68 | parameter_types! { 69 | pub const ExistentialDeposit: Balance = 1; 70 | } 71 | 72 | impl pallet_balances::Config for Test { 73 | type Balance = Balance; 74 | type DustRemoval = (); 75 | type RuntimeEvent = RuntimeEvent; 76 | type ExistentialDeposit = ExistentialDeposit; 77 | type AccountStore = System; 78 | type WeightInfo = (); 79 | type MaxLocks = (); 80 | type MaxReserves = (); 81 | type ReserveIdentifier = [u8; 8]; 82 | type FreezeIdentifier = (); 83 | type MaxFreezes = (); 84 | type RuntimeHoldReason = (); 85 | type MaxHolds = (); 86 | } 87 | 88 | parameter_types! { 89 | pub const AssetDeposit: Balance = 1; // 1 Unit deposit to create asset 90 | pub const ApprovalDeposit: Balance = 1; 91 | pub const AssetsStringLimit: u32 = 50; 92 | pub const MetadataDepositBase: Balance = 1; 93 | pub const MetadataDepositPerByte: Balance = 1; 94 | } 95 | 96 | impl pallet_assets::Config for Test { 97 | type RuntimeEvent = RuntimeEvent; 98 | type Balance = Balance; 99 | type AssetId = u32; 100 | type AssetIdParameter = codec::Compact; 101 | type Currency = Balances; 102 | type CreateOrigin = AsEnsureOriginWithArg>; 103 | type ForceOrigin = frame_system::EnsureRoot; 104 | type AssetDeposit = AssetDeposit; 105 | type AssetAccountDeposit = ConstU128<10>; 106 | type MetadataDepositBase = MetadataDepositBase; 107 | type MetadataDepositPerByte = MetadataDepositPerByte; 108 | type ApprovalDeposit = ApprovalDeposit; 109 | type StringLimit = AssetsStringLimit; 110 | type RemoveItemsLimit = ConstU32<1000>; 111 | type Freezer = (); 112 | type Extra = (); 113 | type CallbackHandle = (); 114 | type WeightInfo = pallet_assets::weights::SubstrateWeight; 115 | #[cfg(feature = "runtime-benchmarks")] 116 | type BenchmarkHelper = (); 117 | } 118 | 119 | parameter_types! { 120 | // Make sure put same value with `construct_runtime` 121 | pub const AccessSegregatorPalletIndex: u8 = 3; 122 | pub const FeeHandlerPalletIndex: u8 = 4; 123 | pub RegisteredExtrinsics: Vec<(u8, Vec)> = [ 124 | (AccessSegregatorPalletIndex::get(), b"grant_access".to_vec()), 125 | (FeeHandlerPalletIndex::get(), b"set_fee".to_vec()), 126 | ].to_vec(); 127 | } 128 | 129 | impl sygma_access_segregator::Config for Test { 130 | type RuntimeEvent = RuntimeEvent; 131 | type BridgeCommitteeOrigin = EnsureRoot; 132 | type PalletIndex = AccessSegregatorPalletIndex; 133 | type Extrinsics = RegisteredExtrinsics; 134 | type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo; 135 | } 136 | 137 | impl basic_fee_handler::Config for Test { 138 | type RuntimeEvent = RuntimeEvent; 139 | type PalletIndex = FeeHandlerPalletIndex; 140 | type WeightInfo = basic_fee_handler::weights::SygmaWeightInfo; 141 | } 142 | 143 | pub fn new_test_ext() -> sp_io::TestExternalities { 144 | let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 145 | let mut ext = sp_io::TestExternalities::new(t); 146 | ext.execute_with(|| System::set_block_number(1)); 147 | ext 148 | } 149 | 150 | // Checks events against the latest. A contiguous set of events must be provided. They must 151 | // include the most recent event, but do not have to include every past event. 152 | pub fn assert_events(mut expected: Vec) { 153 | let mut actual: Vec = 154 | system::Pallet::::events().iter().map(|e| e.event.clone()).collect(); 155 | 156 | expected.reverse(); 157 | 158 | for evt in expected { 159 | let next = actual.pop().expect("event expected"); 160 | assert_eq!(next, evt, "Events don't match"); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /basic-fee-handler/src/weights.rs: -------------------------------------------------------------------------------- 1 | 2 | //! Autogenerated weights for `sygma_basic_feehandler` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 5 | //! DATE: 2023-04-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 6 | //! WORST CASE MAP SIZE: `1000000` 7 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 8 | 9 | // Executed Command: 10 | // ./target/release/standalone-node-template 11 | // benchmark 12 | // pallet 13 | // --chain 14 | // dev 15 | // --execution=wasm 16 | // --wasm-execution=compiled 17 | // --pallet 18 | // sygma_basic_feehandler 19 | // --extrinsic 20 | // * 21 | // --steps 22 | // 50 23 | // --repeat 24 | // 20 25 | // --output 26 | // basic_feehandler_weight.rs 27 | 28 | #![cfg_attr(rustfmt, rustfmt_skip)] 29 | #![allow(unused_parens)] 30 | #![allow(unused_imports)] 31 | 32 | use frame_support::{traits::Get, weights::Weight}; 33 | use sp_std::marker::PhantomData; 34 | 35 | /// Weight functions for `sygma_basic_feehandler`. 36 | pub struct SygmaWeightInfo(PhantomData); 37 | impl super::WeightInfo for SygmaWeightInfo { 38 | /// Storage: SygmaBasicFeeHandler AssetFees (r:0 w:1) 39 | /// Proof Skipped: SygmaBasicFeeHandler AssetFees (max_values: None, max_size: None, mode: Measured) 40 | fn set_fee() -> Weight { 41 | // Proof Size summary in bytes: 42 | // Measured: `0` 43 | // Estimated: `0` 44 | // Minimum execution time: 9_000_000 picoseconds. 45 | Weight::from_parts(10_000_000, 0) 46 | .saturating_add(Weight::from_parts(0, 0)) 47 | .saturating_add(T::DbWeight::get().writes(1)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /bridge-forwarder/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-bridge-forwarder" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | hex-literal = { version = "0.3", default-features = false } 11 | 12 | # Substrate 13 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 15 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 17 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 18 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | 20 | # Polkadot 21 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 22 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 23 | xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 24 | 25 | # Cumulus 26 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 27 | cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 28 | cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 29 | 30 | # Local 31 | sygma-traits = { path = "../traits", default-features = false } 32 | 33 | [dev-dependencies] 34 | # Substrate 35 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 36 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 37 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 38 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 39 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 40 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 41 | pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 42 | 43 | # Polkadot 44 | polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 45 | 46 | # Local 47 | sygma-traits = { path = "../traits" } 48 | pallet-parachain-info = { path = "../parachain-info" } 49 | 50 | [features] 51 | default = ["std"] 52 | std = [ 53 | "codec/std", 54 | "scale-info/std", 55 | "frame-support/std", 56 | "frame-system/std", 57 | "sp-std/std", 58 | "sp-io/std", 59 | "xcm/std", 60 | "xcm-builder/std", 61 | "xcm-executor/std", 62 | "cumulus-primitives-core/std", 63 | "cumulus-primitives-utility/std", 64 | "cumulus-pallet-xcm/std", 65 | "sygma-traits/std", 66 | ] 67 | runtime-benchmarks = [ 68 | 'frame-support/runtime-benchmarks', 69 | 'frame-system/runtime-benchmarks', 70 | ] 71 | try-runtime = ["frame-support/try-runtime"] 72 | -------------------------------------------------------------------------------- /bridge-forwarder/src/xcm_asset_transactor.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use core::marker::PhantomData; 5 | 6 | use codec::Encode; 7 | use hex_literal::hex; 8 | use sygma_traits::{AssetTypeIdentifier, TransactorForwarder}; 9 | use xcm::latest::{Junction, MultiAsset, MultiLocation, XcmContext}; 10 | use xcm::prelude::*; 11 | use xcm_executor::{traits::TransactAsset, Assets}; 12 | 13 | pub struct XCMAssetTransactor( 14 | PhantomData<(CurrencyTransactor, FungiblesTransactor, AssetTypeChecker, Forwarder)>, 15 | ); 16 | impl< 17 | CurrencyTransactor: TransactAsset, 18 | FungiblesTransactor: TransactAsset, 19 | AssetTypeChecker: AssetTypeIdentifier, 20 | Forwarder: TransactorForwarder, 21 | > TransactAsset 22 | for XCMAssetTransactor 23 | { 24 | // deposit_asset implements the TransactAsset deposit_asset method and contains the logic to classify 25 | // the asset recipient location: 26 | // 1. recipient is on the local parachain 27 | // 2. recipient is on non-substrate chain(evm, cosmos, etc.) 28 | // 3. recipient is on the remote parachain 29 | fn deposit_asset(what: &MultiAsset, who: &MultiLocation, context: &XcmContext) -> XcmResult { 30 | match (who.parents, who.interior) { 31 | // 1. recipient is on the local parachain 32 | (0, X1(AccountId32 { .. })) | (0, X1(AccountKey20 { .. })) | (1, X1(Parachain(_))) => { 33 | // check if the asset is native, and call the corresponding deposit_asset() 34 | if AssetTypeChecker::is_native_asset(what) { 35 | CurrencyTransactor::deposit_asset(what, who, context)?; 36 | } else { 37 | FungiblesTransactor::deposit_asset(what, who, context)? 38 | } 39 | }, 40 | // recipient is on the remote chain 41 | _ => { 42 | // 2. recipient is on non-substrate chain(evm, cosmos, etc.), will forward to sygma bridge pallet 43 | match who.interior { 44 | // sygma: 7379676d61000000000000000000000000000000000000000000000000000000 45 | // sygma-bridge: 7379676d612d6272696467650000000000000000000000000000000000000000 46 | // outer world multilocation pattern: { Parachain(X), GeneralKey { length: 5, data: b"sygma"}, GeneralKey { length: 12, data: b"sygma-bridge"}, GeneralIndex(domainID), GeneralKey { length: length_of_recipient_address, data: recipient_address} } 47 | X4(GeneralKey { length: 5, data: hex!["7379676d61000000000000000000000000000000000000000000000000000000"]}, GeneralKey { length: 12, data: hex!["7379676d612d6272696467650000000000000000000000000000000000000000"]}, GeneralIndex(..), GeneralKey { .. }) => { 48 | // check if the asset is native or foreign, and deposit the asset to a tmp account first 49 | let tmp_account = sp_io::hashing::blake2_256(&MultiLocation::new(0, X1(GeneralKey { length: 8, data: [1u8; 32] })).encode()); 50 | if AssetTypeChecker::is_native_asset(what) { 51 | CurrencyTransactor::deposit_asset(&what.clone(), &Junction::AccountId32 { network: None, id: tmp_account }.into(), context)?; 52 | } else { 53 | FungiblesTransactor::deposit_asset(&what.clone(), &Junction::AccountId32 { network: None, id: tmp_account }.into(), context)? 54 | } 55 | 56 | Forwarder::other_world_transactor_forwarder(tmp_account, what.clone(), *who).map_err(|e| XcmError::FailedToTransactAsset(e.into()))?; 57 | } 58 | // 3. recipient is on remote parachain, will forward to xcm bridge pallet 59 | _ => { 60 | // xcm message must have a sender(origin), so a tmp account derived from pallet would be necessary here 61 | let tmp_account = sp_io::hashing::blake2_256(&MultiLocation::new(0, X1(GeneralKey { length: 8, data: [2u8; 32] })).encode()); 62 | 63 | // check if the asset is native or foreign, and call the corresponding deposit_asset(), recipient will be the derived tmp account 64 | // xcm message execution 65 | if AssetTypeChecker::is_native_asset(what) { 66 | CurrencyTransactor::deposit_asset(&what.clone(), &Junction::AccountId32 { network: None, id: tmp_account }.into(), context)?; 67 | } else { 68 | FungiblesTransactor::deposit_asset(&what.clone(), &Junction::AccountId32 { network: None, id: tmp_account }.into(), context)? 69 | } 70 | 71 | Forwarder::xcm_transactor_forwarder(tmp_account, what.clone(), *who).map_err(|e| XcmError::FailedToTransactAsset(e.into()))?; 72 | } 73 | } 74 | }, 75 | } 76 | 77 | Ok(()) 78 | } 79 | 80 | fn withdraw_asset( 81 | what: &MultiAsset, 82 | who: &MultiLocation, 83 | maybe_context: Option<&XcmContext>, 84 | ) -> Result { 85 | let assets = if AssetTypeChecker::is_native_asset(what) { 86 | CurrencyTransactor::withdraw_asset(what, who, maybe_context)? 87 | } else { 88 | FungiblesTransactor::withdraw_asset(what, who, maybe_context)? 89 | }; 90 | 91 | Ok(assets) 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /bridge/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.3.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-bridge-v0.2.0...sygma-bridge-v0.3.0) (2023-05-24) 4 | 5 | 6 | ### Features 7 | 8 | * Remove BridgeCommitteeOrigin from some pallets' config ([#104](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/104)) ([abfe1ff](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abfe1ffdf1d992d33be4cad9374bd5be92b87343)) 9 | 10 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-bridge-v0.1.0...sygma-bridge-v0.2.0) (2023-05-11) 11 | 12 | 13 | ### Features 14 | 15 | * Separate MPC address setup logic from other admin extrinsics ([#82](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/82)) ([1590c91](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/1590c91d84b2e5fa92650ae8bc5b23162dfd6f99)) 16 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 17 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 18 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 19 | 20 | 21 | ### Bug Fixes 22 | 23 | * add overflow checks ([#96](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/96)) ([2255492](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/2255492150d523277034dd2646cae900b6f7e4b4)) 24 | * avoid panic with invalid proposal data ([#97](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/97)) ([c3b7da7](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/c3b7da77459023ac2b8ce3a83b9c24b74a80a004)) 25 | * avoid without storage info macro ([#99](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/99)) ([abd6db1](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abd6db1c00940de65a71a50232962bc943e0aa39)) 26 | * Set extrinsic weight based on benchmarking ([#100](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/100)) ([d52594c](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d52594caecdd95ef9e259e1b31dc340d9059d41e)) 27 | 28 | ## 0.1.0 (2023-03-01) 29 | 30 | 31 | ### Features 32 | 33 | * Add runtime RPC call ([#55](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/55)) ([cd6e7ee](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cd6e7ee5748e89b32cb6c756f724ef9662e9be0c)) 34 | * Change generalIndex to generalKey in extract dest data method ([#62](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/62)) ([3422f01](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/3422f01acff51ed19bcae2159a34ac4f0968c0ad)) 35 | * Decimal converter ([#57](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/57)) ([9dddcd7](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/9dddcd77d1dad41ba7012896ae4a180d222da00f)) 36 | * Impl fee handler router ([#43](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/43)) ([efb6818](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/efb6818e7558b7142aa1954b90f32397ad87f4f6)) 37 | * Multi domain support ([#48](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/48)) ([f892602](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/f8926024df10a5b814c8b043ae70760e7c498e3e)) 38 | * Retry extrinisic changes ([#63](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/63)) ([798236c](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/798236c4fb9f130844c26e7b0ed487f3864cee07)) 39 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 40 | 41 | 42 | ### Bug Fixes 43 | 44 | * Fix for proposal execution ([#56](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/56)) ([8ea2b3d](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/8ea2b3da7a0ecb424160f45d34435e5b60f96243)) 45 | * Remove dependencies for toolchain mem-allocator/panic-handler ([#58](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/58)) ([54cf3cb](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/54cf3cb07832c79cac9a467e7119239cfb12311e)) 46 | * Reorder of transfer_type in Deposit event ([#50](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/50)) ([2c2ee18](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/2c2ee18d330340e5f78a853d8810102bec363f2b)) 47 | -------------------------------------------------------------------------------- /bridge/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-bridge" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | log = { version = "0.4.14", default-features = false } 11 | ethabi = { version = "18.0.0", default-features = false } 12 | primitive-types = { version = "0.12", default-features = false, features = ["scale-info", "serde_no_std"] } 13 | arrayref = { version = "0.3.6", default-features = false } 14 | funty = { version = "3.0.0-rc1", default-features = false } 15 | hex = {version = "0.4.3", default-features = false, features = ["alloc"] } 16 | fixed = {version = "1.23.0", default-features = false } 17 | bounded-collections = { version = "0.1.4", default-features = false } 18 | hex-literal = { version = "0.3", default-features = false } 19 | 20 | # Substrate 21 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 22 | sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 23 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 24 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 25 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 26 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 27 | frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, optional = true } 28 | sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 29 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 30 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 31 | 32 | # Polkadot 33 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 34 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 35 | xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 36 | 37 | # Cumulus 38 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 39 | cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 40 | cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 41 | 42 | # Local 43 | sygma-traits = { path = "../traits", default-features = false } 44 | sygma-access-segregator = { path = "../access-segregator", default-features = false } 45 | sygma-basic-feehandler = { path = "../basic-fee-handler", default-features = false } 46 | sygma-percentage-feehandler = { path = "../percentage-fee-handler", default-features = false } 47 | sygma-fee-handler-router = { path = "../fee-handler-router", default-features = false } 48 | sygma-bridge-forwarder = { path = "../bridge-forwarder", default-features = false } 49 | sygma-xcm-bridge = { path = "../xcm-bridge", default-features = false } 50 | 51 | [dev-dependencies] 52 | assert_matches = "1.4.0" 53 | hex-literal = "0.3" 54 | 55 | # Substrate 56 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 57 | sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 58 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 59 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 60 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 61 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 62 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 63 | pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 64 | 65 | # Polkadot 66 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 67 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 68 | xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 69 | polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0"} 70 | 71 | parachains-common = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 72 | 73 | # Local 74 | sygma-basic-feehandler = { path = "../basic-fee-handler" } 75 | sygma-traits = { path = "../traits" } 76 | 77 | [features] 78 | default = ["std"] 79 | runtime-benchmarks = [ 80 | 'frame-benchmarking', 81 | 'frame-support/runtime-benchmarks', 82 | 'frame-system/runtime-benchmarks', 83 | ] 84 | std = [ 85 | "codec/std", 86 | "scale-info/std", 87 | "log/std", 88 | "ethabi/std", 89 | "hex/std", 90 | "bounded-collections/std", 91 | "primitive-types/std", 92 | "sp-runtime/std", 93 | "sp-io/std", 94 | "sp-std/std", 95 | "sp-core/full_crypto", 96 | "sp-arithmetic/std", 97 | "frame-support/std", 98 | "frame-system/std", 99 | "frame-benchmarking/std", 100 | "cumulus-primitives-core/std", 101 | "cumulus-primitives-utility/std", 102 | "cumulus-pallet-xcm/std", 103 | "xcm/std", 104 | "xcm-builder/std", 105 | "xcm-executor/std", 106 | "pallet-balances/std", 107 | "pallet-assets/std", 108 | "sygma-traits/std", 109 | "sygma-access-segregator/std", 110 | "sygma-basic-feehandler/std", 111 | "sygma-percentage-feehandler/std", 112 | "sygma-fee-handler-router/std", 113 | "sygma-bridge-forwarder/std", 114 | "sygma-xcm-bridge/std", 115 | ] 116 | try-runtime = ["frame-support/try-runtime"] 117 | -------------------------------------------------------------------------------- /bridge/src/eip712.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | /// Port from https://github.com/gakonst/ethers-rs/blob/master/ethers-core/src/types/transaction/eip712.rs 5 | /// Replace hash provided by `sp_io` 6 | use ethabi::{ 7 | encode as abi_encode, 8 | ethereum_types::{Address, U256}, 9 | token::Token, 10 | }; 11 | use sp_io::hashing::keccak_256; 12 | use sp_std::{vec, vec::Vec}; 13 | 14 | /// Pre-computed value of the following statement: 15 | /// 16 | /// `keccak_256("EIP712Domain(string name,string version,uint256 chainId,address 17 | /// verifyingContract)")` 18 | pub const EIP712_DOMAIN_TYPE_HASH: [u8; 32] = [ 19 | 139, 115, 195, 198, 155, 184, 254, 61, 81, 46, 204, 76, 247, 89, 204, 121, 35, 159, 123, 23, 20 | 155, 15, 250, 202, 169, 167, 93, 82, 43, 57, 64, 15, 21 | ]; 22 | 23 | /// Pre-computed value of the following statement: 24 | /// 25 | /// `keccak_256("EIP712Domain(string name,string version,uint256 chainId,address 26 | /// verifyingContract,bytes32 salt)")` 27 | pub const EIP712_DOMAIN_TYPE_HASH_WITH_SALT: [u8; 32] = [ 28 | 216, 124, 214, 239, 121, 212, 226, 185, 94, 21, 206, 138, 191, 115, 45, 181, 30, 199, 113, 241, 29 | 202, 46, 220, 207, 34, 164, 108, 114, 154, 197, 100, 114, 30 | ]; 31 | 32 | /// Eip712 Domain attributes used in determining the domain separator; 33 | /// Unused fields are left out of the struct type. 34 | #[derive(Debug, Default, Clone)] 35 | pub struct EIP712Domain { 36 | /// The user readable name of signing domain, i.e. the name of the DApp or the protocol. 37 | pub name: Vec, 38 | 39 | /// The current major version of the signing domain. Signatures from different versions are not 40 | /// compatible. 41 | pub version: Vec, 42 | 43 | /// The EIP-155 chain id. The user-agent should refuse signing if it does not match the 44 | /// currently active chain. 45 | pub chain_id: U256, 46 | 47 | /// The address of the contract that will verify the signature. 48 | pub verifying_contract: Address, 49 | 50 | /// A disambiguating salt for the protocol. This can be used as a domain separator of last 51 | /// resort. 52 | pub salt: Option<[u8; 32]>, 53 | } 54 | 55 | impl EIP712Domain { 56 | // Compute the domain separator; 57 | // See: https://github.com/gakonst/ethers-rs/blob/master/examples/permit_hash.rs#L41 58 | pub fn separator(&self) -> [u8; 32] { 59 | let domain_type_hash = if self.salt.is_some() { 60 | EIP712_DOMAIN_TYPE_HASH_WITH_SALT 61 | } else { 62 | EIP712_DOMAIN_TYPE_HASH 63 | }; 64 | 65 | let mut tokens = vec![ 66 | Token::Uint(U256::from(domain_type_hash)), 67 | Token::Uint(U256::from(keccak_256(&self.name))), 68 | Token::Uint(U256::from(keccak_256(&self.version))), 69 | Token::Uint(self.chain_id), 70 | Token::Address(self.verifying_contract), 71 | ]; 72 | 73 | // Add the salt to the struct to be hashed if it exists; 74 | if let Some(salt) = &self.salt { 75 | tokens.push(Token::Uint(U256::from(salt))); 76 | } 77 | 78 | keccak_256(&abi_encode(&tokens)) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /bridge/src/encode.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | /// Port from https://github.com/roberts-ivanovs/eth-encode-packed-rs 5 | use ethabi::ethereum_types::{Address, U256}; 6 | 7 | pub struct TakeLastXBytes(pub usize); 8 | 9 | #[allow(dead_code)] 10 | pub enum SolidityDataType<'a> { 11 | String(&'a str), 12 | Address(Address), 13 | Bytes(&'a [u8]), 14 | Bool(bool), 15 | Number(U256), 16 | NumberWithShift(U256, TakeLastXBytes), 17 | } 18 | 19 | pub mod abi { 20 | use super::SolidityDataType; 21 | use sp_std::{vec, vec::Vec}; 22 | 23 | /// Pack a single `SolidityDataType` into bytes 24 | #[allow(clippy::needless_lifetimes)] 25 | fn pack<'a>(data_type: &'a SolidityDataType) -> Vec { 26 | let mut res = Vec::new(); 27 | match data_type { 28 | SolidityDataType::String(s) => { 29 | res.extend(s.as_bytes()); 30 | }, 31 | SolidityDataType::Address(a) => { 32 | res.extend(a.0); 33 | }, 34 | SolidityDataType::Number(n) => { 35 | for b in n.0.iter().rev() { 36 | let bytes = b.to_be_bytes(); 37 | res.extend(bytes); 38 | } 39 | }, 40 | SolidityDataType::Bytes(b) => { 41 | res.extend(*b); 42 | }, 43 | SolidityDataType::Bool(b) => { 44 | if *b { 45 | res.push(1); 46 | } else { 47 | res.push(0); 48 | } 49 | }, 50 | SolidityDataType::NumberWithShift(n, to_take) => { 51 | let local_res = n.0.iter().rev().fold(vec![], |mut acc, i| { 52 | let bytes = i.to_be_bytes(); 53 | acc.extend(bytes); 54 | acc 55 | }); 56 | 57 | let to_skip = local_res.len() - (to_take.0 / 8); 58 | let local_res = local_res.into_iter().skip(to_skip).collect::>(); 59 | res.extend(local_res); 60 | }, 61 | }; 62 | res 63 | } 64 | 65 | pub fn encode_packed(items: &[SolidityDataType]) -> Vec { 66 | let res = items.iter().fold(Vec::new(), |mut acc, i| { 67 | let pack = pack(i); 68 | acc.push(pack); 69 | acc 70 | }); 71 | res.join(&[][..]) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /bridge/src/migration.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #[allow(unused_imports)] 5 | use super::*; 6 | 7 | #[cfg(feature = "try-runtime")] 8 | use frame_support::ensure; 9 | use frame_support::traits::{Get, OnRuntimeUpgrade, StorageVersion}; 10 | use log; 11 | #[cfg(feature = "try-runtime")] 12 | use sp_std::vec::Vec; 13 | use sygma_traits::MpcAddress; 14 | 15 | const EXPECTED_STORAGE_VERSION: StorageVersion = StorageVersion::new(0); 16 | #[cfg(feature = "try-runtime")] 17 | const FINAL_STORAGE_VERSION: StorageVersion = StorageVersion::new(1); 18 | const MPC_ADDR: &str = "B01137123EF02fAeF251a39108c6ef513AAaC485"; 19 | 20 | pub struct FixMpcAddress(sp_std::marker::PhantomData); 21 | 22 | impl OnRuntimeUpgrade for FixMpcAddress { 23 | fn on_runtime_upgrade() -> frame_support::weights::Weight { 24 | if StorageVersion::get::>() == EXPECTED_STORAGE_VERSION { 25 | log::info!("Start sygma bridge migration"); 26 | 27 | let mut slice: [u8; 20] = [0; 20]; 28 | slice.copy_from_slice(&hex::decode(MPC_ADDR).unwrap()[..20]); 29 | MpcAddr::::kill(); 30 | MpcAddr::::set(MpcAddress(slice)); 31 | 32 | // Set new storage version to 1 33 | StorageVersion::new(1).put::>(); 34 | 35 | log::info!("Sygma bridge migration done👏"); 36 | 37 | // kill + set + put 38 | T::DbWeight::get().writes(3) 39 | } else { 40 | T::DbWeight::get().reads(1) 41 | } 42 | } 43 | 44 | #[cfg(feature = "try-runtime")] 45 | fn pre_upgrade() -> Result, &'static str> { 46 | ensure!( 47 | StorageVersion::get::>() == EXPECTED_STORAGE_VERSION, 48 | "Incorrect Sygma bridge storage version in pre migrate" 49 | ); 50 | 51 | log::info!("Sygma bridge pre migration check passed👏"); 52 | 53 | Ok(Vec::new()) 54 | } 55 | 56 | #[cfg(feature = "try-runtime")] 57 | fn post_upgrade(_state: Vec) -> Result<(), &'static str> { 58 | ensure!( 59 | StorageVersion::get::>() == FINAL_STORAGE_VERSION, 60 | "Incorrect Sygma bridge storage version in post migrate" 61 | ); 62 | 63 | let mut slice: [u8; 20] = [0; 20]; 64 | slice.copy_from_slice(&hex::decode(MPC_ADDR).unwrap()[..20]); 65 | ensure!(MpcAddr::::get() == MpcAddress(slice), "Unexpected MPC address in post migrate"); 66 | 67 | log::info!("Sygma bridge post migration check passed👏"); 68 | 69 | Ok(()) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sprintertech/sygma-substrate-pallets/57a61e733f5c2d5270e08fc889ec36f694a0ca3a/diagram.png -------------------------------------------------------------------------------- /docs/Fees.md: -------------------------------------------------------------------------------- 1 | # Fees 2 | 3 | #### Fee Handler Router 4 | 5 | [Fee Handler Router pallet](https://github.com/sygmaprotocol/sygma-substrate-pallets/blob/main/fee-handler-router/src/lib.rs) enables registration of different fee strategies per resource ID and domain ID, which facilitates [Sygma's approach to managing fees with granularity](https://github.com/sygmaprotocol/sygma-relayer/blob/main/docs/general/Fees.md#fees). 6 | 7 | To configure the router, pallet implements [`set_fee_handler`](https://github.com/sygmaprotocol/sygma-substrate-pallets/blob/main/fee-handler-router/src/lib.rs#L77) method. With this method, the administrator can register a particular fee strategy for bridging a resource (specified by the `asset` parameter) to a specific destination domain (specified by the `domain` parameter). 8 | 9 | #### Basic Fee Handler 10 | 11 | This handler facilitates static fee strategy 12 | 13 | #### Dynamic Fee Handler 14 | 15 | Dynamic Fee Handler processes fee estimate message that was provided on deposit and calculates fee amount that should be transfered as fee. Fee calculation inside fee handler is following this logic: 16 | 17 | ##### Token transfer: fee is paid in a token being transferred 18 | 19 | destination -> EVM 20 | 21 | `final_fee = feeOracleMsg.dstGasPrice * _gasUsed * feeOracleMsg.ter` 22 | 23 | destination -> Substrate 24 | 25 | `final_fee = feeOracleMsg.inclusionFee * feeOracleMsg.ter` 26 | 27 | ##### Generic messages: fee is paid in base currency 28 | 29 | destination -> EVM 30 | 31 | `final_fee = feeOracleMsg.dstGasPrice * feeOracleMsg.msgGasLimit * feeOracleMsg.ber` 32 | 33 | destination -> Substrate 34 | 35 | `final_fee = feeOracleMsg.inclusionFee * feeOracleMsg.ber` 36 | 37 | ![](/docs/resources/dynamic-fees-substrate.png) -------------------------------------------------------------------------------- /docs/Home.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sprintertech/sygma-substrate-pallets/57a61e733f5c2d5270e08fc889ec36f694a0ca3a/docs/Home.md -------------------------------------------------------------------------------- /docs/resources/dynamic-fees-substrate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sprintertech/sygma-substrate-pallets/57a61e733f5c2d5270e08fc889ec36f694a0ca3a/docs/resources/dynamic-fees-substrate.png -------------------------------------------------------------------------------- /dynamic-fee-handler/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sprintertech/sygma-substrate-pallets/57a61e733f5c2d5270e08fc889ec36f694a0ca3a/dynamic-fee-handler/.keep -------------------------------------------------------------------------------- /fee-handler-router/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.3.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-fee-handler-router-v0.2.0...sygma-fee-handler-router-v0.3.0) (2023-05-24) 4 | 5 | 6 | ### Features 7 | 8 | * Remove BridgeCommitteeOrigin from some pallets' config ([#104](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/104)) ([abfe1ff](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abfe1ffdf1d992d33be4cad9374bd5be92b87343)) 9 | 10 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-fee-handler-router-v0.1.0...sygma-fee-handler-router-v0.2.0) (2023-05-11) 11 | 12 | 13 | ### Features 14 | 15 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 16 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 17 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 18 | 19 | 20 | ### Bug Fixes 21 | 22 | * avoid without storage info macro ([#99](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/99)) ([abd6db1](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abd6db1c00940de65a71a50232962bc943e0aa39)) 23 | * Set extrinsic weight based on benchmarking ([#100](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/100)) ([d52594c](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d52594caecdd95ef9e259e1b31dc340d9059d41e)) 24 | 25 | ## 0.1.0 (2023-03-01) 26 | 27 | 28 | ### Features 29 | 30 | * Impl fee handler router ([#43](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/43)) ([efb6818](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/efb6818e7558b7142aa1954b90f32397ad87f4f6)) 31 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 32 | -------------------------------------------------------------------------------- /fee-handler-router/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-fee-handler-router" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | 11 | # Substrate 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, optional = true } 15 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | 17 | # Polkadot 18 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 20 | 21 | # Local 22 | sygma-traits = { path = "../traits", default-features = false } 23 | sygma-basic-feehandler = { path = "../basic-fee-handler", default-features = false } 24 | sygma-percentage-feehandler = { path = "../percentage-fee-handler", default-features = false } 25 | sygma-access-segregator = { path = "../access-segregator", default-features = false } 26 | 27 | [dev-dependencies] 28 | # Substrate 29 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 30 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 31 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 32 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 33 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 34 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 35 | 36 | sygma-access-segregator = { path = "../access-segregator" } 37 | sygma-basic-feehandler = { path = "../basic-fee-handler" } 38 | sygma-traits = { path = "../traits" } 39 | 40 | [features] 41 | default = ["std"] 42 | std = [ 43 | "codec/std", 44 | "scale-info/std", 45 | "frame-support/std", 46 | "frame-system/std", 47 | "frame-benchmarking/std", 48 | "sp-std/std", 49 | "xcm/std", 50 | "xcm-builder/std", 51 | "sygma-traits/std", 52 | "sygma-basic-feehandler/std", 53 | "sygma-percentage-feehandler/std", 54 | "sygma-access-segregator/std", 55 | ] 56 | runtime-benchmarks = [ 57 | 'frame-benchmarking', 58 | 'frame-support/runtime-benchmarks', 59 | 'frame-system/runtime-benchmarks', 60 | ] 61 | try-runtime = ["frame-support/try-runtime"] 62 | -------------------------------------------------------------------------------- /fee-handler-router/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Sygma basic-fee-handler pallet benchmarking. 5 | 6 | #![cfg(feature = "runtime-benchmarks")] 7 | use super::*; 8 | use frame_benchmarking::v2::*; 9 | use frame_system::RawOrigin as SystemOrigin; 10 | 11 | use sp_std::vec; 12 | use sygma_traits::DomainID; 13 | use xcm::latest::prelude::*; 14 | 15 | #[benchmarks] 16 | mod benchmarks { 17 | use super::*; 18 | 19 | #[benchmark] 20 | fn set_fee_handler() { 21 | let dest_domain_id: DomainID = 1; 22 | let native_location: MultiLocation = MultiLocation::here(); 23 | 24 | #[extrinsic_call] 25 | set_fee_handler( 26 | SystemOrigin::Root, 27 | dest_domain_id, 28 | Box::new(native_location.clone().into()), 29 | FeeHandlerType::BasicFeeHandler, 30 | ); 31 | 32 | assert_eq!( 33 | HandlerType::::get(&(dest_domain_id, native_location.into())), 34 | Some(FeeHandlerType::BasicFeeHandler), 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /fee-handler-router/src/mock.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use frame_support::{ 5 | pallet_prelude::ConstU32, 6 | parameter_types, 7 | sp_runtime::{ 8 | testing::H256, 9 | traits::{BlakeTwo256, IdentityLookup}, 10 | AccountId32, BuildStorage, Perbill, 11 | }, 12 | traits::{AsEnsureOriginWithArg, ConstU128}, 13 | }; 14 | use frame_system::{self as system, EnsureRoot, EnsureSigned}; 15 | use sygma_traits::DomainID; 16 | use xcm::latest::MultiLocation; 17 | 18 | use crate as fee_handler_router; 19 | 20 | type Block = frame_system::mocking::MockBlock; 21 | 22 | pub(crate) type Balance = u128; 23 | 24 | pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); 25 | 26 | frame_support::construct_runtime!( 27 | pub enum Test { 28 | System: frame_system, 29 | Assets: pallet_assets::{Pallet, Call, Storage, Event}, 30 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 31 | AccessSegregator: sygma_access_segregator::{Pallet, Call, Storage, Event} = 3, 32 | SygmaBasicFeeHandler: sygma_basic_feehandler::{Pallet, Call, Storage, Event} = 4, 33 | FeeHandlerRouter: fee_handler_router::{Pallet, Call, Storage, Event} = 5, 34 | SygamPercenrageFeeHandler: sygma_percentage_feehandler::{Pallet, Call, Storage, Event} = 6, 35 | } 36 | ); 37 | 38 | parameter_types! { 39 | pub const BlockHashCount: u64 = 250; 40 | pub const MaximumBlockLength: u32 = 2 * 1024; 41 | pub const AvailableBlockRatio: Perbill = Perbill::one(); 42 | pub const MaxLocks: u32 = 100; 43 | pub const MinimumPeriod: u64 = 1; 44 | } 45 | 46 | impl frame_system::Config for Test { 47 | type BaseCallFilter = frame_support::traits::Everything; 48 | type Block = Block; 49 | type BlockWeights = (); 50 | type BlockLength = (); 51 | type RuntimeOrigin = RuntimeOrigin; 52 | type RuntimeCall = RuntimeCall; 53 | type Nonce = u64; 54 | type Hash = H256; 55 | type Hashing = BlakeTwo256; 56 | type AccountId = AccountId32; 57 | type Lookup = IdentityLookup; 58 | type RuntimeEvent = RuntimeEvent; 59 | type BlockHashCount = BlockHashCount; 60 | type DbWeight = (); 61 | type Version = (); 62 | type PalletInfo = PalletInfo; 63 | type AccountData = pallet_balances::AccountData; 64 | type OnNewAccount = (); 65 | type OnKilledAccount = (); 66 | type SystemWeightInfo = (); 67 | type SS58Prefix = (); 68 | type OnSetCode = (); 69 | type MaxConsumers = ConstU32<2>; 70 | } 71 | 72 | parameter_types! { 73 | pub const ExistentialDeposit: Balance = 1; 74 | } 75 | 76 | impl pallet_balances::Config for Test { 77 | type Balance = Balance; 78 | type DustRemoval = (); 79 | type RuntimeEvent = RuntimeEvent; 80 | type ExistentialDeposit = ExistentialDeposit; 81 | type AccountStore = System; 82 | type WeightInfo = (); 83 | type MaxLocks = (); 84 | type MaxReserves = (); 85 | type ReserveIdentifier = [u8; 8]; 86 | type FreezeIdentifier = (); 87 | type MaxFreezes = (); 88 | type RuntimeHoldReason = (); 89 | type MaxHolds = (); 90 | } 91 | 92 | parameter_types! { 93 | pub const AssetDeposit: Balance = 1; // 1 Unit deposit to create asset 94 | pub const ApprovalDeposit: Balance = 1; 95 | pub const AssetsStringLimit: u32 = 50; 96 | pub const MetadataDepositBase: Balance = 1; 97 | pub const MetadataDepositPerByte: Balance = 1; 98 | } 99 | 100 | impl pallet_assets::Config for Test { 101 | type RuntimeEvent = RuntimeEvent; 102 | type Balance = Balance; 103 | type AssetId = u32; 104 | type AssetIdParameter = codec::Compact; 105 | type Currency = Balances; 106 | type CreateOrigin = AsEnsureOriginWithArg>; 107 | type ForceOrigin = frame_system::EnsureRoot; 108 | type AssetDeposit = AssetDeposit; 109 | type AssetAccountDeposit = ConstU128<10>; 110 | type MetadataDepositBase = MetadataDepositBase; 111 | type MetadataDepositPerByte = MetadataDepositPerByte; 112 | type ApprovalDeposit = ApprovalDeposit; 113 | type StringLimit = AssetsStringLimit; 114 | type RemoveItemsLimit = ConstU32<1000>; 115 | type Freezer = (); 116 | type Extra = (); 117 | type CallbackHandle = (); 118 | type WeightInfo = pallet_assets::weights::SubstrateWeight; 119 | #[cfg(feature = "runtime-benchmarks")] 120 | type BenchmarkHelper = (); 121 | } 122 | 123 | parameter_types! { 124 | pub const EthereumDomainID: DomainID = 0; 125 | pub const MoonbeamDomainID: DomainID = 1; 126 | // Make sure put same value with `construct_runtime` 127 | pub const AccessSegregatorPalletIndex: u8 = 3; 128 | pub const BasicFeeHandlerPalletIndex: u8 = 4; 129 | pub const FeeHandlerRouterPalletIndex: u8 = 5; 130 | pub const PercentageFeeHandlerPalletIndex: u8 = 6; 131 | pub RegisteredExtrinsics: Vec<(u8, Vec)> = [ 132 | (AccessSegregatorPalletIndex::get(), b"grant_access".to_vec()), 133 | (FeeHandlerRouterPalletIndex::get(), b"set_fee_handler".to_vec()), 134 | ].to_vec(); 135 | pub PhaLocation: MultiLocation = MultiLocation::here(); 136 | } 137 | 138 | impl sygma_basic_feehandler::Config for Test { 139 | type RuntimeEvent = RuntimeEvent; 140 | type PalletIndex = BasicFeeHandlerPalletIndex; 141 | type WeightInfo = sygma_basic_feehandler::weights::SygmaWeightInfo; 142 | } 143 | 144 | impl sygma_access_segregator::Config for Test { 145 | type RuntimeEvent = RuntimeEvent; 146 | type BridgeCommitteeOrigin = EnsureRoot; 147 | type PalletIndex = AccessSegregatorPalletIndex; 148 | type Extrinsics = RegisteredExtrinsics; 149 | type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo; 150 | } 151 | 152 | impl fee_handler_router::Config for Test { 153 | type RuntimeEvent = RuntimeEvent; 154 | type BasicFeeHandler = SygmaBasicFeeHandler; 155 | type DynamicFeeHandler = (); 156 | type PercentageFeeHandler = SygamPercenrageFeeHandler; 157 | type PalletIndex = FeeHandlerRouterPalletIndex; 158 | type WeightInfo = fee_handler_router::weights::SygmaWeightInfo; 159 | } 160 | 161 | impl sygma_percentage_feehandler::Config for Test { 162 | type RuntimeEvent = RuntimeEvent; 163 | type PalletIndex = PercentageFeeHandlerPalletIndex; 164 | type WeightInfo = sygma_percentage_feehandler::weights::SygmaWeightInfo; 165 | } 166 | 167 | pub fn new_test_ext() -> sp_io::TestExternalities { 168 | let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 169 | let mut ext = sp_io::TestExternalities::new(t); 170 | ext.execute_with(|| System::set_block_number(1)); 171 | ext 172 | } 173 | 174 | // Checks events against the latest. A contiguous set of events must be provided. They must 175 | // include the most recent event, but do not have to include every past event. 176 | pub fn assert_events(mut expected: Vec) { 177 | let mut actual: Vec = 178 | system::Pallet::::events().iter().map(|e| e.event.clone()).collect(); 179 | 180 | expected.reverse(); 181 | 182 | for evt in expected { 183 | let next = actual.pop().expect("event expected"); 184 | assert_eq!(next, evt, "Events don't match"); 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /fee-handler-router/src/weights.rs: -------------------------------------------------------------------------------- 1 | 2 | //! Autogenerated weights for `sygma_fee_handler_router` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 5 | //! DATE: 2023-04-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 6 | //! WORST CASE MAP SIZE: `1000000` 7 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 8 | 9 | // Executed Command: 10 | // ./target/release/standalone-node-template 11 | // benchmark 12 | // pallet 13 | // --chain 14 | // dev 15 | // --execution=wasm 16 | // --wasm-execution=compiled 17 | // --pallet 18 | // sygma_fee_handler_router 19 | // --extrinsic 20 | // * 21 | // --steps 22 | // 50 23 | // --repeat 24 | // 20 25 | // --output 26 | // feehandler_router_weight.rs 27 | 28 | #![cfg_attr(rustfmt, rustfmt_skip)] 29 | #![allow(unused_parens)] 30 | #![allow(unused_imports)] 31 | 32 | use frame_support::{traits::Get, weights::Weight}; 33 | use sp_std::marker::PhantomData; 34 | 35 | /// Weight functions for `sygma_fee_handler_router`. 36 | pub struct SygmaWeightInfo(PhantomData); 37 | impl super::WeightInfo for SygmaWeightInfo { 38 | /// Storage: SygmaFeeHandlerRouter HandlerType (r:0 w:1) 39 | /// Proof Skipped: SygmaFeeHandlerRouter HandlerType (max_values: None, max_size: None, mode: Measured) 40 | fn set_fee_handler() -> Weight { 41 | // Proof Size summary in bytes: 42 | // Measured: `0` 43 | // Estimated: `0` 44 | // Minimum execution time: 9_000_000 picoseconds. 45 | Weight::from_parts(9_000_000, 0) 46 | .saturating_add(Weight::from_parts(0, 0)) 47 | .saturating_add(T::DbWeight::get().writes(1)) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /parachain-info/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | authors = ["Parity Technologies "] 3 | edition = "2021" 4 | name = "pallet-parachain-info" 5 | version = "0.1.0" 6 | license = "LGPL-3.0" 7 | 8 | [dependencies] 9 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } 10 | scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } 11 | 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 15 | 16 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 17 | 18 | [features] 19 | default = ["std"] 20 | std = [ 21 | "codec/std", 22 | "scale-info/std", 23 | "cumulus-primitives-core/std", 24 | "frame-support/std", 25 | "frame-system/std", 26 | "sp-runtime/std", 27 | ] 28 | try-runtime = ["frame-support/try-runtime"] 29 | -------------------------------------------------------------------------------- /parachain-info/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020-2021 Parity Technologies (UK) Ltd. 2 | // This file is part of Cumulus. 3 | 4 | // Cumulus is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Cumulus is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Cumulus. If not, see . 16 | 17 | //! Minimal Pallet that injects a ParachainId into Runtime storage from 18 | 19 | #![cfg_attr(not(feature = "std"), no_std)] 20 | 21 | pub use pallet::*; 22 | 23 | #[frame_support::pallet] 24 | pub mod pallet { 25 | use cumulus_primitives_core::ParaId; 26 | use frame_support::{pallet_prelude::*, traits::BuildGenesisConfig}; 27 | use frame_system::pallet_prelude::*; 28 | 29 | #[pallet::pallet] 30 | #[pallet::without_storage_info] 31 | pub struct Pallet(_); 32 | 33 | #[pallet::config] 34 | pub trait Config: frame_system::Config {} 35 | 36 | #[pallet::hooks] 37 | impl Hooks> for Pallet {} 38 | 39 | #[pallet::call] 40 | impl Pallet {} 41 | 42 | #[pallet::genesis_config] 43 | pub struct GenesisConfig { 44 | pub parachain_id: ParaId, 45 | pub phantom: PhantomData, 46 | } 47 | 48 | impl Default for GenesisConfig { 49 | fn default() -> Self { 50 | Self { parachain_id: 100.into(), phantom: PhantomData } 51 | } 52 | } 53 | 54 | #[pallet::genesis_build] 55 | impl BuildGenesisConfig for GenesisConfig { 56 | fn build(&self) { 57 | >::put(self.parachain_id); 58 | } 59 | } 60 | 61 | #[pallet::type_value] 62 | pub(super) fn DefaultForParachainId() -> ParaId { 63 | 100.into() 64 | } 65 | 66 | #[pallet::storage] 67 | #[pallet::getter(fn parachain_id)] 68 | pub(super) type ParachainId = 69 | StorageValue<_, ParaId, ValueQuery, DefaultForParachainId>; 70 | 71 | impl Get for Pallet { 72 | fn get() -> ParaId { 73 | Self::parachain_id() 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /percentage-fee-handler/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-percentage-feehandler" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | 11 | # Substrate 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false, optional = true } 15 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | 17 | # Polkadot 18 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 20 | 21 | # Local 22 | sygma-traits = { path = "../traits", default-features = false } 23 | sygma-access-segregator = { path = "../access-segregator", default-features = false } 24 | 25 | [dev-dependencies] 26 | # Substrate 27 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 28 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 29 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 30 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 31 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 32 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 33 | 34 | [features] 35 | default = ["std"] 36 | std = [ 37 | "codec/std", 38 | "scale-info/std", 39 | "frame-support/std", 40 | "frame-system/std", 41 | "frame-benchmarking/std", 42 | "sp-std/std", 43 | "xcm/std", 44 | "xcm-builder/std", 45 | "sygma-traits/std", 46 | "sygma-access-segregator/std", 47 | ] 48 | runtime-benchmarks = [ 49 | 'frame-benchmarking', 50 | 'frame-support/runtime-benchmarks', 51 | 'frame-system/runtime-benchmarks', 52 | ] 53 | try-runtime = ["frame-support/try-runtime"] 54 | 55 | -------------------------------------------------------------------------------- /percentage-fee-handler/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Sygma percentage-fee-handler pallet benchmarking. 5 | 6 | #![cfg(feature = "runtime-benchmarks")] 7 | use super::*; 8 | use frame_benchmarking::v2::*; 9 | use frame_system::RawOrigin as SystemOrigin; 10 | 11 | use sp_std::vec; 12 | use sygma_traits::DomainID; 13 | use xcm::latest::prelude::*; 14 | 15 | #[benchmarks] 16 | mod benchmarks { 17 | use super::*; 18 | 19 | #[benchmark] 20 | fn set_fee_rate() { 21 | let dest_domain_id: DomainID = 1; 22 | let native_location: MultiLocation = MultiLocation::here(); 23 | let fee_rate = 500u32; // 5% 24 | 25 | #[extrinsic_call] 26 | set_fee_rate( 27 | SystemOrigin::Root, 28 | dest_domain_id, 29 | Box::new(native_location.clone().into()), 30 | fee_rate, 31 | 0u128, 32 | 100_000_000_000_000u128, 33 | ); 34 | 35 | assert_eq!( 36 | AssetFeeRate::::get(&(dest_domain_id, native_location.into())), 37 | Some((fee_rate, 0u128, 100_000_000_000_000u128)), 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /percentage-fee-handler/src/mock.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use frame_support::{ 5 | pallet_prelude::ConstU32, 6 | parameter_types, 7 | sp_runtime::{ 8 | testing::H256, 9 | traits::{BlakeTwo256, IdentityLookup}, 10 | AccountId32, BuildStorage, Perbill, 11 | }, 12 | traits::{AsEnsureOriginWithArg, ConstU128}, 13 | }; 14 | use frame_system::{self as system, EnsureRoot, EnsureSigned}; 15 | 16 | use crate as percentage_fee_handler; 17 | 18 | type Block = frame_system::mocking::MockBlock; 19 | 20 | pub(crate) type Balance = u128; 21 | 22 | pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); 23 | 24 | frame_support::construct_runtime!( 25 | pub enum Test { 26 | System: frame_system, 27 | Assets: pallet_assets::{Pallet, Call, Storage, Event}, 28 | Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, 29 | AccessSegregator: sygma_access_segregator::{Pallet, Call, Storage, Event} = 3, 30 | PercentageFeeHandler: percentage_fee_handler::{Pallet, Call, Storage, Event} = 4, 31 | } 32 | ); 33 | 34 | parameter_types! { 35 | pub const BlockHashCount: u64 = 250; 36 | pub const MaximumBlockLength: u32 = 2 * 1024; 37 | pub const AvailableBlockRatio: Perbill = Perbill::one(); 38 | pub const MaxLocks: u32 = 100; 39 | pub const MinimumPeriod: u64 = 1; 40 | } 41 | 42 | impl frame_system::Config for Test { 43 | type BaseCallFilter = frame_support::traits::Everything; 44 | type Block = Block; 45 | type BlockWeights = (); 46 | type BlockLength = (); 47 | type RuntimeOrigin = RuntimeOrigin; 48 | type RuntimeCall = RuntimeCall; 49 | type Nonce = u64; 50 | type Hash = H256; 51 | type Hashing = BlakeTwo256; 52 | type AccountId = AccountId32; 53 | type Lookup = IdentityLookup; 54 | type RuntimeEvent = RuntimeEvent; 55 | type BlockHashCount = BlockHashCount; 56 | type DbWeight = (); 57 | type Version = (); 58 | type PalletInfo = PalletInfo; 59 | type AccountData = pallet_balances::AccountData; 60 | type OnNewAccount = (); 61 | type OnKilledAccount = (); 62 | type SystemWeightInfo = (); 63 | type SS58Prefix = (); 64 | type OnSetCode = (); 65 | type MaxConsumers = ConstU32<2>; 66 | } 67 | 68 | parameter_types! { 69 | pub const ExistentialDeposit: Balance = 1; 70 | } 71 | 72 | impl pallet_balances::Config for Test { 73 | type Balance = Balance; 74 | type DustRemoval = (); 75 | type RuntimeEvent = RuntimeEvent; 76 | type ExistentialDeposit = ExistentialDeposit; 77 | type AccountStore = System; 78 | type WeightInfo = (); 79 | type MaxLocks = (); 80 | type MaxReserves = (); 81 | type ReserveIdentifier = [u8; 8]; 82 | type FreezeIdentifier = (); 83 | type MaxFreezes = (); 84 | type RuntimeHoldReason = (); 85 | type MaxHolds = (); 86 | } 87 | 88 | parameter_types! { 89 | pub const AssetDeposit: Balance = 1; // 1 Unit deposit to create asset 90 | pub const ApprovalDeposit: Balance = 1; 91 | pub const AssetsStringLimit: u32 = 50; 92 | pub const MetadataDepositBase: Balance = 1; 93 | pub const MetadataDepositPerByte: Balance = 1; 94 | } 95 | 96 | impl pallet_assets::Config for Test { 97 | type RuntimeEvent = RuntimeEvent; 98 | type Balance = Balance; 99 | type AssetId = u32; 100 | type AssetIdParameter = codec::Compact; 101 | type Currency = Balances; 102 | type CreateOrigin = AsEnsureOriginWithArg>; 103 | type ForceOrigin = frame_system::EnsureRoot; 104 | type AssetDeposit = AssetDeposit; 105 | type AssetAccountDeposit = ConstU128<10>; 106 | type MetadataDepositBase = MetadataDepositBase; 107 | type MetadataDepositPerByte = MetadataDepositPerByte; 108 | type ApprovalDeposit = ApprovalDeposit; 109 | type StringLimit = AssetsStringLimit; 110 | type RemoveItemsLimit = ConstU32<1000>; 111 | type Freezer = (); 112 | type Extra = (); 113 | type CallbackHandle = (); 114 | type WeightInfo = pallet_assets::weights::SubstrateWeight; 115 | #[cfg(feature = "runtime-benchmarks")] 116 | type BenchmarkHelper = (); 117 | } 118 | 119 | parameter_types! { 120 | // Make sure put same value with `construct_runtime` 121 | pub const AccessSegregatorPalletIndex: u8 = 3; 122 | pub const PercentageFeeHandlerPalletIndex: u8 = 4; 123 | pub RegisteredExtrinsics: Vec<(u8, Vec)> = [ 124 | (AccessSegregatorPalletIndex::get(), b"grant_access".to_vec()), 125 | (PercentageFeeHandlerPalletIndex::get(), b"set_fee_rate".to_vec()), 126 | ].to_vec(); 127 | } 128 | 129 | impl sygma_access_segregator::Config for Test { 130 | type RuntimeEvent = RuntimeEvent; 131 | type BridgeCommitteeOrigin = EnsureRoot; 132 | type PalletIndex = AccessSegregatorPalletIndex; 133 | type Extrinsics = RegisteredExtrinsics; 134 | type WeightInfo = sygma_access_segregator::weights::SygmaWeightInfo; 135 | } 136 | 137 | impl percentage_fee_handler::Config for Test { 138 | type RuntimeEvent = RuntimeEvent; 139 | type PalletIndex = PercentageFeeHandlerPalletIndex; 140 | type WeightInfo = percentage_fee_handler::weights::SygmaWeightInfo; 141 | } 142 | 143 | pub fn new_test_ext() -> sp_io::TestExternalities { 144 | let t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 145 | let mut ext = sp_io::TestExternalities::new(t); 146 | ext.execute_with(|| System::set_block_number(1)); 147 | ext 148 | } 149 | 150 | // Checks events against the latest. A contiguous set of events must be provided. They must 151 | // include the most recent event, but do not have to include every past event. 152 | pub fn assert_events(mut expected: Vec) { 153 | let mut actual: Vec = 154 | system::Pallet::::events().iter().map(|e| e.event.clone()).collect(); 155 | 156 | expected.reverse(); 157 | 158 | for evt in expected { 159 | let next = actual.pop().expect("event expected"); 160 | assert_eq!(next, evt, "Events don't match"); 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /percentage-fee-handler/src/weights.rs: -------------------------------------------------------------------------------- 1 | 2 | //! Autogenerated weights for `sygma_percentage_feehandler` 3 | //! 4 | //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev 5 | //! DATE: 2023-07-26, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` 6 | //! WORST CASE MAP SIZE: `1000000` 7 | //! HOSTNAME: `Freddys-MacBook-Pro-15.local`, CPU: `` 8 | //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 9 | 10 | // Executed Command: 11 | // ./target/release/standalone-node-template 12 | // benchmark 13 | // pallet 14 | // --chain 15 | // dev 16 | // --execution=wasm 17 | // --wasm-execution=compiled 18 | // --pallet 19 | // sygma_percentage_feehandler 20 | // --extrinsic 21 | // * 22 | // --steps 23 | // 50 24 | // --repeat 25 | // 20 26 | // --output 27 | // percentage_feehandler_weight.rs 28 | 29 | #![cfg_attr(rustfmt, rustfmt_skip)] 30 | #![allow(unused_parens)] 31 | #![allow(unused_imports)] 32 | #![allow(missing_docs)] 33 | 34 | use frame_support::{traits::Get, weights::Weight}; 35 | use core::marker::PhantomData; 36 | 37 | /// Weight functions for `sygma_percentage_feehandler`. 38 | pub struct SygmaWeightInfo(PhantomData); 39 | impl super::WeightInfo for SygmaWeightInfo { 40 | /// Storage: SygmaPercentageFeeHandler AssetFeeRate (r:0 w:1) 41 | /// Proof: SygmaPercentageFeeHandler AssetFeeRate (max_values: None, max_size: Some(648), added: 3123, mode: MaxEncodedLen) 42 | fn set_fee_rate() -> Weight { 43 | // Proof Size summary in bytes: 44 | // Measured: `0` 45 | // Estimated: `0` 46 | // Minimum execution time: 31_000_000 picoseconds. 47 | Weight::from_parts(32_000_000, 0) 48 | .saturating_add(Weight::from_parts(0, 0)) 49 | .saturating_add(T::DbWeight::get().writes(1)) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "bootstrap-sha": "da515d6007f2927e8c6cefd22e99da7d2dcb6fbf", 3 | "plugins": ["cargo-workspace"], 4 | "release-type": "rust", 5 | "packages": { 6 | "access-segregator": {}, 7 | "basic-fee-handler": {}, 8 | "bridge": {}, 9 | "dynamic-fee-handler": {}, 10 | "fee-handler-router": {}, 11 | "rpc": {}, 12 | "runtime-api": {}, 13 | "traits": {} 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /rpc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 4 | 5 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-rpc-v0.1.0...sygma-rpc-v0.2.0) (2023-05-11) 6 | 7 | 8 | ### Features 9 | 10 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 11 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 12 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 13 | 14 | ## 0.1.0 (2023-03-01) 15 | 16 | 17 | ### Features 18 | 19 | * Add runtime RPC call ([#55](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/55)) ([cd6e7ee](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cd6e7ee5748e89b32cb6c756f724ef9662e9be0c)) 20 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 21 | -------------------------------------------------------------------------------- /rpc/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-rpc" 3 | version = "0.2.1" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1" } 9 | scale-info = { version = "2.5.0" } 10 | jsonrpsee = { version = "0.16.2", features = ["server", "macros"] } 11 | 12 | # Substrate 13 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 14 | sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 15 | sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 16 | sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 17 | sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 18 | 19 | sygma-runtime-api = { path = "../runtime-api", default-features = false } 20 | sygma-traits = { path = "../traits", default-features = false } 21 | 22 | [features] 23 | default = ["std"] 24 | std = [ 25 | "codec/std", 26 | "scale-info/std", 27 | "sp-runtime/std", 28 | "sp-api/std", 29 | "sygma-runtime-api/std", 30 | "sygma-traits/std", 31 | ] 32 | -------------------------------------------------------------------------------- /rpc/src/lib.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | use std::{marker::PhantomData, sync::Arc}; 4 | 5 | use jsonrpsee::{ 6 | core::{async_trait, Error as JsonRpseeError, RpcResult}, 7 | proc_macros::rpc, 8 | }; 9 | use sp_api::{BlockT, ProvideRuntimeApi}; 10 | use sp_blockchain::HeaderBackend; 11 | use sygma_runtime_api::SygmaBridgeApi; 12 | use sygma_traits::{DepositNonce, DomainID}; 13 | 14 | pub struct SygmaBridgeStorage { 15 | client: Arc, 16 | _marker: PhantomData, 17 | } 18 | 19 | impl SygmaBridgeStorage { 20 | /// Create new `SygmaBridgeStorage` instance with the given reference to the client. 21 | pub fn new(client: Arc) -> Self { 22 | Self { client, _marker: Default::default() } 23 | } 24 | } 25 | 26 | #[rpc(server, namespace = "sygma")] 27 | pub trait SygmaBridgeRpc { 28 | #[method(name = "isProposalExecuted")] 29 | fn is_proposal_executed( 30 | &self, 31 | nonce: DepositNonce, 32 | domain_id: DomainID, 33 | at: Option, 34 | ) -> RpcResult; 35 | } 36 | 37 | #[async_trait] 38 | impl SygmaBridgeRpcServer<::Hash> for SygmaBridgeStorage 39 | where 40 | Block: BlockT, 41 | C: Send + Sync + 'static, 42 | C: ProvideRuntimeApi, 43 | C: HeaderBackend, 44 | C::Api: SygmaBridgeApi, 45 | { 46 | fn is_proposal_executed( 47 | &self, 48 | nonce: DepositNonce, 49 | domain_id: DomainID, 50 | at: Option<::Hash>, 51 | ) -> RpcResult { 52 | let api = self.client.runtime_api(); 53 | let at = at.unwrap_or_else(|| self.client.info().best_hash); 54 | 55 | let runtime_api_result = api.is_proposal_executed(at, nonce, domain_id); 56 | runtime_api_result.map_err(|e| JsonRpseeError::Custom(format!("runtime error: {e:?}"))) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /runtime-api/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | 4 | 5 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-runtime-api-v0.1.0...sygma-runtime-api-v0.2.0) (2023-05-11) 6 | 7 | 8 | ### Features 9 | 10 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 11 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 12 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 13 | 14 | ## 0.1.0 (2023-03-01) 15 | 16 | 17 | ### Features 18 | 19 | * Add runtime RPC call ([#55](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/55)) ([cd6e7ee](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cd6e7ee5748e89b32cb6c756f724ef9662e9be0c)) 20 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 21 | -------------------------------------------------------------------------------- /runtime-api/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-runtime-api" 3 | version = "0.2.1" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | # Substrate 9 | sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 10 | 11 | sygma-bridge = { path = "../bridge", default-features = false } 12 | sygma-traits = { path = "../traits", default-features = false } 13 | 14 | [features] 15 | default = ["std"] 16 | std = [ 17 | "sp-api/std", 18 | "sygma-traits/std", 19 | "sygma-bridge/std", 20 | ] 21 | -------------------------------------------------------------------------------- /runtime-api/src/lib.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #![cfg_attr(not(feature = "std"), no_std)] 5 | 6 | use sygma_traits::{DepositNonce, DomainID}; 7 | 8 | sp_api::decl_runtime_apis! { 9 | pub trait SygmaBridgeApi { 10 | fn is_proposal_executed(nonce: DepositNonce, domain_id: DomainID) -> bool; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /rust-toolchain: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "1.79.0" 3 | components = ["rustfmt"] 4 | targets = ["wasm32-unknown-unknown"] 5 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | # Basic 2 | hard_tabs = true 3 | max_width = 100 4 | use_small_heuristics = "Max" 5 | # Imports 6 | imports_granularity = "Crate" 7 | reorder_imports = true 8 | # Consistency 9 | newline_style = "Unix" 10 | # Format comments 11 | comment_width = 100 12 | wrap_comments = true 13 | # Misc 14 | chain_width = 80 15 | spaces_around_ranges = false 16 | binop_separator = "Back" 17 | reorder_impl_items = false 18 | match_arm_leading_pipes = "Preserve" 19 | match_arm_blocks = false 20 | match_block_trailing_comma = true 21 | trailing_comma = "Vertical" 22 | trailing_semicolon = false 23 | use_field_init_shorthand = true 24 | edition = "2021" -------------------------------------------------------------------------------- /scripts/e2e_setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # The Licensed Work is (c) 2022 Sygma 3 | # SPDX-License-Identifier: LGPL-3.0-only 4 | 5 | set -e 6 | 7 | NODE_DB_DIR=${PWD}/db 8 | 9 | # Run dev node 10 | echo "start the dev node up..." 11 | ./standalone-node-template --dev --rpc-external --base-path "$NODE_DB_DIR" > substrate_node.log 2>&1 & 12 | 13 | echo "waiting for dev node start..." 14 | sleep 60 15 | 16 | SETUP_SCRIPTS_DIR=${PWD} 17 | CHAINSPECFILE="chain-spec.json" 18 | 19 | # Run setup script 20 | echo "run scripts to set up pallets..." 21 | npm i --prefix $SETUP_SCRIPTS_DIR/scripts/standalone 22 | node $SETUP_SCRIPTS_DIR/scripts/standalone/setup.js 23 | 24 | sleep 10 25 | 26 | # Run chain snapshot after setup 27 | echo "set up is done, now export the chain state..." 28 | ./standalone-node-template export-state > $CHAINSPECFILE 29 | 30 | # Stop the node 31 | echo "stopping the dev node..." 32 | nPid=`pgrep -f "standalone-node-template"` 33 | if [ "$nPid" ] 34 | then 35 | echo "terminating dev node" 36 | kill $nPid 37 | fi 38 | 39 | echo "done" 40 | -------------------------------------------------------------------------------- /scripts/header.txt: -------------------------------------------------------------------------------- 1 | The Licensed Work is (c) 2022 Sygma 2 | SPDX-License-Identifier: LGPL-3.0-only -------------------------------------------------------------------------------- /scripts/phala-subbridge/e2e_setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # The Licensed Work is (c) 2022 Sygma 3 | # SPDX-License-Identifier: LGPL-3.0-only 4 | 5 | set -e 6 | 7 | SETUP_SCRIPTS_DIR=${PWD} 8 | 9 | echo $SETUP_SCRIPTS_DIR 10 | 11 | yarn --cwd $SETUP_SCRIPTS_DIR start khala-e2e.config.json > subbridge_node_launching.log 2>&1 & 12 | 13 | echo "waiting for relay chain nodes and parachain nodes start..." 14 | sleep 60 15 | 16 | # Run setup script 17 | echo "run scripts to set up sygma pallets..." 18 | npm i --prefix $SETUP_SCRIPTS_DIR/scripts 19 | node $SETUP_SCRIPTS_DIR/scripts/setup_sygma.js 20 | 21 | # Stop the node 22 | echo "stopping the relaychain node..." 23 | pkill polkadot 24 | 25 | echo "stopping the parachain node..." 26 | pkill khala-node 27 | 28 | echo "done" 29 | -------------------------------------------------------------------------------- /scripts/phala-subbridge/khala-e2e.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "relaychain": { 3 | "bin": "./bin/polkadot", 4 | "chain": "rococo-local", 5 | "nodes": [ 6 | { 7 | "name": "alice", 8 | "wsPort": 19944, 9 | "port": 10333, 10 | "nodeKey": "807e26fb3fd3d694b8b5f78a04d4bcff2e94a6f2e87bc809d9690e771bba8aca", 11 | "basePath": "data/relay_alice", 12 | "flags": [ 13 | "--rpc-cors=all" 14 | ] 15 | }, 16 | { 17 | "name": "bob", 18 | "wsPort": 19244, 19 | "port": 12333, 20 | "basePath": "data/relay_bob" 21 | }, 22 | { 23 | "name": "charlie", 24 | "wsPort": 19344, 25 | "port": 13333, 26 | "basePath": "data/relay_charlie" 27 | }, 28 | { 29 | "name": "dave", 30 | "wsPort": 19444, 31 | "port": 14333, 32 | "basePath": "data/relay_dave" 33 | } 34 | ], 35 | "genesis": { 36 | "runtime": { 37 | "runtime_genesis_config": { 38 | "configuration": { 39 | "config": { 40 | "validation_upgrade_frequency": 10, 41 | "validation_upgrade_delay": 10 42 | } 43 | } 44 | } 45 | } 46 | } 47 | }, 48 | "parachains": [ 49 | { 50 | "bin": "./bin/khala-node", 51 | "chain": "thala-dev-2004", 52 | "balance": "1000000000000000000000", 53 | "nodes": [ 54 | { 55 | "name": "alice", 56 | "wsPort": 9944, 57 | "port": 30333, 58 | "nodeKey": "81bbf2ee046d4f57ab9ce02e822ac2a3192e4a7b38af757383f3dcb039c15e05", 59 | "basePath": "data/para_alice", 60 | "flags": [ 61 | "--ws-external", 62 | "--rpc-external", 63 | "--rpc-cors=all", 64 | "--rpc-methods=Unsafe", 65 | "-lsygma-wrapper=trace", 66 | "-lassets-registry=trace", 67 | "-lfungbible-adapter=trace", 68 | "--", 69 | "--node-key=1335ac151f2d804189bfc68bd0843a676a3dc2aa6a208326970a75e6c75d4226", 70 | "--port=30334", 71 | "--ws-port=9945", 72 | "--pruning=archive", 73 | "--ws-external", 74 | "--rpc-external", 75 | "--rpc-cors=all" 76 | ] 77 | }, 78 | { 79 | "name": "bob", 80 | "basePath": "data/para_bob", 81 | "wsPort": 9244, 82 | "port": 32333 83 | } 84 | ] 85 | } 86 | ], 87 | "hrmpChannels": [], 88 | "types": {}, 89 | "finalization": false 90 | } 91 | -------------------------------------------------------------------------------- /scripts/standalone/execute_proposal_test.js: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | require('dotenv').config(); 5 | 6 | const {ApiPromise, WsProvider, Keyring} = require('@polkadot/api'); 7 | const {cryptoWaitReady} = require('@polkadot/util-crypto'); 8 | const { 9 | executeProposal, 10 | queryAssetBalance, 11 | queryBalance, 12 | queryMPCAddress 13 | } = require("./util"); 14 | 15 | // these are the dummy proposals that used to verify if proposal execution works on pallet 16 | // bridge amount from relayer is 100000000000000 17 | const proposal_usdc = { 18 | origin_domain_id: 1, 19 | deposit_nonce: 2, 20 | resource_id: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0], 21 | data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 243, 16, 122, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 1, 1, 0, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125] 22 | } 23 | const proposal_native = { 24 | origin_domain_id: 1, 25 | deposit_nonce: 3, 26 | resource_id: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], 27 | data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 90, 243, 16, 122, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 0, 1, 1, 0, 212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125] 28 | } 29 | 30 | // signer is the mpc address 0x1c5541A79AcC662ab2D2647F3B141a3B7Cdb2Ae4 31 | const signature_usdc = [180, 250, 104, 54, 47, 69, 174, 209, 145, 226, 25, 32, 184, 96, 142, 125, 103, 53, 60, 180, 107, 207, 80, 188, 9, 138, 218, 97, 50, 132, 193, 10, 6, 15, 186, 139, 6, 21, 63, 39, 157, 144, 81, 12, 81, 165, 215, 213, 200, 105, 198, 105, 115, 193, 42, 183, 145, 118, 52, 47, 45, 198, 165, 5, 28]; 32 | const signature_native = [57, 218, 225, 125, 128, 217, 23, 82, 49, 217, 8, 197, 110, 174, 42, 157, 129, 43, 22, 63, 215, 213, 100, 179, 17, 170, 23, 95, 72, 80, 78, 181, 108, 176, 60, 138, 137, 29, 157, 138, 244, 0, 5, 180, 128, 243, 48, 99, 175, 53, 140, 245, 162, 111, 36, 65, 89, 208, 41, 69, 209, 149, 247, 149, 28]; 33 | 34 | const mpcAddress = "0x1c5541a79acc662ab2d2647f3b141a3b7cdb2ae4"; 35 | const aliceAddress = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"; 36 | 37 | // this script take one param as the USDC assetID, default is 2000 if not provided 38 | async function main() { 39 | const [assetID] = process.argv.slice(2); 40 | if (!assetID) { 41 | console.log("assetID is not provided, using default assetID 2000") 42 | } 43 | const sygmaPalletProvider = new WsProvider(process.env.PALLETWSENDPOINT || 'ws://127.0.0.1:9944'); 44 | const api = await ApiPromise.create({ 45 | provider: sygmaPalletProvider, 46 | }); 47 | 48 | await cryptoWaitReady(); 49 | const keyring = new Keyring({type: 'sr25519'}); 50 | const sudo = keyring.addFromUri('//Alice'); 51 | 52 | // make sure mpc address matches 53 | const registeredMpcAddr = await queryMPCAddress(api); 54 | if (registeredMpcAddr !== mpcAddress) { 55 | throw Error("mpc address not match") 56 | } 57 | 58 | console.log(`sudo address ${sudo.address}`) 59 | 60 | // USDC 61 | const usdcBalanceBefore = await queryAssetBalance(api, assetID || 2000, aliceAddress); 62 | console.log('usdc asset balance before: ', usdcBalanceBefore.balance); 63 | await executeProposal(api, [proposal_usdc], signature_usdc, true, sudo); 64 | const usdcbalanceAfter = await queryAssetBalance(api, assetID || 2000, aliceAddress); 65 | console.log('usdc asset balance after: ', usdcbalanceAfter.balance); 66 | 67 | if (usdcbalanceAfter.balance === usdcBalanceBefore.balance) { 68 | throw Error('proposal execution test failed(proposal of USDC)') 69 | } 70 | 71 | // Native asset 72 | const nativeBalanceBefore = await queryBalance(api, aliceAddress); 73 | console.log('native asset balance before: ', nativeBalanceBefore.data.free); 74 | await executeProposal(api, [proposal_native], signature_native, true, sudo); 75 | const nativeBalanceAfter = await queryBalance(api, aliceAddress); 76 | console.log('native asset balance after: ', nativeBalanceAfter.data.free); 77 | 78 | // this fee is proposal execution fee for sygma pallet standalone node with hardcoded dummy proposal 79 | // its value might be different when running on other parachain, so need to be adjusted accordingly 80 | const fee = BigInt(293974317); 81 | const amount = BigInt(100000000); 82 | const before_num = BigInt(nativeBalanceBefore.data.free.replaceAll(',', '')); 83 | const after_num = BigInt(nativeBalanceAfter.data.free.replaceAll(',', '')); 84 | 85 | if (after_num !== before_num + amount - fee) { 86 | throw Error('proposal execution test failed(proposal of Native asset)') 87 | } 88 | 89 | console.log('proposal execution test pass✅'); 90 | } 91 | 92 | main().catch(console.error).finally(() => process.exit()); 93 | -------------------------------------------------------------------------------- /scripts/standalone/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sygma-substrate-pallet-scripts", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "dependencies": { 6 | "@polkadot/api": "^10.11.2", 7 | "@polkadot/api-augment": "^10.11.2", 8 | "@polkadot/keyring": "^12.6.2", 9 | "@polkadot/rpc-provider": "^10.11.2", 10 | "@polkadot/types": "^10.11.2", 11 | "@polkadot/util": "^12.6.2", 12 | "@polkadot/util-crypto": "^12.6.2", 13 | "bn.js": "^5.2.1", 14 | "dotenv": "^16.0.3" 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /scripts/standalone/setup.js: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | require('dotenv').config(); 5 | 6 | const {ApiPromise, WsProvider, Keyring} = require('@polkadot/api'); 7 | const {cryptoWaitReady} = require('@polkadot/util-crypto'); 8 | const { 9 | setBalance, 10 | setFeeHandler, 11 | setMpcAddress, 12 | registerDomain, 13 | setFee, 14 | setFeeRate, 15 | getNativeAssetId, 16 | getERC20TSTAssetId, 17 | getERC20TSTD20AssetId, 18 | createAsset, 19 | setAssetMetadata, 20 | mintAsset, 21 | getUSDCAssetId, 22 | queryBridgePauseStatus 23 | } = require("./util"); 24 | 25 | const BN = require('bn.js'); 26 | const bn1e12 = new BN(10).pow(new BN(12)); 27 | const bn1e18 = new BN(10).pow(new BN(18)); 28 | const bn1e20 = new BN(10).pow(new BN(20)); 29 | 30 | const feeHandlerType = { 31 | BasicFeeHandler: "BasicFeeHandler", 32 | PercentageFeeHandler: "PercentageFeeHandler", 33 | DynamicFeeHandler: "DynamicFeeHandler" 34 | } 35 | 36 | const supportedDestDomains = [ 37 | { 38 | domainID: 1, 39 | chainID: 1 40 | }, 41 | { 42 | domainID: 2, 43 | chainID: 2 44 | } 45 | ] 46 | 47 | // those account are configured in the substrate-node runtime, and are only applicable for sygma pallet standalone node, 48 | // other parachain might have different runtime config so those account address need to be adjusted accordingly 49 | const FeeReserveAccountAddress = "5ELLU7ibt5ZrNEYRwohtaRBDBa3TzcWwwPELBPSWWd2mbgv3"; 50 | const TransferReserveNativeAccount = "5EYCAe5jLbHcAAMKvLFSXgCTbPrLgBJusvPwfKcaKzuf5X5e"; 51 | const TransferReserveOtherAccount = "5EYCAe5jLbHcAAMKvLFiGhk3htXY8jQncbLTDGJQnpnPMAVp"; 52 | 53 | async function main() { 54 | const sygmaPalletProvider = new WsProvider(process.env.PALLETWSENDPOINT || 'ws://127.0.0.1:9944'); 55 | const api = await ApiPromise.create({ 56 | provider: sygmaPalletProvider, 57 | }); 58 | 59 | await cryptoWaitReady(); 60 | const keyring = new Keyring({type: 'sr25519'}); 61 | const sudo = keyring.addFromUri('//Alice'); 62 | const basicFeeAmount = bn1e12.mul(new BN(1)); // 1 * 10 ** 12 63 | const percentageFeeRate = 500; // 5% 64 | const feeRateLowerBound = 0; 65 | const feeRateUpperBound = bn1e12.mul(new BN(1000)); // 1000 * 10 ** 12 66 | const mpcAddr = process.env.MPCADDR; 67 | 68 | // register dest domains 69 | for (const domain of supportedDestDomains) { 70 | await registerDomain(api, domain.domainID, domain.chainID, true, sudo); 71 | } 72 | 73 | // set fee rate for native asset for domains 74 | for (const domain of supportedDestDomains) { 75 | await setFeeHandler(api, domain.domainID, getNativeAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo) 76 | await setFeeRate(api, domain.domainID, getNativeAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound, true, sudo); 77 | } 78 | 79 | // transfer some native asset to FeeReserveAccount and TransferReserveAccounts as Existential Deposit(aka ED) 80 | await setBalance(api, FeeReserveAccountAddress, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset 81 | await setBalance(api, TransferReserveNativeAccount, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset 82 | await setBalance(api, TransferReserveOtherAccount, bn1e12.mul(new BN(10000)), true, sudo); // set balance to 10000 native asset 83 | 84 | // create USDC test asset (foreign asset) 85 | // UsdcAssetId: AssetId defined in runtime.rs 86 | const usdcAssetID = 2000; 87 | const usdcAdmin = sudo.address; 88 | const usdcMinBalance = 100; 89 | const usdcName = "USDC test asset"; 90 | const usdcSymbol = "USDC"; 91 | const usdcDecimal = 12; 92 | await createAsset(api, usdcAssetID, usdcAdmin, usdcMinBalance, true, sudo); 93 | await setAssetMetadata(api, usdcAssetID, usdcName, usdcSymbol, usdcDecimal, true, sudo); 94 | await mintAsset(api, usdcAssetID, usdcAdmin, bn1e12.mul(new BN(100)), true, sudo); // mint 100 USDC to Alice 95 | await mintAsset(api, usdcAssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 USDC to OtherTokenReserved account 96 | 97 | // create ERC20TST test asset (foreign asset) 98 | const erc20tstAssetID = 2001; 99 | const erc20tstAdmin = sudo.address; 100 | const erc20tstMinBalance = 100; 101 | const erc20tstName = "erc20tst test asset"; 102 | const erc20tstSymbol = "ERC20TST"; 103 | const erc20tstDecimal = 18; 104 | await createAsset(api, erc20tstAssetID, erc20tstAdmin, erc20tstMinBalance, true, sudo); 105 | await setAssetMetadata(api, erc20tstAssetID, erc20tstName, erc20tstSymbol, erc20tstDecimal, true, sudo); 106 | await mintAsset(api, erc20tstAssetID, erc20tstAdmin, bn1e18.mul(new BN(100)), true, sudo); // mint 100 ERC20TST to Alice 107 | await mintAsset(api, erc20tstAssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 ERC20TST to OtherTokenReserved account 108 | 109 | // create ERC20TSTD20 test asset (foreign asset) 110 | const erc20tstd20AssetID = 2002; 111 | const erc20tstd20Admin = sudo.address; 112 | const erc20tstd20MinBalance = 100; 113 | const erc20tstd20Name = "erc20tstd20 test asset"; 114 | const erc20tstd20Symbol = "ERC20TSTD20"; 115 | const erc20tstd20Decimal = 20; 116 | await createAsset(api, erc20tstd20AssetID, erc20tstd20Admin, erc20tstd20MinBalance, true, sudo); 117 | await setAssetMetadata(api, erc20tstd20AssetID, erc20tstd20Name, erc20tstd20Symbol, erc20tstd20Decimal, true, sudo); 118 | await mintAsset(api, erc20tstd20AssetID, erc20tstd20Admin, bn1e20.mul(new BN(100)), true, sudo); // mint 100 ERC20TSTD20 to Alice 119 | await mintAsset(api, erc20tstd20AssetID, TransferReserveOtherAccount, bn1e12.mul(new BN(100)), true, sudo); // mint 100 ERC20TSTD20 to OtherTokenReserved account 120 | 121 | // set fee for tokens with domains 122 | for (const domain of supportedDestDomains) { 123 | await setFeeHandler(api, domain.domainID, getUSDCAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo) 124 | await setFeeRate(api, domain.domainID, getUSDCAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo); 125 | 126 | await setFeeHandler(api, domain.domainID, getERC20TSTAssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo) 127 | await setFeeRate(api, domain.domainID, getERC20TSTAssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo); 128 | 129 | await setFeeHandler(api, domain.domainID, getERC20TSTD20AssetId(api), feeHandlerType.PercentageFeeHandler, true, sudo) 130 | await setFeeRate(api, domain.domainID, getERC20TSTD20AssetId(api), percentageFeeRate, feeRateLowerBound, feeRateUpperBound,true, sudo); 131 | } 132 | 133 | // set up MPC address(will also unpause all registered domains) 134 | if (mpcAddr) { 135 | console.log(`set up mpc address: ${mpcAddr}`); 136 | await setMpcAddress(api, mpcAddr, true, sudo); 137 | // bridge should be unpaused by the end of the setup 138 | for (const domain of supportedDestDomains) { 139 | if (!await queryBridgePauseStatus(api, domain.domainID)) console.log(`DestDomainID: ${domain.domainID} is ready✅`); 140 | } 141 | } 142 | 143 | console.log('🚀 Sygma substrate pallet setup is done! 🚀'); 144 | 145 | // It is unnecessary to set up access segregator here since ALICE will be the sudo account and all methods with access control logic are already setup in this script. 146 | // so that on Relayer, E2E test only cases about public extrinsic such as deposit, executionProposal, retry .etc 147 | } 148 | 149 | main().catch(console.error).finally(() => process.exit()); 150 | -------------------------------------------------------------------------------- /scripts/tangle/e2e_setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # The Licensed Work is (c) 2022 Sygma 3 | # SPDX-License-Identifier: LGPL-3.0-only 4 | 5 | set -e 6 | 7 | # Run dev node 8 | echo "start the dev node up..." 9 | ./scripts/run-standalone-local.sh --clean > substrate_node.log 2>&1 & 10 | 11 | echo "waiting for dev node start..." 12 | sleep 60 13 | 14 | # Run setup script 15 | echo "run scripts to set up pallets..." 16 | npm i --prefix ./scripts/sygma-setup 17 | node ./scripts/sygma-setup/setup.js 18 | 19 | sleep 10 20 | 21 | # Stop the node 22 | echo "stopping the dev node..." 23 | nPid=`pgrep -f "tangle"` 24 | if [ "$nPid" ] 25 | then 26 | echo "terminating dev node" 27 | kill $nPid 28 | fi 29 | 30 | echo "done" 31 | -------------------------------------------------------------------------------- /scripts/xcm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sygma-substrate-pallet-xcm-scripts", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "dependencies": { 6 | "@polkadot/api": "^10.11.2", 7 | "@polkadot/api-augment": "^10.11.2", 8 | "@polkadot/keyring": "^12.6.2", 9 | "@polkadot/rpc-provider": "^10.11.2", 10 | "@polkadot/types": "^10.11.2", 11 | "@polkadot/util": "^12.6.2", 12 | "@polkadot/util-crypto": "^12.6.2", 13 | "bn.js": "^5.2.1", 14 | "dotenv": "^16.0.3", 15 | "ethers": "5.4.5" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/xcm_e2e_setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # The Licensed Work is (c) 2022 Sygma 3 | # SPDX-License-Identifier: LGPL-3.0-only 4 | 5 | set -e 6 | 7 | cd polkadot-sdk/local-test 8 | 9 | NODE_DB_DIR=${PWD}/db 10 | echo "node db dir:${NODE_DB_DIR}" 11 | 12 | # Run zombienet node 13 | echo "spin up the zombienet..." 14 | ./zombienet spawn --provider native ./bridge_hub_rococo_local_network.toml -d "$NODE_DB_DIR" > zombienet_node.log 2>&1 & 15 | 16 | echo "waiting for zombienet start..." 17 | sleep 120 18 | 19 | # back to ./script 20 | # doing this will keep the zombienet toml file as is, so that no zombienet file changes required when debugging manually in terminal 21 | cd .. 22 | cd .. 23 | 24 | SETUP_SCRIPTS_DIR=${PWD} 25 | CHAINSPECFILE="chain-spec.json" 26 | 27 | # Run setup script 28 | echo "run scripts to set up the zombienet..." 29 | npm i --prefix $SETUP_SCRIPTS_DIR/xcm 30 | node $SETUP_SCRIPTS_DIR/xcm/setup.js 31 | 32 | sleep 20 33 | 34 | # Stop the node 35 | echo "stopping the zombienet..." 36 | nPid=`pgrep -f "zombienet"` 37 | if [ "$nPid" ] 38 | then 39 | echo "terminating zombienet nodes" 40 | kill $nPid 41 | fi 42 | 43 | echo "done" 44 | -------------------------------------------------------------------------------- /substrate-node/parachain/node/build.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 5 | 6 | fn main() { 7 | generate_cargo_keys(); 8 | 9 | rerun_if_git_head_changed(); 10 | } 11 | -------------------------------------------------------------------------------- /substrate-node/parachain/node/src/cli.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use std::path::PathBuf; 5 | 6 | /// Sub-commands supported by the collator. 7 | #[allow(clippy::large_enum_variant)] 8 | #[derive(Debug, clap::Subcommand)] 9 | pub enum Subcommand { 10 | /// Build a chain specification. 11 | BuildSpec(sc_cli::BuildSpecCmd), 12 | 13 | /// Validate blocks. 14 | CheckBlock(sc_cli::CheckBlockCmd), 15 | 16 | /// Export blocks. 17 | ExportBlocks(sc_cli::ExportBlocksCmd), 18 | 19 | /// Export the state of a given block into a chain spec. 20 | ExportState(sc_cli::ExportStateCmd), 21 | 22 | /// Import blocks. 23 | ImportBlocks(sc_cli::ImportBlocksCmd), 24 | 25 | /// Revert the chain to a previous state. 26 | Revert(sc_cli::RevertCmd), 27 | 28 | /// Remove the whole chain. 29 | PurgeChain(cumulus_client_cli::PurgeChainCmd), 30 | 31 | /// Export the genesis state of the parachain. 32 | ExportGenesisState(cumulus_client_cli::ExportGenesisStateCommand), 33 | 34 | /// Export the genesis wasm of the parachain. 35 | ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand), 36 | 37 | /// Sub-commands concerned with benchmarking. 38 | /// The pallet benchmarking moved to the `pallet` sub-command. 39 | #[command(subcommand)] 40 | Benchmark(frame_benchmarking_cli::BenchmarkCmd), 41 | 42 | /// Try-runtime has migrated to a standalone 43 | /// [CLI](). The subcommand exists as a stub and 44 | /// deprecation notice. It will be removed entirely some time after Janurary 2024. 45 | TryRuntime, 46 | } 47 | 48 | const AFTER_HELP_EXAMPLE: &str = color_print::cstr!( 49 | r#"Examples: 50 | parachain-template-node build-spec --disable-default-bootnode > plain-parachain-chainspec.json 51 | Export a chainspec for a local testnet in json format. 52 | parachain-template-node --chain plain-parachain-chainspec.json --tmp -- --chain rococo-local 53 | Launch a full node with chain specification loaded from plain-parachain-chainspec.json. 54 | parachain-template-node 55 | Launch a full node with default parachain local-testnet and relay chain rococo-local. 56 | parachain-template-node --collator 57 | Launch a collator with default parachain local-testnet and relay chain rococo-local. 58 | "# 59 | ); 60 | #[derive(Debug, clap::Parser)] 61 | #[command( 62 | propagate_version = true, 63 | args_conflicts_with_subcommands = true, 64 | subcommand_negates_reqs = true 65 | )] 66 | #[clap(after_help = AFTER_HELP_EXAMPLE)] 67 | pub struct Cli { 68 | #[command(subcommand)] 69 | pub subcommand: Option, 70 | 71 | #[command(flatten)] 72 | pub run: cumulus_client_cli::RunCmd, 73 | 74 | /// Disable automatic hardware benchmarks. 75 | /// 76 | /// By default these benchmarks are automatically ran at startup and measure 77 | /// the CPU speed, the memory bandwidth and the disk speed. 78 | /// 79 | /// The results are then printed out in the logs, and also sent as part of 80 | /// telemetry, if telemetry is enabled. 81 | #[arg(long)] 82 | pub no_hardware_benchmarks: bool, 83 | 84 | /// Relay chain arguments 85 | #[arg(raw = true)] 86 | pub relay_chain_args: Vec, 87 | } 88 | 89 | #[derive(Debug)] 90 | pub struct RelayChainCli { 91 | /// The actual relay chain cli object. 92 | pub base: polkadot_cli::RunCmd, 93 | 94 | /// Optional chain id that should be passed to the relay chain. 95 | pub chain_id: Option, 96 | 97 | /// The base path that should be used by the relay chain. 98 | pub base_path: Option, 99 | } 100 | 101 | impl RelayChainCli { 102 | /// Parse the relay chain CLI parameters using the para chain `Configuration`. 103 | pub fn new<'a>( 104 | para_config: &sc_service::Configuration, 105 | relay_chain_args: impl Iterator, 106 | ) -> Self { 107 | let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec); 108 | let chain_id = extension.map(|e| e.relay_chain.clone()); 109 | let base_path = para_config.base_path.path().join("polkadot"); 110 | Self { 111 | base_path: Some(base_path), 112 | chain_id, 113 | base: clap::Parser::parse_from(relay_chain_args), 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /substrate-node/parachain/node/src/main.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Substrate Node Template CLI library. 5 | #![warn(missing_docs)] 6 | 7 | mod chain_spec; 8 | #[macro_use] 9 | mod service; 10 | // mod benchmarking; 11 | mod cli; 12 | mod command; 13 | mod rpc; 14 | 15 | fn main() -> sc_cli::Result<()> { 16 | command::run() 17 | } 18 | -------------------------------------------------------------------------------- /substrate-node/parachain/node/src/rpc.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #![warn(missing_docs)] 5 | 6 | use std::sync::Arc; 7 | 8 | use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce}; 9 | 10 | use sc_client_api::AuxStore; 11 | pub use sc_rpc::DenyUnsafe; 12 | use sc_transaction_pool_api::TransactionPool; 13 | use sp_api::ProvideRuntimeApi; 14 | use sp_block_builder::BlockBuilder; 15 | use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; 16 | 17 | /// A type representing all RPC extensions. 18 | pub type RpcExtension = jsonrpsee::RpcModule<()>; 19 | 20 | /// Full client dependencies 21 | pub struct FullDeps { 22 | /// The client instance to use. 23 | pub client: Arc, 24 | /// Transaction pool instance. 25 | pub pool: Arc

, 26 | /// Whether to deny unsafe calls 27 | pub deny_unsafe: DenyUnsafe, 28 | } 29 | 30 | /// Instantiate all RPC extensions. 31 | pub fn create_full( 32 | deps: FullDeps, 33 | ) -> Result> 34 | where 35 | C: ProvideRuntimeApi 36 | + HeaderBackend 37 | + AuxStore 38 | + HeaderMetadata 39 | + Send 40 | + Sync 41 | + 'static, 42 | C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, 43 | C::Api: substrate_frame_rpc_system::AccountNonceApi, 44 | C::Api: BlockBuilder, 45 | P: TransactionPool + Sync + Send + 'static, 46 | { 47 | use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; 48 | use substrate_frame_rpc_system::{System, SystemApiServer}; 49 | 50 | let mut module = RpcExtension::new(()); 51 | let FullDeps { client, pool, deny_unsafe } = deps; 52 | 53 | module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; 54 | module.merge(TransactionPayment::new(client).into_rpc())?; 55 | Ok(module) 56 | } 57 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/build.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #[cfg(feature = "std")] 5 | fn main() { 6 | substrate_wasm_builder::WasmBuilder::new() 7 | .with_current_project() 8 | .export_heap_base() 9 | .import_memory() 10 | .build() 11 | } 12 | 13 | /// The wasm builder is deactivated when compiling 14 | /// this crate for wasm to speed up the compilation. 15 | #[cfg(not(feature = "std"))] 16 | fn main() {} 17 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/src/weights/block_weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | pub mod constants { 19 | use frame_support::{ 20 | parameter_types, 21 | weights::{constants, Weight}, 22 | }; 23 | 24 | parameter_types! { 25 | /// Importing a block with 0 Extrinsics. 26 | pub const BlockExecutionWeight: Weight = 27 | Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(5_000_000), 0); 28 | } 29 | 30 | #[cfg(test)] 31 | mod test_weights { 32 | use frame_support::weights::constants; 33 | 34 | /// Checks that the weight exists and is sane. 35 | // NOTE: If this test fails but you are sure that the generated values are fine, 36 | // you can delete it. 37 | #[test] 38 | fn sane() { 39 | let w = super::constants::BlockExecutionWeight::get(); 40 | 41 | // At least 100 µs. 42 | assert!( 43 | w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS, 44 | "Weight should be at least 100 µs." 45 | ); 46 | // At most 50 ms. 47 | assert!( 48 | w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS, 49 | "Weight should be at most 50 ms." 50 | ); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/src/weights/extrinsic_weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | pub mod constants { 19 | use frame_support::{ 20 | parameter_types, 21 | weights::{constants, Weight}, 22 | }; 23 | 24 | parameter_types! { 25 | /// Executing a NO-OP `System::remarks` Extrinsic. 26 | pub const ExtrinsicBaseWeight: Weight = 27 | Weight::from_parts(constants::WEIGHT_REF_TIME_PER_NANOS.saturating_mul(125_000), 0); 28 | } 29 | 30 | #[cfg(test)] 31 | mod test_weights { 32 | use frame_support::weights::constants; 33 | 34 | /// Checks that the weight exists and is sane. 35 | // NOTE: If this test fails but you are sure that the generated values are fine, 36 | // you can delete it. 37 | #[test] 38 | fn sane() { 39 | let w = super::constants::ExtrinsicBaseWeight::get(); 40 | 41 | // At least 10 µs. 42 | assert!( 43 | w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS, 44 | "Weight should be at least 10 µs." 45 | ); 46 | // At most 1 ms. 47 | assert!( 48 | w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, 49 | "Weight should be at most 1 ms." 50 | ); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/src/weights/mod.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | //! Expose the auto generated weight files. 19 | 20 | pub mod block_weights; 21 | pub mod extrinsic_weights; 22 | pub mod paritydb_weights; 23 | pub mod rocksdb_weights; 24 | 25 | pub use block_weights::constants::BlockExecutionWeight; 26 | pub use extrinsic_weights::constants::ExtrinsicBaseWeight; 27 | // pub use paritydb_weights::constants::ParityDbWeight; 28 | pub use rocksdb_weights::constants::RocksDbWeight; 29 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/src/weights/paritydb_weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | pub mod constants { 19 | use frame_support::{ 20 | parameter_types, 21 | weights::{constants, RuntimeDbWeight}, 22 | }; 23 | 24 | parameter_types! { 25 | /// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights 26 | /// are available for brave runtime engineers who may want to try this out as default. 27 | pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { 28 | read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS, 29 | write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS, 30 | }; 31 | } 32 | 33 | #[cfg(test)] 34 | mod test_db_weights { 35 | use super::constants::ParityDbWeight as W; 36 | use frame_support::weights::constants; 37 | 38 | /// Checks that all weights exist and have sane values. 39 | // NOTE: If this test fails but you are sure that the generated values are fine, 40 | // you can delete it. 41 | #[test] 42 | fn sane() { 43 | // At least 1 µs. 44 | assert!( 45 | W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, 46 | "Read weight should be at least 1 µs." 47 | ); 48 | assert!( 49 | W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, 50 | "Write weight should be at least 1 µs." 51 | ); 52 | // At most 1 ms. 53 | assert!( 54 | W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, 55 | "Read weight should be at most 1 ms." 56 | ); 57 | assert!( 58 | W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, 59 | "Write weight should be at most 1 ms." 60 | ); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /substrate-node/parachain/runtime/src/weights/rocksdb_weights.rs: -------------------------------------------------------------------------------- 1 | // This file is part of Substrate. 2 | 3 | // Copyright (C) Parity Technologies (UK) Ltd. 4 | // SPDX-License-Identifier: Apache-2.0 5 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | 18 | pub mod constants { 19 | use frame_support::{ 20 | parameter_types, 21 | weights::{constants, RuntimeDbWeight}, 22 | }; 23 | 24 | parameter_types! { 25 | /// By default, Substrate uses `RocksDB`, so this will be the weight used throughout 26 | /// the runtime. 27 | pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { 28 | read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS, 29 | write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS, 30 | }; 31 | } 32 | 33 | #[cfg(test)] 34 | mod test_db_weights { 35 | use super::constants::RocksDbWeight as W; 36 | use frame_support::weights::constants; 37 | 38 | /// Checks that all weights exist and have sane values. 39 | // NOTE: If this test fails but you are sure that the generated values are fine, 40 | // you can delete it. 41 | #[test] 42 | fn sane() { 43 | // At least 1 µs. 44 | assert!( 45 | W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, 46 | "Read weight should be at least 1 µs." 47 | ); 48 | assert!( 49 | W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS, 50 | "Write weight should be at least 1 µs." 51 | ); 52 | // At most 1 ms. 53 | assert!( 54 | W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, 55 | "Read weight should be at most 1 ms." 56 | ); 57 | assert!( 58 | W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS, 59 | "Write weight should be at most 1 ms." 60 | ); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "standalone-node-template" 3 | version = "4.0.3-dev" 4 | description = "A fresh FRAME-based Substrate node, ready for hacking." 5 | authors = ["Substrate DevHub "] 6 | homepage = "https://substrate.io/" 7 | edition = "2021" 8 | license = "LGPL-3.0" 9 | publish = false 10 | repository = "https://github.com/substrate-developer-hub/substrate-node-template/" 11 | build = "build.rs" 12 | 13 | [package.metadata.docs.rs] 14 | targets = ["x86_64-unknown-linux-gnu"] 15 | 16 | [[bin]] 17 | name = "standalone-node-template" 18 | 19 | [dependencies] 20 | clap = { version = "4.2.5", features = ["derive"] } 21 | futures = { version = "0.3.21", features = ["thread-pool"]} 22 | 23 | sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 24 | sp-core = { version = "21.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 25 | sc-executor = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 26 | sc-network = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 27 | sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 28 | sc-telemetry = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 29 | sc-keystore = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 30 | sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 31 | sc-statement-store = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 32 | sc-transaction-pool = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 33 | sc-transaction-pool-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 34 | sc-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 35 | sp-consensus-aura = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 36 | sp-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 37 | sc-consensus = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 38 | sc-consensus-grandpa = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 39 | sp-consensus-grandpa = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 40 | sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 41 | sp-runtime = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 42 | sp-io = { version = "23.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 43 | sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 44 | sp-inherents = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 45 | sp-keyring = { version = "24.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 46 | frame-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 47 | pallet-transaction-payment = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 48 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 49 | 50 | # These dependencies are used for the node template's RPCs 51 | jsonrpsee = { version = "0.16.2", features = ["server"] } 52 | sc-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 53 | sp-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 54 | sc-rpc-api = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 55 | sp-blockchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 56 | sp-block-builder = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 57 | sc-basic-authorship = { version = "0.10.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 58 | substrate-frame-rpc-system = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 59 | pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 60 | 61 | # These dependencies are used for runtime benchmarking 62 | frame-benchmarking = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 63 | frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 64 | 65 | # Local Dependencies 66 | standalone-template-runtime = { version = "4.0.3-dev", path = "../runtime" } 67 | sygma-rpc = { path = "../../../rpc", default-features = false } 68 | sygma-runtime-api = { path = "../../../runtime-api", default-features = false } 69 | 70 | # CLI-specific dependencies 71 | try-runtime-cli = { version = "0.10.0-dev", optional = true, git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 72 | 73 | [build-dependencies] 74 | substrate-build-script-utils = { version = "3.0.0", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 75 | 76 | [features] 77 | default = [] 78 | # Dependencies that are only required if runtime benchmarking should be build. 79 | runtime-benchmarks = [ 80 | "standalone-template-runtime/runtime-benchmarks", 81 | "frame-benchmarking/runtime-benchmarks", 82 | "frame-benchmarking-cli/runtime-benchmarks", 83 | ] 84 | # Enable features that allow the runtime to be tried and debugged. Name might be subject to change 85 | # in the near future. 86 | try-runtime = ["standalone-template-runtime/try-runtime", "try-runtime-cli/try-runtime"] 87 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/build.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use substrate_build_script_utils::{generate_cargo_keys, rerun_if_git_head_changed}; 5 | 6 | fn main() { 7 | generate_cargo_keys(); 8 | 9 | rerun_if_git_head_changed(); 10 | } 11 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/src/benchmarking.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | // This file is part of Substrate. 5 | 6 | // Copyright (C) 2022 Parity Technologies (UK) Ltd. 7 | // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 8 | 9 | // This program is free software: you can redistribute it and/or modify 10 | // it under the terms of the GNU General Public License as published by 11 | // the Free Software Foundation, either version 3 of the License, or 12 | // (at your option) any later version. 13 | 14 | // This program is distributed in the hope that it will be useful, 15 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | // GNU General Public License for more details. 18 | 19 | // You should have received a copy of the GNU General Public License 20 | // along with this program. If not, see . 21 | 22 | //! Setup code for [`super::command`] which would otherwise bloat that module. 23 | //! 24 | //! Should only be used for benchmarking as it may break in other contexts. 25 | 26 | use crate::service::FullClient; 27 | 28 | use runtime::{AccountId, Balance, BalancesCall, SystemCall}; 29 | use sc_cli::Result; 30 | use sc_client_api::BlockBackend; 31 | use sp_core::{Encode, Pair}; 32 | use sp_inherents::{InherentData, InherentDataProvider}; 33 | use sp_keyring::Sr25519Keyring; 34 | use sp_runtime::{OpaqueExtrinsic, SaturatedConversion}; 35 | use standalone_template_runtime as runtime; 36 | 37 | use std::{sync::Arc, time::Duration}; 38 | 39 | /// Generates extrinsics for the `benchmark overhead` command. 40 | /// 41 | /// Note: Should only be used for benchmarking. 42 | pub struct RemarkBuilder { 43 | client: Arc, 44 | } 45 | 46 | impl RemarkBuilder { 47 | /// Creates a new [`Self`] from the given client. 48 | pub fn new(client: Arc) -> Self { 49 | Self { client } 50 | } 51 | } 52 | 53 | impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder { 54 | fn pallet(&self) -> &str { 55 | "system" 56 | } 57 | 58 | fn extrinsic(&self) -> &str { 59 | "remark" 60 | } 61 | 62 | fn build(&self, nonce: u32) -> std::result::Result { 63 | let acc = Sr25519Keyring::Bob.pair(); 64 | let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic( 65 | self.client.as_ref(), 66 | acc, 67 | SystemCall::remark { remark: vec![] }.into(), 68 | nonce, 69 | ) 70 | .into(); 71 | 72 | Ok(extrinsic) 73 | } 74 | } 75 | 76 | /// Generates `Balances::TransferKeepAlive` extrinsics for the benchmarks. 77 | /// 78 | /// Note: Should only be used for benchmarking. 79 | pub struct TransferKeepAliveBuilder { 80 | client: Arc, 81 | dest: AccountId, 82 | value: Balance, 83 | } 84 | 85 | impl TransferKeepAliveBuilder { 86 | /// Creates a new [`Self`] from the given client. 87 | pub fn new(client: Arc, dest: AccountId, value: Balance) -> Self { 88 | Self { client, dest, value } 89 | } 90 | } 91 | 92 | impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder { 93 | fn pallet(&self) -> &str { 94 | "balances" 95 | } 96 | 97 | fn extrinsic(&self) -> &str { 98 | "transfer_keep_alive" 99 | } 100 | 101 | fn build(&self, nonce: u32) -> std::result::Result { 102 | let acc = Sr25519Keyring::Bob.pair(); 103 | let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic( 104 | self.client.as_ref(), 105 | acc, 106 | BalancesCall::transfer_keep_alive { dest: self.dest.clone().into(), value: self.value } 107 | .into(), 108 | nonce, 109 | ) 110 | .into(); 111 | 112 | Ok(extrinsic) 113 | } 114 | } 115 | 116 | /// Create a transaction using the given `call`. 117 | /// 118 | /// Note: Should only be used for benchmarking. 119 | pub fn create_benchmark_extrinsic( 120 | client: &FullClient, 121 | sender: sp_core::sr25519::Pair, 122 | call: runtime::RuntimeCall, 123 | nonce: u32, 124 | ) -> runtime::UncheckedExtrinsic { 125 | let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed"); 126 | let best_hash = client.chain_info().best_hash; 127 | let best_block = client.chain_info().best_number; 128 | 129 | let period = runtime::BlockHashCount::get() 130 | .checked_next_power_of_two() 131 | .map(|c| c / 2) 132 | .unwrap_or(2) as u64; 133 | let extra: runtime::SignedExtra = ( 134 | frame_system::CheckNonZeroSender::::new(), 135 | frame_system::CheckSpecVersion::::new(), 136 | frame_system::CheckTxVersion::::new(), 137 | frame_system::CheckGenesis::::new(), 138 | frame_system::CheckEra::::from(sp_runtime::generic::Era::mortal( 139 | period, 140 | best_block.saturated_into(), 141 | )), 142 | frame_system::CheckNonce::::from(nonce), 143 | frame_system::CheckWeight::::new(), 144 | pallet_transaction_payment::ChargeTransactionPayment::::from(0), 145 | ); 146 | 147 | let raw_payload = runtime::SignedPayload::from_raw( 148 | call.clone(), 149 | extra.clone(), 150 | ( 151 | (), 152 | runtime::VERSION.spec_version, 153 | runtime::VERSION.transaction_version, 154 | genesis_hash, 155 | best_hash, 156 | (), 157 | (), 158 | (), 159 | ), 160 | ); 161 | let signature = raw_payload.using_encoded(|e| sender.sign(e)); 162 | 163 | runtime::UncheckedExtrinsic::new_signed( 164 | call, 165 | sp_runtime::AccountId32::from(sender.public()).into(), 166 | runtime::Signature::Sr25519(signature), 167 | extra, 168 | ) 169 | } 170 | 171 | /// Generates inherent data for the `benchmark overhead` command. 172 | /// 173 | /// Note: Should only be used for benchmarking. 174 | pub fn inherent_benchmark_data() -> Result { 175 | let mut inherent_data = InherentData::new(); 176 | let d = Duration::from_millis(0); 177 | let timestamp = sp_timestamp::InherentDataProvider::new(d.into()); 178 | 179 | futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data)) 180 | .map_err(|e| format!("creating inherent data: {e:?}"))?; 181 | Ok(inherent_data) 182 | } 183 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/src/chain_spec.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use cumulus_primitives_core::ParaId; 5 | use sc_service::ChainType; 6 | use sp_consensus_aura::sr25519::AuthorityId as AuraId; 7 | use sp_consensus_grandpa::AuthorityId as GrandpaId; 8 | use sp_core::{sr25519, Pair, Public}; 9 | use sp_runtime::traits::{IdentifyAccount, Verify}; 10 | use standalone_template_runtime::{ 11 | AccountId, AuraConfig, BalancesConfig, GrandpaConfig, ParachainInfoConfig, 12 | RuntimeGenesisConfig, Signature, SudoConfig, SystemConfig, WASM_BINARY, 13 | }; 14 | 15 | // The URL for the telemetry server. 16 | // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; 17 | 18 | /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. 19 | pub type ChainSpec = sc_service::GenericChainSpec; 20 | 21 | /// Generate a crypto pair from seed. 22 | pub fn get_from_seed(seed: &str) -> ::Public { 23 | TPublic::Pair::from_string(&format!("//{seed}"), None) 24 | .expect("static values are valid; qed") 25 | .public() 26 | } 27 | 28 | type AccountPublic = ::Signer; 29 | 30 | /// Generate an account ID from seed. 31 | pub fn get_account_id_from_seed(seed: &str) -> AccountId 32 | where 33 | AccountPublic: From<::Public>, 34 | { 35 | AccountPublic::from(get_from_seed::(seed)).into_account() 36 | } 37 | 38 | /// Generate an Aura authority key. 39 | pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { 40 | (get_from_seed::(s), get_from_seed::(s)) 41 | } 42 | 43 | pub fn development_config() -> Result { 44 | let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; 45 | 46 | Ok(ChainSpec::from_genesis( 47 | // Name 48 | "Development", 49 | // ID 50 | "dev", 51 | ChainType::Development, 52 | move || { 53 | testnet_genesis( 54 | wasm_binary, 55 | // Initial PoA authorities 56 | vec![authority_keys_from_seed("Alice")], 57 | // Sudo account 58 | get_account_id_from_seed::("Alice"), 59 | // Pre-funded accounts 60 | vec![ 61 | get_account_id_from_seed::("Alice"), 62 | get_account_id_from_seed::("Bob"), 63 | get_account_id_from_seed::("Alice//stash"), 64 | get_account_id_from_seed::("Bob//stash"), 65 | ], 66 | true, 67 | ) 68 | }, 69 | // Bootnodes 70 | vec![], 71 | // Telemetry 72 | None, 73 | // Protocol ID 74 | None, 75 | None, 76 | // Properties 77 | None, 78 | // Extensions 79 | None, 80 | )) 81 | } 82 | 83 | pub fn local_testnet_config() -> Result { 84 | let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; 85 | 86 | Ok(ChainSpec::from_genesis( 87 | // Name 88 | "Local Testnet", 89 | // ID 90 | "local_testnet", 91 | ChainType::Local, 92 | move || { 93 | testnet_genesis( 94 | wasm_binary, 95 | // Initial PoA authorities 96 | vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], 97 | // Sudo account 98 | get_account_id_from_seed::("Alice"), 99 | // Pre-funded accounts 100 | vec![ 101 | get_account_id_from_seed::("Alice"), 102 | get_account_id_from_seed::("Bob"), 103 | get_account_id_from_seed::("Charlie"), 104 | get_account_id_from_seed::("Dave"), 105 | get_account_id_from_seed::("Eve"), 106 | get_account_id_from_seed::("Ferdie"), 107 | get_account_id_from_seed::("Alice//stash"), 108 | get_account_id_from_seed::("Bob//stash"), 109 | get_account_id_from_seed::("Charlie//stash"), 110 | get_account_id_from_seed::("Dave//stash"), 111 | get_account_id_from_seed::("Eve//stash"), 112 | get_account_id_from_seed::("Ferdie//stash"), 113 | ], 114 | true, 115 | ) 116 | }, 117 | // Bootnodes 118 | vec![], 119 | // Telemetry 120 | None, 121 | // Protocol ID 122 | None, 123 | // Properties 124 | None, 125 | None, 126 | // Extensions 127 | None, 128 | )) 129 | } 130 | 131 | /// Configure initial storage state for FRAME modules. 132 | fn testnet_genesis( 133 | wasm_binary: &[u8], 134 | initial_authorities: Vec<(AuraId, GrandpaId)>, 135 | root_key: AccountId, 136 | endowed_accounts: Vec, 137 | _enable_println: bool, 138 | ) -> RuntimeGenesisConfig { 139 | // hardcoded dummy parachainID 140 | let id: ParaId = ParaId::from(1000); 141 | RuntimeGenesisConfig { 142 | system: SystemConfig { 143 | // Add Wasm runtime to storage. 144 | code: wasm_binary.to_vec(), 145 | ..Default::default() 146 | }, 147 | balances: BalancesConfig { 148 | // Configure endowed accounts with initial balance of 1 << 60. 149 | balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), 150 | }, 151 | aura: AuraConfig { 152 | authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), 153 | }, 154 | grandpa: GrandpaConfig { 155 | authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), 156 | ..Default::default() 157 | }, 158 | sudo: SudoConfig { 159 | // Assign network admin rights. 160 | key: Some(root_key), 161 | }, 162 | parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, 163 | transaction_payment: Default::default(), 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/src/cli.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use sc_cli::RunCmd; 5 | 6 | #[derive(Debug, clap::Parser)] 7 | pub struct Cli { 8 | #[command(subcommand)] 9 | pub subcommand: Option, 10 | 11 | #[clap(flatten)] 12 | pub run: RunCmd, 13 | } 14 | 15 | #[allow(clippy::large_enum_variant)] 16 | #[derive(Debug, clap::Subcommand)] 17 | pub enum Subcommand { 18 | /// Key management cli utilities 19 | #[command(subcommand)] 20 | Key(sc_cli::KeySubcommand), 21 | 22 | /// Build a chain specification. 23 | BuildSpec(sc_cli::BuildSpecCmd), 24 | 25 | /// Validate blocks. 26 | CheckBlock(sc_cli::CheckBlockCmd), 27 | 28 | /// Export blocks. 29 | ExportBlocks(sc_cli::ExportBlocksCmd), 30 | 31 | /// Export the state of a given block into a chain spec. 32 | ExportState(sc_cli::ExportStateCmd), 33 | 34 | /// Import blocks. 35 | ImportBlocks(sc_cli::ImportBlocksCmd), 36 | 37 | /// Remove the whole chain. 38 | PurgeChain(sc_cli::PurgeChainCmd), 39 | 40 | /// Revert the chain to a previous state. 41 | Revert(sc_cli::RevertCmd), 42 | 43 | /// Sub-commands concerned with benchmarking. 44 | #[command(subcommand)] 45 | Benchmark(frame_benchmarking_cli::BenchmarkCmd), 46 | 47 | /// Try some command against runtime state. 48 | #[cfg(feature = "try-runtime")] 49 | TryRuntime(try_runtime_cli::TryRuntimeCmd), 50 | 51 | /// Try some command against runtime state. Note: `try-runtime` feature must be enabled. 52 | #[cfg(not(feature = "try-runtime"))] 53 | TryRuntime, 54 | 55 | /// Db meta columns information. 56 | ChainInfo(sc_cli::ChainInfoCmd), 57 | } 58 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/src/main.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! Substrate Node Template CLI library. 5 | #![warn(missing_docs)] 6 | 7 | mod chain_spec; 8 | #[macro_use] 9 | mod service; 10 | mod benchmarking; 11 | mod cli; 12 | mod command; 13 | mod rpc; 14 | 15 | fn main() -> sc_cli::Result<()> { 16 | command::run() 17 | } 18 | -------------------------------------------------------------------------------- /substrate-node/standalone/node/src/rpc.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | //! A collection of node-specific RPC methods. 5 | //! Substrate provides the `sc-rpc` crate, which defines the core RPC layer 6 | //! used by Substrate nodes. This file extends those RPC definitions with 7 | //! capabilities that are specific to this project's runtime configuration. 8 | 9 | #![warn(missing_docs)] 10 | 11 | use std::sync::Arc; 12 | 13 | use jsonrpsee::RpcModule; 14 | use sc_transaction_pool_api::TransactionPool; 15 | use sp_api::ProvideRuntimeApi; 16 | use sp_block_builder::BlockBuilder; 17 | use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; 18 | use standalone_template_runtime::{opaque::Block, AccountId, Balance, Nonce}; 19 | 20 | pub use sc_rpc_api::DenyUnsafe; 21 | 22 | /// Full client dependencies. 23 | pub struct FullDeps { 24 | /// The client instance to use. 25 | pub client: Arc, 26 | /// Transaction pool instance. 27 | pub pool: Arc

, 28 | /// Whether to deny unsafe calls 29 | pub deny_unsafe: DenyUnsafe, 30 | } 31 | 32 | /// Instantiate all full RPC extensions. 33 | pub fn create_full( 34 | deps: FullDeps, 35 | ) -> Result, Box> 36 | where 37 | C: ProvideRuntimeApi, 38 | C: HeaderBackend + HeaderMetadata + 'static, 39 | C: Send + Sync + 'static, 40 | C::Api: substrate_frame_rpc_system::AccountNonceApi, 41 | C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, 42 | C::Api: BlockBuilder, 43 | C::Api: sygma_runtime_api::SygmaBridgeApi, 44 | P: TransactionPool + 'static, 45 | { 46 | use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; 47 | use substrate_frame_rpc_system::{System, SystemApiServer}; 48 | use sygma_rpc::{SygmaBridgeRpcServer, SygmaBridgeStorage}; 49 | 50 | let mut module = RpcModule::new(()); 51 | let FullDeps { client, pool, deny_unsafe } = deps; 52 | 53 | module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?; 54 | module.merge(TransactionPayment::new(client.clone()).into_rpc())?; 55 | 56 | // Extend this RPC with a custom API by using the following syntax. 57 | // `YourRpcStruct` should have a reference to a client, which is needed 58 | // to call into the runtime. 59 | // `module.merge(YourRpcTrait::into_rpc(YourRpcStruct::new(ReferenceToClient, ...)))?;` 60 | module.merge(SygmaBridgeStorage::new(client).into_rpc())?; 61 | 62 | Ok(module) 63 | } 64 | -------------------------------------------------------------------------------- /substrate-node/standalone/runtime/build.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | fn main() { 5 | #[cfg(feature = "std")] 6 | { 7 | substrate_wasm_builder::WasmBuilder::new() 8 | .with_current_project() 9 | .export_heap_base() 10 | .import_memory() 11 | .build(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /traits/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.2.0](https://github.com/sygmaprotocol/sygma-substrate-pallets/compare/sygma-traits-v0.1.0...sygma-traits-v0.2.0) (2023-05-11) 4 | 5 | 6 | ### Features 7 | 8 | * Upgrade to Polkadot v0.9.39 ([#85](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/85)) ([d964bc6](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/d964bc607c2c5c5bb9436fa07262977c19ebbaa4)) 9 | * Upgrade to Polkadot v0.9.40 ([#87](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/87)) ([db11298](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/db11298c91f65d52c9b6eeab0e7757ca49bf77ff)) 10 | * Upgrade to polkadot v0.9.42 ([#101](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/101)) ([6651e31](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/6651e31e9f98f6ca07cfd3be482963c3281d68cc)) 11 | 12 | 13 | ### Bug Fixes 14 | 15 | * avoid without storage info macro ([#99](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/99)) ([abd6db1](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/abd6db1c00940de65a71a50232962bc943e0aa39)) 16 | 17 | ## 0.1.0 (2023-03-01) 18 | 19 | 20 | ### Features 21 | 22 | * Decimal converter ([#57](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/57)) ([9dddcd7](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/9dddcd77d1dad41ba7012896ae4a180d222da00f)) 23 | * Impl fee handler router ([#43](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/43)) ([efb6818](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/efb6818e7558b7142aa1954b90f32397ad87f4f6)) 24 | * Multi domain support ([#48](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/48)) ([f892602](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/f8926024df10a5b814c8b043ae70760e7c498e3e)) 25 | * Upgrade to polkadot v0.9.37 ([#61](https://github.com/sygmaprotocol/sygma-substrate-pallets/issues/61)) ([cbe3f83](https://github.com/sygmaprotocol/sygma-substrate-pallets/commit/cbe3f8391c1110a22c167c9ddb1c5f28b7fc2466)) 26 | -------------------------------------------------------------------------------- /traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-traits" 3 | version = "0.2.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 11 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | ethabi = { version = "18.0.0", default-features = false } 15 | primitive-types = { version = "0.12", default-features = false, features = ["scale-info", "serde_no_std"] } 16 | 17 | # Polkadot 18 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 20 | 21 | [features] 22 | default = ["std"] 23 | std = [ 24 | "codec/std", 25 | "scale-info/std", 26 | "xcm/std", 27 | "xcm-builder/std", 28 | "sp-std/std", 29 | "ethabi/std", 30 | "primitive-types/std", 31 | ] 32 | -------------------------------------------------------------------------------- /traits/src/lib.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | #![cfg_attr(not(feature = "std"), no_std)] 5 | 6 | use codec::{Decode, Encode, MaxEncodedLen}; 7 | use frame_support::dispatch::DispatchResult; 8 | use primitive_types::{H160, U256}; 9 | use scale_info::TypeInfo; 10 | use sp_std::vec::Vec; 11 | use xcm::latest::{prelude::*, MultiLocation}; 12 | 13 | pub type DomainID = u8; 14 | pub type DepositNonce = u64; 15 | pub type ResourceId = [u8; 32]; 16 | pub type ChainID = U256; 17 | pub type VerifyingContractAddress = H160; 18 | 19 | #[derive(Clone, Debug, Eq, PartialEq, Encode, Decode, TypeInfo)] 20 | pub enum TransferType { 21 | FungibleTransfer, 22 | NonFungibleTransfer, 23 | GenericTransfer, 24 | } 25 | 26 | #[derive( 27 | Clone, 28 | Eq, 29 | PartialEq, 30 | Ord, 31 | PartialOrd, 32 | Debug, 33 | Encode, 34 | Decode, 35 | TypeInfo, 36 | Copy, 37 | Default, 38 | MaxEncodedLen, 39 | )] 40 | pub struct MpcAddress(pub [u8; 20]); 41 | 42 | pub trait ExtractDestinationData { 43 | fn extract_dest(dest: &MultiLocation) -> Option<(Vec, DomainID)>; 44 | } 45 | 46 | pub trait FeeHandler { 47 | // Return fee represent by a specific asset 48 | fn get_fee(domain: DomainID, asset: MultiAsset) -> Option; 49 | } 50 | 51 | impl FeeHandler for () { 52 | fn get_fee(_domain: DomainID, _asset: MultiAsset) -> Option { 53 | None 54 | } 55 | } 56 | 57 | pub trait DecimalConverter { 58 | /// convert_to converts the MultiAsset to u128 when bridging from sygma substrate pallet. 59 | /// Sygma relayer will always expect asset in 18 decimal 60 | fn convert_to(asset: &MultiAsset) -> Option; 61 | /// convert_from converts a u128 to MultiAsset when bridging to sygma substrate pallet. 62 | /// Sygma relayer will always send asset in 18 decimal 63 | fn convert_from(asset: &MultiAsset) -> Option; 64 | } 65 | 66 | // when integrating with parachain, parachain team can implement their own version 67 | pub trait AssetTypeIdentifier { 68 | fn is_native_asset(asset: &MultiAsset) -> bool; 69 | } 70 | 71 | pub trait TransactorForwarder { 72 | fn xcm_transactor_forwarder( 73 | sender: [u8; 32], 74 | what: MultiAsset, 75 | dest: MultiLocation, 76 | ) -> DispatchResult; 77 | fn other_world_transactor_forwarder( 78 | sender: [u8; 32], 79 | what: MultiAsset, 80 | dest: MultiLocation, 81 | ) -> DispatchResult; 82 | } 83 | 84 | pub trait Bridge { 85 | fn transfer( 86 | sender: [u8; 32], 87 | asset: MultiAsset, 88 | dest: MultiLocation, 89 | max_weight: Option, 90 | ) -> DispatchResult; 91 | } 92 | 93 | pub trait AssetReserveLocationParser { 94 | fn reserved_location(asset: &MultiAsset) -> Option; 95 | } 96 | -------------------------------------------------------------------------------- /xcm-bridge/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sygma-xcm-bridge" 3 | version = "0.3.0" 4 | edition = "2021" 5 | license = "LGPL-3.0" 6 | 7 | [dependencies] 8 | codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] } 9 | scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde", "decode"] } 10 | 11 | # Substrate 12 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 13 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 14 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 15 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 16 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 17 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 18 | sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 19 | sp-std = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 20 | 21 | # Polkadot 22 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 23 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 24 | xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 25 | 26 | # Cumulus 27 | cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 28 | cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 29 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0", default-features = false } 30 | 31 | # Local 32 | sygma-traits = { path = "../traits", default-features = false } 33 | sygma-bridge-forwarder = { path = "../bridge-forwarder", default-features = false } 34 | half = { version = "2.3.1", default-features = false } 35 | log = "0.4.20" 36 | 37 | [dev-dependencies] 38 | # Substrate 39 | sp-io = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 40 | sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 41 | sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 42 | frame-support = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 43 | frame-system = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 44 | pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 45 | pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 46 | pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 47 | 48 | # Polkadot 49 | xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 50 | xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 51 | xcm-simulator = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 52 | xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 53 | polkadot-parachain-primitives = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 54 | polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 55 | polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 56 | pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 57 | 58 | # Cumulus 59 | cumulus-primitives-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 60 | cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 61 | cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 62 | cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 63 | cumulus-primitives-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.2.0" } 64 | 65 | # Local 66 | sygma-traits = { path = "../traits" } 67 | pallet-parachain-info = { path = "../parachain-info" } 68 | 69 | env_logger = "0.10.2" 70 | 71 | [features] 72 | default = ["std"] 73 | std = [ 74 | "codec/std", 75 | "scale-info/std", 76 | "frame-support/std", 77 | "frame-system/std", 78 | "sp-runtime/std", 79 | "sp-std/std", 80 | "sp-core/full_crypto", 81 | "xcm/std", 82 | "xcm-builder/std", 83 | "xcm-executor/std", 84 | "pallet-balances/std", 85 | "pallet-assets/std", 86 | "cumulus-primitives-core/std", 87 | "cumulus-primitives-utility/std", 88 | "cumulus-pallet-xcm/std", 89 | "sygma-traits/std", 90 | "sygma-bridge-forwarder/std", 91 | ] 92 | runtime-benchmarks = [ 93 | 'frame-support/runtime-benchmarks', 94 | 'frame-system/runtime-benchmarks', 95 | ] 96 | try-runtime = ["frame-support/try-runtime"] 97 | -------------------------------------------------------------------------------- /xcm-bridge/src/mock/mod.rs: -------------------------------------------------------------------------------- 1 | // The Licensed Work is (c) 2022 Sygma 2 | // SPDX-License-Identifier: LGPL-3.0-only 3 | 4 | use frame_support::sp_runtime::{AccountId32, BuildStorage}; 5 | use sp_io::TestExternalities; 6 | use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; 7 | 8 | pub mod para; 9 | pub mod relay; 10 | 11 | pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); 12 | pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); 13 | pub const ASSET_OWNER: AccountId32 = AccountId32::new([2u8; 32]); 14 | pub const ENDOWED_BALANCE: u128 = 100_000_000_000_000_000_000; 15 | 16 | pub type ParaBalances = pallet_balances::Pallet; 17 | pub type ParaAssets = pallet_assets::Pallet; 18 | 19 | decl_test_parachain! { 20 | pub struct ParaA { 21 | Runtime = para::Runtime, 22 | XcmpMessageHandler = para::XcmpQueue, 23 | DmpMessageHandler = para::DmpQueue, 24 | new_ext = para_ext(1), 25 | } 26 | } 27 | 28 | decl_test_parachain! { 29 | pub struct ParaB { 30 | Runtime = para::Runtime, 31 | XcmpMessageHandler = para::XcmpQueue, 32 | DmpMessageHandler = para::DmpQueue, 33 | new_ext = para_ext(2), 34 | } 35 | } 36 | 37 | decl_test_parachain! { 38 | pub struct ParaC { 39 | Runtime = para::Runtime, 40 | XcmpMessageHandler = para::XcmpQueue, 41 | DmpMessageHandler = para::DmpQueue, 42 | new_ext = para_ext(2005), // for USDT 43 | } 44 | } 45 | 46 | decl_test_relay_chain! { 47 | pub struct Relay { 48 | Runtime = relay::Runtime, 49 | RuntimeCall = relay::RuntimeCall, 50 | RuntimeEvent = relay::RuntimeEvent, 51 | XcmConfig = relay::XcmConfig, 52 | MessageQueue = relay::MessageQueue, 53 | System = relay::System, 54 | new_ext = relay_ext(), 55 | } 56 | } 57 | 58 | decl_test_network! { 59 | pub struct TestNet { 60 | relay_chain = Relay, 61 | parachains = vec![ 62 | (1, ParaA), 63 | (2, ParaB), 64 | (2005, ParaC), 65 | ], 66 | } 67 | } 68 | 69 | pub fn para_ext(para_id: u32) -> TestExternalities { 70 | use para::{Runtime, System}; 71 | 72 | let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 73 | 74 | let parachain_info_config = pallet_parachain_info::GenesisConfig:: { 75 | parachain_id: para_id.into(), 76 | phantom: Default::default(), 77 | }; 78 | parachain_info_config.assimilate_storage(&mut t).unwrap(); 79 | 80 | // set Alice, Bob and ASSET_OWNER with ENDOWED_BALANCE amount of native asset on every parachain 81 | pallet_balances::GenesisConfig:: { 82 | balances: vec![ 83 | (ALICE, ENDOWED_BALANCE), 84 | (BOB, ENDOWED_BALANCE), 85 | (ASSET_OWNER, ENDOWED_BALANCE), 86 | ], 87 | } 88 | .assimilate_storage(&mut t) 89 | .unwrap(); 90 | 91 | let mut ext = TestExternalities::new(t); 92 | ext.execute_with(|| System::set_block_number(1)); 93 | ext 94 | } 95 | 96 | pub fn relay_ext() -> sp_io::TestExternalities { 97 | use relay::{Runtime, System}; 98 | 99 | let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); 100 | 101 | // set Alice with ENDOWED_BALANCE amount of native asset on relay chain 102 | pallet_balances::GenesisConfig:: { balances: vec![(ALICE, ENDOWED_BALANCE)] } 103 | .assimilate_storage(&mut t) 104 | .unwrap(); 105 | 106 | let mut ext = sp_io::TestExternalities::new(t); 107 | ext.execute_with(|| System::set_block_number(1)); 108 | ext 109 | } 110 | -------------------------------------------------------------------------------- /zombienet/bridge_hub_rococo_local_network.toml: -------------------------------------------------------------------------------- 1 | [settings] 2 | node_spawn_timeout = 240 3 | 4 | [relaychain] 5 | default_command = "./polkadot" 6 | default_args = [ "-lparachain=debug,xcm=trace" ] 7 | chain = "rococo-local" 8 | 9 | [[relaychain.nodes]] 10 | name = "alice-validator" 11 | validator = true 12 | rpc_port = 9932 13 | ws_port = 9942 14 | extra_args = ["--no-mdns --bootnodes {{'bob-validator'|zombie('multiAddress')}}"] 15 | 16 | [[relaychain.nodes]] 17 | name = "bob-validator" 18 | validator = true 19 | rpc_port = 9933 20 | ws_port = 9943 21 | extra_args = ["--no-mdns --bootnodes {{'alice-validator'|zombie('multiAddress')}}"] 22 | 23 | [[parachains]] 24 | id = 1013 25 | chain = "bridge-hub-rococo-local" 26 | cumulus_based = true 27 | 28 | # run alice as parachain collator 29 | [[parachains.collators]] 30 | name = "bridge-hub-alice-collator" 31 | validator = true 32 | command = "./polkadot-parachain" 33 | rpc_port = 8933 34 | ws_port = 8943 35 | args = [ 36 | "-lparachain=warn,runtime::bridge-hub=debug,runtime::bridge=trace,runtime::bridge-dispatch=debug,bridge=trace,runtime::bridge-messages=debug,xcm=trace", 37 | ] 38 | extra_args = [ 39 | "--force-authoring", "--no-mdns", "--bootnodes {{'bridge-hub-bob-collator'|zombie('multiAddress')}}", "--bootnodes {{'alice-validator'|zombie('multiAddress')}}" 40 | ] 41 | 42 | # run bob as parachain collator 43 | [[parachains.collators]] 44 | name = "bridge-hub-bob-collator" 45 | validator = true 46 | command = "./polkadot-parachain" 47 | rpc_port = 8934 48 | ws_port = 8944 49 | args = [ 50 | "-lparachain=warn,runtime::bridge-hub=debug,runtime::bridge=trace,runtime::bridge-dispatch=debug,bridge=trace,runtime::bridge-messages=debug,xcm=trace", 51 | ] 52 | extra_args = [ 53 | "--force-authoring", "--no-mdns", "--bootnodes {{'bridge-hub-alice-collator'|zombie('multiAddress')}}", "--bootnodes {{'bob-validator'|zombie('multiAddress')}}" 54 | ] 55 | 56 | [[parachains]] 57 | id = 1000 58 | chain = "asset-hub-kusama-local" 59 | cumulus_based = true 60 | 61 | [[parachains.collators]] 62 | name = "asset-hub-alice-collator" 63 | rpc_port = 9911 64 | ws_port = 9910 65 | command = "./polkadot-parachain" 66 | args = [ 67 | "-lparachain=warn,runtime::bridge-hub=debug,runtime::bridge=trace,runtime::bridge-dispatch=debug,bridge=trace,runtime::bridge-messages=debug,xcm=trace", 68 | ] 69 | extra_args = [ 70 | "--no-mdns", "--bootnodes {{'asset-hub-bob-collator'|zombie('multiAddress')}}", "--bootnodes {{'alice-validator'|zombie('multiAddress')}}" 71 | ] 72 | 73 | [[parachains.collators]] 74 | name = "asset-hub-bob-collator" 75 | rpc_port = 9811 76 | ws_port = 9810 77 | command = "./polkadot-parachain" 78 | args = [ 79 | "-lparachain=warn,runtime::bridge-hub=debug,runtime::bridge=trace,runtime::bridge-dispatch=debug,bridge=trace,runtime::bridge-messages=debug,xcm=trace", 80 | ] 81 | extra_args = [ 82 | "--no-mdns", "--bootnodes {{'asset-hub-alice-collator'|zombie('multiAddress')}}", "--bootnodes {{'alice-validator'|zombie('multiAddress')}}" 83 | ] 84 | 85 | # TODO: open an issue on zombienet repo 86 | # for now, using setup scripts to build HRMP channels 87 | #[[hrmp_channels]] 88 | #sender = 1000 89 | #recipient = 1013 90 | #max_capacity = 8 91 | #max_message_size = 1048576 92 | # 93 | #[[hrmp_channels]] 94 | #sender = 1013 95 | #recipient = 1000 96 | #max_capacity = 8 97 | #max_message_size = 1048576 98 | -------------------------------------------------------------------------------- /zombienet/local_zombienet.toml: -------------------------------------------------------------------------------- 1 | [relaychain] 2 | default_image = "docker.io/parity/polkadot:latest" 3 | default_command = "./zombienet/polkadot" 4 | default_args = [ "-lparachain=debug" ] 5 | 6 | chain = "rococo-local" 7 | 8 | [[relaychain.nodes]] 9 | name = "relaychain-alice" 10 | validator = true 11 | 12 | [[relaychain.nodes]] 13 | name = "relaychain-bob" 14 | validator = true 15 | 16 | [[parachains]] 17 | id = 1000 18 | 19 | [parachains.collator] 20 | name = "parachain-01" 21 | image = "docker.io/parity/polkadot-parachain:latest" 22 | command = "./target/release/parachain-node-template" 23 | args = ["-lparachain=debug"] 24 | -------------------------------------------------------------------------------- /zombienet/scripts/zombienet_prepare.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # The Licensed Work is (c) 2022 Sygma 3 | # SPDX-License-Identifier: LGPL-3.0-only 4 | 5 | set -e 6 | 7 | POLKADOT_SDK_VERSION='v1.2.0-rc1' 8 | 9 | POLKADOT_SDK_DIR=${PWD}/zombienet/polkadot-sdk 10 | ZOMBIENET_DIR=${PWD}/zombienet 11 | 12 | # fetch and build polkadot-sdk 13 | #git clone https://github.com/paritytech/polkadot-sdk.git ${POLKADOT_SDK_DIR} && cd ${POLKADOT_SDK_DIR} && git checkout ${POLKADOT_SDK_VERSION} && cargo build --release 14 | 15 | # copy polkadot binaries 16 | cp ${POLKADOT_SDK_DIR}/target/release/polkadot ${ZOMBIENET_DIR}/polkadot 17 | cp ${POLKADOT_SDK_DIR}/target/release/polkadot-execute-worker ${ZOMBIENET_DIR}/polkadot-execute-worker 18 | cp ${POLKADOT_SDK_DIR}/target/release/polkadot-prepare-worker ${ZOMBIENET_DIR}/polkadot-prepare-worker 19 | 20 | # grant execution permission 21 | chmod +x ${ZOMBIENET_DIR}/polkadot 22 | chmod +x ${ZOMBIENET_DIR}/polkadot-execute-worker 23 | chmod +x ${ZOMBIENET_DIR}/polkadot-prepare-worker 24 | 25 | # fetch zombienet binary 26 | echo "Please fetch zombienet binary based on your OS to this location: ${ZOMBIENET_DIR}/" 27 | echo "Zombienet Docs: https://github.com/paritytech/zombienet?tab=readme-ov-file" 28 | echo "Zombienet binary can be found: https://github.com/paritytech/zombienet/releases" 29 | echo "Make sure to grand execution permission to zombienet binary" 30 | 31 | echo "Cleaning up..." 32 | rm -rf ${POLKADOT_SDK_DIR} 33 | 34 | echo "done" 35 | --------------------------------------------------------------------------------