-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Honeypot.sol
47 lines (43 loc) · 1.57 KB
/
Honeypot.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
// 极简貔貅ERC20代币,只能买,不能卖
contract HoneyPot is ERC20, Ownable {
address public pair;
// 构造函数:初始化代币名称和代号
constructor() ERC20("HoneyPot", "Pi Xiu") Ownable(msg.sender){
address factory = 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f; // goerli uniswap v2 factory
address tokenA = address(this); // 貔貅代币地址
address tokenB = 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6; // goerli WETH
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); //将tokenA和tokenB按大小排序
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
// calculate pair address
pair = address(uint160(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
salt,
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f'
)))));
}
/**
* 铸造函数,只有合约所有者可以调用
*/
function mint(address to, uint amount) public onlyOwner {
_mint(to, amount);
}
/**
* @dev See {ERC20-_update}.
* 貔貅函数:只有合约拥有者可以卖出
*/
function _update(
address from,
address to,
uint256 amount
) internal virtual override {
if(to == pair){
require(from == owner(), "Can not Transfer");
}
super._update(from, to, amount);
}
}