
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@0xmonaco/utils
Advanced tools
Utility functions for the Monaco protocol. This package provides decimal conversion utilities and logging functionality.
Utility functions for the Monaco protocol. This package provides decimal conversion utilities and logging functionality.
npm install @0xmonaco/utils
The package provides utilities for handling token amounts in different decimal formats:
import {
convertToUniversal,
convertFromUniversal,
parseToUniversal,
formatFromUniversal,
UNIVERSAL_DECIMALS,
} from "@0xmonaco/utils";
// Convert between native decimals and universal 18-decimal format
const universalAmount = convertToUniversal(1000000n, 6); // 1 USDC (6 decimals) -> universal format
const nativeAmount = convertFromUniversal(universalAmount, 6); // universal format -> 1 USDC (6 decimals)
// Parse human-readable amounts directly to universal format
const universalAmount = parseToUniversal("1.5", 6); // "1.5" with 6 decimals -> universal format (bigint)
// Format universal amounts to human-readable strings
const readableAmount = formatFromUniversal(universalAmount, 6); // universal format -> "1.5" with 6 decimals
// Price conversion utilities
const universalPrice = convertToUniversalPrice(2000n, 6); // 2000 USDC (6 decimals) -> universal format
const nativePrice = convertFromUniversalPrice(universalPrice, 6); // universal format -> 2000 USDC (6 decimals)
A simple logging utility that provides consistent logging across the protocol:
import { createDefaultLogger, LogLevel } from "@0xmonaco/utils";
const logger = createDefaultLogger({
level: "info" as LogLevel, // 'debug' | 'info' | 'warn' | 'error'
debug: false, // enable/disable debug logs
});
logger.info("Order placed", { orderId: "0x123...", price: "2000", size: "1" });
logger.error("Order failed", {
error: "Insufficient balance",
orderId: "0x123...",
});
logger.debug("Market update", { bestBid: "1999", bestAsk: "2001" });
logger.warn("High slippage detected", { expected: "2000", actual: "2010" });
UNIVERSAL_DECIMALS
: The standard decimal format used by Monaco (18 decimals)convertToUniversal(amount: bigint, nativeDecimals: number): bigint
convertFromUniversal(universalAmount: bigint, nativeDecimals: number): bigint
convertToUniversalPrice(nativePrice: bigint, quoteDecimals: number): bigint
convertFromUniversalPrice(universalPrice: bigint, quoteDecimals: number): bigint
parseTokenAmount(amount: string, decimals: number): bigint
formatTokenAmount(amount: bigint, decimals: number): string
parseToUniversal(amount: string, nativeDecimals: number): bigint
formatFromUniversal(universalAmount: bigint, nativeDecimals: number): string
createDefaultLogger(options?: { level?: LogLevel; debug?: boolean }): Logger
level
: 'debug' | 'info' | 'warn' | 'error' (default: 'info')debug
: boolean to enable/disable debug logs (default: false)FAQs
Utility functions for the Monaco protocol. This package provides decimal conversion utilities and logging functionality.
We found that @0xmonaco/utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.