Initialize the lending pool contract
env - The Soroban environmentpool_admin - Address with pool admin privilegesemergency_admin - Address with emergency admin privilegesprice_oracle - Address of the price oracle contracttreasury - Address of the treasury (receives protocol fees)dex_router - Address of DEX router (Soroswap router)fn initialize(
env: soroban_sdk::Env,
pool_admin: soroban_sdk::Address,
emergency_admin: soroban_sdk::Address,
price_oracle: soroban_sdk::Address,
treasury: soroban_sdk::Address,
dex_router: soroban_sdk::Address,
incentives_contract: Option,
) -> Result<(), KineticRouterError>
Supply assets to the protocol
env - The Soroban environmentcaller - The address calling this functionasset - The address of the underlying asset to supplyamount - The amount to be suppliedon_behalf_of - The address that will receive the aTokens_referral_code - Code used to register the integrator (unused for now)Ok(()) - Supply successfulErr(KineticRouterError) - Supply failed due to validation or cap limitsThis function enforces supply caps if configured. Caps are stored as whole tokens and converted to smallest units during enforcement to maximize the effective range.
fn supply(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
amount: u128,
on_behalf_of: soroban_sdk::Address,
_referral_code: u32,
) -> Result<(), KineticRouterError>
fn withdraw(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
amount: u128,
to: soroban_sdk::Address,
) -> Result
fn swap_collateral(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
from_asset: soroban_sdk::Address,
to_asset: soroban_sdk::Address,
amount: u128,
min_amount_out: u128,
) -> Result
Set DEX router address (admin only)
fn set_dex_router(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
router: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Get DEX router address
fn get_dex_router(env: soroban_sdk::Env) -> Option
Set DEX factory address (admin only)
fn set_dex_factory(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
factory: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Get DEX factory address
fn get_dex_factory(env: soroban_sdk::Env) -> Option
fn borrow(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
amount: u128,
interest_rate_mode: u32,
_referral_code: u32,
on_behalf_of: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn repay(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
amount: u128,
rate_mode: u32,
on_behalf_of: soroban_sdk::Address,
) -> Result
Liquidate a position
collateral_asset - The address of the underlying asset used as collateraldebt_asset - The address of the underlying borrowed asset to be repaiduser - The address of the borrower getting liquidateddebt_to_cover - The debt amount of borrowed asset to liquidatereceive_a_token - True if liquidator receives aTokens, false for underlying assetfn liquidation_call(
env: soroban_sdk::Env,
liquidator: soroban_sdk::Address,
collateral_asset: soroban_sdk::Address,
debt_asset: soroban_sdk::Address,
user: soroban_sdk::Address,
debt_to_cover: u128,
_receive_a_token: bool,
) -> Result<(), KineticRouterError>
fn execute_operation(
env: soroban_sdk::Env,
_assets: soroban_sdk::Vec,
_amounts: soroban_sdk::Vec,
premiums: soroban_sdk::Vec,
initiator: soroban_sdk::Address,
_params: soroban_sdk::Bytes,
) -> bool
fn set_flash_loan_premium(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
premium_bps: u128,
) -> Result<(), KineticRouterError>
Set maximum flash loan premium allowed (admin only)
caller - Pool admin address (must be authorized)max_premium_bps - Maximum premium in basis points (e.g., 100 = 1%)Ok(()) if max premium updated successfullyErr(Unauthorized) if caller is not adminfn set_flash_loan_premium_max(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
max_premium_bps: u128,
) -> Result<(), KineticRouterError>
fn get_flash_loan_premium_max(env: soroban_sdk::Env) -> u128
fn set_hf_liquidation_threshold(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
threshold: u128,
) -> Result<(), KineticRouterError>
fn get_hf_liquidation_threshold(env: soroban_sdk::Env) -> u128
fn set_min_swap_output_bps(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
min_output_bps: u128,
) -> Result<(), KineticRouterError>
fn get_min_swap_output_bps(env: soroban_sdk::Env) -> u128
fn set_partial_liq_hf_threshold(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
threshold: u128,
) -> Result<(), KineticRouterError>
fn get_partial_liq_hf_threshold(env: soroban_sdk::Env) -> u128
fn get_flash_loan_premium(env: soroban_sdk::Env) -> u128
Execute a flash loan
Flash loans are permissionless - anyone can initiate them.
The receiver contract must implement execute_operation callback.
initiator: Address initiating the flash loan (must authorize)receiver: Contract that will receive the loan and execute callbackassets: Assets to borrowamounts: Amounts to borrow for each assetparams: Arbitrary data passed to receiverThe receiver must implement execute_operation with the standard flash loan interface.
Initiator must authorize the call, but anyone can be an initiator. The receiver handles its own authorization logic.
InvalidFlashLoanParams: Invalid parametersInsufficientLiquidityForFlashLoan: Not enough liquidityFlashLoanExecutionFailed: Receiver callback failedFlashLoanNotRepaid: Loan not fully repaidfn flash_loan(
env: soroban_sdk::Env,
initiator: soroban_sdk::Address,
receiver: soroban_sdk::Address,
assets: soroban_sdk::Vec,
amounts: soroban_sdk::Vec,
params: soroban_sdk::Bytes,
) -> Result<(), KineticRouterError>
Flash liquidation - atomic liquidation using flash loan
liquidator - Address of the liquidator (must be authorized)user - Address of the user being liquidateddebt_asset - Address of the debt assetcollateral_asset - Address of the collateral assetdebt_to_cover - Amount of debt to covercollateral_to_seize - Amount of collateral to seizemin_swap_out - Minimum amount of debt asset to receive from swapdeadline - Transaction deadline timestampOk(()) if liquidation successfulfn flash_liquidation(
env: soroban_sdk::Env,
liquidator: soroban_sdk::Address,
user: soroban_sdk::Address,
debt_asset: soroban_sdk::Address,
collateral_asset: soroban_sdk::Address,
debt_to_cover: u128,
collateral_to_seize: u128,
min_swap_out: u128,
deadline: u64,
) -> Result<(), KineticRouterError>
Set treasury address for protocol fees (admin only)
caller - Pool admin address (must be authorized)treasury - New treasury address for protocol fee collectionOk(()) if treasury updated successfullyErr(Unauthorized) if caller is not adminfn set_treasury(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
treasury: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn get_treasury(env: soroban_sdk::Env) -> Option
fn set_flash_liquidation_helper(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
helper: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn get_flash_liquidation_helper(env: soroban_sdk::Env) -> Option
Set pool configurator contract address (admin only)
caller - Pool admin address (must be authorized)configurator - Pool configurator contract addressOk(()) if configurator address updated successfullyErr(Unauthorized) if caller is not adminfn set_pool_configurator(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
configurator: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn get_pool_configurator(env: soroban_sdk::Env) -> Option
Get available protocol reserves for an asset
Protocol reserves accumulate due to the reserve factor, which reduces supplier APY. Reserves = underlying_balance_in_atoken - total_withdrawable_supply
asset - The address of the underlying assetOk(u128) - Available reserves in smallest unitsErr - If reserve not found or calculation failsfn get_protocol_reserves(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
Get swap quote and maximum safe swap amount for collateral swap
Returns a tuple of:
env - Soroban environmentuser - User address to check swap limits forfrom_asset - Asset to swap fromto_asset - Asset to swap toamount_in - Amount to get quote for (used to calculate DEX ratio)Ok((u128, u128, u128, u128)) - (quote, max_swapable, current_hf, projected_hf)Err - If calculation failsfn get_swap_collateral_quote(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
from_asset: soroban_sdk::Address,
to_asset: soroban_sdk::Address,
amount_in: u128,
) -> Result<(u128, u128, u128, u128), KineticRouterError>
fn collect_protocol_reserves(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
) -> Result
fn set_user_use_reserve_as_coll(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
use_as_collateral: bool,
) -> Result<(), KineticRouterError>
Get user account data
user - The address of the userfn get_user_account_data(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
) -> Result
fn get_reserve_data(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
fn get_current_reserve_data(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
fn get_current_liquidity_index(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
fn get_current_var_borrow_idx(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
Get incentives contract address
env - The Soroban environmentOption<Address> - The incentives contract address if set, None otherwisefn get_incentives_contract(env: soroban_sdk::Env) -> Option
fn set_incentives_contract(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
incentives: soroban_sdk::Address,
) -> Result
Get user configuration
user - The address of the userfn get_user_configuration(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
) -> UserConfiguration
fn get_reserves_list(env: soroban_sdk::Env) -> soroban_sdk::Vec
fn update_reserve_state(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
fn get_utilization_rate(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> Result
fn is_paused(env: soroban_sdk::Env) -> bool
fn pause(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn unpause(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Initialize a new reserve
This function should be called by the pool configurator contract. The pool configurator should validate authorization before calling this function.
underlying_asset - The address of the underlying asseta_token_impl - The address of the aToken implementationvariable_debt_impl - The address of the variable debt token implementationinterest_rate_strategy - The address of the interest rate strategytreasury - The address of the treasuryparams - Reserve initialization parametersfn init_reserve(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
underlying_asset: soroban_sdk::Address,
a_token_impl: soroban_sdk::Address,
variable_debt_impl: soroban_sdk::Address,
interest_rate_strategy: soroban_sdk::Address,
_treasury: soroban_sdk::Address,
params: InitReserveParams,
) -> Result<(), KineticRouterError>
Get user's total collateral value (for testing/debugging)
fn get_user_collateral_value(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
) -> Result
fn get_user_debt_value(
env: soroban_sdk::Env,
user: soroban_sdk::Address,
) -> Result
Updates the supply cap for a reserve.
The supply cap limits the total amount that can be supplied to a reserve. Caps are stored as whole tokens (not smallest units) to maximize the effective range within the 32-bit storage limit.
env: The Soroban environmentcaller: The address calling this function (must be admin)asset: The underlying asset addresssupply_cap: New supply cap in whole tokens (0 = no cap, virtually unlimited)Ok(()): Supply cap updated successfullyErr(KineticRouterError::InvalidAmount): Invalid cap valueErr(KineticRouterError::Unauthorized): Caller is not adminEmits (sup_cap, asset) event with the new supply cap value.
fn set_reserve_supply_cap(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
supply_cap: u128,
) -> Result<(), KineticRouterError>
Updates the borrow cap for a reserve.
The borrow cap limits the total amount that can be borrowed from a reserve. Caps are stored as whole tokens (not smallest units) to maximize the effective range within the 32-bit storage limit.
env: The Soroban environmentcaller: The address calling this function (must be admin)asset: The underlying asset addressborrow_cap: New borrow cap in whole tokens (0 = no cap, virtually unlimited)Ok(()): Borrow cap updated successfullyErr(KineticRouterError::InvalidAmount): Invalid cap valueErr(KineticRouterError::Unauthorized): Caller is not adminEmits (bor_cap, asset) event with the new borrow cap value.
fn set_reserve_borrow_cap(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
borrow_cap: u128,
) -> Result<(), KineticRouterError>
Update reserve configuration (called by pool configurator)
caller: The address calling this function (must be pool configurator)asset: The underlying asset addressconfiguration: New reserve configurationfn update_reserve_configuration(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
configuration: ReserveConfiguration,
) -> Result<(), KineticRouterError>
fn update_reserve_rate_strategy(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
interest_rate_strategy: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
fn update_atoken_implementation(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
a_token_impl: soroban_sdk::BytesN<32>,
) -> Result<(), KineticRouterError>
fn update_debt_token_implementation(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
debt_token_impl: soroban_sdk::BytesN<32>,
) -> Result<(), KineticRouterError>
fn drop_reserve(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Upgrade contract WASM (admin only)
new_wasm_hash - Hash of new WASM binaryUnauthorized - Caller is not adminfn upgrade(
env: soroban_sdk::Env,
new_wasm_hash: soroban_sdk::BytesN<32>,
) -> Result<(), KineticRouterError>
fn version(env: soroban_sdk::Env) -> u32
fn get_admin(env: soroban_sdk::Env) -> soroban_sdk::Address
Transfer admin to a new address (current admin only) This transfers the upgrade admin. Use this to assign a multisig as admin.
caller - Current admin address (must be authorized)new_admin - New admin address (can be a multisig contract)Unauthorized - Caller is not current adminfn transfer_admin(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
new_admin: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Transfer pool admin to a new address (current pool admin only)
caller - Current pool admin address (must be authorized)new_admin - New pool admin address (can be a multisig contract)Unauthorized - Caller is not current pool adminfn transfer_pool_admin(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
new_admin: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Transfer emergency admin to a new address (current pool admin only)
caller - Current pool admin address (must be authorized)new_admin - New emergency admin address (can be a multisig contract)Unauthorized - Caller is not current pool adminfn transfer_emergency_admin(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
new_admin: soroban_sdk::Address,
) -> Result<(), KineticRouterError>
Set reserve whitelist (admin only)
caller - Pool admin addressasset - Underlying asset addresswhitelist - Addresses allowed to interact with this reserve** Note **: This function replaces the entire whitelist. To add/remove addresses, first get the current list, modify it, then set the complete new list.
Unauthorized - Caller is not adminfn set_reserve_whitelist(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
whitelist: soroban_sdk::Vec,
) -> Result<(), KineticRouterError>
fn get_reserve_whitelist(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> soroban_sdk::Vec
fn is_whitelisted_for_reserve(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
address: soroban_sdk::Address,
) -> bool
fn set_liquidation_whitelist(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
whitelist: soroban_sdk::Vec,
) -> Result<(), KineticRouterError>
fn get_liquidation_whitelist(
env: soroban_sdk::Env,
) -> soroban_sdk::Vec
fn is_whitelisted_for_liquidation(
env: soroban_sdk::Env,
address: soroban_sdk::Address,
) -> bool
fn set_reserve_blacklist(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
asset: soroban_sdk::Address,
blacklist: soroban_sdk::Vec,
) -> Result<(), KineticRouterError>
fn get_reserve_blacklist(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
) -> soroban_sdk::Vec
fn is_blacklisted_for_reserve(
env: soroban_sdk::Env,
asset: soroban_sdk::Address,
address: soroban_sdk::Address,
) -> bool
fn set_liquidation_blacklist(
env: soroban_sdk::Env,
caller: soroban_sdk::Address,
blacklist: soroban_sdk::Vec,
) -> Result<(), KineticRouterError>
fn get_liquidation_blacklist(
env: soroban_sdk::Env,
) -> soroban_sdk::Vec
fn is_blacklisted_for_liquidation(
env: soroban_sdk::Env,
address: soroban_sdk::Address,
) -> bool