-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
120 changed files
with
9,753 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
Oops, something went wrong.