@lifi/composer-sdk 0.0.1-alpha → 0.2.0-staging.4
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 +37 -1
- package/dist/authoring/signatureArgs.cjs +2 -2
- package/dist/authoring/signatureArgs.cjs.map +1 -1
- package/dist/authoring/signatureArgs.js +2 -2
- package/dist/authoring/signatureArgs.js.map +1 -1
- package/dist/client.cjs +2 -2
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +2 -2
- package/dist/client.js.map +1 -1
- package/dist/generated/config.generated.cjs.map +1 -1
- package/dist/generated/config.generated.d.cts +307 -16
- package/dist/generated/config.generated.d.ts +307 -16
- 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/materialisers.generated.cjs +8 -2
- 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 +6 -1
- package/dist/generated/materialisers.generated.js.map +1 -1
- package/dist/generated/operations.generated.cjs +84 -14
- package/dist/generated/operations.generated.cjs.map +1 -1
- package/dist/generated/operations.generated.d.cts +208 -13
- package/dist/generated/operations.generated.d.ts +208 -13
- package/dist/generated/operations.generated.js +84 -14
- package/dist/generated/operations.generated.js.map +1 -1
- package/dist/guards.generated-BPLFwe7y.d.ts +19 -0
- package/dist/guards.generated-M3VAIevI.d.cts +19 -0
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/materialisers.generated-BfWJ-g7t.d.ts +29 -0
- package/dist/materialisers.generated-DaJRwiRe.d.cts +29 -0
- package/dist/run/inputs.cjs +8 -5
- package/dist/run/inputs.cjs.map +1 -1
- package/dist/run/inputs.d.cts +8 -0
- package/dist/run/inputs.d.ts +8 -0
- package/dist/run/inputs.js +8 -5
- package/dist/run/inputs.js.map +1 -1
- package/dist/sdk.cjs +1 -0
- package/dist/sdk.cjs.map +1 -1
- package/dist/sdk.js +1 -0
- package/dist/sdk.js.map +1 -1
- package/package.json +14 -6
- package/src/authoring/signatureArgs.ts +2 -2
- package/src/client.ts +1 -1
- package/src/examples/aaveClaimRewards.ts +80 -0
- package/src/examples/aaveRepay.ts +69 -0
- package/src/examples/aaveRepayWithATokens.ts +81 -0
- package/src/examples/aaveSetEMode.ts +68 -0
- package/src/examples/run.ts +41 -4
- package/src/examples/staged/aaveBorrow.ts +104 -0
- package/src/examples/staged/aaveDebtRebalanceExactOut.ts +301 -0
- package/src/examples/staged/aaveHealthFactorExplode.ts +70 -0
- package/src/examples/staged/aaveToMorphoDebtMigration.ts +190 -0
- package/src/examples/staged/aaveToMorphoDebtMigrationWithSwap.ts +221 -0
- package/src/examples/staged/aaveToMorphoDebtMigrationWithSwapExactOut.ts +302 -0
- package/src/examples/staged/flashloanRepay.ts +138 -0
- package/src/examples/staged/morphoBlueBorrow.ts +89 -0
- package/src/examples/staged/morphoBlueRepay.ts +91 -0
- package/src/examples/staged/registry.ts +78 -0
- package/src/examples/swapToRecipient.ts +0 -19
- package/src/examples/swapWithFee.ts +59 -0
- package/src/generated/config.generated.ts +364 -18
- package/src/generated/guards.generated.ts +12 -1
- package/src/generated/materialisers.generated.ts +24 -12
- package/src/generated/operations.generated.ts +373 -13
- package/src/run/inputs.ts +16 -5
- package/src/sdk.ts +1 -0
- package/dist/guards.generated-DKKDKREA.d.ts +0 -14
- package/dist/guards.generated-hrQ1KPNv.d.cts +0 -14
- package/dist/materialisers.generated-BsA1uDW8.d.ts +0 -24
- package/dist/materialisers.generated-nMxTAaVi.d.cts +0 -24
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
amount: '1000000000',
|
|
29
|
+
}).request,
|
|
30
|
+
'aave-hf-explode': () =>
|
|
31
|
+
buildAaveHealthFactorExplode({ signer: OWNER }).request,
|
|
32
|
+
'morpho-borrow': () =>
|
|
33
|
+
buildMorphoBlueBorrow({
|
|
34
|
+
owner: OWNER,
|
|
35
|
+
collateralAmount: '1000000000000000000',
|
|
36
|
+
borrowAmount: '1500000000',
|
|
37
|
+
}).request,
|
|
38
|
+
'morpho-repay': () =>
|
|
39
|
+
buildMorphoBlueRepay({
|
|
40
|
+
owner: OWNER,
|
|
41
|
+
repayAmount: '1505000000',
|
|
42
|
+
collateralAmount: '1000000000000000000',
|
|
43
|
+
}).request,
|
|
44
|
+
'debt-rebalance': () =>
|
|
45
|
+
buildAaveDebtRebalanceExactOut({
|
|
46
|
+
owner: OWNER,
|
|
47
|
+
collateralAmount: '1000000000000000000',
|
|
48
|
+
debtAmount: '1000000000',
|
|
49
|
+
newDebtBorrowAmount: '965000000',
|
|
50
|
+
}).request,
|
|
51
|
+
'debt-migration-swap-exact-out': () =>
|
|
52
|
+
buildAaveToMorphoDebtMigrationWithSwapExactOut({
|
|
53
|
+
owner: OWNER,
|
|
54
|
+
collateralAmount: '1000000000000000000',
|
|
55
|
+
debtAmount: '2000000000',
|
|
56
|
+
morphoBorrowAmount: '1950000000',
|
|
57
|
+
}).request,
|
|
58
|
+
'flashloan-repay': () =>
|
|
59
|
+
buildTrivialFlashloanRepay({
|
|
60
|
+
owner: OWNER,
|
|
61
|
+
amount: '10000000000',
|
|
62
|
+
fee: '5000000',
|
|
63
|
+
}).request,
|
|
64
|
+
'debt-migration': () =>
|
|
65
|
+
buildAaveToMorphoDebtMigration({
|
|
66
|
+
owner: OWNER,
|
|
67
|
+
collateralAmount: '1000000000000000000',
|
|
68
|
+
debtAmount: '1000000000',
|
|
69
|
+
debtFlashloanFee: '500000',
|
|
70
|
+
}).request,
|
|
71
|
+
'debt-migration-swap': () =>
|
|
72
|
+
buildAaveToMorphoDebtMigrationWithSwap({
|
|
73
|
+
owner: OWNER,
|
|
74
|
+
collateralAmount: '1000000000000000000',
|
|
75
|
+
debtAmount: '1000000000',
|
|
76
|
+
morphoBorrowAmount: '1100000000',
|
|
77
|
+
}).request,
|
|
78
|
+
};
|
|
@@ -17,32 +17,13 @@ export interface SwapToRecipientInput {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
<<<<<<< HEAD
|
|
21
|
-
<<<<<<< HEAD
|
|
22
|
-
* Swap WETH and DAI into USDC, merge the outputs, transfer to a recipient,
|
|
23
|
-
=======
|
|
24
|
-
* Swap WETH and DAI into USDC, merge the outputs, transfer to the recipient,
|
|
25
|
-
>>>>>>> a2c178fd (chore: fix examples)
|
|
26
|
-
* and verify the recipient holds the combined balance.
|
|
27
|
-
=======
|
|
28
20
|
* Swap WETH and DAI into USDC, merge the outputs, and deliver to a recipient.
|
|
29
|
-
>>>>>>> 4c49ff9b (fix: support resource bindings for handle ports)
|
|
30
21
|
*
|
|
31
22
|
* Demonstrates:
|
|
32
23
|
* - Multiple resource inputs (two ERC-20 tokens)
|
|
33
24
|
* - A handle input (recipient address as a scalar value)
|
|
34
25
|
* - Chaining two swaps through a merge node
|
|
35
|
-
<<<<<<< HEAD
|
|
36
|
-
<<<<<<< HEAD
|
|
37
|
-
* - Explicit core.transfer to send merged tokens to the recipient
|
|
38
|
-
* - Copy-mode resource input on invariant.balanceAtLeast (reads without consuming)
|
|
39
|
-
=======
|
|
40
|
-
* - core.transfer to send merged tokens to the recipient
|
|
41
|
-
* - Using invariant.balanceAtLeast with a handle input for the account
|
|
42
|
-
>>>>>>> a2c178fd (chore: fix examples)
|
|
43
|
-
=======
|
|
44
26
|
* - Using `sweepTo` with a handle input to deliver tokens to the recipient
|
|
45
|
-
>>>>>>> 4c49ff9b (fix: support resource bindings for handle ports)
|
|
46
27
|
* - Typed request inputs inferred from the flow schema
|
|
47
28
|
*/
|
|
48
29
|
export const buildSwapToRecipient = ({
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
|
|
2
|
+
|
|
3
|
+
import { createComposeSdk, materialisers, resources } from '../index.js';
|
|
4
|
+
|
|
5
|
+
import { BASE_URL, OWNER } from './config.js';
|
|
6
|
+
|
|
7
|
+
const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
8
|
+
const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Swap WETH to USDC via LI.FI while collecting an integrator fee.
|
|
12
|
+
*
|
|
13
|
+
* Demonstrates:
|
|
14
|
+
* - Setting `integratorFeeBps` on the compile request (50 bps = 0.5%)
|
|
15
|
+
* - The fee is taken on the input token; the backend injects the fee transfer
|
|
16
|
+
*
|
|
17
|
+
* A non-zero `integratorFeeBps` requires the SDK to be configured with an
|
|
18
|
+
* integration-scoped API key (`apiKey`); the integration is derived from the
|
|
19
|
+
* key, not the request body.
|
|
20
|
+
*/
|
|
21
|
+
export const buildSwapWithFeeExample = (): {
|
|
22
|
+
flow: Flow;
|
|
23
|
+
request: ComposeCompileRequest;
|
|
24
|
+
} => {
|
|
25
|
+
const sdk = createComposeSdk({ baseUrl: BASE_URL });
|
|
26
|
+
|
|
27
|
+
// Declare the flow with a single WETH input on Ethereum mainnet.
|
|
28
|
+
const builder = sdk.flow(1, {
|
|
29
|
+
name: 'swap-with-fee',
|
|
30
|
+
inputs: {
|
|
31
|
+
amountIn: resources.erc20(WETH, 1),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Swap WETH → USDC via LI.FI.
|
|
36
|
+
builder.lifi.swap('swap', {
|
|
37
|
+
bind: { amountIn: builder.inputs.amountIn },
|
|
38
|
+
config: {
|
|
39
|
+
resourceOut: resources.erc20(USDC, 1),
|
|
40
|
+
slippage: 0.03,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const flow = builder.build();
|
|
45
|
+
|
|
46
|
+
// Build the compile request with a 50 bps (0.5%) integrator fee.
|
|
47
|
+
const request = sdk.request(flow, {
|
|
48
|
+
signer: OWNER,
|
|
49
|
+
inputs: {
|
|
50
|
+
amountIn: materialisers.directDeposit({
|
|
51
|
+
amount: '1000000000000000000',
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
integratorFeeBps: 50,
|
|
55
|
+
sweepTo: builder.context.sender,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return { flow, request };
|
|
59
|
+
};
|
|
@@ -11,6 +11,16 @@ export interface CoreSplitConfig {
|
|
|
11
11
|
* a positive number
|
|
12
12
|
*/
|
|
13
13
|
export type Positive = number;
|
|
14
|
+
/**
|
|
15
|
+
* a string at most 64 character(s) long
|
|
16
|
+
*/
|
|
17
|
+
export type MaxLength64 = string;
|
|
18
|
+
/**
|
|
19
|
+
* an array of at most 50 item(s)
|
|
20
|
+
*
|
|
21
|
+
* @maxItems 50
|
|
22
|
+
*/
|
|
23
|
+
export type MaxItems50 = MaxLength64[];
|
|
14
24
|
|
|
15
25
|
export interface LifiSwapConfig {
|
|
16
26
|
resourceOut:
|
|
@@ -38,19 +48,11 @@ export interface LifiSwapConfig {
|
|
|
38
48
|
reduceEveryMs: number;
|
|
39
49
|
}[];
|
|
40
50
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
kind: 'native';
|
|
47
|
-
chainId: Positive;
|
|
48
|
-
}
|
|
49
|
-
| {
|
|
50
|
-
kind: 'erc20';
|
|
51
|
-
token: Address;
|
|
52
|
-
chainId: Positive;
|
|
53
|
-
};
|
|
51
|
+
exchanges?: {
|
|
52
|
+
allow?: MaxItems50;
|
|
53
|
+
deny?: MaxItems50;
|
|
54
|
+
prefer?: MaxItems50;
|
|
55
|
+
};
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
export interface CoreBpsDownConfig {
|
|
@@ -120,22 +122,357 @@ export interface CoreAsResourceConfig {
|
|
|
120
122
|
};
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
export interface
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
export interface AaveBorrowConfig {
|
|
126
|
+
pool: string;
|
|
127
|
+
asset: string;
|
|
128
|
+
variableDebtToken: string;
|
|
129
|
+
amount: IntegerStringInput;
|
|
130
|
+
referralId?: number;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export type AaveRepayConfig =
|
|
134
|
+
| {
|
|
135
|
+
pool: string;
|
|
136
|
+
mode: 'exact';
|
|
137
|
+
}
|
|
138
|
+
| {
|
|
139
|
+
pool: string;
|
|
140
|
+
mode: 'max';
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export interface AaveRepayWithATokensConfig {
|
|
144
|
+
pool: string;
|
|
145
|
+
asset: string;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface AaveClaimRewardsConfig {
|
|
149
|
+
rewardsController: string;
|
|
150
|
+
assets: string[];
|
|
151
|
+
reward: string;
|
|
152
|
+
amount?: IntegerStringInput;
|
|
153
|
+
to?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* a number between 0 and 255
|
|
158
|
+
*/
|
|
159
|
+
export type Between0255 = number;
|
|
160
|
+
|
|
161
|
+
export interface AaveSetEModeConfig {
|
|
162
|
+
pool: string;
|
|
163
|
+
category: Between0255;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface AaveGetHealthFactorConfig {
|
|
167
|
+
pool: string;
|
|
168
|
+
user?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export type MorphoBlueSupplyCollateralConfig =
|
|
172
|
+
| (
|
|
173
|
+
| {
|
|
174
|
+
morpho?: string;
|
|
175
|
+
onBehalfOf?: string;
|
|
176
|
+
mode: 'exact';
|
|
177
|
+
/**
|
|
178
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
179
|
+
*/
|
|
180
|
+
marketId: string;
|
|
181
|
+
}
|
|
182
|
+
| {
|
|
183
|
+
morpho?: string;
|
|
184
|
+
onBehalfOf?: string;
|
|
185
|
+
mode: 'exact';
|
|
186
|
+
marketParams: {
|
|
187
|
+
loanToken: string;
|
|
188
|
+
collateralToken: string;
|
|
189
|
+
oracle: string;
|
|
190
|
+
irm: string;
|
|
191
|
+
lltv: string;
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
)
|
|
195
|
+
| (
|
|
196
|
+
| {
|
|
197
|
+
morpho?: string;
|
|
198
|
+
onBehalfOf?: string;
|
|
199
|
+
mode: 'all';
|
|
200
|
+
/**
|
|
201
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
202
|
+
*/
|
|
203
|
+
marketId: string;
|
|
204
|
+
}
|
|
205
|
+
| {
|
|
206
|
+
morpho?: string;
|
|
207
|
+
onBehalfOf?: string;
|
|
208
|
+
mode: 'all';
|
|
209
|
+
marketParams: {
|
|
210
|
+
loanToken: string;
|
|
211
|
+
collateralToken: string;
|
|
212
|
+
oracle: string;
|
|
213
|
+
irm: string;
|
|
214
|
+
lltv: string;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
export type MorphoBlueWithdrawCollateralConfig =
|
|
220
|
+
| {
|
|
221
|
+
morpho?: string;
|
|
222
|
+
amount: IntegerStringInput;
|
|
223
|
+
onBehalfOf?: string;
|
|
224
|
+
receiver?: string;
|
|
225
|
+
/**
|
|
226
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
227
|
+
*/
|
|
228
|
+
marketId: string;
|
|
229
|
+
}
|
|
230
|
+
| {
|
|
231
|
+
morpho?: string;
|
|
232
|
+
amount: IntegerStringInput;
|
|
233
|
+
onBehalfOf?: string;
|
|
234
|
+
receiver?: string;
|
|
235
|
+
marketParams: {
|
|
236
|
+
loanToken: string;
|
|
237
|
+
collateralToken: string;
|
|
238
|
+
oracle: string;
|
|
239
|
+
irm: string;
|
|
240
|
+
lltv: string;
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export type MorphoBlueBorrowConfig =
|
|
245
|
+
| {
|
|
246
|
+
morpho?: string;
|
|
247
|
+
amount: IntegerStringInput;
|
|
248
|
+
onBehalfOf?: string;
|
|
249
|
+
receiver?: string;
|
|
250
|
+
/**
|
|
251
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
252
|
+
*/
|
|
253
|
+
marketId: string;
|
|
254
|
+
}
|
|
255
|
+
| {
|
|
256
|
+
morpho?: string;
|
|
257
|
+
amount: IntegerStringInput;
|
|
258
|
+
onBehalfOf?: string;
|
|
259
|
+
receiver?: string;
|
|
260
|
+
marketParams: {
|
|
261
|
+
loanToken: string;
|
|
262
|
+
collateralToken: string;
|
|
263
|
+
oracle: string;
|
|
264
|
+
irm: string;
|
|
265
|
+
lltv: string;
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
export type MorphoBlueRepayConfig =
|
|
270
|
+
| (
|
|
271
|
+
| {
|
|
272
|
+
morpho?: string;
|
|
273
|
+
mode: 'exact';
|
|
274
|
+
/**
|
|
275
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
276
|
+
*/
|
|
277
|
+
marketId: string;
|
|
278
|
+
}
|
|
279
|
+
| {
|
|
280
|
+
morpho?: string;
|
|
281
|
+
mode: 'exact';
|
|
282
|
+
marketParams: {
|
|
283
|
+
loanToken: string;
|
|
284
|
+
collateralToken: string;
|
|
285
|
+
oracle: string;
|
|
286
|
+
irm: string;
|
|
287
|
+
lltv: string;
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
)
|
|
291
|
+
| (
|
|
292
|
+
| {
|
|
293
|
+
morpho?: string;
|
|
294
|
+
mode: 'max';
|
|
295
|
+
/**
|
|
296
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
297
|
+
*/
|
|
298
|
+
marketId: string;
|
|
299
|
+
}
|
|
300
|
+
| {
|
|
301
|
+
morpho?: string;
|
|
302
|
+
mode: 'max';
|
|
303
|
+
marketParams: {
|
|
304
|
+
loanToken: string;
|
|
305
|
+
collateralToken: string;
|
|
306
|
+
oracle: string;
|
|
307
|
+
irm: string;
|
|
308
|
+
lltv: string;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
export type MorphoBlueSupplyConfig =
|
|
314
|
+
| {
|
|
315
|
+
morpho?: string;
|
|
316
|
+
onBehalfOf?: string;
|
|
317
|
+
/**
|
|
318
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
319
|
+
*/
|
|
320
|
+
marketId: string;
|
|
321
|
+
}
|
|
322
|
+
| {
|
|
323
|
+
morpho?: string;
|
|
324
|
+
onBehalfOf?: string;
|
|
325
|
+
marketParams: {
|
|
326
|
+
loanToken: string;
|
|
327
|
+
collateralToken: string;
|
|
328
|
+
oracle: string;
|
|
329
|
+
irm: string;
|
|
330
|
+
lltv: string;
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
export type MorphoBlueWithdrawConfig =
|
|
335
|
+
| (
|
|
336
|
+
| {
|
|
337
|
+
morpho?: string;
|
|
338
|
+
mode: 'exact';
|
|
339
|
+
amount: IntegerStringInput;
|
|
340
|
+
onBehalfOf?: string;
|
|
341
|
+
receiver?: string;
|
|
342
|
+
/**
|
|
343
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
344
|
+
*/
|
|
345
|
+
marketId: string;
|
|
346
|
+
}
|
|
347
|
+
| {
|
|
348
|
+
morpho?: string;
|
|
349
|
+
mode: 'exact';
|
|
350
|
+
amount: IntegerStringInput;
|
|
351
|
+
onBehalfOf?: string;
|
|
352
|
+
receiver?: string;
|
|
353
|
+
marketParams: {
|
|
354
|
+
loanToken: string;
|
|
355
|
+
collateralToken: string;
|
|
356
|
+
oracle: string;
|
|
357
|
+
irm: string;
|
|
358
|
+
lltv: string;
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
)
|
|
362
|
+
| (
|
|
363
|
+
| {
|
|
364
|
+
morpho?: string;
|
|
365
|
+
mode: 'max';
|
|
366
|
+
onBehalfOf?: string;
|
|
367
|
+
receiver?: string;
|
|
368
|
+
/**
|
|
369
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
370
|
+
*/
|
|
371
|
+
marketId: string;
|
|
372
|
+
}
|
|
373
|
+
| {
|
|
374
|
+
morpho?: string;
|
|
375
|
+
mode: 'max';
|
|
376
|
+
onBehalfOf?: string;
|
|
377
|
+
receiver?: string;
|
|
378
|
+
marketParams: {
|
|
379
|
+
loanToken: string;
|
|
380
|
+
collateralToken: string;
|
|
381
|
+
oracle: string;
|
|
382
|
+
irm: string;
|
|
383
|
+
lltv: string;
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
export type MorphoBlueGetPositionConfig =
|
|
389
|
+
| {
|
|
390
|
+
morpho?: string;
|
|
391
|
+
user?: string;
|
|
392
|
+
/**
|
|
393
|
+
* a string matching the pattern ^0x[0-9a-fA-F]{64}$
|
|
394
|
+
*/
|
|
395
|
+
marketId: string;
|
|
396
|
+
}
|
|
397
|
+
| {
|
|
398
|
+
morpho?: string;
|
|
399
|
+
user?: string;
|
|
400
|
+
marketParams: {
|
|
401
|
+
loanToken: string;
|
|
402
|
+
collateralToken: string;
|
|
403
|
+
oracle: string;
|
|
404
|
+
irm: string;
|
|
405
|
+
lltv: string;
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export interface LifiFlashloanRepayConfig {
|
|
410
|
+
leg: string;
|
|
411
|
+
fee?: string;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export interface LifiZapConfig {
|
|
415
|
+
resourceOut:
|
|
416
|
+
| {
|
|
417
|
+
kind: 'native';
|
|
418
|
+
chainId: Positive;
|
|
419
|
+
}
|
|
420
|
+
| {
|
|
421
|
+
kind: 'erc20';
|
|
422
|
+
token: Address;
|
|
423
|
+
chainId: Positive;
|
|
424
|
+
};
|
|
127
425
|
}
|
|
128
426
|
|
|
427
|
+
/**
|
|
428
|
+
* a non-negative number
|
|
429
|
+
*/
|
|
430
|
+
export type GreaterThanOrEqualTo0 = number;
|
|
129
431
|
/**
|
|
130
432
|
* a number between 0 and 10000
|
|
131
433
|
*/
|
|
132
434
|
export type Between010000 = number;
|
|
133
435
|
|
|
436
|
+
export interface ParaswapBuyConfig {
|
|
437
|
+
resourceOut:
|
|
438
|
+
| {
|
|
439
|
+
kind: 'native';
|
|
440
|
+
chainId: Positive;
|
|
441
|
+
}
|
|
442
|
+
| {
|
|
443
|
+
kind: 'erc20';
|
|
444
|
+
token: Address;
|
|
445
|
+
chainId: Positive;
|
|
446
|
+
};
|
|
447
|
+
exactAmountOut: string;
|
|
448
|
+
srcDecimals: GreaterThanOrEqualTo0;
|
|
449
|
+
destDecimals: GreaterThanOrEqualTo0;
|
|
450
|
+
maxSlippageBps?: Between010000;
|
|
451
|
+
partner?: string;
|
|
452
|
+
partnerAddress?: string;
|
|
453
|
+
/**
|
|
454
|
+
* Integrator fee in basis points; non-negative integer string capped at 9000.
|
|
455
|
+
*/
|
|
456
|
+
partnerFeeBps?: string;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface CorePeekConfig {
|
|
460
|
+
target: Address;
|
|
461
|
+
functionSignature: string;
|
|
462
|
+
args?: string[];
|
|
463
|
+
}
|
|
464
|
+
|
|
134
465
|
export interface SlippageGuardConfig {
|
|
135
466
|
port: string;
|
|
136
467
|
bps: Between010000;
|
|
137
468
|
}
|
|
138
469
|
|
|
470
|
+
export interface CoreNumericInvariantGuardConfig {
|
|
471
|
+
port: string;
|
|
472
|
+
op: 'gte' | 'gt' | 'lte' | 'lt' | 'eq' | 'neq';
|
|
473
|
+
threshold: IntegerStringInput;
|
|
474
|
+
}
|
|
475
|
+
|
|
139
476
|
export interface BalanceOfMaterialiserConfig {
|
|
140
477
|
owner: Address;
|
|
141
478
|
}
|
|
@@ -146,8 +483,12 @@ export type DirectDepositMaterialiserConfig =
|
|
|
146
483
|
allowNonExact?: false;
|
|
147
484
|
}
|
|
148
485
|
| {
|
|
149
|
-
amount
|
|
486
|
+
amount: IntegerStringInput;
|
|
150
487
|
allowNonExact: true;
|
|
488
|
+
}
|
|
489
|
+
| {
|
|
490
|
+
allowNonExact: true;
|
|
491
|
+
simAmount?: string;
|
|
151
492
|
};
|
|
152
493
|
|
|
153
494
|
export interface CallMaterialiserConfig {
|
|
@@ -155,6 +496,11 @@ export interface CallMaterialiserConfig {
|
|
|
155
496
|
calldata: string;
|
|
156
497
|
}
|
|
157
498
|
|
|
499
|
+
export interface FlashloanMaterialiserConfig {
|
|
500
|
+
providerKind: 'aave-v3' | 'erc3156' | 'balancer-v2' | 'morpho-blue';
|
|
501
|
+
amount: IntegerStringInput;
|
|
502
|
+
}
|
|
503
|
+
|
|
158
504
|
export interface Erc20BalancePreconditionConfig {
|
|
159
505
|
wallet: Address;
|
|
160
506
|
token: Address;
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
|
|
4
4
|
import type { TypedGuard } from '../types.js';
|
|
5
5
|
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
CoreNumericInvariantGuardConfig,
|
|
8
|
+
SlippageGuardConfig,
|
|
9
|
+
} from './config.generated.js';
|
|
7
10
|
|
|
8
11
|
/** Assert that output amounts are within a slippage tolerance in basis points */
|
|
9
12
|
export const slippage = <P extends string>(
|
|
@@ -12,3 +15,11 @@ export const slippage = <P extends string>(
|
|
|
12
15
|
kind: 'slippage',
|
|
13
16
|
...config,
|
|
14
17
|
});
|
|
18
|
+
|
|
19
|
+
/** Assert a numeric (uint256) handle output of the target op satisfies a comparison against a constant threshold. Emits one IR1 binary invariant; reverts the run on violation. */
|
|
20
|
+
export const coreNumericInvariant = <P extends string>(
|
|
21
|
+
config: Omit<CoreNumericInvariantGuardConfig, 'port'> & { port: P },
|
|
22
|
+
): TypedGuard<P> => ({
|
|
23
|
+
kind: 'core.numericInvariant',
|
|
24
|
+
...config,
|
|
25
|
+
});
|
|
@@ -7,38 +7,50 @@ import type {
|
|
|
7
7
|
} from '@lifi/compose-spec';
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
-
BalanceOfMaterialiserConfig,
|
|
11
|
-
CallMaterialiserConfig,
|
|
12
|
-
DirectDepositMaterialiserConfig,
|
|
10
|
+
BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfigSchema,
|
|
11
|
+
CallMaterialiserConfig as CallMaterialiserConfigSchema,
|
|
12
|
+
DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfigSchema,
|
|
13
|
+
FlashloanMaterialiserConfig as FlashloanMaterialiserConfigSchema,
|
|
13
14
|
} from './config.generated.js';
|
|
14
15
|
|
|
15
|
-
export type
|
|
16
|
-
MaterialiserConfigOf<
|
|
16
|
+
export type BalanceOfMaterialiserConfig =
|
|
17
|
+
MaterialiserConfigOf<BalanceOfMaterialiserConfigSchema>;
|
|
17
18
|
|
|
18
19
|
/** Read the on-chain token balance of an address as the input amount — accepts: resource */
|
|
19
20
|
export const balanceOf = (
|
|
20
|
-
config:
|
|
21
|
+
config: BalanceOfMaterialiserConfig,
|
|
21
22
|
): MaterialiserInput => ({
|
|
22
23
|
kind: 'balanceOf',
|
|
23
24
|
...config,
|
|
24
25
|
});
|
|
25
26
|
|
|
26
|
-
export type
|
|
27
|
-
MaterialiserConfigOf<
|
|
27
|
+
export type DirectDepositMaterialiserConfig =
|
|
28
|
+
MaterialiserConfigOf<DirectDepositMaterialiserConfigSchema>;
|
|
28
29
|
|
|
29
30
|
/** Deposit tokens into the VM — native via msg.value, ERC-20 via transferFrom — accepts: resource */
|
|
30
31
|
export const directDeposit = (
|
|
31
|
-
config:
|
|
32
|
+
config: DirectDepositMaterialiserConfig,
|
|
32
33
|
): MaterialiserInput => ({
|
|
33
34
|
kind: 'directDeposit',
|
|
34
35
|
...config,
|
|
35
36
|
});
|
|
36
37
|
|
|
37
|
-
export type
|
|
38
|
-
MaterialiserConfigOf<
|
|
38
|
+
export type CallMaterialiserConfig =
|
|
39
|
+
MaterialiserConfigOf<CallMaterialiserConfigSchema>;
|
|
39
40
|
|
|
40
41
|
/** Execute an arbitrary contract call and measure the resulting token balance diff — accepts: resource */
|
|
41
|
-
export const call = (config:
|
|
42
|
+
export const call = (config: CallMaterialiserConfig): MaterialiserInput => ({
|
|
42
43
|
kind: 'call',
|
|
43
44
|
...config,
|
|
44
45
|
});
|
|
46
|
+
|
|
47
|
+
export type FlashloanMaterialiserConfig =
|
|
48
|
+
MaterialiserConfigOf<FlashloanMaterialiserConfigSchema>;
|
|
49
|
+
|
|
50
|
+
/** Borrow tokens from a flashloan provider; amount becomes a register populated by the proxy at callback time — accepts: resource */
|
|
51
|
+
export const flashloan = (
|
|
52
|
+
config: FlashloanMaterialiserConfig,
|
|
53
|
+
): MaterialiserInput => ({
|
|
54
|
+
kind: 'flashloan',
|
|
55
|
+
...config,
|
|
56
|
+
});
|