文件 1 的 1:STREETH.sol
pragma solidity ^0.8.0;
library UniswapV2Library {
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
function pairFor(bytes32 initCodeHash, address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint160(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
initCodeHash
)))));
}
}
pragma solidity ^0.8.0;
library UniswapV3Library {
bytes32 internal constant POOL_INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
struct PoolKey {
address token0;
address token1;
uint24 fee;
}
function getPoolKey(
address tokenA,
address tokenB,
uint24 fee
) internal pure returns (PoolKey memory) {
if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);
return PoolKey({token0: tokenA, token1: tokenB, fee: fee});
}
function computeAddress(address factory, PoolKey memory key) internal pure returns (address pool) {
require(key.token0 < key.token1);
pool = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encode(key.token0, key.token1, key.fee)),
POOL_INIT_CODE_HASH
)
)
)
)
);
}
}
pragma solidity ^0.8.0;
interface IPLPS {
function LiquidityProtection_beforeTokenTransfer(
address _pool, address _from, address _to, uint _amount) external;
function isBlocked(address _pool, address _who) external view returns(bool);
function unblock(address pool, address[] calldata whos) external;
}
pragma solidity ^0.8.0;
abstract contract UsingLiquidityProtectionService {
bool private unProtected = false;
IPLPS private plps;
uint64 internal constant HUNDRED_PERCENT = 1e18;
bytes32 internal constant UNISWAP = 0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
bytes32 internal constant PANCAKESWAP = 0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5;
bytes32 internal constant QUICKSWAP = 0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f;
bytes32 internal constant SUSHISWAP = 0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303;
bytes32 internal constant PANGOLIN = 0x40231f6b438bce0797c9ada29b718a87ea0a5cea3fe9a771abdd76bd41a3e545;
bytes32 internal constant TRADERJOE = 0x0bbca9af0511ad1a1da383135cf3a8d2ac620e549ef9f6ae3a4c33c2fed0af91;
enum UniswapVersion {
V2,
V3
}
enum UniswapV3Fees {
_005,
_03,
_1
}
modifier onlyProtectionAdmin() {
protectionAdminCheck();
_;
}
constructor (address _plps) {
plps = IPLPS(_plps);
}
function LiquidityProtection_setLiquidityProtectionService(IPLPS _plps) external onlyProtectionAdmin() {
require(token_balanceOf(getLiquidityPool()) == 0, 'UsingLiquidityProtectionService: liquidity already added');
plps = _plps;
}
function token_transfer(address from, address to, uint amount) internal virtual;
function token_balanceOf(address holder) internal view virtual returns(uint);
function protectionAdminCheck() internal view virtual;
function uniswapVariety() internal pure virtual returns(bytes32);
function uniswapVersion() internal pure virtual returns(UniswapVersion);
function uniswapFactory() internal pure virtual returns(address);
function counterToken() internal pure virtual returns(address) {
return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
}
function uniswapV3Fee() internal pure virtual returns(UniswapV3Fees) {
return UniswapV3Fees._03;
}
function protectionChecker() internal view virtual returns(bool) {
return ProtectionSwitch_manual();
}
function lps() private view returns(IPLPS) {
return plps;
}
function LiquidityProtection_beforeTokenTransfer(address _from, address _to, uint _amount) internal virtual {
if (protectionChecker()) {
if (unProtected) {
return;
}
lps().LiquidityProtection_beforeTokenTransfer(getLiquidityPool(), _from, _to, _amount);
}
}
function revokeBlocked(address[] calldata _holders, address _revokeTo) external onlyProtectionAdmin() {
require(protectionChecker(), 'UsingLiquidityProtectionService: protection removed');
bool unProtectedOld = unProtected;
unProtected = true;
address pool = getLiquidityPool();
for (uint i = 0; i < _holders.length; i++) {
address holder = _holders[i];
if (lps().isBlocked(pool, holder)) {
token_transfer(holder, _revokeTo, token_balanceOf(holder));
}
}
unProtected = unProtectedOld;
}
function LiquidityProtection_unblock(address[] calldata _holders) external onlyProtectionAdmin() {
require(protectionChecker(), 'UsingLiquidityProtectionService: protection removed');
address pool = getLiquidityPool();
lps().unblock(pool, _holders);
}
function disableProtection() external onlyProtectionAdmin() {
unProtected = true;
}
function isProtected() public view returns(bool) {
return not(unProtected);
}
function ProtectionSwitch_manual() internal view returns(bool) {
return isProtected();
}
function ProtectionSwitch_timestamp(uint _timestamp) internal view returns(bool) {
return not(passed(_timestamp));
}
function ProtectionSwitch_block(uint _block) internal view returns(bool) {
return not(blockPassed(_block));
}
function blockPassed(uint _block) internal view returns(bool) {
return _block < block.number;
}
function passed(uint _timestamp) internal view returns(bool) {
return _timestamp < block.timestamp;
}
function not(bool _condition) internal pure returns(bool) {
return !_condition;
}
function feeToUint24(UniswapV3Fees _fee) internal pure returns(uint24) {
if (_fee == UniswapV3Fees._03) return 3000;
if (_fee == UniswapV3Fees._005) return 500;
return 10000;
}
function getLiquidityPool() public view returns(address) {
if (uniswapVersion() == UniswapVersion.V2) {
return UniswapV2Library.pairFor(uniswapVariety(), uniswapFactory(), address(this), counterToken());
}
require(uniswapVariety() == UNISWAP, 'LiquidityProtection: uniswapVariety() can only be UNISWAP for V3.');
return UniswapV3Library.computeAddress(uniswapFactory(),
UniswapV3Library.getPoolKey(address(this), counterToken(), feeToUint24(uniswapV3Fee())));
}
}
pragma solidity ^0.8.6;
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
this;
return msg.data;
}
}
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
interface IFactory{
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IRouter {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline) external;
}
contract STREETH is Context, IERC20, Ownable, UsingLiquidityProtectionService(0x346E0Ca75bA94B42acD4E551551aa3e60E613137) {
mapping (address => uint256) private _rOwned;
mapping (address => uint256) private _tOwned;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => bool) private _isExcluded;
address[] private _excluded;
bool public swapEnabled;
bool private swapping;
IRouter public router;
address public pair;
uint8 private constant _decimals = 18;
uint256 private constant MAX = ~uint256(0);
uint256 private _tTotal = 300_000_000 * 10**_decimals;
uint256 private _rTotal = (MAX - (MAX % _tTotal));
uint256 public swapTokensAtAmount = 50000 * 10**_decimals;
string private constant _name = "STREETH";
string private constant _symbol = "STREETH";
address public marketingWallet = 0x5cd0a4043cFa2776bFeD01E5DE11cA8f86bb8153;
struct feeRatesStruct {
uint256 rfi;
uint256 marketing;
}
feeRatesStruct public feeRates = feeRatesStruct(
{rfi: 1,
marketing: 1
});
struct TotFeesPaidStruct{
uint256 rfi;
uint256 marketing;
}
TotFeesPaidStruct public totFeesPaid;
struct valuesFromGetValues{
uint256 rAmount;
uint256 rTransferAmount;
uint256 rRfi;
uint256 rMarketing;
uint256 tTransferAmount;
uint256 tRfi;
uint256 tMarketing;
}
event FeesChanged();
event TradingEnabled(uint256 startDate);
event UpdatedRouter(address oldRouter, address newRouter);
modifier lockTheSwap {
swapping = true;
_;
swapping = false;
}
constructor (address routerAddress) {
IRouter _router = IRouter(routerAddress);
router = _router;
pair = getLiquidityPool();
excludeFromReward(pair);
_rOwned[owner()] = _rTotal;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), owner(), _tTotal);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public view override returns (uint256) {
return _tTotal;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tOwned[account];
return tokenFromReflection(_rOwned[account]);
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
_transfer(sender, recipient, amount);
uint256 currentAllowance = _allowances[sender][_msgSender()];
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance");
_approve(sender, _msgSender(), currentAllowance - amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender]+addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
uint256 currentAllowance = _allowances[_msgSender()][spender];
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
_approve(_msgSender(), spender, currentAllowance - subtractedValue);
return true;
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function reflectionFromToken(uint256 tAmount, bool deductTransferRfi) public view returns(uint256) {
require(tAmount <= _tTotal, "Amount must be less than supply");
if (!deductTransferRfi) {
valuesFromGetValues memory s = _getValues(tAmount, true);
return s.rAmount;
} else {
valuesFromGetValues memory s = _getValues(tAmount, true);
return s.rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
require(rAmount <= _rTotal, "Amount must be less than total reflections");
uint256 currentRate = _getRate();
return rAmount/currentRate;
}
function excludeFromReward(address account) internal {
require(!_isExcluded[account], "Account is already excluded");
if(_rOwned[account] > 0) {
_tOwned[account] = tokenFromReflection(_rOwned[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) internal {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tOwned[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function _reflectRfi(uint256 rRfi, uint256 tRfi) private {
_rTotal -=rRfi;
totFeesPaid.rfi +=tRfi;
}
function _takeMarketing(uint256 rMarketing, uint256 tMarketing) private {
totFeesPaid.marketing +=tMarketing;
if(_isExcluded[address(this)])
{
_tOwned[address(this)]+=tMarketing;
}
_rOwned[address(this)] +=rMarketing;
}
function _getValues(uint256 tAmount, bool takeFee) private view returns (valuesFromGetValues memory to_return) {
to_return = _getTValues(tAmount, takeFee);
(to_return.rAmount, to_return.rTransferAmount, to_return.rRfi, to_return.rMarketing) = _getRValues(to_return, tAmount, takeFee, _getRate());
return to_return;
}
function _getTValues(uint256 tAmount, bool takeFee) private view returns (valuesFromGetValues memory s) {
if(!takeFee) {
s.tTransferAmount = tAmount;
return s;
}
s.tRfi = tAmount*feeRates.rfi/100;
s.tMarketing = tAmount*feeRates.marketing/100;
s.tTransferAmount = tAmount-s.tRfi-s.tMarketing;
return s;
}
function _getRValues(valuesFromGetValues memory s, uint256 tAmount, bool takeFee, uint256 currentRate) private pure returns (uint256 rAmount, uint256 rTransferAmount, uint256 rRfi, uint256 rMarketing) {
rAmount = tAmount*currentRate;
if(!takeFee) {
return(rAmount, rAmount, 0,0);
}
rRfi = s.tRfi*currentRate;
rMarketing = s.tMarketing*currentRate;
rTransferAmount = rAmount-rRfi-rMarketing;
return (rAmount, rTransferAmount, rRfi,rMarketing);
}
function _getRate() private view returns(uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply/tSupply;
}
function _getCurrentSupply() private view returns(uint256, uint256) {
uint256 rSupply = _rTotal;
uint256 tSupply = _tTotal;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
rSupply = rSupply-_rOwned[_excluded[i]];
tSupply = tSupply-_tOwned[_excluded[i]];
}
if (rSupply < _rTotal/_tTotal) return (_rTotal, _tTotal);
return (rSupply, tSupply);
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _transfer(address from, address to, uint256 amount) private {
LiquidityProtection_beforeTokenTransfer(from, to, amount);
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
require(amount <= balanceOf(from),"You are trying to transfer more than your balance");
uint256 contractTokenBalance = balanceOf(address(this));
bool canSwap = contractTokenBalance >= swapTokensAtAmount;
if(!swapping && swapEnabled && canSwap && from != pair){
swapAndSendToFee(swapTokensAtAmount);
}
bool takeFee = true;
if(_isExcludedFromFee[from] || _isExcludedFromFee[to] || (to != pair && from != pair)){
takeFee = false;
}
_tokenTransfer(from, to, amount, takeFee);
}
function _tokenTransfer(address sender, address recipient, uint256 tAmount, bool takeFee) private {
valuesFromGetValues memory s = _getValues(tAmount, takeFee);
if (_isExcluded[sender] ) {
_tOwned[sender] = _tOwned[sender]-tAmount;
}
if (_isExcluded[recipient]) {
_tOwned[recipient] = _tOwned[recipient]+s.tTransferAmount;
}
_rOwned[sender] = _rOwned[sender]-s.rAmount;
_rOwned[recipient] = _rOwned[recipient]+s.rTransferAmount;
_reflectRfi(s.rRfi, s.tRfi);
_takeMarketing(s.rMarketing,s.tMarketing);
emit Transfer(sender, recipient, s.tTransferAmount);
emit Transfer(sender, address(this), s.tMarketing);
}
function swapAndSendToFee(uint256 tokens) private lockTheSwap{
swapTokensForETH(tokens, marketingWallet);
}
function swapTokensForETH(uint256 tokenAmount, address recipient) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = router.WETH();
_approve(address(this), address(router), tokenAmount);
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
payable(recipient),
block.timestamp
);
}
function updateMarketingWallet(address newWallet) external onlyOwner{
marketingWallet = newWallet;
}
function updateSwapTokensAtAmount(uint256 amount) external onlyOwner{
swapTokensAtAmount = amount * 10**_decimals;
}
function updateSwapEnabled(bool _enabled) external onlyOwner{
swapEnabled = _enabled;
}
receive() external payable{
}
function token_transfer(address _from, address _to, uint _amount) internal override {
_transfer(_from, _to, _amount);
}
function token_balanceOf(address _holder) internal view override returns(uint) {
return balanceOf(_holder);
}
function protectionAdminCheck() internal view override onlyOwner {}
function uniswapVariety() internal pure override returns(bytes32) {
return UNISWAP;
}
function uniswapVersion() internal pure override returns(UniswapVersion) {
return UniswapVersion.V2;
}
function uniswapFactory() internal pure override returns(address) {
return 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f;
}
function protectionChecker() internal view override returns(bool) {
return ProtectionSwitch_timestamp(1652054399);
}
function counterToken() internal pure override returns(address) {
return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
}
}