Skip to content

Commit e5db325

Browse files
authored
[DEVREL-1425] fix: chunk setConfig to avoid calldata limits on L2s (#1935)
1 parent 306ee69 commit e5db325

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

.changeset/chunk-setconfig-l2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@layerzerolabs/protocol-devtools-evm": patch
3+
---
4+
5+
Chunk setConfig into batches of 10 to avoid calldata/gas limits on L2s

packages/protocol-devtools-evm/src/endpointv2/sdk.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ import { BlockedUln302 } from '@/uln302/blockedSdk'
3838
const CONFIG_TYPE_EXECUTOR = 1
3939
const CONFIG_TYPE_ULN = 2
4040
const CONFIG_TYPE_READ_LIB_CONFIG = 1
41+
const CONFIG_BATCH_SIZE = 10
42+
43+
const chunkArray = <T>(array: T[], size: number): T[][] => {
44+
const chunks: T[][] = []
45+
for (let i = 0; i < array.length; i += size) {
46+
chunks.push(array.slice(i, i + size))
47+
}
48+
return chunks
49+
}
4150

4251
/**
4352
* EVM-specific SDK for EndpointV2 contracts
@@ -283,14 +292,15 @@ export class EndpointV2 extends OmniSDK implements IEndpointV2 {
283292
async setConfig(oapp: OmniAddress, uln: OmniAddress, setConfigParam: SetConfigParam[]): Promise<OmniTransaction[]> {
284293
this.logger.debug(`Setting config for OApp ${oapp} to ULN ${uln} with config ${printJson(setConfigParam)}`)
285294

286-
const data = this.contract.contract.interface.encodeFunctionData('setConfig', [oapp, uln, setConfigParam])
295+
const chunks = chunkArray(setConfigParam, CONFIG_BATCH_SIZE)
287296

288-
return [
289-
{
297+
return chunks.map((chunk) => {
298+
const data = this.contract.contract.interface.encodeFunctionData('setConfig', [oapp, uln, chunk])
299+
return {
290300
...this.createTransaction(data),
291-
description: `Setting config for ULN ${uln} to ${printJson(setConfigParam)}`,
292-
},
293-
]
301+
description: `Setting config for ULN ${uln} to ${printJson(chunk)}`,
302+
}
303+
})
294304
}
295305

296306
async setUlnConfig(

0 commit comments

Comments
 (0)