@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,57 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { SimulateResult, SimulationRevert } from "@lifi/compose-spec";
|
|
2
|
+
//#region src/responseSchemas.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
5
5
|
* when the body does not match the `ok`/`revert`/`error` union, letting the
|
|
6
6
|
* caller raise a transport-level error.
|
|
7
7
|
*/
|
|
8
|
-
declare const parseSimulateResult: (body: unknown) => SimulateResult | null;
|
|
8
|
+
export declare const parseSimulateResult: (body: unknown) => SimulateResult | null;
|
|
9
9
|
/**
|
|
10
10
|
* The validated members of an HTTP 206 partial compile envelope. `data` is
|
|
11
11
|
* verified to be an object at runtime but left `unknown` here — compose-spec
|
|
12
12
|
* owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so
|
|
13
13
|
* the caller narrows it in one step. `error` is fully validated.
|
|
14
14
|
*/
|
|
15
|
-
interface CompilePartialEnvelope {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
export interface CompilePartialEnvelope {
|
|
16
|
+
readonly data: unknown;
|
|
17
|
+
readonly error: {
|
|
18
|
+
readonly kind: string;
|
|
19
|
+
readonly message: string;
|
|
20
|
+
};
|
|
21
21
|
}
|
|
22
22
|
/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
|
|
23
|
-
declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
|
|
23
|
+
export declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
|
|
24
24
|
/**
|
|
25
25
|
* A single prepared-op failure inside a `preparation_error` envelope. `kind` is
|
|
26
26
|
* kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in
|
|
27
27
|
* `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.
|
|
28
28
|
*/
|
|
29
|
-
interface ServerFailedPreparedOp {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
export interface ServerFailedPreparedOp {
|
|
30
|
+
readonly callId: string;
|
|
31
|
+
readonly op: string;
|
|
32
|
+
readonly kind: string;
|
|
33
|
+
readonly message: string;
|
|
34
|
+
readonly path?: string;
|
|
35
|
+
readonly port?: string;
|
|
36
|
+
readonly fix?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Error envelope returned on non-2xx responses. */
|
|
39
|
+
export interface ServerErrorBody {
|
|
40
|
+
readonly error?: {
|
|
41
|
+
readonly kind?: string;
|
|
42
|
+
readonly message?: string;
|
|
34
43
|
readonly path?: string;
|
|
35
44
|
readonly port?: string;
|
|
36
45
|
readonly fix?: string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readonly
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
readonly port?: string;
|
|
45
|
-
readonly fix?: string;
|
|
46
|
-
readonly sdkVersion?: string;
|
|
47
|
-
readonly serverVersion?: string;
|
|
48
|
-
readonly minimumSdkVersion?: string;
|
|
49
|
-
readonly details?: SimulationRevert;
|
|
50
|
-
readonly failedOps?: readonly ServerFailedPreparedOp[];
|
|
51
|
-
readonly succeededOps?: readonly string[];
|
|
52
|
-
};
|
|
46
|
+
readonly sdkVersion?: string;
|
|
47
|
+
readonly serverVersion?: string;
|
|
48
|
+
readonly minimumSdkVersion?: string;
|
|
49
|
+
readonly details?: SimulationRevert;
|
|
50
|
+
readonly failedOps?: readonly ServerFailedPreparedOp[];
|
|
51
|
+
readonly succeededOps?: readonly string[];
|
|
52
|
+
};
|
|
53
53
|
}
|
|
54
54
|
/** Validates an already-parsed error envelope; `null` when it does not match. */
|
|
55
|
-
declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
export declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
|
|
56
|
+
//#endregion
|
|
57
|
+
//# sourceMappingURL=responseSchemas.d.ts.map
|
package/dist/responseSchemas.js
CHANGED
|
@@ -1,90 +1,109 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
+
//#region src/responseSchemas.ts
|
|
3
|
+
/**
|
|
4
|
+
* Zod-backed parsers for Compose API response bodies.
|
|
5
|
+
*
|
|
6
|
+
* Server responses are untrusted input crossing into the SDK, so the shapes the
|
|
7
|
+
* client reads back are validated here rather than asserted with `as` casts. The
|
|
8
|
+
* schemas are module-private (the package builds with `--isolatedDeclarations`,
|
|
9
|
+
* which forbids exporting un-annotated complex values); the public surface is
|
|
10
|
+
* the typed `parse*` helpers, whose explicit return types double as the contract.
|
|
11
|
+
*
|
|
12
|
+
* The simulate union is the one response the SDK fully owns and parses itself
|
|
13
|
+
* (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in
|
|
14
|
+
* lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the
|
|
15
|
+
* compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for
|
|
16
|
+
* its server-side simulate schema, so the two cannot silently drift.
|
|
17
|
+
*/
|
|
2
18
|
const balanceEntrySchema = z.object({
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
19
|
+
token: z.string(),
|
|
20
|
+
owner: z.string(),
|
|
21
|
+
amount: z.string()
|
|
6
22
|
});
|
|
7
23
|
const simulateOkSchema = z.object({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
status: z.literal("ok"),
|
|
25
|
+
block: z.number(),
|
|
26
|
+
timestamp: z.number(),
|
|
27
|
+
balancesBefore: z.array(balanceEntrySchema),
|
|
28
|
+
balancesAfter: z.array(balanceEntrySchema),
|
|
29
|
+
deltas: z.array(balanceEntrySchema),
|
|
30
|
+
gasUsed: z.string()
|
|
15
31
|
});
|
|
16
32
|
const simulateRevertDecodeResultSchema = z.object({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
).optional(),
|
|
23
|
-
error: z.string().optional()
|
|
33
|
+
errorCandidates: z.array(z.object({
|
|
34
|
+
decodedErrorSignature: z.string(),
|
|
35
|
+
decodedParams: z.array(z.string())
|
|
36
|
+
})).optional(),
|
|
37
|
+
error: z.string().optional()
|
|
24
38
|
});
|
|
25
39
|
const simulateRevertSchema = z.object({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
status: z.literal("revert"),
|
|
41
|
+
block: z.number(),
|
|
42
|
+
timestamp: z.number(),
|
|
43
|
+
revertReason: z.string().optional(),
|
|
44
|
+
code: z.number().optional(),
|
|
45
|
+
rawErrorBytes: z.string().optional(),
|
|
46
|
+
decodeResult: simulateRevertDecodeResultSchema.optional()
|
|
33
47
|
});
|
|
34
48
|
const simulateSetupErrorSchema = z.object({
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
status: z.literal("error"),
|
|
50
|
+
message: z.string()
|
|
37
51
|
});
|
|
38
52
|
const simulateResultSchema = z.discriminatedUnion("status", [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
simulateOkSchema,
|
|
54
|
+
simulateRevertSchema,
|
|
55
|
+
simulateSetupErrorSchema
|
|
42
56
|
]);
|
|
57
|
+
/**
|
|
58
|
+
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
59
|
+
* when the body does not match the `ok`/`revert`/`error` union, letting the
|
|
60
|
+
* caller raise a transport-level error.
|
|
61
|
+
*/
|
|
43
62
|
const parseSimulateResult = (body) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return result;
|
|
63
|
+
const parsed = simulateResultSchema.safeParse(body);
|
|
64
|
+
if (!parsed.success) return null;
|
|
65
|
+
return parsed.data;
|
|
48
66
|
};
|
|
49
67
|
const compilePartialEnvelopeSchema = z.object({
|
|
50
|
-
|
|
51
|
-
|
|
68
|
+
data: z.record(z.string(), z.unknown()),
|
|
69
|
+
error: z.object({
|
|
70
|
+
kind: z.string(),
|
|
71
|
+
message: z.string()
|
|
72
|
+
})
|
|
52
73
|
});
|
|
74
|
+
/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
|
|
53
75
|
const parseCompilePartialEnvelope = (body) => {
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
const parsed = compilePartialEnvelopeSchema.safeParse(body);
|
|
77
|
+
return parsed.success ? parsed.data : null;
|
|
56
78
|
};
|
|
57
79
|
const failedPreparedOpSchema = z.object({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
const serverErrorBodySchema = z.object({
|
|
67
|
-
error: z.object({
|
|
68
|
-
kind: z.string().optional(),
|
|
69
|
-
message: z.string().optional(),
|
|
70
|
-
path: z.string().optional(),
|
|
71
|
-
port: z.string().optional(),
|
|
72
|
-
fix: z.string().optional(),
|
|
73
|
-
sdkVersion: z.string().optional(),
|
|
74
|
-
serverVersion: z.string().optional(),
|
|
75
|
-
minimumSdkVersion: z.string().optional(),
|
|
76
|
-
details: z.custom().optional(),
|
|
77
|
-
failedOps: z.array(failedPreparedOpSchema).readonly().optional(),
|
|
78
|
-
succeededOps: z.array(z.string()).readonly().optional()
|
|
79
|
-
}).optional()
|
|
80
|
+
callId: z.string(),
|
|
81
|
+
op: z.string(),
|
|
82
|
+
kind: z.string(),
|
|
83
|
+
message: z.string(),
|
|
84
|
+
path: z.string().optional(),
|
|
85
|
+
port: z.string().optional(),
|
|
86
|
+
fix: z.string().optional()
|
|
80
87
|
});
|
|
88
|
+
const serverErrorBodySchema = z.object({ error: z.object({
|
|
89
|
+
kind: z.string().optional(),
|
|
90
|
+
message: z.string().optional(),
|
|
91
|
+
path: z.string().optional(),
|
|
92
|
+
port: z.string().optional(),
|
|
93
|
+
fix: z.string().optional(),
|
|
94
|
+
sdkVersion: z.string().optional(),
|
|
95
|
+
serverVersion: z.string().optional(),
|
|
96
|
+
minimumSdkVersion: z.string().optional(),
|
|
97
|
+
details: z.custom().optional(),
|
|
98
|
+
failedOps: z.array(failedPreparedOpSchema).readonly().optional(),
|
|
99
|
+
succeededOps: z.array(z.string()).readonly().optional()
|
|
100
|
+
}).optional() });
|
|
101
|
+
/** Validates an already-parsed error envelope; `null` when it does not match. */
|
|
81
102
|
const parseServerErrorBody = (json) => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
export {
|
|
86
|
-
parseCompilePartialEnvelope,
|
|
87
|
-
parseServerErrorBody,
|
|
88
|
-
parseSimulateResult
|
|
103
|
+
const parsed = serverErrorBodySchema.safeParse(json);
|
|
104
|
+
return parsed.success ? parsed.data : null;
|
|
89
105
|
};
|
|
106
|
+
//#endregion
|
|
107
|
+
export { parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
|
|
108
|
+
|
|
90
109
|
//# sourceMappingURL=responseSchemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object at runtime but left `unknown` here — compose-spec\n * owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so\n * the caller narrows it in one step. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: unknown;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n readonly sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: string;\n readonly details?: SimulationRevert;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them — which is\n// also why `port` and `fix`, set on every author-caused `validation_error`,\n// have to be declared here to reach the caller.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"responseSchemas.js","names":[],"sources":["../src/responseSchemas.ts"],"sourcesContent":["import type { SimulateResult, SimulationRevert } from '@lifi/compose-spec';\nimport z from 'zod';\n\n/**\n * Zod-backed parsers for Compose API response bodies.\n *\n * Server responses are untrusted input crossing into the SDK, so the shapes the\n * client reads back are validated here rather than asserted with `as` casts. The\n * schemas are module-private (the package builds with `--isolatedDeclarations`,\n * which forbids exporting un-annotated complex values); the public surface is\n * the typed `parse*` helpers, whose explicit return types double as the contract.\n *\n * The simulate union is the one response the SDK fully owns and parses itself\n * (it is un-enveloped, unlike `/compose`), so it gets a complete schema kept in\n * lockstep with the canonical `SimulateResult` in `@lifi/compose-spec` by the\n * compile-time assertion below — the same anchoring `@lifi/api-schemas` uses for\n * its server-side simulate schema, so the two cannot silently drift.\n */\n\nconst balanceEntrySchema = z.object({\n token: z.string(),\n owner: z.string(),\n amount: z.string(),\n});\n\nconst simulateOkSchema = z.object({\n status: z.literal('ok'),\n block: z.number(),\n timestamp: z.number(),\n balancesBefore: z.array(balanceEntrySchema),\n balancesAfter: z.array(balanceEntrySchema),\n deltas: z.array(balanceEntrySchema),\n gasUsed: z.string(),\n});\n\nconst simulateRevertDecodeResultSchema = z.object({\n errorCandidates: z\n .array(\n z.object({\n decodedErrorSignature: z.string(),\n decodedParams: z.array(z.string()),\n }),\n )\n .optional(),\n error: z.string().optional(),\n});\n\nconst simulateRevertSchema = z.object({\n status: z.literal('revert'),\n block: z.number(),\n timestamp: z.number(),\n revertReason: z.string().optional(),\n code: z.number().optional(),\n rawErrorBytes: z.string().optional(),\n decodeResult: simulateRevertDecodeResultSchema.optional(),\n});\n\nconst simulateSetupErrorSchema = z.object({\n status: z.literal('error'),\n message: z.string(),\n});\n\nconst simulateResultSchema = z.discriminatedUnion('status', [\n simulateOkSchema,\n simulateRevertSchema,\n simulateSetupErrorSchema,\n]);\n\n// The type the schema actually parses out. Kept private (referencing it from an\n// exported declaration would break `--isolatedDeclarations`) and pinned to the\n// canonical `SimulateResult` inside `parseSimulateResult` below.\ntype SimulateResultWire = z.infer<typeof simulateResultSchema>;\n\n/**\n * Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`\n * when the body does not match the `ok`/`revert`/`error` union, letting the\n * caller raise a transport-level error.\n */\nexport const parseSimulateResult = (body: unknown): SimulateResult | null => {\n const parsed = simulateResultSchema.safeParse(body);\n if (!parsed.success) return null;\n // Pin the schema to the canonical contract in both directions, so it cannot\n // silently drift (mirroring the conformance assertion `@lifi/api-schemas` runs\n // on its server-side simulate schema). Assigning the inferred wire value to a\n // `SimulateResult` checks wire→spec; `satisfies SimulateResultWire` checks\n // spec→wire. A missing or mistyped field on either side fails to compile.\n const result: SimulateResult = parsed.data;\n return result satisfies SimulateResultWire;\n};\n\n/**\n * The validated members of an HTTP 206 partial compile envelope. `data` is\n * verified to be an object at runtime but left `unknown` here — compose-spec\n * owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so\n * the caller narrows it in one step. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: unknown;\n readonly error: { readonly kind: string; readonly message: string };\n}\n\nconst compilePartialEnvelopeSchema = z.object({\n data: z.record(z.string(), z.unknown()),\n error: z.object({ kind: z.string(), message: z.string() }),\n});\n\n/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */\nexport const parseCompilePartialEnvelope = (\n body: unknown,\n): CompilePartialEnvelope | null => {\n const parsed = compilePartialEnvelopeSchema.safeParse(body);\n return parsed.success ? parsed.data : null;\n};\n\n/**\n * A single prepared-op failure inside a `preparation_error` envelope. `kind` is\n * kept as `string` here — the narrowing to `GenericComposeErrorKind` happens in\n * `errorFromHttpResponse`, where the value is lifted onto `ComposeError`.\n */\nexport interface ServerFailedPreparedOp {\n readonly callId: string;\n readonly op: string;\n readonly kind: string;\n readonly message: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n}\n\n/** Error envelope returned on non-2xx responses. */\nexport interface ServerErrorBody {\n readonly error?: {\n readonly kind?: string;\n readonly message?: string;\n readonly path?: string;\n readonly port?: string;\n readonly fix?: string;\n readonly sdkVersion?: string;\n readonly serverVersion?: string;\n readonly minimumSdkVersion?: string;\n readonly details?: SimulationRevert;\n readonly failedOps?: readonly ServerFailedPreparedOp[];\n readonly succeededOps?: readonly string[];\n };\n}\n\nconst failedPreparedOpSchema = z.object({\n callId: z.string(),\n op: z.string(),\n kind: z.string(),\n message: z.string(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n});\n\n// `details` is passed through (`z.custom`) rather than parsed: the SDK does not\n// own the `SimulationRevert` schema and forwards the field verbatim onto\n// `ComposeError`.\n//\n// `failedOps`/`succeededOps` are optional here because every error kind shares\n// this envelope; they are only populated for `preparation_error` (422). Zod\n// strips undeclared keys, so omitting them would silently drop them — which is\n// also why `port` and `fix`, set on every author-caused `validation_error`,\n// have to be declared here to reach the caller.\nconst serverErrorBodySchema = z.object({\n error: z\n .object({\n kind: z.string().optional(),\n message: z.string().optional(),\n path: z.string().optional(),\n port: z.string().optional(),\n fix: z.string().optional(),\n sdkVersion: z.string().optional(),\n serverVersion: z.string().optional(),\n minimumSdkVersion: z.string().optional(),\n details: z.custom<SimulationRevert>().optional(),\n failedOps: z.array(failedPreparedOpSchema).readonly().optional(),\n succeededOps: z.array(z.string()).readonly().optional(),\n })\n .optional(),\n});\n\n/** Validates an already-parsed error envelope; `null` when it does not match. */\nexport const parseServerErrorBody = (json: unknown): ServerErrorBody | null => {\n const parsed = serverErrorBodySchema.safeParse(json);\n return parsed.success ? parsed.data : null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAM,qBAAqB,EAAE,OAAO;CAClC,OAAO,EAAE,OAAO;CAChB,OAAO,EAAE,OAAO;CAChB,QAAQ,EAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,EAAE,OAAO;CAChC,QAAQ,EAAE,QAAQ,IAAI;CACtB,OAAO,EAAE,OAAO;CAChB,WAAW,EAAE,OAAO;CACpB,gBAAgB,EAAE,MAAM,kBAAkB;CAC1C,eAAe,EAAE,MAAM,kBAAkB;CACzC,QAAQ,EAAE,MAAM,kBAAkB;CAClC,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,EAAE,OAAO;CAChD,iBAAiB,EACd,MACC,EAAE,OAAO;EACP,uBAAuB,EAAE,OAAO;EAChC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC;CACnC,CAAC,CACH,CAAC,CACA,SAAS;CACZ,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS;AAC7B,CAAC;AAED,MAAM,uBAAuB,EAAE,OAAO;CACpC,QAAQ,EAAE,QAAQ,QAAQ;CAC1B,OAAO,EAAE,OAAO;CAChB,WAAW,EAAE,OAAO;CACpB,cAAc,EAAE,OAAO,CAAC,CAAC,SAAS;CAClC,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,eAAe,EAAE,OAAO,CAAC,CAAC,SAAS;CACnC,cAAc,iCAAiC,SAAS;AAC1D,CAAC;AAED,MAAM,2BAA2B,EAAE,OAAO;CACxC,QAAQ,EAAE,QAAQ,OAAO;CACzB,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,uBAAuB,EAAE,mBAAmB,UAAU;CAC1D;CACA;CACA;AACF,CAAC;;;;;;AAYD,MAAa,uBAAuB,SAAyC;CAC3E,MAAM,SAAS,qBAAqB,UAAU,IAAI;CAClD,IAAI,CAAC,OAAO,SAAS,OAAO;CAO5B,OAD+B,OAAO;AAExC;AAaA,MAAM,+BAA+B,EAAE,OAAO;CAC5C,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;CACtC,OAAO,EAAE,OAAO;EAAE,MAAM,EAAE,OAAO;EAAG,SAAS,EAAE,OAAO;CAAE,CAAC;AAC3D,CAAC;;AAGD,MAAa,+BACX,SACkC;CAClC,MAAM,SAAS,6BAA6B,UAAU,IAAI;CAC1D,OAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAkCA,MAAM,yBAAyB,EAAE,OAAO;CACtC,QAAQ,EAAE,OAAO;CACjB,IAAI,EAAE,OAAO;CACb,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,OAAO;CAClB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS;AAC3B,CAAC;AAWD,MAAM,wBAAwB,EAAE,OAAO,EACrC,OAAO,EACJ,OAAO;CACN,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS;CAC7B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;CAC1B,KAAK,EAAE,OAAO,CAAC,CAAC,SAAS;CACzB,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS;CAChC,eAAe,EAAE,OAAO,CAAC,CAAC,SAAS;CACnC,mBAAmB,EAAE,OAAO,CAAC,CAAC,SAAS;CACvC,SAAS,EAAE,OAAyB,CAAC,CAAC,SAAS;CAC/C,WAAW,EAAE,MAAM,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;CAC/D,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS;AACxD,CAAC,CAAC,CACD,SAAS,EACd,CAAC;;AAGD,MAAa,wBAAwB,SAA0C;CAC7E,MAAM,SAAS,sBAAsB,UAAU,IAAI;CACnD,OAAO,OAAO,UAAU,OAAO,OAAO;AACxC"}
|
package/dist/routeAmount.cjs
CHANGED
|
@@ -1,38 +1,68 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __export = (target, all2) => {
|
|
7
|
-
for (var name in all2)
|
|
8
|
-
__defProp(target, name, { get: all2[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
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 routeAmount_exports = {};
|
|
20
|
-
__export(routeAmount_exports, {
|
|
21
|
-
all: () => all,
|
|
22
|
-
exact: () => exact
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/routeAmount.ts
|
|
3
|
+
var routeAmount_exports = /* @__PURE__ */ require("./_virtual/_rolldown/runtime.cjs").__exportAll({
|
|
4
|
+
all: () => all,
|
|
5
|
+
exact: () => exact
|
|
23
6
|
});
|
|
24
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
9
|
+
*
|
|
10
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
11
|
+
* to a decimal string when the request is sent.
|
|
12
|
+
* @returns The `EXACT` member of the route amount union.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const result = await sdk.route({
|
|
17
|
+
* chainId: 1,
|
|
18
|
+
* fromToken: NATIVE_ETH,
|
|
19
|
+
* toToken: WETH,
|
|
20
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
21
|
+
* signer: OWNER,
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
25
|
const exact = (amount) => ({
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
type: "EXACT",
|
|
27
|
+
amount
|
|
28
28
|
});
|
|
29
|
+
/**
|
|
30
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
31
|
+
* time.
|
|
32
|
+
*
|
|
33
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
34
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
35
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
36
|
+
*
|
|
37
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
38
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
39
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
40
|
+
* is whatever the balance turns out to be.
|
|
41
|
+
* @returns The `ALL` member of the route amount union.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const result = await sdk.route({
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* fromToken: USDC,
|
|
48
|
+
* toToken: A_ETH_USDC,
|
|
49
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
50
|
+
* signer: OWNER,
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
29
54
|
const all = (simAmount) => ({
|
|
30
|
-
|
|
31
|
-
|
|
55
|
+
type: "ALL",
|
|
56
|
+
simAmount
|
|
32
57
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.all = all;
|
|
60
|
+
exports.exact = exact;
|
|
61
|
+
Object.defineProperty(exports, "routeAmount_exports", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function() {
|
|
64
|
+
return routeAmount_exports;
|
|
65
|
+
}
|
|
37
66
|
});
|
|
67
|
+
|
|
38
68
|
//# sourceMappingURL=routeAmount.cjs.map
|
package/dist/routeAmount.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"routeAmount.cjs","names":[],"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,SAAS,YAA+C;CACnE,MAAM;CACN;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,OAAO,eAAgD;CAClE,MAAM;CACN;AACF"}
|
package/dist/routeAmount.d.cts
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { RouteAmountAll, RouteAmountExact } from "@lifi/compose-spec";
|
|
2
|
+
declare namespace routeAmount_d_exports {
|
|
3
|
+
export { all, exact };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
7
|
+
*
|
|
8
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
9
|
+
* to a decimal string when the request is sent.
|
|
10
|
+
* @returns The `EXACT` member of the route amount union.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result = await sdk.route({
|
|
15
|
+
* chainId: 1,
|
|
16
|
+
* fromToken: NATIVE_ETH,
|
|
17
|
+
* toToken: WETH,
|
|
18
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
19
|
+
* signer: OWNER,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const exact: (amount: bigint | string) => RouteAmountExact;
|
|
24
|
+
/**
|
|
25
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
26
|
+
* time.
|
|
27
|
+
*
|
|
28
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
29
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
30
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
31
|
+
*
|
|
32
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
33
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
34
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
35
|
+
* is whatever the balance turns out to be.
|
|
36
|
+
* @returns The `ALL` member of the route amount union.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const result = await sdk.route({
|
|
41
|
+
* chainId: 1,
|
|
42
|
+
* fromToken: USDC,
|
|
43
|
+
* toToken: A_ETH_USDC,
|
|
44
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
45
|
+
* signer: OWNER,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const all: (simAmount: bigint | string) => RouteAmountAll;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { routeAmount_d_exports };
|
|
52
|
+
//# sourceMappingURL=routeAmount.d.cts.map
|
package/dist/routeAmount.d.ts
CHANGED
|
@@ -1,2 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { RouteAmountAll, RouteAmountExact } from "@lifi/compose-spec";
|
|
2
|
+
declare namespace routeAmount_d_exports {
|
|
3
|
+
export { all, exact };
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
7
|
+
*
|
|
8
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
9
|
+
* to a decimal string when the request is sent.
|
|
10
|
+
* @returns The `EXACT` member of the route amount union.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const result = await sdk.route({
|
|
15
|
+
* chainId: 1,
|
|
16
|
+
* fromToken: NATIVE_ETH,
|
|
17
|
+
* toToken: WETH,
|
|
18
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
19
|
+
* signer: OWNER,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const exact: (amount: bigint | string) => RouteAmountExact;
|
|
24
|
+
/**
|
|
25
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
26
|
+
* time.
|
|
27
|
+
*
|
|
28
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
29
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
30
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
31
|
+
*
|
|
32
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
33
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
34
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
35
|
+
* is whatever the balance turns out to be.
|
|
36
|
+
* @returns The `ALL` member of the route amount union.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const result = await sdk.route({
|
|
41
|
+
* chainId: 1,
|
|
42
|
+
* fromToken: USDC,
|
|
43
|
+
* toToken: A_ETH_USDC,
|
|
44
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
45
|
+
* signer: OWNER,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const all: (simAmount: bigint | string) => RouteAmountAll;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { routeAmount_d_exports };
|
|
52
|
+
//# sourceMappingURL=routeAmount.d.ts.map
|
package/dist/routeAmount.js
CHANGED
|
@@ -1,13 +1,61 @@
|
|
|
1
|
+
import { __exportAll } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
//#region src/routeAmount.ts
|
|
3
|
+
var routeAmount_exports = /* @__PURE__ */ __exportAll({
|
|
4
|
+
all: () => all,
|
|
5
|
+
exact: () => exact
|
|
6
|
+
});
|
|
7
|
+
/**
|
|
8
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
9
|
+
*
|
|
10
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
11
|
+
* to a decimal string when the request is sent.
|
|
12
|
+
* @returns The `EXACT` member of the route amount union.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const result = await sdk.route({
|
|
17
|
+
* chainId: 1,
|
|
18
|
+
* fromToken: NATIVE_ETH,
|
|
19
|
+
* toToken: WETH,
|
|
20
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
21
|
+
* signer: OWNER,
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
1
25
|
const exact = (amount) => ({
|
|
2
|
-
|
|
3
|
-
|
|
26
|
+
type: "EXACT",
|
|
27
|
+
amount
|
|
4
28
|
});
|
|
29
|
+
/**
|
|
30
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
31
|
+
* time.
|
|
32
|
+
*
|
|
33
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
34
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
35
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
36
|
+
*
|
|
37
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
38
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
39
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
40
|
+
* is whatever the balance turns out to be.
|
|
41
|
+
* @returns The `ALL` member of the route amount union.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const result = await sdk.route({
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* fromToken: USDC,
|
|
48
|
+
* toToken: A_ETH_USDC,
|
|
49
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
50
|
+
* signer: OWNER,
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
5
54
|
const all = (simAmount) => ({
|
|
6
|
-
|
|
7
|
-
|
|
55
|
+
type: "ALL",
|
|
56
|
+
simAmount
|
|
8
57
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { all, exact, routeAmount_exports };
|
|
60
|
+
|
|
13
61
|
//# sourceMappingURL=routeAmount.js.map
|
package/dist/routeAmount.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"routeAmount.js","names":[],"sources":["../src/routeAmount.ts"],"sourcesContent":["import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';\n\n// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire\n// union is discriminated by `type` and — deliberately, because the two variants\n// mean different things — names its payload field differently in each variant:\n// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for\n// a balance resolved on-chain. These helpers keep call sites from having to\n// remember which name goes with which discriminant.\n\n/**\n * Spend an exact amount of the route's `fromToken`.\n *\n * @param amount - Amount in the token's smallest unit. `bigint` is serialised\n * to a decimal string when the request is sent.\n * @returns The `EXACT` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: NATIVE_ETH,\n * toToken: WETH,\n * amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped\n * signer: OWNER,\n * });\n * ```\n */\nexport const exact = (amount: bigint | string): RouteAmountExact => ({\n type: 'EXACT',\n amount,\n});\n\n/**\n * Spend the signer's entire `fromToken` balance, resolved on-chain at execution\n * time.\n *\n * Not supported when `fromToken` is the chain's native sentinel — the server\n * rejects it. A gas coin is sent via `msg.value`, so there is no on-chain\n * balance to sweep; use {@link exact} for native inputs.\n *\n * @param simAmount - A realistic estimate of that balance, in the token's\n * smallest unit. The server quotes and simulates against this value, so it\n * shapes the returned quote and preconditions — but the amount actually moved\n * is whatever the balance turns out to be.\n * @returns The `ALL` member of the route amount union.\n *\n * @example\n * ```ts\n * const result = await sdk.route({\n * chainId: 1,\n * fromToken: USDC,\n * toToken: A_ETH_USDC,\n * amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand\n * signer: OWNER,\n * });\n * ```\n */\nexport const all = (simAmount: bigint | string): RouteAmountAll => ({\n type: 'ALL',\n simAmount,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,SAAS,YAA+C;CACnE,MAAM;CACN;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,MAAa,OAAO,eAAgD;CAClE,MAAM;CACN;AACF"}
|