{"version":3,"sources":["../../src/utils/balanceValue.ts"],"sourcesContent":["import { BigDecimal, toBigDecimal } from '@vertex-protocol/utils';\nimport {\n  BalanceWithProduct,\n  PerpBalanceWithProduct,\n  Product,\n  SpotBalanceWithProduct,\n} from '../common';\n\n/**\n * Calculates the quote value of a spot balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcSpotBalanceValue(\n  balanceWithProduct: SpotBalanceWithProduct,\n): BigDecimal {\n  return balanceWithProduct.amount.multipliedBy(balanceWithProduct.oraclePrice);\n}\n\n/**\n * Calculates the notional value of a perp balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceNotionalValue(\n  balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n  return balanceWithProduct.amount\n    .multipliedBy(balanceWithProduct.oraclePrice)\n    .abs();\n}\n\n/**\n * Calculates the true quote value of a perp balance, which is the same as its unrealized pnl / unsettled quote, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcPerpBalanceValue(\n  balanceWithProduct: PerpBalanceWithProduct,\n): BigDecimal {\n  return balanceWithProduct.amount\n    .multipliedBy(balanceWithProduct.oraclePrice)\n    .plus(balanceWithProduct.vQuoteBalance);\n}\n\n/**\n * Calculates the implied value of an LP balance, in terms of quote units\n *\n * @param balanceWithProduct\n */\nexport function calcLpBalanceValue(\n  balanceWithProduct: BalanceWithProduct,\n): BigDecimal {\n  const lpBalance = balanceWithProduct.lpAmount;\n  if (lpBalance.isZero()) {\n    return toBigDecimal(0);\n  }\n\n  return calcLpTokenValue(balanceWithProduct).times(lpBalance);\n}\n\n/**\n * Calculates the implied value of an LP token, in terms of quote units\n *\n * @param product\n */\nexport function calcLpTokenValue(product: Product) {\n  if (product.totalLpSupply.isZero()) {\n    return toBigDecimal(0);\n  }\n  const baseValue = product.totalLpBaseAmount\n    .div(product.totalLpSupply)\n    .multipliedBy(product.oraclePrice);\n  const quoteValue = product.totalLpQuoteAmount.div(product.totalLpSupply);\n  return baseValue.plus(quoteValue);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyC;AAalC,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OAAO,aAAa,mBAAmB,WAAW;AAC9E;AAOO,SAAS,6BACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,IAAI;AACT;AAOO,SAAS,qBACd,oBACY;AACZ,SAAO,mBAAmB,OACvB,aAAa,mBAAmB,WAAW,EAC3C,KAAK,mBAAmB,aAAa;AAC1C;AAOO,SAAS,mBACd,oBACY;AACZ,QAAM,YAAY,mBAAmB;AACrC,MAAI,UAAU,OAAO,GAAG;AACtB,eAAO,2BAAa,CAAC;AAAA,EACvB;AAEA,SAAO,iBAAiB,kBAAkB,EAAE,MAAM,SAAS;AAC7D;AAOO,SAAS,iBAAiB,SAAkB;AACjD,MAAI,QAAQ,cAAc,OAAO,GAAG;AAClC,eAAO,2BAAa,CAAC;AAAA,EACvB;AACA,QAAM,YAAY,QAAQ,kBACvB,IAAI,QAAQ,aAAa,EACzB,aAAa,QAAQ,WAAW;AACnC,QAAM,aAAa,QAAQ,mBAAmB,IAAI,QAAQ,aAAa;AACvE,SAAO,UAAU,KAAK,UAAU;AAClC;","names":[]}