This repository is a collection of smart contracts built with the cosmwasm framework.
The repo's organization is relatively simple. The top-level directory is just a placeholder and has no real code. And we use workspaces to add multiple contracts below. This allows us to compile all contracts with one command.
The following contracts are available for use. For each of the contracts in ./contracts
, you can view the source code under src
A basic contract to burn token balances.
The cw20 tokens manager allow users to pay a token_creation_fee
to mint cw20 tokens managed by this contract.
A constant product (AMM) implementation that allows the trading of any CW20
or IBC
tokens quoted against the base token (HUAHUA
).
Before you merge the code, make sure it builds and passes all tests using the command below.
$ cargo test
You can build release artifacts manually like this, which creates a reproducible
optimized build for each contract and saves them to the ./artifacts
directory:
$ 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/rust-optimizer:0.12.6
(See instructions on how install chihuahuad
)
$ open ~/.chihuahua/config/config.toml
$ cargo install cargo-generate --features vendored-openssl
$ cargo generate --git <https://github.com/CosmWasm/cosmwasm-template.git> --name my-first-contract
https://testnet.ping.pub/chihuahua
https://testnet.explorer.erialos.me/chihuahua
$ chihuahuad keys add <wallet_name> --recover
$ chihuahuad keys list
$ source ~/.profile
$ export CHAIN_ID="chitestnet-5"
$ export RPC="https://chihuahua-testnet-rpc.polkachu.com:443"
$ export NODE=(--node $RPC)
$ export TXFLAG=($NODE --chain-id $CHAIN_ID --gas-prices 0.25stake --gas auto --gas-adjustment 1.3)
$ export TXFLAG_LOCAL=(--gas-prices 0.25stake --gas auto --gas-adjustment 1.3 --keyring-backend test)
$ chihuahuad query bank total $NODE
$ chihuahuad query bank balances $(chihuahuad keys show -a palingram) $NODE
$ chihuahuad tx bank send <sender_account_name> <receiver_address> <amount><denom> $TXFLAG
$ chihuahuad query wasm list-code $NODE
$ export RES=$(chihuahuad tx wasm store artifacts/<contract_name.wasm> --from <account_name> $TXFLAG -y --output json -b block)
$ export CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[0].value')
$ echo $CODE_ID
$ chihuahuad query wasm list-contract-by-code $CODE_ID $NODE --output json
$ export INIT='{}'
$ chihuahuad tx wasm instantiate $CODE_ID "$INIT" --from <account_name> --label "BURN TEST CONTRACT" $TXFLAG -y --no-admin
$ export CONTRACT=$(wasmd query wasm list-contract-by-code $CODE_ID $NODE --output json | jq -r '.contracts[-1]')
$ echo $CONTRACT
$ chihuahuad query wasm contract $CONTRACT $NODE
$ chihuahuad query bank balances $CONTRACT $NODE
$ chihuahuad query wasm contract-state all $CONTRACT $NODE
$ chihuahuad query wasm contract-state raw $CONTRACT 636F6E666967 $NODE --output "json" | jq -r '.data' | base64 -d
$ export E_PAYLOAD='{"burn_contract_balance":{}}'
$ chihuahuad tx wasm execute $CONTRACT "$E_PAYLOAD" --amount 1000000000stake --from palingram $NODE $TXFLAG -y
$ export Q_PAYLOAD='{"query_list":{}}'
$ chihuahuad query wasm contract-state smart $CONTRACT "$Q_PAYLOAD" $NODE --output json