Skip to content

Commit 8d609e9

Browse files
committed
fix(pricing): replace currentConnectionInfo with jitContext.nodePrices in pricingContext and enhance logging in priceFeedApi
1 parent 8a1fe73 commit 8d609e9

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

packages/lit-client/src/lib/LitClient/createLitClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const _createNagaLitClient = async (
219219
pricingContext: {
220220
product: 'SIGN',
221221
userMaxPrice: params.userMaxPrice,
222-
nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices,
222+
nodePrices: jitContext.nodePrices,
223223
threshold: currentHandshakeResult.threshold,
224224
},
225225
authContext: params.authContext,
@@ -383,7 +383,7 @@ export const _createNagaLitClient = async (
383383
pricingContext: {
384384
product: 'LIT_ACTION',
385385
userMaxPrice: params.userMaxPrice,
386-
nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices,
386+
nodePrices: jitContext.nodePrices,
387387
threshold: currentHandshakeResult.threshold,
388388
},
389389
authContext: params.authContext,
@@ -650,7 +650,7 @@ export const _createNagaLitClient = async (
650650
pricingContext: {
651651
product: 'DECRYPTION',
652652
userMaxPrice: params.userMaxPrice,
653-
nodePrices: currentConnectionInfo.priceFeedInfo.networkPrices,
653+
nodePrices: jitContext.nodePrices,
654654
threshold: currentHandshakeResult.threshold,
655655
},
656656
authContext: params.authContext,

packages/networks/src/networks/vNaga/LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@
2323
* ```
2424
*/
2525

26+
const _logger = getChildLogger({
27+
module: 'priceFeedApi',
28+
});
29+
2630
import { NodePrices } from '@lit-protocol/types';
2731
import { ExpectedAccountOrWalletClient } from '../../../../LitChainClient/contract-manager/createContractsManager';
2832
import { INetworkConfig } from '../../../../interfaces/NetworkContext';
2933
import {
3034
getNodesForRequest,
3135
PRODUCT_IDS,
3236
} from '../../../apis/rawContractApis/pricing/getNodesForRequest';
37+
import { getChildLogger } from '@lit-protocol/logger';
3338

3439
// Configuration constants
3540
const STALE_PRICES_SECONDS = 3 * 1000; // Update prices if > X seconds old
@@ -152,6 +157,7 @@ export async function getPriceFeedInfo(
152157
): Promise<PriceFeedInfo> {
153158
// If there's a local promise, an update is in progress; wait for that
154159
if (fetchingPriceFeedInfo) {
160+
_logger.info('💲 Local promise is already fetching price feed info. Returning that instead.');
155161
return fetchingPriceFeedInfo;
156162
}
157163

@@ -160,9 +166,13 @@ export async function getPriceFeedInfo(
160166
priceFeedInfo &&
161167
Date.now() - lastUpdatedTimestamp < STALE_PRICES_SECONDS
162168
) {
169+
_logger.info(
170+
`💲 Returning stale price feed info. Remaining stale time: ${STALE_PRICES_SECONDS - (Date.now() - lastUpdatedTimestamp)
171+
}ms`
172+
);
163173
return priceFeedInfo;
164174
}
165-
175+
_logger.info('💲 Fetching new price feed info');
166176
// Fetch new prices, update local cache values, and return them
167177
return fetchPriceFeedInfoWithLocalPromise(params, accountOrWalletClient);
168178
}

packages/networks/src/networks/vNaga/envs/naga-dev/naga-dev.module.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import type { PKPStorageProvider } from '../../../../storage/types';
4747
import { createRequestId } from '../../../shared/helpers/createRequestId';
4848
import { handleAuthServerRequest } from '../../../shared/helpers/handleAuthServerRequest';
4949
import { composeLitUrl } from '../../endpoints-manager/composeLitUrl';
50-
import { PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis';
50+
import { getNodePrices, PKPPermissionsManager } from '../../LitChainClient/apis/highLevelApis';
5151
import { PaymentManager } from '../../LitChainClient/apis/highLevelApis/PaymentManager/PaymentManager';
5252
import { MintWithMultiAuthsRequest } from '../../LitChainClient/apis/highLevelApis/mintPKP/mintWithMultiAuths';
5353
import { PkpIdentifierRaw } from '../../LitChainClient/apis/rawContractApis/permissions/utils/resolvePkpTokenId';
@@ -80,6 +80,7 @@ import {
8080
} from './chain-manager/createChainManager';
8181
import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct';
8282
import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice';
83+
import { privateKeyToAccount } from 'viem/accounts';
8384

8485
const MODULE_NAME = 'naga-dev';
8586

@@ -484,6 +485,7 @@ const networkModuleObject = {
484485
): Promise<NagaJitContext> => {
485486
const keySet: KeySet = {};
486487

488+
// 1. Generate a key set for the JIT context
487489
for (const url of connectionInfo.bootstrapUrls) {
488490
keySet[url] = {
489491
publicKey: hexToBytes(
@@ -495,7 +497,18 @@ const networkModuleObject = {
495497
};
496498
}
497499

498-
return { keySet };
500+
// Use read-only account for viewing PKPs
501+
const account = privateKeyToAccount(
502+
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
503+
);
504+
505+
// 2. Fetch the price feed info
506+
const nodePrices = await getNodePrices({
507+
realmId: 1,
508+
networkCtx: networkConfig,
509+
}, account);
510+
511+
return { keySet, nodePrices };
499512
},
500513
handshake: {
501514
schemas: {

packages/networks/src/networks/vNaga/envs/naga-test/naga-test.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ const networkModuleObject = {
508508
networkCtx: networkConfig,
509509
}, account);
510510

511-
return { keySet, nodePrices: [] };
511+
return { keySet, nodePrices };
512512
},
513513
handshake: {
514514
schemas: {

0 commit comments

Comments
 (0)