Skip to content

Commit

Permalink
Apply formating changes
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGrandpa925 committed Jun 28, 2022
1 parent 76e6665 commit cbf80c3
Show file tree
Hide file tree
Showing 9 changed files with 479 additions and 432 deletions.
11 changes: 5 additions & 6 deletions contracts/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ pragma solidity ^0.8.0;

import "./IERC20Metadata.sol";

contract ERC20 is IERC20Metadata{

contract ERC20 is IERC20Metadata {
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
mapping(address=>uint) private ownership;
mapping(address => mapping(address=>uint256)) private allowances;
mapping(address => uint256) private ownership;
mapping(address => mapping(address => uint256)) private allowances;

event Mint(address to, uint256 amount);
event Burn(address from, uint256 amount);

modifier validAddress (address myAddress) {
modifier validAddress(address myAddress) {
require(myAddress != address(0), "Invalid address");
_;
}

constructor (string memory _name, string memory _symbol) {
constructor(string memory _name, string memory _symbol) {
decimals = 18;
name = _name;
symbol = _symbol;
Expand Down
41 changes: 19 additions & 22 deletions contracts/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,27 @@ import "./Pair.sol";
import "./IERC20.sol";

contract Factory is IFactory {
mapping(address => mapping(address => address)) private pairMapping;
address[] public allPairs;

mapping(address => mapping(address => address)) private pairMapping;
address[] public allPairs;
function allPairsLength() external view returns (uint256) {
return allPairs.length;
}

function allPairsLength() external view returns (uint) {
return allPairs.length;
}
function getPair(address tokenA, address tokenB) external view returns (address) {
return pairMapping[tokenA][tokenB];
}

function getPair(address tokenA, address tokenB) external view returns (address){
return pairMapping[tokenA][tokenB];
}

function createPair(address tokenA, address tokenB) external returns (address newPair){

require(tokenA != tokenB, "Same token");
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), "Invalid token address");
require(pairMapping[token0][token1] == address(0), "Pair exists");

newPair = address(new Pair(token0, token1, "LP TOKEN", "LPT"));
allPairs.push(newPair);
pairMapping[token0][token1] = newPair;
pairMapping[token1][token0] = newPair;
emit PairCreated(token0, token1, newPair);
}
function createPair(address tokenA, address tokenB) external returns (address newPair) {
require(tokenA != tokenB, "Same token");
(address token0, address token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), "Invalid token address");
require(pairMapping[token0][token1] == address(0), "Pair exists");

newPair = address(new Pair(token0, token1, "LP TOKEN", "LPT"));
allPairs.push(newPair);
pairMapping[token0][token1] = newPair;
pairMapping[token1][token0] = newPair;
emit PairCreated(token0, token1, newPair);
}
}
26 changes: 13 additions & 13 deletions contracts/IERC20Metadata.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import "./IERC20.sol";
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);

/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);

/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
15 changes: 9 additions & 6 deletions contracts/IFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
pragma solidity ^0.8.0;

interface IFactory {
event PairCreated(address indexed token0, address indexed token1, address pair);
event PairCreated(address indexed token0, address indexed token1, address pair);

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 getPair(address tokenA, address tokenB) external view returns (address pair);

function allPairs(uint256) external view returns (address pair);

function allPairsLength() external view returns (uint256);

function createPair(address tokenA, address tokenB) external returns (address pair);
}
60 changes: 40 additions & 20 deletions contracts/IPair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,47 @@ pragma solidity ^0.8.0;
import "./IERC20Metadata.sol";

interface IPair is IERC20Metadata {
event ProvideLiquidity(address indexed sender, uint amount0, uint amount1);
event RemoveLiquidity(address indexed sender, uint amount0, uint amount1);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out
event ProvideLiquidity(address indexed sender, uint256 amount0, uint256 amount1);
event RemoveLiquidity(address indexed sender, uint256 amount0, uint256 amount1);
event Swap(
address indexed sender,
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out
);

event Sync(uint112 reserve0, uint112 reserve1);

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
);

event Sync(uint112 reserve0, uint112 reserve1);
function kLast() external view returns (uint256);

function provideLiquidity(uint256 amount0In, uint256 amount1In) external;

function removeLiquidity(uint256 amount0Out, uint256 amount1Out) external;

function MINIMUM_LIQUIDITY() external pure returns (uint);
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 kLast() external view returns (uint);
function swap(
uint256 amount0In,
uint256 amount1In,
uint256 amount0Out,
uint256 amount1Out
) external;

function provideLiquidity(uint amount0In, uint amount1In) external;
function removeLiquidity(uint amount0Out, uint amount1Out) external;
function swap(uint amount0In, uint amount1In, uint amount0Out, uint amount1Out) external;
function sync() external;
}
function sync() external;
}
Loading

0 comments on commit cbf80c3

Please sign in to comment.