This document describes the initialization process for the Predictify Hybrid smart contract.
The contract must be initialized once after deployment to set up administrative privileges, platform fee configuration, and allowed assets. Initialization can only be performed once to prevent security vulnerabilities.
pub fn initialize(
env: Env,
admin: Address,
platform_fee_percentage: Option<i128>,
allowed_assets: Option<Vec<Address>>
) -> Result<(), Error>env: Soroban environmentadmin: Address to be granted SuperAdmin privilegesplatform_fee_percentage: Optional platform fee percentage (0-10%). Defaults to 2% if Noneallowed_assets: Optional list of allowed asset contract addresses. Uses defaults if None
-
Re-initialization Prevention: The function checks if
platform_feeis already stored in persistent storage. If found, returnsError::InvalidState. -
Fee Validation: Platform fee must be between
MIN_PLATFORM_FEE_PERCENTAGE(0) andMAX_PLATFORM_FEE_PERCENTAGE(10). Invalid fees returnError::InvalidFeeConfig. -
Admin Validation: The admin address is validated through
AdminInitializer::initialize, which includes its own re-initialization check for the "Admin" key.
contract_initialized: Emitted with admin address and platform fee percentageplatform_fee_set: Emitted with fee percentage and admin address
All initialization failures return Error instead of panicking, allowing callers to handle errors appropriately:
InvalidState: Contract already initializedInvalidFeeConfig: Fee percentage out of boundsUnauthorized: Admin validation failed (from admin initializer)
// Initialize with default settings
PredictifyHybrid::initialize(env.clone(), admin, None, None)?;
// Initialize with custom 5% fee
PredictifyHybrid::initialize(env.clone(), admin, Some(5), None)?;
// Initialize with custom assets
let assets = vec![&env, asset1, asset2];
PredictifyHybrid::initialize(env.clone(), admin, None, Some(assets))?;After successful initialization:
- Admin is stored in persistent storage with SuperAdmin role
- Platform fee percentage is stored in persistent storage
- Allowed assets are configured (defaults or custom)
- Audit trail records the initialization
- Contract is ready for market creation and other operations
- Initialization should be done immediately after deployment
- Use a secure admin address (consider multi-sig for production)
- Validate all parameters before calling
- Handle potential errors in deployment scripts /home/semicolon/Drip/predictify-contracts/docs/contracts/INITIALIZATION.md