From 3b95608258ce161700d5bc88dd16f57a50bc7e59 Mon Sep 17 00:00:00 2001 From: gator-boi Date: Fri, 14 Jun 2024 16:23:22 -0400 Subject: [PATCH] evm: add FillRedeemed event --- evm/env/localnet/Base.env | 2 +- evm/forge/tests/TokenRouter.t.sol | 10 +++++++--- evm/package.json | 4 ++-- evm/src/TokenRouter/assets/RedeemFill.sol | 16 ++++++++++------ evm/src/interfaces/ITokenRouter.sol | 2 ++ evm/src/interfaces/ITokenRouterEvents.sol | 15 +++++++++++++++ 6 files changed, 37 insertions(+), 12 deletions(-) create mode 100644 evm/src/interfaces/ITokenRouterEvents.sol diff --git a/evm/env/localnet/Base.env b/evm/env/localnet/Base.env index 55478d18..5122b61c 100644 --- a/evm/env/localnet/Base.env +++ b/evm/env/localnet/Base.env @@ -36,7 +36,7 @@ export RELEASE_OWNER_ASSISTANT_ADDRESS=0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6 ### Token Router Proxy (evm address) -export RELEASE_TOKEN_ROUTER_ADDRESS=0x27D44c7337ce4D67b7cd573e9c36bDEED2b2162a +export RELEASE_TOKEN_ROUTER_ADDRESS=0x1943bd00e3a4f46b10e6657dd9236be95e20398a ############################### Matching Engine ############################### diff --git a/evm/forge/tests/TokenRouter.t.sol b/evm/forge/tests/TokenRouter.t.sol index 9f68d84e..02c54a60 100644 --- a/evm/forge/tests/TokenRouter.t.sol +++ b/evm/forge/tests/TokenRouter.t.sol @@ -29,11 +29,11 @@ import {Messages} from "src/shared/Messages.sol"; import {Utils} from "src/shared/Utils.sol"; import "src/interfaces/ITokenRouter.sol"; +import "src/interfaces/ITokenRouterEvents.sol"; import {FastTransferParameters, Endpoint} from "src/interfaces/ITokenRouterTypes.sol"; - import {WormholeCctpMessages} from "src/shared/WormholeCctpMessages.sol"; -contract TokenRouterTest is Test { +contract TokenRouterTest is Test, ITokenRouterEvents { using BytesParsing for bytes; using WormholeCctpMessages for *; using Messages for *; @@ -933,7 +933,7 @@ contract TokenRouterTest is Test { encoded, // redeemerMessage address(this) // refundAddress ); - } + } function testCannotPlaceMarketOrderErrUnsupportedChain() public { uint64 amountIn = 69; @@ -1811,6 +1811,10 @@ contract TokenRouterTest is Test { ); uint256 balanceBefore = _router.orderToken().balanceOf(address(this)); + (IWormhole.VM memory _vm) = wormhole.parseVM(redeemParams.encodedWormholeMessage); + + vm.expectEmit(); + emit FillRedeemed(_vm.emitterChainId, _vm.emitterAddress, _vm.sequence); RedeemedFill memory redeemed = _router.redeemFill( OrderResponse({ diff --git a/evm/package.json b/evm/package.json index 4ecd1f32..e2462784 100644 --- a/evm/package.json +++ b/evm/package.json @@ -14,7 +14,7 @@ "build:esm": "tsc -p tsconfig.esm.json", "build:cjs": "tsc -p tsconfig.cjs.json", "build": "npm run build:esm && npm run build:cjs", - "generate": "typechain --target=ethers-v5 --out-dir=ts/src/types out/*/*.json", + "generate": "typechain --target=ethers-v5 --out-dir=ts/src/types out/[!build-info]*/*.json", "clean": "rm -rf dist && rm -rf node_modules && rm -f ./*.tsbuildinfo" }, "exports": { @@ -50,4 +50,4 @@ "ts-mocha": "^10.0.0", "typechain": "^8.1.1" } -} \ No newline at end of file +} diff --git a/evm/src/TokenRouter/assets/RedeemFill.sol b/evm/src/TokenRouter/assets/RedeemFill.sol index 6378dc12..9bbcb6db 100644 --- a/evm/src/TokenRouter/assets/RedeemFill.sol +++ b/evm/src/TokenRouter/assets/RedeemFill.sol @@ -16,26 +16,30 @@ import "./Errors.sol"; import {State} from "./State.sol"; import "src/interfaces/IRedeemFill.sol"; +import "src/interfaces/ITokenRouterEvents.sol"; -abstract contract RedeemFill is IRedeemFill, Admin, State { +abstract contract RedeemFill is IRedeemFill, ITokenRouterEvents, Admin, State { using Messages for *; using Utils for *; /// @inheritdoc IRedeemFill - function redeemFill(OrderResponse calldata response) external returns (RedeemedFill memory) { - uint16 emitterChain = response.encodedWormholeMessage.unsafeEmitterChainFromVaa(); - bytes32 emitterAddress = response.encodedWormholeMessage.unsafeEmitterAddressFromVaa(); + function redeemFill(OrderResponse calldata response) external returns (RedeemedFill memory fill) { + (, uint16 emitterChain, bytes32 emitterAddress, uint64 sequence) = + response.encodedWormholeMessage.unsafeVaaKeyFromVaa(); // If the emitter is the matching engine, and this TokenRouter is on the same chain // as the matching engine, then this is a fast fill. + if ( (emitterChain == _matchingEngineChain && _chainId == _matchingEngineChain) && emitterAddress == _matchingEngineAddress ) { - return _handleFastFill(response.encodedWormholeMessage); + fill = _handleFastFill(response.encodedWormholeMessage); } else { - return _handleFill(emitterChain, response); + fill = _handleFill(emitterChain, response); } + + emit FillRedeemed(emitterChain, emitterAddress, sequence); } // ------------------------------- Private --------------------------------- diff --git a/evm/src/interfaces/ITokenRouter.sol b/evm/src/interfaces/ITokenRouter.sol index 7257d071..b4fe5ca5 100644 --- a/evm/src/interfaces/ITokenRouter.sol +++ b/evm/src/interfaces/ITokenRouter.sol @@ -7,6 +7,7 @@ import "./IPlaceMarketOrder.sol"; import "./IRedeemFill.sol"; import "./ITokenRouterState.sol"; import "./ITokenRouterAdmin.sol"; +import "./ITokenRouterEvents.sol"; import "./IAdmin.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -16,5 +17,6 @@ interface ITokenRouter is IRedeemFill, ITokenRouterState, ITokenRouterAdmin, + ITokenRouterEvents, IAdmin {} diff --git a/evm/src/interfaces/ITokenRouterEvents.sol b/evm/src/interfaces/ITokenRouterEvents.sol new file mode 100644 index 00000000..44661cfb --- /dev/null +++ b/evm/src/interfaces/ITokenRouterEvents.sol @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache 2 + +pragma solidity ^0.8.0; + +interface ITokenRouterEvents { + /** + * @notice Emitted when a fill is redeemed by this contract. + * @param emitterChainId Wormhole chain ID of emitter on the source chain. + * @param emitterAddress Address (bytes32 zero-left-padded) of emitter on the source chain. + * @param sequence Sequence of the Wormhole message. + */ + event FillRedeemed( + uint16 indexed emitterChainId, bytes32 indexed emitterAddress, uint64 indexed sequence + ); +} \ No newline at end of file