Giter Club home page Giter Club logo

mars-core's Introduction

Mars Protocol

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 Terra blockchain.

Bug bounty

A bug bounty is currently open for these contracts. See details at: https://immunefi.com/bounty/marsprotocol/

Verify contracts

Follow these instructions to verify that the smart contracts that exist on chain correspond to a particular version of the contract's source code:

  1. Find the code ID of the contract you wish to verify.

    This can be found on the smart contract's page on Terra Finder.

  2. Get the SHA256 checksum of the code ID's wasm binary:

    • One way to do this is to get the checksum directly from the blockchain:
    curl "https://fcd.terra.dev/terra/wasm/v1beta1/codes/${CODE_ID}" \
      | jq ".code_info.code_hash" \
      | tr -d \" \
      | base64 -d \
      | hexdump -v -e '/1 "%02x"'
    
    • Alternatively, download the wasm byte code relating to the code ID from the blockchain and calculate its SHA256 checksum:
    curl "https://fcd.terra.dev/terra/wasm/v1beta1/codes/${CODE_ID}/byte_code" \
      | jq ".byte_code" \
      | tr -d \" \
      | base64 -d \
      | shasum -a 256
    
  3. Get the SHA256 checksum of a smart contract's wasm binary built from source code. To do this, first clone this repo, checkout a particular release, compile the smart contracts using the same version of rust-optimizer listed in the releases, and verify the checksum written to artifacts/checksums.txt.

  4. Finally, verify that the two checksums are identical.

Building

Smart contracts

./scripts/build_artifacts.sh

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

Schemas

./scripts/build_schema.sh

Is equivalent of running cargo schema in each of the smart contracts in /contracts directory, which creates JSON schema files for relevant contract calls, quieries and query responses (See: cosmwams-schema.

Linting

rustfmt is used to format any Rust source code:

cargo fmt

clippy is used as a linting tool:

cargo +nightly clippy --tests --all-features -- -D warnings

Setup for Node.js scripts

Node.js scripts are used for deploying and integration testing. These scripts must be run from the scripts directory.

Setup:

cd scripts
npm install

TypeScript scripts must be executed with ts-node using:

node --loader ts-node/esm <script>.ts

Deploying

# build the smart contracts
./scripts/build_artifacts.sh

cd scripts
npm install

# set the deploying wallet
echo "TEST_MAIN=<MNEMONIC_OF_YOUR_DEPLOYING_WALLET>" >> .env

# set the network, defaults to LocalTerra if unset
echo "NETWORK=testnet" >> .env

# ensure the deploy_config.ts has a cw20_code_id specified for above network

node --loader ts-node/esm deploy.ts

Testing

Unit tests

# inside a package to run specific package tests
cargo unit-test

# in the root directory to run all tests
cargo test

Integration tests

Local Terra

Integration tests require LocalTerra to be running:

git clone https://github.com/terra-money/LocalTerra.git
cd LocalTerra
docker compose up

Adjust the timeout_* config items in LocalTerra/config/config.toml to 250ms to make the test run faster:

sed -E -I .bak '/timeout_(propose|prevote|precommit|commit)/s/[0-9]+m?s/250ms/' config/config.toml

Environment variables

Required environment variables (can be set in scripts/.env):

CW_PLUS_ARTIFACTS_PATH # path to cw-plus artifacts (example cw20-base.wasm)
ASTROPORT_ARTIFACTS_PATH # path to astroport artifacts
MARS_MOCKS_ARTIFACTS_PATH # path to mars-mocks artifacts

Running a single integration test

cd scripts
node --loader ts-node/esm tests/<test>.ts

Running the main integration test suite

  1. Get LocalTerra repo and set LOCAL_TERRA_REPO_PATH env variable to its path.
  2. Run run_tests.sh from the scripts directory:
cd scripts
./run_tests.sh

Generating a whitelist.json

  1. Create a .env file in the top level of the scripts directory if doesn't already exist
  2. Add the env variable NETWORK=[network_to_generate_from_e.g._NETWORK=testnet]
  3. Add the env variable REDBANK_ADDRESS=[your_deployed_red_bank_contract_address]
  4. Run node --loader ts-node/esm whitelist.ts
  5. Check the whitelists folder for [NETWORK].json output

License

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

mars-core's People

Contributors

spikeonmars avatar piobab avatar harryscholes avatar larry0x avatar dancreee avatar genysys avatar lsuanet avatar lukesaunders avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.