@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.
- package/README.md +4 -0
- package/dist/authoring/FlowBuilderCore.cjs +17 -4
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
- package/dist/authoring/FlowBuilderCore.d.cts +12 -4
- package/dist/authoring/FlowBuilderCore.d.ts +12 -4
- package/dist/authoring/FlowBuilderCore.js +20 -4
- package/dist/authoring/FlowBuilderCore.js.map +1 -1
- package/dist/authoring/handles.cjs.map +1 -1
- package/dist/authoring/handles.d.cts +35 -1
- package/dist/authoring/handles.d.ts +35 -1
- package/dist/authoring/handles.js.map +1 -1
- package/dist/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +500 -6
- package/dist/generated/config.generated.d.ts +500 -6
- package/dist/generated/operations.generated.cjs +36 -1
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +101 -5
- package/dist/generated/operations.generated.d.ts +101 -5
- package/dist/generated/operations.generated.js +36 -1
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/authoring/FlowBuilderCore.ts +59 -19
- package/src/authoring/handles.ts +67 -0
- package/src/examples/aaveBorrow.ts +129 -0
- package/src/examples/aaveHealthFactorExplode.ts +63 -0
- package/src/examples/morphoBlueBorrow.ts +94 -0
- package/src/examples/morphoBlueRepay.ts +133 -0
- package/src/examples/run.ts +30 -0
- package/src/examples/splitAndZap.ts +9 -8
- package/src/generated/config.generated.ts +516 -5
- package/src/generated/operations.generated.ts +211 -3
- package/src/index.ts +5 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
import { createComposeSdk, materialisers, resources } from '../index.js';
|
|
4
|
+
import type { Address } from '../types.js';
|
|
5
|
+
|
|
6
|
+
import { API_KEY, BASE_URL } from './config.js';
|
|
7
|
+
|
|
8
|
+
// Morpho Blue WETH/USDC market on Base (chainId 8453).
|
|
9
|
+
const ADAPTIVE_CURVE_IRM_BASE = '0x46415998764C29aB2a25CbeA6254146D50D22687';
|
|
10
|
+
const BASE_USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
11
|
+
const BASE_WETH = '0x4200000000000000000000000000000000000006';
|
|
12
|
+
const WETH_USDC_ORACLE = '0xFEa2D58cEfCb9fcb597723c6bAE66fFE4193aFE4';
|
|
13
|
+
const WETH_USDC_LLTV = '860000000000000000';
|
|
14
|
+
|
|
15
|
+
const WETH_USDC_MARKET = {
|
|
16
|
+
loanToken: BASE_USDC,
|
|
17
|
+
collateralToken: BASE_WETH,
|
|
18
|
+
oracle: WETH_USDC_ORACLE,
|
|
19
|
+
irm: ADAPTIVE_CURVE_IRM_BASE,
|
|
20
|
+
lltv: WETH_USDC_LLTV,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export interface MorphoBlueRepayInput {
|
|
24
|
+
readonly owner: Address;
|
|
25
|
+
/** WETH supplied as collateral for the in-flow borrow (18 dp). */
|
|
26
|
+
readonly collateralAmount: `${bigint}`;
|
|
27
|
+
/** USDC borrowed against the collateral, then repaid by this flow (6 dp). */
|
|
28
|
+
readonly borrowAmount: `${bigint}`;
|
|
29
|
+
/**
|
|
30
|
+
* USDC deposited to repay the debt (6 dp). Must exceed `borrowAmount`:
|
|
31
|
+
* Morpho's share rounding can leave the debt a wei above the borrowed
|
|
32
|
+
* amount, so the `max`-mode repay needs a little headroom. The leftover
|
|
33
|
+
* surfaces on the `residual` port.
|
|
34
|
+
*/
|
|
35
|
+
readonly repayAmount: `${bigint}`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Open and close a Morpho Blue WETH/USDC position on Base in one flow —
|
|
40
|
+
* a self-contained supplyCollateral → borrow → repay → withdrawCollateral
|
|
41
|
+
* round trip that creates the debt it retires.
|
|
42
|
+
*
|
|
43
|
+
* Demonstrates:
|
|
44
|
+
* - `morphoBlue.supplyCollateral` to post WETH (collateral is internal
|
|
45
|
+
* position state — no receipt token).
|
|
46
|
+
* - `morphoBlue.borrow` to mint USDC debt against it.
|
|
47
|
+
* - `morphoBlue.repay` with `mode: 'max'`, which reads the proxy's current
|
|
48
|
+
* `borrowShares` on-chain and repays in shares mode to retire the debt to
|
|
49
|
+
* the wei. Unused USDC surfaces on the `residual` Resource port.
|
|
50
|
+
* - `morphoBlue.withdrawCollateral` to pull the freed WETH once the debt
|
|
51
|
+
* is cleared.
|
|
52
|
+
* - `sweepTo` to return the borrowed USDC, the repay residual, and the
|
|
53
|
+
* freed WETH to the signer.
|
|
54
|
+
*/
|
|
55
|
+
export const buildMorphoBlueRepay = ({
|
|
56
|
+
owner,
|
|
57
|
+
collateralAmount,
|
|
58
|
+
borrowAmount,
|
|
59
|
+
repayAmount,
|
|
60
|
+
}: MorphoBlueRepayInput): {
|
|
61
|
+
flow: Flow;
|
|
62
|
+
request: ComposeCompileRequest;
|
|
63
|
+
} => {
|
|
64
|
+
const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
|
|
65
|
+
|
|
66
|
+
const builder = sdk.flow(8453, {
|
|
67
|
+
name: 'morpho-blue-repay-usdc-withdraw-weth',
|
|
68
|
+
inputs: {
|
|
69
|
+
collateralIn: resources.erc20(BASE_WETH, 8453),
|
|
70
|
+
repayIn: resources.erc20(BASE_USDC, 8453),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Post WETH collateral so the proxy can open the debt it will repay.
|
|
75
|
+
builder.morphoBlue.supplyCollateral('supply-collateral', {
|
|
76
|
+
bind: {
|
|
77
|
+
assetIn: builder.inputs.collateralIn,
|
|
78
|
+
},
|
|
79
|
+
config: {
|
|
80
|
+
marketParams: WETH_USDC_MARKET,
|
|
81
|
+
mode: 'exact',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Borrow USDC against the collateral; the borrowed USDC stays on the
|
|
86
|
+
// proxy as a terminal resource and is swept back to the signer.
|
|
87
|
+
builder.morphoBlue.borrow('borrow', {
|
|
88
|
+
bind: {},
|
|
89
|
+
config: {
|
|
90
|
+
marketParams: WETH_USDC_MARKET,
|
|
91
|
+
amount: borrowAmount,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Retire the just-opened debt from the deposited USDC. mode 'max' reads
|
|
96
|
+
// the live borrowShares and repays in shares mode, clearing the debt to
|
|
97
|
+
// the wei; the unused USDC surfaces on the `residual` port.
|
|
98
|
+
builder.morphoBlue.repay('repay', {
|
|
99
|
+
bind: {
|
|
100
|
+
assetIn: builder.inputs.repayIn,
|
|
101
|
+
onBehalfOf: builder.context.executionAddress,
|
|
102
|
+
},
|
|
103
|
+
config: {
|
|
104
|
+
marketParams: WETH_USDC_MARKET,
|
|
105
|
+
mode: 'max',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// The debt is cleared, so the full collateral can be withdrawn. The freed
|
|
110
|
+
// WETH lands on the proxy and is swept to the signer.
|
|
111
|
+
builder.morphoBlue.withdrawCollateral('withdraw-collateral', {
|
|
112
|
+
bind: {},
|
|
113
|
+
config: {
|
|
114
|
+
marketParams: WETH_USDC_MARKET,
|
|
115
|
+
amount: collateralAmount,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const flow = builder.build();
|
|
120
|
+
|
|
121
|
+
const request = sdk.request(flow, {
|
|
122
|
+
signer: owner,
|
|
123
|
+
inputs: {
|
|
124
|
+
collateralIn: materialisers.directDeposit({ amount: collateralAmount }),
|
|
125
|
+
repayIn: materialisers.directDeposit({ amount: repayAmount }),
|
|
126
|
+
},
|
|
127
|
+
// Sweep the borrowed USDC, the repay residual, and the freed WETH back
|
|
128
|
+
// to the signer.
|
|
129
|
+
sweepTo: builder.context.sender,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return { flow, request };
|
|
133
|
+
};
|
package/src/examples/run.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* LIFI_API_KEY=your-key COMPOSER_BASE_URL=https://composer.li.quest yarn example <name>
|
|
9
9
|
*
|
|
10
10
|
* Available examples:
|
|
11
|
+
* aave-borrow — supply USDC to Aave v3, borrow against it with a health-factor guard
|
|
12
|
+
* aave-hf-explode — read the Aave v3 health factor and assert it stays >= 1.0
|
|
11
13
|
* aave-repay — repay an Aave v3 WETH debt by supplying WETH
|
|
12
14
|
* aave-repay-atoken — repay an Aave v3 USDC debt by burning proxy aTokens
|
|
13
15
|
* aave-emode — switch the proxy's Aave v3 eMode category
|
|
@@ -21,6 +23,8 @@
|
|
|
21
23
|
* split-arithmetic — split USDC 70/30 with arithmetic assertions
|
|
22
24
|
* zap — zap USDC into Aave lending position
|
|
23
25
|
* zap-async — zap USDC into an async Aave position (future output)
|
|
26
|
+
* morpho-borrow — supply WETH collateral to Morpho Blue and borrow USDC
|
|
27
|
+
* morpho-repay — open, repay and close a Morpho Blue WETH/USDC position
|
|
24
28
|
* fly-swap — exit a Pendle PT position and swap ALL proceeds to WETH
|
|
25
29
|
* swap-zap — swap WETH to USDC then zap into Aave
|
|
26
30
|
* swap-check — swap WETH to USDC with balance check
|
|
@@ -46,6 +50,8 @@ import type {
|
|
|
46
50
|
import { bigintReplacer } from '../client.js';
|
|
47
51
|
import { type ComposeSdk, createComposeSdk } from '../sdk.js';
|
|
48
52
|
|
|
53
|
+
import { buildAaveBorrow } from './aaveBorrow.js';
|
|
54
|
+
import { buildAaveHealthFactorExplode } from './aaveHealthFactorExplode.js';
|
|
49
55
|
import { buildAaveRepay } from './aaveRepay.js';
|
|
50
56
|
import { buildAaveRepayWithATokens } from './aaveRepayWithATokens.js';
|
|
51
57
|
import { buildAaveSetEMode } from './aaveSetEMode.js';
|
|
@@ -60,6 +66,8 @@ import { buildFlySwapExample } from './flySwap.js';
|
|
|
60
66
|
import { buildLifiSwapExample } from './lifiSwap.js';
|
|
61
67
|
import { buildLifiZapExample } from './lifiZap.js';
|
|
62
68
|
import { buildLifiZapAsyncExample } from './lifiZapAsync.js';
|
|
69
|
+
import { buildMorphoBlueBorrow } from './morphoBlueBorrow.js';
|
|
70
|
+
import { buildMorphoBlueRepay } from './morphoBlueRepay.js';
|
|
63
71
|
import { buildRawCallWithArithmetic } from './rawCallWithArithmetic.js';
|
|
64
72
|
import { buildReadContractState } from './readContractState.js';
|
|
65
73
|
import {
|
|
@@ -81,6 +89,15 @@ const stringifyJson = (value: unknown) =>
|
|
|
81
89
|
JSON.stringify(value, bigintReplacer, 2);
|
|
82
90
|
|
|
83
91
|
const EXAMPLES: Record<string, () => ComposeCompileRequest> = {
|
|
92
|
+
'aave-borrow': () =>
|
|
93
|
+
buildAaveBorrow({
|
|
94
|
+
owner: OWNER,
|
|
95
|
+
recipient: RECIPIENT,
|
|
96
|
+
collateralAmount: '1000000000',
|
|
97
|
+
borrowAmount: '500000000',
|
|
98
|
+
}).request,
|
|
99
|
+
'aave-hf-explode': () =>
|
|
100
|
+
buildAaveHealthFactorExplode({ signer: OWNER }).request,
|
|
84
101
|
'aave-repay': () =>
|
|
85
102
|
buildAaveRepay({
|
|
86
103
|
owner: OWNER,
|
|
@@ -128,6 +145,19 @@ const EXAMPLES: Record<string, () => ComposeCompileRequest> = {
|
|
|
128
145
|
'zap-async': () =>
|
|
129
146
|
buildLifiZapAsyncExample({ owner: OWNER, recipient: RECIPIENT }).request,
|
|
130
147
|
'fly-swap': () => buildFlySwapExample().request,
|
|
148
|
+
'morpho-borrow': () =>
|
|
149
|
+
buildMorphoBlueBorrow({
|
|
150
|
+
owner: OWNER,
|
|
151
|
+
collateralAmount: '1000000000000000000',
|
|
152
|
+
borrowAmount: '1200000000',
|
|
153
|
+
}).request,
|
|
154
|
+
'morpho-repay': () =>
|
|
155
|
+
buildMorphoBlueRepay({
|
|
156
|
+
owner: OWNER,
|
|
157
|
+
collateralAmount: '1000000000000000000',
|
|
158
|
+
borrowAmount: '500000000',
|
|
159
|
+
repayAmount: '501000000',
|
|
160
|
+
}).request,
|
|
131
161
|
'swap-zap': () => buildSwapAndZapExample().request,
|
|
132
162
|
'swap-check': () =>
|
|
133
163
|
buildSwapWithBalanceCheck({ owner: OWNER, amount: '1000000000000000000' })
|
|
@@ -18,8 +18,8 @@ const STEAKHOUSE_USDC = '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB';
|
|
|
18
18
|
* Split USDC 60/40 and zap each portion into a different vault.
|
|
19
19
|
*
|
|
20
20
|
* Demonstrates:
|
|
21
|
-
* - core.
|
|
22
|
-
* -
|
|
21
|
+
* - core.partition to divide a resource into one part per basis-point share
|
|
22
|
+
* - Destructuring the typed `parts` tuple into two independent lifi.zap nodes
|
|
23
23
|
* - Slippage guards on both zap outputs
|
|
24
24
|
*/
|
|
25
25
|
export const buildSplitAndZapExample = (): {
|
|
@@ -35,15 +35,16 @@ export const buildSplitAndZapExample = (): {
|
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
|
|
38
|
+
// Partition USDC 60/40 — one part per `bps` entry. Every part but the last
|
|
39
|
+
// is rounded down; the last takes the remainder.
|
|
40
|
+
const [toAave, toMorpho] = builder.core.partition('split', {
|
|
40
41
|
bind: { source: builder.inputs.amountIn },
|
|
41
|
-
config: { bps: 6000 },
|
|
42
|
-
});
|
|
42
|
+
config: { bps: [6000, 4000] },
|
|
43
|
+
}).parts;
|
|
43
44
|
|
|
44
45
|
// Zap 60% into Aave v3 aEthUSDC.
|
|
45
46
|
builder.lifi.zap('zap-aave', {
|
|
46
|
-
bind: { amountIn:
|
|
47
|
+
bind: { amountIn: toAave },
|
|
47
48
|
config: {
|
|
48
49
|
resourceOut: resources.erc20(A_ETH_USDC, 1),
|
|
49
50
|
},
|
|
@@ -52,7 +53,7 @@ export const buildSplitAndZapExample = (): {
|
|
|
52
53
|
|
|
53
54
|
// Zap 40% into Steakhouse USDC (Morpho).
|
|
54
55
|
builder.lifi.zap('zap-morpho', {
|
|
55
|
-
bind: { amountIn:
|
|
56
|
+
bind: { amountIn: toMorpho },
|
|
56
57
|
config: {
|
|
57
58
|
resourceOut: resources.erc20(STEAKHOUSE_USDC, 1),
|
|
58
59
|
},
|