@lifi/composer-sdk 0.2.0-staging.5 → 0.3.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 +103 -2
- package/dist/client.cjs +46 -8
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +27 -3
- package/dist/client.d.ts +27 -3
- package/dist/client.js +49 -8
- package/dist/client.js.map +1 -1
- package/dist/errors.cjs +4 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +6 -1
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +80 -20
- package/dist/generated/config.generated.d.ts +80 -20
- package/dist/generated/materialisers.generated.cjs +2 -8
- package/dist/generated/materialisers.generated.cjs.map +1 -1
- package/dist/generated/materialisers.generated.d.cts +1 -1
- package/dist/generated/materialisers.generated.d.ts +1 -1
- package/dist/generated/materialisers.generated.js +1 -6
- package/dist/generated/materialisers.generated.js.map +1 -1
- package/dist/generated/operations.generated.cjs +1 -30
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +2 -94
- package/dist/generated/operations.generated.d.ts +2 -94
- package/dist/generated/operations.generated.js +1 -30
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/{materialisers.generated-BfWJ-g7t.d.ts → materialisers.generated-BMkBQgWZ.d.ts} +3 -8
- package/dist/{materialisers.generated-DaJRwiRe.d.cts → materialisers.generated-BWq5oePO.d.cts} +3 -8
- package/dist/responseSchemas.cjs +110 -0
- package/dist/responseSchemas.cjs.map +1 -0
- package/dist/responseSchemas.d.cts +36 -0
- package/dist/responseSchemas.d.ts +36 -0
- package/dist/responseSchemas.js +74 -0
- package/dist/responseSchemas.js.map +1 -0
- package/dist/run/simulate.cjs +41 -0
- package/dist/run/simulate.cjs.map +1 -0
- package/dist/run/simulate.d.cts +59 -0
- package/dist/run/simulate.d.ts +59 -0
- package/dist/run/simulate.js +17 -0
- package/dist/run/simulate.js.map +1 -0
- package/dist/sdk.cjs +6 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +18 -6
- package/dist/sdk.d.ts +18 -6
- package/dist/sdk.js +6 -1
- package/dist/sdk.js.map +1 -1
- package/package.json +8 -6
- package/src/client.ts +96 -16
- package/src/errors.ts +8 -10
- package/src/examples/aaveClaimRewards.ts +2 -2
- package/src/examples/aaveRepay.ts +2 -2
- package/src/examples/aaveRepayWithATokens.ts +2 -2
- package/src/examples/aaveSetEMode.ts +2 -2
- package/src/examples/approveAndDeposit.ts +2 -2
- package/src/examples/callContract.ts +4 -4
- package/src/examples/config.ts +4 -1
- package/src/examples/consolidateToEth.ts +2 -2
- package/src/examples/consolidateToUsdc.ts +2 -2
- package/src/examples/depositFromProxy.ts +2 -2
- package/src/examples/dustSweep.ts +2 -2
- package/src/examples/emitCustomEvent.ts +2 -2
- package/src/examples/invariantChecks.ts +2 -2
- package/src/examples/lifiSwap.ts +2 -2
- package/src/examples/lifiZap.ts +2 -2
- package/src/examples/rawCallWithArithmetic.ts +2 -2
- package/src/examples/readContractState.ts +2 -2
- package/src/examples/simulateCompiledSwap.ts +76 -0
- package/src/examples/simulateRawTransaction.ts +39 -0
- package/src/examples/splitAndZap.ts +2 -2
- package/src/examples/splitWithArithmetic.ts +2 -2
- package/src/examples/swapAndZap.ts +2 -2
- package/src/examples/swapToRecipient.ts +2 -2
- package/src/examples/swapWithAllowRevert.ts +3 -3
- package/src/examples/swapWithBalanceCheck.ts +2 -2
- package/src/examples/swapWithFee.ts +2 -2
- package/src/examples/swapWithOutputValidation.ts +2 -2
- package/src/examples/transferTokens.ts +3 -3
- package/src/examples/untypedOpWithTypedRef.ts +2 -2
- package/src/generated/config.generated.ts +221 -20
- package/src/generated/materialisers.generated.ts +0 -12
- package/src/generated/operations.generated.ts +0 -177
- package/src/index.ts +25 -0
- package/src/responseSchemas.ts +143 -0
- package/src/run/simulate.ts +78 -0
- package/src/sdk.ts +25 -6
- package/src/examples/staged/aaveBorrow.ts +0 -128
- package/src/examples/staged/aaveDebtRebalanceExactOut.ts +0 -301
- package/src/examples/staged/aaveHealthFactorExplode.ts +0 -70
- package/src/examples/staged/aaveToMorphoDebtMigration.ts +0 -200
- package/src/examples/staged/aaveToMorphoDebtMigrationWithSwap.ts +0 -231
- package/src/examples/staged/aaveToMorphoDebtMigrationWithSwapExactOut.ts +0 -307
- package/src/examples/staged/flashloanRepay.ts +0 -142
- package/src/examples/staged/morphoBlueBorrow.ts +0 -93
- package/src/examples/staged/morphoBlueRepay.ts +0 -132
- package/src/examples/staged/registry.ts +0 -80
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var responseSchemas_exports = {};
|
|
30
|
+
__export(responseSchemas_exports, {
|
|
31
|
+
parseCompilePartialEnvelope: () => parseCompilePartialEnvelope,
|
|
32
|
+
parseServerErrorBody: () => parseServerErrorBody,
|
|
33
|
+
parseSimulateResult: () => parseSimulateResult
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(responseSchemas_exports);
|
|
36
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
37
|
+
const balanceEntrySchema = import_zod.default.object({
|
|
38
|
+
token: import_zod.default.string(),
|
|
39
|
+
owner: import_zod.default.string(),
|
|
40
|
+
amount: import_zod.default.string()
|
|
41
|
+
});
|
|
42
|
+
const simulateOkSchema = import_zod.default.object({
|
|
43
|
+
status: import_zod.default.literal("ok"),
|
|
44
|
+
block: import_zod.default.number(),
|
|
45
|
+
timestamp: import_zod.default.number(),
|
|
46
|
+
balancesBefore: import_zod.default.array(balanceEntrySchema),
|
|
47
|
+
balancesAfter: import_zod.default.array(balanceEntrySchema),
|
|
48
|
+
deltas: import_zod.default.array(balanceEntrySchema),
|
|
49
|
+
gasUsed: import_zod.default.string()
|
|
50
|
+
});
|
|
51
|
+
const simulateRevertDecodeResultSchema = import_zod.default.object({
|
|
52
|
+
errorCandidates: import_zod.default.array(
|
|
53
|
+
import_zod.default.object({
|
|
54
|
+
decodedErrorSignature: import_zod.default.string(),
|
|
55
|
+
decodedParams: import_zod.default.array(import_zod.default.string())
|
|
56
|
+
})
|
|
57
|
+
).optional(),
|
|
58
|
+
error: import_zod.default.string().optional()
|
|
59
|
+
});
|
|
60
|
+
const simulateRevertSchema = import_zod.default.object({
|
|
61
|
+
status: import_zod.default.literal("revert"),
|
|
62
|
+
block: import_zod.default.number(),
|
|
63
|
+
timestamp: import_zod.default.number(),
|
|
64
|
+
revertReason: import_zod.default.string().optional(),
|
|
65
|
+
code: import_zod.default.number().optional(),
|
|
66
|
+
rawErrorBytes: import_zod.default.string().optional(),
|
|
67
|
+
decodeResult: simulateRevertDecodeResultSchema.optional()
|
|
68
|
+
});
|
|
69
|
+
const simulateSetupErrorSchema = import_zod.default.object({
|
|
70
|
+
status: import_zod.default.literal("error"),
|
|
71
|
+
message: import_zod.default.string()
|
|
72
|
+
});
|
|
73
|
+
const simulateResultSchema = import_zod.default.discriminatedUnion("status", [
|
|
74
|
+
simulateOkSchema,
|
|
75
|
+
simulateRevertSchema,
|
|
76
|
+
simulateSetupErrorSchema
|
|
77
|
+
]);
|
|
78
|
+
const parseSimulateResult = (body) => {
|
|
79
|
+
const parsed = simulateResultSchema.safeParse(body);
|
|
80
|
+
if (!parsed.success) return null;
|
|
81
|
+
const result = parsed.data;
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
const compilePartialEnvelopeSchema = import_zod.default.object({
|
|
85
|
+
data: import_zod.default.record(import_zod.default.string(), import_zod.default.unknown()),
|
|
86
|
+
error: import_zod.default.object({ kind: import_zod.default.string(), message: import_zod.default.string() })
|
|
87
|
+
});
|
|
88
|
+
const parseCompilePartialEnvelope = (body) => {
|
|
89
|
+
const parsed = compilePartialEnvelopeSchema.safeParse(body);
|
|
90
|
+
return parsed.success ? parsed.data : null;
|
|
91
|
+
};
|
|
92
|
+
const serverErrorBodySchema = import_zod.default.object({
|
|
93
|
+
error: import_zod.default.object({
|
|
94
|
+
kind: import_zod.default.string().optional(),
|
|
95
|
+
message: import_zod.default.string().optional(),
|
|
96
|
+
path: import_zod.default.string().optional(),
|
|
97
|
+
details: import_zod.default.custom().optional()
|
|
98
|
+
}).optional()
|
|
99
|
+
});
|
|
100
|
+
const parseServerErrorBody = (json) => {
|
|
101
|
+
const parsed = serverErrorBodySchema.safeParse(json);
|
|
102
|
+
return parsed.success ? parsed.data : null;
|
|
103
|
+
};
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
parseCompilePartialEnvelope,
|
|
107
|
+
parseServerErrorBody,
|
|
108
|
+
parseSimulateResult
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=responseSchemas.cjs.map
|
|
@@ -0,0 +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 but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, 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/** 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 details?: SimulationRevert;\n };\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`.\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 details: z.custom<SimulationRevert>().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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAc;AAkBd,MAAM,qBAAqB,WAAAA,QAAE,OAAO;AAAA,EAClC,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,QAAQ,WAAAA,QAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,WAAAA,QAAE,OAAO;AAAA,EAChC,QAAQ,WAAAA,QAAE,QAAQ,IAAI;AAAA,EACtB,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,WAAW,WAAAA,QAAE,OAAO;AAAA,EACpB,gBAAgB,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EAC1C,eAAe,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EACzC,QAAQ,WAAAA,QAAE,MAAM,kBAAkB;AAAA,EAClC,SAAS,WAAAA,QAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,WAAAA,QAAE,OAAO;AAAA,EAChD,iBAAiB,WAAAA,QACd;AAAA,IACC,WAAAA,QAAE,OAAO;AAAA,MACP,uBAAuB,WAAAA,QAAE,OAAO;AAAA,MAChC,eAAe,WAAAA,QAAE,MAAM,WAAAA,QAAE,OAAO,CAAC;AAAA,IACnC,CAAC;AAAA,EACH,EACC,SAAS;AAAA,EACZ,OAAO,WAAAA,QAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAED,MAAM,uBAAuB,WAAAA,QAAE,OAAO;AAAA,EACpC,QAAQ,WAAAA,QAAE,QAAQ,QAAQ;AAAA,EAC1B,OAAO,WAAAA,QAAE,OAAO;AAAA,EAChB,WAAW,WAAAA,QAAE,OAAO;AAAA,EACpB,cAAc,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EAClC,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,eAAe,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,EACnC,cAAc,iCAAiC,SAAS;AAC1D,CAAC;AAED,MAAM,2BAA2B,WAAAA,QAAE,OAAO;AAAA,EACxC,QAAQ,WAAAA,QAAE,QAAQ,OAAO;AAAA,EACzB,SAAS,WAAAA,QAAE,OAAO;AACpB,CAAC;AAED,MAAM,uBAAuB,WAAAA,QAAE,mBAAmB,UAAU;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAYM,MAAM,sBAAsB,CAAC,SAAyC;AAC3E,QAAM,SAAS,qBAAqB,UAAU,IAAI;AAClD,MAAI,CAAC,OAAO,QAAS,QAAO;AAM5B,QAAM,SAAyB,OAAO;AACtC,SAAO;AACT;AAaA,MAAM,+BAA+B,WAAAA,QAAE,OAAO;AAAA,EAC5C,MAAM,WAAAA,QAAE,OAAO,WAAAA,QAAE,OAAO,GAAG,WAAAA,QAAE,QAAQ,CAAC;AAAA,EACtC,OAAO,WAAAA,QAAE,OAAO,EAAE,MAAM,WAAAA,QAAE,OAAO,GAAG,SAAS,WAAAA,QAAE,OAAO,EAAE,CAAC;AAC3D,CAAC;AAGM,MAAM,8BAA8B,CACzC,SACkC;AAClC,QAAM,SAAS,6BAA6B,UAAU,IAAI;AAC1D,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAeA,MAAM,wBAAwB,WAAAA,QAAE,OAAO;AAAA,EACrC,OAAO,WAAAA,QACJ,OAAO;AAAA,IACN,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,MAAM,WAAAA,QAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,WAAAA,QAAE,OAAyB,EAAE,SAAS;AAAA,EACjD,CAAC,EACA,SAAS;AACd,CAAC;AAGM,MAAM,uBAAuB,CAAC,SAA0C;AAC7E,QAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;","names":["z"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SimulationRevert, SimulateResult } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
5
|
+
* when the body does not match the `ok`/`revert`/`error` union, letting the
|
|
6
|
+
* caller raise a transport-level error.
|
|
7
|
+
*/
|
|
8
|
+
declare const parseSimulateResult: (body: unknown) => SimulateResult | null;
|
|
9
|
+
/**
|
|
10
|
+
* The validated members of an HTTP 206 partial compile envelope. `data` is
|
|
11
|
+
* verified to be an object but kept untyped — compose-spec owns its full shape
|
|
12
|
+
* (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows
|
|
13
|
+
* it. `error` is fully validated.
|
|
14
|
+
*/
|
|
15
|
+
interface CompilePartialEnvelope {
|
|
16
|
+
readonly data: Record<string, unknown>;
|
|
17
|
+
readonly error: {
|
|
18
|
+
readonly kind: string;
|
|
19
|
+
readonly message: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
|
|
23
|
+
declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
|
|
24
|
+
/** Error envelope returned on non-2xx responses. */
|
|
25
|
+
interface ServerErrorBody {
|
|
26
|
+
readonly error?: {
|
|
27
|
+
readonly kind?: string;
|
|
28
|
+
readonly message?: string;
|
|
29
|
+
readonly path?: string;
|
|
30
|
+
readonly details?: SimulationRevert;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Validates an already-parsed error envelope; `null` when it does not match. */
|
|
34
|
+
declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
|
|
35
|
+
|
|
36
|
+
export { type CompilePartialEnvelope, type ServerErrorBody, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SimulationRevert, SimulateResult } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Parses a `POST /simulate` body into a {@link SimulateResult}. Returns `null`
|
|
5
|
+
* when the body does not match the `ok`/`revert`/`error` union, letting the
|
|
6
|
+
* caller raise a transport-level error.
|
|
7
|
+
*/
|
|
8
|
+
declare const parseSimulateResult: (body: unknown) => SimulateResult | null;
|
|
9
|
+
/**
|
|
10
|
+
* The validated members of an HTTP 206 partial compile envelope. `data` is
|
|
11
|
+
* verified to be an object but kept untyped — compose-spec owns its full shape
|
|
12
|
+
* (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows
|
|
13
|
+
* it. `error` is fully validated.
|
|
14
|
+
*/
|
|
15
|
+
interface CompilePartialEnvelope {
|
|
16
|
+
readonly data: Record<string, unknown>;
|
|
17
|
+
readonly error: {
|
|
18
|
+
readonly kind: string;
|
|
19
|
+
readonly message: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Parses an HTTP 206 partial compile envelope; `null` when it does not match. */
|
|
23
|
+
declare const parseCompilePartialEnvelope: (body: unknown) => CompilePartialEnvelope | null;
|
|
24
|
+
/** Error envelope returned on non-2xx responses. */
|
|
25
|
+
interface ServerErrorBody {
|
|
26
|
+
readonly error?: {
|
|
27
|
+
readonly kind?: string;
|
|
28
|
+
readonly message?: string;
|
|
29
|
+
readonly path?: string;
|
|
30
|
+
readonly details?: SimulationRevert;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Validates an already-parsed error envelope; `null` when it does not match. */
|
|
34
|
+
declare const parseServerErrorBody: (json: unknown) => ServerErrorBody | null;
|
|
35
|
+
|
|
36
|
+
export { type CompilePartialEnvelope, type ServerErrorBody, parseCompilePartialEnvelope, parseServerErrorBody, parseSimulateResult };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
const balanceEntrySchema = z.object({
|
|
3
|
+
token: z.string(),
|
|
4
|
+
owner: z.string(),
|
|
5
|
+
amount: z.string()
|
|
6
|
+
});
|
|
7
|
+
const simulateOkSchema = z.object({
|
|
8
|
+
status: z.literal("ok"),
|
|
9
|
+
block: z.number(),
|
|
10
|
+
timestamp: z.number(),
|
|
11
|
+
balancesBefore: z.array(balanceEntrySchema),
|
|
12
|
+
balancesAfter: z.array(balanceEntrySchema),
|
|
13
|
+
deltas: z.array(balanceEntrySchema),
|
|
14
|
+
gasUsed: z.string()
|
|
15
|
+
});
|
|
16
|
+
const simulateRevertDecodeResultSchema = z.object({
|
|
17
|
+
errorCandidates: z.array(
|
|
18
|
+
z.object({
|
|
19
|
+
decodedErrorSignature: z.string(),
|
|
20
|
+
decodedParams: z.array(z.string())
|
|
21
|
+
})
|
|
22
|
+
).optional(),
|
|
23
|
+
error: z.string().optional()
|
|
24
|
+
});
|
|
25
|
+
const simulateRevertSchema = z.object({
|
|
26
|
+
status: z.literal("revert"),
|
|
27
|
+
block: z.number(),
|
|
28
|
+
timestamp: z.number(),
|
|
29
|
+
revertReason: z.string().optional(),
|
|
30
|
+
code: z.number().optional(),
|
|
31
|
+
rawErrorBytes: z.string().optional(),
|
|
32
|
+
decodeResult: simulateRevertDecodeResultSchema.optional()
|
|
33
|
+
});
|
|
34
|
+
const simulateSetupErrorSchema = z.object({
|
|
35
|
+
status: z.literal("error"),
|
|
36
|
+
message: z.string()
|
|
37
|
+
});
|
|
38
|
+
const simulateResultSchema = z.discriminatedUnion("status", [
|
|
39
|
+
simulateOkSchema,
|
|
40
|
+
simulateRevertSchema,
|
|
41
|
+
simulateSetupErrorSchema
|
|
42
|
+
]);
|
|
43
|
+
const parseSimulateResult = (body) => {
|
|
44
|
+
const parsed = simulateResultSchema.safeParse(body);
|
|
45
|
+
if (!parsed.success) return null;
|
|
46
|
+
const result = parsed.data;
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
const compilePartialEnvelopeSchema = z.object({
|
|
50
|
+
data: z.record(z.string(), z.unknown()),
|
|
51
|
+
error: z.object({ kind: z.string(), message: z.string() })
|
|
52
|
+
});
|
|
53
|
+
const parseCompilePartialEnvelope = (body) => {
|
|
54
|
+
const parsed = compilePartialEnvelopeSchema.safeParse(body);
|
|
55
|
+
return parsed.success ? parsed.data : null;
|
|
56
|
+
};
|
|
57
|
+
const serverErrorBodySchema = z.object({
|
|
58
|
+
error: z.object({
|
|
59
|
+
kind: z.string().optional(),
|
|
60
|
+
message: z.string().optional(),
|
|
61
|
+
path: z.string().optional(),
|
|
62
|
+
details: z.custom().optional()
|
|
63
|
+
}).optional()
|
|
64
|
+
});
|
|
65
|
+
const parseServerErrorBody = (json) => {
|
|
66
|
+
const parsed = serverErrorBodySchema.safeParse(json);
|
|
67
|
+
return parsed.success ? parsed.data : null;
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
parseCompilePartialEnvelope,
|
|
71
|
+
parseServerErrorBody,
|
|
72
|
+
parseSimulateResult
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=responseSchemas.js.map
|
|
@@ -0,0 +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 but kept untyped — compose-spec owns its full shape\n * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows\n * it. `error` is fully validated.\n */\nexport interface CompilePartialEnvelope {\n readonly data: Record<string, 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/** 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 details?: SimulationRevert;\n };\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`.\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 details: z.custom<SimulationRevert>().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":"AACA,OAAO,OAAO;AAkBd,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,OAAO,EAAE,OAAO;AAAA,EAChB,OAAO,EAAE,OAAO;AAAA,EAChB,QAAQ,EAAE,OAAO;AACnB,CAAC;AAED,MAAM,mBAAmB,EAAE,OAAO;AAAA,EAChC,QAAQ,EAAE,QAAQ,IAAI;AAAA,EACtB,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AAAA,EACpB,gBAAgB,EAAE,MAAM,kBAAkB;AAAA,EAC1C,eAAe,EAAE,MAAM,kBAAkB;AAAA,EACzC,QAAQ,EAAE,MAAM,kBAAkB;AAAA,EAClC,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,mCAAmC,EAAE,OAAO;AAAA,EAChD,iBAAiB,EACd;AAAA,IACC,EAAE,OAAO;AAAA,MACP,uBAAuB,EAAE,OAAO;AAAA,MAChC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC;AAAA,IACnC,CAAC;AAAA,EACH,EACC,SAAS;AAAA,EACZ,OAAO,EAAE,OAAO,EAAE,SAAS;AAC7B,CAAC;AAED,MAAM,uBAAuB,EAAE,OAAO;AAAA,EACpC,QAAQ,EAAE,QAAQ,QAAQ;AAAA,EAC1B,OAAO,EAAE,OAAO;AAAA,EAChB,WAAW,EAAE,OAAO;AAAA,EACpB,cAAc,EAAE,OAAO,EAAE,SAAS;AAAA,EAClC,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,eAAe,EAAE,OAAO,EAAE,SAAS;AAAA,EACnC,cAAc,iCAAiC,SAAS;AAC1D,CAAC;AAED,MAAM,2BAA2B,EAAE,OAAO;AAAA,EACxC,QAAQ,EAAE,QAAQ,OAAO;AAAA,EACzB,SAAS,EAAE,OAAO;AACpB,CAAC;AAED,MAAM,uBAAuB,EAAE,mBAAmB,UAAU;AAAA,EAC1D;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAYM,MAAM,sBAAsB,CAAC,SAAyC;AAC3E,QAAM,SAAS,qBAAqB,UAAU,IAAI;AAClD,MAAI,CAAC,OAAO,QAAS,QAAO;AAM5B,QAAM,SAAyB,OAAO;AACtC,SAAO;AACT;AAaA,MAAM,+BAA+B,EAAE,OAAO;AAAA,EAC5C,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;AAAA,EACtC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,CAAC;AAC3D,CAAC;AAGM,MAAM,8BAA8B,CACzC,SACkC;AAClC,QAAM,SAAS,6BAA6B,UAAU,IAAI;AAC1D,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAeA,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,OAAO,EACJ,OAAO;AAAA,IACN,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,IAC7B,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,IAC1B,SAAS,EAAE,OAAyB,EAAE,SAAS;AAAA,EACjD,CAAC,EACA,SAAS;AACd,CAAC;AAGM,MAAM,uBAAuB,CAAC,SAA0C;AAC7E,QAAM,SAAS,sBAAsB,UAAU,IAAI;AACnD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;","names":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[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 simulate_exports = {};
|
|
20
|
+
__export(simulate_exports, {
|
|
21
|
+
buildSimulateRequest: () => buildSimulateRequest
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(simulate_exports);
|
|
24
|
+
const buildSimulateRequest = (input) => {
|
|
25
|
+
const { result, chainId, signer, trackedBalances, requirements, block } = input;
|
|
26
|
+
return {
|
|
27
|
+
chainId,
|
|
28
|
+
from: signer,
|
|
29
|
+
to: result.transactionRequest.to,
|
|
30
|
+
data: result.transactionRequest.data,
|
|
31
|
+
value: input.value ?? result.transactionRequest.value,
|
|
32
|
+
block,
|
|
33
|
+
requirements,
|
|
34
|
+
trackedBalances
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
buildSimulateRequest
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=simulate.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results carry a `transactionRequest`, so either is\n * valid input — the helper does not discriminate on `status`.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8DO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AACF,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRequest } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Input for {@link buildSimulateRequest}: a compile result plus the fields a
|
|
5
|
+
* simulation needs that a compiled flow does not carry.
|
|
6
|
+
*/
|
|
7
|
+
interface BuildSimulateRequestInput {
|
|
8
|
+
/**
|
|
9
|
+
* A result from `builder.compile(...)` / `client.compile(...)`. Both
|
|
10
|
+
* `success` and `partial` results carry a `transactionRequest`, so either is
|
|
11
|
+
* valid input — the helper does not discriminate on `status`.
|
|
12
|
+
*/
|
|
13
|
+
readonly result: ComposeCompileResult;
|
|
14
|
+
/** EVM chain id. A compile result does not carry the target chain. */
|
|
15
|
+
readonly chainId: number;
|
|
16
|
+
/**
|
|
17
|
+
* The transaction sender (`from`). A compile result does not carry the
|
|
18
|
+
* signer, so it must be supplied here.
|
|
19
|
+
*/
|
|
20
|
+
readonly signer: string;
|
|
21
|
+
/**
|
|
22
|
+
* Balances to watch across the simulation. These cannot be inferred from a
|
|
23
|
+
* flow and must be supplied by the caller.
|
|
24
|
+
*/
|
|
25
|
+
readonly trackedBalances: readonly TrackedBalance[];
|
|
26
|
+
/** Optional funding instructions applied before simulation. */
|
|
27
|
+
readonly requirements?: readonly SlotFinderRequirement[];
|
|
28
|
+
/** Optional block to pin the simulation to. Omitted ⇒ chain head. */
|
|
29
|
+
readonly block?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Optional native value override. Defaults to the compiled
|
|
32
|
+
* `transactionRequest.value` when omitted.
|
|
33
|
+
*/
|
|
34
|
+
readonly value?: bigint | string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Assembles a {@link SimulateRequest} from a compile result and the
|
|
38
|
+
* caller-supplied chain, signer, and tracked balances. Pure: performs no
|
|
39
|
+
* network I/O, does not mutate its input, and returns a fresh object.
|
|
40
|
+
*
|
|
41
|
+
* Bridges the common case — simulate the transaction you just compiled —
|
|
42
|
+
* without coupling raw-transaction simulation to the flow builder. The
|
|
43
|
+
* `value` defaults to the compiled transaction's value unless overridden.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });
|
|
48
|
+
* const req = buildSimulateRequest({
|
|
49
|
+
* result: compiled,
|
|
50
|
+
* chainId: 1,
|
|
51
|
+
* signer: '0x1111111111111111111111111111111111111111',
|
|
52
|
+
* trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],
|
|
53
|
+
* });
|
|
54
|
+
* const sim = await sdk.client.simulate(req);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
|
|
58
|
+
|
|
59
|
+
export { type BuildSimulateRequestInput, buildSimulateRequest };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ComposeCompileResult, TrackedBalance, SlotFinderRequirement, SimulateRequest } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Input for {@link buildSimulateRequest}: a compile result plus the fields a
|
|
5
|
+
* simulation needs that a compiled flow does not carry.
|
|
6
|
+
*/
|
|
7
|
+
interface BuildSimulateRequestInput {
|
|
8
|
+
/**
|
|
9
|
+
* A result from `builder.compile(...)` / `client.compile(...)`. Both
|
|
10
|
+
* `success` and `partial` results carry a `transactionRequest`, so either is
|
|
11
|
+
* valid input — the helper does not discriminate on `status`.
|
|
12
|
+
*/
|
|
13
|
+
readonly result: ComposeCompileResult;
|
|
14
|
+
/** EVM chain id. A compile result does not carry the target chain. */
|
|
15
|
+
readonly chainId: number;
|
|
16
|
+
/**
|
|
17
|
+
* The transaction sender (`from`). A compile result does not carry the
|
|
18
|
+
* signer, so it must be supplied here.
|
|
19
|
+
*/
|
|
20
|
+
readonly signer: string;
|
|
21
|
+
/**
|
|
22
|
+
* Balances to watch across the simulation. These cannot be inferred from a
|
|
23
|
+
* flow and must be supplied by the caller.
|
|
24
|
+
*/
|
|
25
|
+
readonly trackedBalances: readonly TrackedBalance[];
|
|
26
|
+
/** Optional funding instructions applied before simulation. */
|
|
27
|
+
readonly requirements?: readonly SlotFinderRequirement[];
|
|
28
|
+
/** Optional block to pin the simulation to. Omitted ⇒ chain head. */
|
|
29
|
+
readonly block?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Optional native value override. Defaults to the compiled
|
|
32
|
+
* `transactionRequest.value` when omitted.
|
|
33
|
+
*/
|
|
34
|
+
readonly value?: bigint | string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Assembles a {@link SimulateRequest} from a compile result and the
|
|
38
|
+
* caller-supplied chain, signer, and tracked balances. Pure: performs no
|
|
39
|
+
* network I/O, does not mutate its input, and returns a fresh object.
|
|
40
|
+
*
|
|
41
|
+
* Bridges the common case — simulate the transaction you just compiled —
|
|
42
|
+
* without coupling raw-transaction simulation to the flow builder. The
|
|
43
|
+
* `value` defaults to the compiled transaction's value unless overridden.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });
|
|
48
|
+
* const req = buildSimulateRequest({
|
|
49
|
+
* result: compiled,
|
|
50
|
+
* chainId: 1,
|
|
51
|
+
* signer: '0x1111111111111111111111111111111111111111',
|
|
52
|
+
* trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],
|
|
53
|
+
* });
|
|
54
|
+
* const sim = await sdk.client.simulate(req);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare const buildSimulateRequest: (input: BuildSimulateRequestInput) => SimulateRequest;
|
|
58
|
+
|
|
59
|
+
export { type BuildSimulateRequestInput, buildSimulateRequest };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const buildSimulateRequest = (input) => {
|
|
2
|
+
const { result, chainId, signer, trackedBalances, requirements, block } = input;
|
|
3
|
+
return {
|
|
4
|
+
chainId,
|
|
5
|
+
from: signer,
|
|
6
|
+
to: result.transactionRequest.to,
|
|
7
|
+
data: result.transactionRequest.data,
|
|
8
|
+
value: input.value ?? result.transactionRequest.value,
|
|
9
|
+
block,
|
|
10
|
+
requirements,
|
|
11
|
+
trackedBalances
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
buildSimulateRequest
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=simulate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/run/simulate.ts"],"sourcesContent":["import type {\n ComposeCompileResult,\n SimulateRequest,\n SlotFinderRequirement,\n TrackedBalance,\n} from '@lifi/compose-spec';\n\n/**\n * Input for {@link buildSimulateRequest}: a compile result plus the fields a\n * simulation needs that a compiled flow does not carry.\n */\nexport interface BuildSimulateRequestInput {\n /**\n * A result from `builder.compile(...)` / `client.compile(...)`. Both\n * `success` and `partial` results carry a `transactionRequest`, so either is\n * valid input — the helper does not discriminate on `status`.\n */\n readonly result: ComposeCompileResult;\n /** EVM chain id. A compile result does not carry the target chain. */\n readonly chainId: number;\n /**\n * The transaction sender (`from`). A compile result does not carry the\n * signer, so it must be supplied here.\n */\n readonly signer: string;\n /**\n * Balances to watch across the simulation. These cannot be inferred from a\n * flow and must be supplied by the caller.\n */\n readonly trackedBalances: readonly TrackedBalance[];\n /** Optional funding instructions applied before simulation. */\n readonly requirements?: readonly SlotFinderRequirement[];\n /** Optional block to pin the simulation to. Omitted ⇒ chain head. */\n readonly block?: number;\n /**\n * Optional native value override. Defaults to the compiled\n * `transactionRequest.value` when omitted.\n */\n readonly value?: bigint | string;\n}\n\n/**\n * Assembles a {@link SimulateRequest} from a compile result and the\n * caller-supplied chain, signer, and tracked balances. Pure: performs no\n * network I/O, does not mutate its input, and returns a fresh object.\n *\n * Bridges the common case — simulate the transaction you just compiled —\n * without coupling raw-transaction simulation to the flow builder. The\n * `value` defaults to the compiled transaction's value unless overridden.\n *\n * @example\n * ```ts\n * const compiled = await builder.compile({ inputs: { ... }, signer: '0x1111...' });\n * const req = buildSimulateRequest({\n * result: compiled,\n * chainId: 1,\n * signer: '0x1111111111111111111111111111111111111111',\n * trackedBalances: [{ token: '0xA0b8...', owner: '0x1111...' }],\n * });\n * const sim = await sdk.client.simulate(req);\n * ```\n */\nexport const buildSimulateRequest = (\n input: BuildSimulateRequestInput,\n): SimulateRequest => {\n const { result, chainId, signer, trackedBalances, requirements, block } =\n input;\n return {\n chainId,\n from: signer,\n to: result.transactionRequest.to,\n data: result.transactionRequest.data,\n value: input.value ?? result.transactionRequest.value,\n block,\n requirements,\n trackedBalances,\n };\n};\n"],"mappings":"AA8DO,MAAM,uBAAuB,CAClC,UACoB;AACpB,QAAM,EAAE,QAAQ,SAAS,QAAQ,iBAAiB,cAAc,MAAM,IACpE;AACF,SAAO;AAAA,IACL;AAAA,IACA,MAAM;AAAA,IACN,IAAI,OAAO,mBAAmB;AAAA,IAC9B,MAAM,OAAO,mBAAmB;AAAA,IAChC,OAAO,MAAM,SAAS,OAAO,mBAAmB;AAAA,IAChD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
package/dist/sdk.cjs
CHANGED
|
@@ -52,7 +52,12 @@ const createComposeSdk = (options) => {
|
|
|
52
52
|
};
|
|
53
53
|
return Object.assign(builder, { compile });
|
|
54
54
|
};
|
|
55
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
client: composeClient,
|
|
57
|
+
flow,
|
|
58
|
+
request,
|
|
59
|
+
simulate: composeClient.simulate
|
|
60
|
+
};
|
|
56
61
|
};
|
|
57
62
|
// Annotate the CommonJS export names for ESM import in node:
|
|
58
63
|
0 && (module.exports = {
|
package/dist/sdk.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /**
|
|
1
|
+
{"version":3,"sources":["../src/sdk.ts"],"sourcesContent":["import type {\n ComposeCompileRequest,\n ComposeCompileResult,\n InputSpec,\n SimulateRequest,\n SimulateResult,\n} from '@lifi/compose-spec';\n\nimport {\n createFlowBuilderCore,\n type FlowBuilderCore,\n type FlowOptions,\n type TypedFlow,\n} from './authoring/FlowBuilderCore.js';\nimport { type ComposeClient, createComposeClient } from './client.js';\nimport {\n bindGeneratedOps,\n type GeneratedOps,\n} from './generated/operations.generated.js';\nimport { buildRun, type ComposeRunInput } from './run/inputs.js';\nimport type { InputSchema } from './types.js';\n\nexport type { ComposeRunInput };\n\n/**\n * A flow builder augmented with generated operation methods and a `compile` method\n * that submits the flow to the Compose backend for compilation.\n *\n * Created via {@link ComposeSdk.flow}.\n *\n * @typeParam T - The input schema describing the flow's required inputs.\n */\nexport type FlowBuilder<T extends InputSchema = InputSchema> =\n FlowBuilderCore<T> &\n GeneratedOps & {\n /**\n * Builds the flow document from the current builder state and submits it\n * to the Compose API for compilation.\n *\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns The compiled transaction calldata and metadata.\n * @throws {@link ComposeError} on network, validation, or server errors.\n *\n * @example\n * ```ts\n * const result = await builder.compile({\n * inputs: { token: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * console.log(result.calldata);\n * ```\n */\n readonly compile: (\n run: ComposeRunInput<T>,\n ) => Promise<ComposeCompileResult>;\n };\n\n/**\n * Configuration for creating a Compose SDK instance.\n */\nexport interface ComposeSdkOptions {\n /** Base URL of the Compose API (e.g. `\"https://li.quest\"`). */\n readonly baseUrl: string;\n /** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */\n readonly fetch?: typeof globalThis.fetch;\n /** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */\n readonly apiKey: string;\n}\n\n/**\n * The top-level Compose SDK interface.\n *\n * Provides methods to build flows, compile them into executable calldata, and\n * interact with the Compose API directly.\n *\n * @example\n * ```ts\n * import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';\n *\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n *\n * const builder = sdk.flow(1, {\n * inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },\n * });\n *\n * builder.lifi.swap('swap1', {\n * bind: { amountIn: builder.inputs.usdc },\n * config: { resourceOut: resources.native(1) },\n * });\n *\n * const result = await builder.compile({\n * inputs: { usdc: materialisers.balanceOf({}) },\n * signer: '0xYourAddress...',\n * });\n * ```\n */\nexport interface ComposeSdk {\n /** Low-level HTTP client for the Compose API. */\n readonly client: ComposeClient;\n /**\n * Creates a new flow builder targeting the given chain.\n * @param chainId - The EVM chain ID (e.g. `1` for Ethereum mainnet).\n * @param options - Flow configuration including input declarations.\n * @returns A {@link FlowBuilder} with generated operation methods and a `compile` method.\n * @throws Error if any resource input's `chainId` doesn't match the flow's `chainId`.\n */\n readonly flow: <T extends InputSchema>(\n chainId: number,\n options: FlowOptions<T>,\n ) => FlowBuilder<T>;\n /**\n * Builds a raw compile request without sending it. Useful for inspecting the\n * request payload or submitting it through a custom transport.\n * @param flow - A built flow document (from `builder.build()`).\n * @param run - Runtime inputs, preconditions, and signer address.\n * @returns A {@link ComposeCompileRequest} ready to send to the Compose API.\n */\n readonly request: <T extends InputSchema>(\n flow: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ) => ComposeCompileRequest;\n /**\n * Simulates a raw, pre-encoded transaction. Thin pass-through to\n * {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`\n * result discrimination and error behaviour. Pair with `buildSimulateRequest`\n * to assemble the request from a compile result.\n *\n * @param request - The raw transaction plus funding `requirements` and\n * `trackedBalances`.\n * @returns A {@link SimulateResult} (`ok` / `revert` / `error`).\n * @throws {@link ComposeError} on network, validation, or server errors.\n */\n readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;\n}\n\n/**\n * Creates a new Compose SDK instance.\n *\n * @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.\n * @returns A {@link ComposeSdk} instance.\n *\n * @example\n * ```ts\n * const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });\n * ```\n */\nexport const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {\n const composeClient = createComposeClient(options);\n\n const request = <T extends InputSchema>(\n flowDoc: TypedFlow<T>,\n run: ComposeRunInput<T>,\n ): ComposeCompileRequest => ({\n flow: flowDoc,\n run: buildRun({\n inputs: run.inputs as Record<string, InputSpec>,\n preconditions: run.preconditions,\n signer: run.signer,\n assumptions: run.assumptions as Record<string, bigint> | undefined,\n referrer: run.referrer,\n integratorFeeBps: run.integratorFeeBps,\n maxPriceImpactBps: run.maxPriceImpactBps,\n sweepTo: run.sweepTo,\n simulationPolicy: run.simulationPolicy,\n checkOnChainAllowances: run.checkOnChainAllowances,\n }),\n });\n\n const flow = <T extends InputSchema>(\n chainId: number,\n opts: FlowOptions<T>,\n ): FlowBuilder<T> => {\n const core = createFlowBuilderCore(chainId, opts);\n const builder = Object.assign(core, bindGeneratedOps(core));\n\n const compile = async (\n run: ComposeRunInput<T>,\n ): Promise<ComposeCompileResult> => {\n const flowDoc = builder.build();\n const req = request(flowDoc, run);\n return composeClient.compile(req);\n };\n\n return Object.assign(builder, { compile });\n };\n\n return {\n client: composeClient,\n flow,\n request,\n simulate: composeClient.simulate,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,6BAKO;AACP,oBAAwD;AACxD,kCAGO;AACP,oBAA+C;AA+HxC,MAAM,mBAAmB,CAAC,YAA2C;AAC1E,QAAM,oBAAgB,mCAAoB,OAAO;AAEjD,QAAM,UAAU,CACd,SACA,SAC2B;AAAA,IAC3B,MAAM;AAAA,IACN,SAAK,wBAAS;AAAA,MACZ,QAAQ,IAAI;AAAA,MACZ,eAAe,IAAI;AAAA,MACnB,QAAQ,IAAI;AAAA,MACZ,aAAa,IAAI;AAAA,MACjB,UAAU,IAAI;AAAA,MACd,kBAAkB,IAAI;AAAA,MACtB,mBAAmB,IAAI;AAAA,MACvB,SAAS,IAAI;AAAA,MACb,kBAAkB,IAAI;AAAA,MACtB,wBAAwB,IAAI;AAAA,IAC9B,CAAC;AAAA,EACH;AAEA,QAAM,OAAO,CACX,SACA,SACmB;AACnB,UAAM,WAAO,8CAAsB,SAAS,IAAI;AAChD,UAAM,UAAU,OAAO,OAAO,UAAM,8CAAiB,IAAI,CAAC;AAE1D,UAAM,UAAU,OACd,QACkC;AAClC,YAAM,UAAU,QAAQ,MAAM;AAC9B,YAAM,MAAM,QAAQ,SAAS,GAAG;AAChC,aAAO,cAAc,QAAQ,GAAG;AAAA,IAClC;AAEA,WAAO,OAAO,OAAO,SAAS,EAAE,QAAQ,CAAC;AAAA,EAC3C;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,UAAU,cAAc;AAAA,EAC1B;AACF;","names":[]}
|
package/dist/sdk.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComposeCompileResult, ComposeCompileRequest } from '@lifi/compose-spec';
|
|
1
|
+
import { ComposeCompileResult, ComposeCompileRequest, SimulateRequest, SimulateResult } from '@lifi/compose-spec';
|
|
2
2
|
import { FlowOptions, FlowBuilderCore, TypedFlow } from './authoring/FlowBuilderCore.cjs';
|
|
3
3
|
import { ComposeClient } from './client.cjs';
|
|
4
4
|
import { GeneratedOps } from './generated/operations.generated.cjs';
|
|
@@ -46,8 +46,8 @@ interface ComposeSdkOptions {
|
|
|
46
46
|
readonly baseUrl: string;
|
|
47
47
|
/** Optional custom `fetch` implementation. Defaults to `globalThis.fetch`. */
|
|
48
48
|
readonly fetch?: typeof globalThis.fetch;
|
|
49
|
-
/**
|
|
50
|
-
readonly apiKey
|
|
49
|
+
/** LI.FI API key, sent as the `x-lifi-api-key` header on every request. Required — the Compose API rejects unauthenticated requests. */
|
|
50
|
+
readonly apiKey: string;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
53
|
* The top-level Compose SDK interface.
|
|
@@ -59,7 +59,7 @@ interface ComposeSdkOptions {
|
|
|
59
59
|
* ```ts
|
|
60
60
|
* import { createComposeSdk, resources, materialisers } from '@lifi/composer-sdk';
|
|
61
61
|
*
|
|
62
|
-
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
62
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
|
|
63
63
|
*
|
|
64
64
|
* const builder = sdk.flow(1, {
|
|
65
65
|
* inputs: { usdc: resources.erc20('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 1) },
|
|
@@ -95,16 +95,28 @@ interface ComposeSdk {
|
|
|
95
95
|
* @returns A {@link ComposeCompileRequest} ready to send to the Compose API.
|
|
96
96
|
*/
|
|
97
97
|
readonly request: <T extends InputSchema>(flow: TypedFlow<T>, run: ComposeRunInput<T>) => ComposeCompileRequest;
|
|
98
|
+
/**
|
|
99
|
+
* Simulates a raw, pre-encoded transaction. Thin pass-through to
|
|
100
|
+
* {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
|
|
101
|
+
* result discrimination and error behaviour. Pair with `buildSimulateRequest`
|
|
102
|
+
* to assemble the request from a compile result.
|
|
103
|
+
*
|
|
104
|
+
* @param request - The raw transaction plus funding `requirements` and
|
|
105
|
+
* `trackedBalances`.
|
|
106
|
+
* @returns A {@link SimulateResult} (`ok` / `revert` / `error`).
|
|
107
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
108
|
+
*/
|
|
109
|
+
readonly simulate: (request: SimulateRequest) => Promise<SimulateResult>;
|
|
98
110
|
}
|
|
99
111
|
/**
|
|
100
112
|
* Creates a new Compose SDK instance.
|
|
101
113
|
*
|
|
102
|
-
* @param options - SDK configuration including the API base URL and optional fetch implementation.
|
|
114
|
+
* @param options - SDK configuration including the API base URL, required API key, and optional fetch implementation.
|
|
103
115
|
* @returns A {@link ComposeSdk} instance.
|
|
104
116
|
*
|
|
105
117
|
* @example
|
|
106
118
|
* ```ts
|
|
107
|
-
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest' });
|
|
119
|
+
* const sdk = createComposeSdk({ baseUrl: 'https://li.quest', apiKey: 'YOUR_API_KEY' });
|
|
108
120
|
* ```
|
|
109
121
|
*/
|
|
110
122
|
declare const createComposeSdk: (options: ComposeSdkOptions) => ComposeSdk;
|