@cowprotocol/sdk-flash-loans 1.3.0 → 1.4.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.d.mts CHANGED
@@ -114,6 +114,25 @@ declare const ADAPTER_SIGNATURE_TYPES: {
114
114
  declare const EMPTY_PERMIT: CollateralPermitData;
115
115
  declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
116
116
 
117
+ /**
118
+ * Configuration options for the AaveCollateralSwapSdk.
119
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} hookAdapterPerType -
120
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
121
+ * Defaults to the predefined addresses from the constants.
122
+ * @example
123
+ * ```typescript
124
+ * const config: AaveCollateralSwapSdkConfig = {
125
+ * hookAdapterPerType: {
126
+ * [AaveFlashLoanType.CollateralSwap]: {
127
+ * [SupportedChainId.GNOSIS_CHAIN]: '0x...',
128
+ * },
129
+ * },
130
+ * }
131
+ * ```
132
+ */
133
+ type AaveCollateralSwapSdkConfig = {
134
+ hookAdapterPerType?: Record<AaveFlashLoanType, Record<SupportedChainId, string>>;
135
+ };
117
136
  /**
118
137
  * SDK for executing Aave flash loan operations, particularly collateral swaps.
119
138
  *
@@ -125,6 +144,16 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
125
144
  * @see https://docs.cow.fi/
126
145
  */
127
146
  declare class AaveCollateralSwapSdk {
147
+ private readonly hookAdapterPerType;
148
+ /**
149
+ * Creates an instance of AaveCollateralSwapSdk.
150
+ *
151
+ * @param {Object} config - Configuration options for the SDK.
152
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
153
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
154
+ * Defaults to the predefined addresses from the constants.
155
+ */
156
+ constructor(config?: AaveCollateralSwapSdkConfig);
128
157
  /**
129
158
  * Executes a collateral swap using Aave flash loans.
130
159
  *
@@ -258,4 +287,4 @@ declare class AaveCollateralSwapSdk {
258
287
  private adapterEIP1271Signature;
259
288
  }
260
289
 
261
- export { AAVE_ADAPTER_FACTORY, AAVE_DAPP_ID_PER_TYPE, AAVE_HOOK_ADAPTER_PER_TYPE, AAVE_POOL_ADDRESS, ADAPTER_DOMAIN_NAME, ADAPTER_DOMAIN_VERSION, ADAPTER_SIGNATURE_TYPES, AaveCollateralSwapSdk, AaveFlashLoanType, BASIS_POINTS_SCALE, type CollateralOrderData, type CollateralParameters, type CollateralPermitData, type CollateralSwapOrder, type CollateralSwapParams, type CollateralSwapPostParams, type CollateralSwapQuoteParams, type CollateralSwapTradeParams, DEFAULT_HOOK_GAS_LIMIT, DEFAULT_VALIDITY, EMPTY_PERMIT, type EncodedOrder, type FlashLoanHint, type FlashLoanHookAmounts, GAS_ESTIMATION_ADDITION_PERCENT, HALF_BASIS_POINTS_SCALE, HASH_ZERO, PERCENT_SCALE };
290
+ export { AAVE_ADAPTER_FACTORY, AAVE_DAPP_ID_PER_TYPE, AAVE_HOOK_ADAPTER_PER_TYPE, AAVE_POOL_ADDRESS, ADAPTER_DOMAIN_NAME, ADAPTER_DOMAIN_VERSION, ADAPTER_SIGNATURE_TYPES, AaveCollateralSwapSdk, type AaveCollateralSwapSdkConfig, AaveFlashLoanType, BASIS_POINTS_SCALE, type CollateralOrderData, type CollateralParameters, type CollateralPermitData, type CollateralSwapOrder, type CollateralSwapParams, type CollateralSwapPostParams, type CollateralSwapQuoteParams, type CollateralSwapTradeParams, DEFAULT_HOOK_GAS_LIMIT, DEFAULT_VALIDITY, EMPTY_PERMIT, type EncodedOrder, type FlashLoanHint, type FlashLoanHookAmounts, GAS_ESTIMATION_ADDITION_PERCENT, HALF_BASIS_POINTS_SCALE, HASH_ZERO, PERCENT_SCALE };
package/dist/index.d.ts CHANGED
@@ -114,6 +114,25 @@ declare const ADAPTER_SIGNATURE_TYPES: {
114
114
  declare const EMPTY_PERMIT: CollateralPermitData;
115
115
  declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
116
116
 
117
+ /**
118
+ * Configuration options for the AaveCollateralSwapSdk.
119
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} hookAdapterPerType -
120
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
121
+ * Defaults to the predefined addresses from the constants.
122
+ * @example
123
+ * ```typescript
124
+ * const config: AaveCollateralSwapSdkConfig = {
125
+ * hookAdapterPerType: {
126
+ * [AaveFlashLoanType.CollateralSwap]: {
127
+ * [SupportedChainId.GNOSIS_CHAIN]: '0x...',
128
+ * },
129
+ * },
130
+ * }
131
+ * ```
132
+ */
133
+ type AaveCollateralSwapSdkConfig = {
134
+ hookAdapterPerType?: Record<AaveFlashLoanType, Record<SupportedChainId, string>>;
135
+ };
117
136
  /**
118
137
  * SDK for executing Aave flash loan operations, particularly collateral swaps.
119
138
  *
@@ -125,6 +144,16 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
125
144
  * @see https://docs.cow.fi/
126
145
  */
127
146
  declare class AaveCollateralSwapSdk {
147
+ private readonly hookAdapterPerType;
148
+ /**
149
+ * Creates an instance of AaveCollateralSwapSdk.
150
+ *
151
+ * @param {Object} config - Configuration options for the SDK.
152
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
153
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
154
+ * Defaults to the predefined addresses from the constants.
155
+ */
156
+ constructor(config?: AaveCollateralSwapSdkConfig);
128
157
  /**
129
158
  * Executes a collateral swap using Aave flash loans.
130
159
  *
@@ -258,4 +287,4 @@ declare class AaveCollateralSwapSdk {
258
287
  private adapterEIP1271Signature;
259
288
  }
260
289
 
261
- export { AAVE_ADAPTER_FACTORY, AAVE_DAPP_ID_PER_TYPE, AAVE_HOOK_ADAPTER_PER_TYPE, AAVE_POOL_ADDRESS, ADAPTER_DOMAIN_NAME, ADAPTER_DOMAIN_VERSION, ADAPTER_SIGNATURE_TYPES, AaveCollateralSwapSdk, AaveFlashLoanType, BASIS_POINTS_SCALE, type CollateralOrderData, type CollateralParameters, type CollateralPermitData, type CollateralSwapOrder, type CollateralSwapParams, type CollateralSwapPostParams, type CollateralSwapQuoteParams, type CollateralSwapTradeParams, DEFAULT_HOOK_GAS_LIMIT, DEFAULT_VALIDITY, EMPTY_PERMIT, type EncodedOrder, type FlashLoanHint, type FlashLoanHookAmounts, GAS_ESTIMATION_ADDITION_PERCENT, HALF_BASIS_POINTS_SCALE, HASH_ZERO, PERCENT_SCALE };
290
+ export { AAVE_ADAPTER_FACTORY, AAVE_DAPP_ID_PER_TYPE, AAVE_HOOK_ADAPTER_PER_TYPE, AAVE_POOL_ADDRESS, ADAPTER_DOMAIN_NAME, ADAPTER_DOMAIN_VERSION, ADAPTER_SIGNATURE_TYPES, AaveCollateralSwapSdk, type AaveCollateralSwapSdkConfig, AaveFlashLoanType, BASIS_POINTS_SCALE, type CollateralOrderData, type CollateralParameters, type CollateralPermitData, type CollateralSwapOrder, type CollateralSwapParams, type CollateralSwapPostParams, type CollateralSwapQuoteParams, type CollateralSwapTradeParams, DEFAULT_HOOK_GAS_LIMIT, DEFAULT_VALIDITY, EMPTY_PERMIT, type EncodedOrder, type FlashLoanHint, type FlashLoanHookAmounts, GAS_ESTIMATION_ADDITION_PERCENT, HALF_BASIS_POINTS_SCALE, HASH_ZERO, PERCENT_SCALE };
package/dist/index.js CHANGED
@@ -449,6 +449,18 @@ var repayWithCollateralAdapterAbi = [
449
449
 
450
450
  // src/aave/AaveCollateralSwapSdk.ts
451
451
  var AaveCollateralSwapSdk = class {
452
+ hookAdapterPerType;
453
+ /**
454
+ * Creates an instance of AaveCollateralSwapSdk.
455
+ *
456
+ * @param {Object} config - Configuration options for the SDK.
457
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
458
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
459
+ * Defaults to the predefined addresses from the constants.
460
+ */
461
+ constructor(config) {
462
+ this.hookAdapterPerType = config?.hookAdapterPerType ?? AAVE_HOOK_ADAPTER_PER_TYPE;
463
+ }
452
464
  /**
453
465
  * Executes a collateral swap using Aave flash loans.
454
466
  *
@@ -704,7 +716,7 @@ var AaveCollateralSwapSdk = class {
704
716
  const hookData = this.buildHookOrderData(trader, hookAmounts, order);
705
717
  return await (0, import_sdk_common.getGlobalAdapter)().readContract({
706
718
  address: AAVE_ADAPTER_FACTORY[chainId],
707
- args: [AAVE_HOOK_ADAPTER_PER_TYPE[flashLoanType][chainId], hookData],
719
+ args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
708
720
  functionName: "getInstanceDeterministicAddress",
709
721
  abi: aaveAdapterFactoryAbi
710
722
  });
@@ -732,7 +744,7 @@ var AaveCollateralSwapSdk = class {
732
744
  }
733
745
  getPreHookCallData(flashLoanType, chainId, trader, hookAmounts, order, instanceAddress) {
734
746
  const hookData = this.buildHookOrderData(trader, hookAmounts, order);
735
- const adapterImplementation = AAVE_HOOK_ADAPTER_PER_TYPE[flashLoanType][chainId];
747
+ const adapterImplementation = this.hookAdapterPerType[flashLoanType][chainId];
736
748
  return (0, import_sdk_common.getGlobalAdapter)().utils.encodeFunction(aaveAdapterFactoryAbi, "deployAndTransferFlashLoan", [
737
749
  adapterImplementation,
738
750
  { ...hookData, receiver: instanceAddress }
package/dist/index.mjs CHANGED
@@ -412,6 +412,18 @@ var repayWithCollateralAdapterAbi = [
412
412
 
413
413
  // src/aave/AaveCollateralSwapSdk.ts
414
414
  var AaveCollateralSwapSdk = class {
415
+ hookAdapterPerType;
416
+ /**
417
+ * Creates an instance of AaveCollateralSwapSdk.
418
+ *
419
+ * @param {Object} config - Configuration options for the SDK.
420
+ * @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
421
+ * Mapping of flash loan types to chain-specific hook adapter addresses.
422
+ * Defaults to the predefined addresses from the constants.
423
+ */
424
+ constructor(config) {
425
+ this.hookAdapterPerType = config?.hookAdapterPerType ?? AAVE_HOOK_ADAPTER_PER_TYPE;
426
+ }
415
427
  /**
416
428
  * Executes a collateral swap using Aave flash loans.
417
429
  *
@@ -667,7 +679,7 @@ var AaveCollateralSwapSdk = class {
667
679
  const hookData = this.buildHookOrderData(trader, hookAmounts, order);
668
680
  return await getGlobalAdapter().readContract({
669
681
  address: AAVE_ADAPTER_FACTORY[chainId],
670
- args: [AAVE_HOOK_ADAPTER_PER_TYPE[flashLoanType][chainId], hookData],
682
+ args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
671
683
  functionName: "getInstanceDeterministicAddress",
672
684
  abi: aaveAdapterFactoryAbi
673
685
  });
@@ -695,7 +707,7 @@ var AaveCollateralSwapSdk = class {
695
707
  }
696
708
  getPreHookCallData(flashLoanType, chainId, trader, hookAmounts, order, instanceAddress) {
697
709
  const hookData = this.buildHookOrderData(trader, hookAmounts, order);
698
- const adapterImplementation = AAVE_HOOK_ADAPTER_PER_TYPE[flashLoanType][chainId];
710
+ const adapterImplementation = this.hookAdapterPerType[flashLoanType][chainId];
699
711
  return getGlobalAdapter().utils.encodeFunction(aaveAdapterFactoryAbi, "deployAndTransferFlashLoan", [
700
712
  adapterImplementation,
701
713
  { ...hookData, receiver: instanceAddress }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-flash-loans",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Flash loans for CoW Protocol",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -17,9 +17,9 @@
17
17
  "@cowprotocol/sdk-common": "0.3.0",
18
18
  "@cowprotocol/sdk-app-data": "4.1.6",
19
19
  "@cowprotocol/sdk-trading": "0.4.6",
20
- "@cowprotocol/sdk-order-signing": "0.1.11",
21
20
  "@cowprotocol/sdk-order-book": "0.2.0",
22
- "@cowprotocol/sdk-config": "0.3.0"
21
+ "@cowprotocol/sdk-config": "0.3.0",
22
+ "@cowprotocol/sdk-order-signing": "0.1.11"
23
23
  },
24
24
  "devDependencies": {
25
25
  "ethers-v5": "npm:ethers@^5.7.2",
@@ -36,8 +36,8 @@
36
36
  "viem": "2.30.5",
37
37
  "@cow-sdk/typescript-config": "0.0.0-beta.0",
38
38
  "@cowprotocol/sdk-ethers-v5-adapter": "0.2.0",
39
- "@cowprotocol/sdk-viem-adapter": "0.2.0",
40
- "@cowprotocol/sdk-ethers-v6-adapter": "0.2.0"
39
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.2.0",
40
+ "@cowprotocol/sdk-viem-adapter": "0.2.0"
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsup src/index.ts --format esm,cjs --dts",