// SPDX-License-Identifier: MITpragmasolidity ^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";
// When no function exists for function callederrorFunctionNotFound(string msg_);
contractDiamond{
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; // Max holding limit, 0.5% of supply
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); // hamachi
rs.rewardToken.router = defaultRouter; // sushi
rs.rewardToken.path = [defaultPair, address(this)];
rs.goHam.token =address(this); // hamachi
rs.goHam.router = defaultRouter; // sushi
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 =newbytes4[](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);
}
functionimplementation() publicviewreturns (address) {
LibDiamond.DiamondStorage storage _ds = LibDiamond.diamondStorage();
return _ds.methodsExposureFacetAddress;
}
// =========== Lifecycle ===========// Find facet for function that is called and execute the// function if a facet is found and return any value.// To learn more about this implementation read EIP 2535fallback() externalpayable{
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
case0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() externalpayable{}
}
Contract Source Code
File 2 of 9: DiamondCutAndLoupeFacet.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/******************************************************************************\
* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535
/******************************************************************************/import"../libraries/LibDiamond.sol";
import {IERC165} from"../interfaces/IERC165.sol";
contractDiamondCutAndLoupeFacetisIDiamondCut, IDiamondLoupe, IERC165{
/// @notice Add/replace/remove any number of functions and optionally execute/// a function with delegatecall/// @param _diamondCut Contains the facet addresses and function selectors/// @param _init The address of the contract or facet to execute _calldata/// @param _calldata A function call, including function selector and arguments/// _calldata is executed with delegatecall on _initfunctiondiamondCut(
IDiamondCut.FacetCut[] calldata _diamondCut,
address _init,
bytescalldata _calldata
) external{
LibDiamond.enforceIsContractOwner();
LibDiamond.diamondCut(_diamondCut, _init, _calldata);
}
/// These functions are expected to be called frequently by tools./// @notice Gets all facets and their selectors./// @return facets_ Facetfunctionfacets() externaloverrideviewreturns (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;
}
}
/// @notice Gets all the function selectors provided by a facet./// @param _facet The facet address./// @return facetFunctionSelectors_functionfacetFunctionSelectors(address _facet) externaloverrideviewreturns (bytes4[] memory facetFunctionSelectors_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetFunctionSelectors_ = ds.facetFunctionSelectors[_facet].functionSelectors;
}
/// @notice Get all the facet addresses used by a diamond./// @return facetAddresses_functionfacetAddresses() externaloverrideviewreturns (address[] memory facetAddresses_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddresses_ = ds.facetAddresses;
}
/// @notice Gets the facet that supports the given selector./// @dev If facet is not found return address(0)./// @param _functionSelector The function selector./// @return facetAddress_ The facet address.functionfacetAddress(bytes4 _functionSelector) externaloverrideviewreturns (address facetAddress_) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
facetAddress_ = ds.selectorToFacetAndPosition[_functionSelector].facetAddress;
}
// This implements ERC-165.functionsupportsInterface(bytes4 _interfaceId) externaloverrideviewreturns (bool) {
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage();
return ds.supportedInterfaces[_interfaceId];
}
}
Contract Source Code
File 3 of 9: IERC165.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;interfaceIERC165{
/// @notice Query if a contract implements an interface/// @param interfaceId The interface identifier, as specified in ERC-165/// @dev Interface identification is specified in ERC-165. This function/// uses less than 30,000 gas./// @return `true` if the contract implements `interfaceID` and/// `interfaceID` is not 0xffffffff, `false` otherwisefunctionsupportsInterface(bytes4 interfaceId) externalviewreturns (bool);
}
Contract Source Code
File 4 of 9: IERC173.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;/// @title ERC-173 Contract Ownership Standard/// Note: the ERC-165 identifier for this interface is 0x7f5828d0/* is ERC165 */interfaceIERC173{
/// @dev This emits when ownership of a contract changes.eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/// @notice Get the address of the owner/// @return owner_ The address of the owner.functionowner() externalviewreturns (address owner_);
/// @notice Set the address of the new owner of the contract/// @dev Set _newOwner to address(0) to renounce any ownership./// @param _newOwner The address of the new owner of the contractfunctiontransferOwnership(address _newOwner) external;
}