Skip to content

Commit

Permalink
evm: add FillRedeemed event
Browse files Browse the repository at this point in the history
  • Loading branch information
gator-boi committed Jun 18, 2024
1 parent d5f4a1d commit 3b95608
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion evm/env/localnet/Base.env
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###############################
Expand Down
10 changes: 7 additions & 3 deletions evm/forge/tests/TokenRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 *;
Expand Down Expand Up @@ -933,7 +933,7 @@ contract TokenRouterTest is Test {
encoded, // redeemerMessage
address(this) // refundAddress
);
}
}

function testCannotPlaceMarketOrderErrUnsupportedChain() public {
uint64 amountIn = 69;
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -50,4 +50,4 @@
"ts-mocha": "^10.0.0",
"typechain": "^8.1.1"
}
}
}
16 changes: 10 additions & 6 deletions evm/src/TokenRouter/assets/RedeemFill.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------
Expand Down
2 changes: 2 additions & 0 deletions evm/src/interfaces/ITokenRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -16,5 +17,6 @@ interface ITokenRouter is
IRedeemFill,
ITokenRouterState,
ITokenRouterAdmin,
ITokenRouterEvents,
IAdmin
{}
15 changes: 15 additions & 0 deletions evm/src/interfaces/ITokenRouterEvents.sol
Original file line number Diff line number Diff line change
@@ -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
);
}

0 comments on commit 3b95608

Please sign in to comment.