Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnySheffield committed Dec 19, 2024
1 parent e411a25 commit ef1f3e0
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 270 deletions.
2 changes: 1 addition & 1 deletion script/DeployAndTest.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract DeployAndTest is Script {
// Deploy factory
address uniswapRouterAddress = 0x920b806E40A00E02E7D2b94fFc89860fDaEd3640;
Glottis20Factory factory = new Glottis20Factory(uniswapRouterAddress, msg.sender);

bytes memory metadata = abi.encode(
"https://example.com/token-logo.png", // Logo URL
"A smol token with flat price points", // Description
Expand Down
21 changes: 13 additions & 8 deletions src/Glottis20Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ contract Glottis20Factory is ReentrancyGuard {
uint256 private constant HUNDRED = 100;

//fees when creating a new uniswap pool, in eth.
uint256 public constant PROTOCOL_FEE = 20e14;
uint256 public constant PROTOCOL_FEE = 20e14;
uint256 public constant CREATOR_FEE = 10e14;
uint256 public constant CALLER_FEE = 5e14;
uint256 public constant CALLER_FEE = 5e14;

//fee on each sell, in eth.
uint256 public constant SELL_FEE = 35e14;
Expand Down Expand Up @@ -103,7 +103,6 @@ contract Glottis20Factory is ReentrancyGuard {

uint256 factoryBalance = glottis20.balanceOf(address(this));


if (factoryBalance < currentSupply) revert InsufficientBalance();

glottis20.setTradingUnlocked();
Expand All @@ -127,7 +126,12 @@ contract Glottis20Factory is ReentrancyGuard {

if (maxSupply < ONE_FULL || maxSupply > type(uint128).max || maxSupply % 2 != 0) revert InvalidInput();

if ((pricePoints[0] < 1 && pricePoints[0] == type(uint128).max) || (pricePoints[1] < 1 && pricePoints[1] == type(uint128).max) || (pricePoints[2] < 1 && pricePoints[2] == type(uint128).max) || (pricePoints[3] < 1 && pricePoints[0] == type(uint128).max)) {
if (
(pricePoints[0] < 1 && pricePoints[0] == type(uint128).max)
|| (pricePoints[1] < 1 && pricePoints[1] == type(uint128).max)
|| (pricePoints[2] < 1 && pricePoints[2] == type(uint128).max)
|| (pricePoints[3] < 1 && pricePoints[0] == type(uint128).max)
) {
revert InvalidPricePoints();
}
if (pricePoints[0] < 1 || pricePoints[1] < 1 || pricePoints[2] < 1 || pricePoints[3] < 1) {
Expand All @@ -138,8 +142,7 @@ contract Glottis20Factory is ReentrancyGuard {
if (predictedAddress.code.length > 0) revert TokenExists();

address tokenAddress = CREATE3.deployDeterministic(
abi.encodePacked(type(Glottis20).creationCode, abi.encode(name, symbol, 18, maxSupply, address(this))),
salt
abi.encodePacked(type(Glottis20).creationCode, abi.encode(name, symbol, 18, maxSupply, address(this))), salt
);

if (tokenAddress.code.length == 0) revert DeploymentFailed();
Expand Down Expand Up @@ -236,7 +239,8 @@ contract Glottis20Factory is ReentrancyGuard {
if (glottis20.maxSupply().rawDiv(2) == glottis20.totalSupply()) revert MaxSupplyReached();

uint256 stepStartSupply = (currentSupply.rawDiv(STEP_SIZE)).rawMul(STEP_SIZE);
uint256 pricePerFullToken = calculatePrice(token, (stepStartSupply.rawMul(ONE_FULL)).rawDiv(glottis20.maxSupply().rawDiv(2)));
uint256 pricePerFullToken =
calculatePrice(token, (stepStartSupply.rawMul(ONE_FULL)).rawDiv(glottis20.maxSupply().rawDiv(2)));

tokensToMint = ethIn.rawMul(ONE_FULL).rawDiv(pricePerFullToken);
uint256 maxInStep = (stepStartSupply.rawDiv(STEP_SIZE).rawAdd(1).rawMul(STEP_SIZE)).rawSub(currentSupply);
Expand Down Expand Up @@ -280,7 +284,8 @@ contract Glottis20Factory is ReentrancyGuard {
if (glottis20.maxSupply().rawDiv(2) == glottis20.totalSupply()) revert MaxSupplyReached();

uint256 stepStartSupply = ((currentSupply - 1).rawDiv(STEP_SIZE)).rawMul(STEP_SIZE);
uint256 pricePerFullToken = calculatePrice(token, (stepStartSupply.rawMul(ONE_FULL)).rawDiv(glottis20.maxSupply().rawDiv(2)));
uint256 pricePerFullToken =
calculatePrice(token, (stepStartSupply.rawMul(ONE_FULL)).rawDiv(glottis20.maxSupply().rawDiv(2)));

uint256 availableInStep = currentSupply.rawSub(stepStartSupply);
tokensToSell = tokenAmount > availableInStep ? availableInStep : tokenAmount;
Expand Down
49 changes: 25 additions & 24 deletions src/interfaces/IUniswapV2Pair.sol
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Transfer(address indexed from, address indexed to, uint256 value);

function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function totalSupply() external view returns (uint256);
function balanceOf(address owner) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);

function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function nonces(address owner) external view returns (uint256);

function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external;

event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);

function MINIMUM_LIQUIDITY() external pure returns (uint);
function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);

function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function mint(address to) external returns (uint256 liquidity);
function burn(address to) external returns (uint256 amount0, uint256 amount1);
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;

function initialize(address, address) external;
}
}
140 changes: 83 additions & 57 deletions src/interfaces/IUniswapV2Router01.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,89 +7,115 @@ interface IUniswapV2Router01 {
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
uint256 deadline
) external returns (uint256 amountA, uint256 amountB, uint256 liquidity);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
uint256 deadline
) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity);
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
uint256 deadline
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
uint256 deadline
) external returns (uint256 amountToken, uint256 amountETH);
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
uint256 liquidity,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountA, uint256 amountB);
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountToken, uint256 amountETH);
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(uint256 amountOutMin, address[] calldata path, address to, uint256 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)
returns (uint256[] memory amounts);
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapETHForExactTokens(uint256 amountOut, address[] calldata path, address to, uint256 deadline)
external
payable
returns (uint[] memory amounts);
returns (uint256[] 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 quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB);
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountOut);
function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut)
external
pure
returns (uint256 amountIn);
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
}
45 changes: 24 additions & 21 deletions src/interfaces/IUniswapV2Router02.sol
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';
import "./IUniswapV2Router01.sol";

interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint deadline
) external returns (uint amountETH);
uint256 deadline
) external returns (uint256 amountETH);
function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountETH);
uint256 deadline,
bool approveMax,
uint8 v,
bytes32 r,
bytes32 s
) external returns (uint256 amountETH);

function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint deadline
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint amountOutMin,
uint256 amountOutMin,
address[] calldata path,
address to,
uint deadline
uint256 deadline
) external payable;
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint deadline
uint256 deadline
) external;
}
}
Loading

0 comments on commit ef1f3e0

Please sign in to comment.