@cowprotocol/sdk-flash-loans 1.2.1 → 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 +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +57 -13
- package/dist/index.mjs +58 -14
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -103,7 +103,7 @@ declare const BASIS_POINTS_SCALE: bigint;
|
|
|
103
103
|
declare const HALF_BASIS_POINTS_SCALE: bigint;
|
|
104
104
|
declare const DEFAULT_VALIDITY: number;
|
|
105
105
|
declare const GAS_ESTIMATION_ADDITION_PERCENT = 10;
|
|
106
|
-
declare const ADAPTER_DOMAIN_NAME = "
|
|
106
|
+
declare const ADAPTER_DOMAIN_NAME = "AaveV3AdapterFactory";
|
|
107
107
|
declare const ADAPTER_DOMAIN_VERSION = "1";
|
|
108
108
|
declare const ADAPTER_SIGNATURE_TYPES: {
|
|
109
109
|
AdapterOrderSig: {
|
|
@@ -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
|
@@ -103,7 +103,7 @@ declare const BASIS_POINTS_SCALE: bigint;
|
|
|
103
103
|
declare const HALF_BASIS_POINTS_SCALE: bigint;
|
|
104
104
|
declare const DEFAULT_VALIDITY: number;
|
|
105
105
|
declare const GAS_ESTIMATION_ADDITION_PERCENT = 10;
|
|
106
|
-
declare const ADAPTER_DOMAIN_NAME = "
|
|
106
|
+
declare const ADAPTER_DOMAIN_NAME = "AaveV3AdapterFactory";
|
|
107
107
|
declare const ADAPTER_DOMAIN_VERSION = "1";
|
|
108
108
|
declare const ADAPTER_SIGNATURE_TYPES: {
|
|
109
109
|
AdapterOrderSig: {
|
|
@@ -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
|
@@ -54,11 +54,43 @@ var AaveFlashLoanType = /* @__PURE__ */ ((AaveFlashLoanType2) => {
|
|
|
54
54
|
AaveFlashLoanType2["RepayCollateral"] = "RepayCollateral";
|
|
55
55
|
return AaveFlashLoanType2;
|
|
56
56
|
})(AaveFlashLoanType || {});
|
|
57
|
-
var AAVE_POOL_ADDRESS =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
var AAVE_POOL_ADDRESS = {
|
|
58
|
+
[import_sdk_config.SupportedChainId.SEPOLIA]: "",
|
|
59
|
+
[import_sdk_config.SupportedChainId.LENS]: "",
|
|
60
|
+
[import_sdk_config.SupportedChainId.GNOSIS_CHAIN]: "0xb50201558B00496A145fE76f7424749556E326D8",
|
|
61
|
+
[import_sdk_config.SupportedChainId.MAINNET]: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
|
|
62
|
+
[import_sdk_config.SupportedChainId.BASE]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
|
|
63
|
+
[import_sdk_config.SupportedChainId.ARBITRUM_ONE]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
64
|
+
[import_sdk_config.SupportedChainId.AVALANCHE]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
65
|
+
[import_sdk_config.SupportedChainId.BNB]: "0x6807dc923806fE8Fd134338EABCA509979a7e0cB",
|
|
66
|
+
[import_sdk_config.SupportedChainId.POLYGON]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
67
|
+
[import_sdk_config.SupportedChainId.LINEA]: "0xc47b8C00b0f69a36fa203Ffeac0334874574a8Ac",
|
|
68
|
+
[import_sdk_config.SupportedChainId.PLASMA]: "0x925a2A7214Ed92428B5b1B090F80b25700095e12"
|
|
69
|
+
};
|
|
70
|
+
var AAVE_ADAPTER_FACTORY = {
|
|
71
|
+
...(0, import_sdk_config.mapAddressToSupportedNetworks)(""),
|
|
72
|
+
[import_sdk_config.SupportedChainId.GNOSIS_CHAIN]: "0x7f230F7Cee38ca371b871B74B3C6ded4932A2f93",
|
|
73
|
+
[import_sdk_config.SupportedChainId.MAINNET]: "0x22E08c56a6799e28e7b05A117D853B9b46abc017",
|
|
74
|
+
[import_sdk_config.SupportedChainId.BASE]: "0xc5D68e305e0b5998f895e34d4440954072F285B6"
|
|
75
|
+
};
|
|
76
|
+
var AAVE_COLLATERAL_SWAP_ADAPTER_HOOK = {
|
|
77
|
+
...(0, import_sdk_config.mapAddressToSupportedNetworks)(""),
|
|
78
|
+
[import_sdk_config.SupportedChainId.GNOSIS_CHAIN]: "0x837aA74e8daf7Fd7160f078ca455a67B7F441E4b",
|
|
79
|
+
[import_sdk_config.SupportedChainId.MAINNET]: "0xFEb471EC22E5572dbb44229301c266f4C305A78a",
|
|
80
|
+
[import_sdk_config.SupportedChainId.BASE]: "0xBb45A7898A6f06a9c148BfeD0C103140F0079cd9"
|
|
81
|
+
};
|
|
82
|
+
var AAVE_DEBT_SWAP_ADAPTER_HOOK = {
|
|
83
|
+
...(0, import_sdk_config.mapAddressToSupportedNetworks)(""),
|
|
84
|
+
[import_sdk_config.SupportedChainId.GNOSIS_CHAIN]: "0xC9A495A17B1eeC18AE0f0865840B8fd3f8a9DE3F",
|
|
85
|
+
[import_sdk_config.SupportedChainId.MAINNET]: "0x238f57A2c3F0696fB20295075a0F9A18EfC67D3a",
|
|
86
|
+
[import_sdk_config.SupportedChainId.BASE]: "0xaCbd34fAB78BD6C8738eb32dDAFd688df98CD2E3"
|
|
87
|
+
};
|
|
88
|
+
var AAVE_REPAY_COLLATERAL_ADAPTER_HOOK = {
|
|
89
|
+
...(0, import_sdk_config.mapAddressToSupportedNetworks)(""),
|
|
90
|
+
[import_sdk_config.SupportedChainId.GNOSIS_CHAIN]: "0x2890CE372f3a397B6f3BB3a71B1836A6F3F33657",
|
|
91
|
+
[import_sdk_config.SupportedChainId.MAINNET]: "0x9eB0ffd318e862D344792a8e589e8393E8bEd96F",
|
|
92
|
+
[import_sdk_config.SupportedChainId.BASE]: "0x1549445700D0Cb2D7Ce85ECd5a7FD7Ba4a3D40A7"
|
|
93
|
+
};
|
|
62
94
|
var AAVE_HOOK_ADAPTER_PER_TYPE = {
|
|
63
95
|
["CollateralSwap" /* CollateralSwap */]: AAVE_COLLATERAL_SWAP_ADAPTER_HOOK,
|
|
64
96
|
["DebtSwap" /* DebtSwap */]: AAVE_DEBT_SWAP_ADAPTER_HOOK,
|
|
@@ -73,7 +105,7 @@ var BASIS_POINTS_SCALE = BigInt(100 * PERCENT_SCALE);
|
|
|
73
105
|
var HALF_BASIS_POINTS_SCALE = BASIS_POINTS_SCALE / 2n;
|
|
74
106
|
var DEFAULT_VALIDITY = 10 * 60;
|
|
75
107
|
var GAS_ESTIMATION_ADDITION_PERCENT = 10;
|
|
76
|
-
var ADAPTER_DOMAIN_NAME = "
|
|
108
|
+
var ADAPTER_DOMAIN_NAME = "AaveV3AdapterFactory";
|
|
77
109
|
var ADAPTER_DOMAIN_VERSION = "1";
|
|
78
110
|
var ADAPTER_SIGNATURE_TYPES = {
|
|
79
111
|
AdapterOrderSig: [
|
|
@@ -269,17 +301,17 @@ var aaveAdapterFactoryAbi = [
|
|
|
269
301
|
stateMutability: "nonpayable"
|
|
270
302
|
},
|
|
271
303
|
{
|
|
272
|
-
|
|
304
|
+
type: "function",
|
|
273
305
|
name: "DOMAIN_SEPARATOR",
|
|
306
|
+
inputs: [],
|
|
274
307
|
outputs: [
|
|
275
308
|
{
|
|
276
|
-
internalType: "bytes32",
|
|
277
309
|
name: "",
|
|
278
|
-
type: "bytes32"
|
|
310
|
+
type: "bytes32",
|
|
311
|
+
internalType: "bytes32"
|
|
279
312
|
}
|
|
280
313
|
],
|
|
281
|
-
stateMutability: "view"
|
|
282
|
-
type: "function"
|
|
314
|
+
stateMutability: "view"
|
|
283
315
|
}
|
|
284
316
|
];
|
|
285
317
|
|
|
@@ -417,6 +449,18 @@ var repayWithCollateralAdapterAbi = [
|
|
|
417
449
|
|
|
418
450
|
// src/aave/AaveCollateralSwapSdk.ts
|
|
419
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
|
+
}
|
|
420
464
|
/**
|
|
421
465
|
* Executes a collateral swap using Aave flash loans.
|
|
422
466
|
*
|
|
@@ -672,7 +716,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
672
716
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
673
717
|
return await (0, import_sdk_common.getGlobalAdapter)().readContract({
|
|
674
718
|
address: AAVE_ADAPTER_FACTORY[chainId],
|
|
675
|
-
args: [
|
|
719
|
+
args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
|
|
676
720
|
functionName: "getInstanceDeterministicAddress",
|
|
677
721
|
abi: aaveAdapterFactoryAbi
|
|
678
722
|
});
|
|
@@ -700,7 +744,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
700
744
|
}
|
|
701
745
|
getPreHookCallData(flashLoanType, chainId, trader, hookAmounts, order, instanceAddress) {
|
|
702
746
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
703
|
-
const adapterImplementation =
|
|
747
|
+
const adapterImplementation = this.hookAdapterPerType[flashLoanType][chainId];
|
|
704
748
|
return (0, import_sdk_common.getGlobalAdapter)().utils.encodeFunction(aaveAdapterFactoryAbi, "deployAndTransferFlashLoan", [
|
|
705
749
|
adapterImplementation,
|
|
706
750
|
{ ...hookData, receiver: instanceAddress }
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { OrderSigningUtils } from "@cowprotocol/sdk-order-signing";
|
|
|
9
9
|
import { SigningScheme } from "@cowprotocol/sdk-order-book";
|
|
10
10
|
|
|
11
11
|
// src/aave/const.ts
|
|
12
|
-
import { mapAddressToSupportedNetworks } from "@cowprotocol/sdk-config";
|
|
12
|
+
import { mapAddressToSupportedNetworks, SupportedChainId } from "@cowprotocol/sdk-config";
|
|
13
13
|
var HASH_ZERO = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
14
14
|
var AaveFlashLoanType = /* @__PURE__ */ ((AaveFlashLoanType2) => {
|
|
15
15
|
AaveFlashLoanType2["CollateralSwap"] = "CollateralSwap";
|
|
@@ -17,11 +17,43 @@ var AaveFlashLoanType = /* @__PURE__ */ ((AaveFlashLoanType2) => {
|
|
|
17
17
|
AaveFlashLoanType2["RepayCollateral"] = "RepayCollateral";
|
|
18
18
|
return AaveFlashLoanType2;
|
|
19
19
|
})(AaveFlashLoanType || {});
|
|
20
|
-
var AAVE_POOL_ADDRESS =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
var AAVE_POOL_ADDRESS = {
|
|
21
|
+
[SupportedChainId.SEPOLIA]: "",
|
|
22
|
+
[SupportedChainId.LENS]: "",
|
|
23
|
+
[SupportedChainId.GNOSIS_CHAIN]: "0xb50201558B00496A145fE76f7424749556E326D8",
|
|
24
|
+
[SupportedChainId.MAINNET]: "0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2",
|
|
25
|
+
[SupportedChainId.BASE]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
|
|
26
|
+
[SupportedChainId.ARBITRUM_ONE]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
27
|
+
[SupportedChainId.AVALANCHE]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
28
|
+
[SupportedChainId.BNB]: "0x6807dc923806fE8Fd134338EABCA509979a7e0cB",
|
|
29
|
+
[SupportedChainId.POLYGON]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
30
|
+
[SupportedChainId.LINEA]: "0xc47b8C00b0f69a36fa203Ffeac0334874574a8Ac",
|
|
31
|
+
[SupportedChainId.PLASMA]: "0x925a2A7214Ed92428B5b1B090F80b25700095e12"
|
|
32
|
+
};
|
|
33
|
+
var AAVE_ADAPTER_FACTORY = {
|
|
34
|
+
...mapAddressToSupportedNetworks(""),
|
|
35
|
+
[SupportedChainId.GNOSIS_CHAIN]: "0x7f230F7Cee38ca371b871B74B3C6ded4932A2f93",
|
|
36
|
+
[SupportedChainId.MAINNET]: "0x22E08c56a6799e28e7b05A117D853B9b46abc017",
|
|
37
|
+
[SupportedChainId.BASE]: "0xc5D68e305e0b5998f895e34d4440954072F285B6"
|
|
38
|
+
};
|
|
39
|
+
var AAVE_COLLATERAL_SWAP_ADAPTER_HOOK = {
|
|
40
|
+
...mapAddressToSupportedNetworks(""),
|
|
41
|
+
[SupportedChainId.GNOSIS_CHAIN]: "0x837aA74e8daf7Fd7160f078ca455a67B7F441E4b",
|
|
42
|
+
[SupportedChainId.MAINNET]: "0xFEb471EC22E5572dbb44229301c266f4C305A78a",
|
|
43
|
+
[SupportedChainId.BASE]: "0xBb45A7898A6f06a9c148BfeD0C103140F0079cd9"
|
|
44
|
+
};
|
|
45
|
+
var AAVE_DEBT_SWAP_ADAPTER_HOOK = {
|
|
46
|
+
...mapAddressToSupportedNetworks(""),
|
|
47
|
+
[SupportedChainId.GNOSIS_CHAIN]: "0xC9A495A17B1eeC18AE0f0865840B8fd3f8a9DE3F",
|
|
48
|
+
[SupportedChainId.MAINNET]: "0x238f57A2c3F0696fB20295075a0F9A18EfC67D3a",
|
|
49
|
+
[SupportedChainId.BASE]: "0xaCbd34fAB78BD6C8738eb32dDAFd688df98CD2E3"
|
|
50
|
+
};
|
|
51
|
+
var AAVE_REPAY_COLLATERAL_ADAPTER_HOOK = {
|
|
52
|
+
...mapAddressToSupportedNetworks(""),
|
|
53
|
+
[SupportedChainId.GNOSIS_CHAIN]: "0x2890CE372f3a397B6f3BB3a71B1836A6F3F33657",
|
|
54
|
+
[SupportedChainId.MAINNET]: "0x9eB0ffd318e862D344792a8e589e8393E8bEd96F",
|
|
55
|
+
[SupportedChainId.BASE]: "0x1549445700D0Cb2D7Ce85ECd5a7FD7Ba4a3D40A7"
|
|
56
|
+
};
|
|
25
57
|
var AAVE_HOOK_ADAPTER_PER_TYPE = {
|
|
26
58
|
["CollateralSwap" /* CollateralSwap */]: AAVE_COLLATERAL_SWAP_ADAPTER_HOOK,
|
|
27
59
|
["DebtSwap" /* DebtSwap */]: AAVE_DEBT_SWAP_ADAPTER_HOOK,
|
|
@@ -36,7 +68,7 @@ var BASIS_POINTS_SCALE = BigInt(100 * PERCENT_SCALE);
|
|
|
36
68
|
var HALF_BASIS_POINTS_SCALE = BASIS_POINTS_SCALE / 2n;
|
|
37
69
|
var DEFAULT_VALIDITY = 10 * 60;
|
|
38
70
|
var GAS_ESTIMATION_ADDITION_PERCENT = 10;
|
|
39
|
-
var ADAPTER_DOMAIN_NAME = "
|
|
71
|
+
var ADAPTER_DOMAIN_NAME = "AaveV3AdapterFactory";
|
|
40
72
|
var ADAPTER_DOMAIN_VERSION = "1";
|
|
41
73
|
var ADAPTER_SIGNATURE_TYPES = {
|
|
42
74
|
AdapterOrderSig: [
|
|
@@ -232,17 +264,17 @@ var aaveAdapterFactoryAbi = [
|
|
|
232
264
|
stateMutability: "nonpayable"
|
|
233
265
|
},
|
|
234
266
|
{
|
|
235
|
-
|
|
267
|
+
type: "function",
|
|
236
268
|
name: "DOMAIN_SEPARATOR",
|
|
269
|
+
inputs: [],
|
|
237
270
|
outputs: [
|
|
238
271
|
{
|
|
239
|
-
internalType: "bytes32",
|
|
240
272
|
name: "",
|
|
241
|
-
type: "bytes32"
|
|
273
|
+
type: "bytes32",
|
|
274
|
+
internalType: "bytes32"
|
|
242
275
|
}
|
|
243
276
|
],
|
|
244
|
-
stateMutability: "view"
|
|
245
|
-
type: "function"
|
|
277
|
+
stateMutability: "view"
|
|
246
278
|
}
|
|
247
279
|
];
|
|
248
280
|
|
|
@@ -380,6 +412,18 @@ var repayWithCollateralAdapterAbi = [
|
|
|
380
412
|
|
|
381
413
|
// src/aave/AaveCollateralSwapSdk.ts
|
|
382
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
|
+
}
|
|
383
427
|
/**
|
|
384
428
|
* Executes a collateral swap using Aave flash loans.
|
|
385
429
|
*
|
|
@@ -635,7 +679,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
635
679
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
636
680
|
return await getGlobalAdapter().readContract({
|
|
637
681
|
address: AAVE_ADAPTER_FACTORY[chainId],
|
|
638
|
-
args: [
|
|
682
|
+
args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
|
|
639
683
|
functionName: "getInstanceDeterministicAddress",
|
|
640
684
|
abi: aaveAdapterFactoryAbi
|
|
641
685
|
});
|
|
@@ -663,7 +707,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
663
707
|
}
|
|
664
708
|
getPreHookCallData(flashLoanType, chainId, trader, hookAmounts, order, instanceAddress) {
|
|
665
709
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
666
|
-
const adapterImplementation =
|
|
710
|
+
const adapterImplementation = this.hookAdapterPerType[flashLoanType][chainId];
|
|
667
711
|
return getGlobalAdapter().utils.encodeFunction(aaveAdapterFactoryAbi, "deployAndTransferFlashLoan", [
|
|
668
712
|
adapterImplementation,
|
|
669
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
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Flash loans for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@cowprotocol/sdk-common": "0.3.0",
|
|
18
18
|
"@cowprotocol/sdk-app-data": "4.1.6",
|
|
19
|
-
"@cowprotocol/sdk-trading": "0.4.
|
|
20
|
-
"@cowprotocol/sdk-order-
|
|
19
|
+
"@cowprotocol/sdk-trading": "0.4.6",
|
|
20
|
+
"@cowprotocol/sdk-order-book": "0.2.0",
|
|
21
21
|
"@cowprotocol/sdk-config": "0.3.0",
|
|
22
|
-
"@cowprotocol/sdk-order-
|
|
22
|
+
"@cowprotocol/sdk-order-signing": "0.1.11"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"ethers-v5": "npm:ethers@^5.7.2",
|