Skip to content

mars-protocol/contracts

Repository files navigation

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

  1. Install Osmosisd

  2. 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.

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

cargo make fmt

clippy is used as a linting tool:

cargo make clippy

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:

cargo make unit-test

Run integration tests:

cargo make integration-test

Run all tests:

cargo make test

Deployments

osmosis-1

Contract Address Tag
mars-address-provider osmo1g677w7mfvn78eeudzwylxzlyz69fsgumqrscj6tekhdvs8fye3asufmvxr v2.0.0
mars-account-nft osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09 v2.0.0
mars-credit-manager osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf v2.0.5
mars-health osmo1pdc49qlyhpkzx4j24uuw97kk6hv7e9xvrdjlww8qj6al53gmu49sge4g79 v2.0.0
mars-incentives osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm v2.0.0
mars-oracle osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g v2.0.1
mars-params osmo1nlmdxt9ctql2jr47qd4fpgzg84cjswxyw6q99u4y4u4q6c2f5ksq7ysent v2.0.3
mars-red-bank osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg v2.0.5
mars-rewards-collector osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy v2.0.4
mars-swapper osmo1wee0z8c7tcawyl647eapqs4a88q8jpa7ddy6nn2nrs7t47p2zhxswetwla v2.0.7
mars-zapper osmo17qwvc70pzc9mudr8t02t3pl74hhqsgwnskl734p4hug3s8mkerdqzduf7c v2.0.0

neutron-1

Contract Address Tag
mars-address-provider neutron17yehp4x7n79zq9dlw4g7xmnrvwdjjj2yecq26844sg8yu74knlxqfx5vqv v2.1.0
mars-account-nft neutron184kvu96rqtetmunkkmhu5hru8yaqg7qfhd8ldu5avjnamdqu69squrh3f5 v2.1.0
mars-credit-manager neutron1qdzn3l4kn7gsjna2tfpg3g3mwd6kunx4p50lfya59k02846xas6qslgs3r v2.1.0
mars-health neutron17ktfwsr7ghlxzzma0gw0hke3j3rnssd58q87jv2wzfrk6uhawa3sv8xxtm v2.1.0
mars-incentives neutron1aszpdh35zsaz0yj80mz7f5dtl9zq5jfl8hgm094y0j0vsychfekqxhzd39 v2.1.0
mars-oracle neutron1dwp6m7pdrz6rnhdyrx5ha0acsduydqcpzkylvfgspsz60pj2agxqaqrr7g v2.1.0
mars-params neutron1x4rgd7ry23v2n49y7xdzje0743c5tgrnqrqsvwyya2h6m48tz4jqqex06x v2.1.0
mars-red-bank neutron1n97wnm7q6d2hrcna3rqlnyqw2we6k0l8uqvmyqq6gsml92epdu7quugyph v2.1.0
mars-rewards-collector neutron1h4l6rvylzcuxwdw3gzkkdzfjdxf4mv2ypfdgvnvag0dtz6x07gps6fl2vm v2.1.0
mars-swapper neutron1udr9fc3kd743dezrj38v2ac74pxxr6qsx4xt4nfpcfczgw52rvyqyjp5au v2.1.0
mars-zapper neutron1dr0ckm3u2ztjuscmgqjr85lwyduphxkgl3tc02ac8zp54r05t5dqp5tgyq v2.1.0

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.