Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
belopash committed Oct 1, 2024
1 parent 7ac0c91 commit 0f4cb63
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion evm/evm-typegen/src/multicall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as p from '@subsquid/evm-codec'
import {fun, ContractBase, type AbiFunction, type FunctionReturn, type FunctionArguments} from '@subsquid/evm-abi'
import {splitArray} from '@subsquid/util-internal'

const aggregate = fun('0x252dba42', "aggregate((address,bytes)[])", {
calls: p.array(p.struct({
Expand Down Expand Up @@ -152,3 +151,24 @@ export class Multicall extends ContractBase {
}
}

export function* splitSlice(maxSize: number, beg: number, end?: number): Iterable<[beg: number, end: number]> {
maxSize = Math.max(1, maxSize)
end = end ?? Number.MAX_SAFE_INTEGER
while (beg < end) {
let left = end - beg
let splits = Math.ceil(left / maxSize)
let step = Math.round(left / splits)
yield [beg, beg + step]
beg += step
}
}

export function* splitArray<T>(maxSize: number, arr: T[]): Iterable<T[]> {
if (arr.length <= maxSize) {
arr
} else {
for (let [beg, end] of splitSlice(maxSize, 0, arr.length)) {
yield arr.slice(beg, end)
}
}
}

0 comments on commit 0f4cb63

Please sign in to comment.