@lifi/composer-sdk 0.7.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 +5 -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 +805 -895
- package/dist/generated/config.generated.d.ts +805 -895
- package/dist/generated/config.generated.js +1 -1
- package/dist/generated/guards.generated.cjs +27 -31
- 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 +21 -8
- 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 -250
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +740 -657
- package/dist/generated/operations.generated.d.ts +740 -657
- package/dist/generated/operations.generated.js +235 -229
- 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 +14 -1
- package/src/examples/transferTokens.ts +21 -17
- package/src/examples/uniswapV2AddLiquidity.ts +106 -0
- package/src/examples/uniswapV3Mint.ts +95 -0
- package/src/generated/config.generated.ts +102 -47
- package/src/generated/guards.generated.ts +9 -0
- package/src/generated/operations.generated.ts +161 -5
- package/src/index.ts +0 -3
- 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-BPLFwe7y.d.ts +0 -19
- package/dist/guards.generated-M3VAIevI.d.cts +0 -19
- 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
package/dist/authoring/raw.js
CHANGED
|
@@ -1,22 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/authoring/raw.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates a typed `$ref` pointer for use in bind slots.
|
|
4
|
+
*
|
|
5
|
+
* This is an **escape hatch** for referencing values that the typed builder
|
|
6
|
+
* API doesn't cover — for example, outputs of an `untypedOp` node or custom
|
|
7
|
+
* context paths. The caller is responsible for choosing the correct type
|
|
8
|
+
* parameter; no runtime validation occurs.
|
|
9
|
+
*
|
|
10
|
+
* Prefer typed handles (`OutputHandle`, `InputHandle`) and `builder.context`
|
|
11
|
+
* whenever possible. Use `ref` only when you need to construct a `$ref` path
|
|
12
|
+
* manually and want it accepted by a `Bindable<T>` slot.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam T - The output kind this ref represents (e.g. `'address'`, `'uint256'`, `'resource'`).
|
|
15
|
+
* @param path - The `$ref` path (e.g. `"context.sender"`, `"myNode.result"`).
|
|
16
|
+
* @returns A {@link TypedRef} accepted by `Bindable<T>` slots matching `T`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { raw } from '@lifi/composer-sdk';
|
|
21
|
+
*
|
|
22
|
+
* // Reference an untypedOp output in a typed operation:
|
|
23
|
+
* builder.untypedOp('custom', 'some.op', {
|
|
24
|
+
* bind: { x: { $ref: 'input.token' } },
|
|
25
|
+
* config: {},
|
|
26
|
+
* });
|
|
27
|
+
* builder.core.add('sum', {
|
|
28
|
+
* bind: {
|
|
29
|
+
* a: raw.ref<'uint256'>('custom.result'),
|
|
30
|
+
* b: someTypedHandle,
|
|
31
|
+
* },
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
const ref = (path) => ({ $ref: path });
|
|
36
|
+
/**
|
|
37
|
+
* Creates a typed literal for use in bind slots: a constant baked into the
|
|
38
|
+
* flow document rather than supplied at run time.
|
|
39
|
+
*
|
|
40
|
+
* Prefer a declared flow input and `builder.inputs.<name>` — a value the
|
|
41
|
+
* caller supplies per run stays out of the document. Use a literal when the
|
|
42
|
+
* flow has no run of its own to take the value from: the `continuationFlow`
|
|
43
|
+
* of a `continuation.settle` node is stored by the settlement backend and
|
|
44
|
+
* re-run later against the deferred proceeds, so its delivery address has to
|
|
45
|
+
* be part of the committed document.
|
|
46
|
+
*
|
|
47
|
+
* @typeParam T - The Solidity type of the literal (e.g. `'address'`).
|
|
48
|
+
* @param kind - The literal's Solidity type.
|
|
49
|
+
* @param value - The literal value, as the wire format carries it: a string.
|
|
50
|
+
* @returns A {@link TypedLiteral} accepted by `Bindable<T>` slots matching `T`.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { raw } from '@lifi/composer-sdk';
|
|
55
|
+
*
|
|
56
|
+
* builder.core.transfer('deliver', {
|
|
57
|
+
* bind: {
|
|
58
|
+
* amount: zap.amountOut,
|
|
59
|
+
* recipient: raw.literal('address', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),
|
|
60
|
+
* },
|
|
61
|
+
* config: {},
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
const literal = (kind, value) => ({
|
|
66
|
+
kind,
|
|
67
|
+
value
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Creates a raw guard object for use in the `guards` array of an operation call.
|
|
71
|
+
*
|
|
72
|
+
* @param kind - The guard type (e.g. `"slippage"`).
|
|
73
|
+
* @param config - Guard-specific configuration (e.g. `{ toleranceBps: 300 }`).
|
|
74
|
+
* @returns An {@link AppliedGuard} object.
|
|
75
|
+
*/
|
|
7
76
|
const rawGuard = (kind, config = {}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
return { ...config, kind };
|
|
16
|
-
};
|
|
17
|
-
export {
|
|
18
|
-
literal,
|
|
19
|
-
rawGuard,
|
|
20
|
-
ref
|
|
77
|
+
if ("kind" in config) throw new Error(`rawGuard: 'kind' must not appear in config (got "${String(config.kind)}"). Pass it as the first argument instead.`);
|
|
78
|
+
return {
|
|
79
|
+
...config,
|
|
80
|
+
kind
|
|
81
|
+
};
|
|
21
82
|
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { literal, rawGuard, ref };
|
|
85
|
+
|
|
22
86
|
//# sourceMappingURL=raw.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/authoring/raw.ts"],"sourcesContent":["import type { AppliedGuard, SolType } from '@lifi/compose-spec';\n\nimport type { OutputKind, TypedLiteral, TypedRef } from '../types.js';\n\n/**\n * Creates a typed `$ref` pointer for use in bind slots.\n *\n * This is an **escape hatch** for referencing values that the typed builder\n * API doesn't cover — for example, outputs of an `untypedOp` node or custom\n * context paths. The caller is responsible for choosing the correct type\n * parameter; no runtime validation occurs.\n *\n * Prefer typed handles (`OutputHandle`, `InputHandle`) and `builder.context`\n * whenever possible. Use `ref` only when you need to construct a `$ref` path\n * manually and want it accepted by a `Bindable<T>` slot.\n *\n * @typeParam T - The output kind this ref represents (e.g. `'address'`, `'uint256'`, `'resource'`).\n * @param path - The `$ref` path (e.g. `\"context.sender\"`, `\"myNode.result\"`).\n * @returns A {@link TypedRef} accepted by `Bindable<T>` slots matching `T`.\n *\n * @example\n * ```ts\n * import { raw } from '@lifi/composer-sdk';\n *\n * // Reference an untypedOp output in a typed operation:\n * builder.untypedOp('custom', 'some.op', {\n * bind: { x: { $ref: 'input.token' } },\n * config: {},\n * });\n * builder.core.add('sum', {\n * bind: {\n * a: raw.ref<'uint256'>('custom.result'),\n * b: someTypedHandle,\n * },\n * });\n * ```\n */\nexport const ref = <T extends OutputKind>(path: string): TypedRef<T> =>\n // The brand is phantom, so the runtime value is the bare wire ref. This is\n // the only place a `TypedRef` is minted; the cast is what the brand buys.\n ({ $ref: path }) as TypedRef<T>;\n\n/**\n * Creates a typed literal for use in bind slots: a constant baked into the\n * flow document rather than supplied at run time.\n *\n * Prefer a declared flow input and `builder.inputs.<name>` — a value the\n * caller supplies per run stays out of the document. Use a literal when the\n * flow has no run of its own to take the value from: the `continuationFlow`\n * of a `continuation.settle` node is stored by the settlement backend and\n * re-run later against the deferred proceeds, so its delivery address has to\n * be part of the committed document.\n *\n * @typeParam T - The Solidity type of the literal (e.g. `'address'`).\n * @param kind - The literal's Solidity type.\n * @param value - The literal value, as the wire format carries it: a string.\n * @returns A {@link TypedLiteral} accepted by `Bindable<T>` slots matching `T`.\n *\n * @example\n * ```ts\n * import { raw } from '@lifi/composer-sdk';\n *\n * builder.core.transfer('deliver', {\n * bind: {\n * amount: zap.amountOut,\n * recipient: raw.literal('address', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),\n * },\n * config: {},\n * });\n * ```\n */\nexport const literal = <T extends SolType>(\n kind: T,\n value: string,\n): TypedLiteral<T> => ({ kind, value });\n\n/**\n * Creates a raw guard object for use in the `guards` array of an operation call.\n *\n * @param kind - The guard type (e.g. `\"slippage\"`).\n * @param config - Guard-specific configuration (e.g. `{ toleranceBps: 300 }`).\n * @returns An {@link AppliedGuard} object.\n */\nexport const rawGuard = (\n kind: string,\n config: Record<string, unknown> = {},\n): AppliedGuard => {\n if ('kind' in config) {\n throw new Error(\n `rawGuard: 'kind' must not appear in config (got \"${String(\n config.kind,\n )}\"). Pass it as the first argument instead.`,\n );\n }\n return { ...config, kind };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"raw.js","names":[],"sources":["../../src/authoring/raw.ts"],"sourcesContent":["import type { AppliedGuard, SolType } from '@lifi/compose-spec';\n\nimport type { OutputKind, TypedLiteral, TypedRef } from '../types.js';\n\n/**\n * Creates a typed `$ref` pointer for use in bind slots.\n *\n * This is an **escape hatch** for referencing values that the typed builder\n * API doesn't cover — for example, outputs of an `untypedOp` node or custom\n * context paths. The caller is responsible for choosing the correct type\n * parameter; no runtime validation occurs.\n *\n * Prefer typed handles (`OutputHandle`, `InputHandle`) and `builder.context`\n * whenever possible. Use `ref` only when you need to construct a `$ref` path\n * manually and want it accepted by a `Bindable<T>` slot.\n *\n * @typeParam T - The output kind this ref represents (e.g. `'address'`, `'uint256'`, `'resource'`).\n * @param path - The `$ref` path (e.g. `\"context.sender\"`, `\"myNode.result\"`).\n * @returns A {@link TypedRef} accepted by `Bindable<T>` slots matching `T`.\n *\n * @example\n * ```ts\n * import { raw } from '@lifi/composer-sdk';\n *\n * // Reference an untypedOp output in a typed operation:\n * builder.untypedOp('custom', 'some.op', {\n * bind: { x: { $ref: 'input.token' } },\n * config: {},\n * });\n * builder.core.add('sum', {\n * bind: {\n * a: raw.ref<'uint256'>('custom.result'),\n * b: someTypedHandle,\n * },\n * });\n * ```\n */\nexport const ref = <T extends OutputKind>(path: string): TypedRef<T> =>\n // The brand is phantom, so the runtime value is the bare wire ref. This is\n // the only place a `TypedRef` is minted; the cast is what the brand buys.\n ({ $ref: path }) as TypedRef<T>;\n\n/**\n * Creates a typed literal for use in bind slots: a constant baked into the\n * flow document rather than supplied at run time.\n *\n * Prefer a declared flow input and `builder.inputs.<name>` — a value the\n * caller supplies per run stays out of the document. Use a literal when the\n * flow has no run of its own to take the value from: the `continuationFlow`\n * of a `continuation.settle` node is stored by the settlement backend and\n * re-run later against the deferred proceeds, so its delivery address has to\n * be part of the committed document.\n *\n * @typeParam T - The Solidity type of the literal (e.g. `'address'`).\n * @param kind - The literal's Solidity type.\n * @param value - The literal value, as the wire format carries it: a string.\n * @returns A {@link TypedLiteral} accepted by `Bindable<T>` slots matching `T`.\n *\n * @example\n * ```ts\n * import { raw } from '@lifi/composer-sdk';\n *\n * builder.core.transfer('deliver', {\n * bind: {\n * amount: zap.amountOut,\n * recipient: raw.literal('address', '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'),\n * },\n * config: {},\n * });\n * ```\n */\nexport const literal = <T extends SolType>(\n kind: T,\n value: string,\n): TypedLiteral<T> => ({ kind, value });\n\n/**\n * Creates a raw guard object for use in the `guards` array of an operation call.\n *\n * @param kind - The guard type (e.g. `\"slippage\"`).\n * @param config - Guard-specific configuration (e.g. `{ toleranceBps: 300 }`).\n * @returns An {@link AppliedGuard} object.\n */\nexport const rawGuard = (\n kind: string,\n config: Record<string, unknown> = {},\n): AppliedGuard => {\n if ('kind' in config) {\n throw new Error(\n `rawGuard: 'kind' must not appear in config (got \"${String(\n config.kind,\n )}\"). Pass it as the first argument instead.`,\n );\n }\n return { ...config, kind };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,MAAa,OAA6B,UAGvC,EAAE,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BhB,MAAa,WACX,MACA,WACqB;CAAE;CAAM;AAAM;;;;;;;;AASrC,MAAa,YACX,MACA,SAAkC,CAAC,MAClB;CACjB,IAAI,UAAU,QACZ,MAAM,IAAI,MACR,oDAAoD,OAClD,OAAO,IACT,EAAE,2CACJ;CAEF,OAAO;EAAE,GAAG;EAAQ;CAAK;AAC3B"}
|
|
@@ -1,114 +1,92 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var signatureArgs_exports = {};
|
|
20
|
-
__export(signatureArgs_exports, {
|
|
21
|
-
buildCallWireFormat: () => buildCallWireFormat,
|
|
22
|
-
buildStaticCallWireFormat: () => buildStaticCallWireFormat,
|
|
23
|
-
parseFunctionParams: () => parseFunctionParams,
|
|
24
|
-
toBindRef: () => toBindRef
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(signatureArgs_exports);
|
|
27
|
-
var import_abitype = require("abitype");
|
|
28
|
-
var import_handles = require("./handles.js");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_authoring_handles = require("./handles.cjs");
|
|
3
|
+
let abitype = require("abitype");
|
|
4
|
+
//#region src/authoring/signatureArgs.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parses a Solidity function signature and returns parameter names in order.
|
|
7
|
+
* Delegates to abitype's runtime `parseAbiItem` — the same parser that powers
|
|
8
|
+
* the compile-time `ParseAbiItem<TSig>` type — so runtime and type-level
|
|
9
|
+
* parsing can never diverge.
|
|
10
|
+
*
|
|
11
|
+
* @throws if the signature is not a valid function signature or a parameter is unnamed
|
|
12
|
+
*/
|
|
29
13
|
const parseFunctionParams = (functionSignature) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return parsed.inputs.map((input, index) => {
|
|
37
|
-
if (!input.name) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`core.call: parameter at index ${index} in signature has no name. All parameters must be named for named binds to work.`
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
return input.name;
|
|
43
|
-
});
|
|
14
|
+
const parsed = (0, abitype.parseAbiItem)(functionSignature);
|
|
15
|
+
if (parsed.type !== "function") throw new Error(`core.call: expected a function signature, got "${parsed.type}": "${functionSignature}"`);
|
|
16
|
+
return parsed.inputs.map((input, index) => {
|
|
17
|
+
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.`);
|
|
18
|
+
return input.name;
|
|
19
|
+
});
|
|
44
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Converts a ref-resolving bindable to a `Ref` (`{ $ref: string }`).
|
|
23
|
+
* Handles carry a `_tag` property and are converted via `handleToRef`;
|
|
24
|
+
* `Ref` objects pass through as-is.
|
|
25
|
+
*/
|
|
45
26
|
const toBindRef = (bindable) => {
|
|
46
|
-
|
|
47
|
-
|
|
27
|
+
if ("_tag" in bindable) return require_authoring_handles.handleToRef(bindable);
|
|
28
|
+
return bindable;
|
|
48
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Parses a function signature from `config`, validates bind keys against it,
|
|
32
|
+
* and converts named binds to positional `$ref` args.
|
|
33
|
+
*/
|
|
49
34
|
const resolvePositionalArgs = (label, bind, config) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
`${label}: bind keys [${bindKeys.join(
|
|
65
|
-
", "
|
|
66
|
-
)}] do not match signature parameters [${paramNames.join(
|
|
67
|
-
", "
|
|
68
|
-
)}]. Missing: ${missing.join(", ") || "(none)"}. Extra: ${extra.join(", ") || "(none)"}.`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
return paramNames.map((name) => {
|
|
72
|
-
const bindable = bind[name];
|
|
73
|
-
if (bindable === void 0) {
|
|
74
|
-
throw new Error(
|
|
75
|
-
`${label}: bind value for parameter "${name}" is undefined`
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
return toBindRef(bindable);
|
|
79
|
-
});
|
|
35
|
+
const functionSignature = config.functionSignature;
|
|
36
|
+
if (typeof functionSignature !== "string") throw new Error(`${label}: config.functionSignature is required and must be a string`);
|
|
37
|
+
const paramNames = parseFunctionParams(functionSignature);
|
|
38
|
+
const paramSet = new Set(paramNames);
|
|
39
|
+
const bindKeys = Object.keys(bind);
|
|
40
|
+
const bindSet = new Set(bindKeys);
|
|
41
|
+
const missing = paramNames.filter((n) => !bindSet.has(n));
|
|
42
|
+
const extra = bindKeys.filter((k) => !paramSet.has(k));
|
|
43
|
+
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)"}.`);
|
|
44
|
+
return paramNames.map((name) => {
|
|
45
|
+
const bindable = bind[name];
|
|
46
|
+
if (bindable === void 0) throw new Error(`${label}: bind value for parameter "${name}" is undefined`);
|
|
47
|
+
return toBindRef(bindable);
|
|
48
|
+
});
|
|
80
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Transforms the user-facing `resource` + named `bind` API into the wire
|
|
52
|
+
* format that the backend expects:
|
|
53
|
+
* - With resource: `core.call` with `bind: { input: <resourceRef> }`
|
|
54
|
+
* - Without resource: `core.invoke` with `bind: {}`
|
|
55
|
+
* - `config: { ...userConfig, args: [positional refs...] }`
|
|
56
|
+
*/
|
|
81
57
|
const buildCallWireFormat = (args) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
58
|
+
const positionalArgs = resolvePositionalArgs("core.call", args.bind, args.config);
|
|
59
|
+
const hasResource = args.resource !== void 0;
|
|
60
|
+
return {
|
|
61
|
+
op: hasResource ? "core.call" : "core.invoke",
|
|
62
|
+
bind: hasResource ? { input: toBindRef(args.resource) } : {},
|
|
63
|
+
config: {
|
|
64
|
+
...args.config,
|
|
65
|
+
args: positionalArgs
|
|
66
|
+
},
|
|
67
|
+
...args.guards && args.guards.length > 0 && { guards: args.guards }
|
|
68
|
+
};
|
|
94
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Transforms the user-facing named `bind` API into the wire format that the
|
|
72
|
+
* backend expects for `core.staticCall`. Same as `buildCallWireFormat` but
|
|
73
|
+
* with no `resource` field — staticCall has no resource inputs.
|
|
74
|
+
*/
|
|
95
75
|
const buildStaticCallWireFormat = (args) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
};
|
|
76
|
+
const positionalArgs = resolvePositionalArgs("core.staticCall", args.bind, args.config);
|
|
77
|
+
return {
|
|
78
|
+
bind: {},
|
|
79
|
+
config: {
|
|
80
|
+
...args.config,
|
|
81
|
+
args: positionalArgs
|
|
82
|
+
},
|
|
83
|
+
...args.guards && args.guards.length > 0 && { guards: args.guards }
|
|
84
|
+
};
|
|
106
85
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.buildCallWireFormat = buildCallWireFormat;
|
|
88
|
+
exports.buildStaticCallWireFormat = buildStaticCallWireFormat;
|
|
89
|
+
exports.parseFunctionParams = parseFunctionParams;
|
|
90
|
+
exports.toBindRef = toBindRef;
|
|
91
|
+
|
|
114
92
|
//# sourceMappingURL=signatureArgs.cjs.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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAgD;AAMhD,qBAA4B;AA0GrB,MAAM,sBAAsB,CAAC,sBAAwC;AAC1E,QAAM,aAAS,6BAAa,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,YAAO,4BAAY,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;AAEhC,QAAM,UAAU,WAAW,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;AACxD,QAAM,QAAQ,SAAS,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;AAErD,MAAI,QAAQ,SAAS,KAAK,MAAM,SAAS,GAAG;AAC1C,UAAM,IAAI;AAAA,MACR,GAAG,KAAK,gBAAgB,SAAS;AAAA,QAC/B;AAAA,MACF,CAAC,wCAAwC,WAAW;AAAA,QAClD;AAAA,MACF,CAAC,eAAe,QAAQ,KAAK,IAAI,KAAK,QAAQ,YAC5C,MAAM,KAAK,IAAI,KAAK,QACtB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,WAAW,IAAI,CAAC,SAAS;AAC9B,UAAM,WAAW,KAAK,IAAI;AAC1B,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI;AAAA,QACR,GAAG,KAAK,+BAA+B,IAAI;AAAA,MAC7C;AAAA,IACF;AACA,WAAO,UAAU,QAAQ;AAAA,EAC3B,CAAC;AACH;AASO,MAAM,sBAAsB,CACjC,SACmB;AACnB,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AACA,QAAM,cAAc,KAAK,aAAa;AAEtC,SAAO;AAAA,IACL,IAAI,cAAc,cAAc;AAAA,IAChC,MAAM,cAAc,EAAE,OAAO,UAAU,KAAK,QAAQ,EAAE,IAAI,CAAC;AAAA,IAC3D,QAAQ,EAAE,GAAG,KAAK,QAAQ,MAAM,eAAe;AAAA,IAC/C,GAAI,KAAK,UAAU,KAAK,OAAO,SAAS,KAAK,EAAE,QAAQ,KAAK,OAAO;AAAA,EACrE;AACF;AAaO,MAAM,4BAA4B,CACvC,SACa;AACb,QAAM,iBAAiB;AAAA,IACrB;AAAA,IACA,KAAK;AAAA,IACL,KAAK;AAAA,EACP;AAEA,SAAO;AAAA,IACL,MAAM,CAAC;AAAA,IACP,QAAQ,EAAE,GAAG,KAAK,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.cjs","names":["parseAbiItem","handleToRef"],"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,UAAA,GAASA,QAAAA,aAAAA,CAAa,iBAAiB;CAC7C,IAAI,OAAO,SAAS,YAClB,MAAM,IAAI,MACR,kDAAkD,OAAO,KAAK,MAAM,kBAAkB,EACxF;CAGF,OAAO,OAAO,OAAO,KAAK,OAAO,UAAU;EACzC,IAAI,CAAC,MAAM,MACT,MAAM,IAAI,MACR,iCAAiC,MAAM,iFACzC;EAEF,OAAO,MAAM;CACf,CAAC;AACH;;;;;;AAOA,MAAa,aAAa,aAAkC;CAC1D,IAAI,UAAU,UAAU,OAAOC,0BAAAA,YAAY,QAAQ;CACnD,OAAO;AACT;;;;;AAoBA,MAAM,yBACJ,OACA,MACA,WACU;CACV,MAAM,oBAAoB,OAAO;CACjC,IAAI,OAAO,sBAAsB,UAC/B,MAAM,IAAI,MACR,GAAG,MAAM,4DACX;CAGF,MAAM,aAAa,oBAAoB,iBAAiB;CACxD,MAAM,WAAW,IAAI,IAAI,UAAU;CACnC,MAAM,WAAW,OAAO,KAAK,IAAI;CACjC,MAAM,UAAU,IAAI,IAAI,QAAQ;CAEhC,MAAM,UAAU,WAAW,QAAQ,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;CACxD,MAAM,QAAQ,SAAS,QAAQ,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;CAErD,IAAI,QAAQ,SAAS,KAAK,MAAM,SAAS,GACvC,MAAM,IAAI,MACR,GAAG,MAAM,eAAe,SAAS,KAC/B,IACF,EAAE,uCAAuC,WAAW,KAClD,IACF,EAAE,cAAc,QAAQ,KAAK,IAAI,KAAK,SAAS,WAC7C,MAAM,KAAK,IAAI,KAAK,SACrB,EACH;CAGF,OAAO,WAAW,KAAK,SAAS;EAC9B,MAAM,WAAW,KAAK;EACtB,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MACR,GAAG,MAAM,8BAA8B,KAAK,eAC9C;EAEF,OAAO,UAAU,QAAQ;CAC3B,CAAC;AACH;;;;;;;;AASA,MAAa,uBACX,SACmB;CACnB,MAAM,iBAAiB,sBACrB,aACA,KAAK,MACL,KAAK,MACP;CACA,MAAM,cAAc,KAAK,aAAa,KAAA;CAEtC,OAAO;EACL,IAAI,cAAc,cAAc;EAChC,MAAM,cAAc,EAAE,OAAO,UAAU,KAAK,QAAQ,EAAE,IAAI,CAAC;EAC3D,QAAQ;GAAE,GAAG,KAAK;GAAQ,MAAM;EAAe;EAC/C,GAAI,KAAK,UAAU,KAAK,OAAO,SAAS,KAAK,EAAE,QAAQ,KAAK,OAAO;CACrE;AACF;;;;;;AAaA,MAAa,6BACX,SACa;CACb,MAAM,iBAAiB,sBACrB,mBACA,KAAK,MACL,KAAK,MACP;CAEA,OAAO;EACL,MAAM,CAAC;EACP,QAAQ;GAAE,GAAG,KAAK;GAAQ,MAAM;EAAe;EAC/C,GAAI,KAAK,UAAU,KAAK,OAAO,SAAS,KAAK,EAAE,QAAQ,KAAK,OAAO;CACrE;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
1
|
+
import { AbiTypeToOutputKind, TypedGuard } from "../types.cjs";
|
|
2
|
+
import { AnyRefBindable, OutputHandle, RefBindable } from "./handles.cjs";
|
|
3
|
+
import { CallArgs } from "./FlowBuilderCore.cjs";
|
|
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.cjs';
|
|
|
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.cts.map
|