Comment on page
PriceFeed
This contract feeds prices into Probity from the FTSO system.
The
PriceFeed
module reads prices from the FTSO system and feeds them into Probity for accounting operations.// 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)
Property | Type | Description |
---|---|---|
liquidationRatio | uint256 | The liquidation ratio for the asset. |
ftso | address | The address of the FTSO contract used for the price data. |
function
assets(
bytes32
assetId) 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)
function
initAsset(
bytes32
assetId, 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)
function
getPrice(
bytes32
assetId)
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)
function
updateAdjustedPrice(
bytes32
assetId)
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)
function
updateFtso(
bytes32
assetId,
address
newFtso)
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)
function
updateLiquidationRatio(
bytes32
assetId,
uint256
liquidationRatio)
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