编译器
0.8.23+commit.f704f362
文件 1 的 21:Context.sol
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
文件 2 的 21:ECDSA.sol
pragma solidity ^0.8.20;
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
error ECDSAInvalidSignature();
error ECDSAInvalidSignatureLength(uint256 length);
error ECDSAInvalidSignatureS(bytes32 s);
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return;
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}
文件 3 的 21:ERC20.sol
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
function name() public view virtual returns (string memory) {
return _name;
}
function symbol() public view virtual returns (string memory) {
return _symbol;
}
function decimals() public view virtual returns (uint8) {
return 18;
}
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
_totalSupply -= value;
}
} else {
unchecked {
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}
文件 4 的 21:ERC20Burnable.sol
pragma solidity ^0.8.20;
import {ERC20} from "../ERC20.sol";
import {Context} from "../../../utils/Context.sol";
abstract contract ERC20Burnable is Context, ERC20 {
function burn(uint256 value) public virtual {
_burn(_msgSender(), value);
}
function burnFrom(address account, uint256 value) public virtual {
_spendAllowance(account, _msgSender(), value);
_burn(account, value);
}
}
文件 5 的 21:IERC1271.sol
pragma solidity ^0.8.20;
interface IERC1271 {
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}
文件 6 的 21:IERC20.sol
pragma solidity ^0.8.20;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 7 的 21:IERC20Metadata.sol
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
interface IERC20Metadata is IERC20 {
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
}
文件 8 的 21:IMoonshotFactory.sol
pragma solidity ^0.8.23;
interface IMoonshotFactory {
error InvalidSignature();
error SignatureIsUsed();
error FailedToSendETH();
error NotReadyForMigration();
error TotalSupplyZeroValue();
error VirtualTokenReservesZeroValue();
error VirtualCollateralReservesZeroValue();
error McUpperLimitZeroValue();
error McLowerLimitZeroValue();
error TokensMigrationThresholdZeroValue();
error TreasuryZeroValue();
error DexTreasuryZeroValue();
error SignerZeroValue();
error McLowerLimitGreaterThanUpperLimit();
error FeeBPSCheckFailed();
event SetConfig(
uint256 totalSupply,
uint256 virtualTokenReserves,
uint256 virtualCollateralReserves,
uint256 feeBasisPoints,
uint256 dexFeeBasisPoints,
uint256 migrationFeeFixed,
uint256 poolCreationFee,
uint256 mcUpperLimit,
uint256 mcLowerLimit,
uint256 tokensMigrationThreshold,
address treasury,
address dexTreasury,
address signer
);
event NewMoonshotToken(address addr, address creator, bytes signature);
event NewMoonshotTokenAndBuy(
address addr,
address creator,
bytes signature,
uint256 tokenAmount,
uint256 collateralAmount,
uint256 fee,
uint256 dexFee,
uint256 curveProgressBps
);
event MarketcapReached(address token);
event Migrated(
address token,
uint256 tokensToMigrate,
uint256 tokensToBurn,
uint256 collateralToMigrate,
uint256 migrationFee,
address pair
);
event BuyExactOut(
address indexed buyer,
address indexed token,
uint256 tokenAmount,
uint256 curvePositionAfterTrade,
uint256 collateralAmount,
uint256 refund,
uint256 fee,
uint256 dexFee,
uint256 curveProgressBps
);
event BuyExactIn(
address indexed buyer,
address indexed token,
uint256 tokenAmount,
uint256 curvePositionAfterTrade,
uint256 collateralAmount,
uint256 fee,
uint256 dexFee,
uint256 curveProgressBps
);
event SellExactIn(
address indexed seller,
address indexed token,
uint256 tokenAmount,
uint256 curvePositionAfterTrade,
uint256 collateralAmount,
uint256 fee,
uint256 dexFee,
uint256 curveProgressBps
);
event SellExactOut(
address indexed seller,
address indexed token,
uint256 tokenAmount,
uint256 curvePositionAfterTrade,
uint256 collateralAmount,
uint256 fee,
uint256 dexFee,
uint256 curveProgressBps
);
function buyExactOut(address _token, uint256 _tokenAmount, uint256 _maxCollateralAmount) external payable;
function buyExactIn(address _token, uint256 _amountOutMin) external payable;
function sellExactIn(address _token, uint256 _tokenAmount, uint256 _amountCollateralMin) external;
function sellExactOut(address _token, uint256 _tokenAmountMax, uint256 _amountCollateral) external;
function setConfig(
uint256 _totalSupply,
uint256 _virtualTokenReserves,
uint256 _virtualCollateralReserves,
uint256 _feeBasisPoints,
uint256 _dexFeeBasisPoints,
uint256 _migrationFeeFixed,
uint256 _poolCreationFee,
uint256 _mcUpperLimit,
uint256 _mcLowerLimit,
uint256 _tokensMigrationThreshold,
address _treasury,
address _dexTreasury,
address _signer
) external;
function createMoonshotToken(
string memory _name,
string memory _symbol,
uint256 _nonce,
bytes memory _signature
) external returns (address);
function createMoonshotTokenAndBuy(
string memory _name,
string memory _symbol,
uint256 _nonce,
uint256 _tokenAmountMin,
bytes memory _signature
) external payable returns (address);
}
文件 9 的 21:IMoonshotToken.sol
pragma solidity ^0.8.23;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IMoonshotToken is IERC20 {
enum CurveType {
ConstantProductV1
}
struct ConstructorParams {
string name;
string symbol;
address creator;
uint256 totalSupply;
uint256 virtualTokenReserves;
uint256 virtualCollateralReserves;
uint256 feeBasisPoints;
uint256 dexFeeBasisPoints;
uint256 migrationFeeFixed;
uint256 poolCreationFee;
uint256 mcLowerLimit;
uint256 mcUpperLimit;
uint256 tokensMigrationThreshold;
address treasury;
address uniV2Router;
address dexTreasury;
}
error NotEnoughETHReserves();
error InsufficientTokenReserves();
error FailedToSendETH();
error NotEnoughtETHToBuyTokens();
error SlippageCheckFailed();
error MarketcapThresholdReached();
error SendingToPairIsNotAllowedBeforeMigration();
error TradingStopped();
error OnlyFactory();
function buyExactOut(
uint256 _tokenAmount,
uint256 _maxCollateralAmount
) external payable returns (uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee);
function buyExactIn(
uint256 _amountOutMin
) external payable returns (uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee);
function sellExactIn(
uint256 _tokenAmount,
uint256 _amountOutMin
) external payable returns (uint256 collateralToReceiveMinusFee, uint256 helioFee, uint256 dexFee);
function sellExactOut(
uint256 _tokenAmountMax,
uint256 _amountCollateral
)
external
payable
returns (uint256 collateralToReceiveMinusFee, uint256 tokensOut, uint256 helioFee, uint256 dexFee);
function getAmountOutAndFee(
uint256 _amountIn,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsIn
) external view returns (uint256 amountOut, uint256 fee);
function getAmountInAndFee(
uint256 _amountOut,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsOut
) external view returns (uint256 amountIn, uint256 fee);
function migrate() external returns (uint256 tokensToMigrate, uint256 tokensToBurn, uint256 collateralAmount);
function getCurveProgressBps() external view returns (uint256);
function getMarketCap() external view returns (uint256);
}
文件 10 的 21:IUniswapV2Factory.sol
pragma solidity ^0.8.23;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
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 feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function createPair(address tokenA, address tokenB) external returns (address pair);
}
文件 11 的 21:IUniswapV2Router02.sol
pragma solidity >=0.6.2;
interface IUniswapV2Router02 {
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);
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;
}
文件 12 的 21:Math.sol
pragma solidity ^0.8.20;
library Math {
error MathOverflowedMulDiv();
enum Rounding {
Floor,
Ceil,
Trunc,
Expand
}
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
return a / b;
}
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0 = x * y;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (0 - denominator);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
文件 13 的 21:MessageHashUtils.sol
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
library MessageHashUtils {
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, messageHash)
digest := keccak256(0x00, 0x3c)
}
}
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}
文件 14 的 21:MoonshotFactory.sol
pragma solidity ^0.8.23;
import {MoonshotToken} from "./MoonshotToken.sol";
import {IMoonshotFactory} from "./interfaces/IMoonshotFactory.sol";
import {IMoonshotToken} from "./interfaces/IMoonshotToken.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
contract MoonshotFactory is IMoonshotFactory, Ownable, ReentrancyGuard {
uint256 public totalSupply;
uint256 public virtualTokenReserves;
uint256 public virtualCollateralReserves;
uint256 public feeBasisPoints;
uint256 public mcUpperLimit;
uint256 public mcLowerLimit;
uint256 public tokensMigrationThreshold;
uint256 public migrationFeeFixed;
uint256 public poolCreationFee;
uint256 public dexFeeBasisPoints;
address public dexTreasury;
address public treasury;
address public immutable UNISWAP_V2_ROUTER;
address public signer;
mapping(bytes32 => bool) public usedSignatures;
mapping(address => bool) public readyForMigration;
address[] public moonshotTokens;
uint256 private constant MAX_BPS = 2_500;
constructor(
uint256 _totalSupply,
uint256 _virtualTokenReserves,
uint256 _virtualCollateralReserves,
uint256 _feeBasisPoints,
uint256 _dexFeeBasisPoints,
uint256 _migrationFeeFixed,
uint256 _poolCreationFee,
uint256 _mcUpperLimit,
uint256 _mcLowerLimit,
uint256 _tokensMigrationThreshold,
address _treasury,
address _dexTreasury,
address _uniswapV2Router,
address _signer
) Ownable(msg.sender) {
_setConfig(
_totalSupply,
_virtualTokenReserves,
_virtualCollateralReserves,
_feeBasisPoints,
_dexFeeBasisPoints,
_migrationFeeFixed,
_poolCreationFee,
_mcUpperLimit,
_mcLowerLimit,
_tokensMigrationThreshold,
_treasury,
_dexTreasury,
_signer
);
UNISWAP_V2_ROUTER = _uniswapV2Router;
}
function setConfig(
uint256 _totalSupply,
uint256 _virtualTokenReserves,
uint256 _virtualCollateralReserves,
uint256 _feeBasisPoints,
uint256 _dexFeeBasisPoints,
uint256 _migrationFeeFixed,
uint256 _poolCreationFee,
uint256 _mcUpperLimit,
uint256 _mcLowerLimit,
uint256 _tokensMigrationThreshold,
address _treasury,
address _dexTreasury,
address _signer
) external onlyOwner {
_setConfig(
_totalSupply,
_virtualTokenReserves,
_virtualCollateralReserves,
_feeBasisPoints,
_dexFeeBasisPoints,
_migrationFeeFixed,
_poolCreationFee,
_mcUpperLimit,
_mcLowerLimit,
_tokensMigrationThreshold,
_treasury,
_dexTreasury,
_signer
);
}
function createMoonshotToken(
string memory _name,
string memory _symbol,
uint256 _nonce,
bytes memory _signature
) external returns (address) {
_checkSignatureAndStore(_name, _symbol, _nonce, _signature);
MoonshotToken token = new MoonshotToken(
IMoonshotToken.ConstructorParams(
_name,
_symbol,
msg.sender,
totalSupply,
virtualTokenReserves,
virtualCollateralReserves,
feeBasisPoints,
dexFeeBasisPoints,
migrationFeeFixed,
poolCreationFee,
mcLowerLimit,
mcUpperLimit,
tokensMigrationThreshold,
treasury,
UNISWAP_V2_ROUTER,
dexTreasury
)
);
moonshotTokens.push(address(token));
emit NewMoonshotToken(address(token), msg.sender, _signature);
return address(token);
}
function createMoonshotTokenAndBuy(
string memory _name,
string memory _symbol,
uint256 _nonce,
uint256 _tokenAmountMin,
bytes memory _signature
) external payable nonReentrant returns (address) {
_checkSignatureAndStore(_name, _symbol, _nonce, _signature);
MoonshotToken token = new MoonshotToken(
IMoonshotToken.ConstructorParams(
_name,
_symbol,
msg.sender,
totalSupply,
virtualTokenReserves,
virtualCollateralReserves,
feeBasisPoints,
dexFeeBasisPoints,
migrationFeeFixed,
poolCreationFee,
mcLowerLimit,
mcUpperLimit,
tokensMigrationThreshold,
treasury,
UNISWAP_V2_ROUTER,
dexTreasury
)
);
(uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee) = token.buyExactIn{value: msg.value}(
_tokenAmountMin
);
uint256 tokenAmount = token.balanceOf(address(this));
token.transfer(msg.sender, tokenAmount);
moonshotTokens.push(address(token));
emit NewMoonshotTokenAndBuy(
address(token),
msg.sender,
_signature,
tokenAmount,
collateralToPayWithFee,
helioFee,
dexFee,
token.getCurveProgressBps()
);
return address(token);
}
function buyExactOut(
address _token,
uint256 _tokenAmount,
uint256 _maxCollateralAmount
) external payable nonReentrant {
(uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee) = IMoonshotToken(_token).buyExactOut{
value: msg.value
}(_tokenAmount, _maxCollateralAmount);
IMoonshotToken(_token).transfer(msg.sender, _tokenAmount);
uint256 refund = address(this).balance;
if (refund > 0) {
(bool sent, ) = msg.sender.call{value: refund}("");
if (!sent) revert FailedToSendETH();
}
emit BuyExactOut(
msg.sender,
_token,
_tokenAmount,
MoonshotToken(_token).totalSupply() - IMoonshotToken(_token).balanceOf(address(_token)),
collateralToPayWithFee,
refund,
helioFee,
dexFee,
IMoonshotToken(_token).getCurveProgressBps()
);
if (MoonshotToken(_token).tradingStopped()) {
readyForMigration[_token] = true;
emit MarketcapReached(_token);
}
}
function buyExactIn(address _token, uint256 _amountOutMin) external payable nonReentrant {
(uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee) = IMoonshotToken(_token).buyExactIn{
value: msg.value
}(_amountOutMin);
uint256 tokensOut = IMoonshotToken(_token).balanceOf(address(this));
IMoonshotToken(_token).transfer(msg.sender, tokensOut);
uint256 refund = address(this).balance;
if (refund > 0) {
(bool sent, ) = msg.sender.call{value: refund}("");
if (!sent) revert FailedToSendETH();
}
emit BuyExactIn(
msg.sender,
_token,
tokensOut,
MoonshotToken(_token).totalSupply() - IMoonshotToken(_token).balanceOf(address(_token)),
collateralToPayWithFee,
helioFee,
dexFee,
IMoonshotToken(_token).getCurveProgressBps()
);
if (MoonshotToken(_token).tradingStopped()) {
readyForMigration[_token] = true;
emit MarketcapReached(_token);
}
}
function sellExactIn(address _token, uint256 _tokenAmount, uint256 _amountCollateralMin) external nonReentrant {
MoonshotToken(_token).transferFrom(msg.sender, address(this), _tokenAmount);
(uint256 collateralToReceiveMinusFee, uint256 helioFee, uint256 dexFee) = MoonshotToken(_token).sellExactIn(
_tokenAmount,
_amountCollateralMin
);
(bool sent, ) = msg.sender.call{value: address(this).balance}("");
if (!sent) revert FailedToSendETH();
emit SellExactIn(
msg.sender,
_token,
_tokenAmount,
MoonshotToken(_token).totalSupply() - MoonshotToken(_token).balanceOf(address(_token)),
collateralToReceiveMinusFee,
helioFee,
dexFee,
IMoonshotToken(_token).getCurveProgressBps()
);
}
function sellExactOut(address _token, uint256 _tokenAmountMax, uint256 _amountCollateral) external nonReentrant {
MoonshotToken(_token).transferFrom(msg.sender, address(this), _tokenAmountMax);
(uint256 collateralToReceiveMinusFee, uint256 tokensOut, uint256 helioFee, uint256 dexFee) = MoonshotToken(
_token
).sellExactOut(_tokenAmountMax, _amountCollateral);
(bool sent, ) = msg.sender.call{value: address(this).balance}("");
if (!sent) revert FailedToSendETH();
emit SellExactOut(
msg.sender,
_token,
tokensOut,
MoonshotToken(_token).totalSupply() - MoonshotToken(_token).balanceOf(address(_token)),
collateralToReceiveMinusFee,
helioFee,
dexFee,
IMoonshotToken(_token).getCurveProgressBps()
);
}
function migrate(address _token) external {
if (!readyForMigration[_token]) revert NotReadyForMigration();
(uint256 tokensToMigrate, uint256 tokensToBurn, uint256 collateralAmount) = MoonshotToken(_token).migrate();
emit Migrated(
_token,
tokensToMigrate,
tokensToBurn,
collateralAmount,
MoonshotToken(_token).fixedMigrationFee() + MoonshotToken(_token).poolCreationFee(),
MoonshotToken(_token).pair()
);
}
function _setConfig(
uint256 _totalSupply,
uint256 _virtualTokenReserves,
uint256 _virtualCollateralReserves,
uint256 _feeBasisPoints,
uint256 _dexFeeBasisPoints,
uint256 _migrationFeeFixed,
uint256 _poolCreationFee,
uint256 _mcUpperLimit,
uint256 _mcLowerLimit,
uint256 _tokensMigrationThreshold,
address _treasury,
address _dexTreasury,
address _signer
) internal {
if (_totalSupply == 0) revert TotalSupplyZeroValue();
if (_virtualTokenReserves == 0) revert VirtualTokenReservesZeroValue();
if (_virtualCollateralReserves == 0) revert VirtualCollateralReservesZeroValue();
if (_mcLowerLimit == 0) revert McUpperLimitZeroValue();
if (_mcUpperLimit == 0) revert McLowerLimitZeroValue();
if (_tokensMigrationThreshold == 0) revert TokensMigrationThresholdZeroValue();
if (_treasury == address(0)) revert TreasuryZeroValue();
if (_dexTreasury == address(0)) revert DexTreasuryZeroValue();
if (_signer == address(0)) revert SignerZeroValue();
if (_mcLowerLimit >= _mcUpperLimit) revert McLowerLimitGreaterThanUpperLimit();
if (dexFeeBasisPoints >= 10_000) revert FeeBPSCheckFailed();
if (feeBasisPoints >= MAX_BPS) revert FeeBPSCheckFailed();
totalSupply = _totalSupply;
virtualTokenReserves = _virtualTokenReserves;
virtualCollateralReserves = _virtualCollateralReserves;
feeBasisPoints = _feeBasisPoints;
dexFeeBasisPoints = _dexFeeBasisPoints;
migrationFeeFixed = _migrationFeeFixed;
poolCreationFee = _poolCreationFee;
mcUpperLimit = _mcUpperLimit;
mcLowerLimit = _mcLowerLimit;
tokensMigrationThreshold = _tokensMigrationThreshold;
treasury = _treasury;
dexTreasury = _dexTreasury;
signer = _signer;
emit SetConfig(
totalSupply,
virtualTokenReserves,
virtualCollateralReserves,
feeBasisPoints,
dexFeeBasisPoints,
migrationFeeFixed,
poolCreationFee,
mcUpperLimit,
mcLowerLimit,
tokensMigrationThreshold,
treasury,
dexTreasury,
signer
);
}
function _checkSignatureAndStore(
string memory _name,
string memory _symbol,
uint256 _nonce,
bytes memory _signature
) internal {
if (usedSignatures[keccak256(_signature)]) revert SignatureIsUsed();
bytes32 message = keccak256(abi.encodePacked(_name, _symbol, _nonce, address(this), block.chainid, msg.sender));
if (!SignatureChecker.isValidSignatureNow(signer, MessageHashUtils.toEthSignedMessageHash(message), _signature))
revert InvalidSignature();
usedSignatures[keccak256(_signature)] = true;
}
receive() external payable {}
}
文件 15 的 21:MoonshotToken.sol
pragma solidity ^0.8.23;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {IUniswapV2Router02} from "./interfaces/IUniswapV2Router02.sol";
import {IUniswapV2Factory} from "./interfaces/IUniswapV2Factory.sol";
import {IMoonshotToken} from "./interfaces/IMoonshotToken.sol";
contract MoonshotToken is ERC20Burnable, IMoonshotToken, ReentrancyGuard {
CurveType public constant curveType = CurveType.ConstantProductV1;
uint256 public initalTokenSupply;
uint256 public virtualTokenReserves;
uint256 public virtualCollateralReserves;
uint256 public immutable virtualCollateralReservesInitial;
uint256 public immutable feeBPS;
uint256 public immutable dexFeeBPS;
uint256 public immutable mcLowerLimit;
uint256 public immutable mcUpperLimit;
uint256 public immutable tokensMigrationThreshold;
uint256 public immutable fixedMigrationFee;
uint256 public immutable poolCreationFee;
address public immutable creator;
address public immutable pair;
address public immutable treasury;
address public immutable dexTreasury;
address public immutable factory;
bool public tradingStopped;
bool public sendingToPairNotAllowed = true;
uint256 public constant MAX_BPS = 10_000;
IUniswapV2Router02 public immutable uniswapV2Router;
modifier buyChecks() {
if (tradingStopped) revert TradingStopped();
_;
_checkMcLower();
_checkMcUpperLimit();
}
modifier sellChecks() {
if (tradingStopped) revert TradingStopped();
_;
}
modifier onlyFactory() {
if (msg.sender != factory) revert OnlyFactory();
_;
}
constructor(ConstructorParams memory _params) ERC20(_params.name, _params.symbol) {
_mint(address(this), _params.totalSupply);
initalTokenSupply = _params.totalSupply;
virtualCollateralReserves = _params.virtualCollateralReserves;
virtualCollateralReservesInitial = _params.virtualCollateralReserves;
virtualTokenReserves = _params.virtualTokenReserves;
creator = _params.creator;
feeBPS = _params.feeBasisPoints;
dexFeeBPS = _params.dexFeeBasisPoints;
treasury = _params.treasury;
dexTreasury = _params.dexTreasury;
fixedMigrationFee = _params.migrationFeeFixed;
poolCreationFee = _params.poolCreationFee;
mcLowerLimit = _params.mcLowerLimit;
mcUpperLimit = _params.mcUpperLimit;
tokensMigrationThreshold = _params.tokensMigrationThreshold;
uniswapV2Router = IUniswapV2Router02(_params.uniV2Router);
factory = msg.sender;
(address token0, address token1) = address(this) < uniswapV2Router.WETH()
? (address(this), uniswapV2Router.WETH())
: (uniswapV2Router.WETH(), address(this));
pair = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
address(uniswapV2Router.factory()),
keccak256(abi.encodePacked(token0, token1)),
hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"
)
)
)
)
);
}
function buyExactOut(
uint256 _tokenAmount,
uint256 _maxCollateralAmount
)
external
payable
onlyFactory
buyChecks
returns (uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee)
{
if (balanceOf(address(this)) <= _tokenAmount) revert InsufficientTokenReserves();
uint256 collateralToSpend = (_tokenAmount * virtualCollateralReserves) / (virtualTokenReserves - _tokenAmount);
(helioFee, dexFee) = _calculateFee(collateralToSpend);
collateralToPayWithFee = collateralToSpend + helioFee + dexFee;
if (collateralToPayWithFee > _maxCollateralAmount) revert SlippageCheckFailed();
_transferCollateral(treasury, helioFee);
_transferCollateral(dexTreasury, dexFee);
virtualTokenReserves -= _tokenAmount;
virtualCollateralReserves += collateralToSpend;
uint256 refund;
if (msg.value > collateralToPayWithFee) {
refund = msg.value - collateralToPayWithFee;
_transferCollateral(msg.sender, refund);
} else if (msg.value < collateralToPayWithFee) {
revert NotEnoughtETHToBuyTokens();
}
_transfer(address(this), msg.sender, _tokenAmount);
}
function buyExactIn(
uint256 _amountOutMin
)
external
payable
onlyFactory
buyChecks
returns (uint256 collateralToPayWithFee, uint256 helioFee, uint256 dexFee)
{
if (balanceOf(address(this)) <= _amountOutMin) revert InsufficientTokenReserves();
collateralToPayWithFee = msg.value;
(helioFee, dexFee) = _calculateFee(collateralToPayWithFee);
uint256 collateralToSpendMinusFee = collateralToPayWithFee - helioFee - dexFee;
_transferCollateral(treasury, helioFee);
_transferCollateral(dexTreasury, dexFee);
uint256 tokensOut = (collateralToSpendMinusFee * virtualTokenReserves) /
(virtualCollateralReserves + collateralToSpendMinusFee);
if (tokensOut < _amountOutMin) revert SlippageCheckFailed();
virtualTokenReserves -= tokensOut;
virtualCollateralReserves += collateralToSpendMinusFee;
_transfer(address(this), msg.sender, tokensOut);
}
function sellExactIn(
uint256 _tokenAmount,
uint256 _amountCollateralMin
)
external
payable
onlyFactory
sellChecks
returns (uint256 collateralToReceiveMinusFee, uint256 helioFee, uint256 dexFee)
{
uint256 collaterallToReceive = (_tokenAmount * virtualCollateralReserves) /
(virtualTokenReserves + _tokenAmount);
(helioFee, dexFee) = _calculateFee(collaterallToReceive);
collateralToReceiveMinusFee = collaterallToReceive - helioFee - dexFee;
_transferCollateral(treasury, helioFee);
_transferCollateral(dexTreasury, dexFee);
if (collateralToReceiveMinusFee < _amountCollateralMin) revert SlippageCheckFailed();
virtualTokenReserves += _tokenAmount;
virtualCollateralReserves -= collaterallToReceive;
_transferCollateral(msg.sender, collateralToReceiveMinusFee);
_transfer(msg.sender, address(this), _tokenAmount);
}
function sellExactOut(
uint256 _tokenAmountMax,
uint256 _amountCollateral
)
external
payable
onlyFactory
sellChecks
returns (uint256 collateralToReceiveMinusFee, uint256 tokensOut, uint256 helioFee, uint256 dexFee)
{
(helioFee, dexFee) = _calculateFee(_amountCollateral);
collateralToReceiveMinusFee = _amountCollateral - helioFee - dexFee;
_transferCollateral(treasury, helioFee);
_transferCollateral(dexTreasury, dexFee);
tokensOut = (_amountCollateral * virtualTokenReserves) / (virtualCollateralReserves - _amountCollateral);
if (tokensOut > _tokenAmountMax) revert SlippageCheckFailed();
_transfer(msg.sender, address(this), tokensOut);
virtualTokenReserves += tokensOut;
virtualCollateralReserves -= _amountCollateral;
_transferCollateral(msg.sender, collateralToReceiveMinusFee);
}
function getAmountOutAndFee(
uint256 _amountIn,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsIn
) external view returns (uint256 amountOut, uint256 fee) {
if (_paymentTokenIsIn) {
(uint256 helioFee, uint256 dexFee) = _calculateFee(_amountIn);
fee = helioFee + dexFee;
amountOut = (_amountIn * _reserveOut) / (_reserveIn + _amountIn);
} else {
amountOut = (_amountIn * _reserveOut) / (_reserveIn + _amountIn);
(uint256 helioFee, uint256 dexFee) = _calculateFee(amountOut);
fee = helioFee + dexFee;
}
}
function getAmountInAndFee(
uint256 _amountOut,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsOut
) external view returns (uint256 amountIn, uint256 fee) {
if (_paymentTokenIsOut) {
(uint256 helioFee, uint256 dexFee) = _calculateFee(_amountOut);
fee = helioFee + dexFee;
amountIn = (_amountOut * _reserveIn) / (_reserveOut - _amountOut);
} else {
amountIn = (_amountOut * _reserveIn) / (_reserveOut - _amountOut);
(uint256 helioFee, uint256 dexFee) = _calculateFee(amountIn);
fee = helioFee + dexFee;
}
}
function migrate()
external
onlyFactory
returns (uint256 tokensToMigrate, uint256 tokensToBurn, uint256 collateralAmount)
{
sendingToPairNotAllowed = false;
if (IUniswapV2Factory(uniswapV2Router.factory()).getPair(address(this), uniswapV2Router.WETH()) == address(0)) {
IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
}
uint256 tokensRemaining = balanceOf(address(this));
this.approve(address(uniswapV2Router), tokensRemaining);
tokensToMigrate = _tokensToMigrate();
tokensToBurn = tokensRemaining - tokensToMigrate;
(uint256 treasuryFee, uint256 dexFee) = _splitFee(fixedMigrationFee);
_transferCollateral(treasury, treasuryFee + poolCreationFee);
_transferCollateral(dexTreasury, dexFee);
_burn(address(this), tokensToBurn);
collateralAmount =
virtualCollateralReserves -
virtualCollateralReservesInitial -
treasuryFee -
dexFee -
poolCreationFee;
(, , uint256 liquidity) = uniswapV2Router.addLiquidityETH{value: collateralAmount}(
address(this),
tokensToMigrate,
tokensToMigrate,
collateralAmount,
address(this),
block.timestamp + 10
);
if (address(this).balance > 0) {
_transferCollateral(treasury, address(this).balance);
}
IERC20(pair).transfer(address(0), liquidity);
}
function getMarketCap() public view returns (uint256) {
uint256 mc = (virtualCollateralReserves * 10 ** 18 * totalSupply()) / virtualTokenReserves;
return mc / 10 ** 18;
}
function getCurveProgressBps() external view returns (uint256) {
uint256 progress = ((initalTokenSupply - balanceOf(address(this))) * MAX_BPS) / tokensMigrationThreshold;
return progress < 100 ? 100 : (progress > MAX_BPS ? MAX_BPS : progress);
}
function _tokensToMigrate() internal view returns (uint256) {
uint256 collateralDeductedFee = address(this).balance - fixedMigrationFee - poolCreationFee;
return (virtualTokenReserves * collateralDeductedFee) / virtualCollateralReserves;
}
function _calculateFee(uint256 _amount) internal view returns (uint256 treasuryFee, uint256 dexFee) {
treasuryFee = (_amount * feeBPS) / MAX_BPS;
dexFee = (treasuryFee * dexFeeBPS) / MAX_BPS;
treasuryFee -= dexFee;
}
function _splitFee(uint256 _feeAmount) internal view returns (uint256 treasuryFee, uint256 dexFee) {
dexFee = (_feeAmount * dexFeeBPS) / MAX_BPS;
treasuryFee = _feeAmount - dexFee;
}
function _transferCollateral(address _to, uint256 _amount) internal {
(bool sent, ) = _to.call{value: _amount}("");
if (!sent) revert FailedToSendETH();
}
function _checkMcUpperLimit() internal view {
uint256 mc = getMarketCap();
if (mc > mcUpperLimit) revert MarketcapThresholdReached();
}
function _checkMcLower() internal {
uint256 mc = getMarketCap();
if (mc > mcLowerLimit) {
tradingStopped = true;
}
}
function transfer(address _to, uint256 _value) public override(ERC20, IERC20) returns (bool) {
if (_to == pair && sendingToPairNotAllowed) revert SendingToPairIsNotAllowedBeforeMigration();
return super.transfer(_to, _value);
}
}
文件 16 的 21:Ownable.sol
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
error OwnableUnauthorizedAccount(address account);
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 17 的 21:ReentrancyGuard.sol
pragma solidity ^0.8.20;
abstract contract ReentrancyGuard {
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
_status = ENTERED;
}
function _nonReentrantAfter() private {
_status = NOT_ENTERED;
}
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
文件 18 的 21:SignatureChecker.sol
pragma solidity ^0.8.20;
import {ECDSA} from "./ECDSA.sol";
import {IERC1271} from "../../interfaces/IERC1271.sol";
library SignatureChecker {
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
(address recovered, ECDSA.RecoverError error, ) = ECDSA.tryRecover(hash, signature);
return
(error == ECDSA.RecoverError.NoError && recovered == signer) ||
isValidERC1271SignatureNow(signer, hash, signature);
}
function isValidERC1271SignatureNow(
address signer,
bytes32 hash,
bytes memory signature
) internal view returns (bool) {
(bool success, bytes memory result) = signer.staticcall(
abi.encodeCall(IERC1271.isValidSignature, (hash, signature))
);
return (success &&
result.length >= 32 &&
abi.decode(result, (bytes32)) == bytes32(IERC1271.isValidSignature.selector));
}
}
文件 19 的 21:SignedMath.sol
pragma solidity ^0.8.20;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
文件 20 的 21:Strings.sol
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
error StringsInsufficientHexLength(uint256 value, uint256 length);
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}
文件 21 的 21:draft-IERC6093.sol
pragma solidity ^0.8.20;
interface IERC20Errors {
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
error ERC20InvalidSender(address sender);
error ERC20InvalidReceiver(address receiver);
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
error ERC20InvalidApprover(address approver);
error ERC20InvalidSpender(address spender);
}
interface IERC721Errors {
error ERC721InvalidOwner(address owner);
error ERC721NonexistentToken(uint256 tokenId);
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
error ERC721InvalidSender(address sender);
error ERC721InvalidReceiver(address receiver);
error ERC721InsufficientApproval(address operator, uint256 tokenId);
error ERC721InvalidApprover(address approver);
error ERC721InvalidOperator(address operator);
}
interface IERC1155Errors {
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
error ERC1155InvalidSender(address sender);
error ERC1155InvalidReceiver(address receiver);
error ERC1155MissingApprovalForAll(address operator, address owner);
error ERC1155InvalidApprover(address approver);
error ERC1155InvalidOperator(address operator);
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}
{
"compilationTarget": {
"contracts/MoonshotFactory.sol": "MoonshotFactory"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"viaIR": true
}
[{"inputs":[{"internalType":"uint256","name":"_totalSupply","type":"uint256"},{"internalType":"uint256","name":"_virtualTokenReserves","type":"uint256"},{"internalType":"uint256","name":"_virtualCollateralReserves","type":"uint256"},{"internalType":"uint256","name":"_feeBasisPoints","type":"uint256"},{"internalType":"uint256","name":"_dexFeeBasisPoints","type":"uint256"},{"internalType":"uint256","name":"_migrationFeeFixed","type":"uint256"},{"internalType":"uint256","name":"_poolCreationFee","type":"uint256"},{"internalType":"uint256","name":"_mcUpperLimit","type":"uint256"},{"internalType":"uint256","name":"_mcLowerLimit","type":"uint256"},{"internalType":"uint256","name":"_tokensMigrationThreshold","type":"uint256"},{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"address","name":"_dexTreasury","type":"address"},{"internalType":"address","name":"_uniswapV2Router","type":"address"},{"internalType":"address","name":"_signer","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DexTreasuryZeroValue","type":"error"},{"inputs":[],"name":"FailedToSendETH","type":"error"},{"inputs":[],"name":"FeeBPSCheckFailed","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"McLowerLimitGreaterThanUpperLimit","type":"error"},{"inputs":[],"name":"McLowerLimitZeroValue","type":"error"},{"inputs":[],"name":"McUpperLimitZeroValue","type":"error"},{"inputs":[],"name":"NotReadyForMigration","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"SignatureIsUsed","type":"error"},{"inputs":[],"name":"SignerZeroValue","type":"error"},{"inputs":[],"name":"TokensMigrationThresholdZeroValue","type":"error"},{"inputs":[],"name":"TotalSupplyZeroValue","type":"error"},{"inputs":[],"name":"TreasuryZeroValue","type":"error"},{"inputs":[],"name":"VirtualCollateralReservesZeroValue","type":"error"},{"inputs":[],"name":"VirtualTokenReservesZeroValue","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curvePositionAfterTrade","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curveProgressBps","type":"uint256"}],"name":"BuyExactIn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curvePositionAfterTrade","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"refund","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curveProgressBps","type":"uint256"}],"name":"BuyExactOut","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"}],"name":"MarketcapReached","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokensToMigrate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensToBurn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralToMigrate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"migrationFee","type":"uint256"},{"indexed":false,"internalType":"address","name":"pair","type":"address"}],"name":"Migrated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"}],"name":"NewMoonshotToken","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"addr","type":"address"},{"indexed":false,"internalType":"address","name":"creator","type":"address"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curveProgressBps","type":"uint256"}],"name":"NewMoonshotTokenAndBuy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curvePositionAfterTrade","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curveProgressBps","type":"uint256"}],"name":"SellExactIn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"seller","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curvePositionAfterTrade","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"curveProgressBps","type":"uint256"}],"name":"SellExactOut","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"totalSupply","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"virtualTokenReserves","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"virtualCollateralReserves","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeBasisPoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dexFeeBasisPoints","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"migrationFeeFixed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"poolCreationFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mcUpperLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"mcLowerLimit","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"tokensMigrationThreshold","type":"uint256"},{"indexed":false,"internalType":"address","name":"treasury","type":"address"},{"indexed":false,"internalType":"address","name":"dexTreasury","type":"address"},{"indexed":false,"internalType":"address","name":"signer","type":"address"}],"name":"SetConfig","type":"event"},{"inputs":[],"name":"UNISWAP_V2_ROUTER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amountOutMin","type":"uint256"}],"name":"buyExactIn","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"},{"internalType":"uint256","name":"_maxCollateralAmount","type":"uint256"}],"name":"buyExactOut","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"createMoonshotToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"uint256","name":"_tokenAmountMin","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"createMoonshotTokenAndBuy","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"dexFeeBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dexTreasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeBasisPoints","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mcLowerLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mcUpperLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"}],"name":"migrate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"migrationFeeFixed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"moonshotTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"poolCreationFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"readyForMigration","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_tokenAmount","type":"uint256"},{"internalType":"uint256","name":"_amountCollateralMin","type":"uint256"}],"name":"sellExactIn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_tokenAmountMax","type":"uint256"},{"internalType":"uint256","name":"_amountCollateral","type":"uint256"}],"name":"sellExactOut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_totalSupply","type":"uint256"},{"internalType":"uint256","name":"_virtualTokenReserves","type":"uint256"},{"internalType":"uint256","name":"_virtualCollateralReserves","type":"uint256"},{"internalType":"uint256","name":"_feeBasisPoints","type":"uint256"},{"internalType":"uint256","name":"_dexFeeBasisPoints","type":"uint256"},{"internalType":"uint256","name":"_migrationFeeFixed","type":"uint256"},{"internalType":"uint256","name":"_poolCreationFee","type":"uint256"},{"internalType":"uint256","name":"_mcUpperLimit","type":"uint256"},{"internalType":"uint256","name":"_mcLowerLimit","type":"uint256"},{"internalType":"uint256","name":"_tokensMigrationThreshold","type":"uint256"},{"internalType":"address","name":"_treasury","type":"address"},{"internalType":"address","name":"_dexTreasury","type":"address"},{"internalType":"address","name":"_signer","type":"address"}],"name":"setConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokensMigrationThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"treasury","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"usedSignatures","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"virtualCollateralReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"virtualTokenReserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]