#order #limit-order #margin #contracts #market #orderbook #kuru

kuru-sdk-rs

Rust SDK to interact with Kuru Contracts

2 releases

new 0.1.1 Nov 7, 2024
0.1.0 Nov 7, 2024

#15 in Magic Beans

MIT license

100KB
2.5K SLoC

Kuru SDK

A comprehensive Rust SDK for interacting with the Kuru Protocol, providing orderbook management, margin trading, and meta-transaction capabilities.

Overview

The Kuru SDK enables seamless interaction with Kuru Protocol's smart contracts, offering:

  • Order management (limit & market orders)
  • Margin trading capabilities
  • Meta-transaction support
  • Real-time order tracking
  • Asset management

๐Ÿ“š Module Documentation

Core Components

  • Order Processing System

    • Multi-threaded transaction processing
    • WebSocket event handling
    • Order state management
    • Real-time status updates
  • Orderbook

    • Limit order placement
    • Market order execution
    • Order cancellation
    • L2 book viewing
    • AMM integration
  • Margin Account

    • Deposit management
    • Withdrawal processing
    • Balance queries
    • Margin position tracking

Supporting Systems

๐Ÿš€ Quick Start

use kuru_sdk::{Orderbook, MarginAccount, Token, KuruForwarder};

// Initialize core components
let orderbook = Orderbook::new("0x...", provider.clone())?;
let margin_account = MarginAccount::new("main", "0x...", provider.clone())?;
let token = Token::new("USDC", "0x...", provider.clone())?;

// Place a limit order
let (tx_hash, order_id) = orderbook.add_buy_order(
    "100.5",  // price
    "1.5",    // size
    false,    // post_only
    None,     // gas_price
    None      // gas_limit
).await?;

// Deposit to margin account
let tx_hash = margin_account.deposit(
    &user_address,
    &token,
    &amount
).await?;

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Kuru SDK                       โ”‚
โ”‚                                                 โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
โ”‚  โ”‚  Orderbook  โ”‚  โ”‚  Margin  โ”‚  โ”‚   Meta    โ”‚   โ”‚
โ”‚  โ”‚   System    โ”‚โ—„โ”€โ”ค  Account โ”‚โ—„โ”€โ”ค   TX      โ”‚   โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
โ”‚         โ–ฒ              โ–ฒ             โ–ฒ          โ”‚
โ”‚         โ”‚              โ”‚             โ”‚          โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”      โ”‚
โ”‚    โ”‚        Order Processing System      โ”‚      โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”˜      โ”‚
โ”‚                                         โ”‚       โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”     โ”‚
โ”‚    โ”‚             Inventory                โ”‚     โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“‹ Features

  • Order Management

    • Limit orders
    • Market orders
    • Post-only orders
    • Order cancellation
    • Batch operations
  • Margin Trading

    • Deposit/withdrawal
    • Position management
    • Balance tracking
    • Risk monitoring
  • Meta Transactions

    • Gasless trading
    • Signature verification
    • Transaction relaying
  • Real-time Updates

    • WebSocket integration
    • Order status tracking
    • Event processing
    • State management

๐Ÿงช Testing

# Run all tests
cargo test

Dependencies

~24โ€“39MB
~673K SLoC