Skip to content

Instantly share code, notes, and snippets.

@cheekybastard
Forked from banteg/uniswap-v3.py
Created May 9, 2021 10:25
Show Gist options
  • Select an option

  • Save cheekybastard/b5d4053a5f13551f61d79a656cf17f2a to your computer and use it in GitHub Desktop.

Select an option

Save cheekybastard/b5d4053a5f13551f61d79a656cf17f2a to your computer and use it in GitHub Desktop.

Revisions

  1. @banteg banteg revised this gist May 8, 2021. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions uniswap-v3.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    from brownie import accounts, Contract, Wei
    from brownie import accounts, chain, Contract, Wei
    from eth_abi.packed import encode_abi_packed

    user = accounts[0]
    @@ -16,6 +16,7 @@

    path = encode_abi_packed(['address', 'uint24', 'address', 'uint24', 'address'], [str(weth), 3000, dai, 500, rai])
    quote = quoter.quoteExactInput.call(path, amount)
    deadline = chain.time() + 600

    tx = router.exactInput((path, user, deadline, amount, quote * 0.99))
    tx.info()
    tx.info()
  2. @banteg banteg created this gist May 8, 2021.
    21 changes: 21 additions & 0 deletions uniswap-v3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    from brownie import accounts, Contract, Wei
    from eth_abi.packed import encode_abi_packed

    user = accounts[0]
    weth = Contract('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', owner=user)
    dai = '0x6B175474E89094C44Da98b954EedeAC495271d0F'
    rai = '0x03ab458634910AaD20eF5f1C8ee96F1D6ac54919'

    # https://github.com/Uniswap/uniswap-v3-periphery/blob/main/deploys.md
    quoter = Contract('0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6')
    router = Contract('0xE592427A0AEce92De3Edee1F18E0157C05861564', owner=user)

    amount = Wei('1 ether')
    weth.deposit({'amount': amount})
    weth.approve(router, amount)

    path = encode_abi_packed(['address', 'uint24', 'address', 'uint24', 'address'], [str(weth), 3000, dai, 500, rai])
    quote = quoter.quoteExactInput.call(path, amount)

    tx = router.exactInput((path, user, deadline, amount, quote * 0.99))
    tx.info()