From bad5458777d4f2893b32156cc3b3f6ead26f6b29 Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Mon, 24 Apr 2023 10:44:18 -0400 Subject: [PATCH 1/2] improve(SpokePool): Pass fillCompleted and relayer to acrossMessageHandler Signed-off-by: nicholaspai --- contracts/SpokePool.sol | 4 +++ contracts/test/AcrossMessageHandlerMock.sol | 2 ++ test/SpokePool.Relay.ts | 30 +++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/contracts/SpokePool.sol b/contracts/SpokePool.sol index cac520df0..0e1ffcbf0 100644 --- a/contracts/SpokePool.sol +++ b/contracts/SpokePool.sol @@ -20,6 +20,8 @@ interface AcrossMessageHandler { function handleAcrossMessage( address tokenSent, uint256 amount, + bool fillCompleted, + address relayer, bytes memory message ) external; } @@ -1244,6 +1246,8 @@ abstract contract SpokePool is AcrossMessageHandler(relayExecution.updatedRecipient).handleAcrossMessage( relayData.destinationToken, amountToSend, + relayFills[relayExecution.relayHash] >= relayData.amount, + msg.sender, relayExecution.updatedMessage ); } diff --git a/contracts/test/AcrossMessageHandlerMock.sol b/contracts/test/AcrossMessageHandlerMock.sol index cda26868c..d2a3a4367 100644 --- a/contracts/test/AcrossMessageHandlerMock.sol +++ b/contracts/test/AcrossMessageHandlerMock.sol @@ -7,6 +7,8 @@ contract AcrossMessageHandlerMock is AcrossMessageHandler { function handleAcrossMessage( address tokenSent, uint256 amount, + bool fillCompleted, + address relayer, bytes memory message ) external override {} } diff --git a/test/SpokePool.Relay.ts b/test/SpokePool.Relay.ts index 4414b9ab9..2233e2592 100644 --- a/test/SpokePool.Relay.ts +++ b/test/SpokePool.Relay.ts @@ -312,11 +312,37 @@ describe("SpokePool Relayer Logic", async function () { expect(acrossMessageHandler.handleAcrossMessage).to.have.been.calledOnceWith( weth.address, consts.amountToRelay, + false, + relayer.address, + "0x1234" + ); + }); + it("Handler is called with correct params", async function () { + const acrossMessageHandler = await createFake("AcrossMessageHandlerMock"); + const { relayData } = getRelayHash( + depositor.address, + acrossMessageHandler.address, + consts.firstDepositId, + consts.originChainId, + consts.destinationChainId, + weth.address, + undefined, + undefined, + undefined, "0x1234" ); - // The collateral should have not unwrapped to ETH and then transferred to recipient. - expect(await weth.balanceOf(acrossMessageHandler.address)).to.equal(consts.amountToRelay); + // Handler is called with full fill and relayer address. + await spokePool + .connect(depositor) + .fillRelay(...getFillRelayParams(relayData, relayData.amount, consts.destinationChainId)); + expect(acrossMessageHandler.handleAcrossMessage).to.have.been.calledOnceWith( + weth.address, + relayData.amount.mul(consts.totalPostFeesPct).div(toBN(consts.oneHundredPct)), + true, // True because fill completed deposit. + depositor.address, // Custom relayer + "0x1234" + ); }); it("Self-relay transfers no tokens", async function () { const largeRelayAmount = consts.amountToSeedWallets.mul(100); From 9ce756f529d3f697e6213485c66a6c4286f29d17 Mon Sep 17 00:00:00 2001 From: nicholaspai Date: Mon, 24 Apr 2023 10:47:18 -0400 Subject: [PATCH 2/2] fix test Signed-off-by: nicholaspai --- test/SpokePool.Relay.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/SpokePool.Relay.ts b/test/SpokePool.Relay.ts index 2233e2592..73fbc4bfe 100644 --- a/test/SpokePool.Relay.ts +++ b/test/SpokePool.Relay.ts @@ -680,6 +680,8 @@ async function testfillRelayWithUpdatedDeposit(depositorAddress: string) { expect(acrossMessageHandler.handleAcrossMessage).to.have.been.calledOnceWith( relayData.destinationToken, amountActuallySent, + false, + relayer.address, updatedMessage );