Skip to content

Commit

Permalink
Merge pull request DefiLlama#4499 from lilchizh/main
Browse files Browse the repository at this point in the history
Add QuickSwap V3 Adapter
  • Loading branch information
g1nt0ki authored Oct 29, 2022
2 parents f0bcd83 + 3b6be07 commit 4599fa7
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions projects/quickswap-v3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const { request, gql } = require('graphql-request');
const { getBlock } = require('../helper/getBlock');
const { sumTokens2 } = require('../helper/unwrapLPs')
const { log } = require('../helper/utils')

const graphs = {
polygon: "https://api.thegraph.com/subgraphs/name/sameepsi/quickswap-v3",
}

const blacklists = {
polygon: [ ],
}

function v3TvlPaged(chain) {
return async (_, _b, { [chain]: block }) => {
block = await getBlock(_, chain, { [chain]: block })
log('Fetching data for block: ',chain, block)
const balances = {}
const size = 1000
let lastId = ''
let pools
const graphQueryPaged = gql`
query poolQuery($lastId: String, $block: Int) {
pools(block: { number: $block } first:${size} where: {id_gt: $lastId totalValueLockedUSD_gt: 100}) {
id
token0 { id }
token1 { id }
}
}
`// remove the bad pools
const blacklisted = blacklists[chain] || []

do {
const res = await request(graphs[chain], graphQueryPaged, { lastId, block: block - 500 });
pools = res.pools
const tokensAndOwners = pools.map(i => ([[i.token0.id, i.id], [i.token1.id, i.id]])).flat()
log(chain, block, lastId, pools.length)
await sumTokens2({ balances, tokensAndOwners, chain, block, blacklistedTokens: blacklisted })
lastId = pools[pools.length - 1].id
} while (pools.length === size)

return balances
}
}

module.exports = {}

const chains = [ 'polygon',]

chains.forEach(chain => {
module.exports[chain] = {
tvl: v3TvlPaged(chain)
}
})

0 comments on commit 4599fa7

Please sign in to comment.