Skip to content
greekfiPublic

About

Flash-funded exercise of Greek options (Aerodrome Slipstream flash swaps)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

exercise: flash-funded exercise of Greek options

GreekFlashExerciseV3 exercises an in-the-money Greek option for whoever holds it, funded by v3-style flash swaps on Aerodrome Slipstream (Base), in one transaction. The holder does not need the strike in its wallet, and there is no lender: the pool pays out first, calls back, and is paid before the callback returns. One deployment serves every holder. It has no owner and no admin.

Exercise pays the consideration and returns the collateral, so both directions swap first, over a route of one or two pools ordered from the underlying to USDC:

  • Call: swap sells amount underlying for USDC (exact input). In the callback: exercise (pay the strike, receive the underlying), pay the pool the underlying. The USDC left is the profit.
  • Put: swap buys the strike's underlying (exact output). In the callback: exercise (deliver it, receive USDC), pay the pool the USDC it is owed. The USDC left is the profit.
  • Two pools (the LSTs, which only trade against WETH): the first pool's callback swaps on the second (WETH/USDC), the exercise runs in the innermost callback, then each pool is paid on the way out. A call sells what the first pool paid; a put buys what the first pool is owed.

A pool checks it was paid after its callback, so a wrong pool or an OTM option reverts the whole tx. Every swap must fill in full (PartialFill), so USDC is the only thing that comes back. Then profit >= minProfit is checked. The swaps run to the min/max price; minProfit is the slippage bound.

Layout

Path What
src/GreekFlashExerciseV3.sol The exerciser. One shared deployment: the caller is the holder
src/V3Quoter.sol Never deployed: quotes a pool by calling its real swap and reverting out of the callback
artifacts/V3Quoter.runtime.hex Its runtime code, for an eth_call state override; test/Artifacts.t.sol keeps it equal to the build
routes/base.json The 33 routes (pools, token path, measured depth) and what was left out
research/aerodrome-flash.md Why Aerodrome, every market's depth, the scan scripts and raw quotes

Consumers

greekfi/maker vendors routes/base.json and artifacts/V3Quoter.runtime.hex into hedger/vendor/exercise/ with the commit they came from (SOURCE). Its hedger/flash_exercise.py quotes the routes (eth_call of V3Quoter under a state override) and builds the calldata. To ship a change here to the maker: merge here, copy the two files, update SOURCE, run the maker's tests.

A consumer grants the exerciser Perm.EXERCISE once per holder address (see "Permissions and approvals") and then sends only flashExercise. There is no per-option approve.

Interface

function flashExercise(
    address option,      // Greek v1.3 option the caller holds
    uint256 amount,      // option tokens, raw (option decimals = collateral decimals)
    address[] pools,     // 1 or 2 different v3-style pools, the underlying's first, ending in USDC
    uint256 minProfit,   // USDC raw the caller must net, else ProfitBelowMin
    uint256 deadline     // unix seconds, else DeadlinePassed
) external returns (uint256 profit); // sent to the caller
constructor(address factory);

The contract calls only token0(), token1() and swap() on a pool and implements uniswapV3SwapCallback, so it works on any Uniswap-v3-interface pool: Aerodrome Slipstream (which kept the callback name) and Uniswap v3 itself. The routes use Aerodrome's "Canonical CL factory" 0x9CB220581b91b0C83223012FE69688b92aD07a76, the deepest venue for every asset measured (see research/aerodrome-flash.md).

V3Quoter is never deployed. It quotes a pool by calling its real swap and reverting out of the callback, so a quote equals what the exerciser gets in the same block.

Permissions and approvals

  • Each holder grants the exerciser Perm.EXERCISE (bit 16) once, on the Greek factory: factory.addPermissions(exerciser, 16). There is no per-option approve. The contract calls option.exerciseFor(holder, amount), which burns the holder's options in place. The options never move, so a TRANSFER pause on the factory does not block a flash exercise.
  • The grant is standing and covers every option of that factory. The contract uses it only for the address that called flashExercise (next section). To revoke it, call factory.setPermissions(exerciser, mask) with bit 16 left out.
  • Inside the innermost callback the contract approves the factory for exactly the strike (toConsideration(amount, true)) and resets it to 0 right after the exercise.

Safety properties (tested)

  • Anyone can call flashExercise. The holder is always msg.sender: only the caller's options are burned and the profit goes to the caller. A caller who names another holder's option has nothing to burn and reverts.
  • The call's context (holder, option, amount, strike, pools) is hashed into transient storage before the first swap, and every callback must present data with that hash (Unauthorized). A pool that calls back with a different holder is refused.
  • uniswapV3SwapCallback runs only when msg.sender is the pool this contract is calling right now: the address is put in transient storage just before each swap, cleared on first use and cleared again when the swap returns, so a stray caller, a pool outside our call, or a pool calling back twice is refused.
  • flashExercise can't be entered while a call is open (Reentered). The lock is released at the end, so one transaction can make several calls in a row.
  • The pools are not checked against a factory on chain: the caller chooses them, from routes/base.json (test/fork/Routes.t.sol checks every route's factory and tokens). A hostile pool can only cost the caller who routed through it.
  • The option must be the factory's (factory, immutable): the factory must list its receipt (receipts(r)) and the receipt must point back at the option (UntrustedOption).
  • One pool, or two different pools, and a pool must be owed exactly one of its two tokens (BadRoute). An OTM exercise reverts (the strike can't be paid, or the buy-back costs more than the put paid).
  • Every swap must fill in full (PartialFill), so only USDC is left to hand back, and the whole USDC balance goes to the caller. A call leaves nothing behind. Anything sent to the contract by mistake is free for anyone: USDC goes to the next caller, any other token to a caller routing through their own pool. No allowances remain. The contract holds no ETH and has no receive.

Pins

what commit how verified
foundry-rs/forge-std ee93fdc45d1e5e4dee883afe0103109881a83549 (v1.9.7-2) same as example-hook and v4-template
solc 0.8.26 exactly (auto_detect_solc = false), evm cancun, no metadata hash artifacts/V3Quoter.runtime.hex is built with these settings; changing them changes it
forge used for tests 1.7.1

No other dependencies: the pool and Greek interfaces are declared in the source.

Set up after a clone:

git submodule update --init lib/forge-std

Tests

forge test --no-match-path 'test/fork/*'    # unit tests (fixed-price v3-style mock pools, mock Greek options)
ALCHEMY_API_KEY=... forge test -vv        # plus the Base fork tests through Alchemy

The fork tests read the key from ${ALCHEMY_API_KEY} in foundry.toml and skip when it's unset. test/fork/Routes.t.sol checks every route in routes/base.json at the latest block: the pools come from the factory, trade the route's tokens, have liquidity, and end in USDC. test/fork/BaseFork.t.sol pins block 60,625,000 and run against the real Aerodrome pools and the real v1.3 factory. Covered: WETH and cbBTC (8 decimals) calls and puts on one pool; cbETH, weETH and wstETH calls and cbETH and weETH puts through WETH; the maker's real held cbETH C2067, which reverts before expiry, in the window (OTM at the fork block) and after the deadline; minProfit, a caller with no grant, a callback from the real pool outside our call, and the deadline; two holders on one deployment; a flash exercise while the factory has transfers paused; a caller naming another holder's option; and a hostile pool that calls back with the holder rewritten. Profit equals V3Quoter's quote less the strike, to the unit.

The Coinbase tokenized stocks are B20 tokens: Rust precompiles in the Base node (Beryl upgrade, spec, source in base/base crates/common/precompiles/). Their account code is the single byte 0xef, a marker the node recognizes; stock Foundry and anvil copy the byte and fail with OpcodeNotFound on the first call. So test/fork/ has no stock test. Two ways to run one:

  • eth_simulateV1 on Alchemy Base, which runs the real precompiles. Done once on 2026-11-28 at block 63,679,849: deploy the exerciser from its init code, create an NVDAc/USDC call (strike 130) on the v1.3 factory, mint 1 share to a holder, grant Perm.EXERCISE, then flashExercise 5 minutes after expiry (time set by blockOverrides). Profit 18.904067 USDC, equal to the quote less the strike; 486k gas; nothing left in the contract. The maker's held NVDAc C150.92 reverted there (OTM at ~$149).
  • base/base-anvil, Base's Foundry fork with the precompiles built in. Untried here: it documents only non-fork use, and its v1.5.1 release trails mainnet's node.

The B20 transfer and approve return true like a standard ERC-20.

Unit tests also cover both token orders in every pool, a partial fill on either pool, a route that never reaches USDC, the same pool twice, a stray contract calling back mid-swap, a pool replaying its callback, a pool reentering flashExercise, a pool claiming both tokens, a pool that returns without calling back, and a token that tries both entry points from inside every transfer.

Base addresses (verified on chain, block ~60.62M)

address
Aerodrome Slipstream CL factory 0x9CB220581b91b0C83223012FE69688b92aD07a76
WETH/USDC (ts 50), the second pool of every LST route 0x4A7af46bC8aBc00048c6c7920a1488DAF568366c
Greek factory v1.3 0x9999999999906A9a5B3CFB1151Ac6812B3042191
WETH 0x4200000000000000000000000000000000000006
USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

Deploying (not done yet)

forge create src/GreekFlashExerciseV3.sol:GreekFlashExerciseV3 \
  --rpc-url "https://base-mainnet.g.alchemy.com/v2/$ALCHEMY_API_KEY" --account <deployer keystore> \
  --broadcast --verify \
  --constructor-args 0x9999999999906A9a5B3CFB1151Ac6812B3042191

forge create only dry-runs without --broadcast. --verify publishes the source on Basescan so a holder can read the contract before granting it. One deployment serves every holder. Each holder then grants it Perm.EXERCISE once (see "Permissions and approvals").

The deploy costs about 1.47M gas (forge test --gas-report). A flash exercise costs about 0.47-0.50M gas on one pool and 0.73-0.93M on two in the fork tests, with no approve transaction. Send it with a low priority fee: the Aerodrome pools charge a fee that grows with it (an MEV tax), which minProfit must absorb.

About

Flash-funded exercise of Greek options (Aerodrome Slipstream flash swaps)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages