Skip to content

sedaprotocol/seda-example-ops

Repository files navigation

seda-protocol

SEDA Oracle Program Templates

This oracle template demonstrates official Oracle Program use cases. If this is your first time working with SEDA and Oracle Programs, we encourage everyone to read our docs to better understand what an Oracle Program is and how it works.

In a quick overview:

  • Oracle Program: Is a WASM (Web Assembly) program that is uploaded to the SEDA network. This program can contain one or both of an Execution and/or Tally phase.
  • Execution Phase: This is where the logic for what data you want onchain is written. This logic is executed by a number of executors decided by the Data Request poster.
  • Tally Phase: This is where the logic for consolidating and choosing the best answer is written, for example, using the mean, median, or another method. This logic is executed by SEDA nodes before posting the Data Result.
  • Data Request: A request posted onto a chain by a user that states which Oracle Program to use, the number of executors to run it, and pass the arguments to the program(s). You can choose an Oracle Program for execution and tally, and pass arguments to them separately.
  • Data Proxy: A proxy to expose a private API to the SEDA network without leaking a private key. Calling one comes with a cost configured by the Data Proxy host.

Clink the links below to learn how to quickly post a Data Request specifically for each example, however, please check out the requirements before posting a Data Request with the examples:

Requirements

Make sure the tools below are installed and in your PATH if you want to build, deploy, post Oracle Programs and post Data Requests. For quick starting, the only requirements are Bun and Rust.

  • Bun: Install Bun for package management and building.

  • Rust: Install Rust for development and building.

  • WASM: Install the wasm32-wasip1 target with rustup target add wasm32-wasip1 for WASM compilation.

  • WASM-OPT: Can be installed via bun/npm/etc install -g binaryren, cargo install binaryren, cargo binstall binaryren, or your OS package manager.

  • WABT: Can be installed via bun/npm/etc install -g wabt, or your OS package manager.

  • WASM-STRIP: Can be installed via cargo install wasm-strip.

  • Alternatively, use the devcontainer for a pre-configured environment.

Getting Started

Please find a few example Oracle Programs here:

Each example can be interacted with in various ways. In order to receive help information for them you can run:

cargo xtask --help

You will need to have run bun install or cargo install-tools to have the bun dependencies installed.

Note

All commands can also be run via cargo run <command> <options>. For example, cargo run compile single-price-feed would work the same as cargo compile single-price-feed.

![NOTE] For some commands, they may require your SEDA mnemonic. This is set via an env variable, so you can also use the example .env file we have here to fill it out. There is one for TESTNET and MAINNET.

Building

To build one of the Oracle Programs, run the following:

cargo compile <oracle-program>

You can list the program names with

cargo compile --help

where'd you get the output:

Usage: xtask compile <ORACLE_PROGRAM>

Arguments:
  <ORACLE_PROGRAM>  [possible values: single-price-feed]

Options:
  -h, --help  Print help

Local Testing

You can test an Oracle Program with:

cargo test-op <oracle-program>`

where you can optionally pass in a test pattern:

cargo test-op <oracle-program> <test-pattern>

This command will compile the Oracle Program as well before testing it.

You can test all programs at once with:

cargo test-all-ops

Uploading an Oracle Program

To upload an Oracle Program binary, run:

cargo deploy <oracle-program> <optional-network>

By default, the network defaults to TESTNET.

This command will compile the Oracle Program as well before uploading it.

Important

Make sure you have all the environment variables set in .env file.

Submitting a Data Request

To submit a Data Request to the SEDA network, run:

cargo post-dr <oracle-program> [oracle-program-specific-args] -i <oracle-program-id>

This will post a transaction and wait until there is a result.

So for example you can do:

cargo post-dr single-price-feed BTC,ETH -i 2f0c7eea6764398e1e5bf9cde27f206620a89d58b0e37f97cdb6567265c6c2b9 -r 3

In order to post the single-price-feed data request example with: the argument BTC,ETH, the id, and a replication factor of 3.

Important

Make sure you have all the environment variables set in .env file.

Formatting and Linting

The TypeScript side is handled by Biome: biome format and biome format fix.

The Rust side is handled by cargo: cargo fmt --all -- --check and cargo fmt --all.

Rust additionally has linting via clippy with cargo clippy --all-features --locked -- -D warnings.

License

Contents of this repository are open source under the MIT license.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •