@@ -620,18 +620,18 @@ export class LitContracts {
620620 } ;
621621
622622 /**
623- * Retrieves the PriceFeed contract instance based on the provided network, context, and RPC URL.
624- * If a context is provided, it determines if a contract resolver is used for bootstrapping contracts.
625- * If a resolver address is present in the context, it retrieves the PriceFeed contract from the contract resolver instance.
626- * Otherwise, it retrieves the PriceFeed contract using the contract address and ABI.
627- * Throws an error if required contract data is missing or if the PriceFeed contract cannot be obtained.
628- *
629- * @param network - The network key.
630- * @param context - The contract context or contract resolver context.
631- * @param rpcUrl - The RPC URL.
632- * @returns The PriceFeed contract instance.
633- * @throws Error if required contract data is missing or if the PriceFeed contract cannot be obtained.
634- */
623+ * Retrieves the PriceFeed contract instance based on the provided network, context, and RPC URL.
624+ * If a context is provided, it determines if a contract resolver is used for bootstrapping contracts.
625+ * If a resolver address is present in the context, it retrieves the PriceFeed contract from the contract resolver instance.
626+ * Otherwise, it retrieves the PriceFeed contract using the contract address and ABI.
627+ * Throws an error if required contract data is missing or if the PriceFeed contract cannot be obtained.
628+ *
629+ * @param network - The network key.
630+ * @param context - The contract context or contract resolver context.
631+ * @param rpcUrl - The RPC URL.
632+ * @returns The PriceFeed contract instance.
633+ * @throws Error if required contract data is missing or if the PriceFeed contract cannot be obtained.
634+ */
635635 public static async getPriceFeedContract (
636636 network : LIT_NETWORKS_KEYS ,
637637 context ?: LitContractContext | LitContractResolverContext ,
@@ -1083,7 +1083,7 @@ export class LitContracts {
10831083 * "https://192.168.1.1:443",
10841084 * "http://192.168.1.2:80"
10851085 * ]
1086- */
1086+ */
10871087 public static generateValidatorURLs ( {
10881088 activeValidatorStructs,
10891089 nodeProtocol,
@@ -1132,7 +1132,7 @@ export class LitContracts {
11321132 networkContext,
11331133 rpcUrl,
11341134 nodeProtocol,
1135- sortByPrice
1135+ sortByPrice,
11361136 } : {
11371137 litNetwork : LIT_NETWORKS_KEYS ;
11381138 networkContext ?: LitContractContext | LitContractResolverContext ;
@@ -1146,7 +1146,6 @@ export class LitContracts {
11461146 bootstrapUrls : string [ ] ;
11471147 priceByNetwork : Record < string , number > ;
11481148 } > => {
1149-
11501149 // if it's true, we will sort the networks by price feed from lowest to highest
11511150 // if it's false, we will not sort the networks
11521151 let _sortByPrice = sortByPrice || true ;
@@ -1202,9 +1201,10 @@ export class LitContracts {
12021201 const unsortedNetworks = LitContracts . generateValidatorURLs ( {
12031202 activeValidatorStructs,
12041203 litNetwork,
1205- } )
1204+ } ) ;
12061205
1207- // networks are all the nodes we know, but we also want to sort it by price feed
1206+ // networks are all the nodes we know from the `getActiveUnkickedValidatorStructsAndCounts` function, but we also want to sort it by price feed
1207+ // which we need to call the price feed contract
12081208 const priceFeedInfo = await LitContracts . getPriceFeedInfo ( {
12091209 litNetwork,
12101210 networkContext,
@@ -1220,13 +1220,13 @@ export class LitContracts {
12201220 const PRICE_BY_NETWORK = priceFeedInfo . networkPrices . mapByAddress ;
12211221
12221222 // sorted networks by prices (lowest to highest)
1223- // [
1223+ // [
12241224 // 'http://xxx:7470', <-- lowest price
12251225 // 'http://zzz:7472', <-- middle price
12261226 // 'http://yyy:7471' <-- highest price
12271227 // ]
1228- const sortedNetworks = unsortedNetworks . sort ( ( a , b ) =>
1229- PRICE_BY_NETWORK [ a ] - PRICE_BY_NETWORK [ b ]
1228+ const sortedNetworks = unsortedNetworks . sort (
1229+ ( a , b ) => PRICE_BY_NETWORK [ a ] - PRICE_BY_NETWORK [ b ]
12301230 ) ;
12311231
12321232 const bootstrapUrls = _sortByPrice ? sortedNetworks : unsortedNetworks ;
@@ -1246,64 +1246,72 @@ export class LitContracts {
12461246 rpcUrl,
12471247 productIds, // Array of product IDs
12481248 } : {
1249- litNetwork : LIT_NETWORKS_KEYS ,
1249+ litNetwork : LIT_NETWORKS_KEYS ;
12501250 networkContext ?: LitContractContext | LitContractResolverContext ;
12511251 rpcUrl ?: string ;
12521252 nodeProtocol ?: typeof HTTP | typeof HTTPS | null ;
12531253 productIds ?: number [ ] ;
12541254 } ) => {
1255-
12561255 if ( ! productIds || productIds . length === 0 ) {
12571256 log ( 'No product IDs provided. Defaulting to 0' ) ;
12581257
12591258 // You should use all [0,1,2] because we fetch the price first to connect to the cheapest node. And after that the user calls the actual function
1260- productIds = [ 0 , 1 , 2 ]
1259+ productIds = [ 0 , 1 , 2 ] ;
12611260 }
12621261
12631262 const priceFeedContract = await LitContracts . getPriceFeedContract (
12641263 litNetwork ,
12651264 networkContext ,
1266- rpcUrl ,
1267- )
1265+ rpcUrl
1266+ ) ;
12681267
1269- const nodesForRequest = await priceFeedContract [ 'getNodesForRequest' ] ( productIds ) ;
1268+ const nodesForRequest = await priceFeedContract [ 'getNodesForRequest' ] (
1269+ productIds
1270+ ) ;
12701271
12711272 const epochId = nodesForRequest [ 0 ] . toNumber ( ) ;
12721273 const minNodeCount = nodesForRequest [ 1 ] . toNumber ( ) ;
12731274 const nodesAndPrices = nodesForRequest [ 2 ] ;
12741275
1275- const activeValidatorStructs : ValidatorStruct [ ] = nodesAndPrices . map ( ( item : any ) => {
1276- return {
1277- ip : item . validator . ip ,
1278- ipv6 : item . validator . ipv6 ,
1279- port : item . validator . port ,
1280- nodeAddress : item . validator . nodeAddress ,
1281- reward : item . validator . reward ,
1282- seconderPubkey : item . validator . seconderPubkey ,
1283- receiverPubkey : item . validator . receiverPubkey ,
1276+ const activeValidatorStructs : ValidatorStruct [ ] = nodesAndPrices . map (
1277+ ( item : any ) => {
1278+ return {
1279+ ip : item . validator . ip ,
1280+ ipv6 : item . validator . ipv6 ,
1281+ port : item . validator . port ,
1282+ nodeAddress : item . validator . nodeAddress ,
1283+ reward : item . validator . reward ,
1284+ seconderPubkey : item . validator . seconderPubkey ,
1285+ receiverPubkey : item . validator . receiverPubkey ,
1286+ } ;
12841287 }
1285- } ) ;
1288+ ) ;
12861289
12871290 const networks = LitContracts . generateValidatorURLs ( {
12881291 activeValidatorStructs,
12891292 litNetwork,
1290- } )
1293+ } ) ;
12911294
1292- console . log ( " networks:" , networks ) ;
1295+ console . log ( ' networks:' , networks ) ;
12931296
12941297 const prices = nodesAndPrices . flatMap ( ( item : any ) => {
12951298 // Flatten the nested prices array and convert BigNumber to number
1296- return item . prices . map ( ( price : ethers . BigNumber ) => parseFloat ( price . toString ( ) ) ) ;
1299+ return item . prices . map ( ( price : ethers . BigNumber ) =>
1300+ parseFloat ( price . toString ( ) )
1301+ ) ;
12971302 } ) ;
12981303
1299- console . log ( " Prices as numbers:" , prices ) ;
1304+ console . log ( ' Prices as numbers:' , prices ) ;
13001305
1301- const networkPriceMap : Record < string , number > = networks . reduce ( ( acc : any , network , index ) => {
1302- acc [ network ] = prices [ index ] ;
1303- return acc ;
1304- } , { } ) ;
1306+ const networkPriceMap : Record < string , number > = networks . reduce (
1307+ ( acc : any , network , index ) => {
1308+ acc [ network ] = prices [ index ] ;
1309+ return acc ;
1310+ } ,
1311+ { }
1312+ ) ;
13051313
1306- console . log ( " Network to Price Map:" , networkPriceMap ) ;
1314+ console . log ( ' Network to Price Map:' , networkPriceMap ) ;
13071315
13081316 const networkPriceObjArr = networks . map ( ( network , index ) => {
13091317 return {
@@ -1317,10 +1325,10 @@ export class LitContracts {
13171325 minNodeCount,
13181326 networkPrices : {
13191327 arr : networkPriceObjArr ,
1320- mapByAddress : networkPriceMap
1328+ mapByAddress : networkPriceMap ,
13211329 } ,
1322- }
1323- }
1330+ } ;
1331+ } ;
13241332
13251333 private static async _resolveContractContext (
13261334 network : LIT_NETWORK_VALUES
0 commit comments