Skip to content

Commit d67c040

Browse files
committed
fix(contracts-sdk): PriceFeed not found & passing realmId to PriceFeed contract
1 parent 1a31a67 commit d67c040

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

packages/contracts-sdk/src/lib/contracts-sdk.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export class LitContracts {
148148
'Multisender',
149149
'LITToken',
150150
'StakingBalances',
151+
'PriceFeed'
151152
];
152153

153154
static logger: Logger = LogManager.Instance.get('contract-sdk');
@@ -653,6 +654,7 @@ export class LitContracts {
653654
}
654655

655656
if (!context) {
657+
656658
const contractData = await LitContracts._resolveContractContext(network);
657659

658660
const priceFeedContract = contractData.find(
@@ -676,6 +678,7 @@ export class LitContracts {
676678

677679
return new ethers.Contract(address, abi, provider);
678680
} else {
681+
679682
if (!context.resolverAddress) {
680683
const priceFeedContract = (context as LitContractContext).PriceFeed;
681684

@@ -934,6 +937,12 @@ export class LitContracts {
934937
environment
935938
);
936939
break;
940+
case 'PriceFeed':
941+
address = await resolverContract['getContract'](
942+
await resolverContract['PRICE_FEED_CONTRACT'](),
943+
environment
944+
);
945+
break;
937946
}
938947

939948
return address;
@@ -1043,6 +1052,11 @@ export class LitContracts {
10431052
addresses.Multisender.address = contract.address;
10441053
addresses.Multisender.abi = contract?.abi ?? MultisenderData.abi;
10451054
break;
1055+
case 'PriceFeed':
1056+
addresses.PriceFeed = {};
1057+
addresses.PriceFeed.address = contract.address;
1058+
addresses.PriceFeed.abi = contract?.abi;
1059+
break;
10461060
}
10471061
}
10481062

@@ -1150,6 +1164,7 @@ export class LitContracts {
11501164
bootstrapUrls: string[];
11511165
priceByNetwork: Record<string, number>;
11521166
}> => {
1167+
11531168
// if it's true, we will sort the networks by price feed from lowest to highest
11541169
// if it's false, we will not sort the networks
11551170
let _sortByPrice = sortByPrice || true;
@@ -1166,7 +1181,7 @@ export class LitContracts {
11661181
rpcUrl
11671182
);
11681183

1169-
// this will be dynamically set see https://github.com/LIT-Protocol/js-sdk/pull/724
1184+
// this will be dynamically set see
11701185
const realmId = 1;
11711186
const [epochInfo, minNodeCount, activeUnkickedValidatorStructs] =
11721187
await stakingContract['getActiveUnkickedValidatorStructsAndCounts'](realmId);
@@ -1212,12 +1227,12 @@ export class LitContracts {
12121227
// networks are all the nodes we know from the `getActiveUnkickedValidatorStructsAndCounts` function, but we also want to sort it by price feed
12131228
// which we need to call the price feed contract
12141229
const priceFeedInfo = await LitContracts.getPriceFeedInfo({
1230+
realmId,
12151231
litNetwork,
12161232
networkContext,
12171233
rpcUrl,
12181234
nodeProtocol,
12191235
});
1220-
12211236
// example of Network to Price Map: {
12221237
// 'http://xxx:7470': 100, <-- lowest price
12231238
// 'http://yyy:7471': 300, <-- highest price
@@ -1266,11 +1281,13 @@ export class LitContracts {
12661281
* }>}
12671282
*/
12681283
public static getPriceFeedInfo = async ({
1284+
realmId,
12691285
litNetwork,
12701286
networkContext,
12711287
rpcUrl,
12721288
productIds, // Array of product IDs
12731289
}: {
1290+
realmId: number;
12741291
litNetwork: LIT_NETWORKS_KEYS;
12751292
networkContext?: LitContractContext | LitContractResolverContext;
12761293
rpcUrl?: string;
@@ -1298,8 +1315,9 @@ export class LitContracts {
12981315
networkContext,
12991316
rpcUrl
13001317
);
1301-
1318+
console.log("priceFeedContract:", priceFeedContract);
13021319
const nodesForRequest = await priceFeedContract['getNodesForRequest'](
1320+
realmId,
13031321
productIds
13041322
);
13051323

0 commit comments

Comments
 (0)