Advertisement
Guest User

Untitled

a guest
Feb 11th, 2022
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.40 KB | None | 0 0
  1. // SPDX-License-Identifier: MIT
  2.  
  3. pragma solidity ^0.8.6;
  4.  
  5.  
  6. contract Handler{
  7. address[] private GenOneHolders;
  8. uint[] private GenOneHolderTokenAmount;
  9. uint private Gen1ToEthRatio = 1;
  10. GenOneDex private genOneDexInstance;
  11. GenOneToken private genOneTokenInstance;
  12. GenTwoToken private genTwoTokenInstance;
  13. bool private allowRedeem = false;
  14. bool airdropDone = false;
  15. address[] private GenTwoHolders;
  16. uint[] private GenTwoHolderTokenAmount;
  17. address [] private GenTwoRedeemedUsers;
  18. bool step2CalledSuccessfully = false;
  19. bool step3CalledSuccessfully = false;
  20. uint decimals;
  21. uint totalSupply; // calibrated for 200000000000000000000000000000 (or roughly 2 times the circulating supply of eth
  22.  
  23.  
  24. constructor(string memory _name, string memory _symbol, uint _decimals, uint _totalSupply) payable{
  25. decimals = _decimals;
  26. totalSupply = _totalSupply;
  27. step1(_name, _symbol, _decimals, _totalSupply);
  28. //step2() will also be called due to its financial incentive nature, but we don't have to call it here
  29. //step3() will also be called due to its financial incentive nature, but we don't have to call it here
  30. }
  31.  
  32. function payMe() public payable returns(bool success) {
  33. return true;
  34. }
  35.  
  36. function loadIncentiveEth(uint weiAmount) public payable{
  37. require (weiAmount == msg.value, "ethAmount does not equal msg.value");
  38. }
  39.  
  40. //private methods that do stuff with the gen1 token or the GenOneDex
  41. function step1(string memory _name, string memory _symbol, uint _decimals, uint _totalSupply) private{
  42. genOneDexInstance = new GenOneDex(payable(address(this))); //deploy a GenOneDex contract instance
  43. genOneTokenInstance = new GenOneToken(_name, _symbol, _decimals, _totalSupply, (address(genOneDexInstance)));//deploy gen1 erc-20 with owner address being the instance of the GenOneDex deployed
  44. genOneDexInstance.addTokenInstanceAddress(genOneTokenInstance);
  45. genOneDexInstance.allowTrading(true); //call GenOneDex to allow trading
  46. }
  47.  
  48. //public methods that are time sensitive
  49.  
  50. //half an ether for the first person to call this function when its available
  51. function step2(address ethAddress) public payable{
  52. require(block.timestamp >= 1640927700, "too early to call");
  53. require(step2CalledSuccessfully == false, "step 2 called successfully not false");
  54. require((address(this).balance) >= 200000000 gwei, "handler does not have enough balance to pay out");
  55. payable(msg.sender).transfer(200000000 gwei);
  56. genOneDexInstance.allowTrading(false);
  57. GenOneHolders = genOneDexInstance.returnGenOneHolders();
  58. GenOneHolderTokenAmount = genOneDexInstance.returnGenOneHolderTokenAmount();
  59. genOneDexInstance.removeLiquidity(); //RUGPULL - remove all eth and gen1 token fraction that the GenOneDex has and send it to the handler, allow users to burn their gen1 tokens by sending to burn address
  60. step2CalledSuccessfully = true;
  61. }
  62.  
  63. //half an ether for the first person to call this function when its available
  64. function step3(address ethAddress) public {
  65. require(block.timestamp > 1641015000, "too early to call");
  66. require(step3CalledSuccessfully == false);
  67. require((address(this).balance) >= 400000000 gwei);
  68. payable(msg.sender).transfer(400000000 gwei);
  69. genTwoTokenInstance = new GenTwoToken("Generation_B", "GENB", decimals, totalSupply, address(this)); //deploy new tokens after new tax year
  70. //airdrop new tokens after tax year (locked on airdrop arrival)
  71. for(uint256 i=0; i < GenOneHolders.length; i++){
  72. genTwoTokenInstance.transfer(GenOneHolders[i], GenOneHolderTokenAmount[i]);
  73. }
  74. genTwoTokenInstance.turnOnRedeem();
  75. allowRedeem = true; //allow gen2 holders to use redeem method to redeem against gen1 rugpulled eth (need to have first sent gen2 token to handler address)
  76. airdropDone = true;
  77. step3CalledSuccessfully = true;
  78. }
  79.  
  80. //will only work once per wallet address so make sure to send all your gen 2 tokens to the handler
  81. //method will fail if user did not first send their Gen 2 tokens to the handler
  82. function redeemGenTwo() public {
  83. require(((block.timestamp > 1641015000) && (block.timestamp < 1643691600)), "too early or too late to call");
  84. //make sure this contract has a positive balance
  85. require(address(this).balance > 0);
  86. //make sure that step3 has been called already
  87. require(step3CalledSuccessfully == true);
  88. //make sure the person calling this redeem function had gen1 tokens
  89. require(findHolderAmountIndex(msg.sender) >= 0);
  90. //make sure the person calling this redeem function also has not redeemed before
  91. require(inGenTwoRedeemedUsers(msg.sender) == false);
  92.  
  93. if(genTwoTokenInstance.checkBalance(msg.sender) < GenOneHolderTokenAmount[uint(findHolderAmountIndex(msg.sender))]){
  94. //helper
  95. int senderIndex = findHolderAmountIndex(msg.sender);
  96. uint256 senderIndexUint = uint256(senderIndex);
  97. payable(msg.sender).transfer((((99*(GenOneHolderTokenAmount[senderIndexUint] - (genTwoTokenInstance.checkBalance(msg.sender))))/100) * Gen1ToEthRatio));
  98. }
  99.  
  100. GenTwoRedeemedUsers.push(msg.sender);
  101.  
  102. }
  103.  
  104. function devRedeem() public {
  105. require(block.timestamp > 1643778000, "too early to call");
  106. require(address(this).balance > 0);
  107. require(msg.sender == address(0xd0fE3391600CbD0b8C055c27Fb269a74ae8f5ba9));
  108. payable(msg.sender).transfer(address(this).balance);//send remaining ether to dev wallet
  109. }
  110.  
  111. function getAirdropDone() public returns (bool){
  112. require(msg.sender == address(genTwoTokenInstance));
  113. return airdropDone;
  114.  
  115. }
  116.  
  117. function findHolderAmountIndex(address _address) public returns (int){
  118. for(uint256 i=0; i < GenOneHolders.length; i++){
  119. if(GenOneHolders[i]==_address){
  120. return int(i);
  121. }
  122. }
  123. return -1;
  124. }
  125.  
  126. function inGenTwoRedeemedUsers(address _address) public returns (bool){
  127. for(uint256 i=0; i < GenTwoRedeemedUsers.length; i++){
  128. if(GenTwoRedeemedUsers[i]==_address){
  129. return true;
  130. }
  131. }
  132. return false;
  133. }
  134.  
  135. function getGenOneDex() public returns (address payable){
  136. return payable(address(genOneDexInstance));
  137. }
  138.  
  139. function getGenTwoToken() public returns (address){
  140. return address(genTwoTokenInstance);
  141. }
  142.  
  143. }
  144.  
  145. contract GenOneDex {
  146. address[] private GenOneHolders;
  147. uint[] private GenOneHolderTokenAmount;
  148. bool private allowTradingFlag = false;
  149. address payable handlerContract;
  150. GenOneToken private tokenInstance;
  151. uint Gen1ToWeiRatio = 1;
  152. uint gen1TokensRemaining = 2000000000000000000000000000;
  153.  
  154. constructor(address payable _handlerContract){
  155. handlerContract = _handlerContract;
  156. }
  157.  
  158.  
  159. function allowTrading(bool value) public{
  160. require(msg.sender == handlerContract);
  161. allowTradingFlag = value;
  162. }
  163.  
  164. function addTokenInstanceAddress(GenOneToken _tokenInstance) public{
  165. require(msg.sender == handlerContract);
  166. tokenInstance = _tokenInstance;
  167. }
  168.  
  169. function removeLiquidity() public payable{
  170. require(msg.sender == handlerContract, "remove liquidity called by non handler contract");
  171. require(address(this).balance > 0, "dex balance is empty");
  172. require(Handler(handlerContract).payMe{value:address(this).balance}(), "dex sending all eth to handler fail for unknown reason");//send all the eth to the handler contract
  173. tokenInstance.flagLiquidityRemoved(true);
  174. tokenInstance.transfer(address(0), gen1TokensRemaining);//burn the remaining gen1 tokens in the GenOneDex instance
  175.  
  176. }
  177.  
  178.  
  179. function exchangeETHForGenOne(uint weiAmountIn) public payable returns (bool value) {
  180. require(msg.value == weiAmountIn, "msg.value and weiAmountIn don't match");
  181. require(allowTradingFlag, "trading flag isn't set to true");
  182. require((GenOneToken(tokenInstance).transfer(msg.sender, weiAmountIn)),"failing transfer");
  183. GenOneHolders.push(msg.sender);
  184. GenOneHolderTokenAmount.push(weiAmountIn);
  185. gen1TokensRemaining = gen1TokensRemaining - (weiAmountIn);
  186. return true;
  187. }
  188.  
  189.  
  190. function returnGenOneHolders() public view returns (address[] memory){
  191. return GenOneHolders;
  192. }
  193.  
  194. function returnGenOneHolderTokenAmount() public view returns(uint[] memory) {
  195. return GenOneHolderTokenAmount;
  196. }
  197.  
  198. }
  199.  
  200.  
  201. contract GenTwoToken{
  202. string public name;
  203. string public symbol;
  204. uint256 public decimals;
  205. uint256 public totalSupply;
  206. address private ownerHandler;
  207. bool allowRedeem = false;
  208.  
  209.  
  210. // Keep track balances and allowances approved
  211. mapping(address => uint256) public balanceOf;
  212. mapping(address => mapping(address => uint256)) public allowance;
  213.  
  214. // Events - fire events on state changes etc
  215. event Transfer(address indexed from, address indexed to, uint256 value);
  216. event Approval(address indexed owner, address indexed spender, uint256 value);
  217.  
  218. constructor(string memory _name, string memory _symbol, uint _decimals, uint _totalSupply, address _ownerHandler) {
  219. name = _name;
  220. symbol = _symbol;
  221. decimals = _decimals;
  222. totalSupply = _totalSupply;
  223. balanceOf[_ownerHandler] = totalSupply;
  224. ownerHandler = _ownerHandler;
  225.  
  226. }
  227.  
  228. /// @notice transfer amount of tokens to an address
  229. /// @param _to receiver of token
  230. /// @param _value amount value of token to send
  231. /// @return success as true, for transfer
  232. function transfer(address _to, uint256 _value) external returns (bool success) {
  233. require(balanceOf[msg.sender] >= _value);
  234. _transfer(msg.sender, _to, _value);
  235. return true;
  236. }
  237.  
  238. /// @dev internal helper transfer function with required safety checks
  239. /// @param _from, where funds coming the sender
  240. /// @param _to receiver of token
  241. /// @param _value amount value of token to send
  242. // Internal function transfer can only be called by this contract
  243. // Emit Transfer Event event
  244. function _transfer(address _from, address _to, uint256 _value) internal {
  245. if(Handler(ownerHandler).getAirdropDone()){
  246. require(_to == address(ownerHandler));
  247. require(allowRedeem);
  248. balanceOf[_from] = balanceOf[_from] - (_value);
  249. balanceOf[_to] = balanceOf[_to] + (_value);
  250. }
  251. else{
  252. require (_from == address(ownerHandler));
  253. balanceOf[_from] = balanceOf[_from] - (_value);
  254. balanceOf[_to] = balanceOf[_to] + (_value);
  255. }
  256.  
  257. }
  258.  
  259.  
  260. /// @notice transfer by approved person from original address of an amount within approved limit
  261. /// @param _from, address sending to and the amount to send
  262. /// @param _to receiver of token
  263. /// @param _value amount value of token to send
  264. /// @dev internal helper transfer function with required safety checks
  265. /// @return true, success once transfered from original account
  266. // Allow _spender to spend up to _value on your behalf
  267. function transferFrom(address _from, address _to, uint256 _value) external returns (bool) {
  268. return false;
  269. }
  270.  
  271. /// @notice Approve other to spend on your behalf eg an exchange
  272. /// @param _spender allowed to spend and a max amount allowed to spend
  273. /// @param _value amount value of token to send
  274. /// @return true, success once address approved
  275. // Emit the Approval event
  276. // Allow _spender to spend up to _value on your behalf
  277. function approve(address _spender, uint256 _value) external returns (bool) {
  278. return false;
  279. }
  280.  
  281. function checkBalance(address _address) public returns (uint){
  282. return balanceOf[_address];
  283. }
  284.  
  285. function turnOnRedeem() public{
  286. require(msg.sender == ownerHandler);
  287. allowRedeem = true;
  288. }
  289. }
  290.  
  291.  
  292. contract GenOneToken {
  293. string public name;
  294. string public symbol;
  295. uint256 public decimals;
  296. uint256 public totalSupply;
  297. address[] public lockedAddresses; //addresses already bought in
  298. address private ownerDex;
  299. bool private liquidityRemoved = false;
  300.  
  301. // Keep track balances and allowances approved
  302. mapping(address => uint256) public balanceOf;
  303. mapping(address => mapping(address => uint256)) public allowance;
  304.  
  305. // Events - fire events on state changes etc
  306. event Transfer(address indexed from, address indexed to, uint256 value);
  307. event Approval(address indexed owner, address indexed spender, uint256 value);
  308.  
  309. constructor(string memory _name, string memory _symbol, uint _decimals, uint _totalSupply, address _ownerDex) {
  310. name = _name;
  311. symbol = _symbol;
  312. decimals = _decimals;
  313. totalSupply = _totalSupply;
  314. ownerDex = _ownerDex;
  315. balanceOf[ownerDex] = totalSupply;
  316. }
  317.  
  318. /// @notice transfer amount of tokens to an address
  319. /// @param _to receiver of token
  320. /// @param _value amount value of token to send
  321. /// @return success as true, for transfer
  322. function transfer(address _to, uint256 _value) external returns (bool success) {
  323. require(balanceOf[msg.sender] >= _value , "balanceOf Dex is not enough for the transaction");
  324. require(_transfer(msg.sender, _to, _value), "inner transfer function not working");
  325. return true;
  326. }
  327.  
  328.  
  329. /// @dev internal helper transfer function with required safety checks
  330. /// @param _from, where funds coming the sender
  331. /// @param _to receiver of token
  332. /// @param _value amount value of token to send
  333. // Internal function transfer can only be called by this contract
  334. // Emit Transfer Event event
  335. function _transfer(address _from, address _to, uint256 _value) internal returns (bool){
  336. // Ensure sending is to valid address! 0x0 address cane be used to burn()
  337. if(liquidityRemoved == false){
  338. require(_to != address(0), "can't send address 0 tokens");
  339. require((!exists(_from) && !exists(_to)), "address already traded before");
  340. balanceOf[_from] = balanceOf[_from] - (_value);
  341. balanceOf[_to] = balanceOf[_to] + (_value);
  342. lockedAddresses.push(_to);
  343. if(_from != ownerDex) {lockedAddresses.push(_from);}
  344. emit Transfer(_from, _to, _value);
  345. return true;
  346. }
  347. else if(liquidityRemoved == true && _to == address(0)){
  348. balanceOf[_from] = balanceOf[_from] - (_value);
  349. balanceOf[_to] = balanceOf[_to] + (_value);
  350. emit Transfer(_from, _to, _value);
  351. return true;
  352. }
  353. }
  354.  
  355. /// @notice Approve other to spend on your behalf eg an exchange
  356. /// @param _spender allowed to spend and a max amount allowed to spend
  357. /// @param _value amount value of token to send
  358. /// @return true, success once address approved
  359. // Emit the Approval event
  360. // Allow _spender to spend up to _value on your behalf
  361. function approve(address _spender, uint256 _value) external returns (bool) {
  362. return false;
  363. }
  364.  
  365. /// @notice transfer by approved person from original address of an amount within approved limit
  366. /// @param _from, address sending to and the amount to send
  367. /// @param _to receiver of token
  368. /// @param _value amount value of token to send
  369. /// @dev internal helper transfer function with required safety checks
  370. /// @return true, success once transfered from original account
  371. // Allow _spender to spend up to _value on your behalf
  372. function transferFrom(address _from, address _to, uint256 _value) external returns (bool) {
  373. return false;
  374. }
  375.  
  376. function flagLiquidityRemoved(bool value) public{
  377. require(msg.sender == ownerDex);
  378. liquidityRemoved = value;
  379. }
  380.  
  381. function exists(address _address) private returns (bool){
  382. for(uint256 i=0; i < lockedAddresses.length; i++){
  383. if(lockedAddresses[i]==_address){
  384. return true;
  385. }
  386. }
  387. return false;
  388. }
  389.  
  390. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement