Skip to content

Lay3rLabs/wavs-foundry-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WAVS Monorepo Template

Template for getting started with developing WAVS applications

A template for developing WebAssembly AVS applications using Rust and Solidity, configured for Windows WSL, Linux, and MacOS. The sample oracle service fetches the current price of a cryptocurrency from CoinMarketCap and saves it on chain.

System Requirements

Core (Docker, Compose, Make, JQ, Node v21+)

Docker

Docker Compose

  • MacOS: Already installed with Docker installer
  • Linux + Windows WSL: sudo apt-get install docker-compose-v2
  • Compose Documentation

Make

  • MacOS: brew install make
  • Linux + Windows WSL: sudo apt -y install make
  • Make Documentation

JQ

  • MacOS: brew install jq
  • Linux + Windows WSL: sudo apt -y install jq
  • JQ Documentation

Node.js

Rust v1.84+

Rust Installation

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

rustup toolchain install stable
rustup target add wasm32-wasip2

Upgrade Rust

# Remove old targets if present
rustup target remove wasm32-wasi || true
rustup target remove wasm32-wasip1 || true

# Update and add required target
rustup update stable
rustup target add wasm32-wasip2
Cargo Components

Install Cargo Components

# Install required cargo components
# https://github.com/bytecodealliance/cargo-component#installation
cargo install cargo-binstall
cargo binstall cargo-component warg-cli wkg --locked --no-confirm

# Configure default registry
wkg config --default-registry wa.dev

Create Project

# If you don't have foundry: `curl -L https://foundry.paradigm.xyz | bash && $HOME/.foundry/bin/foundryup`
forge init --template Lay3rLabs/wavs-foundry-template my-wavs

Tip

Run make help to see all available commands and environment variable overrides.

Solidity

Install the required packages to build the Solidity contracts. This project supports both submodules and npm packages.

# Install packages
make setup

# Build the contracts
forge build

# Run the solidity tests
forge test

Build WASI components

Now build the WASI rust components into the compiled output directory.

Warning

If you get: error: no registry configured for namespace "wavs"

run, wkg config --default-registry wa.dev

make wasi-build # or `make build` to include solidity compilation.

Execute WASI component directly

Test run the component locally to validate the business logic works. An ID of 1 is Bitcoin. Nothing will be saved on-chain, just the output of the component is shown.

COIN_MARKET_CAP_ID=1 make wasi-exec

WAVS

Note

If you are running on a Mac with an ARM chip, you will need to do the following:

  • Set up Rosetta: softwareupdate --install-rosetta
  • Enable Rosetta (Docker Desktop: Settings -> General -> enable "Use Rosetta for x86_64/amd64 emulation on Apple Silicon")

Configure one of the following networking:

  • Docker Desktop: Settings -> Resources -> Network -> 'Enable Host Networking'
  • brew install chipmk/tap/docker-mac-net-connect && sudo brew services start chipmk/tap/docker-mac-net-connect

Start Environment

Start an ethereum node (anvil), the WAVS service, and deploy eigenlayer contracts to the local network.

cp .env.example .env

# Start the backend
#
# This must remain running in your terminal. Use another terminal to run other commands.
# You can stop the services with `ctrl+c`. Some MacOS terminals require pressing it twice.
make start-all

Deploy Contract

Upload your service's trigger and submission contracts. The trigger contract is where WAVS will watch for events, and the submission contract is where the AVS service operator will submit the result on chain.

# Run `./script/Deploy.s.sol`
make deploy-contracts

Tip

You can see the deployed trigger address with make get-trigger-from-deploy and the deployed submission address with make get-service-handler-from-deploy

Deploy Service

Deploy the compiled component with the contracts from the previous steps. Review the makefile for more details and configuration options.TRIGGER_EVENT is the event that the trigger contract emits and WAVS watches for. By altering SERVICE_TRIGGER_ADDR you can watch events for contracts others have deployed.

TRIGGER_EVENT="NewTrigger(bytes)" make deploy-service

Trigger the Service

Anyone can now call the trigger contract which emits the trigger event WAVS is watching for from the previous step. WAVS then calls the service and saves the result on-chain.

COIN_MARKET_CAP_ID=1 make trigger-service

Show the result

Query the latest submission contract id from the previous request made.

# Get the latest TriggerId and show the result via `script/ShowResult.s.sol`
make show-result