UNPKG

@chorus-one/ethereum

Version:

All-in-one toolkit for building staking dApps on Ethereum network

36 lines (35 loc) 1.21 kB
import Decimal from 'decimal.js'; import { PriceOracleAbi } from '../contracts/priceOracleAbi'; export const getBaseData = async (connector, vaultAddress) => { const publicClient = connector.eth; const mintTokenRatePromise = publicClient.readContract({ abi: PriceOracleAbi, functionName: 'latestAnswer', address: connector.priceOracle }); const osTokenConfigPromise = connector.graphqlRequest({ type: 'graph', op: 'Vault', query: ` query Vault($address: ID!) { vault(id: $address) { osTokenConfig { ltvPercent liqThresholdPercent } } } `, variables: { address: vaultAddress } }); const [mintTokenRate, osTokenConfig] = await Promise.all([mintTokenRatePromise, osTokenConfigPromise]); // ETH per osETH exchange rate const rate = new Decimal(mintTokenRate.toString()).div(1_000_000_000_000_000_000).toString(); return { rate, ltvPercent: BigInt(osTokenConfig.data.vault.osTokenConfig.ltvPercent), thresholdPercent: BigInt(osTokenConfig.data.vault.osTokenConfig.liqThresholdPercent) // minting threshold, max 90% }; };