hackbg / okp4-contracts

πŸ“œ Smart contracts for the OKP4 network built on CosmWasm.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ“œ OKP4 Smart Contracts

CosmWasm contracts for the OKP4 network.

release build lint test coverage conventional commits semantic-release license

✨ Smart Contracts

This repository hosts Smart Contracts that are deployed on the OKP4 network. But they are compatible with any Cosmos blockchains that uses the CosmWasm framework.

πŸ—„οΈ Storage oriented Smart Contracts

contract kind state description status
objectarium
objectarium
object immutable Persists unstructured data on-chain. βœ…
cognitarium
cognitarium
semantic mutable Persists semantic data on-chain. 🚧

βš–οΈ Sovereignty oriented Smart Contracts

contract state description status
law-stone
law‑stone
immutable Interprets governances expressed as Prolog program. βœ…

πŸ—‚ Directory Structure

The project is structured around a set of Rust workspaces, each defining a smart contract.

.
β”œβ”€β”€ contracts
β”‚   └── <contract>
β”‚       β”œβ”€β”€ Cargo.toml
β”‚       β”œβ”€β”€ examples
β”‚       β”œβ”€β”€ schema
β”‚       └── src
β”œβ”€β”€ packages
β”‚   └── <package>
β”‚       β”œβ”€β”€ Cargo.toml
β”‚       β”œβ”€β”€ examples
β”‚       └── src
└─── Cargo.toml

πŸ— Build

Pre-requisites

Be sure you have the following tools installed:

And the following common GNU Core utilities:

Compiling Smart Contracts to Wasm

To compile the Smart Contracts to Wasm, just invoke the wasm goal of the makefile:

cargo make wasm

This will install the rust Wasm toolchain, if not already done, and start the process for compiling the Smart Contracts to Wasm.

Test Smart Contracts

The Smart Contracts are under unit testing. The tests can be launched with the following invocation:

cargo make test-coverage

πŸ“ Play with the Smart Contracts

The project comes with a set of convenient tasks to manage the Smart Contracts and the blockchain. To see the list of available tasks, run the following command:

cargo make --list-all-steps | grep chain | sort | sed -r 's/chain(-?[a-zA-Z\-]*)/- `chain\1`/'

The list of available tasks for managing the chain is as follows:

  • chain - Run the okp4d CLI using the chain's home directory under a Docker container.
  • chain-add-keys - Add a set of predefined keys (recovered from the seed phrases) to the chain.
  • chain-clean - Clean the chain data (⚠️ definitively)
  • chain-deploy-contract - Deploy a specific contract to the chain. The contract must be compiled and the wasm file must be present in the artifacts directory (under target/wasm32-unknown-unknown/...).
  • chain-deploy-contracts - Deploy all the available contracts to the chain (under target/wasm32-unknown-unknown/...).
  • chain-execute-contract - Execute a command on a specific contract to the chain. The contract must be already deployed and instantiated.
  • chain-init-folder - Initialize deploy folder to make sure scripts have the right permission (needed for linux)
  • chain-initialize - Initialize the chain with a validator's key and a set of predefined keys. ⚠️ The home directory is cleaned before.
  • chain-inspect-contract - Inspect a specific contract deployed to the chain.
  • chain-instantiate-contract - Instantiate a specific contract to the chain. The contract must be already deployed.
  • chain-list-contracts - List all the contracts deployed to the chain.
  • chain-logs - Show the chain's container logs.
  • chain-query-contract - Query a specific contract to the chain. The contract must be already deployed and instantiated.
  • chain-start - Run the full node okp4d application using the chain's home directory under a Docker container.
  • chain-stop - Stop the chain's container.

Initialize the chain

To initialize the chain, just run:

cargo make chain-initialize

This will initialize the chain's home directory and create a validator's key and a set of predefined keys (recovered from the seed phrases).

Start the chain

To start the chain, just run:

cargo make chain-start

This will start the chain's container and run the full node wasmd application.

You can check the chain's logs with:

cargo make chain-logs

Deploy the Smart Contracts

To deploy the Smart Contracts, just run:

cargo make chain-deploy-contracts

This will deploy all the available contracts to the chain. For this, the contracts must be compiled and the wasm files must be present in the artifacts directory. See the Build section for more details.

Now, you can interact with the deployed smart contracts and test them out.

Free execution of the CLI command

You can freely interact with the local chain by executing the following CLI command. This will execute the okp4d binary inside a Docker container with the --home argument pointing to the chain's home directory and using the same network as the chain's container. The arguments passed to the command will be directly passed to the okp4d binary.

cargo make chain <command>

For example, to check the status of the chain, just run:

cargo make chain status

Stop the chain

To stop the chain, just run:

cargo make chain-stop

Clean the chain

To clean the chain, just run:

cargo make chain-clean

⚠️ Please be cautious when running this command as it will completely clean the chain's home directory and the action is irreversible.

Develop

Smart Contracts scaffolding

When developing a new Smart Contract, you can use the scaffolding to generate the Smart Contract's code.

Pre-requisites

Be sure you have the following tools installed:

Generate the scaffolding

To generate the scaffolding, just run:

cargo make scaffold-smart-contract

Then, follow the instructions.

Documentation

The documentation of the smart contracts must be committed to the repository. The documentation is generated from the smart contracts' schema.

To generate the documentation follow the steps below.

Pre-requisites

Be sure you have the following tools installed:

  • Yarn v1.22.10 or higher

Then, install the dependencies:

yarn global add @adobe/jsonschema2md@7.1.5

Generate the documentation

To generate the documentation, just run:

cargo make schema
cargo make docs-generate

You'll find the generated documentation under the docs folder.

Commit the documentation

When developing a new contract, you should commit the generated documentation to the repository. For this, gerenate the documentation and commit the changes:

git commit -am "docs: update generated documentation"

Resources

You want to get involved? 😍

So you want to contribute? Great! ❀️ We appreciate any help you're willing to give. Don't hesitate to open issues and/or submit pull requests.

Please check out OKP4 health files:

About

πŸ“œ Smart contracts for the OKP4 network built on CosmWasm.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Rust 98.5%Language:Prolog 1.5%