@lifi/composer-sdk 0.6.3 → 0.7.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 (38) hide show
  1. package/README.md +4 -0
  2. package/dist/authoring/FlowBuilderCore.cjs +17 -4
  3. package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
  4. package/dist/authoring/FlowBuilderCore.d.cts +12 -4
  5. package/dist/authoring/FlowBuilderCore.d.ts +12 -4
  6. package/dist/authoring/FlowBuilderCore.js +20 -4
  7. package/dist/authoring/FlowBuilderCore.js.map +1 -1
  8. package/dist/authoring/handles.cjs.map +1 -1
  9. package/dist/authoring/handles.d.cts +35 -1
  10. package/dist/authoring/handles.d.ts +35 -1
  11. package/dist/authoring/handles.js.map +1 -1
  12. package/dist/client.cjs +1 -1
  13. package/dist/client.js +1 -1
  14. package/dist/generated/config.generated.cjs.map +1 -1
  15. package/dist/generated/config.generated.d.cts +500 -6
  16. package/dist/generated/config.generated.d.ts +500 -6
  17. package/dist/generated/operations.generated.cjs +36 -1
  18. package/dist/generated/operations.generated.cjs.map +1 -1
  19. package/dist/generated/operations.generated.d.cts +101 -5
  20. package/dist/generated/operations.generated.d.ts +101 -5
  21. package/dist/generated/operations.generated.js +36 -1
  22. package/dist/generated/operations.generated.js.map +1 -1
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +3 -3
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js.map +1 -1
  27. package/package.json +3 -3
  28. package/src/authoring/FlowBuilderCore.ts +59 -19
  29. package/src/authoring/handles.ts +67 -0
  30. package/src/examples/aaveBorrow.ts +129 -0
  31. package/src/examples/aaveHealthFactorExplode.ts +63 -0
  32. package/src/examples/morphoBlueBorrow.ts +94 -0
  33. package/src/examples/morphoBlueRepay.ts +133 -0
  34. package/src/examples/run.ts +30 -0
  35. package/src/examples/splitAndZap.ts +9 -8
  36. package/src/generated/config.generated.ts +516 -5
  37. package/src/generated/operations.generated.ts +211 -3
  38. package/src/index.ts +5 -1
@@ -2,7 +2,13 @@
2
2
  // Regenerate with: yarn workspace @lifi/composer-sdk generate
3
3
 
4
4
  import type { FlowBuilderInternal } from '../authoring/FlowBuilderCore.js';
5
- import type { Bindable, OutputHandle } from '../authoring/handles.js';
5
+ import type {
6
+ Bindable,
7
+ FamilyCount,
8
+ FamilySource,
9
+ OutputFamilyHandles,
10
+ OutputHandle,
11
+ } from '../authoring/handles.js';
6
12
  import type {
7
13
  CoreCallResult,
8
14
  SignatureBind,
@@ -17,6 +23,7 @@ import type { TypedGuard } from '../types.js';
17
23
  import type {
18
24
  AaveBorrowConfig,
19
25
  AaveClaimRewardsConfig,
26
+ AaveGetHealthFactorConfig,
20
27
  AaveRepayConfig,
21
28
  AaveRepayWithATokensConfig,
22
29
  AaveSetEModeConfig,
@@ -30,6 +37,7 @@ import type {
30
37
  CoreEmitEvent2Config,
31
38
  CoreEmitEvent3Config,
32
39
  CoreEmitEvent4Config,
40
+ CorePartitionConfig,
33
41
  CorePeekConfig,
34
42
  CoreRawCallConfig,
35
43
  CoreSplitConfig,
@@ -48,12 +56,17 @@ import type {
48
56
  LifiSwapConfig,
49
57
  LifiZapAsyncConfig,
50
58
  LifiZapConfig,
59
+ MorphoBlueBorrowConfig,
60
+ MorphoBlueGetPositionConfig,
61
+ MorphoBlueRepayConfig,
51
62
  MorphoBlueSupplyCollateralConfig,
63
+ MorphoBlueSupplyConfig,
52
64
  MorphoBlueWithdrawCollateralConfig,
65
+ MorphoBlueWithdrawConfig,
53
66
  ParaswapBuyConfig,
54
67
  } from './config.generated.js';
55
68
 
56
- /** Split a resource into two outputs by basis-point ratio */
69
+ /** Split a resource into two outputs by basis-point ratio. Output `a` receives `bps` of the source, rounded up, and `b` takes the remainder. */
57
70
  export interface CoreSplitArgs {
58
71
  readonly bind: {
59
72
  readonly source: Bindable<'resource'>;
@@ -62,6 +75,22 @@ export interface CoreSplitArgs {
62
75
  readonly guards?: readonly TypedGuard<'a' | 'b'>[];
63
76
  }
64
77
 
78
+ /** Partition a resource into one output per basis-point share. `bps` lists 2 to 16 shares summing to 10000; output `parts.i` receives share i, rounded down, and the last part takes the remainder. */
79
+ export interface CorePartitionArgs<
80
+ TBps extends FamilySource<CorePartitionConfig['bps']> = FamilySource<
81
+ CorePartitionConfig['bps']
82
+ >,
83
+ > {
84
+ readonly bind: {
85
+ readonly source: Bindable<'resource'>;
86
+ };
87
+ readonly config: Omit<CorePartitionConfig, 'bps'> & {
88
+ readonly bps: TBps &
89
+ FamilyCount<NoInfer<TBps>, Readonly<CorePartitionConfig['bps']>>;
90
+ };
91
+ readonly guards?: readonly TypedGuard<`parts.${number}`>[];
92
+ }
93
+
65
94
  /** Merge two same-token resources into one by addition */
66
95
  export interface CoreMergeArgs {
67
96
  readonly bind: {
@@ -509,6 +538,13 @@ export interface AaveSetEModeArgs {
509
538
  readonly guards?: readonly TypedGuard<never>[];
510
539
  }
511
540
 
541
+ /** Read the current Aave v3 health factor (WAD-scaled, 1e18; type(uint256).max for users with no debt) by static-calling IPool.getUserAccountData and decomposing the returned tuple. Exposes the healthFactor element as a uint256 handle suitable for use with core.numericInvariant. */
542
+ export interface AaveGetHealthFactorArgs {
543
+ readonly bind: Record<string, never>;
544
+ readonly config: AaveGetHealthFactorConfig;
545
+ readonly guards?: readonly TypedGuard<'healthFactor'>[];
546
+ }
547
+
512
548
  /** Deposit the collateral asset of a Morpho Blue market on behalf of the execution proxy. mode: 'exact' pulls the input handle's amount. mode: 'all' reads the proxy's current ERC20 balance of the market's collateral token and pulls that amount, ignoring the input handle's literal value — note this pulls the proxy's total balance (including unrelated upstream residuals), not just the input port's delivery. Credits Position.collateral on the Morpho singleton; emits no return value and exposes no resource output (the collateral is non-transferable accounting state). */
513
549
  export interface MorphoBlueSupplyCollateralArgs {
514
550
  readonly bind: {
@@ -525,6 +561,54 @@ export interface MorphoBlueWithdrawCollateralArgs {
525
561
  readonly guards?: readonly TypedGuard<'collateralWithdrawn'>[];
526
562
  }
527
563
 
564
+ /** Borrow the loan asset from a Morpho Blue market against existing collateral. Exposes the borrowed amount as a Resource and the (assetsBorrowed, sharesBorrowed) tuple as handles. */
565
+ export interface MorphoBlueBorrowArgs {
566
+ readonly bind: Record<string, never>;
567
+ readonly config: MorphoBlueBorrowConfig;
568
+ readonly guards?: readonly TypedGuard<'assetsBorrowed' | 'sharesBorrowed'>[];
569
+ }
570
+
571
+ /** Repay a Morpho Blue debt position with the supplied asset. mode: 'exact' repays the input handle amount; mode: 'max' reads Position.borrowShares via a precursor static call and repays in shares mode to retire the debt to the wei. Returns any unspent residual as a Resource. */
572
+ export interface MorphoBlueRepayArgs {
573
+ readonly bind: {
574
+ readonly assetIn: Bindable<'resource'>;
575
+ readonly onBehalfOf: Bindable<'address'>;
576
+ };
577
+ readonly config: MorphoBlueRepayConfig;
578
+ readonly guards?: readonly TypedGuard<
579
+ 'actualRepaid' | 'sharesRepaid' | 'residual'
580
+ >[];
581
+ }
582
+
583
+ /** Supply the loan asset of a Morpho Blue market and receive supplyShares accounting credit. Returns the (assetsSupplied, sharesSupplied) tuple as handles and any unspent residual as a Resource. */
584
+ export interface MorphoBlueSupplyArgs {
585
+ readonly bind: {
586
+ readonly assetIn: Bindable<'resource'>;
587
+ };
588
+ readonly config: MorphoBlueSupplyConfig;
589
+ readonly guards?: readonly TypedGuard<
590
+ 'assetsSupplied' | 'sharesSupplied' | 'residual'
591
+ >[];
592
+ }
593
+
594
+ /** Withdraw the loan asset from a Morpho Blue supply position. mode: 'exact' withdraws the configured amount; mode: 'max' reads Position.supplyShares via a precursor static call and burns all shares to retire the supply to the wei. Exposes the withdrawn amount as a Resource. */
595
+ export interface MorphoBlueWithdrawArgs {
596
+ readonly bind: Record<string, never>;
597
+ readonly config: MorphoBlueWithdrawConfig;
598
+ readonly guards?: readonly TypedGuard<
599
+ 'assetsWithdrawn' | 'sharesWithdrawn'
600
+ >[];
601
+ }
602
+
603
+ /** Read a Morpho Blue Position struct via a static call on the singleton. Exposes (supplyShares, borrowShares, collateral) as handles whose kinds match the on-chain field types (uint256, uint128, uint128). */
604
+ export interface MorphoBlueGetPositionArgs {
605
+ readonly bind: Record<string, never>;
606
+ readonly config: MorphoBlueGetPositionConfig;
607
+ readonly guards?: readonly TypedGuard<
608
+ 'supplyShares' | 'borrowShares' | 'collateral'
609
+ >[];
610
+ }
611
+
528
612
  /** Route tokens into a DeFi protocol position via the edge catalog */
529
613
  export interface LifiZapArgs {
530
614
  readonly bind: {
@@ -575,6 +659,14 @@ export interface CoreSplitOutputs {
575
659
  readonly b: OutputHandle<'resource'>;
576
660
  }
577
661
 
662
+ export interface CorePartitionOutputs<
663
+ TBps extends FamilySource<CorePartitionConfig['bps']> = FamilySource<
664
+ CorePartitionConfig['bps']
665
+ >,
666
+ > {
667
+ readonly parts: OutputFamilyHandles<TBps>;
668
+ }
669
+
578
670
  export interface CoreMergeOutputs {
579
671
  readonly merged: OutputHandle<'resource'>;
580
672
  }
@@ -654,11 +746,45 @@ export interface AaveClaimRewardsOutputs {
654
746
  readonly claimedAmount: OutputHandle<'uint256'>;
655
747
  }
656
748
 
749
+ export interface AaveGetHealthFactorOutputs {
750
+ readonly healthFactor: OutputHandle<'uint256'>;
751
+ }
752
+
657
753
  export interface MorphoBlueWithdrawCollateralOutputs {
658
754
  readonly withdrawn: OutputHandle<'resource'>;
659
755
  readonly collateralWithdrawn: OutputHandle<'uint256'>;
660
756
  }
661
757
 
758
+ export interface MorphoBlueBorrowOutputs {
759
+ readonly borrowed: OutputHandle<'resource'>;
760
+ readonly assetsBorrowed: OutputHandle<'uint256'>;
761
+ readonly sharesBorrowed: OutputHandle<'uint256'>;
762
+ }
763
+
764
+ export interface MorphoBlueRepayOutputs {
765
+ readonly actualRepaid: OutputHandle<'uint256'>;
766
+ readonly sharesRepaid: OutputHandle<'uint256'>;
767
+ readonly residual: OutputHandle<'resource'>;
768
+ }
769
+
770
+ export interface MorphoBlueSupplyOutputs {
771
+ readonly assetsSupplied: OutputHandle<'uint256'>;
772
+ readonly sharesSupplied: OutputHandle<'uint256'>;
773
+ readonly residual: OutputHandle<'resource'>;
774
+ }
775
+
776
+ export interface MorphoBlueWithdrawOutputs {
777
+ readonly withdrawn: OutputHandle<'resource'>;
778
+ readonly assetsWithdrawn: OutputHandle<'uint256'>;
779
+ readonly sharesWithdrawn: OutputHandle<'uint256'>;
780
+ }
781
+
782
+ export interface MorphoBlueGetPositionOutputs {
783
+ readonly supplyShares: OutputHandle<'uint256'>;
784
+ readonly borrowShares: OutputHandle<'uint128'>;
785
+ readonly collateral: OutputHandle<'uint128'>;
786
+ }
787
+
662
788
  export interface LifiZapOutputs {
663
789
  readonly amountOut: OutputHandle<'resource'>;
664
790
  }
@@ -683,8 +809,15 @@ export interface FlySwapOutputs {
683
809
 
684
810
  export type GeneratedOps = {
685
811
  readonly core: {
686
- /** Split a resource into two outputs by basis-point ratio — original id: "core.split" */
812
+ /** Split a resource into two outputs by basis-point ratio. Output `a` receives `bps` of the source, rounded up, and `b` takes the remainder. — original id: "core.split" */
687
813
  readonly split: (nodeId: string, args: CoreSplitArgs) => CoreSplitOutputs;
814
+ /** Partition a resource into one output per basis-point share. `bps` lists 2 to 16 shares summing to 10000; output `parts.i` receives share i, rounded down, and the last part takes the remainder. — original id: "core.partition" */
815
+ readonly partition: <
816
+ const TBps extends FamilySource<CorePartitionConfig['bps']>,
817
+ >(
818
+ nodeId: string,
819
+ args: CorePartitionArgs<TBps>,
820
+ ) => CorePartitionOutputs<TBps>;
688
821
  /** Merge two same-token resources into one by addition — original id: "core.merge" */
689
822
  readonly merge: (nodeId: string, args: CoreMergeArgs) => CoreMergeOutputs;
690
823
  /** Add two unsigned integers (a + b) — original id: "core.add" */
@@ -876,6 +1009,11 @@ export type GeneratedOps = {
876
1009
  ) => AaveClaimRewardsOutputs;
877
1010
  /** Switch the executionAddress's Aave v3 eMode category. 0 disables eMode. The pool reverts if the switch would make the position unhealthy or if any open borrow is for an asset outside the target category. — original id: "aave.setEMode" */
878
1011
  readonly setEMode: (nodeId: string, args: AaveSetEModeArgs) => void;
1012
+ /** Read the current Aave v3 health factor (WAD-scaled, 1e18; type(uint256).max for users with no debt) by static-calling IPool.getUserAccountData and decomposing the returned tuple. Exposes the healthFactor element as a uint256 handle suitable for use with core.numericInvariant. — original id: "aave.getHealthFactor" */
1013
+ readonly getHealthFactor: (
1014
+ nodeId: string,
1015
+ args: AaveGetHealthFactorArgs,
1016
+ ) => AaveGetHealthFactorOutputs;
879
1017
  };
880
1018
  readonly morphoBlue: {
881
1019
  /** Deposit the collateral asset of a Morpho Blue market on behalf of the execution proxy. mode: 'exact' pulls the input handle's amount. mode: 'all' reads the proxy's current ERC20 balance of the market's collateral token and pulls that amount, ignoring the input handle's literal value — note this pulls the proxy's total balance (including unrelated upstream residuals), not just the input port's delivery. Credits Position.collateral on the Morpho singleton; emits no return value and exposes no resource output (the collateral is non-transferable accounting state). — original id: "morphoBlue.supplyCollateral" */
@@ -888,6 +1026,31 @@ export type GeneratedOps = {
888
1026
  nodeId: string,
889
1027
  args: MorphoBlueWithdrawCollateralArgs,
890
1028
  ) => MorphoBlueWithdrawCollateralOutputs;
1029
+ /** Borrow the loan asset from a Morpho Blue market against existing collateral. Exposes the borrowed amount as a Resource and the (assetsBorrowed, sharesBorrowed) tuple as handles. — original id: "morphoBlue.borrow" */
1030
+ readonly borrow: (
1031
+ nodeId: string,
1032
+ args: MorphoBlueBorrowArgs,
1033
+ ) => MorphoBlueBorrowOutputs;
1034
+ /** Repay a Morpho Blue debt position with the supplied asset. mode: 'exact' repays the input handle amount; mode: 'max' reads Position.borrowShares via a precursor static call and repays in shares mode to retire the debt to the wei. Returns any unspent residual as a Resource. — original id: "morphoBlue.repay" */
1035
+ readonly repay: (
1036
+ nodeId: string,
1037
+ args: MorphoBlueRepayArgs,
1038
+ ) => MorphoBlueRepayOutputs;
1039
+ /** Supply the loan asset of a Morpho Blue market and receive supplyShares accounting credit. Returns the (assetsSupplied, sharesSupplied) tuple as handles and any unspent residual as a Resource. — original id: "morphoBlue.supply" */
1040
+ readonly supply: (
1041
+ nodeId: string,
1042
+ args: MorphoBlueSupplyArgs,
1043
+ ) => MorphoBlueSupplyOutputs;
1044
+ /** Withdraw the loan asset from a Morpho Blue supply position. mode: 'exact' withdraws the configured amount; mode: 'max' reads Position.supplyShares via a precursor static call and burns all shares to retire the supply to the wei. Exposes the withdrawn amount as a Resource. — original id: "morphoBlue.withdraw" */
1045
+ readonly withdraw: (
1046
+ nodeId: string,
1047
+ args: MorphoBlueWithdrawArgs,
1048
+ ) => MorphoBlueWithdrawOutputs;
1049
+ /** Read a Morpho Blue Position struct via a static call on the singleton. Exposes (supplyShares, borrowShares, collateral) as handles whose kinds match the on-chain field types (uint256, uint128, uint128). — original id: "morphoBlue.getPosition" */
1050
+ readonly getPosition: (
1051
+ nodeId: string,
1052
+ args: MorphoBlueGetPositionArgs,
1053
+ ) => MorphoBlueGetPositionOutputs;
891
1054
  };
892
1055
  readonly paraswap: {
893
1056
  /** Exact-output (BUY) swap via the Paraswap/Velora Market API: produce exactly `exactAmountOut` of the destination token, pulling only the source needed and exposing the genuinely-unspent source as `unspentIn`. — original id: "paraswap.buy" */
@@ -908,6 +1071,17 @@ export const bindGeneratedOps = (
908
1071
  a: 'resource',
909
1072
  b: 'resource',
910
1073
  } as const),
1074
+ partition: <const TBps extends FamilySource<CorePartitionConfig['bps']>>(
1075
+ nodeId: string,
1076
+ args: CorePartitionArgs<TBps>,
1077
+ ) =>
1078
+ builder.call(
1079
+ nodeId,
1080
+ 'core.partition',
1081
+ args,
1082
+ { parts: 'resource' } as const,
1083
+ { parts: 'bps' } as const,
1084
+ ) as unknown as CorePartitionOutputs<TBps>,
911
1085
  merge: (nodeId: string, args: CoreMergeArgs) =>
912
1086
  builder.call(nodeId, 'core.merge', { ...args, config: {} }, {
913
1087
  merged: 'resource',
@@ -1124,6 +1298,10 @@ export const bindGeneratedOps = (
1124
1298
  } as const),
1125
1299
  setEMode: (nodeId: string, args: AaveSetEModeArgs) =>
1126
1300
  builder.call(nodeId, 'aave.setEMode', args, {}),
1301
+ getHealthFactor: (nodeId: string, args: AaveGetHealthFactorArgs) =>
1302
+ builder.call(nodeId, 'aave.getHealthFactor', args, {
1303
+ healthFactor: 'uint256',
1304
+ } as const),
1127
1305
  },
1128
1306
  morphoBlue: {
1129
1307
  supplyCollateral: (nodeId: string, args: MorphoBlueSupplyCollateralArgs) =>
@@ -1136,6 +1314,36 @@ export const bindGeneratedOps = (
1136
1314
  withdrawn: 'resource',
1137
1315
  collateralWithdrawn: 'uint256',
1138
1316
  } as const),
1317
+ borrow: (nodeId: string, args: MorphoBlueBorrowArgs) =>
1318
+ builder.call(nodeId, 'morphoBlue.borrow', args, {
1319
+ borrowed: 'resource',
1320
+ assetsBorrowed: 'uint256',
1321
+ sharesBorrowed: 'uint256',
1322
+ } as const),
1323
+ repay: (nodeId: string, args: MorphoBlueRepayArgs) =>
1324
+ builder.call(nodeId, 'morphoBlue.repay', args, {
1325
+ actualRepaid: 'uint256',
1326
+ sharesRepaid: 'uint256',
1327
+ residual: 'resource',
1328
+ } as const),
1329
+ supply: (nodeId: string, args: MorphoBlueSupplyArgs) =>
1330
+ builder.call(nodeId, 'morphoBlue.supply', args, {
1331
+ assetsSupplied: 'uint256',
1332
+ sharesSupplied: 'uint256',
1333
+ residual: 'resource',
1334
+ } as const),
1335
+ withdraw: (nodeId: string, args: MorphoBlueWithdrawArgs) =>
1336
+ builder.call(nodeId, 'morphoBlue.withdraw', args, {
1337
+ withdrawn: 'resource',
1338
+ assetsWithdrawn: 'uint256',
1339
+ sharesWithdrawn: 'uint256',
1340
+ } as const),
1341
+ getPosition: (nodeId: string, args: MorphoBlueGetPositionArgs) =>
1342
+ builder.call(nodeId, 'morphoBlue.getPosition', args, {
1343
+ supplyShares: 'uint256',
1344
+ borrowShares: 'uint128',
1345
+ collateral: 'uint128',
1346
+ } as const),
1139
1347
  },
1140
1348
  paraswap: {
1141
1349
  buy: (nodeId: string, args: ParaswapBuyArgs) =>
package/src/index.ts CHANGED
@@ -101,7 +101,8 @@ export type {
101
101
  ContinuationOutcome,
102
102
  Check,
103
103
  CheckComparator,
104
- Phase1ArtifactWire,
104
+ SettlementWire,
105
+ SettlementEscrowWire,
105
106
  ContinuationPlanWire,
106
107
  } from '@lifi/compose-spec';
107
108
  export {
@@ -122,6 +123,9 @@ export type {
122
123
  InputHandle,
123
124
  ResourceInputHandle,
124
125
  OutputHandle,
126
+ OutputFamilyHandles,
127
+ FamilyCount,
128
+ FamilySource,
125
129
  AnyHandle,
126
130
  } from './authoring/handles.js';
127
131
  export { isInputHandle, isOutputHandle } from './authoring/handles.js';