Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Latest commit

 

History

History

avalanche-c-chain

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

🧱🥪 gmx sandwiches


tl; dr


in this project, we inspect historical data on avalanche c-chain to simulate sandwich attacks in the gmx protocol.



gathering input data


  1. define the desired assets and/or protocols you want to research. in this example, we are looking at gmx and running the test test/testGmx().

  2. find out the methods that trigger prices updates (e.g. swap() on gmx's router).

  3. add/clone all the contracts needed for the methods above to contracts/. the main code we will be running is located inside test/ (foundry's forge is a testing framework).

  4. use any blockchain analytics tools (e.g., dune or avax apis) to search for past blocks with a suspecting price movement (e.g., set a threshold that could be interesting to look at).

  5. create a list with all the blocks you found and add them to data/blocks.txt. there is already two examples to get you started (a block from this week and another from last summer).



installing deps


  1. install foundry (this will create lib/forge-std). this is not only needed for running forge per se, but also because our tests import forge-std/Test.sol. note that our directory setup is defined inside foundry.toml:
[profile.default]
src = 'data'
out = 'out'
libs = ['lib']
fs_permissions = [{ access = "read", path = "./"}]
  1. install a solidity compiler. you need to look at which solidity version your protocol is using. for instance, for gmx we have to use 0.6.12.

  2. export an env variable for avalanche c-chain's RPC url (e.g., from infura's or ankr's or your own node):

> export RPC_URL=<RPC_URL>


running the simulation


  • build the contracts and run with:
> make test

[⠢] Compiling...
[⠔] Compiling 17 files with 0.6.12
[⠑] Solc 0.6.12 finished in 2.31s
Compiler run successful

Running 1 test for test/Gmx.sol:getHistorical
[PASS] testHistoricalGmx() (gas: 81654567)
Logs:
  🧱 block number: 19443666
    🪙 token 1: USDC
    🪙 token 2: WETH.e
      🔂 loops in the simulation: 12
  🧱 block number: 19905430
      🔂 loops in the simulation: 10
      🥪 possible $ profit (usd): 9720

Test result: ok. 1 passed; 0 failed; finished in 2.01s