Smart contracts for Mars Outposts
This repository contains the source code for the core smart contracts of Mars Protocol. Smart contracts are meant to be compiled to .wasm files and uploaded to the Cosmos chains.
Audits
See reports for red-bank and rover here.
Bug bounty
A bug bounty is currently open for these contracts. See details here.
Verify contracts
For contracts deployed on the Osmosis chain
-
Install Osmosisd
-
Get the wasm binary executable on your local machine.
git clone https://github.com/mars-protocol/contracts.git git checkout <commit-id> cargo make rust-optimizer
Note: Intel/Amd 64-bit processor is required. While there is experimental ARM support for CosmWasm/rust-optimizer, it's discouraged to use in production and the wasm bytecode will not match up to an Intel compiled wasm file.
-
Download the wasm from the chain.
osmosisd query wasm code $CODEID -- $NODE download.wasm
-
Verify that the diff is empty between them. If any value is returned, then the wasm files differ.
diff artifacts/$CONTRACTNAME.wasm download.wasm -
Alternatively, compare the wasm files' checksums:
sha256sum artifacts/$CONTRACTNAME.wasm download.wasm
Environment set up
-
Install cargo-make
cargo install --force cargo-make
-
Install rust
cargo make install-stable
-
Install Docker
-
Install Node.js v16
-
Install Yarn
-
Create the build folder:
cd scripts yarn yarn build -
Compile all contracts:
cargo make rust-optimizer
-
Formatting:
cd scripts yarn format yarn lint
This compiles and optimizes all contracts, storing them in /artifacts directory along with checksum.txt which contains sha256 hashes of each of the .wasm files (The script just uses CosmWasm's rust-optimizer).
Note: Intel/Amd 64-bit processor is required. While there is experimental ARM support for CosmWasm/rust-optimizer, it's discouraged to use in production.
Deployment
When the deployment scripts run for the first time, it will upload code IDs for each contract, instantiate each contract, initialize assets, and set oracles. If you want to redeploy, you must locally delete the file with .json extension (e.g. devnet-deployer-owner.json) in the artifacts directory.
Everything related to deployment must be ran from the scripts directory.
Each outpost has a config file for its respective deployment and assets.
For Osmosis:
cd scripts # for devnet deployment with deployerAddr set as owner & admin: yarn deploy:osmosis-devnet # for mainnet deployment: yarn deploy:osmosis-mainnet
Schemas
cargo make --makefile Makefile.toml generate-all-schemas
Creates JSON schema files for relevant contract calls, queries and query responses (See: cosmwams-schema).
Linting
rustfmt is used to format any Rust source code:
clippy is used as a linting tool:
Testing
Install Go. It is used by osmosis-test-tube dependency.
Integration tests (task integration-test or test) use .wasm files. They have to be generated with cargo make build.
Run unit tests:
Run integration tests:
cargo make integration-test
Run all tests:
Deployments
osmosis-1
neutron-1
See repo: core-contracts
mars-1
| Module Account | Address |
|---|---|
fee_collector |
mars17xpfvakm2amg962yls6f84z3kell8c5ldy6e7x |
safety |
mars1s4hgh56can3e33e0zqpnjxh0t5wdf7u3pze575 |
License
Contents of this repository are open source under GNU General Public License v3 or later.