Skip to content

Commit 9bfa2af

Browse files
authored
fix(smart-wallet-sdk): Call struct ordering (#350)
1 parent 416793e commit 9bfa2af

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

sdks/smart-wallet-sdk/src/utils/callPlanner.test.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { zeroAddress } from 'viem'
1+
import { decodeAbiParameters, zeroAddress } from 'viem'
22

3-
import { CallPlanner } from './callPlanner'
3+
import { CALL_ABI_PARAMS, CallPlanner } from './callPlanner'
44

55

66
// Test constants
@@ -53,13 +53,14 @@ describe('CallPlanner', () => {
5353
describe('encode', () => {
5454
it('should correctly abi encode the calls', () => {
5555
const planner = new CallPlanner([
56-
{ to: TEST_ADDRESS_1, data: TEST_DATA_1, value: TEST_VALUE_1 }
56+
{ to: TEST_ADDRESS_1, value: TEST_VALUE_1, data: TEST_DATA_1 }
5757
])
5858

5959
const encoded = planner.encode()
60-
// We're just checking that it returns a hex string and doesn't throw
61-
expect(encoded).toMatch(/^0x/)
62-
expect(typeof encoded).toBe('string')
60+
61+
// decode the encoded data
62+
const decoded = decodeAbiParameters(CALL_ABI_PARAMS, encoded)
63+
expect(decoded).toEqual([[{ to: TEST_ADDRESS_1, value: TEST_VALUE_1, data: TEST_DATA_1 }]])
6364
})
6465

6566
it('should throw an error if there are no calls to encode', () => {
@@ -71,31 +72,31 @@ describe('CallPlanner', () => {
7172
describe('add', () => {
7273
it('should add a new call to the calls array', () => {
7374
const planner = new CallPlanner()
74-
planner.add(TEST_ADDRESS_1, TEST_DATA_1, TEST_VALUE_1)
75+
planner.add(TEST_ADDRESS_1, TEST_VALUE_1, TEST_DATA_1)
7576
expect(planner.calls).toEqual([{ to: TEST_ADDRESS_1, data: TEST_DATA_1, value: TEST_VALUE_1 }])
7677
})
7778

7879
it('should add a new call with bigint value', () => {
7980
const planner = new CallPlanner()
80-
planner.add(TEST_ADDRESS_1, TEST_DATA_1, 100n)
81+
planner.add(TEST_ADDRESS_1, 100n, TEST_DATA_1)
8182
expect(planner.calls).toEqual([{ to: TEST_ADDRESS_1, data: TEST_DATA_1, value: 100n }])
8283
})
8384

8485
it('should return the planner instance for chaining', () => {
8586
const planner = new CallPlanner()
86-
const result = planner.add(TEST_ADDRESS_1, TEST_DATA_1, TEST_VALUE_1)
87+
const result = planner.add(TEST_ADDRESS_1, TEST_VALUE_1, TEST_DATA_1)
8788
expect(result).toBe(planner)
8889
})
8990

9091
it('should allow chaining multiple add calls', () => {
9192
const planner = new CallPlanner()
9293
planner
93-
.add(TEST_ADDRESS_1, TEST_DATA_1, TEST_VALUE_1)
94-
.add(TEST_ADDRESS_1, TEST_DATA_2, TEST_VALUE_2)
94+
.add(TEST_ADDRESS_1, TEST_VALUE_1, TEST_DATA_1)
95+
.add(TEST_ADDRESS_1, TEST_VALUE_2, TEST_DATA_2)
9596

9697
expect(planner.calls).toEqual([
97-
{ to: TEST_ADDRESS_1, data: TEST_DATA_1, value: TEST_VALUE_1 },
98-
{ to: TEST_ADDRESS_1, data: TEST_DATA_2, value: TEST_VALUE_2 }
98+
{ to: TEST_ADDRESS_1, value: TEST_VALUE_1, data: TEST_DATA_1 },
99+
{ to: TEST_ADDRESS_1, value: TEST_VALUE_2, data: TEST_DATA_2 }
99100
])
100101
})
101102
})

sdks/smart-wallet-sdk/src/utils/callPlanner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { encodeAbiParameters } from 'viem'
33
import { Call } from '../types'
44

55
// Define the ABI parameter type for the call tuple
6-
const CALL_ABI_PARAMS = [
6+
export const CALL_ABI_PARAMS = [
77
{
88
type: 'tuple[]',
99
components: [
1010
{ type: 'address', name: 'to' },
11-
{ type: 'bytes', name: 'data' },
12-
{ type: 'uint256', name: 'value' }
11+
{ type: 'uint256', name: 'value' },
12+
{ type: 'bytes', name: 'data' }
1313
]
1414
}
1515
] as const
@@ -57,11 +57,11 @@ export class CallPlanner {
5757
/**
5858
* Add a command to execute a call
5959
* @param to The target address of the call
60-
* @param data The calldata for the call
6160
* @param value The ETH value to send with the call
61+
* @param data The calldata for the call
6262
*/
63-
add(to: `0x${string}`, data: `0x${string}`, value: bigint): CallPlanner {
64-
this.calls.push({ to, data, value })
63+
add(to: `0x${string}`, value: bigint, data: `0x${string}`): CallPlanner {
64+
this.calls.push({ to, value, data })
6565
return this
6666
}
6767
}

0 commit comments

Comments
 (0)