Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize updating pools #110

Merged
merged 23 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are exactly 100 entities to query, this while loop used to enter into an infinite loop. Now, we do one extra check to make sure there are no extra entities to fetch, and if not we exit the loop.

}
export const paginatedGetter = errorHandler(_paginatedGetter)
Loading
Loading