Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 28, 2024
1 parent d9c5566 commit 6d8c76e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
38 changes: 37 additions & 1 deletion examples/router/contracts/Connected.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,42 @@ contract Connected is ConnectedRouter {
CallOptions memory callOptions,
RevertOptions memory revertOptions
) external payable {
gatewaySendMessage(targetToken, data, callOptions, revertOptions);
bytes memory message = abi.encode(
abi.encodePacked(counterparty),
targetToken,
data,
callOptions,
revertOptions
);
gateway.depositAndCall{value: msg.value}(
router,
message,
revertOptions
);
}

// function sendMessage(
// address targetToken,
// uint256 amount,
// address asset,
// bytes memory data,
// CallOptions memory callOptions,
// RevertOptions memory revertOptions
// ) external {
// bytes memory message = abi.encode(
// abi.encodePacked(counterparty),
// targetToken,
// data,
// callOptions,
// revertOptions
// );
// if (!IERC20(asset).transferFrom(msg.sender, address(this), amount)) {
// revert TransferFailed();
// }
// if (!IERC20(asset).approve(address(gateway), amount)) {
// revert ApprovalFailed();
// }

// gateway.depositAndCall(router, amount, asset, message, revertOptions);
// }
}
22 changes: 2 additions & 20 deletions examples/router/contracts/ConnectedRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ contract ConnectedRouter is Ownable {
event OnRevertEvent(string, RevertContext);

error Unauthorized();
error TransferFailed();
error ApprovalFailed();

function setCounterparty(address contractAddress) external onlyOwner {
counterparty = contractAddress;
Expand All @@ -36,26 +38,6 @@ contract ConnectedRouter is Ownable {
router = routerAddress;
}

function gatewaySendMessage(
address targetToken,
bytes memory data,
CallOptions memory callOptions,
RevertOptions memory revertOptions
) public payable {
bytes memory message = abi.encode(
abi.encodePacked(counterparty),
targetToken,
data,
callOptions,
revertOptions
);
gateway.depositAndCall{value: msg.value}(
router,
message,
revertOptions
);
}

function onCall(
MessageContext calldata context,
bytes calldata message
Expand Down
11 changes: 0 additions & 11 deletions examples/router/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ contract Universal is UniversalContract, Ownable {
error Unauthorized();
error InvalidAddress();

mapping(address => bytes) public counterparty;

event CounterpartySet(address indexed zrc20, bytes indexed contractAddress);
event GasFeeAndOut(uint256 gasFee, uint256 out);
event RevertEvent(string);

Expand All @@ -45,14 +42,6 @@ contract Universal is UniversalContract, Ownable {
uniswapRouter = uniswapRouterAddress;
}

function setCounterparty(
address zrc20,
bytes memory contractAddress
) external onlyOwner {
counterparty[zrc20] = contractAddress;
emit CounterpartySet(zrc20, contractAddress);
}

function onCall(
MessageContext calldata context,
address zrc20,
Expand Down
1 change: 1 addition & 0 deletions examples/router/tasks/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,5 @@ task("transfer", "Make a cross-chain call", main)
"function",
"The function to call on the destination chain (only for arbitrary calls)"
)
.addOptionalParam("erc20", "The address of the ERC20 token to transfer")
.addVariadicPositionalParam("values", "The values of the parameters");

0 comments on commit 6d8c76e

Please sign in to comment.