-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLP.sol
123 lines (106 loc) · 5.86 KB
/
LP.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: None
pragma solidity ^0.6.12;
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "./uniswapv2/interfaces/IUniswapV2Factory.sol"; // interface factorys
import "./uniswapv2/interfaces/IUniswapV2Router02.sol"; // interface factorys
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract LPEvent is Context, Ownable {
address internal _encoreAddress;
address[] internal _path;
constructor(address _token ,address _encore) public {
_encoreAddress = _encore;
initialSetup(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D, 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f, _token);
IUniswapV2Router02 router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
_path.push(address(_encoreAddress));_path.push(router.WETH());_path.push(address(tokenAddress));
}
using SafeMath for uint256;
using Address for address;
using SafeMath for uint;
IUniswapV2Router02 public uniswapRouterV2;
IUniswapV2Factory public uniswapFactory;
address public tokenUniswapPair;
uint256 public contractStartTimestamp;
uint256 public totalENCORE;
mapping (address => uint) public contributed;
address public tokenAddress;
event LPTokenClaimed(address dst, uint value);
event LiquidityAddition(address indexed dst, uint value);
function initialSetup(address router, address factory, address _token) internal {
contractStartTimestamp = block.timestamp;
uniswapRouterV2 = IUniswapV2Router02(router != address(0) ? router : 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapFactory = IUniswapV2Factory(factory != address(0) ? factory : 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f);
createUniswapPairMainnet(_token, _encoreAddress);
tokenAddress = _token;
}
function createUniswapPairMainnet(address _token, address _encore) public returns (address) {
require(tokenUniswapPair == address(0), "Token: pool already created");
// tokenUniswapPair = uniswapFactory.createPair(
// address(_encore),
// address(_token)
// );
tokenUniswapPair = address(0x64F2d5E35742858Df71e04385052BD7423623392);
return tokenUniswapPair;
}
function getSecondsLeftInLiquidityGenerationEvent() public view returns (uint256) {
require(liquidityGenerationOngoing(), "Event over");
return contractStartTimestamp.add(3 days).sub(block.timestamp);
}
function liquidityGenerationOngoing() public view returns (bool) {
return contractStartTimestamp.add(3 days) > block.timestamp;
}
function emergencyDrain24hAfterLiquidityGenerationEventIsDone() public onlyOwner {
require(contractStartTimestamp.add(4 days) < block.timestamp, "Liquidity generation grace period still ongoing"); // About 24h after liquidity generation happens
IERC20 encore = IERC20(_encoreAddress);
IERC20 token = IERC20(tokenAddress);
encore.transfer(msg.sender, encore.balanceOf(address(this)));
token.transfer(msg.sender, encore.balanceOf(address(this)));
}
function deposit(uint256 _amountENCORE, bool agreesToTermsOutlinedInLiquidityGenerationParticipationAgreement) public {
require(liquidityGenerationOngoing(), "Liquidity Generation Event over");
require(agreesToTermsOutlinedInLiquidityGenerationParticipationAgreement, "No agreement provided");
IERC20 encore = IERC20(_encoreAddress);
IERC20 token = IERC20(tokenAddress);
require(encore.balanceOf(address(this)) < 1000e18, "Cap reached");
require(encore.balanceOf(address(this)).add(_amountENCORE) <= 1000e18, "Deposit exceeds cap");
encore.transferFrom(address(msg.sender), address(this), _amountENCORE);
token.transferFrom(address(msg.sender), address(this), _amountENCORE.mul(50));
contributed[msg.sender] += _amountENCORE;
totalENCORE.add(_amountENCORE);
emit LiquidityAddition(msg.sender, _amountENCORE);
}
bool public LPGenerationCompleted;
uint256 public totalLPTokensMinted;
uint256 public totalContributed;
uint256 public LPperUnit;
function addLiquidityToUniswapENCORExTOKENPair() public {
require(LPGenerationCompleted == false, "Liquidity generation already finished");
IERC20 token = IERC20(tokenAddress);
IERC20 encore = IERC20(_encoreAddress);
if(liquidityGenerationOngoing()) {
require(encore.balanceOf(address(this)) >= 1000e18, "LPE: Event not over, cap not reached");
}
totalContributed = encore.balanceOf(address(this));
IUniswapV2Pair pair = IUniswapV2Pair(tokenUniswapPair);
encore.transfer(address(pair), encore.balanceOf(address(this)));
token.transfer(address(pair), token.balanceOf(address(this)));
pair.mint(address(this));
totalLPTokensMinted = pair.balanceOf(address(this));
require(totalLPTokensMinted != 0 , "LP creation failed");
LPperUnit = totalLPTokensMinted.mul(1e18).div(totalContributed); // 1e18x for change
require(LPperUnit != 0 , "LP creation failed");
LPGenerationCompleted = true;
}
function claimLPTokens() public {
require(LPGenerationCompleted, "Event not over yet");
require(contributed[msg.sender] > 0 , "Nothing to claim, move along");
IUniswapV2Pair pair = IUniswapV2Pair(tokenUniswapPair);
uint256 amountLPToTransfer = contributed[msg.sender].mul(LPperUnit).div(1e18);
pair.transfer(msg.sender, amountLPToTransfer); // stored as 1e18x value for change
contributed[msg.sender] = 0;
emit LPTokenClaimed(msg.sender, amountLPToTransfer);
}
}