@lifi/composer-sdk 0.7.0 → 0.8.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 +6 -0
- package/dist/authoring/FlowBuilderCore.cjs +1 -1
- package/dist/authoring/FlowBuilderCore.cjs.map +1 -1
- package/dist/authoring/FlowBuilderCore.js +1 -1
- package/dist/authoring/FlowBuilderCore.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 +77 -35
- package/dist/generated/config.generated.d.ts +77 -35
- package/dist/generated/guards.generated.cjs +6 -0
- package/dist/generated/guards.generated.cjs.map +1 -1
- package/dist/generated/guards.generated.d.cts +1 -1
- package/dist/generated/guards.generated.d.ts +1 -1
- package/dist/generated/guards.generated.js +5 -0
- package/dist/generated/guards.generated.js.map +1 -1
- package/dist/generated/operations.generated.cjs +56 -1
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +155 -2
- package/dist/generated/operations.generated.d.ts +155 -2
- package/dist/generated/operations.generated.js +56 -1
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/{guards.generated-M3VAIevI.d.cts → guards.generated-CDCgYGZo.d.cts} +8 -3
- package/dist/{guards.generated-BPLFwe7y.d.ts → guards.generated-CdYcs4h0.d.ts} +8 -3
- 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 +2 -2
- package/src/authoring/FlowBuilderCore.ts +4 -1
- 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 +43 -0
- package/src/examples/uniswapV2AddLiquidity.ts +106 -0
- package/src/examples/uniswapV3Mint.ts +95 -0
- package/src/generated/config.generated.ts +82 -38
- package/src/generated/guards.generated.ts +9 -0
- package/src/generated/operations.generated.ts +292 -0
- package/src/index.ts +0 -3
|
@@ -0,0 +1,95 @@
|
|
|
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
|
+
|
|
11
|
+
import { API_KEY, BASE_URL } from './config.js';
|
|
12
|
+
|
|
13
|
+
// Uniswap V3 USDC/WETH 0.05% pool on Ethereum mainnet (chainId 1).
|
|
14
|
+
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
|
15
|
+
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
16
|
+
const POSITION_MANAGER = '0xC36442b4a4522E871399CD717aBDD847Ab11FE88';
|
|
17
|
+
const FACTORY = '0x1F98431c8aD98523631AE4a59f267346ea31F984';
|
|
18
|
+
const USDC_WETH_500_POOL = '0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640';
|
|
19
|
+
// Full range: the widest ticks that are multiples of the pool's tick spacing (10).
|
|
20
|
+
const TICK_LOWER = -887270;
|
|
21
|
+
const TICK_UPPER = 887270;
|
|
22
|
+
|
|
23
|
+
export interface UniswapV3MintInput {
|
|
24
|
+
readonly owner: Address;
|
|
25
|
+
readonly usdcAmount: `${bigint}`;
|
|
26
|
+
readonly wethAmount: `${bigint}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Open a full-range Uniswap V3 USDC/WETH position on Ethereum mainnet.
|
|
31
|
+
*
|
|
32
|
+
* - `uniswapV3.mint` deposits the proxy's USDC and WETH and mints the
|
|
33
|
+
* position NFT straight to the signer.
|
|
34
|
+
* - Unused USDC or WETH comes back as residuals, swept to the signer.
|
|
35
|
+
*/
|
|
36
|
+
export const buildUniswapV3Mint = ({
|
|
37
|
+
owner,
|
|
38
|
+
usdcAmount,
|
|
39
|
+
wethAmount,
|
|
40
|
+
}: UniswapV3MintInput): {
|
|
41
|
+
flow: Flow;
|
|
42
|
+
request: ComposeCompileRequest;
|
|
43
|
+
} => {
|
|
44
|
+
const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
|
|
45
|
+
|
|
46
|
+
const builder = sdk.flow(1, {
|
|
47
|
+
name: 'uniswap-v3-mint-usdc-weth',
|
|
48
|
+
inputs: {
|
|
49
|
+
usdc: resources.erc20(USDC, 1),
|
|
50
|
+
weth: resources.erc20(WETH, 1),
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
builder.uniswapV3.mint('mint', {
|
|
55
|
+
bind: {
|
|
56
|
+
tokenA: builder.inputs.usdc,
|
|
57
|
+
tokenB: builder.inputs.weth,
|
|
58
|
+
recipient: builder.context.sender,
|
|
59
|
+
},
|
|
60
|
+
config: {
|
|
61
|
+
positionManager: POSITION_MANAGER,
|
|
62
|
+
factory: FACTORY,
|
|
63
|
+
pool: USDC_WETH_500_POOL,
|
|
64
|
+
fee: 500,
|
|
65
|
+
tickLower: TICK_LOWER,
|
|
66
|
+
tickUpper: TICK_UPPER,
|
|
67
|
+
},
|
|
68
|
+
guards: [
|
|
69
|
+
// Bound the pool price before the deposit; N bps on the sqrt price
|
|
70
|
+
// allows about 2N bps of price movement, so this caps it near 50 bps.
|
|
71
|
+
guards.band({ port: 'sqrtPriceX96', bps: 25 }),
|
|
72
|
+
// Floor the minted liquidity. Liquidity is a handle, not a resource,
|
|
73
|
+
// so no minimum appears in the response.
|
|
74
|
+
guards.slippage({ port: 'liquidity', bps: 50 }),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const flow = builder.build();
|
|
79
|
+
|
|
80
|
+
const request = sdk.request(flow, {
|
|
81
|
+
signer: owner,
|
|
82
|
+
inputs: {
|
|
83
|
+
usdc: materialisers.directDeposit({ amount: usdcAmount }),
|
|
84
|
+
weth: materialisers.directDeposit({ amount: wethAmount }),
|
|
85
|
+
},
|
|
86
|
+
// Return unused USDC or WETH to the signer.
|
|
87
|
+
sweepTo: builder.context.sender,
|
|
88
|
+
// The position NFT is not a resource, so only the residuals count as
|
|
89
|
+
// output and the default price-impact check would read a full loss.
|
|
90
|
+
// 0 skips the check; the band and slippage guards protect the deposit.
|
|
91
|
+
maxPriceImpactBps: 0,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return { flow, request };
|
|
95
|
+
};
|
|
@@ -1170,44 +1170,6 @@ export interface LifiFlashloanRepayConfig {
|
|
|
1170
1170
|
fee?: string;
|
|
1171
1171
|
}
|
|
1172
1172
|
|
|
1173
|
-
export type ContinuationAssertReadyConfig =
|
|
1174
|
-
| {
|
|
1175
|
-
kind: 'erc20BalanceGte';
|
|
1176
|
-
chainId: Positive;
|
|
1177
|
-
/**
|
|
1178
|
-
* EVM address: 0x followed by 40 hex characters
|
|
1179
|
-
*/
|
|
1180
|
-
token: Address;
|
|
1181
|
-
/**
|
|
1182
|
-
* EVM address: 0x followed by 40 hex characters
|
|
1183
|
-
*/
|
|
1184
|
-
owner: Address;
|
|
1185
|
-
minAmount: string;
|
|
1186
|
-
}
|
|
1187
|
-
| {
|
|
1188
|
-
kind: 'nativeBalanceGte';
|
|
1189
|
-
chainId: Positive;
|
|
1190
|
-
/**
|
|
1191
|
-
* EVM address: 0x followed by 40 hex characters
|
|
1192
|
-
*/
|
|
1193
|
-
owner: Address;
|
|
1194
|
-
minAmount: string;
|
|
1195
|
-
}
|
|
1196
|
-
| {
|
|
1197
|
-
kind: 'call';
|
|
1198
|
-
chainId: Positive;
|
|
1199
|
-
/**
|
|
1200
|
-
* EVM address: 0x followed by 40 hex characters
|
|
1201
|
-
*/
|
|
1202
|
-
to: string;
|
|
1203
|
-
/**
|
|
1204
|
-
* Hex bytes: 0x followed by an even number of hex characters
|
|
1205
|
-
*/
|
|
1206
|
-
calldata: string;
|
|
1207
|
-
comparator: 'gte' | 'eq' | 'lte';
|
|
1208
|
-
value: string;
|
|
1209
|
-
};
|
|
1210
|
-
|
|
1211
1173
|
export interface LifiZapConfig {
|
|
1212
1174
|
resourceOut:
|
|
1213
1175
|
| {
|
|
@@ -1305,6 +1267,83 @@ export interface FlySwapConfig {
|
|
|
1305
1267
|
maxSlippageBps?: Between05000;
|
|
1306
1268
|
}
|
|
1307
1269
|
|
|
1270
|
+
export interface UniswapV2AddLiquidityConfig {
|
|
1271
|
+
/**
|
|
1272
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1273
|
+
*/
|
|
1274
|
+
router: string;
|
|
1275
|
+
/**
|
|
1276
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1277
|
+
*/
|
|
1278
|
+
factory: string;
|
|
1279
|
+
/**
|
|
1280
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1281
|
+
*/
|
|
1282
|
+
pair: string;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
export interface UniswapV2RemoveLiquidityConfig {
|
|
1286
|
+
/**
|
|
1287
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1288
|
+
*/
|
|
1289
|
+
router: string;
|
|
1290
|
+
/**
|
|
1291
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1292
|
+
*/
|
|
1293
|
+
factory: string;
|
|
1294
|
+
/**
|
|
1295
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1296
|
+
*/
|
|
1297
|
+
tokenA: string;
|
|
1298
|
+
/**
|
|
1299
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1300
|
+
*/
|
|
1301
|
+
tokenB: string;
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* a number between 0 and 999999
|
|
1306
|
+
*/
|
|
1307
|
+
export type Between0999999 = number;
|
|
1308
|
+
/**
|
|
1309
|
+
* a number between -887272 and 887272
|
|
1310
|
+
*/
|
|
1311
|
+
export type Between887272887272 = number;
|
|
1312
|
+
|
|
1313
|
+
export interface UniswapV3MintConfig {
|
|
1314
|
+
/**
|
|
1315
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1316
|
+
*/
|
|
1317
|
+
positionManager: string;
|
|
1318
|
+
/**
|
|
1319
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1320
|
+
*/
|
|
1321
|
+
factory: string;
|
|
1322
|
+
/**
|
|
1323
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1324
|
+
*/
|
|
1325
|
+
pool: string;
|
|
1326
|
+
fee: Between0999999;
|
|
1327
|
+
tickLower: Between887272887272;
|
|
1328
|
+
tickUpper: Between887272887272;
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
export interface UniswapV3IncreaseLiquidityConfig {
|
|
1332
|
+
/**
|
|
1333
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1334
|
+
*/
|
|
1335
|
+
positionManager: string;
|
|
1336
|
+
/**
|
|
1337
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1338
|
+
*/
|
|
1339
|
+
factory: string;
|
|
1340
|
+
/**
|
|
1341
|
+
* EVM address: 0x followed by 40 hex characters
|
|
1342
|
+
*/
|
|
1343
|
+
pool: string;
|
|
1344
|
+
tokenId: string;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1308
1347
|
export interface SlippageGuardConfig {
|
|
1309
1348
|
port: string;
|
|
1310
1349
|
bps: Between010000;
|
|
@@ -1316,6 +1355,11 @@ export interface CoreNumericInvariantGuardConfig {
|
|
|
1316
1355
|
threshold: IntegerStringInput;
|
|
1317
1356
|
}
|
|
1318
1357
|
|
|
1358
|
+
export interface BandGuardConfig {
|
|
1359
|
+
port: string;
|
|
1360
|
+
bps: Between010000;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1319
1363
|
export interface BalanceOfMaterialiserConfig {
|
|
1320
1364
|
/**
|
|
1321
1365
|
* EVM address: 0x followed by 40 hex characters
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { TypedGuard } from '../types.js';
|
|
5
5
|
|
|
6
6
|
import type {
|
|
7
|
+
BandGuardConfig,
|
|
7
8
|
CoreNumericInvariantGuardConfig,
|
|
8
9
|
SlippageGuardConfig,
|
|
9
10
|
} from './config.generated.js';
|
|
@@ -23,3 +24,11 @@ export const coreNumericInvariant = <P extends string>(
|
|
|
23
24
|
kind: 'core.numericInvariant',
|
|
24
25
|
...config,
|
|
25
26
|
});
|
|
27
|
+
|
|
28
|
+
/** Assert that an output stays within a tolerance in basis points of its simulated value, in both directions */
|
|
29
|
+
export const band = <P extends string>(
|
|
30
|
+
config: Omit<BandGuardConfig, 'port'> & { port: P },
|
|
31
|
+
): TypedGuard<P> => ({
|
|
32
|
+
kind: 'band',
|
|
33
|
+
...config,
|
|
34
|
+
});
|
|
@@ -23,6 +23,7 @@ import type { TypedGuard } from '../types.js';
|
|
|
23
23
|
import type {
|
|
24
24
|
AaveBorrowConfig,
|
|
25
25
|
AaveClaimRewardsConfig,
|
|
26
|
+
AaveGetHealthFactorConfig,
|
|
26
27
|
AaveRepayConfig,
|
|
27
28
|
AaveRepayWithATokensConfig,
|
|
28
29
|
AaveSetEModeConfig,
|
|
@@ -55,9 +56,18 @@ import type {
|
|
|
55
56
|
LifiSwapConfig,
|
|
56
57
|
LifiZapAsyncConfig,
|
|
57
58
|
LifiZapConfig,
|
|
59
|
+
MorphoBlueBorrowConfig,
|
|
60
|
+
MorphoBlueGetPositionConfig,
|
|
61
|
+
MorphoBlueRepayConfig,
|
|
58
62
|
MorphoBlueSupplyCollateralConfig,
|
|
63
|
+
MorphoBlueSupplyConfig,
|
|
59
64
|
MorphoBlueWithdrawCollateralConfig,
|
|
65
|
+
MorphoBlueWithdrawConfig,
|
|
60
66
|
ParaswapBuyConfig,
|
|
67
|
+
UniswapV2AddLiquidityConfig,
|
|
68
|
+
UniswapV2RemoveLiquidityConfig,
|
|
69
|
+
UniswapV3IncreaseLiquidityConfig,
|
|
70
|
+
UniswapV3MintConfig,
|
|
61
71
|
} from './config.generated.js';
|
|
62
72
|
|
|
63
73
|
/** Split a resource into two outputs by basis-point ratio. Output `a` receives `bps` of the source, rounded up, and `b` takes the remainder. */
|
|
@@ -532,6 +542,13 @@ export interface AaveSetEModeArgs {
|
|
|
532
542
|
readonly guards?: readonly TypedGuard<never>[];
|
|
533
543
|
}
|
|
534
544
|
|
|
545
|
+
/** 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. */
|
|
546
|
+
export interface AaveGetHealthFactorArgs {
|
|
547
|
+
readonly bind: Record<string, never>;
|
|
548
|
+
readonly config: AaveGetHealthFactorConfig;
|
|
549
|
+
readonly guards?: readonly TypedGuard<'healthFactor'>[];
|
|
550
|
+
}
|
|
551
|
+
|
|
535
552
|
/** 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). */
|
|
536
553
|
export interface MorphoBlueSupplyCollateralArgs {
|
|
537
554
|
readonly bind: {
|
|
@@ -548,6 +565,54 @@ export interface MorphoBlueWithdrawCollateralArgs {
|
|
|
548
565
|
readonly guards?: readonly TypedGuard<'collateralWithdrawn'>[];
|
|
549
566
|
}
|
|
550
567
|
|
|
568
|
+
/** 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. */
|
|
569
|
+
export interface MorphoBlueBorrowArgs {
|
|
570
|
+
readonly bind: Record<string, never>;
|
|
571
|
+
readonly config: MorphoBlueBorrowConfig;
|
|
572
|
+
readonly guards?: readonly TypedGuard<'assetsBorrowed' | 'sharesBorrowed'>[];
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/** 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. */
|
|
576
|
+
export interface MorphoBlueRepayArgs {
|
|
577
|
+
readonly bind: {
|
|
578
|
+
readonly assetIn: Bindable<'resource'>;
|
|
579
|
+
readonly onBehalfOf: Bindable<'address'>;
|
|
580
|
+
};
|
|
581
|
+
readonly config: MorphoBlueRepayConfig;
|
|
582
|
+
readonly guards?: readonly TypedGuard<
|
|
583
|
+
'actualRepaid' | 'sharesRepaid' | 'residual'
|
|
584
|
+
>[];
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/** 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. */
|
|
588
|
+
export interface MorphoBlueSupplyArgs {
|
|
589
|
+
readonly bind: {
|
|
590
|
+
readonly assetIn: Bindable<'resource'>;
|
|
591
|
+
};
|
|
592
|
+
readonly config: MorphoBlueSupplyConfig;
|
|
593
|
+
readonly guards?: readonly TypedGuard<
|
|
594
|
+
'assetsSupplied' | 'sharesSupplied' | 'residual'
|
|
595
|
+
>[];
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** 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. */
|
|
599
|
+
export interface MorphoBlueWithdrawArgs {
|
|
600
|
+
readonly bind: Record<string, never>;
|
|
601
|
+
readonly config: MorphoBlueWithdrawConfig;
|
|
602
|
+
readonly guards?: readonly TypedGuard<
|
|
603
|
+
'assetsWithdrawn' | 'sharesWithdrawn'
|
|
604
|
+
>[];
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** 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). */
|
|
608
|
+
export interface MorphoBlueGetPositionArgs {
|
|
609
|
+
readonly bind: Record<string, never>;
|
|
610
|
+
readonly config: MorphoBlueGetPositionConfig;
|
|
611
|
+
readonly guards?: readonly TypedGuard<
|
|
612
|
+
'supplyShares' | 'borrowShares' | 'collateral'
|
|
613
|
+
>[];
|
|
614
|
+
}
|
|
615
|
+
|
|
551
616
|
/** Route tokens into a DeFi protocol position via the edge catalog */
|
|
552
617
|
export interface LifiZapArgs {
|
|
553
618
|
readonly bind: {
|
|
@@ -593,6 +658,53 @@ export interface FlySwapArgs {
|
|
|
593
658
|
readonly guards?: readonly TypedGuard<'unspentIn'>[];
|
|
594
659
|
}
|
|
595
660
|
|
|
661
|
+
/** Deposit two ERC-20 tokens into an existing Uniswap V2 pair (or an ABI-identical fork such as SushiSwap V2) through its Router02 and receive the pair's LP token; unused input returns as residuals. Asserts on chain that the router's factory is `factory`, that the factory's pair for the two tokens is `pair`, and that the pair holds non-zero reserves. Exposes the pool price read before the deposit as `poolPrice`. The deposit is protected only with a `band` guard on `poolPrice` and a `slippage` guard on `liquidity`. Fee-on-transfer tokens are unsupported. */
|
|
662
|
+
export interface UniswapV2AddLiquidityArgs {
|
|
663
|
+
readonly bind: {
|
|
664
|
+
readonly tokenA: Bindable<'resource'>;
|
|
665
|
+
readonly tokenB: Bindable<'resource'>;
|
|
666
|
+
};
|
|
667
|
+
readonly config: UniswapV2AddLiquidityConfig;
|
|
668
|
+
readonly guards?: readonly TypedGuard<
|
|
669
|
+
'liquidity' | 'residualA' | 'residualB' | 'poolPrice'
|
|
670
|
+
>[];
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** Burn a Uniswap V2 LP token (or one of an ABI-identical fork such as SushiSwap V2) through its Router02 and receive both underlying tokens. Asserts on chain that the router's factory is `factory` and that the factory's pair for `tokenA`/`tokenB` is the input LP token. The withdrawal is protected only with a `slippage` guard on each of `tokenA` and `tokenB`. Fee-on-transfer tokens are unsupported: the outputs are the amounts the router reports, which would overstate what such a token delivers. */
|
|
674
|
+
export interface UniswapV2RemoveLiquidityArgs {
|
|
675
|
+
readonly bind: {
|
|
676
|
+
readonly liquidity: Bindable<'resource'>;
|
|
677
|
+
};
|
|
678
|
+
readonly config: UniswapV2RemoveLiquidityConfig;
|
|
679
|
+
readonly guards?: readonly TypedGuard<'tokenA' | 'tokenB'>[];
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** Open a Uniswap V3 concentrated-liquidity position (or one on an ABI-identical fork) for a tick range, minting the position NFT straight to `recipient`, which must not be the execution address. Exposes the new `tokenId`; unused input comes back as residuals. The deposit is protected only with a `band` guard on `sqrtPriceX96` (read before the deposit) and a `slippage` guard on `liquidity`; a band of N bps on `sqrtPriceX96` allows about 2N bps of price movement. Fee-on-transfer tokens are unsupported. */
|
|
683
|
+
export interface UniswapV3MintArgs {
|
|
684
|
+
readonly bind: {
|
|
685
|
+
readonly tokenA: Bindable<'resource'>;
|
|
686
|
+
readonly tokenB: Bindable<'resource'>;
|
|
687
|
+
readonly recipient: Bindable<'address'>;
|
|
688
|
+
};
|
|
689
|
+
readonly config: UniswapV3MintConfig;
|
|
690
|
+
readonly guards?: readonly TypedGuard<
|
|
691
|
+
'tokenId' | 'liquidity' | 'sqrtPriceX96' | 'residualA' | 'residualB'
|
|
692
|
+
>[];
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/** Add two tokens to an existing Uniswap V3 position (or one on an ABI-identical fork). `owner` must own `tokenId`, and the position must hold the two input tokens; both are asserted on chain, since the position manager checks neither. Unused input comes back as residuals. The deposit is protected only with a `band` guard on `sqrtPriceX96` (read before the deposit) and a `slippage` guard on `liquidity`; a band of N bps on `sqrtPriceX96` allows about 2N bps of price movement. Fee-on-transfer tokens are unsupported. */
|
|
696
|
+
export interface UniswapV3IncreaseLiquidityArgs {
|
|
697
|
+
readonly bind: {
|
|
698
|
+
readonly tokenA: Bindable<'resource'>;
|
|
699
|
+
readonly tokenB: Bindable<'resource'>;
|
|
700
|
+
readonly owner: Bindable<'address'>;
|
|
701
|
+
};
|
|
702
|
+
readonly config: UniswapV3IncreaseLiquidityConfig;
|
|
703
|
+
readonly guards?: readonly TypedGuard<
|
|
704
|
+
'liquidity' | 'sqrtPriceX96' | 'residualA' | 'residualB'
|
|
705
|
+
>[];
|
|
706
|
+
}
|
|
707
|
+
|
|
596
708
|
export interface CoreSplitOutputs {
|
|
597
709
|
readonly a: OutputHandle<'resource'>;
|
|
598
710
|
readonly b: OutputHandle<'resource'>;
|
|
@@ -685,11 +797,45 @@ export interface AaveClaimRewardsOutputs {
|
|
|
685
797
|
readonly claimedAmount: OutputHandle<'uint256'>;
|
|
686
798
|
}
|
|
687
799
|
|
|
800
|
+
export interface AaveGetHealthFactorOutputs {
|
|
801
|
+
readonly healthFactor: OutputHandle<'uint256'>;
|
|
802
|
+
}
|
|
803
|
+
|
|
688
804
|
export interface MorphoBlueWithdrawCollateralOutputs {
|
|
689
805
|
readonly withdrawn: OutputHandle<'resource'>;
|
|
690
806
|
readonly collateralWithdrawn: OutputHandle<'uint256'>;
|
|
691
807
|
}
|
|
692
808
|
|
|
809
|
+
export interface MorphoBlueBorrowOutputs {
|
|
810
|
+
readonly borrowed: OutputHandle<'resource'>;
|
|
811
|
+
readonly assetsBorrowed: OutputHandle<'uint256'>;
|
|
812
|
+
readonly sharesBorrowed: OutputHandle<'uint256'>;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
export interface MorphoBlueRepayOutputs {
|
|
816
|
+
readonly actualRepaid: OutputHandle<'uint256'>;
|
|
817
|
+
readonly sharesRepaid: OutputHandle<'uint256'>;
|
|
818
|
+
readonly residual: OutputHandle<'resource'>;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export interface MorphoBlueSupplyOutputs {
|
|
822
|
+
readonly assetsSupplied: OutputHandle<'uint256'>;
|
|
823
|
+
readonly sharesSupplied: OutputHandle<'uint256'>;
|
|
824
|
+
readonly residual: OutputHandle<'resource'>;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
export interface MorphoBlueWithdrawOutputs {
|
|
828
|
+
readonly withdrawn: OutputHandle<'resource'>;
|
|
829
|
+
readonly assetsWithdrawn: OutputHandle<'uint256'>;
|
|
830
|
+
readonly sharesWithdrawn: OutputHandle<'uint256'>;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
export interface MorphoBlueGetPositionOutputs {
|
|
834
|
+
readonly supplyShares: OutputHandle<'uint256'>;
|
|
835
|
+
readonly borrowShares: OutputHandle<'uint128'>;
|
|
836
|
+
readonly collateral: OutputHandle<'uint128'>;
|
|
837
|
+
}
|
|
838
|
+
|
|
693
839
|
export interface LifiZapOutputs {
|
|
694
840
|
readonly amountOut: OutputHandle<'resource'>;
|
|
695
841
|
}
|
|
@@ -712,6 +858,33 @@ export interface FlySwapOutputs {
|
|
|
712
858
|
readonly unspentIn: OutputHandle<'resource'>;
|
|
713
859
|
}
|
|
714
860
|
|
|
861
|
+
export interface UniswapV2AddLiquidityOutputs {
|
|
862
|
+
readonly liquidity: OutputHandle<'resource'>;
|
|
863
|
+
readonly residualA: OutputHandle<'resource'>;
|
|
864
|
+
readonly residualB: OutputHandle<'resource'>;
|
|
865
|
+
readonly poolPrice: OutputHandle<'uint256'>;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
export interface UniswapV2RemoveLiquidityOutputs {
|
|
869
|
+
readonly tokenA: OutputHandle<'resource'>;
|
|
870
|
+
readonly tokenB: OutputHandle<'resource'>;
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
export interface UniswapV3MintOutputs {
|
|
874
|
+
readonly tokenId: OutputHandle<'uint256'>;
|
|
875
|
+
readonly liquidity: OutputHandle<'uint256'>;
|
|
876
|
+
readonly sqrtPriceX96: OutputHandle<'uint256'>;
|
|
877
|
+
readonly residualA: OutputHandle<'resource'>;
|
|
878
|
+
readonly residualB: OutputHandle<'resource'>;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
export interface UniswapV3IncreaseLiquidityOutputs {
|
|
882
|
+
readonly liquidity: OutputHandle<'uint256'>;
|
|
883
|
+
readonly sqrtPriceX96: OutputHandle<'uint256'>;
|
|
884
|
+
readonly residualA: OutputHandle<'resource'>;
|
|
885
|
+
readonly residualB: OutputHandle<'resource'>;
|
|
886
|
+
}
|
|
887
|
+
|
|
715
888
|
export type GeneratedOps = {
|
|
716
889
|
readonly core: {
|
|
717
890
|
/** Split a resource into two outputs by basis-point ratio. Output `a` receives `bps` of the source, rounded up, and `b` takes the remainder. — original id: "core.split" */
|
|
@@ -914,6 +1087,11 @@ export type GeneratedOps = {
|
|
|
914
1087
|
) => AaveClaimRewardsOutputs;
|
|
915
1088
|
/** 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" */
|
|
916
1089
|
readonly setEMode: (nodeId: string, args: AaveSetEModeArgs) => void;
|
|
1090
|
+
/** 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" */
|
|
1091
|
+
readonly getHealthFactor: (
|
|
1092
|
+
nodeId: string,
|
|
1093
|
+
args: AaveGetHealthFactorArgs,
|
|
1094
|
+
) => AaveGetHealthFactorOutputs;
|
|
917
1095
|
};
|
|
918
1096
|
readonly morphoBlue: {
|
|
919
1097
|
/** 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" */
|
|
@@ -926,6 +1104,31 @@ export type GeneratedOps = {
|
|
|
926
1104
|
nodeId: string,
|
|
927
1105
|
args: MorphoBlueWithdrawCollateralArgs,
|
|
928
1106
|
) => MorphoBlueWithdrawCollateralOutputs;
|
|
1107
|
+
/** 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" */
|
|
1108
|
+
readonly borrow: (
|
|
1109
|
+
nodeId: string,
|
|
1110
|
+
args: MorphoBlueBorrowArgs,
|
|
1111
|
+
) => MorphoBlueBorrowOutputs;
|
|
1112
|
+
/** 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" */
|
|
1113
|
+
readonly repay: (
|
|
1114
|
+
nodeId: string,
|
|
1115
|
+
args: MorphoBlueRepayArgs,
|
|
1116
|
+
) => MorphoBlueRepayOutputs;
|
|
1117
|
+
/** 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" */
|
|
1118
|
+
readonly supply: (
|
|
1119
|
+
nodeId: string,
|
|
1120
|
+
args: MorphoBlueSupplyArgs,
|
|
1121
|
+
) => MorphoBlueSupplyOutputs;
|
|
1122
|
+
/** 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" */
|
|
1123
|
+
readonly withdraw: (
|
|
1124
|
+
nodeId: string,
|
|
1125
|
+
args: MorphoBlueWithdrawArgs,
|
|
1126
|
+
) => MorphoBlueWithdrawOutputs;
|
|
1127
|
+
/** 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" */
|
|
1128
|
+
readonly getPosition: (
|
|
1129
|
+
nodeId: string,
|
|
1130
|
+
args: MorphoBlueGetPositionArgs,
|
|
1131
|
+
) => MorphoBlueGetPositionOutputs;
|
|
929
1132
|
};
|
|
930
1133
|
readonly paraswap: {
|
|
931
1134
|
/** 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" */
|
|
@@ -935,6 +1138,30 @@ export type GeneratedOps = {
|
|
|
935
1138
|
/** Swap via Fly's DexAggregator, sized at runtime: the router calldata leaves `amountIn` unset, so an upstream op's output can feed the swap without being known at plan time. Either leg may be the chain-native coin. — original id: "fly.swap" */
|
|
936
1139
|
readonly swap: (nodeId: string, args: FlySwapArgs) => FlySwapOutputs;
|
|
937
1140
|
};
|
|
1141
|
+
readonly uniswapV2: {
|
|
1142
|
+
/** Deposit two ERC-20 tokens into an existing Uniswap V2 pair (or an ABI-identical fork such as SushiSwap V2) through its Router02 and receive the pair's LP token; unused input returns as residuals. Asserts on chain that the router's factory is `factory`, that the factory's pair for the two tokens is `pair`, and that the pair holds non-zero reserves. Exposes the pool price read before the deposit as `poolPrice`. The deposit is protected only with a `band` guard on `poolPrice` and a `slippage` guard on `liquidity`. Fee-on-transfer tokens are unsupported. — original id: "uniswapV2.addLiquidity" */
|
|
1143
|
+
readonly addLiquidity: (
|
|
1144
|
+
nodeId: string,
|
|
1145
|
+
args: UniswapV2AddLiquidityArgs,
|
|
1146
|
+
) => UniswapV2AddLiquidityOutputs;
|
|
1147
|
+
/** Burn a Uniswap V2 LP token (or one of an ABI-identical fork such as SushiSwap V2) through its Router02 and receive both underlying tokens. Asserts on chain that the router's factory is `factory` and that the factory's pair for `tokenA`/`tokenB` is the input LP token. The withdrawal is protected only with a `slippage` guard on each of `tokenA` and `tokenB`. Fee-on-transfer tokens are unsupported: the outputs are the amounts the router reports, which would overstate what such a token delivers. — original id: "uniswapV2.removeLiquidity" */
|
|
1148
|
+
readonly removeLiquidity: (
|
|
1149
|
+
nodeId: string,
|
|
1150
|
+
args: UniswapV2RemoveLiquidityArgs,
|
|
1151
|
+
) => UniswapV2RemoveLiquidityOutputs;
|
|
1152
|
+
};
|
|
1153
|
+
readonly uniswapV3: {
|
|
1154
|
+
/** Open a Uniswap V3 concentrated-liquidity position (or one on an ABI-identical fork) for a tick range, minting the position NFT straight to `recipient`, which must not be the execution address. Exposes the new `tokenId`; unused input comes back as residuals. The deposit is protected only with a `band` guard on `sqrtPriceX96` (read before the deposit) and a `slippage` guard on `liquidity`; a band of N bps on `sqrtPriceX96` allows about 2N bps of price movement. Fee-on-transfer tokens are unsupported. — original id: "uniswapV3.mint" */
|
|
1155
|
+
readonly mint: (
|
|
1156
|
+
nodeId: string,
|
|
1157
|
+
args: UniswapV3MintArgs,
|
|
1158
|
+
) => UniswapV3MintOutputs;
|
|
1159
|
+
/** Add two tokens to an existing Uniswap V3 position (or one on an ABI-identical fork). `owner` must own `tokenId`, and the position must hold the two input tokens; both are asserted on chain, since the position manager checks neither. Unused input comes back as residuals. The deposit is protected only with a `band` guard on `sqrtPriceX96` (read before the deposit) and a `slippage` guard on `liquidity`; a band of N bps on `sqrtPriceX96` allows about 2N bps of price movement. Fee-on-transfer tokens are unsupported. — original id: "uniswapV3.increaseLiquidity" */
|
|
1160
|
+
readonly increaseLiquidity: (
|
|
1161
|
+
nodeId: string,
|
|
1162
|
+
args: UniswapV3IncreaseLiquidityArgs,
|
|
1163
|
+
) => UniswapV3IncreaseLiquidityOutputs;
|
|
1164
|
+
};
|
|
938
1165
|
};
|
|
939
1166
|
|
|
940
1167
|
export const bindGeneratedOps = (
|
|
@@ -1173,6 +1400,10 @@ export const bindGeneratedOps = (
|
|
|
1173
1400
|
} as const),
|
|
1174
1401
|
setEMode: (nodeId: string, args: AaveSetEModeArgs) =>
|
|
1175
1402
|
builder.call(nodeId, 'aave.setEMode', args, {}),
|
|
1403
|
+
getHealthFactor: (nodeId: string, args: AaveGetHealthFactorArgs) =>
|
|
1404
|
+
builder.call(nodeId, 'aave.getHealthFactor', args, {
|
|
1405
|
+
healthFactor: 'uint256',
|
|
1406
|
+
} as const),
|
|
1176
1407
|
},
|
|
1177
1408
|
morphoBlue: {
|
|
1178
1409
|
supplyCollateral: (nodeId: string, args: MorphoBlueSupplyCollateralArgs) =>
|
|
@@ -1185,6 +1416,36 @@ export const bindGeneratedOps = (
|
|
|
1185
1416
|
withdrawn: 'resource',
|
|
1186
1417
|
collateralWithdrawn: 'uint256',
|
|
1187
1418
|
} as const),
|
|
1419
|
+
borrow: (nodeId: string, args: MorphoBlueBorrowArgs) =>
|
|
1420
|
+
builder.call(nodeId, 'morphoBlue.borrow', args, {
|
|
1421
|
+
borrowed: 'resource',
|
|
1422
|
+
assetsBorrowed: 'uint256',
|
|
1423
|
+
sharesBorrowed: 'uint256',
|
|
1424
|
+
} as const),
|
|
1425
|
+
repay: (nodeId: string, args: MorphoBlueRepayArgs) =>
|
|
1426
|
+
builder.call(nodeId, 'morphoBlue.repay', args, {
|
|
1427
|
+
actualRepaid: 'uint256',
|
|
1428
|
+
sharesRepaid: 'uint256',
|
|
1429
|
+
residual: 'resource',
|
|
1430
|
+
} as const),
|
|
1431
|
+
supply: (nodeId: string, args: MorphoBlueSupplyArgs) =>
|
|
1432
|
+
builder.call(nodeId, 'morphoBlue.supply', args, {
|
|
1433
|
+
assetsSupplied: 'uint256',
|
|
1434
|
+
sharesSupplied: 'uint256',
|
|
1435
|
+
residual: 'resource',
|
|
1436
|
+
} as const),
|
|
1437
|
+
withdraw: (nodeId: string, args: MorphoBlueWithdrawArgs) =>
|
|
1438
|
+
builder.call(nodeId, 'morphoBlue.withdraw', args, {
|
|
1439
|
+
withdrawn: 'resource',
|
|
1440
|
+
assetsWithdrawn: 'uint256',
|
|
1441
|
+
sharesWithdrawn: 'uint256',
|
|
1442
|
+
} as const),
|
|
1443
|
+
getPosition: (nodeId: string, args: MorphoBlueGetPositionArgs) =>
|
|
1444
|
+
builder.call(nodeId, 'morphoBlue.getPosition', args, {
|
|
1445
|
+
supplyShares: 'uint256',
|
|
1446
|
+
borrowShares: 'uint128',
|
|
1447
|
+
collateral: 'uint128',
|
|
1448
|
+
} as const),
|
|
1188
1449
|
},
|
|
1189
1450
|
paraswap: {
|
|
1190
1451
|
buy: (nodeId: string, args: ParaswapBuyArgs) =>
|
|
@@ -1200,4 +1461,35 @@ export const bindGeneratedOps = (
|
|
|
1200
1461
|
unspentIn: 'resource',
|
|
1201
1462
|
} as const),
|
|
1202
1463
|
},
|
|
1464
|
+
uniswapV2: {
|
|
1465
|
+
addLiquidity: (nodeId: string, args: UniswapV2AddLiquidityArgs) =>
|
|
1466
|
+
builder.call(nodeId, 'uniswapV2.addLiquidity', args, {
|
|
1467
|
+
liquidity: 'resource',
|
|
1468
|
+
residualA: 'resource',
|
|
1469
|
+
residualB: 'resource',
|
|
1470
|
+
poolPrice: 'uint256',
|
|
1471
|
+
} as const),
|
|
1472
|
+
removeLiquidity: (nodeId: string, args: UniswapV2RemoveLiquidityArgs) =>
|
|
1473
|
+
builder.call(nodeId, 'uniswapV2.removeLiquidity', args, {
|
|
1474
|
+
tokenA: 'resource',
|
|
1475
|
+
tokenB: 'resource',
|
|
1476
|
+
} as const),
|
|
1477
|
+
},
|
|
1478
|
+
uniswapV3: {
|
|
1479
|
+
mint: (nodeId: string, args: UniswapV3MintArgs) =>
|
|
1480
|
+
builder.call(nodeId, 'uniswapV3.mint', args, {
|
|
1481
|
+
tokenId: 'uint256',
|
|
1482
|
+
liquidity: 'uint256',
|
|
1483
|
+
sqrtPriceX96: 'uint256',
|
|
1484
|
+
residualA: 'resource',
|
|
1485
|
+
residualB: 'resource',
|
|
1486
|
+
} as const),
|
|
1487
|
+
increaseLiquidity: (nodeId: string, args: UniswapV3IncreaseLiquidityArgs) =>
|
|
1488
|
+
builder.call(nodeId, 'uniswapV3.increaseLiquidity', args, {
|
|
1489
|
+
liquidity: 'uint256',
|
|
1490
|
+
sqrtPriceX96: 'uint256',
|
|
1491
|
+
residualA: 'resource',
|
|
1492
|
+
residualB: 'resource',
|
|
1493
|
+
} as const),
|
|
1494
|
+
},
|
|
1203
1495
|
});
|
package/src/index.ts
CHANGED
|
@@ -99,11 +99,8 @@ export type {
|
|
|
99
99
|
Erc20AllowanceRequirement,
|
|
100
100
|
ContinuationIntent,
|
|
101
101
|
ContinuationOutcome,
|
|
102
|
-
Check,
|
|
103
|
-
CheckComparator,
|
|
104
102
|
SettlementWire,
|
|
105
103
|
SettlementEscrowWire,
|
|
106
|
-
ContinuationPlanWire,
|
|
107
104
|
} from '@lifi/compose-spec';
|
|
108
105
|
export {
|
|
109
106
|
SIMULATE_MAX_TRACKED_BALANCES,
|