forked from minaminao/ctf-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDexFactory.sol
49 lines (38 loc) · 1.53 KB
/
DexFactory.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "../Ethernaut/Level.sol";
import "./Dex.sol";
import "openzeppelin/token/ERC20/ERC20.sol";
contract DexFactory is Level {
function createInstance(address _player) public payable override returns (address) {
Dex instance = new Dex();
address instanceAddress = address(instance);
SwappableToken tokenInstance = new SwappableToken(
instanceAddress,
"Token 1",
"TKN1",
110
);
SwappableToken tokenInstanceTwo = new SwappableToken(
instanceAddress,
"Token 2",
"TKN2",
110
);
address tokenInstanceAddress = address(tokenInstance);
address tokenInstanceTwoAddress = address(tokenInstanceTwo);
instance.setTokens(tokenInstanceAddress, tokenInstanceTwoAddress);
tokenInstance.approve(instanceAddress, 100);
tokenInstanceTwo.approve(instanceAddress, 100);
instance.addLiquidity(tokenInstanceAddress, 100);
instance.addLiquidity(tokenInstanceTwoAddress, 100);
tokenInstance.transfer(_player, 10);
tokenInstanceTwo.transfer(_player, 10);
return instanceAddress;
}
function validateInstance(address payable _instance, address) public view override returns (bool) {
address token1 = Dex(_instance).token1();
address token2 = Dex(_instance).token2();
return IERC20(token1).balanceOf(_instance) == 0 || ERC20(token2).balanceOf(_instance) == 0;
}
}