Skip to content

Commit 54b0bdc

Browse files
committed
feat(networks): add fresh price feed fetcher to network modules
- Introduced `getFreshPriceFeedInfo` method to fetch price feed data independently of state refresh across various network environments (naga-dev, naga-local, naga-staging, naga-test). - Updated multi-endpoint processor to utilize the new `LitClientType` for better type safety. - Enhanced the `createLitClient` function to include a fresh price feed info fetcher.
1 parent 98c1f62 commit 54b0bdc

File tree

6 files changed

+66
-2
lines changed

6 files changed

+66
-2
lines changed

e2e/artillery/src/processors/multi-endpoints.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAuthManager, storagePlugins } from "@lit-protocol/auth";
2-
import { createLitClient } from "@lit-protocol/lit-client";
2+
import { createLitClient, LitClientType } from "@lit-protocol/lit-client";
33
import { z } from "zod";
44
import * as StateManager from "../StateManager";
55
import * as NetworkManager from "../../../src/helper/NetworkManager";
@@ -16,7 +16,7 @@ const PkpSignResultSchema = z.object({
1616
});
1717

1818
// Global variables to cache expensive operations
19-
let litClient: any = null;
19+
let litClient: LitClientType;
2020
let authManager: any = null;
2121
let masterAccountAuthContext: any = null;
2222
let networkModule: any = null;
@@ -113,6 +113,7 @@ export async function runPkpSignTest() {
113113
authContext: authContext,
114114
pubKey: state.masterAccount.pkp.publicKey,
115115
toSign: `Hello from Artillery! ${Date.now()}`, // Unique message per request
116+
// userMaxPrice: await litClient
116117
});
117118

118119
// Validate the result using Zod schema

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ export const _createNagaLitClient = async (
715715
handshakeResult: _stateManager.getCallbackResult(),
716716
getMaxPricesForNodeProduct: networkModule.getMaxPricesForNodeProduct,
717717
getUserMaxPrice: networkModule.getUserMaxPrice,
718+
getFreshPriceFeedInfo: async () => {
719+
return await networkModule.getFreshPriceFeedInfo();
720+
},
718721
signSessionKey: _signSessionKey,
719722
signCustomSessionKey: _signCustomSessionKey,
720723
executeJs: _executeJs,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import {
8080
} from './chain-manager/createChainManager';
8181
import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct';
8282
import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice';
83+
import { getPriceFeedInfo } from '../../LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi';
84+
import { createReadOnlyContractsManager } from '../../LitChainClient/contract-manager/createContractsManager';
8385

8486
const MODULE_NAME = 'naga-dev';
8587

@@ -323,6 +325,19 @@ const networkModuleObject = {
323325
});
324326
},
325327

328+
// Expose a fresh price feed fetcher (chain read; independent of state refresh)
329+
getFreshPriceFeedInfo: async () => {
330+
const { walletClient } = createReadOnlyContractsManager(networkConfig);
331+
const realmId = Number(networkConfig.networkSpecificConfigs?.realmId ?? 1);
332+
return await getPriceFeedInfo(
333+
{
334+
realmId,
335+
networkCtx: networkConfig as any,
336+
},
337+
walletClient
338+
);
339+
},
340+
326341
getMaxPricesForNodeProduct: getMaxPricesForNodeProduct,
327342
getUserMaxPrice: getUserMaxPrice,
328343
getVerifyReleaseId: () => verifyReleaseId,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import {
8080
} from './chain-manager/createChainManager';
8181
import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct';
8282
import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice';
83+
import { getPriceFeedInfo } from '../../LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi';
84+
import { createReadOnlyContractsManager } from '../../LitChainClient/contract-manager/createContractsManager';
8385

8486
const MODULE_NAME = 'naga-local';
8587

@@ -323,6 +325,19 @@ const networkModuleObject = {
323325
});
324326
},
325327

328+
// Expose a fresh price feed fetcher (chain read; independent of state refresh)
329+
getFreshPriceFeedInfo: async () => {
330+
const { walletClient } = createReadOnlyContractsManager(networkConfig);
331+
const realmId = Number(networkConfig.networkSpecificConfigs?.realmId ?? 1);
332+
return await getPriceFeedInfo(
333+
{
334+
realmId,
335+
networkCtx: networkConfig as any,
336+
},
337+
walletClient
338+
);
339+
},
340+
326341
getMaxPricesForNodeProduct: getMaxPricesForNodeProduct,
327342
getUserMaxPrice: getUserMaxPrice,
328343
getVerifyReleaseId: () => verifyReleaseId,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import {
8080
} from './chain-manager/createChainManager';
8181
import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct';
8282
import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice';
83+
import { getPriceFeedInfo } from '../../LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi';
84+
import { createReadOnlyContractsManager } from '../../LitChainClient/contract-manager/createContractsManager';
8385

8486
const MODULE_NAME = 'naga-staging';
8587

@@ -323,6 +325,19 @@ const networkModuleObject = {
323325
});
324326
},
325327

328+
// Expose a fresh price feed fetcher (chain read; independent of state refresh)
329+
getFreshPriceFeedInfo: async () => {
330+
const { walletClient } = createReadOnlyContractsManager(networkConfig);
331+
const realmId = Number(networkConfig.networkSpecificConfigs?.realmId ?? 1);
332+
return await getPriceFeedInfo(
333+
{
334+
realmId,
335+
networkCtx: networkConfig as any,
336+
},
337+
walletClient
338+
);
339+
},
340+
326341
getMaxPricesForNodeProduct: getMaxPricesForNodeProduct,
327342
getUserMaxPrice: getUserMaxPrice,
328343
getVerifyReleaseId: () => verifyReleaseId,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ import {
8080
} from './chain-manager/createChainManager';
8181
import { getMaxPricesForNodeProduct } from './pricing-manager/getMaxPricesForNodeProduct';
8282
import { getUserMaxPrice } from './pricing-manager/getUserMaxPrice';
83+
import { getPriceFeedInfo } from '../../LitChainClient/apis/highLevelApis/priceFeed/priceFeedApi';
84+
import { createReadOnlyContractsManager } from '../../LitChainClient/contract-manager/createContractsManager';
8385

8486
const MODULE_NAME = 'naga-test';
8587

@@ -323,6 +325,19 @@ const networkModuleObject = {
323325
});
324326
},
325327

328+
// Expose a fresh price feed fetcher (chain read; independent of state refresh)
329+
getFreshPriceFeedInfo: async () => {
330+
const { walletClient } = createReadOnlyContractsManager(networkConfig);
331+
const realmId = Number(networkConfig.networkSpecificConfigs?.realmId ?? 1);
332+
return await getPriceFeedInfo(
333+
{
334+
realmId,
335+
networkCtx: networkConfig as any,
336+
},
337+
walletClient
338+
);
339+
},
340+
326341
getMaxPricesForNodeProduct: getMaxPricesForNodeProduct,
327342
getUserMaxPrice: getUserMaxPrice,
328343
getVerifyReleaseId: () => verifyReleaseId,

0 commit comments

Comments
 (0)