Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit WETH and Send #1320

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
33 changes: 33 additions & 0 deletions contracts/src/DepositWETH9AndSend.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
pragma solidity 0.8.25;

import {IGateway} from "./interfaces/IGateway.sol";
import {WETH9} from "canonical-weth/WETH9.sol";
import {ParaID, MultiAddress} from "./Types.sol";

contract DepositWETH9AndSend {
address public immutable GATEWAY_PROXY;
address payable public immutable WETH_INSTANCE;

constructor(address _gatewayProxy, address payable _wethInstance) {
GATEWAY_PROXY = _gatewayProxy;
WETH_INSTANCE = _wethInstance;
}

// Transfer ERC20 tokens to a Polkadot parachain
function sendToken(
ParaID destinationChain,
MultiAddress calldata destinationAddress,
uint128 destinationFee,
uint128 amount
) external payable {
WETH9(WETH_INSTANCE).deposit{value: amount}();
WETH9(WETH_INSTANCE).approve(GATEWAY_PROXY, amount);

uint256 fee = msg.value - amount;
IGateway(GATEWAY_PROXY).sendToken{value: fee}(
WETH_INSTANCE, destinationChain, destinationAddress, destinationFee, amount
);
}
}
28 changes: 28 additions & 0 deletions contracts/test/Gateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Gateway} from "../src/Gateway.sol";
import {MockGateway} from "./mocks/MockGateway.sol";
import {MockGatewayV2} from "./mocks/MockGatewayV2.sol";
import {GatewayProxy} from "../src/GatewayProxy.sol";
import {DepositWETH9AndSend} from "../src/DepositWETH9AndSend.sol";

import {AgentExecutor} from "../src/AgentExecutor.sol";
import {Agent} from "../src/Agent.sol";
Expand Down Expand Up @@ -76,6 +77,7 @@ contract GatewayTest is Test {

MockGateway public gatewayLogic;
GatewayProxy public gateway;
DepositWETH9AndSend public depositAndSend;

WETH9 public token;

Expand Down Expand Up @@ -154,6 +156,9 @@ contract GatewayTest is Test {
recipientAddress20 = multiAddressFromBytes20(bytes20(keccak256("recipient")));

dotTokenID = bytes32(uint256(1));

// Deposit and send
depositAndSend = new DepositWETH9AndSend(address(gateway), payable(token));
}

function makeCreateAgentCommand() public pure returns (Command, bytes memory) {
Expand Down Expand Up @@ -609,6 +614,29 @@ contract GatewayTest is Test {
IGateway(address(gateway)).sendToken{value: fee}(address(token), destPara, recipientAddress32, 1, 1);
}


function testDepositAndSendTokenAddress32() public {
// Multilocation for recipient
ParaID destPara = ParaID.wrap(2043);

// register token first
uint256 fee = IGateway(address(gateway)).quoteRegisterTokenFee();
IGateway(address(gateway)).registerToken{value: fee}(address(token));

fee = IGateway(address(gateway)).quoteSendTokenFee(address(token), destPara, 1);

vm.expectEmit(true, true, false, true);
emit IGateway.TokenSent(address(token), address(depositAndSend), destPara, recipientAddress32, 1);

// Expect the gateway to emit `OutboundMessageAccepted`
vm.expectEmit(true, false, false, false);
emit IGateway.OutboundMessageAccepted(assetHubParaID.into(), 1, messageID, bytes(""));

uint128 amount = 1;

depositAndSend.sendToken{value: fee + amount}(destPara, recipientAddress32, 1, amount);
}

function testSendTokenAddress32ToAssetHub() public {
// Let gateway lock up to 1 tokens
token.approve(address(gateway), 1);
Expand Down
Loading