Skip to content

CosmWasm/cw-plus

Repository files navigation

CosmWasm Plus

CircleCI

Specification Download Docs
cw0 cw0 on crates.io Docs
cw1 cw1 on crates.io Docs
cw2 cw2 on crates.io Docs
cw3 cw3 on crates.io Docs
cw20 cw20 on crates.io Docs
cw721 cw721 on crates.io Docs
Contracts Download Docs
cw1-subkeys cw1-subkeys on crates.io Docs
cw1-whitelist cw1-whitelist on crates.io Docs
cw3-fixed-multisig cw3-fixed-multisig on crates.io Docs
cw20-atomic-swap cw20-atomic-swap on crates.io Docs
cw20-base cw20-base on crates.io Docs
cw20-escrow cw20-escrow on crates.io Docs
cw20-staking cw20-staking on crates.io Docs
cw721-base cw721-base on crates.io Docs

This is a collection of specification and contracts designed for use on real networks. They are designed not just as examples, but to solve real-world use cases, and to provide a reusable basis to build many custom contracts.

If you don't know what CosmWasm is, please check out our homepage and our documentation to get more background. We are running a public testnet you can use to test out any contracts.

Warning None of these contracts have been audited and no liability is assumed for the use of any of this code. They are provided to turbo-start your projects.

Note All code in pre-1.0 packages is in "draft" form, meaning it may undergo minor changes and additions until 1.0. For example between 0.1 and 0.2 we adjusted the Expiration type to make the JSON representation cleaner (before: expires: {at_height: {height: 12345}} after expires: {at_height: 12345})

Specifications

The most reusable components are the various cwXYZ specifications under packages. Each one defines a standard interface for different domains, eg. cw20 for fungible tokens, cw721 for non-fungible tokens, cw1 for "proxy contracts", etc. The interface comes with a human description in the READMEs, as well as Rust types that can be imported.

They contain no logic, but specify an interface. It shows what you need to implement to create a compatible contracts, as well as what interface we guarantee to any consumer of such contracts. This is the real bonus of specifications, we can create an escrow contract that can handle many different fungible tokens, as long as they all adhere to the cw20 specification.

If you have ideas for new specifications or want to make enhancements to existing spec, please raise an issue or create a pull request on this repo.

Contracts

We provide sample contracts that either implement or consume these specifications to both provide examples, as well as provide a basis for code you can extend for more custom contacts, without worrying about reinventing the wheel each time. For example cw20-base is a basic implementation of a cw20 compatible contract that can be imported in any custom contract you want to build on it.

CW1 Proxy Contracts:

  • cw1-whitelist a minimal implementation of cw1 mainly designed for reference
  • cw1-subkeys a simple, but useful implementation, which lets us use a proxy contract to provide "allowances" for native tokens without modifying the bank module

CW20 Fungible Tokens:

  • cw20-base a straightforward, but complete implementation of the cw20 spec along with all extensions. Can be deployed as-is, or imported by other contracts
  • cw20-staking provides staking derivatives, staking native tokens on your behalf and minting cw20 tokens that can be used to claim them. It uses cw20-base for all the cw20 logic and only implements the interactions with the staking module and accounting for prices
  • cw20-escrow is a basic escrow contract (arbiter can release or refund tokens) that is compatible with all native and cw20 tokens. This is a good example to show how to interact with cw20 tokens.

Compiling

To compile all the contracts, 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.10.3

This will compile all packages in the contracts directory and output the stripped and optimized wasm code under the artifacts directory as output, along with a checksums.txt file.

If you hit any issues there and want to debug, you can try to run the following in each contract dir: RUSTFLAGS="-C link-arg=-s" cargo build --release --target=wasm32-unknown-unknown --locked

Licenses

This repo contains two license, Apache 2.0 and AGPL 3.0. All crates in this repo may be licensed as one or the other. Please check the NOTICE in each crate or the relevant Cargo.toml file for clarity.

All specifications will always be Apache-2.0. All contracts that are meant to be building blocks will also be Apache-2.0. This is along the lines of Open Zepellin or other public references.

Contracts that are "ready to deploy" may be licensed under AGPL 3.0 to encourage anyone using them to contribute back any improvements they make. This is common practice for actual projects running on Ethereum, like Uniswap or Maker DAO.