-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc46522
feat: check for accounting approval modules
0xyaco 04e4ca8
refactor: simplify typing
0xyaco fcad3d5
Merge remote-tracking branch 'origin/dev' into feat/accounting-module…
0xyaco ea3c9b2
fix: remove unneeded abi data
0xyaco 585230a
Merge remote-tracking branch 'origin/dev' into feat/accounting-module…
0xyaco d3a6e68
fix: agent imports from packages instead of dist
0xyaco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1,125 changes: 0 additions & 1,125 deletions
1,125
packages/automated-dispute/src/abis/bondEscalationModule.ts
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/automated-dispute/src/exceptions/eboProcessor/index.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 +1,2 @@ | ||
export * from "./pendingModulesApproval.exception.js"; | ||
export * from "./processorAlreadyStarted.exception.js"; |
21 changes: 21 additions & 0 deletions
21
packages/automated-dispute/src/exceptions/eboProcessor/pendingModulesApproval.exception.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 |
---|---|---|
@@ -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}`, | ||
); | ||
} | ||
} |
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 +1,3 @@ | ||
export { EboProcessor, EboActorsManager } from "./services/index.js"; | ||
export { ProtocolProvider } from "./providers/index.js"; | ||
export type { AccountingModules } from "./types/index.js"; |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -3,11 +3,22 @@ import { BlockNumberService } from "@ebo-agent/blocknumber"; | |||||
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js"; | ||||||
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 { | ||||||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Totally! Already did it in #49 's latest commit