@lifi/composer-sdk 0.4.0-staging.1 → 0.4.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.
Files changed (34) hide show
  1. package/dist/client.cjs +1 -1
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.js +1 -1
  4. package/dist/client.js.map +1 -1
  5. package/dist/generated/materialisers.generated.cjs +2 -8
  6. package/dist/generated/materialisers.generated.cjs.map +1 -1
  7. package/dist/generated/materialisers.generated.d.cts +1 -1
  8. package/dist/generated/materialisers.generated.d.ts +1 -1
  9. package/dist/generated/materialisers.generated.js +1 -6
  10. package/dist/generated/materialisers.generated.js.map +1 -1
  11. package/dist/generated/operations.generated.cjs +1 -39
  12. package/dist/generated/operations.generated.cjs.map +1 -1
  13. package/dist/generated/operations.generated.d.cts +2 -111
  14. package/dist/generated/operations.generated.d.ts +2 -111
  15. package/dist/generated/operations.generated.js +1 -39
  16. package/dist/generated/operations.generated.js.map +1 -1
  17. package/dist/index.d.cts +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/{materialisers.generated-BfWJ-g7t.d.ts → materialisers.generated-BMkBQgWZ.d.ts} +3 -8
  20. package/dist/{materialisers.generated-DaJRwiRe.d.cts → materialisers.generated-BWq5oePO.d.cts} +3 -8
  21. package/package.json +4 -3
  22. package/src/generated/materialisers.generated.ts +0 -12
  23. package/src/generated/operations.generated.ts +0 -214
  24. package/src/examples/staged/aaveBorrow.ts +0 -128
  25. package/src/examples/staged/aaveDebtRebalanceExactOut.ts +0 -301
  26. package/src/examples/staged/aaveHealthFactorExplode.ts +0 -70
  27. package/src/examples/staged/aaveToMorphoDebtMigration.ts +0 -200
  28. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwap.ts +0 -231
  29. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwapExactOut.ts +0 -307
  30. package/src/examples/staged/flashloanRepay.ts +0 -142
  31. package/src/examples/staged/manualRelayContinuation.ts +0 -161
  32. package/src/examples/staged/morphoBlueBorrow.ts +0 -93
  33. package/src/examples/staged/morphoBlueRepay.ts +0 -132
  34. package/src/examples/staged/registry.ts +0 -89
@@ -1,5 +1,5 @@
1
1
  import { MaterialiserConfigOf, MaterialiserInput } from '@lifi/compose-spec';
2
- import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1, FlashloanMaterialiserConfig as FlashloanMaterialiserConfig$1 } from './generated/config.generated.cjs';
2
+ import { BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig$1, CallMaterialiserConfig as CallMaterialiserConfig$1, DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig$1 } from './generated/config.generated.cjs';
3
3
 
4
4
  type BalanceOfMaterialiserConfig = MaterialiserConfigOf<BalanceOfMaterialiserConfig$1>;
5
5
  /** Read the on-chain token balance of an address as the input amount — accepts: resource */
@@ -10,20 +10,15 @@ declare const directDeposit: (config: DirectDepositMaterialiserConfig) => Materi
10
10
  type CallMaterialiserConfig = MaterialiserConfigOf<CallMaterialiserConfig$1>;
11
11
  /** Execute an arbitrary contract call and measure the resulting token balance diff — accepts: resource */
12
12
  declare const call: (config: CallMaterialiserConfig) => MaterialiserInput;
13
- type FlashloanMaterialiserConfig = MaterialiserConfigOf<FlashloanMaterialiserConfig$1>;
14
- /** Borrow tokens from a flashloan provider; amount becomes a register populated by the proxy at callback time — accepts: resource */
15
- declare const flashloan: (config: FlashloanMaterialiserConfig) => MaterialiserInput;
16
13
 
17
14
  type materialisersMod_BalanceOfMaterialiserConfig = BalanceOfMaterialiserConfig;
18
15
  type materialisersMod_CallMaterialiserConfig = CallMaterialiserConfig;
19
16
  type materialisersMod_DirectDepositMaterialiserConfig = DirectDepositMaterialiserConfig;
20
- type materialisersMod_FlashloanMaterialiserConfig = FlashloanMaterialiserConfig;
21
17
  declare const materialisersMod_balanceOf: typeof balanceOf;
22
18
  declare const materialisersMod_call: typeof call;
23
19
  declare const materialisersMod_directDeposit: typeof directDeposit;
24
- declare const materialisersMod_flashloan: typeof flashloan;
25
20
  declare namespace materialisersMod {
26
- export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, type materialisersMod_FlashloanMaterialiserConfig as FlashloanMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit, materialisersMod_flashloan as flashloan };
21
+ export { type materialisersMod_BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfig, type materialisersMod_CallMaterialiserConfig as CallMaterialiserConfig, type materialisersMod_DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfig, materialisersMod_balanceOf as balanceOf, materialisersMod_call as call, materialisersMod_directDeposit as directDeposit };
27
22
  }
28
23
 
29
- export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, type FlashloanMaterialiserConfig as F, balanceOf as b, call as c, directDeposit as d, flashloan as f, materialisersMod as m };
24
+ export { type BalanceOfMaterialiserConfig as B, type CallMaterialiserConfig as C, type DirectDepositMaterialiserConfig as D, balanceOf as b, call as c, directDeposit as d, materialisersMod as m };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/composer-sdk",
3
- "version": "0.4.0-staging.1",
3
+ "version": "0.4.0",
4
4
  "description": "Public Composer SDK for building and submitting flows",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  "example:staged": "tsx src/examples/run.ts --staged"
52
52
  },
53
53
  "peerDependencies": {
54
- "@lifi/compose-spec": "0.4.0-staging.1"
54
+ "@lifi/compose-spec": "0.4.0"
55
55
  },
56
56
  "dependencies": {
57
57
  "abitype": "^1.2.3",
@@ -85,6 +85,7 @@
85
85
  "!src/**/*.test.ts",
86
86
  "!src/**/*.mock.ts",
87
87
  "!src/**/*.typecheck.ts",
88
- "!dist/**/*.typecheck.*"
88
+ "!dist/**/*.typecheck.*",
89
+ "!src/examples/staged/**"
89
90
  ]
90
91
  }
@@ -10,7 +10,6 @@ import type {
10
10
  BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfigSchema,
11
11
  CallMaterialiserConfig as CallMaterialiserConfigSchema,
12
12
  DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfigSchema,
13
- FlashloanMaterialiserConfig as FlashloanMaterialiserConfigSchema,
14
13
  } from './config.generated.js';
15
14
 
16
15
  export type BalanceOfMaterialiserConfig =
@@ -43,14 +42,3 @@ export const call = (config: CallMaterialiserConfig): MaterialiserInput => ({
43
42
  kind: 'call',
44
43
  ...config,
45
44
  });
46
-
47
- export type FlashloanMaterialiserConfig =
48
- MaterialiserConfigOf<FlashloanMaterialiserConfigSchema>;
49
-
50
- /** Borrow tokens from a flashloan provider; amount becomes a register populated by the proxy at callback time — accepts: resource */
51
- export const flashloan = (
52
- config: FlashloanMaterialiserConfig,
53
- ): MaterialiserInput => ({
54
- kind: 'flashloan',
55
- ...config,
56
- });
@@ -20,11 +20,9 @@ import type { TypedGuard } from '../types.js';
20
20
  import type {
21
21
  AaveBorrowConfig,
22
22
  AaveClaimRewardsConfig,
23
- AaveGetHealthFactorConfig,
24
23
  AaveRepayConfig,
25
24
  AaveRepayWithATokensConfig,
26
25
  AaveSetEModeConfig,
27
- ContinuationAssertReadyConfig,
28
26
  CoreApproveConfig,
29
27
  CoreAsResourceConfig,
30
28
  CoreBalanceOfConfig,
@@ -48,16 +46,10 @@ import type {
48
46
  InvariantNeqConfig,
49
47
  InvariantNumericConfig,
50
48
  InvariantNumericInRangeConfig,
51
- LifiFlashloanRepayConfig,
52
49
  LifiSwapConfig,
53
50
  LifiZapConfig,
54
- MorphoBlueBorrowConfig,
55
- MorphoBlueGetPositionConfig,
56
- MorphoBlueRepayConfig,
57
51
  MorphoBlueSupplyCollateralConfig,
58
- MorphoBlueSupplyConfig,
59
52
  MorphoBlueWithdrawCollateralConfig,
60
- MorphoBlueWithdrawConfig,
61
53
  ParaswapBuyConfig,
62
54
  } from './config.generated.js';
63
55
 
@@ -508,13 +500,6 @@ export interface AaveSetEModeArgs {
508
500
  readonly guards?: readonly TypedGuard<never>[];
509
501
  }
510
502
 
511
- /** 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. */
512
- export interface AaveGetHealthFactorArgs {
513
- readonly bind: Record<string, never>;
514
- readonly config: AaveGetHealthFactorConfig;
515
- readonly guards?: readonly TypedGuard<'healthFactor'>[];
516
- }
517
-
518
503
  /** 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). */
519
504
  export interface MorphoBlueSupplyCollateralArgs {
520
505
  readonly bind: {
@@ -531,77 +516,6 @@ export interface MorphoBlueWithdrawCollateralArgs {
531
516
  readonly guards?: readonly TypedGuard<'collateralWithdrawn'>[];
532
517
  }
533
518
 
534
- /** 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. */
535
- export interface MorphoBlueBorrowArgs {
536
- readonly bind: Record<string, never>;
537
- readonly config: MorphoBlueBorrowConfig;
538
- readonly guards?: readonly TypedGuard<'assetsBorrowed' | 'sharesBorrowed'>[];
539
- }
540
-
541
- /** 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. */
542
- export interface MorphoBlueRepayArgs {
543
- readonly bind: {
544
- readonly assetIn: Bindable<'resource'>;
545
- readonly onBehalfOf: Bindable<'address'>;
546
- };
547
- readonly config: MorphoBlueRepayConfig;
548
- readonly guards?: readonly TypedGuard<
549
- 'actualRepaid' | 'sharesRepaid' | 'residual'
550
- >[];
551
- }
552
-
553
- /** 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. */
554
- export interface MorphoBlueSupplyArgs {
555
- readonly bind: {
556
- readonly assetIn: Bindable<'resource'>;
557
- };
558
- readonly config: MorphoBlueSupplyConfig;
559
- readonly guards?: readonly TypedGuard<
560
- 'assetsSupplied' | 'sharesSupplied' | 'residual'
561
- >[];
562
- }
563
-
564
- /** 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. */
565
- export interface MorphoBlueWithdrawArgs {
566
- readonly bind: Record<string, never>;
567
- readonly config: MorphoBlueWithdrawConfig;
568
- readonly guards?: readonly TypedGuard<
569
- 'assetsWithdrawn' | 'sharesWithdrawn'
570
- >[];
571
- }
572
-
573
- /** 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). */
574
- export interface MorphoBlueGetPositionArgs {
575
- readonly bind: Record<string, never>;
576
- readonly config: MorphoBlueGetPositionConfig;
577
- readonly guards?: readonly TypedGuard<
578
- 'supplyShares' | 'borrowShares' | 'collateral'
579
- >[];
580
- }
581
-
582
- /** Transfer principal + fee back to the LiFi flashloan adapter for one leg */
583
- export interface LifiFlashloanRepayArgs {
584
- readonly bind: {
585
- readonly funds: Bindable<'resource'>;
586
- readonly feeBuffer?: Bindable<'resource'>;
587
- };
588
- readonly config: LifiFlashloanRepayConfig;
589
- readonly guards?: readonly TypedGuard<never>[];
590
- }
591
-
592
- /** Assert a continuation readiness check on-chain; reverts the second leg if its proceeds have not landed */
593
- export interface ContinuationAssertReadyArgs {
594
- readonly bind: Record<string, never>;
595
- readonly config: ContinuationAssertReadyConfig;
596
- readonly guards?: readonly TypedGuard<never>[];
597
- }
598
-
599
- /** Carries a committed continuation thunk as node metadata for the settlement echo; emits no IR1 */
600
- export interface ContinuationCommitmentArgs {
601
- readonly bind: Record<string, never>;
602
- readonly guards?: readonly TypedGuard<never>[];
603
- }
604
-
605
519
  /** Route tokens into a DeFi protocol position via the edge catalog */
606
520
  export interface LifiZapArgs {
607
521
  readonly bind: {
@@ -706,45 +620,11 @@ export interface AaveClaimRewardsOutputs {
706
620
  readonly claimedAmount: OutputHandle<'uint256'>;
707
621
  }
708
622
 
709
- export interface AaveGetHealthFactorOutputs {
710
- readonly healthFactor: OutputHandle<'uint256'>;
711
- }
712
-
713
623
  export interface MorphoBlueWithdrawCollateralOutputs {
714
624
  readonly withdrawn: OutputHandle<'resource'>;
715
625
  readonly collateralWithdrawn: OutputHandle<'uint256'>;
716
626
  }
717
627
 
718
- export interface MorphoBlueBorrowOutputs {
719
- readonly borrowed: OutputHandle<'resource'>;
720
- readonly assetsBorrowed: OutputHandle<'uint256'>;
721
- readonly sharesBorrowed: OutputHandle<'uint256'>;
722
- }
723
-
724
- export interface MorphoBlueRepayOutputs {
725
- readonly actualRepaid: OutputHandle<'uint256'>;
726
- readonly sharesRepaid: OutputHandle<'uint256'>;
727
- readonly residual: OutputHandle<'resource'>;
728
- }
729
-
730
- export interface MorphoBlueSupplyOutputs {
731
- readonly assetsSupplied: OutputHandle<'uint256'>;
732
- readonly sharesSupplied: OutputHandle<'uint256'>;
733
- readonly residual: OutputHandle<'resource'>;
734
- }
735
-
736
- export interface MorphoBlueWithdrawOutputs {
737
- readonly withdrawn: OutputHandle<'resource'>;
738
- readonly assetsWithdrawn: OutputHandle<'uint256'>;
739
- readonly sharesWithdrawn: OutputHandle<'uint256'>;
740
- }
741
-
742
- export interface MorphoBlueGetPositionOutputs {
743
- readonly supplyShares: OutputHandle<'uint256'>;
744
- readonly borrowShares: OutputHandle<'uint128'>;
745
- readonly collateral: OutputHandle<'uint128'>;
746
- }
747
-
748
628
  export interface LifiZapOutputs {
749
629
  readonly amountOut: OutputHandle<'resource'>;
750
630
  }
@@ -859,11 +739,6 @@ export type GeneratedOps = {
859
739
  readonly lifi: {
860
740
  /** Swap tokens via the LI.FI aggregator API — original id: "lifi.swap" */
861
741
  readonly swap: (nodeId: string, args: LifiSwapArgs) => LifiSwapOutputs;
862
- /** Transfer principal + fee back to the LiFi flashloan adapter for one leg — original id: "lifi.flashloanRepay" */
863
- readonly flashloanRepay: (
864
- nodeId: string,
865
- args: LifiFlashloanRepayArgs,
866
- ) => void;
867
742
  /** Route tokens into a DeFi protocol position via the edge catalog — original id: "lifi.zap" */
868
743
  readonly zap: (nodeId: string, args: LifiZapArgs) => LifiZapOutputs;
869
744
  };
@@ -948,11 +823,6 @@ export type GeneratedOps = {
948
823
  ) => AaveClaimRewardsOutputs;
949
824
  /** 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" */
950
825
  readonly setEMode: (nodeId: string, args: AaveSetEModeArgs) => void;
951
- /** 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" */
952
- readonly getHealthFactor: (
953
- nodeId: string,
954
- args: AaveGetHealthFactorArgs,
955
- ) => AaveGetHealthFactorOutputs;
956
826
  };
957
827
  readonly morphoBlue: {
958
828
  /** 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" */
@@ -965,43 +835,6 @@ export type GeneratedOps = {
965
835
  nodeId: string,
966
836
  args: MorphoBlueWithdrawCollateralArgs,
967
837
  ) => MorphoBlueWithdrawCollateralOutputs;
968
- /** 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" */
969
- readonly borrow: (
970
- nodeId: string,
971
- args: MorphoBlueBorrowArgs,
972
- ) => MorphoBlueBorrowOutputs;
973
- /** 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" */
974
- readonly repay: (
975
- nodeId: string,
976
- args: MorphoBlueRepayArgs,
977
- ) => MorphoBlueRepayOutputs;
978
- /** 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" */
979
- readonly supply: (
980
- nodeId: string,
981
- args: MorphoBlueSupplyArgs,
982
- ) => MorphoBlueSupplyOutputs;
983
- /** 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" */
984
- readonly withdraw: (
985
- nodeId: string,
986
- args: MorphoBlueWithdrawArgs,
987
- ) => MorphoBlueWithdrawOutputs;
988
- /** 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" */
989
- readonly getPosition: (
990
- nodeId: string,
991
- args: MorphoBlueGetPositionArgs,
992
- ) => MorphoBlueGetPositionOutputs;
993
- };
994
- readonly continuation: {
995
- /** Assert a continuation readiness check on-chain; reverts the second leg if its proceeds have not landed — original id: "continuation.assertReady" */
996
- readonly assertReady: (
997
- nodeId: string,
998
- args: ContinuationAssertReadyArgs,
999
- ) => void;
1000
- /** Carries a committed continuation thunk as node metadata for the settlement echo; emits no IR1 — original id: "continuation.commitment" */
1001
- readonly commitment: (
1002
- nodeId: string,
1003
- args: ContinuationCommitmentArgs,
1004
- ) => void;
1005
838
  };
1006
839
  readonly paraswap: {
1007
840
  /** 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" */
@@ -1123,8 +956,6 @@ export const bindGeneratedOps = (
1123
956
  amountOut: 'resource',
1124
957
  unspentIn: 'resource',
1125
958
  } as const),
1126
- flashloanRepay: (nodeId: string, args: LifiFlashloanRepayArgs) =>
1127
- builder.call(nodeId, 'lifi.flashloanRepay', args, {}),
1128
959
  zap: (nodeId: string, args: LifiZapArgs) =>
1129
960
  builder.call(nodeId, 'lifi.zap', args, {
1130
961
  amountOut: 'resource',
@@ -1227,10 +1058,6 @@ export const bindGeneratedOps = (
1227
1058
  } as const),
1228
1059
  setEMode: (nodeId: string, args: AaveSetEModeArgs) =>
1229
1060
  builder.call(nodeId, 'aave.setEMode', args, {}),
1230
- getHealthFactor: (nodeId: string, args: AaveGetHealthFactorArgs) =>
1231
- builder.call(nodeId, 'aave.getHealthFactor', args, {
1232
- healthFactor: 'uint256',
1233
- } as const),
1234
1061
  },
1235
1062
  morphoBlue: {
1236
1063
  supplyCollateral: (nodeId: string, args: MorphoBlueSupplyCollateralArgs) =>
@@ -1243,47 +1070,6 @@ export const bindGeneratedOps = (
1243
1070
  withdrawn: 'resource',
1244
1071
  collateralWithdrawn: 'uint256',
1245
1072
  } as const),
1246
- borrow: (nodeId: string, args: MorphoBlueBorrowArgs) =>
1247
- builder.call(nodeId, 'morphoBlue.borrow', args, {
1248
- borrowed: 'resource',
1249
- assetsBorrowed: 'uint256',
1250
- sharesBorrowed: 'uint256',
1251
- } as const),
1252
- repay: (nodeId: string, args: MorphoBlueRepayArgs) =>
1253
- builder.call(nodeId, 'morphoBlue.repay', args, {
1254
- actualRepaid: 'uint256',
1255
- sharesRepaid: 'uint256',
1256
- residual: 'resource',
1257
- } as const),
1258
- supply: (nodeId: string, args: MorphoBlueSupplyArgs) =>
1259
- builder.call(nodeId, 'morphoBlue.supply', args, {
1260
- assetsSupplied: 'uint256',
1261
- sharesSupplied: 'uint256',
1262
- residual: 'resource',
1263
- } as const),
1264
- withdraw: (nodeId: string, args: MorphoBlueWithdrawArgs) =>
1265
- builder.call(nodeId, 'morphoBlue.withdraw', args, {
1266
- withdrawn: 'resource',
1267
- assetsWithdrawn: 'uint256',
1268
- sharesWithdrawn: 'uint256',
1269
- } as const),
1270
- getPosition: (nodeId: string, args: MorphoBlueGetPositionArgs) =>
1271
- builder.call(nodeId, 'morphoBlue.getPosition', args, {
1272
- supplyShares: 'uint256',
1273
- borrowShares: 'uint128',
1274
- collateral: 'uint128',
1275
- } as const),
1276
- },
1277
- continuation: {
1278
- assertReady: (nodeId: string, args: ContinuationAssertReadyArgs) =>
1279
- builder.call(nodeId, 'continuation.assertReady', args, {}),
1280
- commitment: (nodeId: string, args: ContinuationCommitmentArgs) =>
1281
- builder.call(
1282
- nodeId,
1283
- 'continuation.commitment',
1284
- { ...args, config: {} },
1285
- {},
1286
- ),
1287
1073
  },
1288
1074
  paraswap: {
1289
1075
  buy: (nodeId: string, args: ParaswapBuyArgs) =>
@@ -1,128 +0,0 @@
1
- import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
2
-
3
- import {
4
- createComposeSdk,
5
- guards,
6
- materialisers,
7
- resources,
8
- } from '../../index.js';
9
- import type { Address } from '../../types.js';
10
- import { API_KEY, BASE_URL } from '../config.js';
11
-
12
- // Aave v3 contracts on Ethereum mainnet.
13
- const AAVE_V3_POOL = '0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2';
14
- const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
15
- // Aave v3 aEthUSDC receipt token and variable-debt USDC token.
16
- const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';
17
- const VDEBT_USDC = '0x72E95b8931767C79bA4EeE721354d6E99a61D004';
18
-
19
- // 1.05 WAD (1e18) — minimum acceptable Aave health factor after the borrow.
20
- // The on-chain VM reverts the run if the post-borrow HF drops below this.
21
- const MIN_HEALTH_FACTOR_WAD = '1050000000000000000';
22
-
23
- export interface AaveBorrowInput {
24
- readonly owner: Address;
25
- readonly recipient: Address;
26
- /** USDC supplied as collateral so the proxy can borrow (6 dp). */
27
- readonly collateralAmount: `${bigint}`;
28
- /** USDC borrowed against the collateral and sent to the recipient (6 dp). */
29
- readonly borrowAmount: `${bigint}`;
30
- }
31
-
32
- /**
33
- * Supply USDC to Aave v3, borrow USDC against it, and transfer the borrowed
34
- * funds to a recipient — with an on-chain health-factor guard that reverts
35
- * if the post-borrow position is too thin.
36
- *
37
- * The in-flow supply makes the example self-contained: the borrow is backed
38
- * by collateral created in the same transaction, so it simulates cleanly
39
- * for a fresh proxy. Keep `borrowAmount` comfortably below the collateral's
40
- * borrowing power or the health-factor guard reverts the run.
41
- *
42
- * Demonstrates:
43
- * - `lifi.zap` to supply USDC into Aave (USDC → aEthUSDC routing edge)
44
- * - `aave.borrow` with no resource input — the borrowed asset materialises
45
- * as the `borrowed` resource output.
46
- * - Chaining the borrow output into a `core.transfer` to forward funds.
47
- * - `aave.getHealthFactor` + `core.numericInvariant` guard asserts that
48
- * `healthFactor >= MIN_HEALTH_FACTOR_WAD` after the borrow; the run reverts
49
- * on-chain if the threshold is violated.
50
- *
51
- * The supplied aEthUSDC stays on the proxy: it backs the open debt, and
52
- * Aave rejects aToken transfers that would break the position's health
53
- * factor, so it cannot be swept while the borrow is outstanding.
54
- */
55
- export const buildAaveBorrow = ({
56
- owner,
57
- recipient,
58
- collateralAmount,
59
- borrowAmount,
60
- }: AaveBorrowInput): {
61
- flow: Flow;
62
- request: ComposeCompileRequest;
63
- } => {
64
- const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
65
-
66
- const builder = sdk.flow(1, {
67
- name: 'aave-borrow-usdc',
68
- inputs: {
69
- collateralIn: resources.erc20(USDC, 1),
70
- recipient: 'address',
71
- },
72
- });
73
-
74
- // Supply USDC as collateral (USDC → aEthUSDC) so the proxy can borrow.
75
- builder.lifi.zap('supply', {
76
- bind: { amountIn: builder.inputs.collateralIn },
77
- config: { resourceOut: resources.erc20(A_ETH_USDC, 1) },
78
- });
79
-
80
- const borrowOut = builder.aave.borrow('borrow', {
81
- bind: {},
82
- config: {
83
- pool: AAVE_V3_POOL,
84
- asset: USDC,
85
- variableDebtToken: VDEBT_USDC,
86
- amount: borrowAmount,
87
- },
88
- });
89
-
90
- // Read the post-borrow Aave health factor and assert it stays above the
91
- // minimum threshold. The numericInvariant guard lowers to an on-chain
92
- // `AssertRawInvariant` IR1 instruction; the run reverts if HF < threshold.
93
- builder.aave.getHealthFactor('hf', {
94
- bind: {},
95
- config: { pool: AAVE_V3_POOL },
96
- guards: [
97
- guards.coreNumericInvariant({
98
- port: 'healthFactor',
99
- op: 'gte',
100
- threshold: MIN_HEALTH_FACTOR_WAD,
101
- }),
102
- ],
103
- });
104
-
105
- // Forward the freshly borrowed USDC to the recipient.
106
- builder.core.transfer('send-borrowed', {
107
- bind: {
108
- amount: borrowOut.borrowed,
109
- recipient: builder.inputs.recipient,
110
- },
111
- config: {},
112
- });
113
-
114
- const flow = builder.build();
115
-
116
- // No sweepTo: the aEthUSDC collateral must stay on the proxy while the
117
- // debt is open — Aave blocks aToken transfers that would leave the
118
- // position undercollateralized.
119
- const request = sdk.request(flow, {
120
- signer: owner,
121
- inputs: {
122
- collateralIn: materialisers.directDeposit({ amount: collateralAmount }),
123
- recipient,
124
- },
125
- });
126
-
127
- return { flow, request };
128
- };