generated from defi-wonderland/ts-turborepo-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: persisting strategy registry into db (#40)
# 🤖 Linear Closes GIT-185 ## Description We want to persist `strategyId`s on `PoolCreated` events so we could later pre-process all of the past events when we implement in code a new Strategy Handler. - Create `StrategyRepository` to store seen strategyIds with their corresponding address and whether it was handled or not - `DBStrategyRegistry` that interfaces with the repo - a Proxied version that caches in memory and uses the `DBStrategyRegistry` (InMemoryCachedStrategyRegistry) - update Processing app to use the InMemoryCachedStrategyRegistry ## Checklist before requesting a review - [x] I have conducted a self-review of my code. - [x] I have conducted a QA. - [x] If it is a core feature, I have included comprehensive tests.
- Loading branch information
Showing
37 changed files
with
820 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 23 additions & 7 deletions
30
packages/data-flow/src/interfaces/strategyRegistry.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import { Address, Hex } from "viem"; | ||
|
||
import { Strategy } from "@grants-stack-indexer/repository"; | ||
import { ChainId } from "@grants-stack-indexer/shared"; | ||
|
||
/** | ||
* The strategy registry saves the mapping between the strategy address and the strategy id. Serves as a Cache | ||
* to avoid having to read from the chain to get the strategy id every time. | ||
*/ | ||
//TODO: implement a mechanism to record Strategy that we still don't have a corresponding handler | ||
// we need to store and mark that this strategy is not handled yet, so when it's supported we can process all of the pending events for it | ||
export interface IStrategyRegistry { | ||
/** | ||
* Get the strategy id by the strategy address | ||
* Get the strategy id by the strategy address and chain id | ||
* | ||
* @param chainId - The chain id | ||
* @param strategyAddress - The strategy address | ||
* @returns The strategy id or undefined if the strategy address is not registered | ||
* @returns The strategy or undefined if the strategy address is not registered | ||
*/ | ||
getStrategyId(strategyAddress: Address): Promise<Hex | undefined>; | ||
getStrategyId(chainId: ChainId, strategyAddress: Address): Promise<Strategy | undefined>; | ||
/** | ||
* Save the strategy id by the strategy address | ||
* Save the strategy id by the strategy address and chain id | ||
* @param chainId - The chain id | ||
* @param strategyAddress - The strategy address | ||
* @param strategyId - The strategy id | ||
* @param handled - Whether the strategy is handled | ||
*/ | ||
saveStrategyId( | ||
chainId: ChainId, | ||
strategyAddress: Address, | ||
strategyId: Hex, | ||
handled: boolean, | ||
): Promise<void>; | ||
|
||
/** | ||
* Get all the strategies | ||
* @returns The strategies | ||
*/ | ||
saveStrategyId(strategyAddress: Address, strategyId: Hex): Promise<void>; | ||
getStrategies(filters?: { handled?: boolean; chainId?: ChainId }): Promise<Strategy[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./strategy/index.js"; |
Oops, something went wrong.