@lifi/composer-sdk 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/_virtual/_rolldown/runtime.cjs +33 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/authoring/FlowBuilderCore.cjs +102 -120
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
- package/dist/authoring/FlowBuilderCore.d.cts +58 -61
- package/dist/authoring/FlowBuilderCore.d.ts +58 -61
- package/dist/authoring/FlowBuilderCore.js +99 -97
- package/dist/authoring/FlowBuilderCore.js.map +1 -1
- package/dist/authoring/handles.cjs +25 -40
- package/dist/authoring/handles.cjs.map +1 -1
- package/dist/authoring/handles.d.cts +33 -34
- package/dist/authoring/handles.d.ts +33 -34
- package/dist/authoring/handles.js +21 -13
- package/dist/authoring/handles.js.map +1 -1
- package/dist/authoring/raw.cjs +85 -44
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.d.cts +8 -8
- package/dist/authoring/raw.d.ts +8 -8
- package/dist/authoring/raw.js +83 -19
- package/dist/authoring/raw.js.map +1 -1
- package/dist/authoring/signatureArgs.cjs +81 -103
- package/dist/authoring/signatureArgs.cjs.map +1 -1
- package/dist/authoring/signatureArgs.d.cts +63 -64
- package/dist/authoring/signatureArgs.d.ts +63 -64
- package/dist/authoring/signatureArgs.js +76 -75
- package/dist/authoring/signatureArgs.js.map +1 -1
- package/dist/client.cjs +172 -220
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +131 -131
- package/dist/client.d.ts +131 -131
- package/dist/client.js +165 -198
- package/dist/client.js.map +1 -1
- package/dist/discovery.cjs +0 -17
- package/dist/discovery.d.cts +57 -56
- package/dist/discovery.d.ts +57 -56
- package/dist/discovery.js +1 -1
- package/dist/errors.cjs +211 -159
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +84 -84
- package/dist/errors.d.ts +84 -84
- package/dist/errors.js +201 -120
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.cjs +0 -17
- package/dist/generated/config.generated.d.cts +804 -936
- package/dist/generated/config.generated.d.ts +804 -936
- package/dist/generated/config.generated.js +1 -1
- package/dist/generated/guards.generated.cjs +25 -35
- package/dist/generated/guards.generated.cjs.map +1 -1
- package/dist/generated/guards.generated.d.cts +20 -4
- package/dist/generated/guards.generated.d.ts +20 -4
- package/dist/generated/guards.generated.js +19 -11
- package/dist/generated/guards.generated.js.map +1 -1
- package/dist/generated/materialisers.generated.cjs +25 -35
- package/dist/generated/materialisers.generated.cjs.map +1 -1
- package/dist/generated/materialisers.generated.d.cts +17 -4
- package/dist/generated/materialisers.generated.d.ts +17 -4
- package/dist/generated/materialisers.generated.js +19 -11
- package/dist/generated/materialisers.generated.js.map +1 -1
- package/dist/generated/operations.generated.cjs +236 -277
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +719 -708
- package/dist/generated/operations.generated.d.ts +719 -708
- package/dist/generated/operations.generated.js +235 -256
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/generated/preconditions.generated.cjs +25 -35
- package/dist/generated/preconditions.generated.cjs.map +1 -1
- package/dist/generated/preconditions.generated.d.cts +17 -4
- package/dist/generated/preconditions.generated.d.ts +17 -4
- package/dist/generated/preconditions.generated.js +19 -11
- package/dist/generated/preconditions.generated.js.map +1 -1
- package/dist/index.cjs +131 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -43
- package/dist/index.d.ts +29 -43
- package/dist/index.js +96 -45
- package/dist/index.js.map +1 -1
- package/dist/outputs.cjs +11 -32
- package/dist/outputs.cjs.map +1 -1
- package/dist/outputs.d.cts +5 -5
- package/dist/outputs.d.ts +5 -5
- package/dist/outputs.js +10 -8
- package/dist/outputs.js.map +1 -1
- package/dist/raw.cjs +21 -33
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.d.cts +8 -4
- package/dist/raw.d.ts +8 -4
- package/dist/raw.js +12 -7
- package/dist/raw.js.map +1 -1
- package/dist/reachability.cjs +82 -112
- package/dist/reachability.cjs.map +1 -1
- package/dist/reachability.d.cts +33 -59
- package/dist/reachability.d.ts +33 -59
- package/dist/reachability.js +81 -88
- package/dist/reachability.js.map +1 -1
- package/dist/resources.cjs +47 -32
- package/dist/resources.cjs.map +1 -1
- package/dist/resources.d.cts +50 -3
- package/dist/resources.d.ts +50 -3
- package/dist/resources.js +42 -9
- package/dist/resources.js.map +1 -1
- package/dist/responseSchemas.cjs +99 -111
- package/dist/responseSchemas.cjs.map +1 -1
- package/dist/responseSchemas.d.cts +34 -34
- package/dist/responseSchemas.d.ts +34 -34
- package/dist/responseSchemas.js +85 -66
- package/dist/responseSchemas.js.map +1 -1
- package/dist/routeAmount.cjs +61 -31
- package/dist/routeAmount.cjs.map +1 -1
- package/dist/routeAmount.d.cts +52 -2
- package/dist/routeAmount.d.ts +52 -2
- package/dist/routeAmount.js +56 -8
- package/dist/routeAmount.js.map +1 -1
- package/dist/run/inputs.cjs +56 -48
- package/dist/run/inputs.cjs.map +1 -1
- package/dist/run/inputs.d.cts +70 -74
- package/dist/run/inputs.d.ts +70 -74
- package/dist/run/inputs.js +54 -23
- package/dist/run/inputs.js.map +1 -1
- package/dist/run/simulate.cjs +38 -43
- package/dist/run/simulate.cjs.map +1 -1
- package/dist/run/simulate.d.cts +36 -36
- package/dist/run/simulate.d.ts +36 -36
- package/dist/run/simulate.js +37 -19
- package/dist/run/simulate.js.map +1 -1
- package/dist/sdk.cjs +55 -66
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +108 -111
- package/dist/sdk.d.ts +108 -111
- package/dist/sdk.js +52 -44
- package/dist/sdk.js.map +1 -1
- package/dist/types.cjs +0 -17
- package/dist/types.d.cts +22 -22
- package/dist/types.d.ts +22 -22
- package/dist/types.js +1 -1
- package/package.json +4 -4
- package/src/client.ts +2 -2
- package/src/examples/aaveClaimRewards.ts +2 -1
- package/src/examples/emitCustomEvent.ts +1 -2
- package/src/examples/run.ts +1 -1
- package/src/examples/transferTokens.ts +21 -17
- package/src/generated/config.generated.ts +20 -9
- package/src/generated/operations.generated.ts +28 -5
- package/dist/discovery.cjs.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/generated/config.generated.cjs.map +0 -1
- package/dist/generated/config.generated.js.map +0 -1
- package/dist/guards.generated-CDCgYGZo.d.cts +0 -24
- package/dist/guards.generated-CdYcs4h0.d.ts +0 -24
- package/dist/materialisers.generated-BMkBQgWZ.d.ts +0 -24
- package/dist/materialisers.generated-BWq5oePO.d.cts +0 -24
- package/dist/preconditions.generated-DblS13Wq.d.cts +0 -24
- package/dist/preconditions.generated-U7YpVh30.d.ts +0 -24
- package/dist/raw-BvRghN3r.d.ts +0 -20
- package/dist/raw-s1rer8X3.d.cts +0 -20
- package/dist/resources-BKlFxjo8.d.cts +0 -56
- package/dist/resources-CYis1_DS.d.ts +0 -56
- package/dist/routeAmount-DdbJYJyM.d.cts +0 -55
- package/dist/routeAmount-DdbJYJyM.d.ts +0 -55
- package/dist/types.cjs.map +0 -1
- package/dist/types.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { AbiTypeToOutputKind, TypedGuard } from "../types.js";
|
|
2
|
+
import { AnyRefBindable, OutputHandle, RefBindable } from "./handles.js";
|
|
3
|
+
import { CallArgs } from "./FlowBuilderCore.js";
|
|
4
|
+
import { Ref } from "@lifi/compose-spec";
|
|
5
|
+
import { ParseAbiItem } from "abitype";
|
|
6
|
+
//#region src/authoring/signatureArgs.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Type-level extraction of named bind keys from a function signature string.
|
|
9
9
|
* When `TSig` is a string literal matching a Solidity function signature,
|
|
@@ -18,34 +18,32 @@ import { AnyRefBindable, RefBindable, OutputHandle } from './handles.js';
|
|
|
18
18
|
* rather than a node `bind` record, so a literal is not accepted here: only
|
|
19
19
|
* values that resolve to a `$ref`.
|
|
20
20
|
*/
|
|
21
|
-
type SignatureBind<TSig extends string> = string extends TSig ? Record<string, AnyRefBindable> : ParseAbiItem<TSig> extends {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} ? {
|
|
28
|
-
readonly [P in I[number] as P['name']]: RefBindable<AbiTypeToOutputKind<P['type']>>;
|
|
29
|
-
} : Record<string, AnyRefBindable>;
|
|
21
|
+
export type SignatureBind<TSig extends string> = string extends TSig ? Record<string, AnyRefBindable> : ParseAbiItem<TSig> extends {
|
|
22
|
+
type: "function";
|
|
23
|
+
inputs: infer I extends readonly {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}[];
|
|
27
|
+
} ? { readonly [P in I[number] as P["name"]]: RefBindable<AbiTypeToOutputKind<P["type"]>>; } : Record<string, AnyRefBindable>;
|
|
30
28
|
/**
|
|
31
29
|
* Describes the output type(s) of a parsed function signature as a
|
|
32
30
|
* human-readable string for inclusion in type-level error messages.
|
|
33
31
|
*/
|
|
34
32
|
type DescribeOutputs<O extends readonly {
|
|
35
|
-
|
|
33
|
+
type: string;
|
|
36
34
|
}[]> = O extends readonly [{
|
|
37
|
-
|
|
38
|
-
}] ? T :
|
|
35
|
+
type: infer T extends string;
|
|
36
|
+
}] ? T : "multiple values";
|
|
39
37
|
/**
|
|
40
38
|
* A string-literal type that surfaces a clear error when the user provides a
|
|
41
39
|
* function signature whose return type is not supported by core.call.
|
|
42
40
|
* The message is visible in IDE tooltips and compiler diagnostics.
|
|
43
41
|
*/
|
|
44
42
|
type UnsupportedReturnTypeError<TLabel extends string, TSig extends string> = ParseAbiItem<TSig> extends {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
type: "function";
|
|
44
|
+
outputs: infer O extends readonly {
|
|
45
|
+
type: string;
|
|
46
|
+
}[];
|
|
49
47
|
} ? `[TypeError] ${TLabel}: return type '${DescribeOutputs<O>}' is not supported — only 'uint256' or void signatures are allowed` : `[TypeError] ${TLabel}: unable to parse return type from signature`;
|
|
50
48
|
/**
|
|
51
49
|
* Conditional output type for `core.call` based on the function signature's
|
|
@@ -59,22 +57,22 @@ type UnsupportedReturnTypeError<TLabel extends string, TSig extends string> = Pa
|
|
|
59
57
|
* constant), the type falls back to `{ result: OutputHandle | undefined }`
|
|
60
58
|
* so that both void and uint256 call sites remain assignable.
|
|
61
59
|
*/
|
|
62
|
-
type CoreCallResult<TSig extends string> = string extends TSig ? {
|
|
63
|
-
|
|
60
|
+
export type CoreCallResult<TSig extends string> = string extends TSig ? {
|
|
61
|
+
readonly result: OutputHandle<"uint256"> | undefined;
|
|
64
62
|
} : ParseAbiItem<TSig> extends {
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
type: "function";
|
|
64
|
+
outputs: readonly [];
|
|
67
65
|
} ? {
|
|
68
|
-
|
|
66
|
+
readonly result: undefined;
|
|
69
67
|
} : ParseAbiItem<TSig> extends {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
type: "function";
|
|
69
|
+
outputs: readonly [{
|
|
70
|
+
type: "uint256";
|
|
71
|
+
}];
|
|
74
72
|
} ? {
|
|
75
|
-
|
|
73
|
+
readonly result: OutputHandle<"uint256">;
|
|
76
74
|
} : {
|
|
77
|
-
|
|
75
|
+
readonly result: UnsupportedReturnTypeError<"core.call", TSig>;
|
|
78
76
|
};
|
|
79
77
|
/**
|
|
80
78
|
* Conditional output type for `core.staticCall`. staticCall always reads a
|
|
@@ -83,22 +81,22 @@ type CoreCallResult<TSig extends string> = string extends TSig ? {
|
|
|
83
81
|
* - `returns (uint256)` → `{ result: OutputHandle }`
|
|
84
82
|
* - No returns / other → `{ result: "[TypeError] ..." }` (compile-time error)
|
|
85
83
|
*/
|
|
86
|
-
type StaticCallResult<TSig extends string> = string extends TSig ? {
|
|
87
|
-
|
|
84
|
+
export type StaticCallResult<TSig extends string> = string extends TSig ? {
|
|
85
|
+
readonly result: OutputHandle<"uint256">;
|
|
88
86
|
} : ParseAbiItem<TSig> extends {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
type: "function";
|
|
88
|
+
outputs: readonly [{
|
|
89
|
+
type: "uint256";
|
|
90
|
+
}];
|
|
93
91
|
} ? {
|
|
94
|
-
|
|
92
|
+
readonly result: OutputHandle<"uint256">;
|
|
95
93
|
} : ParseAbiItem<TSig> extends {
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
type: "function";
|
|
95
|
+
outputs: readonly [];
|
|
98
96
|
} ? {
|
|
99
|
-
|
|
97
|
+
readonly result: `[TypeError] core.staticCall: function has no return value — staticCall requires a 'returns (uint256)' signature`;
|
|
100
98
|
} : {
|
|
101
|
-
|
|
99
|
+
readonly result: UnsupportedReturnTypeError<"core.staticCall", TSig>;
|
|
102
100
|
};
|
|
103
101
|
/**
|
|
104
102
|
* Parses a Solidity function signature and returns parameter names in order.
|
|
@@ -108,24 +106,24 @@ type StaticCallResult<TSig extends string> = string extends TSig ? {
|
|
|
108
106
|
*
|
|
109
107
|
* @throws if the signature is not a valid function signature or a parameter is unnamed
|
|
110
108
|
*/
|
|
111
|
-
declare const parseFunctionParams: (functionSignature: string) => string[];
|
|
109
|
+
export declare const parseFunctionParams: (functionSignature: string) => string[];
|
|
112
110
|
/**
|
|
113
111
|
* Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).
|
|
114
112
|
* Handles carry a `_tag` property and are converted via `handleToRef`;
|
|
115
113
|
* `Ref` objects pass through as-is.
|
|
116
114
|
*/
|
|
117
|
-
declare const toBindRef: (bindable: AnyRefBindable) => Ref;
|
|
118
|
-
interface BuildCallWireFormatInput {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
export declare const toBindRef: (bindable: AnyRefBindable) => Ref;
|
|
116
|
+
export interface BuildCallWireFormatInput {
|
|
117
|
+
readonly resource?: AnyRefBindable;
|
|
118
|
+
readonly bind: Record<string, AnyRefBindable>;
|
|
119
|
+
readonly config: Record<string, unknown>;
|
|
120
|
+
readonly guards?: readonly TypedGuard[];
|
|
123
121
|
}
|
|
124
|
-
interface CallWireResult {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
export interface CallWireResult {
|
|
123
|
+
readonly op: "core.call" | "core.invoke";
|
|
124
|
+
readonly bind: Record<string, Ref>;
|
|
125
|
+
readonly config: Record<string, unknown>;
|
|
126
|
+
readonly guards?: readonly TypedGuard[];
|
|
129
127
|
}
|
|
130
128
|
/**
|
|
131
129
|
* Transforms the user-facing `resource` + named `bind` API into the wire
|
|
@@ -134,17 +132,18 @@ interface CallWireResult {
|
|
|
134
132
|
* - Without resource: `core.invoke` with `bind: {}`
|
|
135
133
|
* - `config: { ...userConfig, args: [positional refs...] }`
|
|
136
134
|
*/
|
|
137
|
-
declare const buildCallWireFormat: (args: BuildCallWireFormatInput) => CallWireResult;
|
|
138
|
-
interface BuildStaticCallWireFormatInput {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
export declare const buildCallWireFormat: (args: BuildCallWireFormatInput) => CallWireResult;
|
|
136
|
+
export interface BuildStaticCallWireFormatInput {
|
|
137
|
+
readonly bind: Record<string, AnyRefBindable>;
|
|
138
|
+
readonly config: Record<string, unknown>;
|
|
139
|
+
readonly guards?: readonly TypedGuard[];
|
|
142
140
|
}
|
|
143
141
|
/**
|
|
144
142
|
* Transforms the user-facing named `bind` API into the wire format that the
|
|
145
143
|
* backend expects for `core.staticCall`. Same as `buildCallWireFormat` but
|
|
146
144
|
* with no `resource` field — staticCall has no resource inputs.
|
|
147
145
|
*/
|
|
148
|
-
declare const buildStaticCallWireFormat: (args: BuildStaticCallWireFormatInput) => CallArgs;
|
|
149
|
-
|
|
150
|
-
export {
|
|
146
|
+
export declare const buildStaticCallWireFormat: (args: BuildStaticCallWireFormatInput) => CallArgs;
|
|
147
|
+
//#endregion
|
|
148
|
+
export {};
|
|
149
|
+
//# sourceMappingURL=signatureArgs.d.ts.map
|
|
@@ -1,87 +1,88 @@
|
|
|
1
|
-
import { parseAbiItem } from "abitype";
|
|
2
1
|
import { handleToRef } from "./handles.js";
|
|
2
|
+
import { parseAbiItem } from "abitype";
|
|
3
|
+
//#region src/authoring/signatureArgs.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parses a Solidity function signature and returns parameter names in order.
|
|
6
|
+
* Delegates to abitype's runtime `parseAbiItem` — the same parser that powers
|
|
7
|
+
* the compile-time `ParseAbiItem<TSig>` type — so runtime and type-level
|
|
8
|
+
* parsing can never diverge.
|
|
9
|
+
*
|
|
10
|
+
* @throws if the signature is not a valid function signature or a parameter is unnamed
|
|
11
|
+
*/
|
|
3
12
|
const parseFunctionParams = (functionSignature) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return parsed.inputs.map((input, index) => {
|
|
11
|
-
if (!input.name) {
|
|
12
|
-
throw new Error(
|
|
13
|
-
`core.call: parameter at index ${index} in signature has no name. All parameters must be named for named binds to work.`
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
return input.name;
|
|
17
|
-
});
|
|
13
|
+
const parsed = parseAbiItem(functionSignature);
|
|
14
|
+
if (parsed.type !== "function") throw new Error(`core.call: expected a function signature, got "${parsed.type}": "${functionSignature}"`);
|
|
15
|
+
return parsed.inputs.map((input, index) => {
|
|
16
|
+
if (!input.name) throw new Error(`core.call: parameter at index ${index} in signature has no name. All parameters must be named for named binds to work.`);
|
|
17
|
+
return input.name;
|
|
18
|
+
});
|
|
18
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).
|
|
22
|
+
* Handles carry a `_tag` property and are converted via `handleToRef`;
|
|
23
|
+
* `Ref` objects pass through as-is.
|
|
24
|
+
*/
|
|
19
25
|
const toBindRef = (bindable) => {
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
if ("_tag" in bindable) return handleToRef(bindable);
|
|
27
|
+
return bindable;
|
|
22
28
|
};
|
|
29
|
+
/**
|
|
30
|
+
* Parses a function signature from `config`, validates bind keys against it,
|
|
31
|
+
* and converts named binds to positional `$ref` args.
|
|
32
|
+
*/
|
|
23
33
|
const resolvePositionalArgs = (label, bind, config) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`${label}: bind keys [${bindKeys.join(
|
|
39
|
-
", "
|
|
40
|
-
)}] do not match signature parameters [${paramNames.join(
|
|
41
|
-
", "
|
|
42
|
-
)}]. Missing: ${missing.join(", ") || "(none)"}. Extra: ${extra.join(", ") || "(none)"}.`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
return paramNames.map((name) => {
|
|
46
|
-
const bindable = bind[name];
|
|
47
|
-
if (bindable === void 0) {
|
|
48
|
-
throw new Error(
|
|
49
|
-
`${label}: bind value for parameter "${name}" is undefined`
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
return toBindRef(bindable);
|
|
53
|
-
});
|
|
34
|
+
const functionSignature = config.functionSignature;
|
|
35
|
+
if (typeof functionSignature !== "string") throw new Error(`${label}: config.functionSignature is required and must be a string`);
|
|
36
|
+
const paramNames = parseFunctionParams(functionSignature);
|
|
37
|
+
const paramSet = new Set(paramNames);
|
|
38
|
+
const bindKeys = Object.keys(bind);
|
|
39
|
+
const bindSet = new Set(bindKeys);
|
|
40
|
+
const missing = paramNames.filter((n) => !bindSet.has(n));
|
|
41
|
+
const extra = bindKeys.filter((k) => !paramSet.has(k));
|
|
42
|
+
if (missing.length > 0 || extra.length > 0) throw new Error(`${label}: bind keys [${bindKeys.join(", ")}] do not match signature parameters [${paramNames.join(", ")}]. Missing: ${missing.join(", ") || "(none)"}. Extra: ${extra.join(", ") || "(none)"}.`);
|
|
43
|
+
return paramNames.map((name) => {
|
|
44
|
+
const bindable = bind[name];
|
|
45
|
+
if (bindable === void 0) throw new Error(`${label}: bind value for parameter "${name}" is undefined`);
|
|
46
|
+
return toBindRef(bindable);
|
|
47
|
+
});
|
|
54
48
|
};
|
|
49
|
+
/**
|
|
50
|
+
* Transforms the user-facing `resource` + named `bind` API into the wire
|
|
51
|
+
* format that the backend expects:
|
|
52
|
+
* - With resource: `core.call` with `bind: { input: <resourceRef> }`
|
|
53
|
+
* - Without resource: `core.invoke` with `bind: {}`
|
|
54
|
+
* - `config: { ...userConfig, args: [positional refs...] }`
|
|
55
|
+
*/
|
|
55
56
|
const buildCallWireFormat = (args) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
57
|
+
const positionalArgs = resolvePositionalArgs("core.call", args.bind, args.config);
|
|
58
|
+
const hasResource = args.resource !== void 0;
|
|
59
|
+
return {
|
|
60
|
+
op: hasResource ? "core.call" : "core.invoke",
|
|
61
|
+
bind: hasResource ? { input: toBindRef(args.resource) } : {},
|
|
62
|
+
config: {
|
|
63
|
+
...args.config,
|
|
64
|
+
args: positionalArgs
|
|
65
|
+
},
|
|
66
|
+
...args.guards && args.guards.length > 0 && { guards: args.guards }
|
|
67
|
+
};
|
|
68
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Transforms the user-facing named `bind` API into the wire format that the
|
|
71
|
+
* backend expects for `core.staticCall`. Same as `buildCallWireFormat` but
|
|
72
|
+
* with no `resource` field — staticCall has no resource inputs.
|
|
73
|
+
*/
|
|
69
74
|
const buildStaticCallWireFormat = (args) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
export {
|
|
82
|
-
buildCallWireFormat,
|
|
83
|
-
buildStaticCallWireFormat,
|
|
84
|
-
parseFunctionParams,
|
|
85
|
-
toBindRef
|
|
75
|
+
const positionalArgs = resolvePositionalArgs("core.staticCall", args.bind, args.config);
|
|
76
|
+
return {
|
|
77
|
+
bind: {},
|
|
78
|
+
config: {
|
|
79
|
+
...args.config,
|
|
80
|
+
args: positionalArgs
|
|
81
|
+
},
|
|
82
|
+
...args.guards && args.guards.length > 0 && { guards: args.guards }
|
|
83
|
+
};
|
|
86
84
|
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { buildCallWireFormat, buildStaticCallWireFormat, parseFunctionParams, toBindRef };
|
|
87
|
+
|
|
87
88
|
//# sourceMappingURL=signatureArgs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/authoring/signatureArgs.ts"],"sourcesContent":["import type { Ref } from '@lifi/compose-spec';\nimport { type ParseAbiItem, parseAbiItem } from 'abitype';\n\nimport type { AbiTypeToOutputKind, TypedGuard } from '../types.js';\n\nimport type { CallArgs } from './FlowBuilderCore.js';\nimport type { AnyRefBindable, OutputHandle, RefBindable } from './handles.js';\nimport { handleToRef } from './handles.js';\n\n/**\n * Type-level extraction of named bind keys from a function signature string.\n * When `TSig` is a string literal matching a Solidity function signature,\n * resolves to a record whose keys are the parameter names and values are\n * `RefBindable<kind>` where the kind is derived from each parameter's Solidity\n * type via `AbiTypeToOutputKind`. For recognised `SolType` parameters\n * (e.g. `uint256`, `address`, `uint128`) the bind slot is precisely typed;\n * for other Solidity types (e.g. tuples) the slot accepts any scalar handle.\n * Falls back to `Record<string, AnyRefBindable>` for non-literal strings.\n *\n * These slots are lowered into `config.args`, which is positional calldata\n * rather than a node `bind` record, so a literal is not accepted here: only\n * values that resolve to a `$ref`.\n */\nexport type SignatureBind<TSig extends string> = string extends TSig\n ? Record<string, AnyRefBindable>\n : ParseAbiItem<TSig> extends {\n type: 'function';\n inputs: infer I extends readonly { name: string; type: string }[];\n }\n ? {\n readonly [P in I[number] as P['name']]: RefBindable<\n AbiTypeToOutputKind<P['type']>\n >;\n }\n : Record<string, AnyRefBindable>;\n\n// ---------------------------------------------------------------------------\n// Return-type inference from function signatures\n// ---------------------------------------------------------------------------\n\n/**\n * Describes the output type(s) of a parsed function signature as a\n * human-readable string for inclusion in type-level error messages.\n */\ntype DescribeOutputs<O extends readonly { type: string }[]> =\n O extends readonly [{ type: infer T extends string }] ? T : 'multiple values';\n\n/**\n * A string-literal type that surfaces a clear error when the user provides a\n * function signature whose return type is not supported by core.call.\n * The message is visible in IDE tooltips and compiler diagnostics.\n */\ntype UnsupportedReturnTypeError<TLabel extends string, TSig extends string> =\n ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: infer O extends readonly { type: string }[];\n }\n ? `[TypeError] ${TLabel}: return type '${DescribeOutputs<O>}' is not supported — only 'uint256' or void signatures are allowed`\n : `[TypeError] ${TLabel}: unable to parse return type from signature`;\n\n/**\n * Conditional output type for `core.call` based on the function signature's\n * return type:\n *\n * - `returns (uint256)` → `{ result: OutputHandle }`\n * - No returns clause → `{ result: undefined }`\n * - Anything else → `{ result: \"[TypeError] ...\" }` (compile-time error)\n *\n * When `TSig` is a non-literal `string` (e.g. a variable, not a string\n * constant), the type falls back to `{ result: OutputHandle | undefined }`\n * so that both void and uint256 call sites remain assignable.\n */\nexport type CoreCallResult<TSig extends string> = string extends TSig\n ? { readonly result: OutputHandle<'uint256'> | undefined }\n : ParseAbiItem<TSig> extends { type: 'function'; outputs: readonly [] }\n ? { readonly result: undefined }\n : ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: readonly [{ type: 'uint256' }];\n }\n ? { readonly result: OutputHandle<'uint256'> }\n : { readonly result: UnsupportedReturnTypeError<'core.call', TSig> };\n\n/**\n * Conditional output type for `core.staticCall`. staticCall always reads a\n * value, so void signatures are also rejected:\n *\n * - `returns (uint256)` → `{ result: OutputHandle }`\n * - No returns / other → `{ result: \"[TypeError] ...\" }` (compile-time error)\n */\nexport type StaticCallResult<TSig extends string> = string extends TSig\n ? { readonly result: OutputHandle<'uint256'> }\n : ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: readonly [{ type: 'uint256' }];\n }\n ? { readonly result: OutputHandle<'uint256'> }\n : ParseAbiItem<TSig> extends { type: 'function'; outputs: readonly [] }\n ? {\n readonly result: `[TypeError] core.staticCall: function has no return value — staticCall requires a 'returns (uint256)' signature`;\n }\n : {\n readonly result: UnsupportedReturnTypeError<'core.staticCall', TSig>;\n };\n\n/**\n * Parses a Solidity function signature and returns parameter names in order.\n * Delegates to abitype's runtime `parseAbiItem` — the same parser that powers\n * the compile-time `ParseAbiItem<TSig>` type — so runtime and type-level\n * parsing can never diverge.\n *\n * @throws if the signature is not a valid function signature or a parameter is unnamed\n */\nexport const parseFunctionParams = (functionSignature: string): string[] => {\n const parsed = parseAbiItem(functionSignature);\n if (parsed.type !== 'function') {\n throw new Error(\n `core.call: expected a function signature, got \"${parsed.type}\": \"${functionSignature}\"`,\n );\n }\n\n return parsed.inputs.map((input, index) => {\n if (!input.name) {\n throw new Error(\n `core.call: parameter at index ${index} in signature has no name. All parameters must be named for named binds to work.`,\n );\n }\n return input.name;\n });\n};\n\n/**\n * Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).\n * Handles carry a `_tag` property and are converted via `handleToRef`;\n * `Ref` objects pass through as-is.\n */\nexport const toBindRef = (bindable: AnyRefBindable): Ref => {\n if ('_tag' in bindable) return handleToRef(bindable);\n return bindable;\n};\n\nexport interface BuildCallWireFormatInput {\n readonly resource?: AnyRefBindable;\n readonly bind: Record<string, AnyRefBindable>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\nexport interface CallWireResult {\n readonly op: 'core.call' | 'core.invoke';\n readonly bind: Record<string, Ref>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\n/**\n * Parses a function signature from `config`, validates bind keys against it,\n * and converts named binds to positional `$ref` args.\n */\nconst resolvePositionalArgs = (\n label: string,\n bind: Record<string, AnyRefBindable>,\n config: Record<string, unknown>,\n): Ref[] => {\n const functionSignature = config.functionSignature;\n if (typeof functionSignature !== 'string') {\n throw new Error(\n `${label}: config.functionSignature is required and must be a string`,\n );\n }\n\n const paramNames = parseFunctionParams(functionSignature);\n const paramSet = new Set(paramNames);\n const bindKeys = Object.keys(bind);\n const bindSet = new Set(bindKeys);\n\n const missing = paramNames.filter((n) => !bindSet.has(n));\n const extra = bindKeys.filter((k) => !paramSet.has(k));\n\n if (missing.length > 0 || extra.length > 0) {\n throw new Error(\n `${label}: bind keys [${bindKeys.join(\n ', ',\n )}] do not match signature parameters [${paramNames.join(\n ', ',\n )}]. Missing: ${missing.join(', ') || '(none)'}. Extra: ${\n extra.join(', ') || '(none)'\n }.`,\n );\n }\n\n return paramNames.map((name) => {\n const bindable = bind[name];\n if (bindable === undefined) {\n throw new Error(\n `${label}: bind value for parameter \"${name}\" is undefined`,\n );\n }\n return toBindRef(bindable);\n });\n};\n\n/**\n * Transforms the user-facing `resource` + named `bind` API into the wire\n * format that the backend expects:\n * - With resource: `core.call` with `bind: { input: <resourceRef> }`\n * - Without resource: `core.invoke` with `bind: {}`\n * - `config: { ...userConfig, args: [positional refs...] }`\n */\nexport const buildCallWireFormat = (\n args: BuildCallWireFormatInput,\n): CallWireResult => {\n const positionalArgs = resolvePositionalArgs(\n 'core.call',\n args.bind,\n args.config,\n );\n const hasResource = args.resource !== undefined;\n\n return {\n op: hasResource ? 'core.call' : 'core.invoke',\n bind: hasResource ? { input: toBindRef(args.resource) } : {},\n config: { ...args.config, args: positionalArgs },\n ...(args.guards && args.guards.length > 0 && { guards: args.guards }),\n };\n};\n\nexport interface BuildStaticCallWireFormatInput {\n readonly bind: Record<string, AnyRefBindable>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\n/**\n * Transforms the user-facing named `bind` API into the wire format that the\n * backend expects for `core.staticCall`. Same as `buildCallWireFormat` but\n * with no `resource` field — staticCall has no resource inputs.\n */\nexport const buildStaticCallWireFormat = (\n args: BuildStaticCallWireFormatInput,\n): CallArgs => {\n const positionalArgs = resolvePositionalArgs(\n 'core.staticCall',\n args.bind,\n args.config,\n );\n\n return {\n bind: {},\n config: { ...args.config, args: positionalArgs },\n ...(args.guards && args.guards.length > 0 && { guards: args.guards }),\n };\n};\n"],"mappings":"AACA,SAA4B,oBAAoB;AAMhD,SAAS,mBAAmB;AA0GrB,MAAM,sBAAsB,CAAC,sBAAwC;AAC1E,QAAM,SAAS,aAAa,iBAAiB;AAC7C,MAAI,OAAO,SAAS,YAAY;AAC9B,UAAM,IAAI;AAAA,MACR,kDAAkD,OAAO,IAAI,OAAO,iBAAiB;AAAA,IACvF;AAAA,EACF;AAEA,SAAO,OAAO,OAAO,IAAI,CAAC,OAAO,UAAU;AACzC,QAAI,CAAC,MAAM,MAAM;AACf,YAAM,IAAI;AAAA,QACR,iCAAiC,KAAK;AAAA,MACxC;AAAA,IACF;AACA,WAAO,MAAM;AAAA,EACf,CAAC;AACH;AAOO,MAAM,YAAY,CAAC,aAAkC;AAC1D,MAAI,UAAU,SAAU,QAAO,YAAY,QAAQ;AACnD,SAAO;AACT;AAoBA,MAAM,wBAAwB,CAC5B,OACA,MACA,WACU;AACV,QAAM,oBAAoB,OAAO;AACjC,MAAI,OAAO,sBAAsB,UAAU;AACzC,UAAM,IAAI;AAAA,MACR,GAAG,KAAK;AAAA,IACV;AAAA,EACF;AAEA,QAAM,aAAa,oBAAoB,iBAAiB;AACxD,QAAM,WAAW,IAAI,IAAI,UAAU;AACnC,QAAM,WAAW,OAAO,KAAK,IAAI;AACjC,QAAM,UAAU,IAAI,IAAI,QAAQ;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QAAQ,MAAM,eAAe;AAAA,IAC/C,GAAI,KAAK,UAAU,KAAK,OAAO,SAAS,KAAK,EAAE,QAAQ,KAAK,OAAO;AAAA,EACrE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"file":"signatureArgs.js","names":[],"sources":["../../src/authoring/signatureArgs.ts"],"sourcesContent":["import type { Ref } from '@lifi/compose-spec';\nimport { type ParseAbiItem, parseAbiItem } from 'abitype';\n\nimport type { AbiTypeToOutputKind, TypedGuard } from '../types.js';\n\nimport type { CallArgs } from './FlowBuilderCore.js';\nimport type { AnyRefBindable, OutputHandle, RefBindable } from './handles.js';\nimport { handleToRef } from './handles.js';\n\n/**\n * Type-level extraction of named bind keys from a function signature string.\n * When `TSig` is a string literal matching a Solidity function signature,\n * resolves to a record whose keys are the parameter names and values are\n * `RefBindable<kind>` where the kind is derived from each parameter's Solidity\n * type via `AbiTypeToOutputKind`. For recognised `SolType` parameters\n * (e.g. `uint256`, `address`, `uint128`) the bind slot is precisely typed;\n * for other Solidity types (e.g. tuples) the slot accepts any scalar handle.\n * Falls back to `Record<string, AnyRefBindable>` for non-literal strings.\n *\n * These slots are lowered into `config.args`, which is positional calldata\n * rather than a node `bind` record, so a literal is not accepted here: only\n * values that resolve to a `$ref`.\n */\nexport type SignatureBind<TSig extends string> = string extends TSig\n ? Record<string, AnyRefBindable>\n : ParseAbiItem<TSig> extends {\n type: 'function';\n inputs: infer I extends readonly { name: string; type: string }[];\n }\n ? {\n readonly [P in I[number] as P['name']]: RefBindable<\n AbiTypeToOutputKind<P['type']>\n >;\n }\n : Record<string, AnyRefBindable>;\n\n// ---------------------------------------------------------------------------\n// Return-type inference from function signatures\n// ---------------------------------------------------------------------------\n\n/**\n * Describes the output type(s) of a parsed function signature as a\n * human-readable string for inclusion in type-level error messages.\n */\ntype DescribeOutputs<O extends readonly { type: string }[]> =\n O extends readonly [{ type: infer T extends string }] ? T : 'multiple values';\n\n/**\n * A string-literal type that surfaces a clear error when the user provides a\n * function signature whose return type is not supported by core.call.\n * The message is visible in IDE tooltips and compiler diagnostics.\n */\ntype UnsupportedReturnTypeError<TLabel extends string, TSig extends string> =\n ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: infer O extends readonly { type: string }[];\n }\n ? `[TypeError] ${TLabel}: return type '${DescribeOutputs<O>}' is not supported — only 'uint256' or void signatures are allowed`\n : `[TypeError] ${TLabel}: unable to parse return type from signature`;\n\n/**\n * Conditional output type for `core.call` based on the function signature's\n * return type:\n *\n * - `returns (uint256)` → `{ result: OutputHandle }`\n * - No returns clause → `{ result: undefined }`\n * - Anything else → `{ result: \"[TypeError] ...\" }` (compile-time error)\n *\n * When `TSig` is a non-literal `string` (e.g. a variable, not a string\n * constant), the type falls back to `{ result: OutputHandle | undefined }`\n * so that both void and uint256 call sites remain assignable.\n */\nexport type CoreCallResult<TSig extends string> = string extends TSig\n ? { readonly result: OutputHandle<'uint256'> | undefined }\n : ParseAbiItem<TSig> extends { type: 'function'; outputs: readonly [] }\n ? { readonly result: undefined }\n : ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: readonly [{ type: 'uint256' }];\n }\n ? { readonly result: OutputHandle<'uint256'> }\n : { readonly result: UnsupportedReturnTypeError<'core.call', TSig> };\n\n/**\n * Conditional output type for `core.staticCall`. staticCall always reads a\n * value, so void signatures are also rejected:\n *\n * - `returns (uint256)` → `{ result: OutputHandle }`\n * - No returns / other → `{ result: \"[TypeError] ...\" }` (compile-time error)\n */\nexport type StaticCallResult<TSig extends string> = string extends TSig\n ? { readonly result: OutputHandle<'uint256'> }\n : ParseAbiItem<TSig> extends {\n type: 'function';\n outputs: readonly [{ type: 'uint256' }];\n }\n ? { readonly result: OutputHandle<'uint256'> }\n : ParseAbiItem<TSig> extends { type: 'function'; outputs: readonly [] }\n ? {\n readonly result: `[TypeError] core.staticCall: function has no return value — staticCall requires a 'returns (uint256)' signature`;\n }\n : {\n readonly result: UnsupportedReturnTypeError<'core.staticCall', TSig>;\n };\n\n/**\n * Parses a Solidity function signature and returns parameter names in order.\n * Delegates to abitype's runtime `parseAbiItem` — the same parser that powers\n * the compile-time `ParseAbiItem<TSig>` type — so runtime and type-level\n * parsing can never diverge.\n *\n * @throws if the signature is not a valid function signature or a parameter is unnamed\n */\nexport const parseFunctionParams = (functionSignature: string): string[] => {\n const parsed = parseAbiItem(functionSignature);\n if (parsed.type !== 'function') {\n throw new Error(\n `core.call: expected a function signature, got \"${parsed.type}\": \"${functionSignature}\"`,\n );\n }\n\n return parsed.inputs.map((input, index) => {\n if (!input.name) {\n throw new Error(\n `core.call: parameter at index ${index} in signature has no name. All parameters must be named for named binds to work.`,\n );\n }\n return input.name;\n });\n};\n\n/**\n * Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).\n * Handles carry a `_tag` property and are converted via `handleToRef`;\n * `Ref` objects pass through as-is.\n */\nexport const toBindRef = (bindable: AnyRefBindable): Ref => {\n if ('_tag' in bindable) return handleToRef(bindable);\n return bindable;\n};\n\nexport interface BuildCallWireFormatInput {\n readonly resource?: AnyRefBindable;\n readonly bind: Record<string, AnyRefBindable>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\nexport interface CallWireResult {\n readonly op: 'core.call' | 'core.invoke';\n readonly bind: Record<string, Ref>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\n/**\n * Parses a function signature from `config`, validates bind keys against it,\n * and converts named binds to positional `$ref` args.\n */\nconst resolvePositionalArgs = (\n label: string,\n bind: Record<string, AnyRefBindable>,\n config: Record<string, unknown>,\n): Ref[] => {\n const functionSignature = config.functionSignature;\n if (typeof functionSignature !== 'string') {\n throw new Error(\n `${label}: config.functionSignature is required and must be a string`,\n );\n }\n\n const paramNames = parseFunctionParams(functionSignature);\n const paramSet = new Set(paramNames);\n const bindKeys = Object.keys(bind);\n const bindSet = new Set(bindKeys);\n\n const missing = paramNames.filter((n) => !bindSet.has(n));\n const extra = bindKeys.filter((k) => !paramSet.has(k));\n\n if (missing.length > 0 || extra.length > 0) {\n throw new Error(\n `${label}: bind keys [${bindKeys.join(\n ', ',\n )}] do not match signature parameters [${paramNames.join(\n ', ',\n )}]. Missing: ${missing.join(', ') || '(none)'}. Extra: ${\n extra.join(', ') || '(none)'\n }.`,\n );\n }\n\n return paramNames.map((name) => {\n const bindable = bind[name];\n if (bindable === undefined) {\n throw new Error(\n `${label}: bind value for parameter \"${name}\" is undefined`,\n );\n }\n return toBindRef(bindable);\n });\n};\n\n/**\n * Transforms the user-facing `resource` + named `bind` API into the wire\n * format that the backend expects:\n * - With resource: `core.call` with `bind: { input: <resourceRef> }`\n * - Without resource: `core.invoke` with `bind: {}`\n * - `config: { ...userConfig, args: [positional refs...] }`\n */\nexport const buildCallWireFormat = (\n args: BuildCallWireFormatInput,\n): CallWireResult => {\n const positionalArgs = resolvePositionalArgs(\n 'core.call',\n args.bind,\n args.config,\n );\n const hasResource = args.resource !== undefined;\n\n return {\n op: hasResource ? 'core.call' : 'core.invoke',\n bind: hasResource ? { input: toBindRef(args.resource) } : {},\n config: { ...args.config, args: positionalArgs },\n ...(args.guards && args.guards.length > 0 && { guards: args.guards }),\n };\n};\n\nexport interface BuildStaticCallWireFormatInput {\n readonly bind: Record<string, AnyRefBindable>;\n readonly config: Record<string, unknown>;\n readonly guards?: readonly TypedGuard[];\n}\n\n/**\n * Transforms the user-facing named `bind` API into the wire format that the\n * backend expects for `core.staticCall`. Same as `buildCallWireFormat` but\n * with no `resource` field — staticCall has no resource inputs.\n */\nexport const buildStaticCallWireFormat = (\n args: BuildStaticCallWireFormatInput,\n): CallArgs => {\n const positionalArgs = resolvePositionalArgs(\n 'core.staticCall',\n args.bind,\n args.config,\n );\n\n return {\n bind: {},\n config: { ...args.config, args: positionalArgs },\n ...(args.guards && args.guards.length > 0 && { guards: args.guards }),\n };\n};\n"],"mappings":";;;;;;;;;;;AAiHA,MAAa,uBAAuB,sBAAwC;CAC1E,MAAM,SAAS,aAAa,iBAAiB;CAC7C,IAAI,OAAO,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