6 releases

0.1.6 Dec 28, 2023
0.1.5 Nov 13, 2023
0.1.3 Jul 17, 2023
0.1.2 Jun 12, 2023
0.1.1 Dec 16, 2022

#2136 in Magic Beans

Download history 7/week @ 2023-12-30 1/week @ 2024-01-13 40/week @ 2024-01-20 51/week @ 2024-01-27 15/week @ 2024-02-03 19/week @ 2024-02-10 49/week @ 2024-02-17 77/week @ 2024-02-24 54/week @ 2024-03-02 67/week @ 2024-03-09 78/week @ 2024-03-16 3/week @ 2024-03-23 46/week @ 2024-03-30 5/week @ 2024-04-06 5/week @ 2024-04-13

64 downloads per month

Apache-2.0

465KB
10K SLoC

Injective Cosmwasm

This repository contains packages and examples for how to use CosmWasm with Injective.

Packages

These packages can be used to integrate CosmWasm and Injective.

Package Description
injective-cosmwasm Package for Injective-specific queries and messages.
injective-math Math utility library including custom FPDecimal type.
injective-protobuf Rust protobuf files generation for Injective messages.
injective-std Injective's proto-generated types and helpers built using Buf. Enables interaction with both custom and standard modules.

Example Contracts

These contracts can be used as examples for CosmWasm and Injective.

Contract Description
dummy A simply template for starting a new contract.
atomic-order-example Example contract on how to do atomic market orders on Injective incl handling the response.
swap-contract More complex atomic swaps over multiple market hops.

Development

Environment Setup

  • Rust v1.69.0
  • wasm32-unknown-unknown target
  • Docker
  1. Install rustup
  2. Run the following
rustup default 1.69.0
rustup target add wasm32-unknown-unknown
  1. Make sure Docker is installed on your machine

Unit / Integration Test

Each contract contains Rust unit tests embedded within the contract source directories. You can run

cargo unit-test

Compiling

Go to the contract directory and run

After making sure tests pass, you can compile each contract with the following

RUSTFLAGS='-C link-arg=-s' cargo wasm
sha256sum target/wasm32-unknown-unknown/release/<CONTRACT_NAME>.wasm

Production

For production builds, run the following:

docker run --rm -v "$(pwd)":/code \
  --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
  --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
  cosmwasm/workspace-optimizer:0.13.0

This performs several optimizations which can significantly reduce the final size of the contract binaries, which will be available inside the artifacts/ directory.

Formatting

Make sure you run rustfmt before creating a PR to the repo.

To run rustfmt,

cargo fmt

Linting

You should run clippy also. This is a lint tool for Rust. It suggests more efficient/readable code. You can see the clippy document for more information.

Run

cargo clippy -- -D warnings

Testing

Developers are strongly encouraged to write unit tests for new code, and to submit new unit tests for old code. Unit tests can be compiled and run with: cargo test --all. For more details, please reference Unit Tests.

Dependencies

~11MB
~232K SLoC