@cowprotocol/sdk-flash-loans 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,629 @@
1
+ // src/aave/AaveCollateralSwapSdk.ts
2
+ import {
3
+ ERC20_ALLOWANCE_ABI,
4
+ ERC20_APPROVE_ABI,
5
+ getGlobalAdapter,
6
+ ZERO_ADDRESS
7
+ } from "@cowprotocol/sdk-common";
8
+ import { OrderSigningUtils } from "@cowprotocol/sdk-order-signing";
9
+ import { SigningScheme } from "@cowprotocol/sdk-order-book";
10
+
11
+ // src/aave/const.ts
12
+ import { mapAddressToSupportedNetworks, SupportedChainId } from "@cowprotocol/sdk-config";
13
+ var HASH_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000";
14
+ var AAVE_POOL_ADDRESS = mapAddressToSupportedNetworks("0xb50201558B00496A145fE76f7424749556E326D8");
15
+ var AAVE_ADAPTER_FACTORY = {
16
+ ...mapAddressToSupportedNetworks("0x1186B5ad42E3e6d6c6901FC53b4A367540E6EcFE"),
17
+ [SupportedChainId.GNOSIS_CHAIN]: "0x889ee28C0a8a41a312546A8eeD77b4b097C84016"
18
+ };
19
+ var AAVE_COLLATERAL_SWAP_ADAPTER_HOOK = {
20
+ ...mapAddressToSupportedNetworks("0xe80eE1e73f120b1106179Ae3D582CA4Fd768d517"),
21
+ [SupportedChainId.GNOSIS_CHAIN]: "0x0aeC794e544B81D96149a4C8C1cC57c6F31A978A"
22
+ };
23
+ var DEFAULT_HOOK_GAS_LIMIT = {
24
+ pre: 300000n,
25
+ post: 600000n
26
+ };
27
+ var PERCENT_SCALE = 1e4;
28
+ var DEFAULT_VALIDITY = 10 * 60;
29
+ var GAS_ESTIMATION_ADDITION_PERCENT = 10;
30
+ var ADAPTER_DOMAIN_NAME = "AaveAdapterFactory";
31
+ var ADAPTER_DOMAIN_VERSION = "1";
32
+ var ADAPTER_SIGNATURE_TYPES = {
33
+ AdapterOrderSig: [
34
+ { name: "instance", type: "address" },
35
+ { name: "sellToken", type: "address" },
36
+ { name: "buyToken", type: "address" },
37
+ { name: "sellAmount", type: "uint256" },
38
+ { name: "buyAmount", type: "uint256" },
39
+ { name: "kind", type: "bytes32" },
40
+ { name: "validTo", type: "uint32" },
41
+ { name: "appData", type: "bytes32" }
42
+ ]
43
+ };
44
+ var EMPTY_PERMIT = {
45
+ amount: "0",
46
+ deadline: 0,
47
+ v: 0,
48
+ r: HASH_ZERO,
49
+ s: HASH_ZERO
50
+ };
51
+
52
+ // src/aave/abi/AaveAdapterFactory.ts
53
+ var aaveAdapterFactoryAbi = [
54
+ {
55
+ type: "function",
56
+ name: "getInstanceDeterministicAddress",
57
+ inputs: [
58
+ {
59
+ name: "adapterImplementation",
60
+ type: "address",
61
+ internalType: "address"
62
+ },
63
+ {
64
+ name: "hookData",
65
+ type: "tuple",
66
+ internalType: "struct DataTypes.HookOrderData",
67
+ components: [
68
+ {
69
+ name: "owner",
70
+ type: "address",
71
+ internalType: "address"
72
+ },
73
+ {
74
+ name: "receiver",
75
+ type: "address",
76
+ internalType: "address"
77
+ },
78
+ {
79
+ name: "sellToken",
80
+ type: "address",
81
+ internalType: "address"
82
+ },
83
+ {
84
+ name: "buyToken",
85
+ type: "address",
86
+ internalType: "address"
87
+ },
88
+ {
89
+ name: "sellAmount",
90
+ type: "uint256",
91
+ internalType: "uint256"
92
+ },
93
+ {
94
+ name: "buyAmount",
95
+ type: "uint256",
96
+ internalType: "uint256"
97
+ },
98
+ {
99
+ name: "kind",
100
+ type: "bytes32",
101
+ internalType: "bytes32"
102
+ },
103
+ {
104
+ name: "validTo",
105
+ type: "uint256",
106
+ internalType: "uint256"
107
+ },
108
+ {
109
+ name: "flashLoanAmount",
110
+ type: "uint256",
111
+ internalType: "uint256"
112
+ },
113
+ {
114
+ name: "flashLoanFeeAmount",
115
+ type: "uint256",
116
+ internalType: "uint256"
117
+ },
118
+ {
119
+ name: "hookSellTokenAmount",
120
+ type: "uint256",
121
+ internalType: "uint256"
122
+ },
123
+ {
124
+ name: "hookBuyTokenAmount",
125
+ type: "uint256",
126
+ internalType: "uint256"
127
+ }
128
+ ]
129
+ }
130
+ ],
131
+ outputs: [
132
+ {
133
+ name: "",
134
+ type: "address",
135
+ internalType: "address"
136
+ }
137
+ ],
138
+ stateMutability: "view"
139
+ },
140
+ {
141
+ type: "function",
142
+ name: "deployAndTransferFlashLoan",
143
+ inputs: [
144
+ {
145
+ name: "adapterImplementation",
146
+ type: "address",
147
+ internalType: "address"
148
+ },
149
+ {
150
+ name: "hookData",
151
+ type: "tuple",
152
+ internalType: "struct DataTypes.HookOrderData",
153
+ components: [
154
+ {
155
+ name: "owner",
156
+ type: "address",
157
+ internalType: "address"
158
+ },
159
+ {
160
+ name: "receiver",
161
+ type: "address",
162
+ internalType: "address"
163
+ },
164
+ {
165
+ name: "sellToken",
166
+ type: "address",
167
+ internalType: "address"
168
+ },
169
+ {
170
+ name: "buyToken",
171
+ type: "address",
172
+ internalType: "address"
173
+ },
174
+ {
175
+ name: "sellAmount",
176
+ type: "uint256",
177
+ internalType: "uint256"
178
+ },
179
+ {
180
+ name: "buyAmount",
181
+ type: "uint256",
182
+ internalType: "uint256"
183
+ },
184
+ {
185
+ name: "kind",
186
+ type: "bytes32",
187
+ internalType: "bytes32"
188
+ },
189
+ {
190
+ name: "validTo",
191
+ type: "uint256",
192
+ internalType: "uint256"
193
+ },
194
+ {
195
+ name: "flashLoanAmount",
196
+ type: "uint256",
197
+ internalType: "uint256"
198
+ },
199
+ {
200
+ name: "flashLoanFeeAmount",
201
+ type: "uint256",
202
+ internalType: "uint256"
203
+ },
204
+ {
205
+ name: "hookSellTokenAmount",
206
+ type: "uint256",
207
+ internalType: "uint256"
208
+ },
209
+ {
210
+ name: "hookBuyTokenAmount",
211
+ type: "uint256",
212
+ internalType: "uint256"
213
+ }
214
+ ]
215
+ }
216
+ ],
217
+ outputs: [],
218
+ stateMutability: "nonpayable"
219
+ },
220
+ {
221
+ inputs: [],
222
+ name: "DOMAIN_SEPARATOR",
223
+ outputs: [
224
+ {
225
+ internalType: "bytes32",
226
+ name: "",
227
+ type: "bytes32"
228
+ }
229
+ ],
230
+ stateMutability: "view",
231
+ type: "function"
232
+ }
233
+ ];
234
+
235
+ // src/aave/abi/CollateralSwapAdapterHook.ts
236
+ var collateralSwapAdapterHookAbi = [
237
+ {
238
+ type: "function",
239
+ name: "collateralSwapWithFlashLoan",
240
+ inputs: [
241
+ {
242
+ name: "erc20Permit",
243
+ type: "tuple",
244
+ internalType: "struct DataTypes.Permit",
245
+ components: [
246
+ {
247
+ name: "amount",
248
+ type: "uint256",
249
+ internalType: "uint256"
250
+ },
251
+ {
252
+ name: "deadline",
253
+ type: "uint256",
254
+ internalType: "uint256"
255
+ },
256
+ {
257
+ name: "v",
258
+ type: "uint8",
259
+ internalType: "uint8"
260
+ },
261
+ {
262
+ name: "r",
263
+ type: "bytes32",
264
+ internalType: "bytes32"
265
+ },
266
+ {
267
+ name: "s",
268
+ type: "bytes32",
269
+ internalType: "bytes32"
270
+ }
271
+ ]
272
+ }
273
+ ],
274
+ outputs: [],
275
+ stateMutability: "nonpayable"
276
+ }
277
+ ];
278
+
279
+ // src/aave/AaveCollateralSwapSdk.ts
280
+ var AaveCollateralSwapSdk = class {
281
+ /**
282
+ * Executes a collateral swap using Aave flash loans.
283
+ *
284
+ * @remarks This method orchestrates a complex flash loan operation:
285
+ * 1. Borrows the sell token via Aave flash loan
286
+ * 2. Uses CoW hooks to deploy adapter contracts and manage the swap
287
+ * 3. Executes a CoW Protocol swap to the buy token
288
+ * 4. Repays the flash loan with fees
289
+ *
290
+ * The order is signed using EIP-1271 with a deterministically generated
291
+ * smart contract address as the signer.
292
+ *
293
+ * @param {CollateralSwapParams} params - Configuration for the collateral swap.
294
+ * @param {TradingSdk} tradingSdk - @cowprotocol/sdk-trading.
295
+ * @returns {Promise<OrderPostingResult>} The result of posting the order to CoW Protocol.
296
+ *
297
+ * @throws Will throw if the quote fails, contract deployment fails, or gas estimation fails.
298
+ * ```
299
+ */
300
+ async collateralSwap(params, tradingSdk) {
301
+ const quoteParams = await this.getSwapQuoteParams(params);
302
+ const {
303
+ collateralToken,
304
+ tradeParameters: { amount },
305
+ settings
306
+ } = params;
307
+ const sellAmount = BigInt(amount);
308
+ const quoteAndPost = await tradingSdk.getQuote(quoteParams);
309
+ const { quoteResults, postSwapOrderFromQuote } = quoteAndPost;
310
+ const { swapSettings, instanceAddress } = await this.getOrderPostingSettings(quoteParams, {
311
+ sellAmount,
312
+ buyAmount: quoteResults.amountsAndCosts.afterSlippage.buyAmount,
313
+ orderToSign: quoteResults.orderToSign,
314
+ collateralPermit: settings?.collateralPermit
315
+ });
316
+ const collateralParams = {
317
+ instanceAddress,
318
+ trader: quoteParams.owner,
319
+ collateralToken,
320
+ amount: sellAmount
321
+ };
322
+ if (!settings?.preventApproval && !settings?.collateralPermit) {
323
+ await this.approveCollateralIfNeeded(collateralParams, sellAmount);
324
+ }
325
+ return postSwapOrderFromQuote(swapSettings);
326
+ }
327
+ /**
328
+ * Prepares quote parameters for the collateral swap operation.
329
+ *
330
+ * @remarks This method calculates the adjusted swap amount after deducting the flash loan fee,
331
+ * resolves the trader address, and computes the order validity timestamp. The flash
332
+ * loan fee is deducted from the sell amount before requesting a quote to ensure the
333
+ * final swap amount covers both the desired output and the flash loan repayment.
334
+ *
335
+ * @param {CollateralSwapParams} params - The collateral swap parameters including chain ID,
336
+ * trade parameters, and optional flash loan fee percentage.
337
+ * @returns {Promise<CollateralSwapQuoteParams>} Quote parameters with adjusted amounts and
338
+ * computed validity period.
339
+ * ```
340
+ */
341
+ async getSwapQuoteParams(params) {
342
+ const { chainId, tradeParameters, flashLoanFeePercent = 0 } = params;
343
+ const { validFor = DEFAULT_VALIDITY, owner, amount } = tradeParameters;
344
+ const adapter = getGlobalAdapter();
345
+ const trader = owner ?? await adapter.signer.getAddress();
346
+ const validTo = tradeParameters.validTo ?? Math.ceil(Date.now() / 1e3) + validFor;
347
+ const sellAmount = BigInt(amount);
348
+ if (!Number.isFinite(flashLoanFeePercent) || flashLoanFeePercent < 0 || flashLoanFeePercent > 100) {
349
+ throw new Error(`flashLoanFeePercent must be between 0 and 100, got: ${flashLoanFeePercent}`);
350
+ }
351
+ const { flashLoanFeeAmount, sellAmountToSign } = this.calculateFlashLoanAmounts({ flashLoanFeePercent, sellAmount });
352
+ const { validFor: _, ...restParameters } = tradeParameters;
353
+ return {
354
+ ...restParameters,
355
+ flashLoanFeeAmount,
356
+ chainId,
357
+ owner: trader,
358
+ amount: sellAmountToSign.toString(),
359
+ validTo
360
+ };
361
+ }
362
+ /**
363
+ * Generates order posting settings including hooks and flash loan metadata.
364
+ *
365
+ * @remarks This method constructs the complete order posting configuration for a flash loan-based
366
+ * collateral swap. It:
367
+ * - Encodes the order data for EIP-1271 signature verification
368
+ * - Calculates the deterministic address for the adapter contract
369
+ * - Configures pre and post-execution hooks for flash loan management
370
+ * - Generates flash loan hint metadata conforming to the flashloan v0.2.0 schema
371
+ * - Sets up EIP-1271 signing scheme with the expected instance address
372
+ * - Includes hooks configuration following the hooks v0.2.0 schema
373
+ *
374
+ * The flash loan metadata includes information about the Aave pool, protocol adapter,
375
+ * and token amounts required for execution. The hooks enable the order to trigger
376
+ * flash loan deployment (pre-hook) and collateral swap execution (post-hook).
377
+ *
378
+ * @param {CollateralSwapTradeParams} params - Trade parameters including chain ID, validity period,
379
+ * owner address, and flash loan fee amount.
380
+ * @param {CollateralSwapOrder} settings - Order configuration including sell/buy amounts, the
381
+ * unsigned order to sign, and optional collateral permit data.
382
+ * @returns {Promise<CollateralSwapPostParams>} Object containing swap advanced settings with
383
+ * appData metadata (flashloan + hooks) and the
384
+ * deterministic adapter instance address.
385
+ *
386
+ * @throws Will throw if contract address calculation fails or gas estimation fails.
387
+ * ```
388
+ */
389
+ async getOrderPostingSettings(params, settings) {
390
+ const { sellAmount, buyAmount, orderToSign, collateralPermit } = settings;
391
+ const { chainId, flashLoanFeeAmount, validTo, owner: trader } = params;
392
+ const amount = sellAmount.toString();
393
+ const encodedOrder = {
394
+ ...OrderSigningUtils.encodeUnsignedOrder(orderToSign),
395
+ appData: HASH_ZERO,
396
+ validTo
397
+ };
398
+ const hookAmounts = {
399
+ flashLoanAmount: amount,
400
+ flashLoanFeeAmount: flashLoanFeeAmount.toString(),
401
+ sellAssetAmount: amount,
402
+ buyAssetAmount: buyAmount.toString()
403
+ };
404
+ const instanceAddress = await this.getExpectedInstanceAddress(chainId, trader, hookAmounts, encodedOrder);
405
+ const flashLoanHint = {
406
+ amount,
407
+ // this is actually in UNDERLYING but aave tokens are 1:1
408
+ receiver: AAVE_ADAPTER_FACTORY[chainId],
409
+ liquidityProvider: AAVE_POOL_ADDRESS[chainId],
410
+ protocolAdapter: AAVE_ADAPTER_FACTORY[chainId],
411
+ token: orderToSign.sellToken
412
+ };
413
+ const hooks = await this.getOrderHooks(
414
+ chainId,
415
+ trader,
416
+ instanceAddress,
417
+ hookAmounts,
418
+ {
419
+ ...encodedOrder,
420
+ receiver: instanceAddress
421
+ },
422
+ collateralPermit
423
+ );
424
+ const swapSettings = {
425
+ quoteRequest: {
426
+ validTo,
427
+ receiver: instanceAddress,
428
+ from: instanceAddress
429
+ },
430
+ additionalParams: {
431
+ signingScheme: SigningScheme.EIP1271,
432
+ customEIP1271Signature: (orderToSign2, signer) => {
433
+ return this.adapterEIP1271Signature(chainId, instanceAddress, orderToSign2, signer);
434
+ }
435
+ },
436
+ appData: {
437
+ metadata: {
438
+ flashloan: flashLoanHint,
439
+ hooks
440
+ }
441
+ }
442
+ };
443
+ return {
444
+ swapSettings,
445
+ instanceAddress
446
+ };
447
+ }
448
+ /**
449
+ * Checks the current allowance for the flash loan adapter to spend collateral tokens.
450
+ *
451
+ * @remarks This method queries the ERC-20 token contract to determine how many tokens
452
+ * the deterministic adapter instance address is approved to spend on behalf
453
+ * of the trader. This is useful for verifying if approval is needed before
454
+ * executing a collateral swap.
455
+ *
456
+ * @param {CollateralParameters} params - Parameters including trader address, collateral
457
+ * token address, and adapter instance address.
458
+ * @returns {Promise<bigint>} The current allowance amount in token's smallest unit (wei).
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * const allowance = await sdk.getCollateralAllowance({
463
+ * trader: '0x...',
464
+ * collateralToken: '0x...',
465
+ * amount: BigInt('1000000000000000000'),
466
+ * instanceAddress: '0x...',
467
+ * })
468
+ * console.log('Current allowance:', allowance.toString())
469
+ * ```
470
+ */
471
+ async getCollateralAllowance(params) {
472
+ const { collateralToken, trader, instanceAddress } = params;
473
+ const adapter = getGlobalAdapter();
474
+ return await adapter.readContract({
475
+ address: collateralToken,
476
+ abi: ERC20_ALLOWANCE_ABI,
477
+ functionName: "allowance",
478
+ args: [trader, instanceAddress]
479
+ });
480
+ }
481
+ /**
482
+ * Approves the flash loan adapter to spend collateral tokens.
483
+ *
484
+ * @remarks This method sends an on-chain approval transaction to allow the deterministic
485
+ * adapter instance address to spend the specified amount of collateral tokens.
486
+ * The approval is required before executing a collateral swap unless using
487
+ * EIP-2612 permit or preventApproval settings.
488
+ *
489
+ * @param {CollateralParameters} params - Parameters including trader address, collateral
490
+ * token address, amount to approve, and adapter
491
+ * instance address.
492
+ * @returns {Promise<TransactionResponse>} The transaction response from the approval transaction.
493
+ *
494
+ * @throws Will throw if the approval transaction fails or is rejected.
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * const txResponse = await sdk.approveCollateral({
499
+ * trader: '0x...',
500
+ * collateralToken: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
501
+ * amount: BigInt('20000000000000000000'),
502
+ * instanceAddress: '0x...',
503
+ * })
504
+ * console.log('Approval transaction hash:', txResponse.hash)
505
+ * ```
506
+ */
507
+ async approveCollateral(params) {
508
+ const { collateralToken, amount, instanceAddress } = params;
509
+ const adapter = getGlobalAdapter();
510
+ const txParams = {
511
+ to: collateralToken,
512
+ data: adapter.utils.encodeFunction(ERC20_APPROVE_ABI, "approve", [instanceAddress, "0x" + amount.toString(16)])
513
+ };
514
+ return adapter.signer.sendTransaction(txParams);
515
+ }
516
+ async getExpectedInstanceAddress(chainId, trader, hookAmounts, order) {
517
+ const hookData = this.buildHookOrderData(trader, hookAmounts, order);
518
+ return await getGlobalAdapter().readContract({
519
+ address: AAVE_ADAPTER_FACTORY[chainId],
520
+ args: [AAVE_COLLATERAL_SWAP_ADAPTER_HOOK[chainId], hookData],
521
+ functionName: "getInstanceDeterministicAddress",
522
+ abi: aaveAdapterFactoryAbi
523
+ });
524
+ }
525
+ async approveCollateralIfNeeded(collateralParams, sellAmount) {
526
+ const allowance = await this.getCollateralAllowance(collateralParams).catch((error) => {
527
+ console.error("[AaveCollateralSwapSdk] Could not get allowance for collateral token", error);
528
+ return null;
529
+ });
530
+ if (!allowance || allowance < sellAmount) {
531
+ await this.approveCollateral(collateralParams);
532
+ }
533
+ }
534
+ calculateFlashLoanAmounts({ sellAmount, flashLoanFeePercent }) {
535
+ const flashLoanFeeAmount = sellAmount * BigInt(Math.round(flashLoanFeePercent * PERCENT_SCALE)) / BigInt(100 * PERCENT_SCALE);
536
+ return {
537
+ flashLoanFeeAmount,
538
+ sellAmountToSign: sellAmount - flashLoanFeeAmount
539
+ };
540
+ }
541
+ getPreHookCallData(chainId, trader, hookAmounts, order, instanceAddress) {
542
+ const hookData = this.buildHookOrderData(trader, hookAmounts, order);
543
+ const adapterImplementation = AAVE_COLLATERAL_SWAP_ADAPTER_HOOK[chainId];
544
+ return getGlobalAdapter().utils.encodeFunction(aaveAdapterFactoryAbi, "deployAndTransferFlashLoan", [
545
+ adapterImplementation,
546
+ { ...hookData, receiver: instanceAddress }
547
+ ]);
548
+ }
549
+ buildHookOrderData(trader, hookAmounts, order) {
550
+ const { sellToken, buyToken, sellAmount, buyAmount, kind, validTo } = order;
551
+ const parsedValidTo = typeof validTo === "number" ? validTo : Number(validTo ?? 0);
552
+ return {
553
+ owner: trader,
554
+ receiver: ZERO_ADDRESS,
555
+ sellToken: String(sellToken),
556
+ buyToken: String(buyToken),
557
+ sellAmount: String(sellAmount),
558
+ buyAmount: String(buyAmount),
559
+ kind: String(kind),
560
+ validTo: parsedValidTo,
561
+ flashLoanAmount: hookAmounts.flashLoanAmount,
562
+ flashLoanFeeAmount: hookAmounts.flashLoanFeeAmount,
563
+ hookSellTokenAmount: hookAmounts.sellAssetAmount,
564
+ hookBuyTokenAmount: hookAmounts.buyAssetAmount
565
+ };
566
+ }
567
+ getPostHookCallData(collateralPermit = EMPTY_PERMIT) {
568
+ return getGlobalAdapter().utils.encodeFunction(collateralSwapAdapterHookAbi, "collateralSwapWithFlashLoan", [
569
+ collateralPermit
570
+ ]);
571
+ }
572
+ async getOrderHooks(chainId, trader, expectedInstanceAddress, hookAmounts, order, collateralPermit) {
573
+ const preHookCallData = this.getPreHookCallData(chainId, trader, hookAmounts, order, expectedInstanceAddress);
574
+ const postHookCallData = this.getPostHookCallData(collateralPermit);
575
+ return {
576
+ pre: [
577
+ {
578
+ target: AAVE_ADAPTER_FACTORY[chainId],
579
+ callData: preHookCallData,
580
+ gasLimit: DEFAULT_HOOK_GAS_LIMIT.pre.toString()
581
+ }
582
+ ],
583
+ post: [
584
+ {
585
+ target: expectedInstanceAddress,
586
+ callData: postHookCallData,
587
+ gasLimit: DEFAULT_HOOK_GAS_LIMIT.post.toString()
588
+ }
589
+ ]
590
+ };
591
+ }
592
+ async adapterEIP1271Signature(chainId, instanceAddress, orderToSign, signer) {
593
+ const adapterFactoryAddress = AAVE_ADAPTER_FACTORY[chainId];
594
+ const encodedOrder = OrderSigningUtils.encodeUnsignedOrder(orderToSign);
595
+ const domain = {
596
+ name: ADAPTER_DOMAIN_NAME,
597
+ version: ADAPTER_DOMAIN_VERSION,
598
+ chainId,
599
+ verifyingContract: adapterFactoryAddress
600
+ };
601
+ const message = {
602
+ instance: instanceAddress,
603
+ sellToken: encodedOrder.sellToken,
604
+ buyToken: encodedOrder.buyToken,
605
+ sellAmount: encodedOrder.sellAmount,
606
+ buyAmount: encodedOrder.buyAmount,
607
+ kind: encodedOrder.kind,
608
+ validTo: encodedOrder.validTo,
609
+ appData: encodedOrder.appData
610
+ };
611
+ const ecdsaSignature = await signer.signTypedData(domain, ADAPTER_SIGNATURE_TYPES, message);
612
+ return OrderSigningUtils.getEip1271Signature(orderToSign, ecdsaSignature);
613
+ }
614
+ };
615
+ export {
616
+ AAVE_ADAPTER_FACTORY,
617
+ AAVE_COLLATERAL_SWAP_ADAPTER_HOOK,
618
+ AAVE_POOL_ADDRESS,
619
+ ADAPTER_DOMAIN_NAME,
620
+ ADAPTER_DOMAIN_VERSION,
621
+ ADAPTER_SIGNATURE_TYPES,
622
+ AaveCollateralSwapSdk,
623
+ DEFAULT_HOOK_GAS_LIMIT,
624
+ DEFAULT_VALIDITY,
625
+ EMPTY_PERMIT,
626
+ GAS_ESTIMATION_ADDITION_PERCENT,
627
+ HASH_ZERO,
628
+ PERCENT_SCALE
629
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@cowprotocol/sdk-flash-loans",
3
+ "version": "1.0.0",
4
+ "description": "Flash loans for CoW Protocol",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "license": "MIT",
10
+ "files": [
11
+ "dist/**"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "@cowprotocol/sdk-common": "0.2.2",
18
+ "@cowprotocol/sdk-trading": "0.4.2",
19
+ "@cowprotocol/sdk-app-data": "4.1.4",
20
+ "@cowprotocol/sdk-order-book": "0.1.3",
21
+ "@cowprotocol/sdk-order-signing": "0.1.7",
22
+ "@cowprotocol/sdk-config": "0.2.0"
23
+ },
24
+ "devDependencies": {
25
+ "ethers-v5": "npm:ethers@^5.7.2",
26
+ "ethers-v6": "npm:ethers@^6.13.7",
27
+ "@types/jest": "^29.4.0",
28
+ "@types/node": "^20.17.31",
29
+ "coveralls": "^3.1.1",
30
+ "tsup": "^7.2.0",
31
+ "typescript": "^5.2.2",
32
+ "jest": "^29.7.0",
33
+ "jest-fetch-mock": "^3.0.3",
34
+ "ts-jest": "^29.0.0",
35
+ "ethers": "^5.7.2",
36
+ "viem": "2.30.5",
37
+ "@cow-sdk/typescript-config": "0.0.0-beta.0",
38
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.1.3",
39
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.1.3",
40
+ "@cowprotocol/sdk-viem-adapter": "0.1.3"
41
+ },
42
+ "scripts": {
43
+ "build": "tsup src/index.ts --format esm,cjs --dts",
44
+ "lint": "eslint src/**/*.ts",
45
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
46
+ "test": "jest",
47
+ "test:coverage": "jest --coverage --json --outputFile=jest.results.json && npx coveralls < ./coverage/lcov.info",
48
+ "test:coverage:html": "jest --silent=false --coverage --coverageReporters html",
49
+ "test:aave-collateral-integration": "npx jest --testNamePattern=^AaveFlashLoanIntegration",
50
+ "typecheck": "tsc --noEmit"
51
+ }
52
+ }