Skip to content

Commit

Permalink
sort allChains by value
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Nov 17, 2024
1 parent 874d837 commit 22c4514
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions defi/src/api2/cron-task/dimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ async function run() {
const protocolSummaries = {} as any
const parentProtocolSummaries = {} as any
const summaries: IJSON<RecordSummary> = {}
const chainSet = new Set<string>()
const chainMappingToVal = {} as {
[chain:string]: number
}
const parentProtocolsData: { [id: string]: any } = {}
adapterData.protocolSummaries = protocolSummaries
adapterData.parentProtocolSummaries = parentProtocolSummaries
Expand All @@ -139,7 +141,7 @@ async function run() {
}

adapterData.summaries = summaries
adapterData.allChains = Array.from(chainSet)
adapterData.allChains = Object.keys(chainMappingToVal).sort((a, b)=>chainMappingToVal[b]-chainMappingToVal[a])
adapterData.lastUpdated = getUnixTimeNow()
console.timeEnd(timeKey3)

Expand Down Expand Up @@ -184,7 +186,6 @@ async function run() {
protocol.info.slug = protocol.info.name?.toLowerCase().replace(/ /g, '-')
protocol.info.protocolType = info.protocolType ?? ProtocolType.PROTOCOL
protocol.info.chains = (info.chains ?? []).map(getDisplayChainNameCached)
protocol.info.chains.forEach((chain: string) => chainSet.add(chain))
protocol.info.defillamaId = protocol.info.defillamaId ?? info.id
protocol.info.displayName = protocol.info.displayName ?? info.name ?? protocol.info.name
const protocolTypeRecords = protocolRecordData[dimensionProtocolId]?.records ?? {}
Expand Down Expand Up @@ -404,6 +405,11 @@ async function run() {
Object.entries(chains).forEach(([chain, value]: any) => {
if (!result[chain]) result[chain] = {}
result[chain][subModuleName] = value
const chainName = getDisplayChainNameCached(chain)
if(chainMappingToVal[chainName] === undefined){
chainMappingToVal[chainName] = 0
}
chainMappingToVal[chainName] += value
})
})
protocolSummary.breakdown24h = result
Expand Down

0 comments on commit 22c4514

Please sign in to comment.