Skip to content

Commit 9c96d88

Browse files
committed
refactor(solvers): move common logic into BaseFiller class
1 parent 3d7d103 commit 9c96d88

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

typescript/solver/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export { LOG_FORMAT, LOG_LEVEL, MNEMONIC, PRIVATE_KEY };
1515

1616
type GenericAllowBlockListItem = z.infer<typeof ConfigSchema>;
1717

18-
type GenericAllowBlockLists = {
18+
export type GenericAllowBlockLists = {
1919
allowList: GenericAllowBlockListItem[];
2020
blockList: GenericAllowBlockListItem[];
2121
};

typescript/solver/solvers/BaseFiller.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import type { MultiProvider } from "@hyperlane-xyz/sdk";
22
import type { Result } from "@hyperlane-xyz/utils";
3+
import {
4+
type GenericAllowBlockLists,
5+
isAllowedIntent,
6+
} from "../config/index.js";
37
import type { Logger } from "../logger.js";
48

59
type Metadata = {
@@ -8,6 +12,11 @@ type Metadata = {
812

913
type ParsedArgs = {
1014
orderId: string;
15+
senderAddress: string;
16+
recipients: Array<{
17+
destinationChainName: string;
18+
recipientAddress: string;
19+
}>;
1120
};
1221

1322
export abstract class BaseFiller<
@@ -17,6 +26,7 @@ export abstract class BaseFiller<
1726
> {
1827
protected constructor(
1928
readonly multiProvider: MultiProvider,
29+
readonly allowBlockLists: GenericAllowBlockLists,
2030
readonly metadata: TMetadata,
2131
readonly log: Logger,
2232
) {}
@@ -57,9 +67,26 @@ export abstract class BaseFiller<
5767
parsedArgs: TParsedArgs,
5868
): Promise<Array<string>>;
5969

60-
protected abstract prepareIntent(
70+
protected async prepareIntent(
6171
parsedArgs: TParsedArgs,
62-
): Promise<Result<TIntentData>>;
72+
): Promise<Result<TIntentData>> {
73+
this.log.info({
74+
msg: "Evaluating filling Intent",
75+
intent: `${this.metadata.protocolName}-${parsedArgs.orderId}`,
76+
});
77+
78+
const { senderAddress, recipients } = parsedArgs;
79+
80+
if (!this.isAllowedIntent({ senderAddress, recipients })) {
81+
return {
82+
error: "Not allowed intent",
83+
success: false,
84+
};
85+
}
86+
87+
return { error: "Not implemented", success: false };
88+
}
89+
6390

6491
protected abstract fill(
6592
parsedArgs: TParsedArgs,
@@ -70,4 +97,23 @@ export abstract class BaseFiller<
7097
protected async settleOrder(parsedArgs: TParsedArgs, data: TIntentData) {
7198
return;
7299
}
100+
101+
protected isAllowedIntent({
102+
senderAddress,
103+
recipients,
104+
}: {
105+
senderAddress: string;
106+
recipients: Array<{
107+
destinationChainName: string;
108+
recipientAddress: string;
109+
}>;
110+
}) {
111+
return recipients.every(({ destinationChainName, recipientAddress }) =>
112+
isAllowedIntent(this.allowBlockLists, {
113+
senderAddress,
114+
destinationDomain: destinationChainName,
115+
recipientAddress,
116+
}),
117+
);
118+
}
73119
}

0 commit comments

Comments
 (0)