Skip to content
Closed
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6bec948
readme command update
evanorti May 9, 2025
9969858
Update custom-components.mdx
evanorti May 9, 2025
92c9d64
docs-planning
evanorti May 9, 2025
e6bf2c6
Update variables.mdx
evanorti May 9, 2025
ca0760b
Update triggers.mdx
evanorti May 12, 2025
d35b20c
Update triggers.mdx
evanorti May 12, 2025
49e3b15
Update workflows.mdx
evanorti May 12, 2025
4857996
Merge branch 'main' into docs-0.4
evanorti May 12, 2025
4285525
Update workflows.mdx
evanorti May 13, 2025
f41ca0d
Update triggers.mdx
evanorti May 13, 2025
8b02b82
re-order component docs
evanorti May 14, 2025
408cf4c
Update component.mdx
evanorti May 14, 2025
14fa24f
Update component.mdx
evanorti May 14, 2025
a9d7f05
Merge branch 'main' into docs-0.4
evanorti May 15, 2025
65e62fb
Merge branch 'main' into docs-0.4
evanorti May 16, 2025
f7caede
Create cursor-rules.mdc
evanorti May 16, 2025
f128a3b
update handbook
evanorti May 16, 2025
3c06d41
cursor-script
evanorti May 16, 2025
a957640
rulefile script
evanorti May 16, 2025
10cde89
Update utilities.mdx
evanorti May 16, 2025
b87aa5d
Update component.mdx
evanorti May 16, 2025
79ea154
Update commands.mdx
evanorti May 16, 2025
df5170a
Update utilities.mdx
evanorti May 16, 2025
c9de9a8
Update service.mdx
evanorti May 16, 2025
f355869
Merge branch 'docs-0.4' into cursor-rules-generation
evanorti May 16, 2025
e767513
Update variables.mdx
evanorti May 19, 2025
43528ef
Update utilities.mdx
evanorti May 19, 2025
6468e50
Update component.mdx
evanorti May 19, 2025
8e8a2e8
update docs
evanorti May 19, 2025
2a4be43
update docs
evanorti May 19, 2025
469f4a7
Update triggers.mdx
evanorti May 20, 2025
b472417
Merge branch 'main' into docs-0.4
evanorti May 20, 2025
fe7f990
Update component.mdx
evanorti May 20, 2025
e93d954
Merge branch 'docs-0.4' into cursor-rules-generation
evanorti May 20, 2025
ff6cb1c
Merge branch '0.3' into cursor-rules-generation
evanorti May 20, 2025
271f3c8
Update service.mdx
evanorti May 20, 2025
63c2981
Update triggers.mdx
evanorti May 20, 2025
862c108
Update workflows.mdx
evanorti May 20, 2025
f63a6cd
Update submission.mdx
evanorti May 20, 2025
791e166
Update submission.mdx
evanorti May 20, 2025
909475d
Update component.mdx
evanorti May 20, 2025
415ad85
Update custom-components.mdx
evanorti May 20, 2025
8e26984
update docs
evanorti May 20, 2025
1f78ffb
Merge branch 'docs-0.4' into cursor-rules-generation
evanorti May 20, 2025
13c246e
Update doc_to_rule.py
evanorti May 21, 2025
d181eba
update docs
evanorti May 21, 2025
1a7f0e1
update docs
evanorti May 21, 2025
51ebf27
update
evanorti May 21, 2025
2726f52
Update component.mdx
evanorti May 21, 2025
d89b421
Update component.mdx
evanorti May 21, 2025
847fec1
Update design.mdx
evanorti May 21, 2025
905e415
Update submission.mdx
evanorti May 21, 2025
bb7ddf9
add docs page descriptions
evanorti May 21, 2025
2741913
Create llms.mdx
evanorti May 21, 2025
0ee8442
Merge branch 'docs-0.4' into cursor-rules-generation
evanorti May 21, 2025
e62ef08
update scripts
evanorti May 22, 2025
f6988f6
example rulefiles
evanorti May 25, 2025
3dace99
Merge branch 'main' into cursor-rules-generation
reecepbcups May 26, 2025
a6a6157
rm old utilities
reecepbcups May 26, 2025
f19f77c
refactor(cursor-rules-generation): latest cursor rules generation (#171)
reecepbcups May 26, 2025
4b390d5
remove old
reecepbcups May 26, 2025
99046e6
rm legacy python stuff
reecepbcups May 26, 2025
3d14158
Merge branch 'main' into cursor-rules-generation
evanorti May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .cursor/rules/blockchain-interactions.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
description: Guide on how to interact with blockchains and smart contracts from WAVS components using Rust.
globs: **/*.rs
alwaysApply: true
---
# Blockchain Interactions in WAVS Components

This document outlines the necessary steps and configurations for interacting with Ethereum and other EVM-compatible blockchains from WAVS components. It includes dependency setup, chain configuration, and examples of querying an NFT balance.

## Dependencies

To interact with Ethereum blockchains, include the following dependencies in your `Cargo.toml`:

```toml
[dependencies]
wit-bindgen-rt = { workspace = true, features = ["bitflags"] }
wavs-wasi-utils = "=0.4.0-beta.2"
wstd = "0.5.3"
alloy-sol-macro = { version = "1.1.0", features = ["json"] }
alloy-sol-types = "1.1.0"
alloy-network = "0.15.10"
alloy-provider = { version = "0.15.10", default-features = false, features = ["rpc-api"] }
alloy-rpc-types = "0.15.10"
alloy-contract = "0.15.10"
anyhow = "1.0.98"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
```

## Chain Configuration

Define chain configurations in `wavs.toml` to specify RPC endpoints and chain IDs:

```toml
[default.chains.evm.local]
chain_id = "31337"
ws_endpoint = "ws://localhost:8545"
http_endpoint = "http://localhost:8545"
poll_interval_ms = 7000

[default.chains.evm.evmereum]
chain_id = "1"
ws_endpoint = "wss://eth.drpc.org"
http_endpoint = "https://eth.drpc.org"
```

## Accessing Configuration and Provider

Use WAVS host bindings to access chain configurations and create a provider for Ethereum interactions:

```rust
use crate::bindings::host::get_evm_chain_config;
use alloy_network::Ethereum;
use alloy_provider::RootProvider;
use wavs_wasi_utils::evm::new_evm_provider;

let chain_config = get_evm_chain_config("local")?;
let provider: RootProvider<Ethereum> = new_evm_provider::<Ethereum>(
chain_config.http_endpoint.unwrap()
)?;
```

## Example: Querying NFT Balance

To query an ERC721 NFT contract for a given owner address:

```rust
use crate::bindings::host::get_evm_chain_config;
use alloy_network::Ethereum;
use alloy_provider::RootProvider;
use alloy_sol_types::sol;
use wavs_wasi_utils::evm::{
alloy_primitives::{Address, U256},
new_evm_provider,
};
use wstd::runtime::block_on;

sol! {
interface IERC721 {
function balanceOf(address owner) external view returns (uint256);
}
}

pub fn query_nft_ownership(address: Address, nft_contract: Address) -> Result<bool, String> {
block_on(async move {
let chain_config = get_evm_chain_config("local").unwrap();
let provider: RootProvider<Ethereum> = new_evm_provider::<Ethereum>(
chain_config.http_endpoint.unwrap()
);
let contract = IERC721::new(nft_contract, &provider);
let balance = contract.balanceOf(address).call().await?;

Ok(balance > U256::ZERO)
})
}
```

For more detailed information and additional resources:
- [wavs-wasi-utils documentation](https://docs.rs/wavs-wasi-utils/latest/wavs_wasi_utils/)
- [Alloy documentation](https://docs.rs/alloy/latest/alloy/)
19 changes: 19 additions & 0 deletions .cursor/rules/commands.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
description: CLI commands for WAVS development
globs: **/Makefile
alwaysApply: true
---
# Makefile Commands for WAVS Development

This rule file provides the necessary command to access the help menu for WAVS development via the Makefile.

To view all available commands for WAVS development, use the following command in your terminal:

```bash
make help
```

This command will display a list of all the commands available in the Makefile that are relevant to WAVS development. It's a quick way to get an overview of the tools and commands at your disposal for managing and developing the WAVS project.

For more information:
- No additional links provided.
132 changes: 132 additions & 0 deletions .cursor/rules/component.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
---
description: Guide on creating and structuring components for WAVS service with examples in Rust.
globs: **/*.rs
alwaysApply: true
---
# Component Overview for WAVS Service

Service components are crucial for the WAVS service, encapsulating the main business logic and interacting with the WAVS runtime through WebAssembly (WASM) bytecode. This guide covers the languages, structure, and examples for creating components.

## Component Languages

WAVS supports multiple programming languages for component development, compiled to WASM for execution. Examples primarily use Rust, with additional samples in Go and JavaScript.

- [Go example](link)
- [JavaScript example](link)

## Component Structure

Components generally follow a three-part structure:

1. Decode incoming trigger data.
2. Process the data with custom business logic.
3. Encode and return the result for submission, if applicable.

### Trigger Inputs

Components can receive trigger data either from on-chain events or local testing. The handling of these inputs varies as shown in the `trigger.rs` example:

```rust
// In trigger.rs

pub fn decode_trigger_event(trigger_data: TriggerData) -> Result<(u64, Vec<u8>, Destination)> {
match trigger_data {
TriggerData::EvmContractEvent(TriggerDataEvmContractEvent { log, .. }) => {
let event: solidity::NewTrigger = decode_event_log_data!(log)?;
let trigger_info = solidity::TriggerInfo::abi_decode(&event._triggerInfo)?;
Ok((trigger_info.triggerId, trigger_info.data.to_vec(), Destination::Ethereum))
},
TriggerData::Raw(data) => Ok((0, data.clone(), Destination::CliOutput)),
_ => Err(anyhow::anyhow!("Unsupported trigger data type")),
}
}
```

### Component Logic

Implement the `Guest` trait for your component, with `run` as the entry point for your logic:

```rust
// In lib.rs
impl Guest for Component {
fn run(action: TriggerAction) -> Result<Option<WasmResponse>, String> {
let (trigger_id, req, dest) = decode_trigger_event(action.data)?;

let res = block_on(async move {
let resp_data = get_price_feed(id).await?;
serde_json::to_vec(&resp_data)
})?;

let output = match dest {
Destination::Ethereum => Some(encode_trigger_output(trigger_id, &res)),
Destination::CliOutput => Some(WasmResponse {
payload: res.into(),
ordering: None
}),
};
Ok(output)
}
}
```

#### Logging

For development, use `println!()` for debugging. In production, use `host::log()` for structured logging with context.

```rust
// Development logging
println!("Debug message: {:?}", data);

// Production logging
host::log(LogLevel::Info, "Production logging message");
```

### Component Output

Encode the output data for submission back to Ethereum using the `encode_trigger_output` function:

```rust
pub fn encode_trigger_output(trigger_id: u64, output: impl AsRef<[u8]>) -> WasmResponse {
WasmResponse {
payload: solidity::DataWithId {
triggerId: trigger_id,
data: output.as_ref().to_vec().into(),
}
.abi_encode(),
ordering: None,
}
}
```

## Component Definition

Define components in the `service.json` file within the workflow object:

```json
{
"component": {
"source": {
"Digest": "65747b4b1a7fa98cab6abd9a81a6102068de77b1040b94de904112272b226f51"
},
"permissions": {
"allowed_http_hosts": "all",
"file_system": true
},
"fuel_limit": null,
"time_limit_seconds": 1800,
"config": {
"Variable_1": "0xb5d4D4a87Cb07f33b5FAd6736D8F1EE7D255d9E9",
"variable_2": "0x34045B4b0cdfADf87B840bCF544161168c8ab85A"
},
"env_keys": [
"WAVS_ENV_API_KEY"
]
}
}
```

For detailed information on component configuration and keys, refer to the [variables page](./variables).

For more information:
- [WAVS WASI Utils Crate Documentation](https://docs.rs/wavs-wasi-utils/latest/wavs_wasi_utils/macro.decode_event_log_data.html)
- [Utilities and Crates Documentation](./utilities#sol-macro)
70 changes: 70 additions & 0 deletions .cursor/rules/cursor-rules.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
description:
globs:
alwaysApply: false
---
---
description: How to add or edit Cursor rules in our project
globs:
alwaysApply: false
---
# Cursor Rules Location

How to add new cursor rules to the project

1. Always place rule files in PROJECT_ROOT/.cursor/rules/:
```
.cursor/rules/
├── your-rule-name.mdc
├── another-rule.mdc
└── ...
```

2. Follow the naming convention:
- Use kebab-case for filenames
- Always use .mdc extension
- Make names descriptive of the rule's purpose

3. Directory structure:
```
PROJECT_ROOT/
├── .cursor/
│ └── rules/
│ ├── your-rule-name.mdc
│ └── ...
└── ...
```

4. Never place rule files:
- In the project root
- In subdirectories outside .cursor/rules
- In any other location

5. Cursor rules have the following structure:

```
---
description: Short description of the rule's purpose
globs: optional/path/pattern/**/*
alwaysApply: false
---
# Rule Title

Main content explaining the rule with markdown formatting.

1. Step-by-step instructions
2. Code examples
3. Guidelines

Example:
```typescript
// Good example
function goodExample() {
// Implementation following guidelines
}

// Bad example
function badExample() {
// Implementation not following guidelines
}
```
Loading