Skip to content

Commit

Permalink
reduce cache size
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Oct 29, 2022
1 parent ca05cb4 commit f0bcd83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions projects/deeplock/apiCache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const sdk = require("@defillama/sdk");
const abi = require("./abi.json");
const { pool2s } = require("../helper/pool2");
const { getUniqueAddresses } = require('../helper/utils')
const { vestingHelper, getCache, setCache, } = require("../helper/cache");

const project = 'deeplock'
Expand Down Expand Up @@ -85,6 +86,7 @@ const bscTvl = async (ts, _b, { bsc: block }) => {
calls, chain, block,
})
output.forEach(i => cCache.tokens.push(i.output.tokenAddress))
cCache.tokens = getUniqueAddresses(cCache.tokens)
return vestingHelper({
cache,
useDefaultCoreAssets: true,
Expand Down
2 changes: 2 additions & 0 deletions projects/pinksale/apiCache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const sdk = require("@defillama/sdk")
const abi = require('./abi')
const config = require('./config')
const { getUniqueAddresses } = require('../helper/utils')
const { vestingHelper, getCache, setCache, } = require("../helper/cache");

const project = 'pinksale'
Expand Down Expand Up @@ -38,6 +39,7 @@ Object.keys(config).forEach(chain => {
})

tokens.map(i => cCache.tokens.push(i.output[1]))
cCache.tokens = getUniqueAddresses(cCache.tokens)

const balance = await vestingHelper({
cache,
Expand Down
24 changes: 13 additions & 11 deletions projects/synthetix/apiCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { sliceIntoChunks, } = require('../helper/utils');
const { getCache, setCache } = require('../helper/cache');
const { request, gql } = require("graphql-request");
const project = 'synthetix'
const { log } = require('../helper/utils')

const QUERY_NO_BLOCK = gql`
query manyHolders($lastID: String, $block: Int) {
Expand Down Expand Up @@ -43,7 +44,7 @@ function chainTvl(chain) {
let totalTopStakersSNX = new BigNumber(0);

const holdersAll = sliceIntoChunks(await SNXHolders(snxGraphEndpoint, block, chain), 5000)
console.log('holders count: ', holdersAll.flat().length, chain)
log('holders count: ', holdersAll.flat().length, chain)

const issuanceRatio = (await sdk.api.abi.call({
block,
Expand All @@ -55,7 +56,7 @@ function chainTvl(chain) {
let i = 0

for (const holders of holdersAll) {
console.log('fetching %s of %s', ++i, holdersAll.length)
log('fetching %s of %s', ++i, holdersAll.length)

const calls = holders.map(holder => ({ target: synthetix, params: holder }))
const [ratio, collateral] = await Promise.all([
Expand Down Expand Up @@ -100,7 +101,7 @@ function chainTvl(chain) {
abi: abi['totalSupply']
})).output;

//console.log(unformattedSnxTotalSupply, new BigNumber(unformattedSnxTotalSupply).div(Math.pow(10, 18)))
//log(unformattedSnxTotalSupply, new BigNumber(unformattedSnxTotalSupply).div(Math.pow(10, 18)))
const snxTotalSupply = parseInt(new BigNumber(unformattedSnxTotalSupply).div(Math.pow(10, 18)));
const totalSNXLocked = percentLocked.times(snxTotalSupply);

Expand All @@ -125,24 +126,25 @@ function chainTvl(chain) {
async function SNXHolders(snxGraphEndpoint, block, chain) {
const cache = getCache(project, chain)
if (!cache.data) cache.data = []
let holders = new Set()
cache.data.forEach(d => holders.add(d.id))
let holders = new Set(cache.data)
let lastID = cache.lastID || ""
let holdersPage;
let i = 0
do {
console.log(chain, ++i, 'current last Id', lastID)
log(chain, ++i, 'current last Id', lastID)
holdersPage = (await request(snxGraphEndpoint, QUERY_NO_BLOCK, {
block,
lastID
})).holders
holdersPage = holdersPage.map(i => i.id)
cache.data.push(...holdersPage)
holdersPage.forEach(h => holders.add(h.id))
lastID = holdersPage[holdersPage.length - 1]?.id
cache.lastID = lastID
} while (holdersPage.length === 1e3);
holdersPage.forEach(h => holders.add(h))
lastID = holdersPage[holdersPage.length - 1]
if (lastID) cache.lastID = lastID
} while (lastID);
cache.data = Array.from(holders)
setCache(project, chain, cache)
return Array.from(holders)
return cache.data
}

module.exports = {
Expand Down

0 comments on commit f0bcd83

Please sign in to comment.