Skip to main content
This page provides reference implementations and example code for integrating with the Open Nile Protocol. Each section describes the available SDKs and tools with usage examples.
Explore the full source code on the GitHub for the latest implementations and usage patterns.

Smart Contract Integration

TypeScript SDK

Auto-generated TypeScript bindings from Foundry contract artifacts via the wagmi CLI. Install @nile-markets/sdk to access pure ABI objects and constants with zero runtime dependencies on React or wagmi. Exports include:
  • Contract ABIs (positionManagerAbi, configAbi, poolVaultAbi, etc.)
  • Type-safe enum constants (Side, Tenor, Mode, CloseReason, PositionStatus)
  • Pair identifiers (PAIR_IDS)
import {
  positionManagerAbi,
  Side,
  Tenor,
  PAIR_IDS
} from "@nile-markets/sdk";
Contract addresses are loaded from deployment JSON files via the address config module, not hardcoded in the SDK.

Rust SDK

Auto-generated Rust bindings from Foundry artifacts. The fx-contracts crate provides type-safe contract interfaces that are regenerated automatically when contract artifacts change. Exports include:
  • Contract interfaces (OracleModule, PositionManager, PoolVault, etc.)
  • Constants (EUR_USD_PAIR_ID computed at build time via Keccak256)
  • Type-safe enums (Side, Tenor, Mode, PositionStatus, CloseReason) with #[repr(u8)]
use fx_contracts::generated::oracle_module::OracleModule;
use fx_contracts::{EUR_USD_PAIR_ID, Tenor, Side};

let contract = OracleModule::new(address, &provider);
let result = contract
    .publishForwardRound(EUR_USD_PAIR_ID, fixing_timestamp, price, round_id)
    .send()
    .await?;
Enable the test-contracts feature to access MockOracle, MockPyth, and MockUSDC bindings for local development and testing.

Data Indexing

Subgraph

A Graph Protocol subgraph that indexes all protocol events. Provides GraphQL access to:
  • Position lifecycle events (open, increase, close, settle, liquidate)
  • LP vault events (deposits, withdrawals, share price changes)
  • Oracle price updates and forward round publications
  • Daily statistics and fee accumulation
  • Protocol mode transitions
See the Subgraph API documentation for the full GraphQL schema and query examples.

Agent Integrations

Agent integration tooling is under active development for M2. The following components provide programmatic access to the protocol for AI agents and automated systems.

MCP Server

Model Context Protocol server enabling AI agents to interact with the protocol. Provides structured tools for reading protocol state, querying positions, and executing trades.

x402 API

Pay-per-request REST API using the x402 payment protocol. Allows agents to access protocol data and execute operations with per-call USDC micropayments.

CLI Tool

Command-line interface for protocol interaction. Supports position management, LP operations, oracle queries, and administrative functions from the terminal.
See the Agent Integrations section for detailed integration guides and API references.