forked from MiloTruck/evm-ctf-challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.sol
61 lines (46 loc) · 1.73 KB
/
Setup.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {GREY} from "./lib/GREY.sol";
import {EscrowFactory} from "./EscrowFactory.sol";
import {DualAssetEscrow} from "./DualAssetEscrow.sol";
contract Setup {
bool public claimed;
// GREY token
GREY public grey;
// Challenge contracts
EscrowFactory public factory;
// Note: This is the address and ID of the escrow to drain
address public escrow;
uint256 public escrowId;
constructor() {
// Deploy the GREY token contract
grey = new GREY();
// Deploy challenge contracts
factory = new EscrowFactory();
// Mint 10,000 GREY for setup
grey.mint(address(this), 10_000e18);
// Add DualAssetEscrow implementation
address impl = address(new DualAssetEscrow());
factory.addImplementation(impl);
// Deploy a DualAssetEscrow
(escrowId, escrow) = factory.deployEscrow(
0, // implId = 0
abi.encodePacked(address(grey), address(0)) // tokenX = GREY, tokenY = ETH
);
// Deposit 10,000 GREY into the escrow
grey.approve(address(escrow), 10_000e18);
DualAssetEscrow(escrow).deposit(true, 10_000e18);
// Renounce ownership of the escrow
factory.renounceOwnership(escrowId);
}
// Note: Call this function to claim 1000 GREY for the challenge
function claim() external {
require(!claimed, "already claimed");
claimed = true;
grey.mint(msg.sender, 1000e18);
}
// Note: Challenge is solved when the escrow has been drained
function isSolved() external view returns (bool) {
return grey.balanceOf(address(escrow)) == 0 && grey.balanceOf(msg.sender) >= 10_000e18;
}
}