Expand description
§delta domain SDK
This crate provides a comprehensive SDK for building and running domains on delta network. It includes components for managing the domain lifecycle, handling transactions, storing state, and communicating with the base layer (delta network).
§Running a Domain
The Domain struct is the entry point for building and running a domain.
It provides three components:
- a
runnerto launch the domain’s event loop; - a
clientto perform actions (apply, submit, prove, …); and viewsto read state and data.
Create a Domain with the builder or from a
configuration file, and destructure it into its
subcomponents upon creation:
use delta_domain_sdk::{Domain, Config};
async fn example() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let Domain { runner, client, views } = Domain::from_config(config)
.build()
.await?;
Ok(())
}The runner must be launched before using the client or views — see
Runner for details.
§Connectivity
The RPC adapter handles communication with the base layer:
- fetching vault data;
- submitting transactions; and
- streaming events from the base layer.
Configure the RPC URL in the configuration file via the rpc_url
field, or programmatically with
with_rpc.
When no RPC URL is configured, a mock RPC is used. The mock RPC provides testing utilities like mock vaults and simulation of base layer events.
§Storage
storage handles the persistence of vault and state diff data. The SDK
supports different backends:
- in-memory storage for testing and development; and
- RocksDB for production use
You can choose which storage backend is used by setting or omitting the
rocksdb crate feature.
§Proving
The proving client generates zero-knowledge proofs for state transitions. Find the available implementations here.
§Key Concepts
§Vaults
Vaults represent account state. There are two types:
-
BaseVault: Used on the base shard and contains native token balance and account nonce. -
Vault: Used on domains and contains native token balance, shard ID, and optional data such as token holdings, token mint metadata, and NFT mint metadata.
Vaults are uniquely identified by an
(Address).
§State Diff List (SDL)
A StateDiffList is a collection of state
changes (diffs) resulting from transaction execution. SDLs:
- represent atomic batches of state changes;
- include information about the originating shard and proposer; and
- require cryptographic proofs for validation.
§Verifiables
VerifiableType are
cryptographically signed messages that can be verified and executed to
produce state changes. such as:
DebitAllowance: permission to debit tokens from a source vault; orfungible::Mint: instruction to mint new fungible tokens.
§Features
rocksdb: enables persistent RocksDB storage (use for production), if disabled an in-memory storage is used by defaultsp1: enables SP1-based zero-knowledge proof generationmetrics: enables performance metrics collection
§Example Usage
use delta_domain_sdk::{Domain, Config};
async fn run_domain() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let Domain { runner, client, views } = Domain::from_config(config)
.with_rpc("http://localhost:8545")
.build().await.unwrap();
runner.run_in_background().await.unwrap();
Ok(())
}§Development
Unlike a smart contract, a domain is a server application in the traditional sense. Developers should apply well-know application development practices like the twelve-factor app. Some tips:
- Listen to any IPv4 or IPv6 address instead of
localhost.
Re-exports§
pub use config::Config;pub use client::DomainClient;pub use domain::Domain;pub use storage::in_memory;pub use storage::rocksdb;
Modules§
- base
- General purpose delta types and helpers re-exported from the base SDK
- builder
- Builder
- client
- Client
- config
- Config
- domain
- Domain
- domain_
agreement - Utils to deal with Domain Agreements
- execution
- Logic for execution
- proving
- Logic to generate proofs
- runner
- Runner
- storage
- Storage
- views
- Views
Structs§
- SdlUpdate
- A local update emitted by the domain to notify users of changes in an SDL’s status.
Enums§
- SdlState
- The state an SDL can reach on the local-state