@clonegod/ttd-sui-common 2.0.2 → 2.0.3
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.
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TokenPriceCache = void 0;
|
|
4
4
|
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const format_1 = require("../../utils/format");
|
|
5
6
|
class TokenPriceCache {
|
|
6
7
|
constructor() {
|
|
7
8
|
this.tokenPriceCache = new Map();
|
|
@@ -12,6 +13,7 @@ class TokenPriceCache {
|
|
|
12
13
|
let tokenParts = tokenAddress.split('::');
|
|
13
14
|
tokenParts[0] = tokenParts[0].toLowerCase();
|
|
14
15
|
tokenAddress = tokenParts.join('::');
|
|
16
|
+
tokenAddress = (0, format_1.normalizeSuiTokenAddress)(tokenAddress, false);
|
|
15
17
|
const now = Date.now();
|
|
16
18
|
const cachedData = this.tokenPriceCache.get(tokenAddress);
|
|
17
19
|
if (cachedData && (now - cachedData.timestamp) < this.PRICE_CACHE_TIMEOUT_MILLS) {
|
|
@@ -7,6 +7,7 @@ exports.getQuoteAmountUsd = getQuoteAmountUsd;
|
|
|
7
7
|
exports.usdToTokenUiAmount = usdToTokenUiAmount;
|
|
8
8
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
9
9
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
10
|
+
const format_1 = require("../utils/format");
|
|
10
11
|
function getQuoteAmountUsd(poolInfo) {
|
|
11
12
|
const envValue = Number(process.env.QUOTE_AMOUNT_USD);
|
|
12
13
|
if (envValue > 0) {
|
|
@@ -15,6 +16,7 @@ function getQuoteAmountUsd(poolInfo) {
|
|
|
15
16
|
return poolInfo.quote_amount_usd;
|
|
16
17
|
}
|
|
17
18
|
async function usdToTokenUiAmount(amountInUsd, tokenAddress) {
|
|
19
|
+
tokenAddress = (0, format_1.normalizeSuiTokenAddress)(tokenAddress, false);
|
|
18
20
|
const priceMap = await (0, ttd_core_1.get_sui_token_price_info)([tokenAddress]);
|
|
19
21
|
const price = priceMap.get(tokenAddress)?.price;
|
|
20
22
|
if (!price || price === '0') {
|