Contract methods

Below are brief descriptions of all the important functions used in our smart contract. For implementation details, please refer to our GitHub repository.

  • fn get_version() -> u8 returns the current version of the smart contract.

  • fn activate_contract(market_configuration: MarketConfiguration, owner: Identity) has read and write permission to contract storage. Accepts a market configuration and owner's identity as argument. Initiates the market and sets the config, you can only call it once.

  • fn add_collateral_asset(configuration: CollateralConfiguration) has read and write permission to contract storage. Accepts a collateral configuration as argument. Adds a new supported collateral asset to the market.

  • fn pause_collateral_asset(asset_id: AssetId) has read and write permission to contract storage. Accepts the asset id as argument. Pause a specific collateral asset.

  • fn resume_collateral_asset(asset_id: AssetId) has read and write permission to contract storage. Accepts the asset id as argument. Resumes a paused collateral asset.

  • fn update_collateral_asset(asset_id: AssetId, configuration: CollateralConfiguration) has read and write permission to contract storage. Accepts the asset id and collateral configuration as arguments. Updates a specific asset id with new collateral configuration.

  • fn get_collateral_configurations() -> Vec<CollateralConfiguration> has read permission to contract storage. Returns all current collateral configurations.

  • fn supply_collateral() has read and write permissions to contract storage. Performs the depositing of collateral assets.

  • fn withdraw_collateral(asset_id: AssetId, amount: u64, price_data_update: PriceDataUpdate) has read and write permissions to contract storage. Accepts an asset id, amount, and price data update (Pyth) as arguments. Performs the withdrawing of collateral assets.

  • fn get_user_collateral(account: Identity, asset_id: AssetId) -> u64 has read permissions to contract storage. Accepts the account's identity and asset id as arguments. Returns the collateral asset position of the account.

  • fn get_all_user_collateral(account: Identity) -> Vec<(AssetId, u64)> has read permissions to contract storage. Accepts the account's identity as an argument. Returns the all collateral asset positions of the account.

  • fn totals_collateral(asset_id: AssetId) -> u64 has read permissions to contract storage. Accepts the asset id as an argument. Returns the total collateral asset amount for the asset.

  • fn supply_base() has read and write permissions to contract storage. Deposit the base asset.

  • fn withdraw_base(amount: u64, price_data_update: PriceDataUpdate) has read and write permissions to contract storage. Accepts the amount and price data update (Pyth) as arguments. Withdrawal of base token.

  • fn get_user_supply_borrow(account: Identity) -> (u256, u256) has read permissions to contract storage. Accepts the account's identity as an argument. Returns the account's supply and borrow amount.

  • fn available_to_borrow(account: Identity) -> u256 has read permissions to contract storage. Accepts the account's identity as an argument. Returns the user’s available amount to borrow.

  • fn absorb(accounts: Vec<Identity>, price_data_update: PriceDataUpdate) has read and write permissions to contract storage. Accepts account identities that should be absorbed and price data update (Pyth) as arguments. Transfers pledge and debt of underwater accounts to protocol balance.

  • fn is_liquidatable(account: Identity) -> bool has read permission to contract storage. Accepts an account's identity as an argument. Returns a boolean whether the account is subject to liquidation.

  • fn buy_collateral(asset_id: AssetId, min_amount: u64, recipient: Identity) has read permission to contract storage. Accepts an asset id, min amount, and recipient's identity as arguments. Buys collateral from liquidated accounts from the protocol and sends it to the recipient.

  • fn collateral_value_to_sell(asset_id: AssetId, collateral_amount: u64) -> u64 has read permission to contract storage. Accepts asset id and collateral amount as arguments. Returns the amount of collateral asset to sell in base asset value.

  • fn quote_collateral(asset_id: AssetId, base_amount: u64) -> u64 has read permission to contract storage. Accepts an asset id to be liquidated and minimal to receive amount values as arguments. Returns how many collateral tokens the liquidator will receive for the number of asset base tokens entered.

  • fn get_reserves() -> I256 has read permission to contract storage. Returns the protocol reserves of the base asset.

  • fn withdraw_reserves(to: Identity, amount: u64) has read permission to contract storage. Accepts an account's identity and amount as arguments. Withdraws the reserves of the underlying asset.

  • fn get_collateral_reserves(asset_id: AssetId) -> I256 has read permission to contract storage. Accepts an asset id as an argument. Returns asset collateral reserves.

  • fn pause(config: PauseConfiguration) has write and read permission to contract storage. Accepts an object with the PauseConfiguration type as argument. Suspends the list of methods (supply, withdraw, absorb, buy collateral).

  • fn get_pause_configuration() -> PauseConfiguration has read permission to contract storage. Returns the pause configuration (supply, withdraw, absorb, buy collateral).

  • fn get_market_configuration() -> MarketConfiguration has read permission to contract storage. Returns the market configuration.

  • fn get_market_basics() -> MarketBasics has read permission to contract storage. Returns the market information.

  • fn get_market_basics_with_interest() -> MarketBasics has read permission to contract storage. Returns the market information including accrued interests.

  • fn get_user_basic(account: Identity) -> UserBasic has read permission to contract storage. Accepts the account's identity as an argument. Returns the user information.

  • fn get_user_basic_with_interest(account: Identity) -> I256 has read permission to contract storage. Accepts the account's identity as an argument. Returns the user information with accrued interests.

  • fn get_utilization() -> u256 has read permission to contract storage. Returns utilization of the market.

  • fn balance_of(asset_id: AssetId) -> u64 has read permission to contract storage. Accepts an asset id as an argument. Returns the balance of the contract for the certain asset.

  • fn get_supply_rate(utilization: u256) -> u256 has read permission to contract storage. Accepts a utilization value as an argument. Returns the deposit rate accrued per second.

  • fn get_borrow_rate(utilization: u256) -> u256 has read permission to contract storage. Accepts a utilization value as an argument. Returns the borrow rate accrued per second.

  • fn set_pyth_contract_id(contract_id: ContractId) has write permissions to contract storage. Accepts a contract id as an argument. Sets the contract id for the Pyth oracle.

  • fn get_pyth_contract_id() -> ContractId has read permissions to contract storage. Returns the contract id for the Pyth oracle.

  • fn get_price(price_feed_id: PriceFeedId) -> Price has read permissions to contract storage. Accepts a price feed id as an argument. Returns the price for the asset (based on its price feed id).

  • fn update_fee(update_data:Vec<Bytes>) -> u64 has read permissions to contract storage. Accepts an update data as an argument. Returns the price fee for updating the price in the Pyth oracle.

  • fn update_price_if_neceessary(price_data_update: PriceDataUpdate) has read permissions to contract storage. Accepts a price data update as an argument. Updates the price of some asset in the Pyth oracle.

  • fn update_market_configuration(configuration: MarketConfiguration) has write permissions to contract storage. Accepts a market configuration as an argument. Updates the market configuration.

  • fn transfer_ownership(new_owner: Identity) has write permissions to contract storage. Accepts a new owner's identity as an argument. Transfers an ownership of the smart contract to the new owner.

  • fn renounce_ownership() has write permissions to contract storage. Renounces ownership of the smart contract (sets it to the zero address).

Last updated