swap三明治合约代码
时间: 2023-04-03 10:01:33 浏览: 196
程序_swap_火箭发射代码_
5星 · 资源好评率100%
以下是 swap 三明治合约代码的示例:
```
// SPDX-License-Identifier: MIT
pragma solidity ^.8.;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract SandwichSwap is Ownable {
using SafeERC20 for IERC20;
IERC20 public tokenA;
IERC20 public tokenB;
constructor(IERC20 _tokenA, IERC20 _tokenB) {
tokenA = _tokenA;
tokenB = _tokenB;
}
function swap(uint256 amountA, uint256 amountB) external {
tokenA.safeTransferFrom(msg.sender, address(this), amountA);
tokenB.safeTransfer(msg.sender, amountB);
}
function setTokenA(IERC20 _tokenA) external onlyOwner {
tokenA = _tokenA;
}
function setTokenB(IERC20 _tokenB) external onlyOwner {
tokenB = _tokenB;
}
}
```
希望能够帮到你!
阅读全文