A comprehensive Rust types library for the Normal ecosystem, providing shared data structures, events, storage types, and error definitions for Soroban smart contracts.
Normal is a decentralized finance platform built on Stellar's Soroban smart contract platform. This crate provides the foundational types used across all Normal smart contracts, including:
- Index Fund Management: Types for creating and managing tokenized index funds
- Automated Market Maker (AMM): Pool management, liquidity provision, and trading types
- Insurance Fund: Risk management and insurance claim structures
- Oracle Integration: Price feed and oracle registry types
- Access Control: Permission and role management types
- Soroban SDK Integration: Built specifically for Soroban smart contracts using
soroban-sdkv22.0.1 - Comprehensive Error Handling: Standardized error types across all contract interactions
- Event Definitions: Structured event types for contract logging and monitoring
- Storage Types: Optimized data structures for Soroban contract storage
- Type Safety: Strongly-typed interfaces preventing common smart contract vulnerabilities
Add this to your Cargo.toml:
[dependencies]
normal-rust-types = "0.1.5"use normal_rust_types::*;// Import specific modules as needed
use normal_rust_types::{
errors::{PoolError, TokenError},
types::{Pool, SwapParams, IndexInfo},
events::{SwapEvent, PoolCreatedEvent},
storage::{PoolStorage, AccessControlStorage}
};use normal_rust_types::{Pool, PoolTier, PoolStatus, SwapParams};
use soroban_sdk::{Env, Address, Symbol};
// Create a new pool configuration
let pool = Pool {
token_b: token_address,
base_asset: Symbol::new(&env, "USDC"),
quote_asset: Symbol::new(&env, "XLM"),
tier: PoolTier::Tier1,
status: PoolStatus::Active,
// ... other fields
};
// Define swap parameters
let swap_params = SwapParams {
token_in: usdc_address,
token_out: xlm_address,
amount_in: 1000_0000000, // 1000 USDC (7 decimals)
amount_out_min: 2500_0000000, // Minimum 2500 XLM expected
to: user_address,
// ... other fields
};use normal_rust_types::{IndexInfo, Component};
// Define index components
let components = vec![
Component {
asset: Symbol::new(&env, "BTC"),
weight: 4000, // 40% allocation
},
Component {
asset: Symbol::new(&env, "ETH"),
weight: 3000, // 30% allocation
},
Component {
asset: Symbol::new(&env, "XLM"),
weight: 3000, // 30% allocation
},
];
// Create index info
let index_info = IndexInfo {
address: index_contract_address,
token_address: index_token_address,
total_shares: 0,
base_nav: 1_0000000, // Starting NAV of 1.0
is_public: true,
components,
// ... other fields
};use normal_rust_types::{PoolError, TokenError, ValidationError};
// Handle specific error types
match contract_result {
Err(PoolError::InsufficientLiquidity) => {
// Handle insufficient liquidity
},
Err(TokenError::InsufficientBalance) => {
// Handle insufficient balance
},
Err(ValidationError::InvalidAmount) => {
// Handle invalid amount
},
Ok(result) => {
// Process successful result
}
}Core data structures used across Normal contracts:
amm_config: AMM configuration and settingsconfig: General configuration typesenums: Common enumerations (PoolTier, PoolStatus, etc.)fees: Fee calculation and structure typesindex: Index fund related types (IndexInfo, Component, etc.)insurance_fund: Insurance and risk management typesoracle: Price oracle and registry typespool: Liquidity pool types and structuresrebalance: Portfolio rebalancing typesrewards: Incentive and reward distribution typestrading: Trading and swap related types
Comprehensive error definitions for all contract operations:
access_control_error: Permission and role errorsindex_error: Index fund operation errorsinsurance_fund_error: Insurance claim and management errorsliquidity_calculator_error: Liquidity calculation errorsmath_error: Mathematical operation errorsoracle_error: Price feed and oracle errorspool_error: Pool operation and validation errorspool_router_error: Pool routing errorsstorage_error: Data storage and retrieval errorsswap_error: Trading and swap errorstoken_error: Token operation errorsupgrade_error: Contract upgrade errorsvalidation_error: Input validation errors
Structured event types for contract logging:
access_control: Permission change eventsamm_config: AMM configuration eventsamm_pool: Pool lifecycle eventsconfig: Configuration update eventsfactory: Contract deployment eventsfees: Fee collection and update eventsindex: Index fund eventsswap: Trading and swap eventsupgrade: Contract upgrade events
Optimized storage structures for Soroban contracts:
access_control: Role and permission storageamm_pool: Pool state storagefactory: Factory contract storageindex: Index fund storageinsurance_fund: Insurance fund storageswap_utility: Swap utility storagetoken: Token storage structurestoken_share: Token share storageupgrade: Upgrade management storage
We welcome contributions to improve and extend the Normal type system. Please ensure that:
- All new types include proper documentation
- Error types include descriptive messages
- Changes maintain backward compatibility when possible
- Tests are included for new functionality
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.
- Jay Malve - Initial work - [email protected]
- Joshua Blew - Initial work - [email protected]