Skip to content

Commit

Permalink
fix, test: chainId to RPC map
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Nov 26, 2024
1 parent 5b67b06 commit cb0fd03
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
12 changes: 6 additions & 6 deletions lib/handlers/hard-quote/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ export class QuoteHandler extends APIGLambdaHandler<
metric.putMetric(Metric.QUOTE_REQUESTED, 1, MetricLoggerUnit.Count);

const provider = chainIdRpcMap.get(requestBody.tokenInChainId);
if (!provider)
throw new Error(
`No rpc provider found for chain: ${requestBody.tokenInChainId}`
);

const orderParser = new UniswapXOrderParser();
const orderType: OrderType = orderParser.getOrderTypeFromEncoded(
Expand Down Expand Up @@ -230,7 +226,7 @@ export function getCosignerData(
export async function getDefaultCosignerData(
request: HardQuoteRequest,
orderType: OrderType,
provider: ethers.providers.Provider
provider: ethers.providers.JsonRpcProvider | undefined
): Promise<CosignerData | V3CosignerData> {
switch (orderType) {
case OrderType.Dutch_V2:
Expand Down Expand Up @@ -316,7 +312,11 @@ function getDefaultV2CosignerData(request: HardQuoteRequest): CosignerData {
};
}

async function getDefaultV3CosignerData(request: HardQuoteRequest, provider: ethers.providers.Provider): Promise<V3CosignerData> {
async function getDefaultV3CosignerData(request: HardQuoteRequest, provider: ethers.providers.JsonRpcProvider | undefined): Promise<V3CosignerData> {
if (!provider)
throw new Error(
`No rpc provider found for chain: ${request.tokenInChainId}, which is required for V3 Dutch orders`
);
const currentBlock = await provider.getBlockNumber();

return {
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/hard-quote/injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ export class QuoteInjector extends ApiInjector<ContainerInjected, RequestInjecte
new WebhookQuoter(log, firehose, webhookProvider, circuitBreakerProvider, fillerComplianceProvider, repository),
];

const chainIdRpcMap = new Map<ChainId, ethers.providers.StaticJsonRpcProvider>();
const chainIdRpcMap = new Map<ChainId, ethers.providers.JsonRpcProvider>();
supportedChains.forEach(
chainId => {
const rpcUrl = checkDefined(
process.env[`RPC_${chainId}`],
`RPC_${chainId} is not defined`
);
const provider = new ethers.providers.StaticJsonRpcProvider(rpcUrl, chainId); // specify chainId to avoid detecctNetwork() call on initialization
const provider = new ethers.providers.JsonRpcProvider(rpcUrl, chainId);
chainIdRpcMap.set(chainId, provider);
}
);
Expand Down
4 changes: 4 additions & 0 deletions test/handlers/hard-quote/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ describe('Quote handler', () => {
return {
quoters,
orderServiceProvider: new MockOrderServiceProvider(),
// Mock chainIdRpcMap
chainIdRpcMap: new Map([
[42161, new ethers.providers.StaticJsonRpcProvider()],
]),
};
},
getRequestInjected: () => requestInjectedMock,
Expand Down
4 changes: 4 additions & 0 deletions test/handlers/hard-quote/handlerDutchV3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ describe('Quote handler', () => {
return {
quoters,
orderServiceProvider: new MockOrderServiceProvider(),
// Mock chainIdRpcMap
chainIdRpcMap: new Map([
[42161, new ethers.providers.StaticJsonRpcProvider()],
]),
};
},
getRequestInjected: () => requestInjectedMock,
Expand Down

0 comments on commit cb0fd03

Please sign in to comment.