@acala-network/subql-utils 中文文档教程

发布于 3年前 浏览 17 项目主页 更新于 3年前

@acala-subql/utils

支持一些有用的功能

Token

  1. isTokenEqual
/**
 * @name isTokenEqual
 * @param token1 {any}
 * @param token2 {any}
 * @return boolean
 **/

const isEqual = isTokenEqual('KAR', 'KUSD')
  1. getTokenName
/**
 * @name getTokenName
 * @descriptions get string token name, { LiquidCrowdloan: 13 } will be lc://13
 * @param token {any}
 * @return string
 **/
const name = getTokenName(token)
  1. getTokenDecimals
/**
 * @name getTokenDecimals
 * @descriptions get token decimals support Token, DexShare, ForeignAssets, LiquidCrowdloanToken
 * @param api {[ApiPromise,ApiAt]}
 * @param token {any}
 * @return number
 **/
const decimals = await getTokenDecimals(api, token)

Date

  1. getEndOfDay
/**
 * @name getEndOfDay
 * @descriptions get end date of params
 * @param date {Date}
 * @return Date
 **/
const endOfDay = getEndOfDay(date)
  1. getStartOfDay
/**
 * @name getStartOfDay
 * @descriptions get start date of params
 * @param date {Date}
 * @return Date
 **/
const startOfDay = getStartOfDay(date)
  1. getEndOfHour
/**
 * @name getEndOfHour
 * @descriptions get end hour date of params
 * @param date {Date}
 * @return Date
 **/
const endOfHour = getEndOfHour(date)
  1. getStartOfHour
/**
 * @name getStartOfHour
 * @descriptions get end hour date of params
 * @param date {Date}
 * @return Date
 **/
const startOfHour = getStartOfHour(date)

Price

  1. getOraclePrice
/**
 * @name queryPriceFromOracle
 * @descriptions get price form oracle, support normal oracle token, liquid token, liquidcrowdloan token
 * @param api {[ApiPromise,ApiAt]}
 * @params block {SubstrateBlock}
 * @params token {string | CurrencyId | Token}
 * @return FixedPointNumber (include decimals information)
 **/
const price = await queryPriceFromOracle(api, block, token)

@acala-subql/utils

support some helpful functions

Token

  1. isTokenEqual
/**
 * @name isTokenEqual
 * @param token1 {any}
 * @param token2 {any}
 * @return boolean
 **/

const isEqual = isTokenEqual('KAR', 'KUSD')
  1. getTokenName
/**
 * @name getTokenName
 * @descriptions get string token name, { LiquidCrowdloan: 13 } will be lc://13
 * @param token {any}
 * @return string
 **/
const name = getTokenName(token)
  1. getTokenDecimals
/**
 * @name getTokenDecimals
 * @descriptions get token decimals support Token, DexShare, ForeignAssets, LiquidCrowdloanToken
 * @param api {[ApiPromise,ApiAt]}
 * @param token {any}
 * @return number
 **/
const decimals = await getTokenDecimals(api, token)

Date

  1. getEndOfDay
/**
 * @name getEndOfDay
 * @descriptions get end date of params
 * @param date {Date}
 * @return Date
 **/
const endOfDay = getEndOfDay(date)
  1. getStartOfDay
/**
 * @name getStartOfDay
 * @descriptions get start date of params
 * @param date {Date}
 * @return Date
 **/
const startOfDay = getStartOfDay(date)
  1. getEndOfHour
/**
 * @name getEndOfHour
 * @descriptions get end hour date of params
 * @param date {Date}
 * @return Date
 **/
const endOfHour = getEndOfHour(date)
  1. getStartOfHour
/**
 * @name getStartOfHour
 * @descriptions get end hour date of params
 * @param date {Date}
 * @return Date
 **/
const startOfHour = getStartOfHour(date)

Price

  1. getOraclePrice
/**
 * @name queryPriceFromOracle
 * @descriptions get price form oracle, support normal oracle token, liquid token, liquidcrowdloan token
 * @param api {[ApiPromise,ApiAt]}
 * @params block {SubstrateBlock}
 * @params token {string | CurrencyId | Token}
 * @return FixedPointNumber (include decimals information)
 **/
const price = await queryPriceFromOracle(api, block, token)
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文