Skip to content

Commit 8a1fe73

Browse files
committed
fix(prices): always getNodePrices prior getting session sigs for paid endpoints
1 parent af86dd4 commit 8a1fe73

File tree

7 files changed

+66
-22
lines changed

7 files changed

+66
-22
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
* ```
2424
*/
2525

26+
import { NodePrices } from '@lit-protocol/types';
2627
import { ExpectedAccountOrWalletClient } from '../../../../LitChainClient/contract-manager/createContractsManager';
27-
import { DefaultNetworkConfig } from '../../../../interfaces/NetworkContext';
28+
import { INetworkConfig } from '../../../../interfaces/NetworkContext';
2829
import {
2930
getNodesForRequest,
3031
PRODUCT_IDS,
@@ -38,16 +39,13 @@ const PRODUCT_IDS_ARRAY = Object.values(PRODUCT_IDS);
3839
export interface PriceFeedInfo {
3940
epochId: any;
4041
minNodeCount: any;
41-
networkPrices: {
42-
url: string;
43-
prices: bigint[];
44-
}[];
42+
networkPrices: NodePrices;
4543
}
4644

47-
// Type for the parameters
45+
// Type for the parameters - now accepts any valid network config
4846
export interface GetPriceFeedInfoParams {
4947
realmId?: number;
50-
networkCtx: DefaultNetworkConfig;
48+
networkCtx: INetworkConfig<any, any>;
5149
productIds?: bigint[];
5250
}
5351

@@ -191,7 +189,7 @@ export async function getPriceFeedInfo(
191189
export async function getNodePrices(
192190
params: GetPriceFeedInfoParams,
193191
accountOrWalletClient: ExpectedAccountOrWalletClient
194-
): Promise<PriceFeedInfo['networkPrices']> {
192+
): Promise<NodePrices> {
195193
const priceInfo = await getPriceFeedInfo(params, accountOrWalletClient);
196194
return priceInfo.networkPrices;
197195
}

packages/networks/src/networks/vNaga/LitChainClient/apis/rawContractApis/pricing/getNodesForRequest.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22
import { generateValidatorURLs } from '../../../../../shared/utils/transformers';
3-
import { DefaultNetworkConfig } from '../../../../interfaces/NetworkContext';
3+
import { DefaultNetworkConfig, INetworkConfig } from '../../../../interfaces/NetworkContext';
44
import {
55
createContractsManager,
66
ExpectedAccountOrWalletClient,
@@ -27,18 +27,15 @@ const getNodesForRequestSchema = z.object({
2727
type GetNodesForRequestRequest = z.infer<typeof getNodesForRequestSchema>;
2828

2929
/**
30-
* Get nodes available for a request with their pricing information
31-
*
32-
* This function retrieves information about nodes that can service a request,
33-
* including their pricing data for various product IDs.
34-
*
30+
* Gets nodes for a given set of product IDs with their prices
31+
*
3532
* @param request - Object containing product IDs to get pricing for
36-
* @param networkCtx - The Naga network context
33+
* @param networkCtx - The network context (any valid network configuration)
3734
* @returns Information about nodes, their prices, epoch ID, and minimum node count
3835
*/
3936
export async function getNodesForRequest(
4037
request: GetNodesForRequestRequest,
41-
networkCtx: DefaultNetworkConfig,
38+
networkCtx: INetworkConfig<any, any>,
4239
accountOrWalletClient: ExpectedAccountOrWalletClient
4340
) {
4441
const { productIds } = getNodesForRequestSchema.parse(request);

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

Lines changed: 17 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-local';
8586

@@ -482,6 +483,8 @@ const networkModuleObject = {
482483
connectionInfo: ConnectionInfo,
483484
handshakeResult: OrchestrateHandshakeResponse
484485
): Promise<NagaJitContext> => {
486+
487+
// 1. Generate a key set for the JIT context
485488
const keySet: KeySet = {};
486489

487490
for (const url of connectionInfo.bootstrapUrls) {
@@ -494,7 +497,19 @@ const networkModuleObject = {
494497
secretKey: nacl.box.keyPair().secretKey,
495498
};
496499
}
497-
return { keySet };
500+
501+
// Use read-only account for viewing PKPs
502+
const account = privateKeyToAccount(
503+
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
504+
);
505+
506+
// 2. Fetch the price feed info
507+
const nodePrices = await getNodePrices({
508+
realmId: 1,
509+
networkCtx: networkConfig,
510+
}, account);
511+
512+
return { keySet, nodePrices };
498513
},
499514
handshake: {
500515
schemas: {

packages/networks/src/networks/vNaga/envs/naga-staging/naga-staging.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-staging';
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: 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-test';
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/interfaces/NetworkContext.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface INetworkConfig<T, M> {
2222
};
2323
}
2424

25+
// TODO: we should use a stablised network config as the default network config
2526
export type DefaultNetworkConfig = INetworkConfig<
2627
typeof localDevSignatures,
2728
any

packages/types/src/lib/v2types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ export type KeySet = Record<
118118
{ publicKey: Uint8Array; secretKey: Uint8Array }
119119
>;
120120

121+
// aka. Network Prices
122+
export type NodePrices = {
123+
url: string;
124+
prices: bigint[];
125+
}[];
126+
121127
export type NagaJitContext = {
122128
keySet: KeySet;
129+
nodePrices: NodePrices;
123130
};

0 commit comments

Comments
 (0)