-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: check for accounting approval modules #44
Changes from 4 commits
fc46522
04e4ca8
fcad3d5
ea3c9b2
585230a
d3a6e68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./pendingModulesApproval.exception.js"; | ||
export * from "./processorAlreadyStarted.exception.js"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { AccountingModules } from "../../types/index.js"; | ||
|
||
export class PendingModulesApproval extends Error { | ||
constructor( | ||
public readonly approvedModules: Partial<AccountingModules>, | ||
public readonly pendingModules: Partial<AccountingModules>, | ||
) { | ||
const approvedModulesStr = Object.entries(approvedModules) | ||
.map(([key, value]) => `(${key}: ${value})`) | ||
.join(", "); | ||
|
||
const pendingModulesStr = Object.entries(pendingModules) | ||
.map(([key, value]) => `(${key}: ${value})`) | ||
.join(", "); | ||
|
||
super( | ||
`Modules approved: ${approvedModulesStr}\n` + | ||
`Modules pending approval: ${pendingModulesStr}`, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,11 +3,22 @@ import { BlockNumberService } from "@ebo-agent/blocknumber"; | |||||
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this isn't in your PR but we should clean up these dist imports eventually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Totally! Already did it in #49 's latest commit |
||||||
import { Address, EBO_SUPPORTED_CHAIN_IDS, ILogger } from "@ebo-agent/shared"; | ||||||
|
||||||
import { ProcessorAlreadyStarted } from "../exceptions/index.js"; | ||||||
import { PendingModulesApproval, ProcessorAlreadyStarted } from "../exceptions/index.js"; | ||||||
import { isRequestCreatedEvent } from "../guards.js"; | ||||||
import { ProtocolProvider } from "../providers/protocolProvider.js"; | ||||||
import { alreadyDeletedActorWarning, droppingUnhandledEventsWarning } from "../templates/index.js"; | ||||||
import { ActorRequest, EboEvent, EboEventName, Epoch, RequestId } from "../types/index.js"; | ||||||
import { | ||||||
alreadyDeletedActorWarning, | ||||||
droppingUnhandledEventsWarning, | ||||||
pendingApprovedModulesError, | ||||||
} from "../templates/index.js"; | ||||||
import { | ||||||
AccountingModules, | ||||||
ActorRequest, | ||||||
EboEvent, | ||||||
EboEventName, | ||||||
Epoch, | ||||||
RequestId, | ||||||
} from "../types/index.js"; | ||||||
import { EboActorsManager } from "./eboActorsManager.js"; | ||||||
|
||||||
const DEFAULT_MS_BETWEEN_CHECKS = 10 * 60 * 1000; // 10 minutes | ||||||
|
@@ -19,6 +30,7 @@ export class EboProcessor { | |||||
private lastCheckedBlock?: bigint; | ||||||
|
||||||
constructor( | ||||||
private readonly accountingModules: AccountingModules, | ||||||
private readonly protocolProvider: ProtocolProvider, | ||||||
private readonly blockNumberService: BlockNumberService, | ||||||
private readonly actorsManager: EboActorsManager, | ||||||
|
@@ -33,6 +45,8 @@ export class EboProcessor { | |||||
public async start(msBetweenChecks: number = DEFAULT_MS_BETWEEN_CHECKS) { | ||||||
if (this.eventsInterval) throw new ProcessorAlreadyStarted(); | ||||||
|
||||||
await this.checkAllModulesApproved(); | ||||||
|
||||||
await this.sync(); // Bootstrapping | ||||||
|
||||||
this.eventsInterval = setInterval(async () => { | ||||||
|
@@ -48,6 +62,42 @@ export class EboProcessor { | |||||
}, msBetweenChecks); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Check if all the modules have been granted approval within the accounting module. | ||||||
* | ||||||
* @throws {PendingModulesApproval} when there is at least one module pending approval | ||||||
*/ | ||||||
private async checkAllModulesApproved() { | ||||||
const approvedModules: Address[] = | ||||||
await this.protocolProvider.getAccountingApprovedModules(); | ||||||
|
||||||
const summary: Record<"approved" | "notApproved", Partial<AccountingModules>> = { | ||||||
approved: {}, | ||||||
notApproved: {}, | ||||||
}; | ||||||
|
||||||
for (const [moduleName, moduleAddress] of Object.entries(this.accountingModules)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You can do it this way also, just to let you know, not requesting any changes here 🤣 |
||||||
const isApproved = approvedModules.includes(moduleAddress); | ||||||
const key = isApproved ? "approved" : "notApproved"; | ||||||
|
||||||
summary[key][moduleName as keyof AccountingModules] = moduleAddress; | ||||||
} | ||||||
|
||||||
if (Object.keys(summary.notApproved).length > 0) { | ||||||
const accountingModuleAddress = this.protocolProvider.getAccountingModuleAddress(); | ||||||
|
||||||
this.logger.error( | ||||||
pendingApprovedModulesError( | ||||||
accountingModuleAddress, | ||||||
summary["approved"], | ||||||
summary["notApproved"], | ||||||
), | ||||||
); | ||||||
|
||||||
throw new PendingModulesApproval(summary["approved"], summary["notApproved"]); | ||||||
} | ||||||
} | ||||||
|
||||||
/** Sync new blocks and their events with their corresponding actors. */ | ||||||
private async sync() { | ||||||
try { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dist
is pointing to the code that has been built ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥴