-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AgentExecuteCommand back for compatibility
- Loading branch information
Showing
6 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.23; | ||
|
||
import {ParaID} from "./Types.sol"; | ||
import {AgentExecuteCommand, ParaID} from "./Types.sol"; | ||
import {SubstrateTypes} from "./SubstrateTypes.sol"; | ||
|
||
import {IERC20} from "./interfaces/IERC20.sol"; | ||
|
@@ -16,6 +16,17 @@ contract AgentExecutor { | |
using SafeTokenTransfer for IERC20; | ||
using SafeNativeTransfer for address payable; | ||
|
||
/// @dev Execute a message which originated from the Polkadot side of the bridge. In other terms, | ||
/// the `data` parameter is constructed by the BridgeHub parachain. | ||
/// | ||
function execute(bytes memory data) external { | ||
(AgentExecuteCommand command, bytes memory params) = abi.decode(data, (AgentExecuteCommand, bytes)); | ||
if (command == AgentExecuteCommand.TransferToken) { | ||
(address token, address recipient, uint128 amount) = abi.decode(params, (address, address, uint128)); | ||
_transferToken(token, recipient, amount); | ||
} | ||
} | ||
|
||
/// @dev Transfer ether to `recipient`. Unlike `_transferToken` This logic is not nested within `execute`, | ||
/// as the gateway needs to control an agent's ether balance directly. | ||
/// | ||
|
@@ -24,10 +35,15 @@ contract AgentExecutor { | |
} | ||
|
||
/// @dev Transfer ERC20 to `recipient`. Only callable via `execute`. | ||
function transferToken(address token, address recipient, uint128 amount) external { | ||
function _transferToken(address token, address recipient, uint128 amount) internal { | ||
IERC20(token).safeTransfer(recipient, amount); | ||
} | ||
|
||
/// @dev Transfer ERC20 to `recipient`. Only callable via `execute`. | ||
function transferToken(address token, address recipient, uint128 amount) external { | ||
_transferToken(token, recipient, amount); | ||
} | ||
|
||
/// @dev Mint ERC20 token to `recipient`. | ||
function mintToken(address token, address recipient, uint256 amount) external { | ||
ERC20(token).mint(recipient, amount); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters