Skip to content

Commit

Permalink
Added cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kpachhai committed Oct 22, 2024
1 parent 15d9da1 commit 23a69c3
Show file tree
Hide file tree
Showing 120 changed files with 9,753 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[workspace]
members = [
"x/contracts/sdk-macros",
"x/contracts/wasmlanche",
"x/contracts/examples/token",
"x/contracts/examples/counter",
"x/contracts/examples/counter-external",
"x/contracts/examples/automated-market-maker",
"x/contracts/wasmlanche/tests/test-crate",
"x/contracts/test/contracts/*",
"x/contracts/simulator",
"x/contracts/examples/tutorial",
"x/contracts/examples/multisig",
]
resolver = "2"

[profile.release]
opt-level = "s"
lto = true
codegen-units = 1
overflow-checks = true
panic = 'abort'
strip = true

[workspace.dependencies]
sdk-macros = { path = "x/contracts/sdk-macros" }
wasmlanche = { path = "x/contracts/wasmlanche" }
simulator = { path = "x/contracts/simulator" }
thiserror = "1.0.61"
1 change: 0 additions & 1 deletion actions/contract_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (t *ContractCall) Execute(
actor codec.Address,
_ ids.ID,
) (codec.Typed, error) {

callInfo := &runtime.CallInfo{
Contract: t.ContractAddress,
Actor: actor,
Expand Down
88 changes: 88 additions & 0 deletions docs/demos/wasm_smart_contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# WASM Smart Contracts

TODO: This is a work in progress.

## Pre-requisites

First install the following dependencies:

### Install Rust

You can install Rust by following these instructions:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

For other platforms, follow directions at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) and install Rust on your machine.

### Install Rust and WASM toolchain

You can do this by running the following command:

```bash
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
```

## Examples

You can find the source code for the wasm smart contracts examples under [contracts](../../x/contracts/examples) directory.

### Counter

This is a smart contract that stores an Address -> Count mapping. It contains two functions `inc` which increments a value by a count and `get_value` a value at an Address.

#### Build the contract

Navigate to the project root directory and build the WASM binary:

```bash
cd x/contracts/examples/counter;
cargo build --release --target wasm32-unknown-unknown --target-dir=./target
```

The generated WASM binary will be found at [counter.wasm](./target/wasm32-unknown-unknown/release/counter.wasm)

#### Publish the contract to the blockchain

Provide the path to the WASM file when prompted.

```bash
./build/nuklai-cli action publishFile
```

Which should output something like:

```bash
contract file: ./x/contracts/examples/counter/target/wasm32-unknown-unknown/release/counter.wasm
continue (y/n): y
✅ txID: BfMeE6jBtvUXfQLLv9u61auFUTr9CtHY4c4wXnYXbWykjZo3J
fee consumed: 0.007489900
0300000023052025B7F3BEEDE2CB8514C1DE7B073CB1E13FE2DF06DF4CB0A1C5FE44A781EE6903EF
```

Note down the contract ID `0300000023052025B7F3BEEDE2CB8514C1DE7B073CB1E13FE2DF06DF4CB0A1C5FE44A781EE6903EF` as it will be required for deployment

#### Deploy the contract on the blockchain

```bash
./build/nuklai-cli action deploy
```

Which should output something like:

```bash
✔ contract id: 0300000023052025B7F3BEEDE2CB8514C1DE7B073CB1E13FE2DF06DF4CB0A1C5FE44A781EE6903EF█
✔ creation info: 00█
continue (y/n): y█
✅ txID: 2KkfSyDAm9UJ5eZKekJ9BAtun2NbuwgstUV2ffPde46GyA1z4a
fee consumed: 0.000045800 NAI
output: &{Address:006e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d}
```

#### Call a function from the deployed contract

```bash
./build/nuklai-cli action
```
6 changes: 6 additions & 0 deletions x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `x` Package

This package contains experimental code that may be moved to other packages in
the future. Code in this package is not stable and may be moved, removed or
modified at any time. This code should not be relied on for correctness in
important applications.
28 changes: 28 additions & 0 deletions x/contracts/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Examples

### amm

- TODO

### counter

- smart-contract that stores an Address -> Count mapping. Contains two functions `inc` which increments a value by a count, and `get_value`a value at an Address.

### counter-external

- example smart-contract showing external smart-contract invocation. Calls the counter smart-contracts `inc` and `get_value` functions.

### token

- A simple ERC-20 replica

## Installation

To run examples locally, you will need to install the following dependencies:

- Rus. You can do this by following these instructions:

- https://www.rust-lang.org/tools/install

- Wasm Target. You can do this by running the following command:
- `rustup target add wasm32-unknown-unknown`
17 changes: 17 additions & 0 deletions x/contracts/examples/automated-market-maker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "automated-market-maker"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["lib", "cdylib"]

[dependencies]
token = { path = "../token", features = ["bindings"] }
wasmlanche = { workspace = true, features = ["debug"] }

[dev-dependencies]
wasmlanche = { workspace = true, features = ["debug", "test"] }

[build-dependencies]
wasmlanche = { workspace = true, features = ["build"] }
4 changes: 4 additions & 0 deletions x/contracts/examples/automated-market-maker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Automatic Market Maker Contract

This example shows a uniswap v2 style constant product market maker that allows a user to swap between two token smart-contracts.
It also allows users to add and remove liquidity to/from the pool.
6 changes: 6 additions & 0 deletions x/contracts/examples/automated-market-maker/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

fn main() {
wasmlanche::build::build_wasm();
}
Loading

0 comments on commit 23a69c3

Please sign in to comment.