Initial commit: add .gitignore and README
This commit is contained in:
52
contracts/examples/ProtocolinkExecutor.sol
Normal file
52
contracts/examples/ProtocolinkExecutor.sol
Normal file
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "../interfaces/IERC20.sol";
|
||||
|
||||
interface IProtocolinkRouter {
|
||||
function execute(
|
||||
bytes calldata data
|
||||
) external payable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title ProtocolinkExecutor
|
||||
* @notice Example contract for executing Protocolink routes
|
||||
* @dev This contract can execute Protocolink transaction plans
|
||||
*/
|
||||
contract ProtocolinkExecutor {
|
||||
IProtocolinkRouter public immutable router;
|
||||
|
||||
constructor(address router_) {
|
||||
router = IProtocolinkRouter(router_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Execute a Protocolink route
|
||||
* @param data The encoded Protocolink route data
|
||||
*/
|
||||
function executeRoute(bytes calldata data) external payable {
|
||||
router.execute{value: msg.value}(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Execute a Protocolink route with token approvals
|
||||
* @param tokens The tokens to approve
|
||||
* @param amounts The amounts to approve
|
||||
* @param data The encoded Protocolink route data
|
||||
*/
|
||||
function executeRouteWithApprovals(
|
||||
address[] calldata tokens,
|
||||
uint256[] calldata amounts,
|
||||
bytes calldata data
|
||||
) external payable {
|
||||
// Approve tokens
|
||||
for (uint256 i = 0; i < tokens.length; i++) {
|
||||
IERC20(tokens[i]).approve(address(router), amounts[i]);
|
||||
}
|
||||
|
||||
// Execute route
|
||||
router.execute{value: msg.value}(data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user