2

I have invested in UniSwap-V3 Liquidity Pool.

And how to track unclaimed fees programmatically?

I plan to have server-backend API fetch data to track unclaimed fees ($27.92 in picture)

enter image description here

I have tried to query position from EthScan Read Contract (in as second picture), but don't know how to get unclaimed fees from this data??

https://etherscan.io/address/0xc36442b4a4522e871399cd717abdd847ab11fe88#readContract

enter image description here

4

I solved this by going through powershell. I query the infura account that the uniswap interface queries to. Here is a powershell script for an DAI/USDC pool. You have to change some things for this to work for your pool.

The easiest way to do this is to go inspect the Uniswap webpage, find an "eth_call" query (not a "eth_blocknumber", and copy the data there. What you need to copy:

  • Your public key (green)
  • The data that is passed with the query (orange)

enter image description here

(You don't need to change this first part)

$r = Invoke-WebRequest -Uri "https://mainnet.infura.io/v3/099fc58e0de9451d80b18d7c74caa7c1" `
-Method "POST" `
-Headers @{
"method"="POST"
  "authority"="mainnet.infura.io"
  "scheme"="https"
  "path"="/v3/099fc58e0de9451d80b18d7c74caa7c1"
  "sec-ch-ua"="`" Not;A Brand`";v=`"99`", `"Google Chrome`";v=`"91`", `"Chromium`";v=`"91`""
  "accept"="application/json"
  "sec-ch-ua-mobile"="?0"
  "user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36"
  "origin"="https://app.uniswap.org"
  "sec-fetch-site"="cross-site"
  "sec-fetch-mode"="cors"
  "sec-fetch-dest"="empty"
  "referer"="https://app.uniswap.org/"
  "accept-encoding"="gzip, deflate, br"
  "accept-language"="nl-NL,nl;q=0.9,en-US;q=0.8,en;q=0.7,fr;q=0.6"
} `

update this part with your own data

-ContentType "application/json" `
-Body "[{`"jsonrpc`":`"2.0`",`"id`":224,`"method`":`"eth_call`",`
  "params`":[{`
    "from`":`"*PUBLIC-KEY-HERE*",` 
    "to`":`"0xc36442b4a4522e871399cd717abdd847ab11fe88`",` 
    "data`":`"*DATA-HERE*"
  },`"latest`"]}]"

Lastly, you need to make sense of the response. This code should parse the hex numbers to integers, but you need to scale them for your currencies. In the code below, it's DAI/USDC. You can just look at the value it returns, and change the powers so that you get the correct result. (You can take a look here if you want more info)

#convert the retrieved hex codes to your currency
$x = $r.Content | Out-String | ConvertFrom-Json 
$res = $x.result
$length = $res.length
$l1 = [Int64]$res.Substring(0,66)
$temp= '0x'+$res.Substring(66,$length-66)
$l2=[Int64]$temp

#change these powers to scale
$l1Scaled= $l1/[Math]::Pow(10,18)
$l2Scaled= $usdt/[Math]::Pow(10,6)
$out = 'Liquidity1:'+$l1Scaled+';Liquidity2:'+$l2Scaled
$out

Hope this works for you too.

EDIT to answer Richard's question: So take this random pool. Inspect the page and go to the network tab. enter image description here

Here you see a lot of outgoing queries. If you scroll down in the "Header" subtab, you can see the method. Most of these are probably "eth_blockNumber", but you need one that says "eth_call" as shown in the first picture. Once you find one of these, expand the first element of "Request Payload".

"0" -> "params" -> "0" -> "data"

Then you just copy whatever is in the data field (orange in the first picture).

2
  • Thank you for the answer. Are you able to supply a link to give a hint as to what should go in the data element? – Richard Hodges Jun 7 at 11:04
  • 1
    I edited the post to (hopefully) answer your question. – Gwen_vere Jun 9 at 17:18
1

There's a much easier way by just calling the "DeBank Open API".

Let's say we have a random wallet address who has a Uniswap V3 position:'0xa71cabc14966c6fae86c05630a20ba1c90944a1f'

Then we make a http request to this API:

https://openapi.debank.com/v1/user/protocol?id=0xa71cabc14966c6fae86c05630a20ba1c90944a1f&protocol_id=uniswap3

Then we will get all the details we need from the response of the request.

"reward_token_list": [
          {
            "id": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
            "chain": "eth",
            "name": "USD Coin",
            "symbol": "USDC",
            "display_symbol": null,
            "optimized_symbol": "USDC",
            "decimals": 6,
            "logo_url": "https://static.debank.com/image/token/logo_url/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48/adee072b10b0db7c5bd7a28dd4fbe96f.png",
            "price": 1,
            "is_verified": true,
            "is_core": true,
            "is_wallet": true,
            "time_at": 1533324504,
            "amount": 101.54812149459985
          },
          {
            "id": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
            "chain": "eth",
            "name": "Wrapped Ether",
            "symbol": "WETH",
            "display_symbol": null,
            "optimized_symbol": "WETH",
            "decimals": 18,
            "logo_url": "https://static.debank.com/image/token/logo_url/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2/61844453e63cf81301f845d7864236f6.png",
            "price": 2291.98,
            "is_verified": true,
            "is_core": true,
            "is_wallet": true,
            "time_at": 1513077455,
            "amount": 0.057207378958831115
          }
        ]

See all the API methods here: https://openapi.debank.com/docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.