编译器
0.8.13+commit.abaa5c0e
文件 1 的 9:Diamond.sol
pragma solidity ^0.8.13;
import "./libraries/LibDiamond.sol";
import {DiamondCutAndLoupeFacet} from "./facets/DiamondCutAndLoupeFacet.sol";
import {IERC173} from "./interfaces/IERC173.sol";
import {IERC165} from "./interfaces/IERC165.sol";
import {IERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/interfaces/IERC20Upgradeable.sol";
import {IUniswapV2Router02} from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Factory} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
error FunctionNotFound(string msg_);
contract Diamond {
constructor(
address liquidityWallet,
address defaultRouter,
address defaultPair,
address diamondCutAndLoupeFacetAddress,
address methodsExposureFacetAddress
) payable {
LibDiamond.setContractOwner(msg.sender);
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
LibDiamond.RewardStorage storage rs = LibDiamond.rewardStorage();
ds.fee.liquidityBuyFee = 100;
ds.fee.rewardBuyFee = 600;
ds.fee.liquiditySellFee = 100;
ds.fee.rewardSellFee = 600;
ds.numTokensToSwap = 5_000_000 * 10**18;
ds.maxTokenPerWallet = 250_000_000 * 10**18;
ds.defaultRouter = defaultRouter;
ds.swapRouters[defaultRouter] = true;
ds.processingGas = 750_000;
ds.processingFees = false;
rs.minRewardBalance = 1000 * 10**18;
rs.claimTimeout = 3600;
ds.liquidityWallet = liquidityWallet;
ds.methodsExposureFacetAddress = methodsExposureFacetAddress;
rs.rewardToken.token = address(this);
rs.rewardToken.router = defaultRouter;
rs.rewardToken.path = [defaultPair, address(this)];
rs.goHam.token = address(this);
rs.goHam.router = defaultRouter;
rs.goHam.path = [defaultPair, address(this)];
ds.supportedInterfaces[type(IDiamondCut).interfaceId] = true;
ds.supportedInterfaces[type(IDiamondLoupe).interfaceId] = true;
ds.supportedInterfaces[type(IERC173).interfaceId] = true;
ds.supportedInterfaces[type(IERC165).interfaceId] = true;
ds.supportedInterfaces[type(IERC20Upgradeable).interfaceId] = true;
bytes4[] memory selectors = new bytes4[](6);
selectors[0] = DiamondCutAndLoupeFacet.diamondCut.selector;
selectors[1] = DiamondCutAndLoupeFacet.facets.selector;
selectors[2] = DiamondCutAndLoupeFacet.facetFunctionSelectors.selector;
selectors[3] = DiamondCutAndLoupeFacet.facetAddresses.selector;
selectors[4] = DiamondCutAndLoupeFacet.facetAddress.selector;
selectors[5] = DiamondCutAndLoupeFacet.supportsInterface.selector;
IUniswapV2Router02 router = IUniswapV2Router02(defaultRouter);
address swapPair = IUniswapV2Factory(router.factory()).createPair(
address(this),
router.WETH()
);
ds.lpPools[address(swapPair)] = true;
LibDiamond.addFunctions(diamondCutAndLoupeFacetAddress, selectors);
}
function implementation() public view returns (address) {
LibDiamond.DiamondStorage storage _ds = LibDiamond.diamondStorage();
return _ds.methodsExposureFacetAddress;
}
fallback() external payable {
address facet = LibDiamond
.diamondStorage()
.selectorToFacetAndPosition[msg.sig]
.facetAddress;
if (facet == address(0)) revert FunctionNotFound("Diamond: Function does not exist");
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), facet, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {}
}
文件 2 的 9:DiamondCutAndLoupeFacet.sol
pragma solidity ^0.8.0;
import "../libraries/LibDiamond.sol";
import {IERC165} from "../interfaces/IERC165.sol";
contract DiamondCutAndLoupeFacet is IDiamondCut, IDiamondLoupe, IERC165 {
function diamondCut(
IDiamondCut.FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external {
LibDiamond.enforceIsContractOwner();
LibDiamond.diamondCut(_diamondCut, _init, _calldata);
}
function facets() external override view returns (Facet[] memory facets_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
uint256 numFacets = ds.facetAddresses.length;
facets_ = new Facet[](numFacets);
for (uint256 i; i < numFacets; i++) {
address facetAddress_ = ds.facetAddresses[i];
facets_[i].facetAddress = facetAddress_;
facets_[i].functionSelectors = ds.facetFunctionSelectors[facetAddress_].functionSelectors;
}
}
function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory facetFunctionSelectors_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetFunctionSelectors_ = ds.facetFunctionSelectors[_facet].functionSelectors;
}
function facetAddresses() external override view returns (address[] memory facetAddresses_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddresses_ = ds.facetAddresses;
}
function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddress_ = ds.selectorToFacetAndPosition[_functionSelector].facetAddress;
}
function supportsInterface(bytes4 _interfaceId) external override view returns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.supportedInterfaces[_interfaceId];
}
}
文件 3 的 9:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 4 的 9:IERC173.sol
pragma solidity ^0.8.0;
interface IERC173 {
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function owner() external view returns (address owner_);
function transferOwnership(address _newOwner) external;
}
文件 5 的 9:IERC20Upgradeable.sol
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20Upgradeable.sol";
文件 6 的 9:IUniswapV2Factory.sol
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
文件 7 的 9:IUniswapV2Router01.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
文件 8 的 9:IUniswapV2Router02.sol
pragma solidity >=0.6.2;
import './IUniswapV2Router01.sol';
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
}
文件 9 的 9:LibDiamond.sol
pragma solidity ^0.8.0;
interface IDiamondCut {
enum FacetCutAction {
Add,
Replace,
Remove
}
struct FacetCut {
address facetAddress;
FacetCutAction action;
bytes4[] functionSelectors;
}
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external;
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);
}
interface IDiamondLoupe {
struct Facet {
address facetAddress;
bytes4[] functionSelectors;
}
function facets() external view returns (Facet[] memory facets_);
function facetFunctionSelectors(address _facet)
external
view
returns (bytes4[] memory facetFunctionSelectors_);
function facetAddresses()
external
view
returns (address[] memory facetAddresses_);
function facetAddress(bytes4 _functionSelector)
external
view
returns (address facetAddress_);
}
library LibDiamond {
bytes32 constant DIAMOND_STORAGE_POSITION =
keccak256("diamond.standard.diamond.storage");
bytes32 constant REWARD_STORAGE_POSITION =
keccak256("diamond.standard.reward.storage");
address public constant BURN_ADDRESS =
0x000000000000000000000000000000000000dEaD;
bytes32 public constant VESTING_ROLE = keccak256("VESTING_ROLE");
bytes32 public constant EXCLUDED_FROM_FEE_ROLE =
keccak256("EXCLUDED_FROM_FEE_ROLE");
bytes32 public constant EXCLUDED_FROM_MAX_WALLET_ROLE =
keccak256("EXCLUDED_FROM_MAX_WALLET_ROLE");
bytes32 public constant EXCLUDED_FROM_REWARD_ROLE =
keccak256("EXCLUDED_FROM_REWARD_ROLE");
uint256 internal constant MAGNITUDE = 2**128;
uint32 public constant PERCENTAGE_DENOMINATOR = 10000;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
event DiamondCut(
IDiamondCut.FacetCut[] _diamondCut,
address _init,
bytes _calldata
);
struct FacetAddressAndPosition {
address facetAddress;
uint16 functionSelectorPosition;
}
struct FacetFunctionSelectors {
bytes4[] functionSelectors;
uint16 facetAddressPosition;
}
struct DiamondStorage {
mapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;
mapping(address => FacetFunctionSelectors) facetFunctionSelectors;
address[] facetAddresses;
mapping(bytes4 => bool) supportedInterfaces;
address contractOwner;
string name;
string symbol;
address methodsExposureFacetAddress;
address liquidityWallet;
address defaultRouter;
uint256 numTokensToSwap;
uint256 maxTokenPerWallet;
mapping(address => bool) lpPools;
mapping(address => bool) swapRouters;
uint32 processingGas;
bool processingFees;
Fee fee;
}
function diamondStorage()
internal
pure
returns (DiamondStorage storage ds)
{
bytes32 position = DIAMOND_STORAGE_POSITION;
assembly {
ds.slot := position
}
}
struct Fee {
uint32 liquidityBuyFee;
uint32 rewardBuyFee;
uint32 liquiditySellFee;
uint32 rewardSellFee;
}
struct RewardToken {
address token;
address router;
address[] path;
}
struct Map {
address[] keys;
mapping(address => uint256) values;
mapping(address => uint256) indexOf;
mapping(address => bool) inserted;
}
struct RewardStorage {
mapping(address => int256) magnifiedReward;
mapping(address => uint256) withdrawnReward;
mapping(address => uint256) claimTimes;
mapping(address => bool) manualClaim;
mapping(address => uint256) rewardBalances;
uint256 totalRewardSupply;
RewardToken rewardToken;
RewardToken goHam;
Map rewardHolders;
uint256 magnifiedRewardPerShare;
uint256 minRewardBalance;
uint256 totalAccruedReward;
uint256 lastProcessedIndex;
uint32 claimTimeout;
}
function rewardStorage() internal pure returns (RewardStorage storage rs) {
bytes32 position = REWARD_STORAGE_POSITION;
assembly {
rs.slot := position
}
}
function setContractOwner(address _newOwner) internal {
DiamondStorage storage ds = diamondStorage();
address previousOwner = ds.contractOwner;
ds.contractOwner = _newOwner;
emit OwnershipTransferred(previousOwner, _newOwner);
}
function contractOwner() internal view returns (address contractOwner_) {
contractOwner_ = diamondStorage().contractOwner;
}
function enforceIsContractOwner() internal view {
require(
msg.sender == diamondStorage().contractOwner,
"LibDiamond: Must be contract owner"
);
}
function diamondCut(
IDiamondCut.FacetCut[] memory _diamondCut,
address _init,
bytes memory _calldata
) internal {
for (
uint256 facetIndex;
facetIndex < _diamondCut.length;
facetIndex++
) {
IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action;
if (action == IDiamondCut.FacetCutAction.Add) {
addFunctions(
_diamondCut[facetIndex].facetAddress,
_diamondCut[facetIndex].functionSelectors
);
} else if (action == IDiamondCut.FacetCutAction.Replace) {
replaceFunctions(
_diamondCut[facetIndex].facetAddress,
_diamondCut[facetIndex].functionSelectors
);
} else if (action == IDiamondCut.FacetCutAction.Remove) {
removeFunctions(
_diamondCut[facetIndex].facetAddress,
_diamondCut[facetIndex].functionSelectors
);
} else {
revert("LibDiamondCut: Incorrect FacetCutAction");
}
}
emit DiamondCut(_diamondCut, _init, _calldata);
initializeDiamondCut(_init, _calldata);
}
function addFunctions(
address _facetAddress,
bytes4[] memory _functionSelectors
) internal {
require(
_functionSelectors.length > 0,
"LibDiamondCut: No selectors in facet to cut"
);
DiamondStorage storage ds = diamondStorage();
require(
_facetAddress != address(0),
"LibDiamondCut: Add facet can't be address(0)"
);
uint16 selectorPosition = uint16(
ds.facetFunctionSelectors[_facetAddress].functionSelectors.length
);
if (selectorPosition == 0) {
enforceHasContractCode(
_facetAddress,
"LibDiamondCut: New facet has no code"
);
ds
.facetFunctionSelectors[_facetAddress]
.facetAddressPosition = uint16(ds.facetAddresses.length);
ds.facetAddresses.push(_facetAddress);
}
for (
uint256 selectorIndex;
selectorIndex < _functionSelectors.length;
selectorIndex++
) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds
.selectorToFacetAndPosition[selector]
.facetAddress;
require(
oldFacetAddress == address(0),
"LibDiamondCut: Can't add function that already exists"
);
ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(
selector
);
ds
.selectorToFacetAndPosition[selector]
.facetAddress = _facetAddress;
ds
.selectorToFacetAndPosition[selector]
.functionSelectorPosition = selectorPosition;
selectorPosition++;
}
}
function replaceFunctions(
address _facetAddress,
bytes4[] memory _functionSelectors
) internal {
require(
_functionSelectors.length > 0,
"LibDiamondCut: No selectors in facet to cut"
);
DiamondStorage storage ds = diamondStorage();
require(
_facetAddress != address(0),
"LibDiamondCut: Add facet can't be address(0)"
);
uint16 selectorPosition = uint16(
ds.facetFunctionSelectors[_facetAddress].functionSelectors.length
);
if (selectorPosition == 0) {
enforceHasContractCode(
_facetAddress,
"LibDiamondCut: New facet has no code"
);
ds
.facetFunctionSelectors[_facetAddress]
.facetAddressPosition = uint16(ds.facetAddresses.length);
ds.facetAddresses.push(_facetAddress);
}
for (
uint256 selectorIndex;
selectorIndex < _functionSelectors.length;
selectorIndex++
) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds
.selectorToFacetAndPosition[selector]
.facetAddress;
require(
oldFacetAddress != _facetAddress,
"LibDiamondCut: Can't replace function with same function"
);
removeFunction(oldFacetAddress, selector);
ds
.selectorToFacetAndPosition[selector]
.functionSelectorPosition = selectorPosition;
ds.facetFunctionSelectors[_facetAddress].functionSelectors.push(
selector
);
ds
.selectorToFacetAndPosition[selector]
.facetAddress = _facetAddress;
selectorPosition++;
}
}
function removeFunctions(
address _facetAddress,
bytes4[] memory _functionSelectors
) internal {
require(
_functionSelectors.length > 0,
"LibDiamondCut: No selectors in facet to cut"
);
DiamondStorage storage ds = diamondStorage();
require(
_facetAddress == address(0),
"LibDiamondCut: Remove facet address must be address(0)"
);
for (
uint256 selectorIndex;
selectorIndex < _functionSelectors.length;
selectorIndex++
) {
bytes4 selector = _functionSelectors[selectorIndex];
address oldFacetAddress = ds
.selectorToFacetAndPosition[selector]
.facetAddress;
removeFunction(oldFacetAddress, selector);
}
}
function removeFunction(address _facetAddress, bytes4 _selector) internal {
DiamondStorage storage ds = diamondStorage();
require(
_facetAddress != address(0),
"LibDiamondCut: Can't remove function that doesn't exist"
);
require(
_facetAddress != address(this),
"LibDiamondCut: Can't remove immutable function"
);
uint256 selectorPosition = ds
.selectorToFacetAndPosition[_selector]
.functionSelectorPosition;
uint256 lastSelectorPosition = ds
.facetFunctionSelectors[_facetAddress]
.functionSelectors
.length - 1;
if (selectorPosition != lastSelectorPosition) {
bytes4 lastSelector = ds
.facetFunctionSelectors[_facetAddress]
.functionSelectors[lastSelectorPosition];
ds.facetFunctionSelectors[_facetAddress].functionSelectors[
selectorPosition
] = lastSelector;
ds
.selectorToFacetAndPosition[lastSelector]
.functionSelectorPosition = uint16(selectorPosition);
}
ds.facetFunctionSelectors[_facetAddress].functionSelectors.pop();
delete ds.selectorToFacetAndPosition[_selector];
if (lastSelectorPosition == 0) {
uint256 lastFacetAddressPosition = ds.facetAddresses.length - 1;
uint256 facetAddressPosition = ds
.facetFunctionSelectors[_facetAddress]
.facetAddressPosition;
if (facetAddressPosition != lastFacetAddressPosition) {
address lastFacetAddress = ds.facetAddresses[
lastFacetAddressPosition
];
ds.facetAddresses[facetAddressPosition] = lastFacetAddress;
ds
.facetFunctionSelectors[lastFacetAddress]
.facetAddressPosition = uint16(facetAddressPosition);
}
ds.facetAddresses.pop();
delete ds
.facetFunctionSelectors[_facetAddress]
.facetAddressPosition;
}
}
function initializeDiamondCut(address _init, bytes memory _calldata)
internal
{
if (_init == address(0)) {
require(
_calldata.length == 0,
"LibDiamondCut: _init is address(0) but_calldata is not empty"
);
} else {
require(
_calldata.length > 0,
"LibDiamondCut: _calldata is empty but _init is not address(0)"
);
if (_init != address(this)) {
enforceHasContractCode(
_init,
"LibDiamondCut: _init address has no code"
);
}
(bool success, bytes memory error) = _init.delegatecall(_calldata);
if (!success) {
if (error.length > 0) {
revert(string(error));
} else {
revert("LibDiamondCut: _init function reverted");
}
}
}
}
function enforceHasContractCode(
address _contract,
string memory _errorMessage
) internal view {
uint256 contractSize;
assembly {
contractSize := extcodesize(_contract)
}
require(contractSize > 0, _errorMessage);
}
}
contract WithStorage {
function _ds() internal pure returns (LibDiamond.DiamondStorage storage) {
return LibDiamond.diamondStorage();
}
function _rs() internal pure returns (LibDiamond.RewardStorage storage) {
return LibDiamond.rewardStorage();
}
}
{
"compilationTarget": {
"contracts/hamachi/Diamond.sol": "Diamond"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 99999
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"liquidityWallet","type":"address"},{"internalType":"address","name":"defaultRouter","type":"address"},{"internalType":"address","name":"defaultPair","type":"address"},{"internalType":"address","name":"diamondCutAndLoupeFacetAddress","type":"address"},{"internalType":"address","name":"methodsExposureFacetAddress","type":"address"}],"stateMutability":"payable","type":"constructor"},{"inputs":[{"internalType":"string","name":"msg_","type":"string"}],"name":"FunctionNotFound","type":"error"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]