Skip to content

Commit ccb284d

Browse files
committed
refactor(eco): modify eco to support BaseFiller
1 parent 9c96d88 commit ccb284d

File tree

3 files changed

+65
-72
lines changed

3 files changed

+65
-72
lines changed

typescript/solver/solvers/eco/filler.ts

Lines changed: 47 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { type Result } from "@hyperlane-xyz/utils";
44

55
import { type BigNumber } from "ethers";
66

7-
import {
8-
chainIds,
9-
chainIdsToName,
10-
isAllowedIntent,
11-
} from "../../config/index.js";
7+
import { chainIds, chainIdsToName } from "../../config/index.js";
128
import { Erc20__factory } from "../../typechain/factories/contracts/Erc20__factory.js";
139
import { EcoAdapter__factory } from "../../typechain/factories/eco/contracts/EcoAdapter__factory.js";
1410
import { BaseFiller } from "../BaseFiller.js";
@@ -17,19 +13,28 @@ import { allowBlockLists, metadata } from "./config/index.js";
1713
import type { EcoMetadata, IntentData, ParsedArgs } from "./types.js";
1814
import { log, withdrawRewards } from "./utils.js";
1915

20-
export class EcoFiller extends BaseFiller<
21-
{
22-
adapters: EcoMetadata["adapters"];
23-
protocolName: EcoMetadata["protocolName"];
24-
},
25-
ParsedArgs,
26-
IntentData
27-
> {
16+
type Metadata = {
17+
adapters: { [chainId: string]: EcoMetadata["adapters"][number] };
18+
protocolName: EcoMetadata["protocolName"];
19+
};
20+
21+
export class EcoFiller extends BaseFiller<Metadata, ParsedArgs, IntentData> {
2822
constructor(multiProvider: MultiProvider) {
2923
const { adapters, protocolName } = metadata;
30-
const ecoFillerMetadata = { adapters, protocolName };
31-
32-
super(multiProvider, ecoFillerMetadata, log);
24+
const ecoFillerMetadata = {
25+
adapters: adapters.reduce<{
26+
[chainId: string]: EcoMetadata["adapters"][number];
27+
}>(
28+
(acc, adapter) => ({
29+
...acc,
30+
[chainIds[adapter.chainName]]: adapter,
31+
}),
32+
{},
33+
),
34+
protocolName,
35+
};
36+
37+
super(multiProvider, allowBlockLists, ecoFillerMetadata, log);
3338
}
3439

3540
protected retrieveOriginInfo(parsedArgs: ParsedArgs, chainName: string) {
@@ -53,7 +58,7 @@ export class EcoFiller extends BaseFiller<
5358
const [, amount] = erc20Interface.decodeFunctionData(
5459
"transfer",
5560
parsedArgs._data[index],
56-
) as [string, BigNumber];
61+
) as [unknown, BigNumber];
5762

5863
return { amount, chainName, tokenAddress };
5964
});
@@ -67,69 +72,39 @@ export class EcoFiller extends BaseFiller<
6772
protected async prepareIntent(
6873
parsedArgs: ParsedArgs,
6974
): Promise<Result<IntentData>> {
70-
this.log.info({
71-
msg: "Evaluating filling Intent",
72-
intent: `${this.metadata.protocolName}-${parsedArgs._hash}`,
73-
});
75+
const adapter =
76+
this.metadata.adapters[parsedArgs._destinationChain.toString()];
7477

75-
try {
76-
const destinationChainId = parsedArgs._destinationChain.toNumber();
77-
const adapter = this.metadata.adapters.find(
78-
({ chainName }) => chainIds[chainName] === destinationChainId,
79-
);
78+
if (!adapter) {
79+
return {
80+
error: "No adapter found for destination chain",
81+
success: false,
82+
};
83+
}
8084

81-
if (!adapter) {
82-
return {
83-
error: "No adapter found for destination chain",
84-
success: false,
85-
};
86-
}
85+
await super.prepareIntent(parsedArgs);
8786

88-
const signer = this.multiProvider.getSigner(destinationChainId);
87+
try {
8988
const erc20Interface = Erc20__factory.createInterface();
9089

91-
const { requiredAmountsByTarget, receivers } =
92-
parsedArgs._targets.reduce<{
93-
requiredAmountsByTarget: { [tokenAddress: string]: BigNumber };
94-
receivers: string[];
95-
}>(
96-
(acc, target, index) => {
97-
const [receiver, amount] = erc20Interface.decodeFunctionData(
98-
"transfer",
99-
parsedArgs._data[index],
100-
) as [string, BigNumber];
90+
const requiredAmountsByTarget = parsedArgs._targets.reduce<{
91+
[tokenAddress: string]: BigNumber;
92+
}>((acc, target, index) => {
93+
const [, amount] = erc20Interface.decodeFunctionData(
94+
"transfer",
95+
parsedArgs._data[index],
96+
) as [unknown, BigNumber];
10197

102-
acc.requiredAmountsByTarget[target] ||= Zero;
103-
acc.requiredAmountsByTarget[target] =
104-
acc.requiredAmountsByTarget[target].add(amount);
98+
acc[target] ||= Zero;
99+
acc[target] = acc[target].add(amount);
105100

106-
acc.receivers.push(receiver);
101+
return acc;
102+
}, {});
107103

108-
return acc;
109-
},
110-
{
111-
requiredAmountsByTarget: {},
112-
receivers: [],
113-
},
114-
);
115-
116-
if (
117-
!receivers.every((recipientAddress) =>
118-
isAllowedIntent(allowBlockLists, {
119-
senderAddress: parsedArgs._creator,
120-
destinationDomain: chainIdsToName[destinationChainId.toString()],
121-
recipientAddress,
122-
}),
123-
)
124-
) {
125-
return {
126-
error: "Not allowed intent",
127-
success: false,
128-
};
129-
}
130-
131-
const fillerAddress =
132-
await this.multiProvider.getSignerAddress(destinationChainId);
104+
const fillerAddress = await this.multiProvider.getSignerAddress(
105+
adapter.chainName,
106+
);
107+
const signer = this.multiProvider.getSigner(adapter.chainName);
133108

134109
const areTargetFundsAvailable = await Promise.all(
135110
Object.entries(requiredAmountsByTarget).map(

typescript/solver/solvers/eco/listener.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { chainIdsToName } from "../../config/index.js";
12
import type { TypedListener } from "../../typechain/common.js";
23
import type {
34
IntentCreatedEvent,
45
IntentSource,
56
} from "../../typechain/eco/contracts/IntentSource.js";
7+
import { Erc20__factory } from "../../typechain/factories/contracts/Erc20__factory.js";
68
import { IntentSource__factory } from "../../typechain/factories/eco/contracts/IntentSource__factory.js";
79
import { BaseListener } from "../BaseListener.js";
810
import { metadata } from "./config/index.js";
@@ -33,8 +35,19 @@ export class EcoListener extends BaseListener<
3335
nonce,
3436
_prover,
3537
]: Parameters<TypedListener<IntentCreatedEvent>>) {
38+
const destinationChainName = chainIdsToName[_destinationChain.toString()];
39+
const erc20Interface = Erc20__factory.createInterface();
40+
3641
return {
3742
orderId: _hash,
43+
senderAddress: _creator,
44+
recipients: _data.map((data) => {
45+
const [recipientAddress] = erc20Interface.decodeFunctionData(
46+
"transfer",
47+
data,
48+
) as [string];
49+
return { destinationChainName, recipientAddress };
50+
}),
3851
_hash,
3952
_creator,
4053
_destinationChain,

typescript/solver/solvers/eco/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,9 @@ export type IntentData = { adapter: EcoMetadata["adapters"][number] };
2828

2929
export type ParsedArgs = IntentCreatedEventObject & {
3030
orderId: string;
31+
senderAddress: IntentCreatedEventObject["_creator"];
32+
recipients: Array<{
33+
destinationChainName: string;
34+
recipientAddress: string;
35+
}>;
3136
};

0 commit comments

Comments
 (0)