Cosmos BSN Contracts
This repository contains the CosmWasm smart contracts that enable the
integration of Cosmos BSNs with the Babylon BTC Staking protocol.
Architecture
The contracts are written in Rust, and use the CosmWasm framework to interact
with the BSN's Cosmos application layer. There's a thin layer which adds a
babylon
module ,
which provides the necessary functionality to interact with the contracts
through privileged calls (sudo messages) and custom messages. This thin layer
is naturally written in Go, and uses the Cosmos SDK.
An integrator can import the babylon module into their Cosmos SDK-based chain,
and use the provided functionality to interact with the Cosmos BSN contracts,
following the demo app's guidelines and layout, which is provided in
babylon-sdk as well.
The entire solution is designed to be modular and extensible, for ease of
integration and future upgrades.
A broad architecture diagram, along with the contracts' main interfaces, can be
found in the docs/ARCHITECTURE.md documentation.
Contract Migration
All contracts support CosmWasm's built-in migration mechanism for upgrading
contract logic while preserving state. For detailed migration procedures,
troubleshooting, and best practices, see the MIGRATION.md
guide.
Development
Prerequisites
Make sure you have cargo-run-script installed and docker running.
cargo install cargo-run-scriptClean the build
cargo cleanBuild the contract
cargo buildFormatting and Linting
Check whether the code is formatted correctly.
cargo fmt --all -- --check
cargo check
cargo clippy --all-targets -- -D warningsAlternatively, you can run the following command to run all the checks at once.
cargo run-script lintTest the contract
Note: Requires the optimized contract to be built (cargo optimize)
Runs all the CI checks locally (in your actual toolchain).
cargo test --libIntegration tests the contract
Note: Requires the optimized contract to be built (cargo optimize)
cargo test --test integrationAlternatively, you can run the following command, that makes sure to build the
optimized contract before running the integration tests.
cargo run-script integrationE2E tests
cargo run-script e2eGenerate the schema
cargo run-script gen-schemaGenerate the protobuf files
cargo run-script gen-protoGenerate test data
cargo run-script gen-dataBuild the optimized contract
cargo run-script optimize