← Index
Source: docs/zsub/hacking-instructions-2/dex-2.md (auto-generated by scripts/generate-docs-html.mjs — edit the .md, not this file)

DEFI Crash Course: DEX Exercise 2 - Sniper

Intro

You got a call from your rich friend who researched MEV (Miner-Extractable Value)!

He asked you to help him setup some Ethereum Validator nodes and create a liquidity "Sniper Bot".

When a DEX pair is created and liquidity is added, this Sniper Bot will attempt to buy it as soon as possible.

During this exercise, you'll develop a liquidity sniper bot called "Sniper".

You'll need to work directly with the low-level UniswapV2 pair smart contract to be quick and precise.

A new "Precious Token" is launching on MAINNET, which is perfect for testing your bot!

According to the Precious Token team, they will add liquidity of 10,000 PRECIOUS tokens and 50 WETH.

The initial price is 50 / 10,000 = 0.005 ETH per PRECIOUS.

Your first goal is to make sure you can purchase the tokens before anyone else

and the second goal is to purchase the tokens at the cheapest price possible.

Note: This exercise is executed on an Ethereum mainnet Fork block number 15969633. Everything is already configured in the hardhat.config.js file

Ethereum MAINNET Addresses

Uniswap V2 Factory: 0x5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f
WETH Token: 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

Your Rich Friend's Account (To be impersonated): 0x8e5dedeaeb2ec54d0508973a0fccd1754586974a

Accounts

Tasks

Task 1 - Contract Development

Complete all the open TODOs in the ./contracts/dex-2/Sniper.sol smart contract.

Implement all the functions:

External snipe() function:

Internal _sortTokens function:

Internal _getAmountOut function:

Internal _swapWithRetries function:

Task 2 - Tests

Complete all the open TODOs in test/dex-2/tests.js

Deployment

Snipe