Skip to content

Commit

Permalink
Merge pull request #110 from centrifuge/optimize-eth-block-handler
Browse files Browse the repository at this point in the history
fix: optimize updating pools
  • Loading branch information
hieronx committed Feb 29, 2024
2 parents c00db9a + 952dbe6 commit 6e5026d
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 122 deletions.
22 changes: 22 additions & 0 deletions abi/multicall.abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "aggregate",
"outputs": [
{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
{ "internalType": "bytes[]", "name": "returnData", "type": "bytes[]" }
],
"stateMutability": "payable",
"type": "function"
}
]
2 changes: 2 additions & 0 deletions chains-tinlake/centrifuge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ dataSources:
file: ./abi/shelf.abi.json
pile:
file: ./abi/pile.abi.json
multicall:
file: ./abi/multicall.abi.json
mapping:
file: ./dist/index.js
handlers:
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const RAY_DIGITS = 27
export const RAY = bnToBn(10).pow(bnToBn(RAY_DIGITS))
export const CPREC = (digits: number) => bnToBn(10).pow(bnToBn(digits))
export const DAIMainnetAddress = '0x6b175474e89094c44da98b954eedeac495271d0f'
export const multicallAddress = '0xeefba1e63905ef1d7acba5a8513c70307c1ce441'
export const tinlakePools = [
{
id: '0x09e43329552c9d81cf205fd5f44796fbc40c822e',
Expand Down
13 changes: 5 additions & 8 deletions src/helpers/paginatedGetter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import type { Entity } from '@subql/types-core'

type StoreArgs = Parameters<typeof store.getByField>

async function _paginatedGetter(
entity: StoreArgs[0],
field: StoreArgs[1],
value: StoreArgs[2]
): Promise<Entity[]> {
async function _paginatedGetter(entity: StoreArgs[0], field: StoreArgs[1], value: StoreArgs[2]): Promise<Entity[]> {
let results: Entity[] = []
const batch = 100
let amount = 0
let entities: Entity[]
do {
const entities: Entity[] = (await store.getByField(entity, field, value, {
entities = (await store.getByField(entity, field, value, {
offset: amount,
limit: batch,
})) as Entity[]
results = results.concat(entities)
amount += results.length
} while (results.length === batch)
amount += entities.length
} while (entities.length > 0)
return results
}
export const paginatedGetter = errorHandler(_paginatedGetter)
Loading

0 comments on commit 6e5026d

Please sign in to comment.