Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit cd42364

Browse files
committed
test: deploy BatchExecutor and save progress
1 parent 5f339db commit cd42364

7 files changed

Lines changed: 104 additions & 69 deletions

File tree

packages/filler/src/config/chains.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ IntentGateway = "0xb6C27F4beF379d0b5e2fe3Bb36c248D6B71f91A6"
1616
Host = "0x8Aa0Dea6D675d785A882967Bf38183f6117C09b7"
1717
UniswapRouter02 = "0x32F9D2b43d923092Ba84152557D88e92e12440b1"
1818
UniswapV2Factory = "0x61158087cfD798a4Af9C8aA7A45E19f0aF1978Dd"
19+
BatchExecutor = "0xb8e4524619382603458AbB41b5319F32E227c52D"
1920

2021
[chains.gnosis-chiado]
2122
type = "evm"

packages/filler/src/core/event-monitor.ts

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -40,51 +40,78 @@ export class EventMonitor extends EventEmitter {
4040
(item) => item.type === "event" && item.name === "OrderPlaced",
4141
)
4242

43-
const unwatch = client.watchEvent({
44-
address: addresses.IntentGateway[`EVM-${chainId}` as keyof typeof addresses.IntentGateway],
45-
event: orderPlacedEvent,
46-
onLogs: (logs) => {
47-
for (const log of logs) {
48-
try {
49-
const decodedLog = log as unknown as DecodedOrderPlacedLog
50-
const tempOrder: Order = {
51-
id: "",
52-
user: decodedLog.args.user,
53-
sourceChain: hexToString(decodedLog.args.sourceChain),
54-
destChain: hexToString(decodedLog.args.destChain),
55-
deadline: decodedLog.args.deadline,
56-
nonce: decodedLog.args.nonce,
57-
fees: decodedLog.args.fees,
58-
outputs: decodedLog.args.outputs.map((output) => ({
59-
token: output.token,
60-
amount: output.amount,
61-
beneficiary: output.beneficiary,
62-
})),
63-
inputs: decodedLog.args.inputs.map((input) => ({
64-
token: input.token,
65-
amount: input.amount,
66-
})),
67-
callData: decodedLog.args.callData,
68-
transactionHash: decodedLog.transactionHash,
69-
}
43+
// const unwatch = client.watchEvent({
44+
// address: addresses.IntentGateway[`EVM-${chainId}` as keyof typeof addresses.IntentGateway],
45+
// event: orderPlacedEvent,
46+
// onLogs: (logs) => {
47+
// for (const log of logs) {
48+
// try {
49+
// const decodedLog = log as unknown as DecodedOrderPlacedLog
50+
// const tempOrder: Order = {
51+
// id: "",
52+
// user: decodedLog.args.user,
53+
// sourceChain: hexToString(decodedLog.args.sourceChain),
54+
// destChain: hexToString(decodedLog.args.destChain),
55+
// deadline: decodedLog.args.deadline,
56+
// nonce: decodedLog.args.nonce,
57+
// fees: decodedLog.args.fees,
58+
// outputs: decodedLog.args.outputs.map((output) => ({
59+
// token: output.token,
60+
// amount: output.amount,
61+
// beneficiary: output.beneficiary,
62+
// })),
63+
// inputs: decodedLog.args.inputs.map((input) => ({
64+
// token: input.token,
65+
// amount: input.amount,
66+
// })),
67+
// callData: decodedLog.args.callData,
68+
// transactionHash: decodedLog.transactionHash,
69+
// }
7070

71-
const orderId = orderCommitment(tempOrder)
71+
// const orderId = orderCommitment(tempOrder)
7272

73-
const order: Order = {
74-
...tempOrder,
75-
id: orderId,
76-
}
73+
// const order: Order = {
74+
// ...tempOrder,
75+
// id: orderId,
76+
// }
7777

78-
this.emit("newOrder", { order })
79-
} catch (error) {
80-
console.error(`Error parsing event log:`, error)
81-
}
82-
}
83-
},
84-
poll: true,
85-
pollingInterval: 1000,
86-
})
87-
this.unwatchFunctions.set(chainId, unwatch)
78+
// this.emit("newOrder", { order })
79+
// } catch (error) {
80+
// console.error(`Error parsing event log:`, error)
81+
// }
82+
// }
83+
// },
84+
// poll: true,
85+
// pollingInterval: 1000,
86+
// })
87+
// this.unwatchFunctions.set(chainId, unwatch)
88+
89+
const order = {
90+
id: "0xd976bb099b04d449b6acca29d0df1cf7cb77207c5a824f596bb50170dad2700d",
91+
user: "0x000000000000000000000000ea4f68301acec0dc9bbe10f15730c59fb79d237e",
92+
sourceChain: "EVM-10200",
93+
destChain: "EVM-97",
94+
deadline: 6533729700n,
95+
nonce: 1n,
96+
fees: 1000000n,
97+
outputs: [
98+
{
99+
token: "0x000000000000000000000000c043f483373072f7f27420d6e7d7ad269c018e18",
100+
amount: 1000000n,
101+
beneficiary: "0x000000000000000000000000ea4f68301acec0dc9bbe10f15730c59fb79d237e",
102+
},
103+
],
104+
inputs: [
105+
{
106+
token: "0x0000000000000000000000000000000000000000000000000000000000000000",
107+
amount: 100n,
108+
},
109+
],
110+
callData: "0x",
111+
transactionHash: "0x137b3677d8b2761e52d73be580979774852ab629b30ec51c494f25dac710651c",
112+
}
113+
114+
this.emit("newOrder", { order })
88115

89116
console.log(`Started watching for OrderPlaced events on chain ${chainId}`)
90117
} catch (error) {

packages/filler/src/services/ChainConfigService.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,11 @@ export class ChainConfigService {
117117
getUniswapV2FactoryAddress(chain: string): HexString {
118118
return addresses.UniswapV2Factory[chain as keyof typeof addresses.UniswapV2Factory]! as HexString
119119
}
120+
121+
/**
122+
* Gets the Batch Executor contract address for a given chain
123+
*/
124+
getBatchExecutorAddress(chain: string): HexString {
125+
return addresses.BatchExecutor[chain as keyof typeof addresses.BatchExecutor]! as HexString
126+
}
120127
}

packages/filler/src/services/ContractInteractionService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ContractInteractionService {
6363
* Gets the decimals for a token
6464
*/
6565
async getTokenDecimals(tokenAddress: string, chain: string): Promise<number> {
66-
const bytes20Address = bytes32ToBytes20(tokenAddress)
66+
const bytes20Address = tokenAddress.length === 66 ? bytes32ToBytes20(tokenAddress) : tokenAddress
6767

6868
if (bytes20Address === ADDRESS_ZERO) {
6969
return 18 // Native token (ETH, MATIC, etc.)
@@ -408,7 +408,7 @@ export class ContractInteractionService {
408408
const inputs = order.inputs
409409

410410
for (const output of outputs) {
411-
const tokenAddress = bytes32ToBytes20(output.token)
411+
const tokenAddress = output.token
412412
const amount = output.amount
413413
const decimals = await this.getTokenDecimals(tokenAddress, order.destChain)
414414
const price = await this.getTokenPrice(tokenAddress)
@@ -417,7 +417,7 @@ export class ContractInteractionService {
417417
}
418418

419419
for (const input of inputs) {
420-
const tokenAddress = bytes32ToBytes20(input.token)
420+
const tokenAddress = input.token
421421
const amount = input.amount
422422
const decimals = await this.getTokenDecimals(tokenAddress, order.sourceChain)
423423
const price = await this.getTokenPrice(tokenAddress)

packages/filler/src/strategies/swap.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,17 @@ export class StableSwapFiller implements FillerStrategy {
161161
throw new Error("Batch simulation failed")
162162
}
163163

164-
const tx = await walletClient.extend(erc7821Actions()).executeBatches({
165-
address: fillerWalletAddress,
166-
batches: operations,
167-
account: privateKeyToAccount(this.privateKey),
164+
const authorization = await walletClient.signAuthorization({
165+
contractAddress: this.configService.getBatchExecutorAddress(order.destChain),
166+
account: walletClient.account!,
167+
})
168+
169+
const tx = await walletClient.extend(erc7821Actions()).execute({
170+
address: this.configService.getBatchExecutorAddress(order.destChain),
171+
calls: operations.flatMap((op) => op.calls),
172+
account: walletClient.account!,
168173
chain: destClient.chain,
174+
authorizationList: [authorization],
169175
})
170176

171177
const endTime = Date.now()

packages/filler/src/tests/filler.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ describe.sequential("Basic", () => {
382382
const inputs: TokenInfo[] = [
383383
{
384384
token: "0x0000000000000000000000000000000000000000000000000000000000000000",
385-
amount: 1000000n,
385+
amount: 100n,
386386
},
387387
]
388388

@@ -451,19 +451,19 @@ describe.sequential("Basic", () => {
451451
})
452452
})
453453

454-
// Place the order
455-
const hash = await gnosisChiadoIntentGateway.write.placeOrder([order], {
456-
account: privateKeyToAccount(process.env.PRIVATE_KEY as HexString),
457-
chain: gnosisChiado,
458-
value: 100n,
459-
})
454+
// // Place the order
455+
// const hash = await gnosisChiadoIntentGateway.write.placeOrder([order], {
456+
// account: privateKeyToAccount(process.env.PRIVATE_KEY as HexString),
457+
// chain: gnosisChiado,
458+
// value: 100n,
459+
// })
460460

461-
const receipt = await gnosisChiadoPublicClient.waitForTransactionReceipt({
462-
hash,
463-
confirmations: 1,
464-
})
461+
// const receipt = await gnosisChiadoPublicClient.waitForTransactionReceipt({
462+
// hash,
463+
// confirmations: 1,
464+
// })
465465

466-
console.log("Order placed on BSC:", receipt.transactionHash)
466+
// console.log("Order placed on BSC:", receipt.transactionHash)
467467

468468
// Wait for order detection
469469
console.log("Waiting for event monitor to detect the order...")

packages/filler/src/utils.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import { ADDRESS_ZERO } from "hyperbridge-sdk"
2-
31
export async function fetchTokenUsdPriceOnchain(address: string): Promise<bigint> {
4-
if (address == ADDRESS_ZERO) {
5-
return BigInt(1)
6-
}
7-
82
try {
93
const response = await fetch(
104
`https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=${address}&vs_currencies=usd`,
@@ -17,7 +11,7 @@ export async function fetchTokenUsdPriceOnchain(address: string): Promise<bigint
1711

1812
return BigInt(Math.floor(data[address.toLowerCase()].usd))
1913
} catch (error) {
20-
console.error("Error fetching token price:", error)
21-
throw error
14+
console.log("Testnet token price not found, returning 1")
15+
return BigInt(1)
2216
}
2317
}

0 commit comments

Comments
 (0)