Skip to content

Commit

Permalink
call: reverts
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 12, 2024
1 parent 382e08c commit f05a97c
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions examples/call/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ contract Connected {
event RevertEvent(string, RevertContext);
event HelloEvent(string, string);

error TransferFailed();
error ApprovalFailed();

modifier onlyGateway() {
require(msg.sender == address(gateway), "Caller is not the gateway");
_;
Expand All @@ -32,29 +35,37 @@ contract Connected {
address asset,
RevertOptions memory revertOptions
) external {
IERC20(asset).transferFrom(msg.sender, address(this), amount);
IERC20(asset).approve(address(gateway), amount);
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) {
revert TransferFailed();
}
if (!IERC20(asset).approve(address(gateway), amount)) {
revert ApprovalFailed();
}
gateway.deposit(receiver, amount, asset, revertOptions);
}

function call(
function depositAndCall(
address receiver,
uint256 amount,
address asset,
bytes calldata message,
RevertOptions memory revertOptions
) external {
gateway.call(receiver, message, revertOptions);
if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) {
revert TransferFailed();
}
if (!IERC20(asset).approve(address(gateway), amount)) {
revert ApprovalFailed();
}
gateway.depositAndCall(receiver, amount, asset, message, revertOptions);
}

function depositAndCall(
function call(
address receiver,
uint256 amount,
address asset,
bytes calldata message,
RevertOptions memory revertOptions
) external {
IERC20(asset).transferFrom(msg.sender, address(this), amount);
IERC20(asset).approve(address(gateway), amount);
gateway.depositAndCall(receiver, amount, asset, message, revertOptions);
gateway.call(receiver, message, revertOptions);
}

function depositAndCall(
Expand Down

0 comments on commit f05a97c

Please sign in to comment.