Skip to content

Commit

Permalink
fix: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Oct 16, 2024
1 parent dd1a3c8 commit afba646
Show file tree
Hide file tree
Showing 18 changed files with 344 additions and 396 deletions.
5 changes: 5 additions & 0 deletions packages/chain-providers/src/providers/evmProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
fallback,
FallbackTransport,
GetBlockReturnType,
GetTransactionReturnType,
Hex,
http,
HttpTransport,
Expand Down Expand Up @@ -65,6 +66,10 @@ export class EvmProvider {
return this.chain?.contracts?.multicall3?.address;
}

async getTransaction(hash: Hex): Promise<GetTransactionReturnType> {
return this.client.getTransaction({ hash });
}

/**
* Retrieves the balance of the specified address.
* @param {Address} address The address for which to retrieve the balance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { arrayAbiFixture, structAbiFixture } from "../../fixtures/batchRequest.fixture.js";

const mockClient = {
getTransaction: vi.fn(),
getBalance: vi.fn(),
getBlockNumber: vi.fn(),
getGasPrice: vi.fn(),
Expand Down Expand Up @@ -70,6 +71,20 @@ describe("EvmProvider", () => {
}).toThrowError(RpcUrlsEmpty);
});

describe("getTransaction", () => {
it("returns the transaction for the given hash", async () => {
viemProvider = new EvmProvider(defaultRpcUrls, defaultMockChain, mockLogger);
const hash = "0x123456789";
const expectedTransaction = { from: "0x123456789", to: "0x987654321" };
vi.spyOn(mockClient, "getTransaction").mockResolvedValue(expectedTransaction);

const transaction = await viemProvider.getTransaction(hash);

expect(transaction).toBe(expectedTransaction);
expect(mockClient.getTransaction).toHaveBeenCalledWith({ hash });
});
});

describe("getBalance", () => {
it("returns the balance of the specified address", async () => {
viemProvider = new EvmProvider(defaultRpcUrls, defaultMockChain, mockLogger);
Expand Down
1 change: 1 addition & 0 deletions packages/processors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"test:cov": "vitest run --config vitest.config.ts --coverage"
},
"dependencies": {
"@grants-stack-indexer/chain-providers": "workspace:*",
"@grants-stack-indexer/metadata": "workspace:*",
"@grants-stack-indexer/pricing": "workspace:*",
"@grants-stack-indexer/repository": "workspace:*",
Expand Down
22 changes: 7 additions & 15 deletions packages/processors/src/allo/allo.processor.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
import { Chain, PublicClient, Transport } from "viem";

import type { IMetadataProvider } from "@grants-stack-indexer/metadata";
import type { IPricingProvider } from "@grants-stack-indexer/pricing";
import { Changeset, IRoundReadRepository } from "@grants-stack-indexer/repository";
import { Changeset } from "@grants-stack-indexer/repository";
import { AlloEvent, ChainId, ProtocolEvent } from "@grants-stack-indexer/shared";

import type { IProcessor } from "../internal.js";
import type { IProcessor, ProcessorDependencies } from "../internal.js";
import { PoolCreatedHandler } from "./handlers/index.js";

export class AlloProcessor implements IProcessor<"Allo", AlloEvent> {
constructor(
private readonly chainId: ChainId,
//TODO: replace with provider abstraction
private readonly viemClient: PublicClient<Transport, Chain>,
private readonly pricingProvider: IPricingProvider,
private readonly metadataProvider: IMetadataProvider,
private readonly roundRepository: IRoundReadRepository,
private readonly dependencies: ProcessorDependencies,
) {}

async process(event: ProtocolEvent<"Allo", AlloEvent>): Promise<Changeset[]> {
switch (event.eventName) {
case "PoolCreated":
return new PoolCreatedHandler(event, this.chainId, {
viemClient: this.viemClient,
pricingProvider: this.pricingProvider,
metadataProvider: this.metadataProvider,
roundRepository: this.roundRepository,
evmProvider: this.dependencies.evmProvider,
pricingProvider: this.dependencies.pricingProvider,
metadataProvider: this.dependencies.metadataProvider,
roundRepository: this.dependencies.roundRepository,
}).handle();
default:
throw new Error(`Unknown event name: ${event.eventName}`);
Expand Down
Loading

0 comments on commit afba646

Please sign in to comment.