Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
41 changes: 35 additions & 6 deletions solidity/contracts/mock/MockValueTransferBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@
pragma solidity ^0.8.13;

import {ITokenBridge, Quote} from "../interfaces/ITokenBridge.sol";
import {Router} from "../client/Router.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ERC20Test} from "../test/ERC20Test.sol";

contract MockValueTransferBridge is ITokenBridge {
contract MockValueTransferBridge is Router, ITokenBridge {
using SafeERC20 for IERC20;
address public collateral;
Comment thread
nambrot marked this conversation as resolved.
Outdated

constructor(address _collateral) {
collateral = _collateral;
}

event SentTransferRemote(
uint32 indexed origin,
uint32 indexed destination,
bytes32 indexed recipient,
uint256 amount
);

constructor(address _collateral, address _mailbox) Router(_mailbox) {
collateral = _collateral;
}

function initialize(
address _hook,
address _ism,
address _owner
) external initializer {
_MailboxClient_initialize(_hook, _ism, _owner);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

function quoteTransferRemote(
uint32, //_destinationDomain,
bytes32, //_recipient,
Expand Down Expand Up @@ -50,6 +60,25 @@ contract MockValueTransferBridge is ITokenBridge {
_amountOut
);

return keccak256("transferId");
// Dispatch through MockMailbox so Dispatch event is emitted
transferId = _Router_dispatch(
_destinationDomain,
msg.value,
abi.encode(_recipient, _amountOut)
);
}

function _handle(
uint32, // _origin
bytes32, // _sender
bytes calldata _message
) internal virtual override {
(bytes32 recipientBytes32, uint256 amount) = abi.decode(
_message,
(bytes32, uint256)
);
address recipient = address(uint160(uint256(recipientBytes32)));
// Mint collateral tokens to recipient (destination warp token)
ERC20Test(collateral).mintTo(recipient, amount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ describe('hyperlane warp rebalancer e2e tests', async function () {
// Deploy the bridge
const bridgeContract = await new MockValueTransferBridge__factory(
chain3Signer,
).deploy(tokenChain3.address);
).deploy(tokenChain3.address, chain3Addresses.mailbox);

// Allow bridge
await chain3CollateralContract.addBridge(
Expand Down Expand Up @@ -877,7 +877,7 @@ describe('hyperlane warp rebalancer e2e tests', async function () {
// Deploy the bridge
const bridgeContract = await new MockValueTransferBridge__factory(
chain3Signer,
).deploy(tokenChain3.address);
).deploy(tokenChain3.address, chain3Addresses.mailbox);

// Allow bridge
await chain3CollateralContract.addBridge(
Expand Down Expand Up @@ -961,7 +961,7 @@ describe('hyperlane warp rebalancer e2e tests', async function () {
// It will also allow us to mock some token movement
const bridgeContract = await new MockValueTransferBridge__factory(
originSigner,
).deploy(tokenChain3.address);
).deploy(tokenChain3.address, chain3Addresses.mailbox);

// Allow bridge
// This allow the bridge to be used to send the rebalance transaction
Expand Down Expand Up @@ -1208,7 +1208,7 @@ describe('hyperlane warp rebalancer e2e tests', async function () {
// It will also allow us to mock some token movement
const bridgeContract = await new MockValueTransferBridge__factory(
originSigner,
).deploy(tokenChain3.address);
).deploy(tokenChain3.address, chain3Addresses.mailbox);

// Allow bridge
// This allow the bridge to be used to send the rebalance transaction
Expand Down
24 changes: 4 additions & 20 deletions typescript/rebalancer-sim/scenarios/inflight-guard.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "inflight-guard",
"description": "Tests rebalancer behavior with slow bridge and fast polling to demonstrate inflight guard importance.",
"expectedBehavior": "With SLOW bridge (3s) and polling at 1000ms, a rebalancer without inflight tracking will over-rebalance.\nWithout inflight guard: Multiple redundant transfers sent before first one delivers.\nWith inflight guard: Only 1-2 transfers sent, tracking pending amounts.",
"duration": 8000,
"expectedBehavior": "With SLOW bridge (4s) and polling at 1000ms, a rebalancer without inflight tracking will over-rebalance.\nWithout inflight guard: Multiple redundant transfers sent before first one delivers.\nWith inflight guard: Only 1-2 transfers sent, tracking pending amounts.",
"duration": 10000,
"chains": ["chain1", "chain2"],
"initialImbalance": {
"chain1": "50000000000000000000"
Expand All @@ -18,27 +18,11 @@
},
{
"id": "keepalive-2",
"timestamp": 3000,
"origin": "chain1",
"destination": "chain2",
"amount": "40000000000000000000",
"user": "0x1111111111111111111111111111111111111111"
},
{
"id": "keepalive-3",
"timestamp": 5000,
"origin": "chain1",
"destination": "chain2",
"amount": "40000000000000000000",
"user": "0x1111111111111111111111111111111111111111"
},
{
"id": "keepalive-4",
"timestamp": 7000,
"origin": "chain1",
"destination": "chain2",
"amount": "40000000000000000000",
"user": "0x1111111111111111111111111111111111111111"
}
],
"defaultInitialCollateral": "100000000000000000000",
Expand All @@ -50,14 +34,14 @@
"defaultBridgeConfig": {
"chain1": {
"chain2": {
"deliveryDelay": 3000,
"deliveryDelay": 4000,
"failureRate": 0,
"deliveryJitter": 0
}
},
"chain2": {
"chain1": {
"deliveryDelay": 3000,
"deliveryDelay": 4000,
"failureRate": 0,
"deliveryJitter": 0
}
Expand Down
Loading
Loading