Normal Finance Rust Types
A comprehensive Rust types library for the Normal Finance ecosystem, providing shared data structures, events, storage types, and error definitions for Soroban smart contracts.
Overview
Normal Finance is a decentralized finance platform built on Stellar's Soroban smart contract platform. This crate provides the foundational types used across all Normal Finance 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
Features
- 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
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Import
use *;
Specific Module Imports
// Import specific modules as needed
use ;
Working with Pool Types
use ;
use ;
// Create a new pool configuration
let pool = Pool ;
// Define swap parameters
let swap_params = SwapParams ;
Working with Index Types
use ;
// Define index components
let components = vec!;
// Create index info
let index_info = IndexInfo ;
Error Handling
use ;
// Handle specific error types
match contract_result
Module Structure
Types (types/)
Core data structures used across Normal Finance 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
Errors (errors/)
Comprehensive error definitions for all contract operations:
access_control_error: Permission and role errorsbuffer_error: Buffer management 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
Events (events/)
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
Storage (storage/)
Optimized storage structures for Soroban contracts:
access_control: Role and permission storageamm_pool: Pool state storagebuffer: Buffer management 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
Contributing
We welcome contributions to improve and extend the Normal Finance 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
License
This project is licensed under the Apache License 2.0 - see the LICENSE.md file for details.
Authors
- Jay Malve - Initial work - jaymalveus@gmail.com
- Joshua Blew - Initial work - joshua@normalfinance.io