Skip to content

mars-protocol/core-contracts

Repository files navigation

Mars Protocol: Red Bank

This repository contains the source code for the core smart contracts of Mars Red Bank. Smart contracts are meant to be compiled to .wasm files and uploaded to the Cosmos chains.

Audits

See reports here.

Bug bounty

A bug bounty is currently open for these contracts. See details here.

Verify contracts

For contracts deployed on the Osmosis chain

  1. Install Osmosisd

  2. Get the wasm binary executable on your local machine.

    git clone https://github.com/mars-protocol/red-bank.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.

  3. Download the wasm from the chain.

    osmosisd query wasm code $CODEID -- $NODE download.wasm
  4. Verify that the diff is empty between them. If any value is returned, then the wasm files differ.

    diff artifacts/$CONTRACTNAME.wasm download.wasm
  5. Alternatively, compare the wasm files' checksums:

    sha256sum artifacts/$CONTRACTNAME.wasm download.wasm

Environment set up

  • Install rustup. Once installed, make sure you have the wasm32 target:

    rustup default stable
    rustup update stable
    rustup target add wasm32-unknown-unknown
  • Install cargo-make

    cargo install --force cargo-make
  • 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 osmo-test-4.json file 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 testnet deployment with deployerAddr set as owner & admin:
yarn deploy:osmosis-testnet

# for testnet deployment with multisigAddr set as owner & admin:
yarn deploy:osmosis-testnet-multisig

# 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:

cargo +nightly fmt

clippy is used as a linting tool:

cargo make clippy

Testing

Integration tests (task integration-test or test) use .wasm files. They have to be generated with cargo make build.

Run unit tests:

cargo make unit-test

Run integration tests:

cargo make integration-test

Run all tests:

cargo make test

Deployments

osmosis-1

Contract Address
mars-address-provider osmo1g677w7mfvn78eeudzwylxzlyz69fsgumqrscj6tekhdvs8fye3asufmvxr
mars-incentives osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm
mars-oracle osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g
mars-red-bank osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg
mars-rewards-collector osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy

osmo-test-5

Contract Address
mars-address-provider osmo1wlm6dc0vnncu2v5z26rv97plmlkmalm84uwqatrlftc4gmp8ahgqs6r4py
mars-incentives osmo1zyz57xf82963mcsgqu3hq5y0h9mrltm4ttq2qe5mjth9ezp3375qe0sm7d
mars-oracle osmo1khe29uw3t85nmmp3mtr8dls7v2qwsfk3tndu5h4w5g2r5tzlz5qqarq2e2
mars-red-bank osmo1dl4rylasnd7mtfzlkdqn2gr0ss4gvyykpvr6d7t5ylzf6z535n9s5jjt8u
mars-rewards-collector osmo1u5pcjue4grmg8lh7xrz2nvpy79xlzknwqkczfkyeyx9zzzj76tpq4tgrcs

License

Contents of this repository are open source under GNU General Public License v3 or later.