Get current admin
fn admin_get(env: soroban_sdk::Env) -> Option
Transfer to new admin Should be called in the same transaction as deploying the contract to ensure that a different account try to become admin
fn admin_set(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)
Admin can redeploy the contract with given hash.
fn redeploy(env: soroban_sdk::Env, wasm_hash: soroban_sdk::BytesN<32>)
Oracle contract used for this contract's XLM price feed. Example: CBJSHY5PQQ4LS7VMHI4BJODEDP5MLANRNUSHKNSVKK7BQ4Y6LSTBDGMR
fn xlm_contract(env: soroban_sdk::Env) -> soroban_sdk::Address
Stellar asset contract address
fn xlm_sac(env: soroban_sdk::Env) -> soroban_sdk::Address
Oracle contract used for this contract's pegged asset. Example: CBJSHY5PQQ4LS7VMHI4BJODEDP5MLANRNUSHKNSVKK7BQ4Y6LSTBDGMR
fn asset_contract(env: soroban_sdk::Env) -> soroban_sdk::Address
Which asset from Oracle this tracks. For --asset '{"Other":"USD"}' on asset contract, set to USD
fn pegged_asset(env: soroban_sdk::Env) -> soroban_sdk::Symbol
Basis points. Default: 110%
fn minimum_collateralization_ratio(env: soroban_sdk::Env) -> u32
Get the most recent price for XLM
fn lastprice_xlm(env: soroban_sdk::Env) -> Result
Get the most recent price for the pegged asset
fn lastprice_asset(env: soroban_sdk::Env) -> Result
Get the number of decimals used by the xlm oracle contract. This is NOT the same as the number of decimals used by the XLM Stellar Asset Contract.
fn decimals_xlm_feed(env: soroban_sdk::Env) -> Result
Get the number of decimals used by the asset oracle contract. This is NOT the same as the number of decimals used by the xAsset Fungible Token contract.
fn decimals_asset_feed(env: soroban_sdk::Env) -> Result
Opens a new Collateralized Debt Position (CDP) by depositing collateral and minting xAsset. The user who creates the CDP becomes the CDP's owner.
fn open_cdp(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
collateral: i128,
asset_lent: i128,
) -> Result<(), soroban_sdk::Error>
Retrieves the CDP information for a specific lender
fn cdp(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
) -> Result
Freezes a CDP if its Collateralization Ratio (CR) is below the xAsset's Minimum Collateralization Ratio (MCR). A frozen CDP is no longer usable or interactable by its former owner.
fn freeze_cdp(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Increases the Collateralization Ratio (CR) by depositing more collateral to an existing CDP.
fn add_collateral(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Lowers the Collateralization Ratio (CR) by withdrawing part or all of the collateral from a CDP. Collateral cannot be withdrawn if it brings CR below the xAsset's MCR.
fn withdraw_collateral(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Lowers the Collateralization Ratio (CR) by minting additional xAsset against existing collateral. More xAsset cannot be minted if it brings CR below the xAsset's MCR.
fn borrow_xasset(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Increases the Collateralization Ratio (CR) by repaying debt in the form of xAsset. When the debt is repaid, the xAsset is burned (i.e., destroyed). More xAsset cannot be burned than debt owed by the CDP.
Repayment Workflow:
get_accrued_interest] to get the latest accrued interest, including approval_amount.approve function to approve spending the required XLM:stellar contract invoke \
--id <xlm_sac_contract_id> \
-- approve \
--from <your_id> \
--spender <token_contract_id> \
--amount <approval_amount> \
--expiration_ledger <current_ledger_seq_plus_x>
--from is your account.--spender is this token contract's ID.--amount is the approval_amount returned by get_accrued_interest.--expiration_ledger should be a value a few ledgers into the future (e.g., current sequence + 100 ~ 5 minutes).repay_debt] within 5 minutes to finalize repayment and burn xAsset.This ensures the proper interest payment is authorized an
fn repay_debt(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Liquidates a frozen CDP. Upon liquidation, CDP debt is repaid by withdrawing xAsset from a Stability Pool. As debt is repaid, collateral is withdrawn from the CDP. If all debt is repaid, then all collateral is withdrawn, and the CDP is closed.
fn liquidate_cdp(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
) -> Result<(i128, i128, CDPStatus), soroban_sdk::Error>
Merges two or more frozen CDPs into one CDP. Upon merging, all but one of the CDPs are closed, and their debt and collateral are transferred into a single CDP.
fn merge_cdps(
env: soroban_sdk::Env,
lenders: soroban_sdk::Vec,
) -> Result<(), soroban_sdk::Error>
Closes a CDP when its Collateralization Ratio (CR) value is zero, having no collateral or debt. A CDP is closed after all its debt is repaid and its collateral is withdrawn.
fn close_cdp(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Updates and returns the accrued interest on a CDP.
Returns an [InterestDetail] struct, including:
amount: total interest accrued;paid: total interest paid;amount_in_xlm: interest amount expressed in XLM;approval_amount: the amount of XLM that needs to be approved for repayment if repaid within five minutes;last_interest_time: timestamp of last calculation.fn get_accrued_interest(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
) -> Result
Pays the accrued interest (but not principal) on a CDP.
get_accrued_interest], which returns both values.amount_in_xlm and/or approval_amount from that result when
approving and paying interest.Note: This function is for paying only the interest; to repay principal, use [repay_debt].
fn pay_interest(
env: soroban_sdk::Env,
lender: soroban_sdk::Address,
amount: i128,
) -> Result
Initialize the subcontract with the given configuration.
This assumes that you have already:
admin_setcdp_init has already been calledadmin_set has not yet been called and there is therefore not yet an adminfn cdp_init(
env: soroban_sdk::Env,
xlm_sac: soroban_sdk::Address,
xlm_contract: soroban_sdk::Address,
asset_contract: soroban_sdk::Address,
pegged_asset: soroban_sdk::Symbol,
min_collat_ratio: u32,
name: soroban_sdk::String,
symbol: soroban_sdk::String,
decimals: u32,
annual_interest_rate: u32,
)
Set the address of the XLM contract
fn set_xlm_sac(env: soroban_sdk::Env, to: soroban_sdk::Address)
Set the oracle price feed contract for xlm. Only callable by admin.
fn set_xlm_contract(env: soroban_sdk::Env, to: soroban_sdk::Address)
Set the oracle price feed contract for xAsset. Only callable by admin.
fn set_asset_contract(env: soroban_sdk::Env, to: soroban_sdk::Address)
Set the asset the xAsset is pegged to. Only callable by admin.
fn set_pegged_asset(env: soroban_sdk::Env, to: soroban_sdk::Symbol)
Set minimum collateralization ration. Only callable by admin.
fn set_min_collat_ratio(env: soroban_sdk::Env, to: u32) -> u32
Set annual interest rate
fn set_interest_rate(env: soroban_sdk::Env, new_rate: u32) -> u32
Get annual interest rate
fn get_interest_rate(env: soroban_sdk::Env) -> u32
Get total interest collected
fn get_total_interest_collected(env: soroban_sdk::Env) -> i128
Returns the allowance for spender to transfer from from.
fn allowance(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
) -> i128
Set the allowance by amount for spender to transfer/burn from from.
fn approve(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
amount: i128,
live_until_ledger: u32,
)
Returns the balance of id.
fn balance(env: soroban_sdk::Env, id: soroban_sdk::Address) -> i128
Transfer amount from from to to.
fn transfer(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)
Transfer amount from from to to, consuming the allowance of spender.
fn transfer_from(
env: soroban_sdk::Env,
spender: soroban_sdk::Address,
from: soroban_sdk::Address,
to: soroban_sdk::Address,
amount: i128,
)
Burn amount from from.
fn burn(env: soroban_sdk::Env, from: soroban_sdk::Address, amount: i128)
Burn amount from from, consuming the allowance of spender.
fn burn_from(
env: soroban_sdk::Env,
spender: soroban_sdk::Address,
from: soroban_sdk::Address,
amount: i128,
)
Returns the number of decimals used to represent amounts of this token.
fn decimals(env: soroban_sdk::Env) -> u32
Returns the name for this token.
fn name(env: soroban_sdk::Env) -> soroban_sdk::String
Returns the symbol for this token.
fn symbol(env: soroban_sdk::Env) -> soroban_sdk::String
Increases the allowance that one address can spend on behalf of another address.
fn increase_allowance(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
amount: i128,
)
Decreases the allowance that one address can spend on behalf of another address.
fn decrease_allowance(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
spender: soroban_sdk::Address,
amount: i128,
)
Returns the spendable balance of tokens for a specific address.
fn spendable_balance(env: soroban_sdk::Env, id: soroban_sdk::Address) -> i128
Checks if a specific address is authorized.
fn authorized(env: soroban_sdk::Env, id: soroban_sdk::Address) -> bool
Sets the authorization status of a specific address.
fn set_authorized(env: soroban_sdk::Env, id: soroban_sdk::Address, authorize: bool)
Mints a specified amount of tokens to a specific address.
fn mint(env: soroban_sdk::Env, to: soroban_sdk::Address, amount: i128)
Retrieves a specified amount of tokens from a specific address (clawback).
fn clawback(env: soroban_sdk::Env, from: soroban_sdk::Address, amount: i128)
Sets a new admin address.
fn set_admin(env: soroban_sdk::Env, new_admin: soroban_sdk::Address)
Deposits xasset tokens into the Stability Pool.
fn deposit(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Withdraws xasset tokens from the Stability Pool.
fn withdraw(
env: soroban_sdk::Env,
to: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Processes a liquidation event for a CDP.
fn liquidate(
env: soroban_sdk::Env,
cdp_owner: soroban_sdk::Address,
) -> Result<(i128, i128, CDPStatus), soroban_sdk::Error>
Allows a user to claim their share of collateral rewards.
fn claim_rewards(
env: soroban_sdk::Env,
to: soroban_sdk::Address,
) -> Result
Retrieves the current deposit amount for a given address.
fn get_staker_deposit_amount(
env: soroban_sdk::Env,
address: soroban_sdk::Address,
) -> Result
Retrieves the total amount of xasset tokens in the Stability Pool.
fn get_total_xasset(env: soroban_sdk::Env) -> i128
Retrieves the total amount of collateral rewards in the Stability Pool.
fn get_total_collateral(env: soroban_sdk::Env) -> i128
Allows a user to add their stake to the pool
fn stake(
env: soroban_sdk::Env,
from: soroban_sdk::Address,
amount: i128,
) -> Result<(), soroban_sdk::Error>
Allows a user to remove their stake from the pool
fn unstake(
env: soroban_sdk::Env,
staker: soroban_sdk::Address,
) -> Result<(), soroban_sdk::Error>
Allows a user to view their available xasset and rewards
fn get_available_assets(
env: soroban_sdk::Env,
staker: soroban_sdk::Address,
) -> Result
Allows a user to view their available current position
fn get_position(
env: soroban_sdk::Env,
staker: soroban_sdk::Address,
) -> Result
Allows a user to view the stability pool's current constants
fn get_constants(env: soroban_sdk::Env) -> StakerPosition