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

devnet (Osmosis)

Contract Address
mars-address-provider osmo1g677w7mfvn78eeudzwylxzlyz69fsgumqrscj6tekhdvs8fye3asufmvxr
mars-account-nft osmo1450hrg6dv2l58c0rvdwx8ec2a0r6dd50hn4frk370tpvqjhy8khqw7sw09
mars-credit-manager osmo1f2m24wktq0sw3c0lexlg7fv4kngwyttvzws3a3r3al9ld2s2pvds87jqvf
mars-health osmo1kqzkuyh23chjwemve7p9t7sl63v0sxtjh84e95w4fdz3htg8gmgspua7q4
mars-incentives osmo1nkahswfr8shg8rlxqwup0vgahp0dk4x8w6tkv3rra8rratnut36sk22vrm
mars-oracle osmo1mhznfr60vjdp2gejhyv2gax9nvyyzhd3z0qcwseyetkfustjauzqycsy2g
mars-params osmo1aye5qcer5n52crrkaf35jprsad2807q6kg3eeeu7k79h4slxfausfqhc9y
mars-red-bank osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg
mars-rewards-collector osmo1urvqe5mw00ws25yqdd4c4hlh8kdyf567mpcml7cdve9w08z0ydcqvsrgdy
mars-swapper osmo1wee0z8c7tcawyl647eapqs4a88q8jpa7ddy6nn2nrs7t47p2zhxswetwla
mars-zapper osmo17qwvc70pzc9mudr8t02t3pl74hhqsgwnskl734p4hug3s8mkerdqzduf7c

neutron-1

Contract Address Tag
mars-address-provider neutron17yehp4x7n79zq9dlw4g7xmnrvwdjjj2yecq26844sg8yu74knlxqfx5vqv v1.2.0
mars-incentives neutron1aszpdh35zsaz0yj80mz7f5dtl9zq5jfl8hgm094y0j0vsychfekqxhzd39 v1.2.0
mars-oracle neutron1dwp6m7pdrz6rnhdyrx5ha0acsduydqcpzkylvfgspsz60pj2agxqaqrr7g v1.3.0
mars-red-bank neutron1n97wnm7q6d2hrcna3rqlnyqw2we6k0l8uqvmyqq6gsml92epdu7quugyph v1.2.2
mars-rewards-collector neutron1h4l6rvylzcuxwdw3gzkkdzfjdxf4mv2ypfdgvnvag0dtz6x07gps6fl2vm v1.2.0
mars-swapper neutron1udr9fc3kd743dezrj38v2ac74pxxr6qsx4xt4nfpcfczgw52rvyqyjp5au v1.2.0

pion-1 (Neutron)

Contract Address
mars-address-provider neutron187fjlesys2c0z7xzhu43we4rx7tc4twnr5m6r2u7u5hpm03wvjqs0gk2lp
mars-incentives neutron187hw8pqfhmxt4tk9star7tkjhu438k566jtgjskz4889pndp2vysh73ezh
mars-oracle neutron1g4samkydfdyjec424ccucvjcuuls0ql8mfp2glf739mg0uqr74yqhdx9kn
mars-red-bank neutron15dn9w9vcdkpp2kfjuz4suqh2w8ajyqsgujlykm9x58hsjss5ff7qpmhlln
mars-rewards-collector neutron1re4v85k6kr8r7f3j4s4vrk3dvlyefc3xeg7jetv2jlpskahs5xrs8d6vw5
mars-swapper neutron16xdh5w4dynfjrvnfuhv9h2znks94fyt4gp448jhtmjs3xd6smjvqumh9x2

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.