@lifi/composer-sdk 0.2.0-staging.5 → 0.3.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.
Files changed (101) hide show
  1. package/README.md +103 -2
  2. package/dist/client.cjs +46 -8
  3. package/dist/client.cjs.map +1 -1
  4. package/dist/client.d.cts +27 -3
  5. package/dist/client.d.ts +27 -3
  6. package/dist/client.js +49 -8
  7. package/dist/client.js.map +1 -1
  8. package/dist/errors.cjs +4 -1
  9. package/dist/errors.cjs.map +1 -1
  10. package/dist/errors.js +6 -1
  11. package/dist/errors.js.map +1 -1
  12. package/dist/generated/config.generated.cjs.map +1 -1
  13. package/dist/generated/config.generated.d.cts +80 -20
  14. package/dist/generated/config.generated.d.ts +80 -20
  15. package/dist/generated/materialisers.generated.cjs +2 -8
  16. package/dist/generated/materialisers.generated.cjs.map +1 -1
  17. package/dist/generated/materialisers.generated.d.cts +1 -1
  18. package/dist/generated/materialisers.generated.d.ts +1 -1
  19. package/dist/generated/materialisers.generated.js +1 -6
  20. package/dist/generated/materialisers.generated.js.map +1 -1
  21. package/dist/generated/operations.generated.cjs +1 -30
  22. package/dist/generated/operations.generated.cjs.map +1 -1
  23. package/dist/generated/operations.generated.d.cts +2 -94
  24. package/dist/generated/operations.generated.d.ts +2 -94
  25. package/dist/generated/operations.generated.js +1 -30
  26. package/dist/generated/operations.generated.js.map +1 -1
  27. package/dist/index.cjs +8 -0
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +4 -3
  30. package/dist/index.d.ts +4 -3
  31. package/dist/index.js +8 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/{materialisers.generated-BfWJ-g7t.d.ts → materialisers.generated-BMkBQgWZ.d.ts} +3 -8
  34. package/dist/{materialisers.generated-DaJRwiRe.d.cts → materialisers.generated-BWq5oePO.d.cts} +3 -8
  35. package/dist/responseSchemas.cjs +110 -0
  36. package/dist/responseSchemas.cjs.map +1 -0
  37. package/dist/responseSchemas.d.cts +36 -0
  38. package/dist/responseSchemas.d.ts +36 -0
  39. package/dist/responseSchemas.js +74 -0
  40. package/dist/responseSchemas.js.map +1 -0
  41. package/dist/run/simulate.cjs +41 -0
  42. package/dist/run/simulate.cjs.map +1 -0
  43. package/dist/run/simulate.d.cts +59 -0
  44. package/dist/run/simulate.d.ts +59 -0
  45. package/dist/run/simulate.js +17 -0
  46. package/dist/run/simulate.js.map +1 -0
  47. package/dist/sdk.cjs +6 -1
  48. package/dist/sdk.cjs.map +1 -1
  49. package/dist/sdk.d.cts +18 -6
  50. package/dist/sdk.d.ts +18 -6
  51. package/dist/sdk.js +6 -1
  52. package/dist/sdk.js.map +1 -1
  53. package/package.json +8 -6
  54. package/src/client.ts +96 -16
  55. package/src/errors.ts +8 -10
  56. package/src/examples/aaveClaimRewards.ts +2 -2
  57. package/src/examples/aaveRepay.ts +2 -2
  58. package/src/examples/aaveRepayWithATokens.ts +2 -2
  59. package/src/examples/aaveSetEMode.ts +2 -2
  60. package/src/examples/approveAndDeposit.ts +2 -2
  61. package/src/examples/callContract.ts +4 -4
  62. package/src/examples/config.ts +4 -1
  63. package/src/examples/consolidateToEth.ts +2 -2
  64. package/src/examples/consolidateToUsdc.ts +2 -2
  65. package/src/examples/depositFromProxy.ts +2 -2
  66. package/src/examples/dustSweep.ts +2 -2
  67. package/src/examples/emitCustomEvent.ts +2 -2
  68. package/src/examples/invariantChecks.ts +2 -2
  69. package/src/examples/lifiSwap.ts +2 -2
  70. package/src/examples/lifiZap.ts +2 -2
  71. package/src/examples/rawCallWithArithmetic.ts +2 -2
  72. package/src/examples/readContractState.ts +2 -2
  73. package/src/examples/simulateCompiledSwap.ts +76 -0
  74. package/src/examples/simulateRawTransaction.ts +39 -0
  75. package/src/examples/splitAndZap.ts +2 -2
  76. package/src/examples/splitWithArithmetic.ts +2 -2
  77. package/src/examples/swapAndZap.ts +2 -2
  78. package/src/examples/swapToRecipient.ts +2 -2
  79. package/src/examples/swapWithAllowRevert.ts +3 -3
  80. package/src/examples/swapWithBalanceCheck.ts +2 -2
  81. package/src/examples/swapWithFee.ts +2 -2
  82. package/src/examples/swapWithOutputValidation.ts +2 -2
  83. package/src/examples/transferTokens.ts +3 -3
  84. package/src/examples/untypedOpWithTypedRef.ts +2 -2
  85. package/src/generated/config.generated.ts +221 -20
  86. package/src/generated/materialisers.generated.ts +0 -12
  87. package/src/generated/operations.generated.ts +0 -177
  88. package/src/index.ts +25 -0
  89. package/src/responseSchemas.ts +143 -0
  90. package/src/run/simulate.ts +78 -0
  91. package/src/sdk.ts +25 -6
  92. package/src/examples/staged/aaveBorrow.ts +0 -128
  93. package/src/examples/staged/aaveDebtRebalanceExactOut.ts +0 -301
  94. package/src/examples/staged/aaveHealthFactorExplode.ts +0 -70
  95. package/src/examples/staged/aaveToMorphoDebtMigration.ts +0 -200
  96. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwap.ts +0 -231
  97. package/src/examples/staged/aaveToMorphoDebtMigrationWithSwapExactOut.ts +0 -307
  98. package/src/examples/staged/flashloanRepay.ts +0 -142
  99. package/src/examples/staged/morphoBlueBorrow.ts +0 -93
  100. package/src/examples/staged/morphoBlueRepay.ts +0 -132
  101. package/src/examples/staged/registry.ts +0 -80
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  // Example contract address for a non-standard oracle
9
9
  const ORACLE = '0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419';
@@ -27,7 +27,7 @@ export const buildRawCallWithArithmetic = ({
27
27
  flow: Flow;
28
28
  request: ComposeCompileRequest;
29
29
  } => {
30
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
30
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
31
31
 
32
32
  const builder = sdk.flow(1, {
33
33
  name: 'raw-call-with-arithmetic',
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
9
9
  // Example ERC-4626 vault address (Steakhouse USDC on Ethereum mainnet)
@@ -28,7 +28,7 @@ export const buildReadContractState = ({
28
28
  flow: Flow;
29
29
  request: ComposeCompileRequest;
30
30
  } => {
31
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
31
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
32
32
 
33
33
  const builder = sdk.flow(1, {
34
34
  name: 'read-contract-state',
@@ -0,0 +1,76 @@
1
+ import type { SimulateResult } from '@lifi/compose-spec';
2
+
3
+ import { buildSimulateRequest, materialisers, resources } from '../index.js';
4
+ import type { ComposeSdk } from '../index.js';
5
+
6
+ import { OWNER } from './config.js';
7
+
8
+ const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
9
+ const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
10
+
11
+ // 1 WETH (18 decimals).
12
+ const ONE_WETH = 1_000_000_000_000_000_000n;
13
+
14
+ /**
15
+ * End-to-end `/simulate` usage: compile a WETH→USDC swap, then simulate the
16
+ * compiled transaction to see how the signer's balances move and how much
17
+ * inner-call gas it burns — without broadcasting anything on-chain.
18
+ *
19
+ * Demonstrates the compile → simulate arc:
20
+ * - `buildSimulateRequest` lifts a `ComposeCompileResult` into a
21
+ * `SimulateRequest`, supplying the fields a compiled flow cannot carry: the
22
+ * target `chainId`, the `signer` (`from`), the funding `requirements`, and the
23
+ * `trackedBalances` to watch.
24
+ * - `sdk.simulate` runs it and returns a discriminated `ok | revert | error`
25
+ * result. A `revert` is a *successful simulation* whose execution reverted, so
26
+ * it is returned (not thrown); only transport/auth/5xx failures throw.
27
+ *
28
+ * Unlike the pure-builder examples, this performs network I/O through the
29
+ * injected `sdk` (one `/compose` call, one `/simulate` call). Pass a live
30
+ * `createComposeSdk({ baseUrl })` to run it for real, or a mock-backed SDK in
31
+ * tests.
32
+ */
33
+ export const simulateCompiledSwap = async (
34
+ sdk: ComposeSdk,
35
+ ): Promise<SimulateResult> => {
36
+ // Author and compile a single WETH → USDC swap on Ethereum mainnet.
37
+ const builder = sdk.flow(1, {
38
+ name: 'swap-weth-to-usdc',
39
+ inputs: { amountIn: resources.erc20(WETH, 1) },
40
+ });
41
+
42
+ builder.lifi.swap('swap', {
43
+ bind: { amountIn: builder.inputs.amountIn },
44
+ config: { resourceOut: resources.erc20(USDC, 1), slippage: 0.03 },
45
+ });
46
+
47
+ const compiled = await builder.compile({
48
+ signer: OWNER,
49
+ inputs: {
50
+ amountIn: materialisers.directDeposit({ amount: ONE_WETH }),
51
+ },
52
+ sweepTo: builder.context.sender,
53
+ });
54
+
55
+ // Lift the compiled transaction into a simulation request. The chain, signer,
56
+ // funding, and watched balances are NOT inferable from a compiled flow, so
57
+ // they are supplied here. `to`/`data`/`value` come from the compile result.
58
+ const request = buildSimulateRequest({
59
+ result: compiled,
60
+ chainId: 1,
61
+ signer: OWNER,
62
+ // Seed the signer with the 1 WETH the swap deposits, so the inner call has
63
+ // funds to pull. `bigint` amounts are serialised to decimal strings.
64
+ requirements: [
65
+ { type: 'Erc20Balance', wallet: OWNER, token: WETH, balance: ONE_WETH },
66
+ ],
67
+ // Watch the signer's WETH (spent) and USDC (received) balances; the response
68
+ // `deltas` come back ordered to match.
69
+ trackedBalances: [
70
+ { token: WETH, owner: OWNER },
71
+ { token: USDC, owner: OWNER },
72
+ ],
73
+ });
74
+
75
+ return sdk.simulate(request);
76
+ };
@@ -0,0 +1,39 @@
1
+ import type { SimulateRequest } from '@lifi/compose-spec';
2
+
3
+ const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
4
+ const SENDER = '0x1111111111111111111111111111111111111111';
5
+ const RECIPIENT = '0x2222222222222222222222222222222222222222';
6
+
7
+ /**
8
+ * Build a representative `POST /simulate` request: a USDC transfer of 1 USDC
9
+ * (1_000_000 base units at 6 decimals) from `SENDER` to `RECIPIENT` on chain 1.
10
+ *
11
+ * Demonstrates:
12
+ * - A pre-encoded `transfer(address,uint256)` calldata literal (`data`)
13
+ * - Funding the sender with an `Erc20Balance` requirement so the transfer can
14
+ * succeed in simulation (`bigint` amounts are accepted and serialised)
15
+ * - Watching both the sender's and recipient's USDC balance via `trackedBalances`
16
+ *
17
+ * Pure: returns a plain {@link SimulateRequest}, performs no network I/O. Pass
18
+ * it to `sdk.client.simulate(...)` / `sdk.simulate(...)` to run it.
19
+ */
20
+ export const buildSimulateRawTransactionExample = (): SimulateRequest => ({
21
+ chainId: 1,
22
+ from: SENDER,
23
+ to: USDC,
24
+ // transfer(RECIPIENT, 1_000_000)
25
+ data: '0xa9059cbb0000000000000000000000002222222222222222222222222222222222222222000000000000000000000000000000000000000000000000000000000f4240',
26
+ value: 0n,
27
+ requirements: [
28
+ {
29
+ type: 'Erc20Balance',
30
+ wallet: SENDER,
31
+ token: USDC,
32
+ balance: 1_000_000n,
33
+ },
34
+ ],
35
+ trackedBalances: [
36
+ { token: USDC, owner: SENDER },
37
+ { token: USDC, owner: RECIPIENT },
38
+ ],
39
+ });
@@ -7,7 +7,7 @@ import {
7
7
  resources,
8
8
  } from '../index.js';
9
9
 
10
- import { BASE_URL, OWNER } from './config.js';
10
+ import { API_KEY, BASE_URL, OWNER } from './config.js';
11
11
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
12
12
  // Aave v3 aEthUSDC receipt token on Ethereum mainnet
13
13
  const A_ETH_USDC = '0x98C23E9d8f34FEFb1B7BD6a91B7FF122F4e16F5c';
@@ -26,7 +26,7 @@ export const buildSplitAndZapExample = (): {
26
26
  flow: Flow;
27
27
  request: ComposeCompileRequest;
28
28
  } => {
29
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
29
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
30
30
 
31
31
  const builder = sdk.flow(1, {
32
32
  name: 'split-usdc-to-two-vaults',
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
9
9
 
@@ -29,7 +29,7 @@ export const buildSplitWithArithmetic = ({
29
29
  flow: Flow;
30
30
  request: ComposeCompileRequest;
31
31
  } => {
32
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
32
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
33
33
 
34
34
  const builder = sdk.flow(1, {
35
35
  name: 'split-with-arithmetic',
@@ -7,7 +7,7 @@ import {
7
7
  resources,
8
8
  } from '../index.js';
9
9
 
10
- import { BASE_URL, OWNER } from './config.js';
10
+ import { API_KEY, BASE_URL, OWNER } from './config.js';
11
11
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
12
12
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
13
13
  // Aave aEthUSDC receipt token on Ethereum mainnet
@@ -25,7 +25,7 @@ export const buildSwapAndZapExample = (): {
25
25
  flow: Flow;
26
26
  request: ComposeCompileRequest;
27
27
  } => {
28
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
28
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
29
29
 
30
30
  // Declare the flow with a single WETH input on Ethereum mainnet.
31
31
  const builder = sdk.flow(1, {
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
9
9
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
@@ -35,7 +35,7 @@ export const buildSwapToRecipient = ({
35
35
  flow: Flow;
36
36
  request: ComposeCompileRequest;
37
37
  } => {
38
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
38
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
39
39
 
40
40
  // Declare the flow on Ethereum mainnet with two token inputs and one address input.
41
41
  const builder = sdk.flow(1, {
@@ -2,7 +2,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
2
2
 
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
 
5
- import { BASE_URL, OWNER } from './config.js';
5
+ import { API_KEY, BASE_URL, OWNER } from './config.js';
6
6
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
7
7
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
8
8
 
@@ -25,7 +25,7 @@ export const buildSwapWithAllowRevertExample = (): {
25
25
  flow: Flow;
26
26
  request: ComposeCompileRequest;
27
27
  } => {
28
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
28
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
29
29
 
30
30
  const builder = sdk.flow(1, {
31
31
  name: 'swap-weth-to-usdc-allow-revert',
@@ -70,7 +70,7 @@ export const buildSwapWithAllowRevertExample = (): {
70
70
  * but demonstrates the branching pattern callers should use.
71
71
  */
72
72
  export const handleCompileResult = async (): Promise<void> => {
73
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
73
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
74
74
 
75
75
  const builder = sdk.flow(1, {
76
76
  inputs: { amountIn: resources.erc20(WETH, 1) },
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
9
9
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
@@ -29,7 +29,7 @@ export const buildSwapWithBalanceCheck = ({
29
29
  flow: Flow;
30
30
  request: ComposeCompileRequest;
31
31
  } => {
32
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
32
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
33
33
 
34
34
  // Declare the flow with a single WETH input on Ethereum mainnet.
35
35
  const builder = sdk.flow(1, {
@@ -2,7 +2,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
2
2
 
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
 
5
- import { BASE_URL, OWNER } from './config.js';
5
+ import { API_KEY, BASE_URL, OWNER } from './config.js';
6
6
 
7
7
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
8
8
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
@@ -22,7 +22,7 @@ export const buildSwapWithFeeExample = (): {
22
22
  flow: Flow;
23
23
  request: ComposeCompileRequest;
24
24
  } => {
25
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
25
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
26
26
 
27
27
  // Declare the flow with a single WETH input on Ethereum mainnet.
28
28
  const builder = sdk.flow(1, {
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const WETH = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
9
9
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
@@ -31,7 +31,7 @@ export const buildSwapWithOutputValidation = ({
31
31
  flow: Flow;
32
32
  request: ComposeCompileRequest;
33
33
  } => {
34
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
34
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
35
35
 
36
36
  const builder = sdk.flow(1, {
37
37
  name: 'swap-with-output-validation',
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, materialisers, resources } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  const USDC = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
9
9
 
@@ -31,7 +31,7 @@ export const buildTransferTokens = ({
31
31
  flow: Flow;
32
32
  request: ComposeCompileRequest;
33
33
  } => {
34
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
34
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
35
35
 
36
36
  const builder = sdk.flow(1, {
37
37
  name: 'transfer-usdc',
@@ -79,7 +79,7 @@ export const buildPartialTransfer = ({
79
79
  flow: Flow;
80
80
  request: ComposeCompileRequest;
81
81
  } => {
82
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
82
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
83
83
 
84
84
  const builder = sdk.flow(1, {
85
85
  name: 'partial-transfer-usdc',
@@ -3,7 +3,7 @@ import type { ComposeCompileRequest, Flow } from '@lifi/compose-spec';
3
3
  import { createComposeSdk, raw } from '../index.js';
4
4
  import type { Address } from '../types.js';
5
5
 
6
- import { BASE_URL } from './config.js';
6
+ import { API_KEY, BASE_URL } from './config.js';
7
7
 
8
8
  // Real ERC-4626 vault (Steakhouse USDC on Ethereum mainnet) queried through
9
9
  // the untyped escape hatch.
@@ -38,7 +38,7 @@ export const buildUntypedOpWithTypedRef = ({
38
38
  flow: Flow;
39
39
  request: ComposeCompileRequest;
40
40
  } => {
41
- const sdk = createComposeSdk({ baseUrl: BASE_URL });
41
+ const sdk = createComposeSdk({ baseUrl: BASE_URL, apiKey: API_KEY });
42
42
 
43
43
  const builder = sdk.flow(1, {
44
44
  name: 'untyped-op-with-typed-ref',
@@ -3,8 +3,13 @@
3
3
 
4
4
  import type { Address, IntegerStringInput } from '../types.js';
5
5
 
6
+ /**
7
+ * a number between 0 and 10000
8
+ */
9
+ export type Between010000 = number;
10
+
6
11
  export interface CoreSplitConfig {
7
- bps: number;
12
+ bps: Between010000;
8
13
  }
9
14
 
10
15
  /**
@@ -89,12 +94,17 @@ export interface InvariantNeqConfig {
89
94
  threshold: IntegerStringInput;
90
95
  }
91
96
 
97
+ /**
98
+ * a non-negative number
99
+ */
100
+ export type NonNegative = number;
101
+
92
102
  export interface CoreBpsDownConfig {
93
- bps: number;
103
+ bps: NonNegative;
94
104
  }
95
105
 
96
106
  export interface CoreBpsUpConfig {
97
- bps: number;
107
+ bps: NonNegative;
98
108
  }
99
109
 
100
110
  export interface CoreApproveConfig {
@@ -126,23 +136,139 @@ export interface CoreEmitEvent4Config {
126
136
  signature: string;
127
137
  }
128
138
 
139
+ /**
140
+ * a string at most 65536 character(s) long
141
+ */
142
+ export type MaxLength65536 = string;
143
+
129
144
  export interface CoreCallConfig {
130
145
  target: Address;
131
146
  functionSignature: string;
132
147
  callType?: 'Call' | 'ValueCall';
133
- args?: Unknown[];
148
+ args?: (
149
+ | (
150
+ | MaxLength65536
151
+ | number
152
+ | boolean
153
+ | {
154
+ $ref: string;
155
+ }
156
+ )
157
+ | (
158
+ | (
159
+ | MaxLength65536
160
+ | number
161
+ | boolean
162
+ | {
163
+ $ref: string;
164
+ }
165
+ )
166
+ | (
167
+ | (
168
+ | MaxLength65536
169
+ | number
170
+ | boolean
171
+ | {
172
+ $ref: string;
173
+ }
174
+ )
175
+ | (
176
+ | (
177
+ | MaxLength65536
178
+ | number
179
+ | boolean
180
+ | {
181
+ $ref: string;
182
+ }
183
+ )
184
+ | (
185
+ | (
186
+ | MaxLength65536
187
+ | number
188
+ | boolean
189
+ | {
190
+ $ref: string;
191
+ }
192
+ )
193
+ | (
194
+ | MaxLength65536
195
+ | number
196
+ | boolean
197
+ | {
198
+ $ref: string;
199
+ }
200
+ )[]
201
+ )[]
202
+ )[]
203
+ )[]
204
+ )[]
205
+ )[];
134
206
  approvals?: {
135
207
  spender: Address;
136
208
  }[];
137
209
  }
138
- export interface Unknown {
139
- [k: string]: unknown;
140
- }
141
210
 
142
211
  export interface CoreStaticCallConfig {
143
212
  target: Address;
144
213
  functionSignature: string;
145
- args?: Unknown[];
214
+ args?: (
215
+ | (
216
+ | MaxLength65536
217
+ | number
218
+ | boolean
219
+ | {
220
+ $ref: string;
221
+ }
222
+ )
223
+ | (
224
+ | (
225
+ | MaxLength65536
226
+ | number
227
+ | boolean
228
+ | {
229
+ $ref: string;
230
+ }
231
+ )
232
+ | (
233
+ | (
234
+ | MaxLength65536
235
+ | number
236
+ | boolean
237
+ | {
238
+ $ref: string;
239
+ }
240
+ )
241
+ | (
242
+ | (
243
+ | MaxLength65536
244
+ | number
245
+ | boolean
246
+ | {
247
+ $ref: string;
248
+ }
249
+ )
250
+ | (
251
+ | (
252
+ | MaxLength65536
253
+ | number
254
+ | boolean
255
+ | {
256
+ $ref: string;
257
+ }
258
+ )
259
+ | (
260
+ | MaxLength65536
261
+ | number
262
+ | boolean
263
+ | {
264
+ $ref: string;
265
+ }
266
+ )[]
267
+ )[]
268
+ )[]
269
+ )[]
270
+ )[]
271
+ )[];
146
272
  }
147
273
 
148
274
  export interface CoreRawCallConfig {
@@ -156,7 +282,64 @@ export interface CoreInvokeConfig {
156
282
  target: Address;
157
283
  functionSignature: string;
158
284
  callType?: 'Call' | 'ValueCall';
159
- args?: Unknown[];
285
+ args?: (
286
+ | (
287
+ | MaxLength65536
288
+ | number
289
+ | boolean
290
+ | {
291
+ $ref: string;
292
+ }
293
+ )
294
+ | (
295
+ | (
296
+ | MaxLength65536
297
+ | number
298
+ | boolean
299
+ | {
300
+ $ref: string;
301
+ }
302
+ )
303
+ | (
304
+ | (
305
+ | MaxLength65536
306
+ | number
307
+ | boolean
308
+ | {
309
+ $ref: string;
310
+ }
311
+ )
312
+ | (
313
+ | (
314
+ | MaxLength65536
315
+ | number
316
+ | boolean
317
+ | {
318
+ $ref: string;
319
+ }
320
+ )
321
+ | (
322
+ | (
323
+ | MaxLength65536
324
+ | number
325
+ | boolean
326
+ | {
327
+ $ref: string;
328
+ }
329
+ )
330
+ | (
331
+ | MaxLength65536
332
+ | number
333
+ | boolean
334
+ | {
335
+ $ref: string;
336
+ }
337
+ )[]
338
+ )[]
339
+ )[]
340
+ )[]
341
+ )[]
342
+ )[];
160
343
  }
161
344
 
162
345
  export interface CoreAsResourceConfig {
@@ -461,6 +644,33 @@ export interface LifiFlashloanRepayConfig {
461
644
  fee?: string;
462
645
  }
463
646
 
647
+ export type ContinuationAssertReadyConfig =
648
+ | {
649
+ kind: 'erc20BalanceGte';
650
+ chainId: Positive;
651
+ token: StartsWith0X;
652
+ owner: StartsWith0X;
653
+ minAmount: string;
654
+ }
655
+ | {
656
+ kind: 'nativeBalanceGte';
657
+ chainId: Positive;
658
+ owner: StartsWith0X;
659
+ minAmount: string;
660
+ }
661
+ | {
662
+ kind: 'call';
663
+ chainId: Positive;
664
+ to: StartsWith0X;
665
+ calldata: StartsWith0X;
666
+ comparator: 'gte' | 'eq' | 'lte';
667
+ value: string;
668
+ };
669
+ /**
670
+ * a string starting with "0x"
671
+ */
672
+ export type StartsWith0X = string;
673
+
464
674
  export interface LifiZapConfig {
465
675
  resourceOut:
466
676
  | {
@@ -474,15 +684,6 @@ export interface LifiZapConfig {
474
684
  };
475
685
  }
476
686
 
477
- /**
478
- * a non-negative number
479
- */
480
- export type GreaterThanOrEqualTo0 = number;
481
- /**
482
- * a number between 0 and 10000
483
- */
484
- export type Between010000 = number;
485
-
486
687
  export interface ParaswapBuyConfig {
487
688
  resourceOut:
488
689
  | {
@@ -495,8 +696,8 @@ export interface ParaswapBuyConfig {
495
696
  chainId: Positive;
496
697
  };
497
698
  exactAmountOut: string;
498
- srcDecimals: GreaterThanOrEqualTo0;
499
- destDecimals: GreaterThanOrEqualTo0;
699
+ srcDecimals: NonNegative;
700
+ destDecimals: NonNegative;
500
701
  maxSlippageBps?: Between010000;
501
702
  partner?: string;
502
703
  partnerAddress?: string;
@@ -10,7 +10,6 @@ import type {
10
10
  BalanceOfMaterialiserConfig as BalanceOfMaterialiserConfigSchema,
11
11
  CallMaterialiserConfig as CallMaterialiserConfigSchema,
12
12
  DirectDepositMaterialiserConfig as DirectDepositMaterialiserConfigSchema,
13
- FlashloanMaterialiserConfig as FlashloanMaterialiserConfigSchema,
14
13
  } from './config.generated.js';
15
14
 
16
15
  export type BalanceOfMaterialiserConfig =
@@ -43,14 +42,3 @@ export const call = (config: CallMaterialiserConfig): MaterialiserInput => ({
43
42
  kind: 'call',
44
43
  ...config,
45
44
  });
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
- });