Singleton contract
This page gives an overview over the storage and the functions of the Singleton contract.
Storage
The following sections shows each storage variable available in the singleton contract.
creator_nonce (LegacyMap)
Tracks a nonce for each creator of a pool to deterministically derive the pool_id from it.
// creator -> nonce
creator_nonce: LegacyMap::<ContractAddress, felt252>
extensions (LegacyMap)
Tracks the address of the extension contract for each pool.
// pool_id -> extension
extensions: LegacyMap::<felt252, ContractAddress>
asset_configs (LegacyMap)
Tracks the configuration / state of each asset in each pool.
Mapping from pool_id & asset to
// (pool_id, asset) -> asset configuration
asset_configs: LegacyMap::<(felt252, ContractAddress), AssetConfig>
ltv_configs (LegacyMap)
Tracks the max. allowed loan-to-value ratio for each asset pairing in each pool.
Mapping from PoolId & Asset to loan-to-value configruation.
ltv_configs: LegacyMap::<(felt252, ContractAddress, ContractAddress), LTVConfig>
positions (LegacyMap)
Tracks the state of each position in each pool.
// (pool_id, collateral_asset, debt_asset, user) -> position
positions: LegacyMap::<(felt252, ContractAddress, ContractAddress, ContractAddress), Position>
delegations (LegacyMap)
Tracks the delegation status for each delegator to a delegatee for a specific pool.
// (pool_id, delegator, delegatee) -> delegation
delegations: LegacyMap::<(felt252, ContractAddress, ContractAddress), bool>
lock (boolean)
Tracks the reentrancy lock status to prohibit reentrancy when loading the context or the asset config.
lock: bool
Functions
asset_config_unsafe
Returns the configuration / state of an asset for a given pool
This method does not prevent reentrancy which may result in asset_config being out of date.
For contract to contract interactions asset_config() should be used instead.
Check source code on Github.
Arguments
pool_id- id of the poolasset- address of the asset
Returns
asset_config- asset configurationfee_shares- accrued fee shares minted to the fee recipient
fn asset_config_unsafe(
self: @ContractState,
pool_id: felt252,
asset: ContractAddress
) -> (AssetConfig, u256)
asset_config
Wrapper around asset_config() that prevents reentrancy
Check source code on Github.
Arguments
pool_id- id of the poolasset- address of the asset
Returns
asset_config- asset configurationfee_shares- accrued fee shares minted to the fee recipient
fn asset_config(
ref self: ContractState,
pool_id: felt252,
asset: ContractAddress
) -> (AssetConfig, u256)
ltv_config
Returns the loan-to-value configuration between two assets (pair) in the pool.
Check source code on Github.
Arguments
pool_id- id of the poolcollateral_asset- address of the collateral assetdebt_asset- address of the debt asset
Returns
ltv_config- ltv configuration
fn ltv_config(
self: @ContractState,
pool_id: felt252,
collateral_asset: ContractAddress,
debt_asset: ContractAddress
) -> LTVConfig
position_unsafe
Returns the current state of a position.
Check source code on Github
Arguments
pool_id- id of the poolcollateral_asset- address of the collateral assetdebt_asset- address of the debt assetuser- address of the position's owner
Returns
position- position statecollateral- amount of collateral (computed from position.collateral_shares) [asset scale]debt- amount of debt (computed from position.nominal_debt) [asset scale]
fn position_unsafe(
self: @ContractState,
pool_id: felt252,
collateral_asset: ContractAddress,
debt_asset: ContractAddress,
user: ContractAddress
) -> (Position, u256, u256)
position
Wrapper around position() that prevents reentrancy.
Check source code on Github
Arguments
pool_id- id of the poolcollateral_asset- address of the collateral assetdebt_asset- address of the debt assetuser- address of the position's owner
Returns
position- position statecollateral- amount of collateral (computed from position.collateral_shares) [asset scale]debt- amount of debt (computed from position.nominal_debt) [asset scale]
fn position(
ref self: ContractState,
pool_id: felt252,
collateral_asset: ContractAddress,
debt_asset: ContractAddress,
user: ContractAddress
) -> (Position, u256, u256)
check_collateralization_unsafe
Checks if a position is collateralized according to the max. loan-to-value ratio.
Check source code on Github
Arguments
pool_id- id of the poolcollateral_asset- address of the collateral assetdebt_asset- address of the debt assetuser- address of the position's owner
Returns
collateralized- true if the position is collateralized, false otherwisecollateral_value- USD value of the collateral [SCALE]debt_value- USD value of the debt [SCALE]
fn check_collateralization_unsafe(
self: @ContractState,
pool_id: felt252,
collateral_asset: ContractAddress,
debt_asset: ContractAddress,
user: ContractAddress
) -> (bool, u256, u256)
check_collateralization
Wrapper around check_collateralization_unsafe() that prevents reentrancy
Check source code on Github
Arguments
pool_id- id of the poolcollateral_asset- address of the collateral assetdebt_asset- address of the debt assetuser- address of the position's owner
Returns
collateralized- true if the position is collateralized, false otherwisecollateral_value- USD value of the collateral [SCALE]debt_value- USD value of the debt [SCALE]
fn check_collateralization(
ref self: ContractState,
pool_id: felt252,
collateral_asset: ContractAddress,
debt_asset: ContractAddress,
user: ContractAddress
) -> (bool, u256, u256)
rate_accumulator_unsafe
Calculates the current (using the current block's timestamp) rate accumulator for a given asset in a pool.
Check source code on Github
Arguments
pool_id- id of the poolasset- address of the asset
Returns
rate_accumulator- computed rate accumulator [SCALE]
fn rate_accumulator_unsafe(
self: @ContractState,
pool_id: felt252,
asset: ContractAddress) -> u256
rate_accumulator
Wrapper around rate_accumulator() that prevents reentrancy.
Check source code on Github.
Arguments
pool_id- id of the poolasset- address of the asset
Returns
rate_accumulator- computed rate accumulator [SCALE]
fn rate_accumulator(
ref self: ContractState,
pool_id: felt252,
asset: ContractAddress) -> u256
utilization_unsafe
Calculates the current utilization of an asset in a pool.
Check source code on Github.
Arguments
pool_id- id of the poolasset- address of the asset
Returns
utilization- computed utilization [SCALE]
fn utilization_unsafe(
self: @ContractState,
pool_id: felt252,
asset: ContractAddress) -> u256
utilization
Wrapper around utilization() that prevents reentrancy.
Check source code on Github.
Arguments
pool_id- id of the poolasset- address of the asset
Returns
utilization- computed utilization [SCALE]
fn utilization(
ref self: ContractState,
pool_id: felt252,
asset: ContractAddress) -> u256
delegation
Returns the delegation status of a delegator to a delegatee for a specific pool.
Check source code on Github.