Created
April 30, 2023 21:58
-
-
Save maurobaraldi/47ae60203abab8351d03aa516e04f61d to your computer and use it in GitHub Desktop.
Uniswap Pools Analyser for Enthereum network.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Uniswap Pools Analyser | |
// Author: Mauro Navarro Baraldi <[email protected]> | |
// License: MIT License | |
// | |
// If you consider pay me a coffee here are the wallets | |
// { | |
// "bitcoin": "1EUGcJHS49242UpDXNVoLVzWSTVPRKmRth", | |
// "litecoin": "LbqRSz5i225FqED4QTFwjU5qQS72cRdvoe", | |
// "ethereum": "0xfA5c619f46848Fefe1E35Da1A04d4cBCeaf16B1f" | |
// } | |
// | |
// For more reference regarding Uniswap GraphQL API look at official API. | |
// https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3/graphql | |
// | |
function getUniswapPoolsEthereumNetwork() { | |
try { | |
// Retrieving and preparing data from Uniswap Pools (Ethereum network) | |
var data = {"query": "{ pools { id token0 { name totalValueLocked } token1 { name totalValueLocked } } } "}; | |
var payload = JSON.stringify(data); | |
var options = { | |
"method" : "POST", | |
"contentType" : "application/json", | |
"payload" : payload | |
}; | |
var url = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3"; | |
var _pools = JSON.parse(UrlFetchApp.fetch(url, options).getContentText())["data"]["pools"]; | |
var pools = []; | |
_pools.forEach(function(el) { | |
pools.push([ | |
"https://info.uniswap.org/#/pools/" + el.id, | |
el.token0.name, | |
el.token0.totalValueLocked, | |
el.token1.name, | |
el.token1.totalValueLocked, | |
]); | |
}); | |
console.log(pools); | |
// Writing data to cells | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getSheetByName('Sheet1'); | |
var numRows = pools.length; | |
var numCols = pools[0].length; | |
sheet.getRange(2,1,numRows,numCols).setValues(pools.reverse()) | |
} catch (error) { | |
// deal with any errors | |
Logger.log(error); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment