Skip to content

Commit 2f0c3bd

Browse files
committed
feat: added composability encoding
1 parent 6b5a539 commit 2f0c3bd

2 files changed

Lines changed: 305 additions & 0 deletions

File tree

src/core/encoding/abis.ts

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
export const COMPOSABILITY_MODULE_ABI_V1_1_0 = [
2+
{
3+
type: 'constructor',
4+
inputs: [{ name: '_defaultEpAddress', type: 'address', internalType: 'address' }],
5+
stateMutability: 'nonpayable',
6+
},
7+
{
8+
type: 'function',
9+
name: 'DEFAULT_EP_ADDRESS',
10+
inputs: [],
11+
outputs: [{ name: '', type: 'address', internalType: 'address' }],
12+
stateMutability: 'view',
13+
},
14+
{
15+
type: 'function',
16+
name: 'executeComposable',
17+
inputs: [
18+
{
19+
name: 'cExecutions',
20+
type: 'tuple[]',
21+
internalType: 'struct ComposableExecution[]',
22+
components: [
23+
{ name: 'functionSig', type: 'bytes4', internalType: 'bytes4' },
24+
{
25+
name: 'inputParams',
26+
type: 'tuple[]',
27+
internalType: 'struct InputParam[]',
28+
components: [
29+
{
30+
name: 'paramType',
31+
type: 'uint8',
32+
internalType: 'enum InputParamType',
33+
},
34+
{
35+
name: 'fetcherType',
36+
type: 'uint8',
37+
internalType: 'enum InputParamFetcherType',
38+
},
39+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
40+
{
41+
name: 'constraints',
42+
type: 'tuple[]',
43+
internalType: 'struct Constraint[]',
44+
components: [
45+
{
46+
name: 'constraintType',
47+
type: 'uint8',
48+
internalType: 'enum ConstraintType',
49+
},
50+
{
51+
name: 'referenceData',
52+
type: 'bytes',
53+
internalType: 'bytes',
54+
},
55+
],
56+
},
57+
],
58+
},
59+
{
60+
name: 'outputParams',
61+
type: 'tuple[]',
62+
internalType: 'struct OutputParam[]',
63+
components: [
64+
{
65+
name: 'fetcherType',
66+
type: 'uint8',
67+
internalType: 'enum OutputParamFetcherType',
68+
},
69+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
70+
],
71+
},
72+
],
73+
},
74+
],
75+
outputs: [],
76+
stateMutability: 'payable',
77+
},
78+
{
79+
type: 'function',
80+
name: 'executeComposableCall',
81+
inputs: [
82+
{
83+
name: 'cExecutions',
84+
type: 'tuple[]',
85+
internalType: 'struct ComposableExecution[]',
86+
components: [
87+
{ name: 'functionSig', type: 'bytes4', internalType: 'bytes4' },
88+
{
89+
name: 'inputParams',
90+
type: 'tuple[]',
91+
internalType: 'struct InputParam[]',
92+
components: [
93+
{
94+
name: 'paramType',
95+
type: 'uint8',
96+
internalType: 'enum InputParamType',
97+
},
98+
{
99+
name: 'fetcherType',
100+
type: 'uint8',
101+
internalType: 'enum InputParamFetcherType',
102+
},
103+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
104+
{
105+
name: 'constraints',
106+
type: 'tuple[]',
107+
internalType: 'struct Constraint[]',
108+
components: [
109+
{
110+
name: 'constraintType',
111+
type: 'uint8',
112+
internalType: 'enum ConstraintType',
113+
},
114+
{
115+
name: 'referenceData',
116+
type: 'bytes',
117+
internalType: 'bytes',
118+
},
119+
],
120+
},
121+
],
122+
},
123+
{
124+
name: 'outputParams',
125+
type: 'tuple[]',
126+
internalType: 'struct OutputParam[]',
127+
components: [
128+
{
129+
name: 'fetcherType',
130+
type: 'uint8',
131+
internalType: 'enum OutputParamFetcherType',
132+
},
133+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
134+
],
135+
},
136+
],
137+
},
138+
],
139+
outputs: [],
140+
stateMutability: 'nonpayable',
141+
},
142+
{
143+
type: 'function',
144+
name: 'executeComposableDelegateCall',
145+
inputs: [
146+
{
147+
name: 'cExecutions',
148+
type: 'tuple[]',
149+
internalType: 'struct ComposableExecution[]',
150+
components: [
151+
{ name: 'functionSig', type: 'bytes4', internalType: 'bytes4' },
152+
{
153+
name: 'inputParams',
154+
type: 'tuple[]',
155+
internalType: 'struct InputParam[]',
156+
components: [
157+
{
158+
name: 'paramType',
159+
type: 'uint8',
160+
internalType: 'enum InputParamType',
161+
},
162+
{
163+
name: 'fetcherType',
164+
type: 'uint8',
165+
internalType: 'enum InputParamFetcherType',
166+
},
167+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
168+
{
169+
name: 'constraints',
170+
type: 'tuple[]',
171+
internalType: 'struct Constraint[]',
172+
components: [
173+
{
174+
name: 'constraintType',
175+
type: 'uint8',
176+
internalType: 'enum ConstraintType',
177+
},
178+
{
179+
name: 'referenceData',
180+
type: 'bytes',
181+
internalType: 'bytes',
182+
},
183+
],
184+
},
185+
],
186+
},
187+
{
188+
name: 'outputParams',
189+
type: 'tuple[]',
190+
internalType: 'struct OutputParam[]',
191+
components: [
192+
{
193+
name: 'fetcherType',
194+
type: 'uint8',
195+
internalType: 'enum OutputParamFetcherType',
196+
},
197+
{ name: 'paramData', type: 'bytes', internalType: 'bytes' },
198+
],
199+
},
200+
],
201+
},
202+
],
203+
outputs: [],
204+
stateMutability: 'nonpayable',
205+
},
206+
{
207+
type: 'function',
208+
name: 'getEntryPoint',
209+
inputs: [{ name: 'account', type: 'address', internalType: 'address' }],
210+
outputs: [{ name: '', type: 'address', internalType: 'address' }],
211+
stateMutability: 'view',
212+
},
213+
{
214+
type: 'function',
215+
name: 'isInitialized',
216+
inputs: [{ name: 'account', type: 'address', internalType: 'address' }],
217+
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
218+
stateMutability: 'view',
219+
},
220+
{
221+
type: 'function',
222+
name: 'isModuleType',
223+
inputs: [{ name: 'moduleTypeId', type: 'uint256', internalType: 'uint256' }],
224+
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
225+
stateMutability: 'pure',
226+
},
227+
{
228+
type: 'function',
229+
name: 'onInstall',
230+
inputs: [{ name: 'data', type: 'bytes', internalType: 'bytes' }],
231+
outputs: [],
232+
stateMutability: 'nonpayable',
233+
},
234+
{
235+
type: 'function',
236+
name: 'onUninstall',
237+
inputs: [{ name: 'data', type: 'bytes', internalType: 'bytes' }],
238+
outputs: [],
239+
stateMutability: 'nonpayable',
240+
},
241+
{
242+
type: 'function',
243+
name: 'setEntryPoint',
244+
inputs: [{ name: '_entryPoint', type: 'address', internalType: 'address' }],
245+
outputs: [],
246+
stateMutability: 'nonpayable',
247+
},
248+
{
249+
type: 'error',
250+
name: 'AlreadyInitialized',
251+
inputs: [{ name: 'smartAccount', type: 'address', internalType: 'address' }],
252+
},
253+
{ type: 'error', name: 'ComposableExecutionFailed', inputs: [] },
254+
{
255+
type: 'error',
256+
name: 'ConstraintNotMet',
257+
inputs: [
258+
{
259+
name: 'constraintType',
260+
type: 'uint8',
261+
internalType: 'enum ConstraintType',
262+
},
263+
],
264+
},
265+
{ type: 'error', name: 'DelegateCallOnly', inputs: [] },
266+
{ type: 'error', name: 'FailedToReturnMsgValue', inputs: [] },
267+
{ type: 'error', name: 'InvalidConstraintType', inputs: [] },
268+
{ type: 'error', name: 'InvalidOutputParamFetcherType', inputs: [] },
269+
{
270+
type: 'error',
271+
name: 'InvalidParameterEncoding',
272+
inputs: [{ name: 'message', type: 'string', internalType: 'string' }],
273+
},
274+
{
275+
type: 'error',
276+
name: 'NotInitialized',
277+
inputs: [{ name: 'smartAccount', type: 'address', internalType: 'address' }],
278+
},
279+
{ type: 'error', name: 'OnlyEntryPointOrAccount', inputs: [] },
280+
{ type: 'error', name: 'Output_StaticCallFailed', inputs: [] },
281+
{ type: 'error', name: 'ZeroAddressNotAllowed', inputs: [] },
282+
];

src/core/encoding/encoding.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import type { AnyData } from '../types';
1515
import { encodeAddress, encodeRuntimeFunctionData } from './runtimeAbiEncoding';
1616
import {
17+
type ComposableCall,
1718
type Constraint,
1819
type ConstraintField,
1920
ConstraintType,
@@ -30,6 +31,7 @@ import {
3031
type runtimeERC20AllowanceOfParams,
3132
} from './types';
3233
import { isRuntimeComposableValue, toBytes32 } from './utils';
34+
import { COMPOSABILITY_MODULE_ABI_V1_1_0 } from './abis';
3335

3436
export const prepareInputParam = (
3537
fetcherType: InputParamFetcherType,
@@ -390,3 +392,24 @@ export const compressCalldataInputParams = (inputParams: InputParam[]): InputPar
390392

391393
return compressedParams;
392394
};
395+
396+
/**
397+
* @description Encodes a composable calls for execution
398+
* @param call - The calls to encode
399+
* @returns The encoded composable compatible call
400+
*/
401+
const encodeExecuteComposable = async (calls: ComposableCall[]): Promise<Hex> => {
402+
const composableCalls = calls.map((call) => {
403+
return {
404+
functionSig: call.functionSig,
405+
inputParams: call.inputParams,
406+
outputParams: call.outputParams,
407+
};
408+
});
409+
410+
return encodeFunctionData({
411+
abi: COMPOSABILITY_MODULE_ABI_V1_1_0,
412+
functionName: 'executeComposable', // Function selector in Composability module which executes the composable calls.
413+
args: [composableCalls], // Multiple composable calls can be batched here.
414+
});
415+
};

0 commit comments

Comments
 (0)