|
6 | 6 | SwapKind, |
7 | 7 | } from '@aave/client'; |
8 | 8 | import { |
9 | | - prepareSwap, |
| 9 | + prepareTokenSwap, |
10 | 10 | swap, |
11 | | - swapQuote, |
12 | 11 | swapStatus, |
13 | 12 | userSwaps, |
14 | 13 | } from '@aave/client/actions'; |
@@ -40,58 +39,56 @@ describe('Aave V4 Swap Scenarios', () => { |
40 | 39 | }); |
41 | 40 |
|
42 | 41 | it(`Then the user's swap positions are updated`, async ({ annotate }) => { |
43 | | - const swapResult = await swapQuote(client, { |
44 | | - amount: bigDecimal('20'), |
45 | | - sell: { erc20: ETHEREUM_USDC_ADDRESS }, |
46 | | - buy: { erc20: ETHEREUM_WETH_ADDRESS }, |
47 | | - chainId: ETHEREUM_FORK_ID, |
48 | | - from: evmAddress(user.account.address), |
49 | | - kind: SwapKind.Sell, |
50 | | - receiver: evmAddress(user.account.address), |
51 | | - }) |
52 | | - .andThen((quote) => |
53 | | - prepareSwap(client, { |
54 | | - limit: { |
55 | | - quoteId: quote.quoteId, |
56 | | - }, |
57 | | - }), |
58 | | - ) |
59 | | - .andThen((swapPlan) => { |
60 | | - switch (swapPlan.__typename) { |
61 | | - case 'SwapByIntent': |
62 | | - return signSwapTypedDataWith(user, swapPlan.data).andThen( |
| 42 | + const swapResult = await prepareTokenSwap(client, { |
| 43 | + market: { |
| 44 | + amount: bigDecimal('20'), |
| 45 | + sell: { erc20: ETHEREUM_USDC_ADDRESS }, |
| 46 | + buy: { erc20: ETHEREUM_WETH_ADDRESS }, |
| 47 | + chainId: ETHEREUM_FORK_ID, |
| 48 | + kind: SwapKind.Sell, |
| 49 | + receiver: evmAddress(user.account.address), |
| 50 | + user: evmAddress(user.account.address), |
| 51 | + }, |
| 52 | + }).andThen((swapPlan) => { |
| 53 | + switch (swapPlan.__typename) { |
| 54 | + case 'SwapByIntent': |
| 55 | + return signSwapTypedDataWith(user, swapPlan.data).andThen( |
| 56 | + (signature) => { |
| 57 | + return swap(client, { |
| 58 | + intent: { |
| 59 | + quoteId: swapPlan.quote.quoteId, |
| 60 | + signature: signature, |
| 61 | + }, |
| 62 | + }); |
| 63 | + }, |
| 64 | + ); |
| 65 | + case 'SwapByIntentWithApprovalRequired': |
| 66 | + return sendTransaction(user, swapPlan.approval).andThen(() => |
| 67 | + signSwapTypedDataWith(user, swapPlan.data).andThen( |
63 | 68 | (signature) => { |
64 | 69 | return swap(client, { |
65 | 70 | intent: { |
66 | 71 | quoteId: swapPlan.quote.quoteId, |
67 | | - signature: signature.value, |
| 72 | + signature: signature, |
68 | 73 | }, |
69 | 74 | }); |
70 | 75 | }, |
71 | | - ); |
72 | | - case 'SwapByIntentWithApprovalRequired': |
73 | | - return sendTransaction(user, swapPlan.approval).andThen(() => |
74 | | - signSwapTypedDataWith(user, swapPlan.data).andThen( |
75 | | - (signature) => { |
76 | | - return swap(client, { |
77 | | - intent: { |
78 | | - quoteId: swapPlan.quote.quoteId, |
79 | | - signature: signature.value, |
80 | | - }, |
81 | | - }); |
82 | | - }, |
83 | | - ), |
84 | | - ); |
85 | | - case 'SwapByTransaction': |
86 | | - return swap(client, { |
87 | | - transaction: { quoteId: swapPlan.quote.quoteId }, |
88 | | - }); |
89 | | - case 'InsufficientBalanceError': |
90 | | - throw new Error( |
91 | | - `Insufficient balance: ${swapPlan.required.value} required.`, |
92 | | - ); |
93 | | - } |
94 | | - }); |
| 76 | + ), |
| 77 | + ); |
| 78 | + case 'SwapByTransaction': |
| 79 | + return swap(client, { |
| 80 | + transaction: { quoteId: swapPlan.quote.quoteId }, |
| 81 | + }); |
| 82 | + case 'InsufficientBalanceError': |
| 83 | + throw new Error( |
| 84 | + `Insufficient balance: ${swapPlan.required.value} required.`, |
| 85 | + ); |
| 86 | + default: |
| 87 | + throw new Error( |
| 88 | + `Unexpected swap plan type: ${(swapPlan as unknown as { __typename: string }).__typename}`, |
| 89 | + ); |
| 90 | + } |
| 91 | + }); |
95 | 92 |
|
96 | 93 | assertOk(swapResult); |
97 | 94 | invariant( |
|
0 commit comments