@@ -4,11 +4,7 @@ import { type Result } from "@hyperlane-xyz/utils";
44
55import { 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" ;
128import { Erc20__factory } from "../../typechain/factories/contracts/Erc20__factory.js" ;
139import { EcoAdapter__factory } from "../../typechain/factories/eco/contracts/EcoAdapter__factory.js" ;
1410import { BaseFiller } from "../BaseFiller.js" ;
@@ -17,19 +13,28 @@ import { allowBlockLists, metadata } from "./config/index.js";
1713import type { EcoMetadata , IntentData , ParsedArgs } from "./types.js" ;
1814import { 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 (
0 commit comments