Trustline
Probity
Search
K
Comment on page

PriceFeed

This contract feeds prices into Probity from the FTSO system.

Concept

For more information about FTSO system, read this
The PriceFeed module reads prices from the FTSO system and feeds them into Probity for accounting operations.

Contracts

Initializing contract

// Import the contract interface from @trustline-inc/probity
import PriceFeed from "@trustline-inc/probity/artifacts/contracts/probity/PriceFeed.sol/PriceFeed.json";
// Get the signer
const [signer]: SignerWithAddress[] = await ethers.getSigners();
// The contract address
const address = "deployed priceFeed contract Address"
// Creates an instance of PriceFeed
const priceFeed = new Contract(address, PriceFeed.abi, signer)

Data

Asset

Property
Type
Description
liquidationRatio
uint256
The liquidation ratio for the asset.
ftso
address
The address of the FTSO contract used for the price data.

Methods

assets

functionassets(bytes32assetId) returns(uint256 liquidationRatio, address ftso)
Accesses details for the asset given by the asset symbol.
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Get SGB asset info
const { liquidationRatio, ftso } = await PriceFeed.assets(id)

initAsset

functioninitAsset(bytes32assetId, uint256 liquidationRatio, FtsoLike ftso)
Initialize a new asset for probity system
Note: This can only be call by "gov" contract
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Wad is a unit of ether, equal to 1e18
const WAD = ethers.BigNumber.from("1000000000000000000")
// A new ratio of 150% (1.5e18)
const liquidationRatio = WAD.mul(15).div(10)
const ftsoAddresss = "SGB FTSO Address goes here"
// Fetch the price (in units of 1e5)
await PriceFeed.initAsset(id, liquidationRatio, ftsoAddress)

getPrice

functiongetPrice(bytes32assetId)
Gets the current price of the given asset.
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Fetch the price (in units of 1e5)
const { price } = await PriceFeed.getPrice(id)
// 100000 = $1.00000
console.log(price)

updateAdjustedPrice

functionupdateAdjustedPrice(bytes32assetId)
Update the adjusted price used in VaultEngine. The adjusted price is the price divided by the liquidation ratio. For example, with a price of $1 and a liquidation ratio of 200%, the adjusted price would be $1/2 = $0.5. Anyone can call this method for the system to fetch the latest price.
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Update the system adjusted price
await PriceFeed.updateAdjustedPrice(id)

updateFtso

functionupdateFtso(bytes32assetId,addressnewFtso)
Updates the FTSO contract address for the given asset. Only callable by the governance address.
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Set the new FTSO address
const newFtso = "0x6F3BCe778eDaa78DF55e32fAe68F2f3E2cd96bE8"
// Update the FTSO
await PriceFeed.updateFtso(id, newFtso)

updateLiquidationRatio

functionupdateLiquidationRatio(bytes32assetId,uint256liquidationRatio)
Updates the liquidation ratio for the given asset. Can only be called by the governance address.
// Convert the symbol string to hex string
const id = ethers.utils.id("SGB")
// Wad is a unit of ether, equal to 1e18
const WAD = ethers.BigNumber.from("1000000000000000000")
// A new ratio of 220% (2.2e18)
const newRatio = WAD.mul(22).div(10)
// Update the liquidation ratio
await PriceFeed.updateLiquidationRatio(id, newRatio)

Last modified 1yr ago