forked from DefiLlama/DefiLlama-Adapters
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DefiLlama#4499 from lilchizh/main
Add QuickSwap V3 Adapter
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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) | ||
} | ||
}) |