@clonegod/ttd-bsc-common 3.1.26 → 3.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,4 @@
1
1
  import { StandardPoolInfoType } from '@clonegod/ttd-core';
2
+ import Decimal from 'decimal.js';
2
3
  export declare function getQuoteAmountUsd(poolInfo: StandardPoolInfoType): number;
4
+ export declare function usdToTokenUiAmount(amountInUsd: number, tokenAddress: string): Promise<Decimal>;
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getQuoteAmountUsd = getQuoteAmountUsd;
7
+ exports.usdToTokenUiAmount = usdToTokenUiAmount;
8
+ const ttd_core_1 = require("@clonegod/ttd-core");
9
+ const decimal_js_1 = __importDefault(require("decimal.js"));
4
10
  function getQuoteAmountUsd(poolInfo) {
5
11
  const envValue = Number(process.env.QUOTE_AMOUNT_USD);
6
12
  if (envValue > 0) {
@@ -8,3 +14,11 @@ function getQuoteAmountUsd(poolInfo) {
8
14
  }
9
15
  return poolInfo.quote_amount_usd;
10
16
  }
17
+ async function usdToTokenUiAmount(amountInUsd, tokenAddress) {
18
+ const priceMap = await (0, ttd_core_1.get_bsc_token_price_info)([tokenAddress]);
19
+ const price = priceMap.get(tokenAddress)?.price;
20
+ if (!price || price === '0') {
21
+ throw new Error(`price not available for ${tokenAddress}`);
22
+ }
23
+ return new decimal_js_1.default(amountInUsd).div(new decimal_js_1.default(price));
24
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-bsc-common",
3
- "version": "3.1.26",
3
+ "version": "3.1.28",
4
4
  "description": "BSC common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -14,7 +14,7 @@
14
14
  "push": "npm run build && npm publish"
15
15
  },
16
16
  "dependencies": {
17
- "@clonegod/ttd-core": "3.1.27",
17
+ "@clonegod/ttd-core": "3.1.29",
18
18
  "axios": "1.15.0",
19
19
  "dotenv": "^16.4.7",
20
20
  "ethers": "^5.8.0",