diff --git a/projects/enclabs/index.js b/projects/enclabs/index.js new file mode 100644 index 0000000000..967bfda073 --- /dev/null +++ b/projects/enclabs/index.js @@ -0,0 +1,34 @@ +const sdk = require("@defillama/sdk"); +const { cachedGraphQuery } = require('../helper/cache') +const { compoundExports2 } = require('../helper/compound') +const config = { + sonic: { + endpoint: sdk.graph.modifyEndpoint('Ha7WNTEk2U1MvMUVMmmv8e7uZxJUYY4n8r57iJHYyYcJ'), + }, + +} + +Object.keys(config).forEach(chain => { + module.exports[chain] = { tvl, borrowed, } +}) + +async function getPools(api) { + const { endpoint, corePools } = config[api.chain] + const poolSet = new Set(corePools.map(i=>i.toLowerCase())) + const { pools } = await cachedGraphQuery('enclabs/'+api.chain, endpoint, `{ pools { id }}`) + return pools.map(i => i.id).filter(i => !poolSet.has(i.toLowerCase())) +} + +async function tvl(...args) { + const [api] = args + const pools = await getPools(api) + const tvls = pools.map(i => compoundExports2({ comptroller: i})) + return sdk.util.sumChainTvls(tvls.map(i => i.tvl))(...args) +} + +async function borrowed(...args) { + const [api] = args + const pools = await getPools(api) + const tvls = pools.map(i => compoundExports2({ comptroller: i})) + return sdk.util.sumChainTvls(tvls.map(i => i.borrowed))(...args) +} \ No newline at end of file