@lifi/composer-sdk 0.2.0-staging.5 → 0.2.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.
- package/README.md +81 -0
- package/dist/client.cjs +38 -6
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +25 -1
- package/dist/client.d.ts +25 -1
- package/dist/client.js +41 -6
- package/dist/client.js.map +1 -1
- package/dist/errors.cjs +4 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +6 -1
- package/dist/errors.js.map +1 -1
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +44 -7
- package/dist/generated/config.generated.d.ts +44 -7
- 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 +1 -30
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +2 -94
- package/dist/generated/operations.generated.d.ts +2 -94
- package/dist/generated/operations.generated.js +1 -30
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/index.cjs +8 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +8 -0
- 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/responseSchemas.cjs +110 -0
- package/dist/responseSchemas.cjs.map +1 -0
- package/dist/responseSchemas.d.cts +36 -0
- package/dist/responseSchemas.d.ts +36 -0
- package/dist/responseSchemas.js +74 -0
- package/dist/responseSchemas.js.map +1 -0
- package/dist/run/simulate.cjs +41 -0
- package/dist/run/simulate.cjs.map +1 -0
- package/dist/run/simulate.d.cts +59 -0
- package/dist/run/simulate.d.ts +59 -0
- package/dist/run/simulate.js +17 -0
- package/dist/run/simulate.js.map +1 -0
- package/dist/sdk.cjs +6 -1
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.d.cts +13 -1
- package/dist/sdk.d.ts +13 -1
- package/dist/sdk.js +6 -1
- package/dist/sdk.js.map +1 -1
- package/package.json +7 -5
- package/src/client.ts +86 -11
- package/src/errors.ts +8 -10
- package/src/examples/simulateCompiledSwap.ts +76 -0
- package/src/examples/simulateRawTransaction.ts +39 -0
- package/src/generated/config.generated.ts +179 -6
- package/src/generated/materialisers.generated.ts +0 -12
- package/src/generated/operations.generated.ts +0 -177
- package/src/index.ts +19 -0
- package/src/responseSchemas.ts +143 -0
- package/src/run/simulate.ts +78 -0
- package/src/sdk.ts +20 -1
- 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/morphoBlueBorrow.ts +0 -93
- package/src/examples/staged/morphoBlueRepay.ts +0 -132
- package/src/examples/staged/registry.ts +0 -80
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
import { BASE_URL } from '../config.js';
|
|
6
|
-
|
|
7
|
-
// Morpho Blue WETH/USDC market on Base (chainId 8453).
|
|
8
|
-
// The Morpho singleton address (0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb)
|
|
9
|
-
// is the default `morpho` config field and is read from compose-builtins.
|
|
10
|
-
const ADAPTIVE_CURVE_IRM_BASE = '0x46415998764C29aB2a25CbeA6254146D50D22687';
|
|
11
|
-
const BASE_USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
12
|
-
const BASE_WETH = '0x4200000000000000000000000000000000000006';
|
|
13
|
-
const WETH_USDC_ORACLE = '0xFEa2D58cEfCb9fcb597723c6bAE66fFE4193aFE4';
|
|
14
|
-
const WETH_USDC_LLTV = '860000000000000000'; // 0.86e18
|
|
15
|
-
|
|
16
|
-
const WETH_USDC_MARKET = {
|
|
17
|
-
loanToken: BASE_USDC,
|
|
18
|
-
collateralToken: BASE_WETH,
|
|
19
|
-
oracle: WETH_USDC_ORACLE,
|
|
20
|
-
irm: ADAPTIVE_CURVE_IRM_BASE,
|
|
21
|
-
lltv: WETH_USDC_LLTV,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export interface MorphoBlueBorrowInput {
|
|
25
|
-
readonly owner: Address;
|
|
26
|
-
readonly collateralAmount: `${bigint}`;
|
|
27
|
-
readonly borrowAmount: `${bigint}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Open a leveraged-borrow position on the Base Morpho Blue WETH/USDC market.
|
|
32
|
-
*
|
|
33
|
-
* - `morphoBlue.supplyCollateral` debits the proxy's WETH and credits
|
|
34
|
-
* `Morpho.position(WETH_USDC_MARKET_ID, proxy).collateral`. There is no
|
|
35
|
-
* receipt token — collateral is non-transferable accounting state.
|
|
36
|
-
* - `morphoBlue.borrow` mints debt shares against that collateral and
|
|
37
|
-
* transfers USDC to the proxy. The borrowed asset is exposed as the
|
|
38
|
-
* `borrowed` Resource port for downstream nodes.
|
|
39
|
-
* - The flow sweeps the borrowed USDC back to the signer's wallet via
|
|
40
|
-
* `sweepTo` on the request.
|
|
41
|
-
*/
|
|
42
|
-
export const buildMorphoBlueBorrow = ({
|
|
43
|
-
owner,
|
|
44
|
-
collateralAmount,
|
|
45
|
-
borrowAmount,
|
|
46
|
-
}: MorphoBlueBorrowInput): {
|
|
47
|
-
flow: Flow;
|
|
48
|
-
request: ComposeCompileRequest;
|
|
49
|
-
} => {
|
|
50
|
-
const sdk = createComposeSdk({ baseUrl: BASE_URL });
|
|
51
|
-
|
|
52
|
-
const builder = sdk.flow(8453, {
|
|
53
|
-
name: 'morpho-blue-borrow-weth-usdc',
|
|
54
|
-
inputs: {
|
|
55
|
-
assetIn: resources.erc20(BASE_WETH, 8453),
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
builder.morphoBlue.supplyCollateral('supply-collateral', {
|
|
60
|
-
bind: {
|
|
61
|
-
assetIn: builder.inputs.assetIn,
|
|
62
|
-
},
|
|
63
|
-
config: {
|
|
64
|
-
marketParams: WETH_USDC_MARKET,
|
|
65
|
-
mode: 'exact',
|
|
66
|
-
},
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
builder.morphoBlue.borrow('borrow', {
|
|
70
|
-
bind: {},
|
|
71
|
-
config: {
|
|
72
|
-
marketParams: WETH_USDC_MARKET,
|
|
73
|
-
amount: borrowAmount,
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
const flow = builder.build();
|
|
78
|
-
|
|
79
|
-
const request = sdk.request(flow, {
|
|
80
|
-
signer: owner,
|
|
81
|
-
inputs: {
|
|
82
|
-
assetIn: materialisers.directDeposit({ amount: collateralAmount }),
|
|
83
|
-
},
|
|
84
|
-
// Sweep the borrowed USDC back to the signer.
|
|
85
|
-
sweepTo: builder.context.sender,
|
|
86
|
-
// The WETH collateral becomes unpriced Morpho position state (no receipt
|
|
87
|
-
// token), so the default 500 bps price-impact check reads any safe borrow
|
|
88
|
-
// (LLTV caps at 86%) as a loss. 0 skips the check.
|
|
89
|
-
maxPriceImpactBps: 0,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return { flow, request };
|
|
93
|
-
};
|
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
import { BASE_URL } from '../config.js';
|
|
6
|
-
|
|
7
|
-
// Morpho Blue WETH/USDC market on Base (chainId 8453).
|
|
8
|
-
const ADAPTIVE_CURVE_IRM_BASE = '0x46415998764C29aB2a25CbeA6254146D50D22687';
|
|
9
|
-
const BASE_USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';
|
|
10
|
-
const BASE_WETH = '0x4200000000000000000000000000000000000006';
|
|
11
|
-
const WETH_USDC_ORACLE = '0xFEa2D58cEfCb9fcb597723c6bAE66fFE4193aFE4';
|
|
12
|
-
const WETH_USDC_LLTV = '860000000000000000';
|
|
13
|
-
|
|
14
|
-
const WETH_USDC_MARKET = {
|
|
15
|
-
loanToken: BASE_USDC,
|
|
16
|
-
collateralToken: BASE_WETH,
|
|
17
|
-
oracle: WETH_USDC_ORACLE,
|
|
18
|
-
irm: ADAPTIVE_CURVE_IRM_BASE,
|
|
19
|
-
lltv: WETH_USDC_LLTV,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export interface MorphoBlueRepayInput {
|
|
23
|
-
readonly owner: Address;
|
|
24
|
-
/** WETH supplied as collateral for the in-flow borrow (18 dp). */
|
|
25
|
-
readonly collateralAmount: `${bigint}`;
|
|
26
|
-
/** USDC borrowed against the collateral, then repaid by this flow (6 dp). */
|
|
27
|
-
readonly borrowAmount: `${bigint}`;
|
|
28
|
-
/**
|
|
29
|
-
* USDC deposited to repay the debt (6 dp). Must exceed `borrowAmount`:
|
|
30
|
-
* Morpho's share rounding can leave the debt a wei above the borrowed
|
|
31
|
-
* amount, so the `max`-mode repay needs a little headroom. The leftover
|
|
32
|
-
* surfaces on the `residual` port.
|
|
33
|
-
*/
|
|
34
|
-
readonly repayAmount: `${bigint}`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Open and close a Morpho Blue WETH/USDC position on Base in one flow —
|
|
39
|
-
* a self-contained supplyCollateral → borrow → repay → withdrawCollateral
|
|
40
|
-
* round trip that creates the debt it retires.
|
|
41
|
-
*
|
|
42
|
-
* Demonstrates:
|
|
43
|
-
* - `morphoBlue.supplyCollateral` to post WETH (collateral is internal
|
|
44
|
-
* position state — no receipt token).
|
|
45
|
-
* - `morphoBlue.borrow` to mint USDC debt against it.
|
|
46
|
-
* - `morphoBlue.repay` with `mode: 'max'`, which reads the proxy's current
|
|
47
|
-
* `borrowShares` on-chain and repays in shares mode to retire the debt to
|
|
48
|
-
* the wei. Unused USDC surfaces on the `residual` Resource port.
|
|
49
|
-
* - `morphoBlue.withdrawCollateral` to pull the freed WETH once the debt
|
|
50
|
-
* is cleared.
|
|
51
|
-
* - `sweepTo` to return the borrowed USDC, the repay residual, and the
|
|
52
|
-
* freed WETH to the signer.
|
|
53
|
-
*/
|
|
54
|
-
export const buildMorphoBlueRepay = ({
|
|
55
|
-
owner,
|
|
56
|
-
collateralAmount,
|
|
57
|
-
borrowAmount,
|
|
58
|
-
repayAmount,
|
|
59
|
-
}: MorphoBlueRepayInput): {
|
|
60
|
-
flow: Flow;
|
|
61
|
-
request: ComposeCompileRequest;
|
|
62
|
-
} => {
|
|
63
|
-
const sdk = createComposeSdk({ baseUrl: BASE_URL });
|
|
64
|
-
|
|
65
|
-
const builder = sdk.flow(8453, {
|
|
66
|
-
name: 'morpho-blue-repay-usdc-withdraw-weth',
|
|
67
|
-
inputs: {
|
|
68
|
-
collateralIn: resources.erc20(BASE_WETH, 8453),
|
|
69
|
-
repayIn: resources.erc20(BASE_USDC, 8453),
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Post WETH collateral so the proxy can open the debt it will repay.
|
|
74
|
-
builder.morphoBlue.supplyCollateral('supply-collateral', {
|
|
75
|
-
bind: {
|
|
76
|
-
assetIn: builder.inputs.collateralIn,
|
|
77
|
-
},
|
|
78
|
-
config: {
|
|
79
|
-
marketParams: WETH_USDC_MARKET,
|
|
80
|
-
mode: 'exact',
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Borrow USDC against the collateral; the borrowed USDC stays on the
|
|
85
|
-
// proxy as a terminal resource and is swept back to the signer.
|
|
86
|
-
builder.morphoBlue.borrow('borrow', {
|
|
87
|
-
bind: {},
|
|
88
|
-
config: {
|
|
89
|
-
marketParams: WETH_USDC_MARKET,
|
|
90
|
-
amount: borrowAmount,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Retire the just-opened debt from the deposited USDC. mode 'max' reads
|
|
95
|
-
// the live borrowShares and repays in shares mode, clearing the debt to
|
|
96
|
-
// the wei; the unused USDC surfaces on the `residual` port.
|
|
97
|
-
builder.morphoBlue.repay('repay', {
|
|
98
|
-
bind: {
|
|
99
|
-
assetIn: builder.inputs.repayIn,
|
|
100
|
-
onBehalfOf: builder.context.executionAddress,
|
|
101
|
-
},
|
|
102
|
-
config: {
|
|
103
|
-
marketParams: WETH_USDC_MARKET,
|
|
104
|
-
mode: 'max',
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
// The debt is cleared, so the full collateral can be withdrawn. The freed
|
|
109
|
-
// WETH lands on the proxy and is swept to the signer.
|
|
110
|
-
builder.morphoBlue.withdrawCollateral('withdraw-collateral', {
|
|
111
|
-
bind: {},
|
|
112
|
-
config: {
|
|
113
|
-
marketParams: WETH_USDC_MARKET,
|
|
114
|
-
amount: collateralAmount,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
const flow = builder.build();
|
|
119
|
-
|
|
120
|
-
const request = sdk.request(flow, {
|
|
121
|
-
signer: owner,
|
|
122
|
-
inputs: {
|
|
123
|
-
collateralIn: materialisers.directDeposit({ amount: collateralAmount }),
|
|
124
|
-
repayIn: materialisers.directDeposit({ amount: repayAmount }),
|
|
125
|
-
},
|
|
126
|
-
// Sweep the borrowed USDC, the repay residual, and the freed WETH back
|
|
127
|
-
// to the signer.
|
|
128
|
-
sweepTo: builder.context.sender,
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return { flow, request };
|
|
132
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// Registry of staged (not-yet-prod) examples for the live runner. This is data,
|
|
2
|
-
// not a runner: src/examples/run.ts imports it via a non-literal dynamic import
|
|
3
|
-
// when invoked with `--staged`, so this file (which references staged definitions)
|
|
4
|
-
// is never pulled into the production type-check. It IS type-checked under
|
|
5
|
-
// tsconfig.staged.json (see verify:staged).
|
|
6
|
-
//
|
|
7
|
-
// Running these requires the SDK regenerated with `--staged`; the example:staged
|
|
8
|
-
// wrapper does that and restores production afterward.
|
|
9
|
-
import type { ComposeCompileRequest } from '@lifi/compose-spec';
|
|
10
|
-
|
|
11
|
-
import { OWNER, RECIPIENT } from '../config.js';
|
|
12
|
-
|
|
13
|
-
import { buildAaveBorrow } from './aaveBorrow.js';
|
|
14
|
-
import { buildAaveDebtRebalanceExactOut } from './aaveDebtRebalanceExactOut.js';
|
|
15
|
-
import { buildAaveHealthFactorExplode } from './aaveHealthFactorExplode.js';
|
|
16
|
-
import { buildAaveToMorphoDebtMigration } from './aaveToMorphoDebtMigration.js';
|
|
17
|
-
import { buildAaveToMorphoDebtMigrationWithSwap } from './aaveToMorphoDebtMigrationWithSwap.js';
|
|
18
|
-
import { buildAaveToMorphoDebtMigrationWithSwapExactOut } from './aaveToMorphoDebtMigrationWithSwapExactOut.js';
|
|
19
|
-
import { buildTrivialFlashloanRepay } from './flashloanRepay.js';
|
|
20
|
-
import { buildMorphoBlueBorrow } from './morphoBlueBorrow.js';
|
|
21
|
-
import { buildMorphoBlueRepay } from './morphoBlueRepay.js';
|
|
22
|
-
|
|
23
|
-
export const STAGED_EXAMPLES: Record<string, () => ComposeCompileRequest> = {
|
|
24
|
-
'aave-borrow': () =>
|
|
25
|
-
buildAaveBorrow({
|
|
26
|
-
owner: OWNER,
|
|
27
|
-
recipient: RECIPIENT,
|
|
28
|
-
collateralAmount: '1000000000',
|
|
29
|
-
borrowAmount: '500000000',
|
|
30
|
-
}).request,
|
|
31
|
-
'aave-hf-explode': () =>
|
|
32
|
-
buildAaveHealthFactorExplode({ signer: OWNER }).request,
|
|
33
|
-
'morpho-borrow': () =>
|
|
34
|
-
buildMorphoBlueBorrow({
|
|
35
|
-
owner: OWNER,
|
|
36
|
-
collateralAmount: '1000000000000000000',
|
|
37
|
-
borrowAmount: '1200000000',
|
|
38
|
-
}).request,
|
|
39
|
-
'morpho-repay': () =>
|
|
40
|
-
buildMorphoBlueRepay({
|
|
41
|
-
owner: OWNER,
|
|
42
|
-
collateralAmount: '1000000000000000000',
|
|
43
|
-
borrowAmount: '500000000',
|
|
44
|
-
repayAmount: '501000000',
|
|
45
|
-
}).request,
|
|
46
|
-
'debt-rebalance': () =>
|
|
47
|
-
buildAaveDebtRebalanceExactOut({
|
|
48
|
-
owner: OWNER,
|
|
49
|
-
collateralAmount: '1000000000000000000',
|
|
50
|
-
debtAmount: '1000000000',
|
|
51
|
-
newDebtBorrowAmount: '965000000',
|
|
52
|
-
}).request,
|
|
53
|
-
'debt-migration-swap-exact-out': () =>
|
|
54
|
-
buildAaveToMorphoDebtMigrationWithSwapExactOut({
|
|
55
|
-
owner: OWNER,
|
|
56
|
-
collateralAmount: '1000000000000000000',
|
|
57
|
-
debtAmount: '1000000000',
|
|
58
|
-
morphoBorrowAmount: '975000000',
|
|
59
|
-
}).request,
|
|
60
|
-
'flashloan-repay': () =>
|
|
61
|
-
buildTrivialFlashloanRepay({
|
|
62
|
-
owner: OWNER,
|
|
63
|
-
amount: '10000000000',
|
|
64
|
-
fee: '5000000',
|
|
65
|
-
}).request,
|
|
66
|
-
'debt-migration': () =>
|
|
67
|
-
buildAaveToMorphoDebtMigration({
|
|
68
|
-
owner: OWNER,
|
|
69
|
-
collateralAmount: '1000000000000000000',
|
|
70
|
-
debtAmount: '1000000000',
|
|
71
|
-
debtFlashloanFee: '500000',
|
|
72
|
-
}).request,
|
|
73
|
-
'debt-migration-swap': () =>
|
|
74
|
-
buildAaveToMorphoDebtMigrationWithSwap({
|
|
75
|
-
owner: OWNER,
|
|
76
|
-
collateralAmount: '1000000000000000000',
|
|
77
|
-
debtAmount: '1000000000',
|
|
78
|
-
morphoBorrowAmount: '1100000000',
|
|
79
|
-
}).request,
|
|
80
|
-
};
|