Skip to content

Conversation

@glitch003
Copy link

A basic script to see the real world USD costs for using Naga

@github-actions
Copy link

github-actions bot commented Nov 26, 2025

PASS [ 43.608s] (3/3) lit_node::test toxiproxy::perf_tests::load_with_no_latency
PASS [ 43.783s] (2/3) lit_node::test toxiproxy::perf_tests::load_with_50ms_latency_single_link
PASS [ 91.200s] (1/3) lit_node::test toxiproxy::perf_tests::load_with_50ms_latency_all_links

Copilot finished reviewing on behalf of GTC6244 November 26, 2025 21:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a utility script to calculate and display the real-world USD costs for using Naga services by fetching the LITKEY token price from CoinGecko and querying the on-chain PriceFeed contract.

Key changes:

  • Added calculateUSDPricing.ts script that fetches LITKEY token prices and displays various pricing tiers
  • Implements price calculations for different product types (PKP Sign, Encrypted Sign, Lit Action, Sign Session Key)
  • Shows pricing at different usage percentages (0%, 25%, 50%, 75%, 100%) and individual Lit Action component costs

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@glitch003 glitch003 marked this pull request as ready for review November 29, 2025 22:22
@glitch003 glitch003 requested a review from Copilot November 29, 2025 22:37
Copilot finished reviewing on behalf of glitch003 November 29, 2025 22:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +96 to +97
throw new Error(
'Unable to fetch LITKEY price. Please check CoinGecko API or set manually.'
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message references "LITKEY price" but the function attempts to fetch "LIT price" from CoinGecko using the token ID 'lit-protocol'. This inconsistency could lead to confusion. Either update the error message to reflect that it's fetching LIT price (not LITKEY), or clarify the relationship between LIT and LITKEY tokens in the comments.

Copilot uses AI. Check for mistakes.
Comment on lines +141 to +144
const priceFeed = await ethers.getContractAt(
'PriceFeedDiamond',
priceFeedAddress
);
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error handling for contract interaction failures. If the contract doesn't exist at the specified address, is not deployed on the current network, or if there's an RPC error, the script will crash with an unhelpful error. Consider adding try-catch blocks around contract calls with meaningful error messages.

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +11
// Usage: HARDHAT_NETWORK=litMainnet npx ts-node --files scripts/calculateUSDPricing.ts

import hre from 'hardhat';

const { ethers } = hre;

// on Lit Chain Mainnet
const NAGA_PROD_PRICE_FEED_ADDRESS =
'0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C';

Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded contract address may cause issues on different networks. The script hardcodes the Naga production PriceFeed address for Lit Chain Mainnet, but doesn't validate that the current network matches. If run on a different network, the contract call will fail. Consider adding network validation or making the address configurable via environment variables or command-line arguments.

Suggested change
// Usage: HARDHAT_NETWORK=litMainnet npx ts-node --files scripts/calculateUSDPricing.ts
import hre from 'hardhat';
const { ethers } = hre;
// on Lit Chain Mainnet
const NAGA_PROD_PRICE_FEED_ADDRESS =
'0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C';
// Usage: HARDHAT_NETWORK=litMainnet PRICE_FEED_ADDRESS=0xYourAddressHere npx ts-node --files scripts/calculateUSDPricing.ts
import hre from 'hardhat';
const { ethers, network } = hre;
// Naga PriceFeed address for Lit Chain Mainnet
const DEFAULT_LIT_MAINNET_PRICE_FEED_ADDRESS = '0x88F5535Fa6dA5C225a3C06489fE4e3405b87608C';
// Get address from env or fallback to default if on Lit Chain Mainnet
function getPriceFeedAddress(): string {
const envAddress = process.env.PRICE_FEED_ADDRESS;
if (envAddress && envAddress !== '') {
return envAddress;
}
// Validate network
if (network.name === 'litMainnet') {
return DEFAULT_LIT_MAINNET_PRICE_FEED_ADDRESS;
}
throw new Error(
`No PRICE_FEED_ADDRESS provided and not on Lit Chain Mainnet (network: ${network.name}). Please set PRICE_FEED_ADDRESS environment variable.`
);
}

Copilot uses AI. Check for mistakes.
// Note: You may need to adjust the token ID if LITKEY is listed differently
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
);
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing HTTP response status check. The fetch call should verify the response is successful before parsing JSON. If the API returns a 4xx or 5xx status, response.json() may fail or return an error object instead of the expected data structure. Add if (!response.ok) throw new Error(...) before parsing the JSON.

Suggested change
);
);
if (!response.ok) {
throw new Error(`Failed to fetch LITKEY price: ${response.status} ${response.statusText}`);
}

Copilot uses AI. Check for mistakes.
Comment on lines +103 to +106
* Get PriceFeed contract address from networkContext.json or use default
*/
function getPriceFeedAddress(): string {
// Naga prod address
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getPriceFeedAddress function always returns the hardcoded mainnet address regardless of the actual network being used. This could be misleading since the function name and comment suggest it might retrieve the address from networkContext.json. Either implement the network-specific logic or rename the function to getMainnetPriceFeedAddress to be more explicit.

Suggested change
* Get PriceFeed contract address from networkContext.json or use default
*/
function getPriceFeedAddress(): string {
// Naga prod address
* Get the PriceFeed contract address for Lit Chain Mainnet.
*/
function getMainnetPriceFeedAddress(): string {
// Naga prod address (Lit Chain Mainnet)

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +97
async function getLitKeyPrice(): Promise<number> {
try {
// Try to get LIT token price from CoinGecko
// Note: You may need to adjust the token ID if LITKEY is listed differently
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
);
const data = await response.json();

if (data['lit-protocol'] && data['lit-protocol'].usd) {
return data['lit-protocol'].usd;
}

throw new Error('LIT price not found in CoinGecko response');
} catch (error) {
console.error('Error fetching LITKEY price from CoinGecko:', error);
console.log('Falling back to manual price input...');
// You can set a default price here or throw
throw new Error(
'Unable to fetch LITKEY price. Please check CoinGecko API or set manually.'
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The script relies on external API (CoinGecko) without rate limiting or caching. For a production script that may be run frequently, consider implementing rate limiting, caching the token price for a reasonable duration, or providing an option to manually specify the price to avoid API rate limits or availability issues.

Suggested change
async function getLitKeyPrice(): Promise<number> {
try {
// Try to get LIT token price from CoinGecko
// Note: You may need to adjust the token ID if LITKEY is listed differently
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
);
const data = await response.json();
if (data['lit-protocol'] && data['lit-protocol'].usd) {
return data['lit-protocol'].usd;
}
throw new Error('LIT price not found in CoinGecko response');
} catch (error) {
console.error('Error fetching LITKEY price from CoinGecko:', error);
console.log('Falling back to manual price input...');
// You can set a default price here or throw
throw new Error(
'Unable to fetch LITKEY price. Please check CoinGecko API or set manually.'
// In-memory cache for LITKEY price
let cachedLitKeyPrice: number | null = null;
let cachedLitKeyPriceTimestamp: number | null = null;
const CACHE_DURATION_MS = 5 * 60 * 1000; // 5 minutes
/**
* Get LITKEY token price in USD from CoinGecko, with caching and manual override
*/
async function getLitKeyPrice(): Promise<number> {
// 1. Check for manual override via environment variable
const manualPrice = process.env.LITKEY_PRICE_USD;
if (manualPrice !== undefined) {
const priceNum = Number(manualPrice);
if (!isNaN(priceNum) && priceNum > 0) {
return priceNum;
} else {
console.warn('Invalid LITKEY_PRICE_USD env var value, falling back to API.');
}
}
// 2. Check cache
const now = Date.now();
if (
cachedLitKeyPrice !== null &&
cachedLitKeyPriceTimestamp !== null &&
now - cachedLitKeyPriceTimestamp < CACHE_DURATION_MS
) {
return cachedLitKeyPrice;
}
// 3. Fetch from CoinGecko
try {
const response = await fetch(
'https://api.coingecko.com/api/v3/simple/price?ids=lit-protocol&vs_currencies=usd'
);
const data = await response.json();
if (data['lit-protocol'] && data['lit-protocol'].usd) {
cachedLitKeyPrice = data['lit-protocol'].usd;
cachedLitKeyPriceTimestamp = now;
return cachedLitKeyPrice;
}
throw new Error('LIT price not found in CoinGecko response');
} catch (error) {
console.error('Error fetching LITKEY price from CoinGecko:', error);
console.log('Falling back to manual price input...');
throw new Error(
'Unable to fetch LITKEY price. Please check CoinGecko API or set manually via LITKEY_PRICE_USD env var.'

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants