Skip to content

Commit

Permalink
amount
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 21, 2024
1 parent 5ee524f commit 33281e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 4 additions & 2 deletions examples/router/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ contract Connected is ConnectedRouter {

function onMessageReceive(
bytes memory data,
address sender
address sender,
uint256 amount
) internal override {
emit OnMessageReceiveEvent();
}

function onMessageRevert(
bytes memory data,
address sender
address sender,
uint256 amount
) internal override {
emit OnMessageRevertEvent();
}
Expand Down
16 changes: 8 additions & 8 deletions examples/router/contracts/ConnectedRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,15 @@ contract ConnectedRouter is Ownable {
bytes calldata message
) external payable onlyGateway returns (bytes4) {
if (context.sender != router) revert Unauthorized();
(bytes memory data, address sender, bool isCall) = abi.decode(
message,
(bytes, address, bool)
);
(bytes memory data, address sender, uint256 amount, bool isCall) = abi
.decode(message, (bytes, address, uint256, bool));

if (sender != counterparty) revert Unauthorized();

if (isCall) {
onMessageReceive(data, sender);
onMessageReceive(data, sender, amount);
} else {
onMessageRevert(data, sender);
onMessageRevert(data, sender, amount);
}
return "";
}
Expand All @@ -86,14 +84,16 @@ contract ConnectedRouter is Ownable {

function onMessageReceive(
bytes memory data,
address sender
address sender,
uint256 amount
) internal virtual {
// To be overridden in the child contract
}

function onMessageRevert(
bytes memory data,
address sender
address sender,
uint256 amount
) internal virtual {
// To be overridden in the child contract
}
Expand Down
10 changes: 6 additions & 4 deletions examples/router/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ contract Universal is UniversalContract, Ownable {
callOptions.gasLimit
);

uint256 withdrawAmount = out - gasFee;

bytes memory m = callOptions.isArbitraryCall
? abi.encodePacked(data, context.sender, true)
: abi.encode(data, context.sender, true);
? abi.encodePacked(data, context.sender, withdrawAmount, true)
: abi.encode(data, context.sender, withdrawAmount, true);

gateway.withdrawAndCall(
receiver,
out - gasFee,
withdrawAmount,
destination,
m,
callOptions,
Expand Down Expand Up @@ -141,7 +143,7 @@ contract Universal is UniversalContract, Ownable {
abi.encodePacked(revertOptions.revertAddress),
out - gasFee,
destination,
abi.encode(data, receiver, false),
abi.encode(data, receiver, out - gasFee, false),
CallOptions(onRevertGasLimit, false),
RevertOptions(address(0), false, address(0), "", 0)
);
Expand Down

0 comments on commit 33281e8

Please sign in to comment.