@lifi/composer-sdk 0.4.0-staging.1 → 0.4.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.
- package/README.md +95 -5
- package/dist/authoring/raw.cjs +3 -1
- package/dist/authoring/raw.cjs.map +1 -1
- package/dist/authoring/raw.js +3 -1
- package/dist/authoring/raw.js.map +1 -1
- package/dist/client.cjs +26 -24
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +31 -1
- package/dist/client.d.ts +31 -1
- package/dist/client.js +26 -24
- package/dist/client.js.map +1 -1
- package/dist/discovery.cjs.map +1 -1
- package/dist/discovery.d.cts +13 -0
- package/dist/discovery.d.ts +13 -0
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +15 -3
- package/dist/generated/config.generated.d.ts +15 -3
- 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 +4 -39
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +17 -111
- package/dist/generated/operations.generated.d.ts +17 -111
- package/dist/generated/operations.generated.js +4 -39
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +4 -1
- 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/routeAmount-DdbJYJyM.d.cts +55 -0
- package/dist/routeAmount-DdbJYJyM.d.ts +55 -0
- package/dist/routeAmount.cjs +38 -0
- package/dist/routeAmount.cjs.map +1 -0
- package/dist/routeAmount.d.cts +2 -0
- package/dist/routeAmount.d.ts +2 -0
- package/dist/routeAmount.js +13 -0
- package/dist/routeAmount.js.map +1 -0
- package/dist/sdk.cjs +1 -0
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +14 -1
- package/dist/sdk.d.ts +14 -1
- package/dist/sdk.js +1 -0
- package/dist/sdk.js.map +1 -1
- package/package.json +7 -6
- package/src/authoring/raw.ts +3 -2
- package/src/client.ts +75 -23
- package/src/discovery.ts +13 -0
- package/src/examples/lifiZap.ts +4 -0
- package/src/examples/lifiZapAsync.ts +88 -0
- package/src/examples/routeTokenPair.ts +58 -0
- package/src/examples/run.ts +30 -5
- package/src/generated/config.generated.ts +21 -3
- package/src/generated/materialisers.generated.ts +0 -12
- package/src/generated/operations.generated.ts +29 -221
- package/src/index.ts +23 -0
- package/src/routeAmount.ts +61 -0
- package/src/sdk.ts +17 -0
- 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/manualRelayContinuation.ts +0 -161
- package/src/examples/staged/morphoBlueBorrow.ts +0 -93
- package/src/examples/staged/morphoBlueRepay.ts +0 -132
- package/src/examples/staged/registry.ts +0 -89
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
// AUTO-GENERATED from manifest.json — do not edit by hand.
|
|
2
2
|
// Regenerate with: yarn workspace @lifi/composer-sdk generate
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
AnyBindable,
|
|
6
|
-
FlowBuilderInternal,
|
|
7
|
-
} from '../authoring/FlowBuilderCore.js';
|
|
4
|
+
import type { FlowBuilderInternal } from '../authoring/FlowBuilderCore.js';
|
|
8
5
|
import type { Bindable, OutputHandle } from '../authoring/handles.js';
|
|
9
6
|
import type {
|
|
10
7
|
CoreCallResult,
|
|
@@ -20,11 +17,9 @@ import type { TypedGuard } from '../types.js';
|
|
|
20
17
|
import type {
|
|
21
18
|
AaveBorrowConfig,
|
|
22
19
|
AaveClaimRewardsConfig,
|
|
23
|
-
AaveGetHealthFactorConfig,
|
|
24
20
|
AaveRepayConfig,
|
|
25
21
|
AaveRepayWithATokensConfig,
|
|
26
22
|
AaveSetEModeConfig,
|
|
27
|
-
ContinuationAssertReadyConfig,
|
|
28
23
|
CoreApproveConfig,
|
|
29
24
|
CoreAsResourceConfig,
|
|
30
25
|
CoreBalanceOfConfig,
|
|
@@ -48,16 +43,11 @@ import type {
|
|
|
48
43
|
InvariantNeqConfig,
|
|
49
44
|
InvariantNumericConfig,
|
|
50
45
|
InvariantNumericInRangeConfig,
|
|
51
|
-
LifiFlashloanRepayConfig,
|
|
52
46
|
LifiSwapConfig,
|
|
47
|
+
LifiZapAsyncConfig,
|
|
53
48
|
LifiZapConfig,
|
|
54
|
-
MorphoBlueBorrowConfig,
|
|
55
|
-
MorphoBlueGetPositionConfig,
|
|
56
|
-
MorphoBlueRepayConfig,
|
|
57
49
|
MorphoBlueSupplyCollateralConfig,
|
|
58
|
-
MorphoBlueSupplyConfig,
|
|
59
50
|
MorphoBlueWithdrawCollateralConfig,
|
|
60
|
-
MorphoBlueWithdrawConfig,
|
|
61
51
|
ParaswapBuyConfig,
|
|
62
52
|
} from './config.generated.js';
|
|
63
53
|
|
|
@@ -508,13 +498,6 @@ export interface AaveSetEModeArgs {
|
|
|
508
498
|
readonly guards?: readonly TypedGuard<never>[];
|
|
509
499
|
}
|
|
510
500
|
|
|
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
501
|
/** 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
502
|
export interface MorphoBlueSupplyCollateralArgs {
|
|
520
503
|
readonly bind: {
|
|
@@ -531,86 +514,26 @@ export interface MorphoBlueWithdrawCollateralArgs {
|
|
|
531
514
|
readonly guards?: readonly TypedGuard<'collateralWithdrawn'>[];
|
|
532
515
|
}
|
|
533
516
|
|
|
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
517
|
/** Route tokens into a DeFi protocol position via the edge catalog */
|
|
606
518
|
export interface LifiZapArgs {
|
|
607
519
|
readonly bind: {
|
|
608
520
|
readonly amountIn: Bindable<'resource'>;
|
|
521
|
+
readonly recipient?: Bindable<'address'>;
|
|
609
522
|
};
|
|
610
523
|
readonly config: LifiZapConfig;
|
|
611
524
|
readonly guards?: readonly TypedGuard<'amountOut'>[];
|
|
612
525
|
}
|
|
613
526
|
|
|
527
|
+
/** Route tokens into a DeFi protocol position whose output becomes available after the initiating transaction settles */
|
|
528
|
+
export interface LifiZapAsyncArgs {
|
|
529
|
+
readonly bind: {
|
|
530
|
+
readonly amountIn: Bindable<'resource'>;
|
|
531
|
+
readonly recipient: Bindable<'address'>;
|
|
532
|
+
};
|
|
533
|
+
readonly config: LifiZapAsyncConfig;
|
|
534
|
+
readonly guards?: readonly TypedGuard<never>[];
|
|
535
|
+
}
|
|
536
|
+
|
|
614
537
|
/** 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`. */
|
|
615
538
|
export interface ParaswapBuyArgs {
|
|
616
539
|
readonly bind: {
|
|
@@ -706,46 +629,16 @@ export interface AaveClaimRewardsOutputs {
|
|
|
706
629
|
readonly claimedAmount: OutputHandle<'uint256'>;
|
|
707
630
|
}
|
|
708
631
|
|
|
709
|
-
export interface AaveGetHealthFactorOutputs {
|
|
710
|
-
readonly healthFactor: OutputHandle<'uint256'>;
|
|
711
|
-
}
|
|
712
|
-
|
|
713
632
|
export interface MorphoBlueWithdrawCollateralOutputs {
|
|
714
633
|
readonly withdrawn: OutputHandle<'resource'>;
|
|
715
634
|
readonly collateralWithdrawn: OutputHandle<'uint256'>;
|
|
716
635
|
}
|
|
717
636
|
|
|
718
|
-
export interface
|
|
719
|
-
readonly
|
|
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'>;
|
|
637
|
+
export interface LifiZapOutputs {
|
|
638
|
+
readonly amountOut: OutputHandle<'resource'>;
|
|
746
639
|
}
|
|
747
640
|
|
|
748
|
-
export interface
|
|
641
|
+
export interface LifiZapAsyncOutputs {
|
|
749
642
|
readonly amountOut: OutputHandle<'resource'>;
|
|
750
643
|
}
|
|
751
644
|
|
|
@@ -859,13 +752,13 @@ export type GeneratedOps = {
|
|
|
859
752
|
readonly lifi: {
|
|
860
753
|
/** Swap tokens via the LI.FI aggregator API — original id: "lifi.swap" */
|
|
861
754
|
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
755
|
/** Route tokens into a DeFi protocol position via the edge catalog — original id: "lifi.zap" */
|
|
868
756
|
readonly zap: (nodeId: string, args: LifiZapArgs) => LifiZapOutputs;
|
|
757
|
+
/** Route tokens into a DeFi protocol position whose output becomes available after the initiating transaction settles — original id: "lifi.zapAsync" */
|
|
758
|
+
readonly zapAsync: (
|
|
759
|
+
nodeId: string,
|
|
760
|
+
args: LifiZapAsyncArgs,
|
|
761
|
+
) => LifiZapAsyncOutputs;
|
|
869
762
|
};
|
|
870
763
|
readonly invariant: {
|
|
871
764
|
/** Assert that an account holds at least a minimum token balance — original id: "invariant.balanceAtLeast" */
|
|
@@ -948,11 +841,6 @@ export type GeneratedOps = {
|
|
|
948
841
|
) => AaveClaimRewardsOutputs;
|
|
949
842
|
/** 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
843
|
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
844
|
};
|
|
957
845
|
readonly morphoBlue: {
|
|
958
846
|
/** 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 +853,6 @@ export type GeneratedOps = {
|
|
|
965
853
|
nodeId: string,
|
|
966
854
|
args: MorphoBlueWithdrawCollateralArgs,
|
|
967
855
|
) => 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
856
|
};
|
|
1006
857
|
readonly paraswap: {
|
|
1007
858
|
/** 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" */
|
|
@@ -1084,8 +935,8 @@ export const bindGeneratedOps = (
|
|
|
1084
935
|
call: <TSig extends string>(nodeId: string, args: CoreCallArgs<TSig>) => {
|
|
1085
936
|
const wire = buildCallWireFormat({
|
|
1086
937
|
resource: args.resource,
|
|
1087
|
-
bind: args.bind
|
|
1088
|
-
config: args.config
|
|
938
|
+
bind: args.bind,
|
|
939
|
+
config: args.config,
|
|
1089
940
|
guards: args.guards,
|
|
1090
941
|
});
|
|
1091
942
|
return builder.call(nodeId, wire.op, wire, {
|
|
@@ -1100,8 +951,8 @@ export const bindGeneratedOps = (
|
|
|
1100
951
|
nodeId,
|
|
1101
952
|
'core.staticCall',
|
|
1102
953
|
buildStaticCallWireFormat({
|
|
1103
|
-
bind: args.bind
|
|
1104
|
-
config: args.config
|
|
954
|
+
bind: args.bind,
|
|
955
|
+
config: args.config,
|
|
1105
956
|
guards: args.guards,
|
|
1106
957
|
}),
|
|
1107
958
|
{ result: 'uint256' } as const,
|
|
@@ -1123,12 +974,14 @@ export const bindGeneratedOps = (
|
|
|
1123
974
|
amountOut: 'resource',
|
|
1124
975
|
unspentIn: 'resource',
|
|
1125
976
|
} as const),
|
|
1126
|
-
flashloanRepay: (nodeId: string, args: LifiFlashloanRepayArgs) =>
|
|
1127
|
-
builder.call(nodeId, 'lifi.flashloanRepay', args, {}),
|
|
1128
977
|
zap: (nodeId: string, args: LifiZapArgs) =>
|
|
1129
978
|
builder.call(nodeId, 'lifi.zap', args, {
|
|
1130
979
|
amountOut: 'resource',
|
|
1131
980
|
} as const),
|
|
981
|
+
zapAsync: (nodeId: string, args: LifiZapAsyncArgs) =>
|
|
982
|
+
builder.call(nodeId, 'lifi.zapAsync', args, {
|
|
983
|
+
amountOut: 'resource',
|
|
984
|
+
} as const),
|
|
1132
985
|
},
|
|
1133
986
|
invariant: {
|
|
1134
987
|
balanceAtLeast: (nodeId: string, args: InvariantBalanceAtLeastArgs) =>
|
|
@@ -1227,10 +1080,6 @@ export const bindGeneratedOps = (
|
|
|
1227
1080
|
} as const),
|
|
1228
1081
|
setEMode: (nodeId: string, args: AaveSetEModeArgs) =>
|
|
1229
1082
|
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
1083
|
},
|
|
1235
1084
|
morphoBlue: {
|
|
1236
1085
|
supplyCollateral: (nodeId: string, args: MorphoBlueSupplyCollateralArgs) =>
|
|
@@ -1243,47 +1092,6 @@ export const bindGeneratedOps = (
|
|
|
1243
1092
|
withdrawn: 'resource',
|
|
1244
1093
|
collateralWithdrawn: 'uint256',
|
|
1245
1094
|
} 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
1095
|
},
|
|
1288
1096
|
paraswap: {
|
|
1289
1097
|
buy: (nodeId: string, args: ParaswapBuyArgs) =>
|
package/src/index.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type {
|
|
|
41
41
|
ComposeCompileSuccessData,
|
|
42
42
|
ComposeContinuation,
|
|
43
43
|
ComposeErrorKind,
|
|
44
|
+
ComposeRouteRequest,
|
|
44
45
|
ComposeTransactionRequest,
|
|
45
46
|
FailedPreparedOp,
|
|
46
47
|
Flow,
|
|
@@ -52,6 +53,9 @@ export type {
|
|
|
52
53
|
PriceImpact,
|
|
53
54
|
Ref,
|
|
54
55
|
Resource,
|
|
56
|
+
RouteAmount,
|
|
57
|
+
RouteAmountAll,
|
|
58
|
+
RouteAmountExact,
|
|
55
59
|
SimulationPolicy,
|
|
56
60
|
SimulationRevert,
|
|
57
61
|
SolType,
|
|
@@ -108,6 +112,7 @@ import * as materialisersMod from './generated/materialisers.generated.js';
|
|
|
108
112
|
import * as preconditionsMod from './generated/preconditions.generated.js';
|
|
109
113
|
import * as rawMod from './raw.js';
|
|
110
114
|
import * as resourcesMod from './resources.js';
|
|
115
|
+
import * as routeAmountMod from './routeAmount.js';
|
|
111
116
|
|
|
112
117
|
/**
|
|
113
118
|
* Guard factories for protecting operation outputs (e.g. slippage tolerance).
|
|
@@ -168,6 +173,24 @@ export const preconditions: typeof preconditionsMod = preconditionsMod;
|
|
|
168
173
|
* ```
|
|
169
174
|
*/
|
|
170
175
|
export const resources: typeof resourcesMod = resourcesMod;
|
|
176
|
+
/**
|
|
177
|
+
* Amount constructors for {@link ComposeSdk.route}. Use
|
|
178
|
+
* {@link routeAmount.exact} to spend a fixed amount of the `fromToken`, and
|
|
179
|
+
* {@link routeAmount.all} to spend the signer's whole balance.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* // USDC into the Aave v3 aEthUSDC position — one routing-catalog edge.
|
|
184
|
+
* const result = await sdk.route({
|
|
185
|
+
* chainId: 1,
|
|
186
|
+
* fromToken: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
187
|
+
* toToken: '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c',
|
|
188
|
+
* amount: routeAmount.exact(1_000_000n),
|
|
189
|
+
* signer: '0xYourAddress...',
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
export const routeAmount: typeof routeAmountMod = routeAmountMod;
|
|
171
194
|
export * from './generated/config.generated.js';
|
|
172
195
|
|
|
173
196
|
/**
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { RouteAmountAll, RouteAmountExact } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
// Constructors for the `amount` member of a `ComposeRouteRequest`. The wire
|
|
4
|
+
// union is discriminated by `type` and — deliberately, because the two variants
|
|
5
|
+
// mean different things — names its payload field differently in each variant:
|
|
6
|
+
// `amount` is the sum actually moved, `simAmount` is only a quoting stand-in for
|
|
7
|
+
// a balance resolved on-chain. These helpers keep call sites from having to
|
|
8
|
+
// remember which name goes with which discriminant.
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Spend an exact amount of the route's `fromToken`.
|
|
12
|
+
*
|
|
13
|
+
* @param amount - Amount in the token's smallest unit. `bigint` is serialised
|
|
14
|
+
* to a decimal string when the request is sent.
|
|
15
|
+
* @returns The `EXACT` member of the route amount union.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const result = await sdk.route({
|
|
20
|
+
* chainId: 1,
|
|
21
|
+
* fromToken: NATIVE_ETH,
|
|
22
|
+
* toToken: WETH,
|
|
23
|
+
* amount: routeAmount.exact(10n ** 17n), // 0.1 ETH, wrapped
|
|
24
|
+
* signer: OWNER,
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const exact = (amount: bigint | string): RouteAmountExact => ({
|
|
29
|
+
type: 'EXACT',
|
|
30
|
+
amount,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Spend the signer's entire `fromToken` balance, resolved on-chain at execution
|
|
35
|
+
* time.
|
|
36
|
+
*
|
|
37
|
+
* Not supported when `fromToken` is the chain's native sentinel — the server
|
|
38
|
+
* rejects it. A gas coin is sent via `msg.value`, so there is no on-chain
|
|
39
|
+
* balance to sweep; use {@link exact} for native inputs.
|
|
40
|
+
*
|
|
41
|
+
* @param simAmount - A realistic estimate of that balance, in the token's
|
|
42
|
+
* smallest unit. The server quotes and simulates against this value, so it
|
|
43
|
+
* shapes the returned quote and preconditions — but the amount actually moved
|
|
44
|
+
* is whatever the balance turns out to be.
|
|
45
|
+
* @returns The `ALL` member of the route amount union.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const result = await sdk.route({
|
|
50
|
+
* chainId: 1,
|
|
51
|
+
* fromToken: USDC,
|
|
52
|
+
* toToken: A_ETH_USDC,
|
|
53
|
+
* amount: routeAmount.all(1_000_000n), // estimate: ~1 USDC on hand
|
|
54
|
+
* signer: OWNER,
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export const all = (simAmount: bigint | string): RouteAmountAll => ({
|
|
59
|
+
type: 'ALL',
|
|
60
|
+
simAmount,
|
|
61
|
+
});
|
package/src/sdk.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ComposeCompileRequest,
|
|
3
3
|
ComposeCompileResult,
|
|
4
|
+
ComposeRouteRequest,
|
|
4
5
|
InputSpec,
|
|
5
6
|
SimulateRequest,
|
|
6
7
|
SimulateResult,
|
|
@@ -119,6 +120,21 @@ export interface ComposeSdk {
|
|
|
119
120
|
flow: TypedFlow<T>,
|
|
120
121
|
run: ComposeRunInput<T>,
|
|
121
122
|
) => ComposeCompileRequest;
|
|
123
|
+
/**
|
|
124
|
+
* Compiles a token pair on one chain — as of today a single zap step over
|
|
125
|
+
* one routing-catalog edge. Thin pass-through to
|
|
126
|
+
* {@link ComposeClient.route}; see it for the current single-step limit,
|
|
127
|
+
* when to prefer `flow(...).compile(...)`, the `success` / `partial`
|
|
128
|
+
* discrimination, and error behaviour. Build the `amount` with
|
|
129
|
+
* `routeAmount.exact(...)` / `routeAmount.all(...)`.
|
|
130
|
+
*
|
|
131
|
+
* @param request - The from/to token pair, amount, signer, and route options.
|
|
132
|
+
* @returns A discriminated result: `status: 'success'` or `status: 'partial'`.
|
|
133
|
+
* @throws {@link ComposeError} on network, validation, or server errors.
|
|
134
|
+
*/
|
|
135
|
+
readonly route: (
|
|
136
|
+
request: ComposeRouteRequest,
|
|
137
|
+
) => Promise<ComposeCompileResult>;
|
|
122
138
|
/**
|
|
123
139
|
* Simulates a raw, pre-encoded transaction. Thin pass-through to
|
|
124
140
|
* {@link ComposeClient.simulate}; see it for the `ok` / `revert` / `error`
|
|
@@ -188,6 +204,7 @@ export const createComposeSdk = (options: ComposeSdkOptions): ComposeSdk => {
|
|
|
188
204
|
client: composeClient,
|
|
189
205
|
flow,
|
|
190
206
|
request,
|
|
207
|
+
route: composeClient.route,
|
|
191
208
|
simulate: composeClient.simulate,
|
|
192
209
|
};
|
|
193
210
|
};
|
|
@@ -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
|
-
};
|