@lifi/composer-sdk 0.5.1 → 0.6.1

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.
Files changed (62) hide show
  1. package/README.md +13 -3
  2. package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
  3. package/dist/authoring/FlowBuilderCore.d.cts +11 -4
  4. package/dist/authoring/FlowBuilderCore.d.ts +11 -4
  5. package/dist/authoring/FlowBuilderCore.js.map +1 -1
  6. package/dist/authoring/handles.cjs.map +1 -1
  7. package/dist/authoring/handles.d.cts +2 -2
  8. package/dist/authoring/handles.d.ts +2 -2
  9. package/dist/authoring/handles.js.map +1 -1
  10. package/dist/authoring/raw.cjs +5 -3
  11. package/dist/authoring/raw.cjs.map +1 -1
  12. package/dist/authoring/raw.js +5 -3
  13. package/dist/authoring/raw.js.map +1 -1
  14. package/dist/client.cjs +41 -30
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.cts +3 -3
  17. package/dist/client.d.ts +3 -3
  18. package/dist/client.js +41 -30
  19. package/dist/client.js.map +1 -1
  20. package/dist/generated/config.generated.cjs.map +1 -1
  21. package/dist/generated/config.generated.d.cts +46 -5
  22. package/dist/generated/config.generated.d.ts +46 -5
  23. package/dist/generated/operations.generated.cjs +4 -0
  24. package/dist/generated/operations.generated.cjs.map +1 -1
  25. package/dist/generated/operations.generated.d.cts +16 -2
  26. package/dist/generated/operations.generated.d.ts +16 -2
  27. package/dist/generated/operations.generated.js +4 -0
  28. package/dist/generated/operations.generated.js.map +1 -1
  29. package/dist/index.cjs +4 -1
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +3 -2
  32. package/dist/index.d.ts +3 -2
  33. package/dist/index.js +3 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/outputs.cjs +33 -0
  36. package/dist/outputs.cjs.map +1 -0
  37. package/dist/outputs.d.cts +10 -0
  38. package/dist/outputs.d.ts +10 -0
  39. package/dist/outputs.js +9 -0
  40. package/dist/outputs.js.map +1 -0
  41. package/dist/responseSchemas.cjs.map +1 -1
  42. package/dist/responseSchemas.d.cts +4 -4
  43. package/dist/responseSchemas.d.ts +4 -4
  44. package/dist/responseSchemas.js.map +1 -1
  45. package/dist/types.cjs.map +1 -1
  46. package/dist/types.d.cts +16 -5
  47. package/dist/types.d.ts +16 -5
  48. package/package.json +4 -3
  49. package/src/authoring/FlowBuilderCore.ts +12 -3
  50. package/src/authoring/handles.ts +2 -1
  51. package/src/authoring/raw.ts +4 -3
  52. package/src/client.ts +77 -45
  53. package/src/examples/flySwap.ts +3 -3
  54. package/src/examples/lifiZapAsync.ts +8 -7
  55. package/src/examples/swapAndZap.ts +7 -0
  56. package/src/examples/swapWithAllowRevert.ts +13 -3
  57. package/src/generated/config.generated.ts +49 -4
  58. package/src/generated/operations.generated.ts +25 -0
  59. package/src/index.ts +13 -2
  60. package/src/outputs.ts +16 -0
  61. package/src/responseSchemas.ts +4 -4
  62. package/src/types.ts +16 -4
@@ -44,6 +44,7 @@ import type {
44
44
  InvariantNeqConfig,
45
45
  InvariantNumericConfig,
46
46
  InvariantNumericInRangeConfig,
47
+ LifiBridgeConfig,
47
48
  LifiSwapConfig,
48
49
  LifiZapAsyncConfig,
49
50
  LifiZapConfig,
@@ -79,6 +80,15 @@ export interface LifiSwapArgs {
79
80
  readonly guards?: readonly TypedGuard<'unspentIn'>[];
80
81
  }
81
82
 
83
+ /** Bridge tokens to another chain via the LI.FI aggregator API */
84
+ export interface LifiBridgeArgs {
85
+ readonly bind: {
86
+ readonly amountIn: Bindable<'resource'>;
87
+ };
88
+ readonly config: LifiBridgeConfig;
89
+ readonly guards?: readonly TypedGuard<'unspentIn'>[];
90
+ }
91
+
82
92
  /** Assert that an account holds at least a minimum token balance */
83
93
  export interface InvariantBalanceAtLeastArgs {
84
94
  readonly bind: {
@@ -574,6 +584,11 @@ export interface LifiSwapOutputs {
574
584
  readonly unspentIn: OutputHandle<'resource'>;
575
585
  }
576
586
 
587
+ export interface LifiBridgeOutputs {
588
+ readonly amountOut: OutputHandle<'resource'>;
589
+ readonly unspentIn: OutputHandle<'resource'>;
590
+ }
591
+
577
592
  export interface CoreAddOutputs {
578
593
  readonly result: OutputHandle<'uint256'>;
579
594
  }
@@ -767,6 +782,11 @@ export type GeneratedOps = {
767
782
  readonly lifi: {
768
783
  /** Swap tokens via the LI.FI aggregator API — original id: "lifi.swap" */
769
784
  readonly swap: (nodeId: string, args: LifiSwapArgs) => LifiSwapOutputs;
785
+ /** Bridge tokens to another chain via the LI.FI aggregator API — original id: "lifi.bridge" */
786
+ readonly bridge: (
787
+ nodeId: string,
788
+ args: LifiBridgeArgs,
789
+ ) => LifiBridgeOutputs;
770
790
  /** Route tokens into a DeFi protocol position via the edge catalog — original id: "lifi.zap" */
771
791
  readonly zap: (nodeId: string, args: LifiZapArgs) => LifiZapOutputs;
772
792
  /** Route tokens into a DeFi protocol position whose output becomes available after the initiating transaction settles — original id: "lifi.zapAsync" */
@@ -993,6 +1013,11 @@ export const bindGeneratedOps = (
993
1013
  amountOut: 'resource',
994
1014
  unspentIn: 'resource',
995
1015
  } as const),
1016
+ bridge: (nodeId: string, args: LifiBridgeArgs) =>
1017
+ builder.call(nodeId, 'lifi.bridge', args, {
1018
+ amountOut: 'resource',
1019
+ unspentIn: 'resource',
1020
+ } as const),
996
1021
  zap: (nodeId: string, args: LifiZapArgs) =>
997
1022
  builder.call(nodeId, 'lifi.zap', args, {
998
1023
  amountOut: 'resource',
package/src/index.ts CHANGED
@@ -55,16 +55,25 @@ export type {
55
55
  InputSpec,
56
56
  MaterialiserConfigOf,
57
57
  MaterialiserInput,
58
+ OutputAmount,
59
+ Amount,
60
+ ConsumedOutput,
61
+ Delivery,
62
+ Estimate,
63
+ EstimateBasis,
64
+ Minimum,
65
+ MinimumBasis,
66
+ Output,
67
+ Outputs,
68
+ TerminalOutput,
58
69
  Precondition,
59
70
  PreconditionConfigOf,
60
71
  PriceImpact,
61
- ProducedResource,
62
72
  Ref,
63
73
  Resource,
64
74
  RouteAmount,
65
75
  RouteAmountAll,
66
76
  RouteAmountExact,
67
- SimulatedAmounts,
68
77
  SimulationPolicy,
69
78
  SimulationRevert,
70
79
  SolType,
@@ -120,6 +129,8 @@ export { materialiser } from './run/inputs.js';
120
129
  export { buildSimulateRequest } from './run/simulate.js';
121
130
  export type { BuildSimulateRequestInput } from './run/simulate.js';
122
131
 
132
+ export { terminalOutputs } from './outputs.js';
133
+
123
134
  export { createComposeSdk } from './sdk.js';
124
135
  export type { ComposeSdk, ComposeSdkOptions, FlowBuilder } from './sdk.js';
125
136
 
package/src/outputs.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { Outputs, TerminalOutput } from '@lifi/compose-spec';
2
+
3
+ /**
4
+ * The entries of `outputs` the caller actually receives: every port no later
5
+ * node spends, keyed `<nodeId>.<portName>` as on the wire. Consumed ports
6
+ * (intermediate amounts a later op takes as input) are dropped.
7
+ */
8
+ export const terminalOutputs = (
9
+ outputs: Outputs,
10
+ ): Record<string, TerminalOutput> =>
11
+ Object.fromEntries(
12
+ Object.entries(outputs).filter(
13
+ (entry): entry is [string, TerminalOutput] =>
14
+ entry[1].role === 'terminal',
15
+ ),
16
+ );
@@ -90,12 +90,12 @@ export const parseSimulateResult = (body: unknown): SimulateResult | null => {
90
90
 
91
91
  /**
92
92
  * The validated members of an HTTP 206 partial compile envelope. `data` is
93
- * verified to be an object but kept untyped — compose-spec owns its full shape
94
- * (`ComposeCompilePartialData`) as a hand-authored type, so the caller narrows
95
- * it. `error` is fully validated.
93
+ * verified to be an object at runtime but left `unknown` here — compose-spec
94
+ * owns its full shape (`ComposeCompilePartialData`) as a hand-authored type, so
95
+ * the caller narrows it in one step. `error` is fully validated.
96
96
  */
97
97
  export interface CompilePartialEnvelope {
98
- readonly data: Record<string, unknown>;
98
+ readonly data: unknown;
99
99
  readonly error: { readonly kind: string; readonly message: string };
100
100
  }
101
101
 
package/src/types.ts CHANGED
@@ -48,14 +48,26 @@ export type AbiTypeToOutputKind<T extends string> = T extends SolType
48
48
  ? T
49
49
  : SolType;
50
50
 
51
+ /**
52
+ * Phantom brand key for {@link TypedRef}.
53
+ *
54
+ * Declared, never assigned: it exists only so the type checker can tell a
55
+ * typed ref from an arbitrary `{ $ref }` object. Keying it on a `unique
56
+ * symbol` means no caller can produce one by writing an object literal.
57
+ */
58
+ export declare const typedRefKind: unique symbol;
59
+
51
60
  /**
52
61
  * A typed `$ref` pointer carrying a phantom type parameter.
53
- * Extends `Ref` so it is accepted anywhere a plain `Ref` is.
54
- * The `__outputKind` field is never set at runtime — it exists only
55
- * for TypeScript's structural type checker to distinguish typed refs.
62
+ *
63
+ * On the wire, and at run time, this is exactly `{ $ref: string }` — the
64
+ * brand is erased. The brand is *required* in the type so a plain `Ref` does
65
+ * not satisfy `TypedRef` structurally, which is the contract `RefBindable`
66
+ * advertises: an untyped `{ $ref }` never enters a typed bind slot. Build one
67
+ * with `raw.ref<T>()`.
56
68
  */
57
69
  export interface TypedRef<T extends OutputKind = OutputKind> extends Ref {
58
- readonly __outputKind?: T;
70
+ readonly [typedRefKind]: T;
59
71
  }
60
72
 
61
73
  /**