Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion evm/env/testing.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export AVALANCHE_RPC=https://api.avax.network/ext/bc/C/rpc
export ETHEREUM_RPC=https://rpc.ankr.com/eth
export ETHEREUM_RPC=https://eth.llamarpc.com
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the Ankr RPC not work anymore or is it flaky? Just curious how you chose this RPC provider as opposed to another public one.

Copy link
Member Author

@fergarrui fergarrui May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ankr free tier is not supported anymore. Chose that one from chainlist, personally used it for other scripts, but we can choose a different one too



export AVAX_USDC_ADDRESS=0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E
Expand Down
14 changes: 11 additions & 3 deletions evm/forge/tests/MatchingEngine.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ contract MatchingEngineTest is Test {
uint32 constant ARB_DOMAIN = 3;
uint32 constant ETH_DOMAIN = 0;
uint32 constant AVAX_DOMAIN = 1;
uint256 constant WORMHOLE_MESSAGE_FEE = 1;
uint256 constant WORMHOLE_MESSAGE_FEE_STORAGE_SLOT = 7;

// Environment variables.
uint256 immutable TESTING_SIGNER = uint256(vm.envBytes32("TESTING_DEVNET_GUARDIAN"));
Expand Down Expand Up @@ -128,6 +130,8 @@ contract MatchingEngineTest is Test {
}

function setUp() public {
// Set core bridge messageFee > 0
vm.store(address(wormhole), bytes32(uint256(WORMHOLE_MESSAGE_FEE_STORAGE_SLOT)), bytes32(uint256(WORMHOLE_MESSAGE_FEE)));
vm.startPrank(makeAddr("owner"));
engine = deployProxy(USDC_ADDRESS, address(wormhole), CIRCLE_BRIDGE.fromUniversalAddress());

Expand Down Expand Up @@ -1794,9 +1798,10 @@ contract MatchingEngineTest is Test {
// Record logs for placeMarketOrder.
vm.recordLogs();

vm.deal(caller, WORMHOLE_MESSAGE_FEE);
// Place the order.
vm.prank(caller);
engine.executeFastOrder(fastMessage);
engine.executeFastOrder{value: WORMHOLE_MESSAGE_FEE}(fastMessage);

// Fetch the logs for Wormhole message. There should be two messages.
Vm.Log[] memory logs = vm.getRecordedLogs();
Expand All @@ -1816,9 +1821,10 @@ contract MatchingEngineTest is Test {
// Record logs for placeMarketOrder.
vm.recordLogs();

vm.deal(caller, WORMHOLE_MESSAGE_FEE);
// Place the order.
vm.prank(caller);
engine.executeFastOrder(fastMessage);
engine.executeFastOrder{value: WORMHOLE_MESSAGE_FEE}(fastMessage);

// Fetch the logs for Wormhole message. There should be two messages.
Vm.Log[] memory logs = vm.getRecordedLogs();
Expand All @@ -1837,8 +1843,10 @@ contract MatchingEngineTest is Test {
// Record logs for placeMarketOrder.
vm.recordLogs();

vm.deal(caller, WORMHOLE_MESSAGE_FEE);

vm.prank(caller);
engine.executeSlowOrderAndRedeem(fastTransferVaa, params);
engine.executeSlowOrderAndRedeem{value: WORMHOLE_MESSAGE_FEE}(fastTransferVaa, params);

// Fetch the logs for Wormhole message. There should be two messages.
Vm.Log[] memory logs = vm.getRecordedLogs();
Expand Down
21 changes: 17 additions & 4 deletions evm/forge/tests/TokenRouter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
ITokenRouter router;
SigningWormholeSimulator wormholeSimulator;
CircleSimulator circleSimulator;

// Core bridge.
uint256 immutable WORMHOLE_MESSAGE_FEE_STORAGE_SLOT = 7;
uint256 immutable WORMHOLE_MESSAGE_FEE = 1;

function deployProxy(address _token, address _wormhole, address _tokenMessenger)
internal
Expand Down Expand Up @@ -128,6 +132,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {

circleSimulator = new CircleSimulator(TESTING_SIGNER, MESSAGE_TRANSMITTER);
circleSimulator.setupCircleAttester();

// Set core bridge messageFee > 0
vm.store(address(wormhole), bytes32(uint256(WORMHOLE_MESSAGE_FEE_STORAGE_SLOT)), bytes32(uint256(WORMHOLE_MESSAGE_FEE)));
}

/**
Expand Down Expand Up @@ -1607,7 +1614,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
vm.recordLogs();

// Place the order.
_router.placeMarketOrder(
_router.placeMarketOrder{
value: WORMHOLE_MESSAGE_FEE
}(
amountIn, minAmountOut, targetChain, redeemer, redeemerMessage, refundAddress
);

Expand Down Expand Up @@ -1637,7 +1646,7 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
vm.recordLogs();

// Place the order.
_router.placeMarketOrder(amountIn, targetChain, redeemer, redeemerMessage);
_router.placeMarketOrder{value: WORMHOLE_MESSAGE_FEE}(amountIn, targetChain, redeemer, redeemerMessage);

// Fetch the logs for Wormhole message.
Vm.Log[] memory logs = vm.getRecordedLogs();
Expand All @@ -1663,7 +1672,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
vm.recordLogs();

// Place the order.
_router.placeFastMarketOrder(
_router.placeFastMarketOrder{
value: WORMHOLE_MESSAGE_FEE * 2
}(
expectedOrder.amountIn,
expectedOrder.minAmountOut,
expectedOrder.targetChain,
Expand Down Expand Up @@ -1708,7 +1719,9 @@ contract TokenRouterTest is Test, ITokenRouterEvents {
vm.recordLogs();

// Place the order.
_router.placeFastMarketOrder(
_router.placeFastMarketOrder{
value: WORMHOLE_MESSAGE_FEE * 2
}(
amountIn, targetChain, redeemer, redeemerMessage, maxFee, deadline
);

Expand Down
14 changes: 14 additions & 0 deletions evm/ts/src/TokenRouter/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
redeemerMessage: Buffer | Uint8Array,
minAmountOut?: bigint,
refundAddress?: string,
transactionValue?: bigint,
) {
if (minAmountOut !== undefined && refundAddress !== undefined) {
return this.contract["placeMarketOrder(uint64,uint64,uint16,bytes32,bytes,address)"](
Expand All @@ -51,13 +52,19 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
redeemer,
redeemerMessage,
refundAddress,
{
value: transactionValue,
}
);
} else {
return this.contract["placeMarketOrder(uint64,uint16,bytes32,bytes)"](
amountIn,
targetChain,
redeemer,
redeemerMessage,
{
value: transactionValue,
}
);
}
}
Expand All @@ -71,6 +78,7 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
deadline: number,
minAmountOut?: bigint,
refundAddress?: string,
transactionValue?: bigint,
) {
if (minAmountOut !== undefined && refundAddress !== undefined) {
return this.contract[
Expand All @@ -84,6 +92,9 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
refundAddress,
maxFee,
deadline,
{
value: transactionValue,
}
);
} else {
return this.contract["placeFastMarketOrder(uint64,uint16,bytes32,bytes,uint64,uint32)"](
Expand All @@ -93,6 +104,9 @@ export class EvmTokenRouter implements TokenRouter<ethers.ContractTransaction> {
redeemerMessage,
maxFee,
deadline,
{
value: transactionValue,
}
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion evm/ts/src/testing/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const USDC_DECIMALS: NetworkVars<number> = {
Base: 6,
};

export const WORMHOLE_MESSAGE_FEE = 0;
export const WORMHOLE_MESSAGE_FEE = 100000000000000n;
export const WORMHOLE_GUARDIAN_SET_INDEX = 4;
export const GUARDIAN_PRIVATE_KEY =
"cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";
Expand Down
11 changes: 10 additions & 1 deletion evm/ts/tests/00__environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ describe("Environment", () => {
const actualChainId = await coreBridge.chainId();
expect(actualChainId).to.equal(chainId);

{
// set message fee
const messageFeeSlot = 7;
await provider.send("anvil_setStorageAt", [
coreBridge.address,
messageFeeSlot,
ethers.utils.hexZeroPad(`0x${WORMHOLE_MESSAGE_FEE.toString(16)}`, 32),
]);
}
// fetch current coreBridge protocol fee
const messageFee = await coreBridge.messageFee();
expect(messageFee.eq(WORMHOLE_MESSAGE_FEE)).to.be.true;
Expand Down Expand Up @@ -243,7 +252,7 @@ describe("Environment", () => {
const scripts = `${__dirname}/../../sh`;
const cmd =
`bash ${scripts}/deploy_matching_engine.sh ` +
`-n localnet -c ${chainName} -u ${localhost} -k ${owner.privateKey} ` +
`-n localnet -c ${chainName} -u ${localhost} -k ${owner.privateKey}` +
`> /dev/null 2>&1`;
const out = execSync(cmd, { encoding: "utf8" });

Expand Down
2 changes: 2 additions & 0 deletions evm/ts/tests/03__marketOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ChainType,
parseLiquidityLayerEnvFile,
tryNativeToUint8Array,
WORMHOLE_MESSAGE_FEE,
} from "../src/testing";
import { toChainId } from "@wormhole-foundation/sdk-base";

Expand Down Expand Up @@ -113,6 +114,7 @@ describe("Market Order Business Logic -- CCTP to CCTP", () => {
Buffer.from("All your base are belong to us."),
minAmountOut,
fromWallet.address,
WORMHOLE_MESSAGE_FEE,
)
.then((tx) => mineWait(fromProvider, tx))
.catch((err) => {
Expand Down