@cowprotocol/sdk-flash-loans 3.0.3 → 3.0.5

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.d.mts CHANGED
@@ -66,9 +66,25 @@ interface CollateralSwapTradeParams {
66
66
  hooksGasLimit?: CollateralSwapHooksGasLimit;
67
67
  }
68
68
  interface CollateralSwapOrder {
69
- sellAmount: bigint;
70
- buyAmount: bigint;
69
+ /**
70
+ * Gross amount borrowed via the Aave flash loan, in the underlying token's unit.
71
+ * Populates {@link FlashLoanHookAmounts.flashLoanAmount} on the resulting hooks.
72
+ * Includes the portion that gets repaid as the flash loan fee — i.e. `orderToSign.sellAmount + flashLoanFeeAmount`
73
+ * for a standard collateral swap, since aTokens are 1:1 with the underlying.
74
+ */
75
+ flashLoanAmount: bigint;
76
+ /**
77
+ * The unsigned CoW Protocol order that will be signed via EIP-1271. The order's `sellAmount`,
78
+ * `buyAmount`, `sellToken`, `buyToken`, `kind`, and `validTo` are the source of truth for the
79
+ * hooks — flash loan amount and hook buy/sell amounts are derived from this order to guarantee
80
+ * the generated hooks match the order they get attached to.
81
+ */
71
82
  orderToSign: UnsignedOrder;
83
+ /**
84
+ * Optional EIP-2612 permit signature authorizing the adapter to spend the collateral aToken.
85
+ * When provided, the SDK uses permit-based approval instead of a separate `approve` tx. Leave
86
+ * undefined to fall back to the standard ERC-20 approval flow.
87
+ */
72
88
  collateralPermit?: CollateralPermitData;
73
89
  }
74
90
  interface CollateralSwapQuoteParams extends Omit<TradeParameters, 'owner' | 'validTo'>, CollateralSwapTradeParams {
@@ -238,6 +254,9 @@ declare class AaveCollateralSwapSdk {
238
254
  * and token amounts required for execution. The hooks enable the order to trigger
239
255
  * flash loan deployment (pre-hook) and collateral swap execution (post-hook).
240
256
  *
257
+ * @param {AaveFlashLoanType} flashLoanType - The flash loan flow to configure (CollateralSwap,
258
+ * DebtSwap, or RepayCollateral). Selects which Aave
259
+ * hook adapter and post-hook call data are used.
241
260
  * @param {CollateralSwapTradeParams} params - Trade parameters including chain ID, validity period,
242
261
  * owner address, and flash loan fee amount.
243
262
  * @param {CollateralSwapOrder} settings - Order configuration including sell/buy amounts, the
package/dist/index.d.ts CHANGED
@@ -66,9 +66,25 @@ interface CollateralSwapTradeParams {
66
66
  hooksGasLimit?: CollateralSwapHooksGasLimit;
67
67
  }
68
68
  interface CollateralSwapOrder {
69
- sellAmount: bigint;
70
- buyAmount: bigint;
69
+ /**
70
+ * Gross amount borrowed via the Aave flash loan, in the underlying token's unit.
71
+ * Populates {@link FlashLoanHookAmounts.flashLoanAmount} on the resulting hooks.
72
+ * Includes the portion that gets repaid as the flash loan fee — i.e. `orderToSign.sellAmount + flashLoanFeeAmount`
73
+ * for a standard collateral swap, since aTokens are 1:1 with the underlying.
74
+ */
75
+ flashLoanAmount: bigint;
76
+ /**
77
+ * The unsigned CoW Protocol order that will be signed via EIP-1271. The order's `sellAmount`,
78
+ * `buyAmount`, `sellToken`, `buyToken`, `kind`, and `validTo` are the source of truth for the
79
+ * hooks — flash loan amount and hook buy/sell amounts are derived from this order to guarantee
80
+ * the generated hooks match the order they get attached to.
81
+ */
71
82
  orderToSign: UnsignedOrder;
83
+ /**
84
+ * Optional EIP-2612 permit signature authorizing the adapter to spend the collateral aToken.
85
+ * When provided, the SDK uses permit-based approval instead of a separate `approve` tx. Leave
86
+ * undefined to fall back to the standard ERC-20 approval flow.
87
+ */
72
88
  collateralPermit?: CollateralPermitData;
73
89
  }
74
90
  interface CollateralSwapQuoteParams extends Omit<TradeParameters, 'owner' | 'validTo'>, CollateralSwapTradeParams {
@@ -238,6 +254,9 @@ declare class AaveCollateralSwapSdk {
238
254
  * and token amounts required for execution. The hooks enable the order to trigger
239
255
  * flash loan deployment (pre-hook) and collateral swap execution (post-hook).
240
256
  *
257
+ * @param {AaveFlashLoanType} flashLoanType - The flash loan flow to configure (CollateralSwap,
258
+ * DebtSwap, or RepayCollateral). Selects which Aave
259
+ * hook adapter and post-hook call data are used.
241
260
  * @param {CollateralSwapTradeParams} params - Trade parameters including chain ID, validity period,
242
261
  * owner address, and flash loan fee amount.
243
262
  * @param {CollateralSwapOrder} settings - Order configuration including sell/buy amounts, the
package/dist/index.js CHANGED
@@ -487,15 +487,14 @@ var AaveCollateralSwapSdk = class {
487
487
  tradeParameters: { amount },
488
488
  settings
489
489
  } = params;
490
- const sellAmount = BigInt(amount);
490
+ const flashLoanAmount = BigInt(amount);
491
491
  const quoteAndPost = await tradingSdk.getQuote(quoteParams);
492
492
  const { quoteResults, postSwapOrderFromQuote } = quoteAndPost;
493
493
  const { swapSettings, instanceAddress } = await this.getOrderPostingSettings(
494
494
  "CollateralSwap" /* CollateralSwap */,
495
495
  quoteParams,
496
496
  {
497
- sellAmount,
498
- buyAmount: quoteResults.amountsAndCosts.afterSlippage.buyAmount,
497
+ flashLoanAmount,
499
498
  orderToSign: quoteResults.orderToSign,
500
499
  collateralPermit: settings?.collateralPermit
501
500
  }
@@ -504,10 +503,10 @@ var AaveCollateralSwapSdk = class {
504
503
  instanceAddress,
505
504
  trader: quoteParams.owner,
506
505
  collateralToken,
507
- amount: sellAmount
506
+ amount: flashLoanAmount
508
507
  };
509
508
  if (!settings?.preventApproval && !settings?.collateralPermit) {
510
- await this.approveCollateralIfNeeded(collateralParams, sellAmount);
509
+ await this.approveCollateralIfNeeded(collateralParams);
511
510
  }
512
511
  return postSwapOrderFromQuote(swapSettings);
513
512
  }
@@ -567,6 +566,9 @@ var AaveCollateralSwapSdk = class {
567
566
  * and token amounts required for execution. The hooks enable the order to trigger
568
567
  * flash loan deployment (pre-hook) and collateral swap execution (post-hook).
569
568
  *
569
+ * @param {AaveFlashLoanType} flashLoanType - The flash loan flow to configure (CollateralSwap,
570
+ * DebtSwap, or RepayCollateral). Selects which Aave
571
+ * hook adapter and post-hook call data are used.
570
572
  * @param {CollateralSwapTradeParams} params - Trade parameters including chain ID, validity period,
571
573
  * owner address, and flash loan fee amount.
572
574
  * @param {CollateralSwapOrder} settings - Order configuration including sell/buy amounts, the
@@ -579,9 +581,10 @@ var AaveCollateralSwapSdk = class {
579
581
  * ```
580
582
  */
581
583
  async getOrderPostingSettings(flashLoanType, params, settings) {
582
- const { sellAmount, buyAmount, orderToSign, collateralPermit } = settings;
584
+ const { flashLoanAmount, orderToSign, collateralPermit } = settings;
583
585
  const { chainId, flashLoanFeeAmount, validTo, owner: trader } = params;
584
- const amount = sellAmount.toString();
586
+ const amount = flashLoanAmount.toString();
587
+ const buyAmount = orderToSign.buyAmount;
585
588
  const encodedOrder = {
586
589
  ...import_sdk_order_signing.OrderSigningUtils.encodeUnsignedOrder(orderToSign),
587
590
  appData: HASH_ZERO,
@@ -591,7 +594,7 @@ var AaveCollateralSwapSdk = class {
591
594
  flashLoanAmount: amount,
592
595
  flashLoanFeeAmount: flashLoanFeeAmount.toString(),
593
596
  sellAssetAmount: amount,
594
- buyAssetAmount: buyAmount.toString()
597
+ buyAssetAmount: buyAmount
595
598
  };
596
599
  const instanceAddress = await this.getExpectedInstanceAddress(
597
600
  flashLoanType,
@@ -723,12 +726,12 @@ var AaveCollateralSwapSdk = class {
723
726
  abi: aaveAdapterFactoryAbi
724
727
  });
725
728
  }
726
- async approveCollateralIfNeeded(collateralParams, sellAmount) {
729
+ async approveCollateralIfNeeded(collateralParams) {
727
730
  const allowance = await this.getCollateralAllowance(collateralParams).catch((error) => {
728
731
  console.error("[AaveCollateralSwapSdk] Could not get allowance for collateral token", error);
729
732
  return null;
730
733
  });
731
- if (!allowance || allowance < sellAmount) {
734
+ if (!allowance || allowance < collateralParams.amount) {
732
735
  await this.approveCollateral(collateralParams);
733
736
  }
734
737
  }
package/dist/index.mjs CHANGED
@@ -450,15 +450,14 @@ var AaveCollateralSwapSdk = class {
450
450
  tradeParameters: { amount },
451
451
  settings
452
452
  } = params;
453
- const sellAmount = BigInt(amount);
453
+ const flashLoanAmount = BigInt(amount);
454
454
  const quoteAndPost = await tradingSdk.getQuote(quoteParams);
455
455
  const { quoteResults, postSwapOrderFromQuote } = quoteAndPost;
456
456
  const { swapSettings, instanceAddress } = await this.getOrderPostingSettings(
457
457
  "CollateralSwap" /* CollateralSwap */,
458
458
  quoteParams,
459
459
  {
460
- sellAmount,
461
- buyAmount: quoteResults.amountsAndCosts.afterSlippage.buyAmount,
460
+ flashLoanAmount,
462
461
  orderToSign: quoteResults.orderToSign,
463
462
  collateralPermit: settings?.collateralPermit
464
463
  }
@@ -467,10 +466,10 @@ var AaveCollateralSwapSdk = class {
467
466
  instanceAddress,
468
467
  trader: quoteParams.owner,
469
468
  collateralToken,
470
- amount: sellAmount
469
+ amount: flashLoanAmount
471
470
  };
472
471
  if (!settings?.preventApproval && !settings?.collateralPermit) {
473
- await this.approveCollateralIfNeeded(collateralParams, sellAmount);
472
+ await this.approveCollateralIfNeeded(collateralParams);
474
473
  }
475
474
  return postSwapOrderFromQuote(swapSettings);
476
475
  }
@@ -530,6 +529,9 @@ var AaveCollateralSwapSdk = class {
530
529
  * and token amounts required for execution. The hooks enable the order to trigger
531
530
  * flash loan deployment (pre-hook) and collateral swap execution (post-hook).
532
531
  *
532
+ * @param {AaveFlashLoanType} flashLoanType - The flash loan flow to configure (CollateralSwap,
533
+ * DebtSwap, or RepayCollateral). Selects which Aave
534
+ * hook adapter and post-hook call data are used.
533
535
  * @param {CollateralSwapTradeParams} params - Trade parameters including chain ID, validity period,
534
536
  * owner address, and flash loan fee amount.
535
537
  * @param {CollateralSwapOrder} settings - Order configuration including sell/buy amounts, the
@@ -542,9 +544,10 @@ var AaveCollateralSwapSdk = class {
542
544
  * ```
543
545
  */
544
546
  async getOrderPostingSettings(flashLoanType, params, settings) {
545
- const { sellAmount, buyAmount, orderToSign, collateralPermit } = settings;
547
+ const { flashLoanAmount, orderToSign, collateralPermit } = settings;
546
548
  const { chainId, flashLoanFeeAmount, validTo, owner: trader } = params;
547
- const amount = sellAmount.toString();
549
+ const amount = flashLoanAmount.toString();
550
+ const buyAmount = orderToSign.buyAmount;
548
551
  const encodedOrder = {
549
552
  ...OrderSigningUtils.encodeUnsignedOrder(orderToSign),
550
553
  appData: HASH_ZERO,
@@ -554,7 +557,7 @@ var AaveCollateralSwapSdk = class {
554
557
  flashLoanAmount: amount,
555
558
  flashLoanFeeAmount: flashLoanFeeAmount.toString(),
556
559
  sellAssetAmount: amount,
557
- buyAssetAmount: buyAmount.toString()
560
+ buyAssetAmount: buyAmount
558
561
  };
559
562
  const instanceAddress = await this.getExpectedInstanceAddress(
560
563
  flashLoanType,
@@ -686,12 +689,12 @@ var AaveCollateralSwapSdk = class {
686
689
  abi: aaveAdapterFactoryAbi
687
690
  });
688
691
  }
689
- async approveCollateralIfNeeded(collateralParams, sellAmount) {
692
+ async approveCollateralIfNeeded(collateralParams) {
690
693
  const allowance = await this.getCollateralAllowance(collateralParams).catch((error) => {
691
694
  console.error("[AaveCollateralSwapSdk] Could not get allowance for collateral token", error);
692
695
  return null;
693
696
  });
694
- if (!allowance || allowance < sellAmount) {
697
+ if (!allowance || allowance < collateralParams.amount) {
695
698
  await this.approveCollateral(collateralParams);
696
699
  }
697
700
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-flash-loans",
3
- "version": "3.0.3",
3
+ "version": "3.0.5",
4
4
  "description": "Flash loans for CoW Protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,12 +19,12 @@
19
19
  "access": "public"
20
20
  },
21
21
  "dependencies": {
22
- "@cowprotocol/sdk-common": "0.10.2",
23
- "@cowprotocol/sdk-order-signing": "1.0.1",
24
- "@cowprotocol/sdk-app-data": "5.1.0",
25
- "@cowprotocol/sdk-order-book": "3.0.0",
26
- "@cowprotocol/sdk-config": "2.0.0",
27
- "@cowprotocol/sdk-trading": "2.0.3"
22
+ "@cowprotocol/sdk-trading": "2.0.5",
23
+ "@cowprotocol/sdk-common": "0.10.3",
24
+ "@cowprotocol/sdk-order-signing": "1.0.3",
25
+ "@cowprotocol/sdk-app-data": "5.1.2",
26
+ "@cowprotocol/sdk-order-book": "3.1.0",
27
+ "@cowprotocol/sdk-config": "2.1.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "ethers-v5": "npm:ethers@^5.7.2",
@@ -40,9 +40,9 @@
40
40
  "ethers": "^5.7.2",
41
41
  "viem": "2.30.5",
42
42
  "@cow-sdk/typescript-config": "0.0.0-beta.0",
43
- "@cowprotocol/sdk-ethers-v5-adapter": "0.4.4",
44
- "@cowprotocol/sdk-ethers-v6-adapter": "0.4.4",
45
- "@cowprotocol/sdk-viem-adapter": "0.3.18"
43
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.4.6",
44
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.4.6",
45
+ "@cowprotocol/sdk-viem-adapter": "0.3.20"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsup src/index.ts --format esm,cjs --dts",