| Crates.io | normal-rust-types |
| lib.rs | normal-rust-types |
| version | 0.1.5 |
| created_at | 2025-08-28 01:40:57.309101+00 |
| updated_at | 2025-08-29 15:12:59.61165+00 |
| description | A common Rust types library for the entire Normal ecosystem |
| homepage | |
| repository | https://github.com/normalfinance/rust-types |
| max_upload_size | |
| id | 1813455 |
| size | 96,800 |
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:
soroban-sdk v22.0.1Add 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
}
}
types/)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 typeserrors/)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 errorsevents/)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 eventsstorage/)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 storageWe welcome contributions to improve and extend the Normal type system. Please ensure that:
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.