Catalog npm
Back to packageRELEASE DETAILS

0.1.0

npm

@0xmonaco/utils

Utility functions for the Monaco protocol. This package provides decimal conversion utilities and logging functionality.

Published28 Aug 2025
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

@0xmonaco/utils

Utility functions for the Monaco protocol. This package provides decimal conversion utilities and logging functionality.

Installation

npm install @0xmonaco/utils

Usage

Decimal Conversion

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)

Logging

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" });

API Reference

Decimal Utilities

  • 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

Logging Utilities

  • createDefaultLogger(options?: { level?: LogLevel; debug?: boolean }): Logger
    • level: 'debug' | 'info' | 'warn' | 'error' (default: 'info')
    • debug: boolean to enable/disable debug logs (default: false)

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
viem
Environment
{
  "local_name": "viem",
  "alias": false,
  "peer_metadata": null
}
^2.30.6runtime
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
5.7.3development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "46fbe0d6805546cf01bb403997a2d373815416f9",
  "tarball": "https://registry.npmjs.org/@0xmonaco/utils/-/utils-0.1.0.tgz",
  "fileCount": 18,
  "integrity": "sha512-keXThUy+C9uRUnqza0jzto86tHA+ojx50lJXTWLFuioG22zp5m4pUHe8pi6g7QyL2dyMN3hHd/iBpG4yyBAGxg==",
  "signatures": [
    {
      "sig": "MEQCIAzXvYEzjHUjoyV7E7TEWFNWZYKfumwGYLEGuBqtkLSCAiAwYadvrRtU5JmYV84J8bcCbKGVYG44y65mX3X5rJJV4g==",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 8486
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 09:15 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:96bef1ae1e29d43e82089d54f62c2b6db65cd167fffefbe930cf675ebdf9aba7

Other collected versions

0.1.58 Sept0.1.128 AugView all collected versions →