Skip to content

Commit

Permalink
feat(v3-sdk): add decode to multicall (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 authored Oct 10, 2024
1 parent 2744804 commit 45ed414
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sdks/v3-sdk/src/multicall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ describe('Multicall', () => {
)
})
})

describe('#decodeMulticall', () => {
it('works for string array with length >1', async () => {
const calldatas: string[] = [
'0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
]

// first encode it
const multicall = Multicall.encodeMulticall(calldatas)
expect(multicall).toBe(
'0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0000000000000000000000000000000000000000000000000000000000000020bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
)

// then decode it
const decodedCalldata = Multicall.decodeMulticall(multicall)
expect(decodedCalldata.length).toBe(calldatas.length)
expect(decodedCalldata[0]).toBe(calldatas[0])
expect(decodedCalldata[1]).toBe(calldatas[1])
})
})
})
4 changes: 4 additions & 0 deletions sdks/v3-sdk/src/multicall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ export abstract class Multicall {

return calldatas.length === 1 ? calldatas[0] : Multicall.INTERFACE.encodeFunctionData('multicall', [calldatas])
}

public static decodeMulticall(multicall: string): string[] {
return Multicall.INTERFACE.decodeFunctionData('multicall', multicall).data
}
}

0 comments on commit 45ed414

Please sign in to comment.