diff --git a/contracts/src/Gateway.sol b/contracts/src/Gateway.sol index 3eb858e806..b9ba740b71 100644 --- a/contracts/src/Gateway.sol +++ b/contracts/src/Gateway.sol @@ -38,7 +38,6 @@ import { CreateChannelParams, UpdateChannelParams, SetOperatingModeParams, - TransferNativeFromAgentParams, SetTokenTransferFeesParams, SetPricingParametersParams, RegisterForeignTokenParams, @@ -197,10 +196,8 @@ contract Gateway is IGateway, IInitializable, IUpgradable { success = false; } } else if (message.command == Command.TransferNativeFromAgent) { - try Gateway(this).transferNativeFromAgent{gas: maxDispatchGas}(message.params) {} - catch { - success = false; - } + // Disable this bridge command because now native Ether can be locked in an agent. + success = true; } else if (message.command == Command.Upgrade) { try Gateway(this).upgrade{gas: maxDispatchGas}(message.params) {} catch { @@ -382,16 +379,6 @@ contract Gateway is IGateway, IInitializable, IUpgradable { emit OperatingModeChanged(params.mode); } - // @dev Transfer funds from an agent to a recipient account - function transferNativeFromAgent(bytes calldata data) external onlySelf { - TransferNativeFromAgentParams memory params = abi.decode(data, (TransferNativeFromAgentParams)); - - address agent = _ensureAgent(params.agentID); - - _transferNativeFromAgent(agent, payable(params.recipient), params.amount); - emit AgentFundsWithdrawn(params.agentID, params.recipient, params.amount); - } - // @dev Set token fees of the gateway function setTokenTransferFees(bytes calldata data) external onlySelf { AssetsStorage.Layout storage $ = AssetsStorage.layout(); @@ -591,12 +578,6 @@ contract Gateway is IGateway, IInitializable, IUpgradable { return Call.verifyResult(success, returndata); } - /// @dev Transfer ether from an agent - function _transferNativeFromAgent(address agent, address payable recipient, uint256 amount) internal { - bytes memory call = abi.encodeCall(AgentExecutor.transferNative, (recipient, amount)); - _invokeOnAgent(agent, call); - } - /// @dev Define the dust threshold as the minimum cost to transfer ether between accounts function _dustThreshold() internal view returns (uint256) { return 21000 * tx.gasprice; diff --git a/contracts/src/interfaces/IGateway.sol b/contracts/src/interfaces/IGateway.sol index 77351c08ec..84d5c072d0 100644 --- a/contracts/src/interfaces/IGateway.sol +++ b/contracts/src/interfaces/IGateway.sol @@ -32,9 +32,6 @@ interface IGateway { // Emitted when pricing params updated event PricingParametersChanged(); - // Emitted when funds are withdrawn from an agent - event AgentFundsWithdrawn(bytes32 indexed agentID, address indexed recipient, uint256 amount); - // Emitted when foreign token from polkadot registed event ForeignTokenRegistered(bytes32 indexed tokenID, address token); diff --git a/contracts/test/Gateway.t.sol b/contracts/test/Gateway.t.sol index 103276bcda..4b1b1af8b7 100644 --- a/contracts/test/Gateway.t.sol +++ b/contracts/test/Gateway.t.sol @@ -181,6 +181,16 @@ contract GatewayTest is Test { return (Command.TransferNativeToken, abi.encode(params)); } + function makeTransferNativeFromAgentCommand(bytes32 agentID, address recipient, uint128 amount) + public + pure + returns (Command, bytes memory) + { + TransferNativeFromAgentParams memory params = + TransferNativeFromAgentParams({agentID: agentID, recipient: recipient, amount: amount}); + return (Command.TransferNativeFromAgent, abi.encode(params)); + } + function makeMockProof() public pure returns (Verification.Proof memory) { return Verification.Proof({ header: Verification.ParachainHeader({ @@ -589,14 +599,6 @@ contract GatewayTest is Test { MockGateway(address(gateway)).transferNativeTokenPublic(encodedParams); } - function testAgentExecutionBadOrigin() public { - TransferNativeFromAgentParams memory params = - TransferNativeFromAgentParams({agentID: bytes32(0), recipient: address(this), amount: 1}); - - vm.expectRevert(Gateway.AgentDoesNotExist.selector); - MockGateway(address(gateway)).transferNativeFromAgentPublic(abi.encode(params)); - } - function testAgentExecutionBadPayload() public { AgentExecuteParams memory params = AgentExecuteParams({agentID: assetHubAgentID, payload: ""}); @@ -758,18 +760,30 @@ contract GatewayTest is Test { assertEq(uint256(mode), 1); } - function testWithdrawAgentFunds() public { - deal(assetHubAgent, 50 ether); + function testWithdrawAgentFundIsIgnored() public { + address recipient = makeAddr("test_recipeint"); + uint128 amount = 1; + + deal(assetHubAgent, amount); - address recipient = makeAddr("recipient"); + (Command command, bytes memory params) = makeTransferNativeFromAgentCommand(assetHubAgentID, recipient, amount); - bytes memory params = - abi.encode(TransferNativeFromAgentParams({agentID: assetHubAgentID, recipient: recipient, amount: 3 ether})); + assertEq(address(assetHubAgent).balance, amount); + assertEq(recipient.balance, 0); - MockGateway(address(gateway)).transferNativeFromAgentPublic(params); + // Expect the gateway to emit `InboundMessageDispatched` + vm.expectEmit(); + emit IGateway.InboundMessageDispatched(assetHubParaID.into(), 1, messageID, true); - assertEq(assetHubAgent.balance, 47 ether); - assertEq(recipient.balance, 3 ether); + hoax(relayer, 1 ether); + IGateway(address(gateway)).submitV1( + InboundMessage(assetHubParaID.into(), 1, command, params, maxDispatchGas, maxRefund, reward, messageID), + proof, + makeMockProof() + ); + + assertEq(address(assetHubAgent).balance, amount); + assertEq(recipient.balance, 0); } /** @@ -961,9 +975,6 @@ contract GatewayTest is Test { vm.expectRevert(Gateway.Unauthorized.selector); Gateway(address(gateway)).upgrade(""); - - vm.expectRevert(Gateway.Unauthorized.selector); - Gateway(address(gateway)).transferNativeFromAgent(""); } function testGetters() public { diff --git a/contracts/test/mocks/MockGateway.sol b/contracts/test/mocks/MockGateway.sol index 4356bb9876..91deec788e 100644 --- a/contracts/test/mocks/MockGateway.sol +++ b/contracts/test/mocks/MockGateway.sol @@ -47,10 +47,6 @@ contract MockGateway is Gateway { this.setOperatingMode(params); } - function transferNativeFromAgentPublic(bytes calldata params) external { - this.transferNativeFromAgent(params); - } - function setCommitmentsAreVerified(bool value) external { commitmentsAreVerified = value; }