@cowprotocol/sdk-flash-loans 1.5.0 → 1.5.3
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 +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +20 -8
- package/dist/index.mjs +20 -8
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -119,6 +119,12 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
|
|
|
119
119
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} hookAdapterPerType -
|
|
120
120
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
121
121
|
* Defaults to the predefined addresses from the constants.
|
|
122
|
+
* @param {Record<SupportedChainId, string>} aaveAdapterFactory -
|
|
123
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
124
|
+
* Defaults to the predefined addresses from the constants.
|
|
125
|
+
* @param {Record<SupportedChainId, string>} aavePoolAddress -
|
|
126
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
127
|
+
* Defaults to the predefined addresses from the constants.
|
|
122
128
|
* @example
|
|
123
129
|
* ```typescript
|
|
124
130
|
* const config: AaveCollateralSwapSdkConfig = {
|
|
@@ -127,11 +133,23 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
|
|
|
127
133
|
* [SupportedChainId.GNOSIS_CHAIN]: '0x...',
|
|
128
134
|
* },
|
|
129
135
|
* },
|
|
136
|
+
* aaveAdapterFactory: {
|
|
137
|
+
* [SupportedChainId.MAINNET]: '0x...',
|
|
138
|
+
* },
|
|
139
|
+
* aavePoolAddress: {
|
|
140
|
+
* [SupportedChainId.MAINNET]: '0x...',
|
|
141
|
+
* },
|
|
130
142
|
* }
|
|
131
143
|
* ```
|
|
132
144
|
*/
|
|
133
145
|
type AaveCollateralSwapSdkConfig = {
|
|
134
146
|
hookAdapterPerType?: Record<AaveFlashLoanType, Record<SupportedChainId, string>>;
|
|
147
|
+
aaveAdapterFactory?: Record<SupportedChainId, string>;
|
|
148
|
+
aavePoolAddress?: Record<SupportedChainId, string>;
|
|
149
|
+
hooksGasLimit?: {
|
|
150
|
+
pre: bigint;
|
|
151
|
+
post: bigint;
|
|
152
|
+
};
|
|
135
153
|
};
|
|
136
154
|
/**
|
|
137
155
|
* SDK for executing Aave flash loan operations, particularly collateral swaps.
|
|
@@ -145,6 +163,9 @@ type AaveCollateralSwapSdkConfig = {
|
|
|
145
163
|
*/
|
|
146
164
|
declare class AaveCollateralSwapSdk {
|
|
147
165
|
private readonly hookAdapterPerType;
|
|
166
|
+
private readonly aaveAdapterFactory;
|
|
167
|
+
private readonly aavePoolAddress;
|
|
168
|
+
private readonly hooksGasLimit;
|
|
148
169
|
/**
|
|
149
170
|
* Creates an instance of AaveCollateralSwapSdk.
|
|
150
171
|
*
|
|
@@ -152,6 +173,12 @@ declare class AaveCollateralSwapSdk {
|
|
|
152
173
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
|
|
153
174
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
154
175
|
* Defaults to the predefined addresses from the constants.
|
|
176
|
+
* @param {Record<SupportedChainId, string>} config.aaveAdapterFactory -
|
|
177
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
178
|
+
* Defaults to the predefined addresses from the constants.
|
|
179
|
+
* @param {Record<SupportedChainId, string>} config.aavePoolAddress -
|
|
180
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
181
|
+
* Defaults to the predefined addresses from the constants.
|
|
155
182
|
*/
|
|
156
183
|
constructor(config?: AaveCollateralSwapSdkConfig);
|
|
157
184
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,12 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
|
|
|
119
119
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} hookAdapterPerType -
|
|
120
120
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
121
121
|
* Defaults to the predefined addresses from the constants.
|
|
122
|
+
* @param {Record<SupportedChainId, string>} aaveAdapterFactory -
|
|
123
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
124
|
+
* Defaults to the predefined addresses from the constants.
|
|
125
|
+
* @param {Record<SupportedChainId, string>} aavePoolAddress -
|
|
126
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
127
|
+
* Defaults to the predefined addresses from the constants.
|
|
122
128
|
* @example
|
|
123
129
|
* ```typescript
|
|
124
130
|
* const config: AaveCollateralSwapSdkConfig = {
|
|
@@ -127,11 +133,23 @@ declare const AAVE_DAPP_ID_PER_TYPE: Record<AaveFlashLoanType, string>;
|
|
|
127
133
|
* [SupportedChainId.GNOSIS_CHAIN]: '0x...',
|
|
128
134
|
* },
|
|
129
135
|
* },
|
|
136
|
+
* aaveAdapterFactory: {
|
|
137
|
+
* [SupportedChainId.MAINNET]: '0x...',
|
|
138
|
+
* },
|
|
139
|
+
* aavePoolAddress: {
|
|
140
|
+
* [SupportedChainId.MAINNET]: '0x...',
|
|
141
|
+
* },
|
|
130
142
|
* }
|
|
131
143
|
* ```
|
|
132
144
|
*/
|
|
133
145
|
type AaveCollateralSwapSdkConfig = {
|
|
134
146
|
hookAdapterPerType?: Record<AaveFlashLoanType, Record<SupportedChainId, string>>;
|
|
147
|
+
aaveAdapterFactory?: Record<SupportedChainId, string>;
|
|
148
|
+
aavePoolAddress?: Record<SupportedChainId, string>;
|
|
149
|
+
hooksGasLimit?: {
|
|
150
|
+
pre: bigint;
|
|
151
|
+
post: bigint;
|
|
152
|
+
};
|
|
135
153
|
};
|
|
136
154
|
/**
|
|
137
155
|
* SDK for executing Aave flash loan operations, particularly collateral swaps.
|
|
@@ -145,6 +163,9 @@ type AaveCollateralSwapSdkConfig = {
|
|
|
145
163
|
*/
|
|
146
164
|
declare class AaveCollateralSwapSdk {
|
|
147
165
|
private readonly hookAdapterPerType;
|
|
166
|
+
private readonly aaveAdapterFactory;
|
|
167
|
+
private readonly aavePoolAddress;
|
|
168
|
+
private readonly hooksGasLimit;
|
|
148
169
|
/**
|
|
149
170
|
* Creates an instance of AaveCollateralSwapSdk.
|
|
150
171
|
*
|
|
@@ -152,6 +173,12 @@ declare class AaveCollateralSwapSdk {
|
|
|
152
173
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
|
|
153
174
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
154
175
|
* Defaults to the predefined addresses from the constants.
|
|
176
|
+
* @param {Record<SupportedChainId, string>} config.aaveAdapterFactory -
|
|
177
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
178
|
+
* Defaults to the predefined addresses from the constants.
|
|
179
|
+
* @param {Record<SupportedChainId, string>} config.aavePoolAddress -
|
|
180
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
181
|
+
* Defaults to the predefined addresses from the constants.
|
|
155
182
|
*/
|
|
156
183
|
constructor(config?: AaveCollateralSwapSdkConfig);
|
|
157
184
|
/**
|
package/dist/index.js
CHANGED
|
@@ -438,6 +438,9 @@ var repayWithCollateralAdapterAbi = [
|
|
|
438
438
|
// src/aave/AaveCollateralSwapSdk.ts
|
|
439
439
|
var AaveCollateralSwapSdk = class {
|
|
440
440
|
hookAdapterPerType;
|
|
441
|
+
aaveAdapterFactory;
|
|
442
|
+
aavePoolAddress;
|
|
443
|
+
hooksGasLimit;
|
|
441
444
|
/**
|
|
442
445
|
* Creates an instance of AaveCollateralSwapSdk.
|
|
443
446
|
*
|
|
@@ -445,9 +448,18 @@ var AaveCollateralSwapSdk = class {
|
|
|
445
448
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
|
|
446
449
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
447
450
|
* Defaults to the predefined addresses from the constants.
|
|
451
|
+
* @param {Record<SupportedChainId, string>} config.aaveAdapterFactory -
|
|
452
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
453
|
+
* Defaults to the predefined addresses from the constants.
|
|
454
|
+
* @param {Record<SupportedChainId, string>} config.aavePoolAddress -
|
|
455
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
456
|
+
* Defaults to the predefined addresses from the constants.
|
|
448
457
|
*/
|
|
449
458
|
constructor(config) {
|
|
450
459
|
this.hookAdapterPerType = config?.hookAdapterPerType ?? AAVE_HOOK_ADAPTER_PER_TYPE;
|
|
460
|
+
this.aaveAdapterFactory = config?.aaveAdapterFactory ?? AAVE_ADAPTER_FACTORY;
|
|
461
|
+
this.aavePoolAddress = config?.aavePoolAddress ?? AAVE_POOL_ADDRESS;
|
|
462
|
+
this.hooksGasLimit = config?.hooksGasLimit ?? DEFAULT_HOOK_GAS_LIMIT;
|
|
451
463
|
}
|
|
452
464
|
/**
|
|
453
465
|
* Executes a collateral swap using Aave flash loans.
|
|
@@ -590,9 +602,9 @@ var AaveCollateralSwapSdk = class {
|
|
|
590
602
|
const flashLoanHint = {
|
|
591
603
|
amount,
|
|
592
604
|
// this is actually in UNDERLYING but aave tokens are 1:1
|
|
593
|
-
receiver:
|
|
594
|
-
liquidityProvider:
|
|
595
|
-
protocolAdapter:
|
|
605
|
+
receiver: this.aaveAdapterFactory[chainId],
|
|
606
|
+
liquidityProvider: this.aavePoolAddress[chainId],
|
|
607
|
+
protocolAdapter: this.aaveAdapterFactory[chainId],
|
|
596
608
|
token: orderToSign.sellToken
|
|
597
609
|
};
|
|
598
610
|
const hooks = await this.getOrderHooks(
|
|
@@ -703,7 +715,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
703
715
|
async getExpectedInstanceAddress(flashLoanType, chainId, trader, hookAmounts, order) {
|
|
704
716
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
705
717
|
return await (0, import_sdk_common.getGlobalAdapter)().readContract({
|
|
706
|
-
address:
|
|
718
|
+
address: this.aaveAdapterFactory[chainId],
|
|
707
719
|
args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
|
|
708
720
|
functionName: "getInstanceDeterministicAddress",
|
|
709
721
|
abi: aaveAdapterFactoryAbi
|
|
@@ -792,9 +804,9 @@ var AaveCollateralSwapSdk = class {
|
|
|
792
804
|
return {
|
|
793
805
|
pre: [
|
|
794
806
|
{
|
|
795
|
-
target:
|
|
807
|
+
target: this.aaveAdapterFactory[chainId],
|
|
796
808
|
callData: preHookCallData,
|
|
797
|
-
gasLimit:
|
|
809
|
+
gasLimit: this.hooksGasLimit.pre.toString(),
|
|
798
810
|
dappId
|
|
799
811
|
}
|
|
800
812
|
],
|
|
@@ -802,14 +814,14 @@ var AaveCollateralSwapSdk = class {
|
|
|
802
814
|
{
|
|
803
815
|
target: expectedInstanceAddress,
|
|
804
816
|
callData: postHookCallData,
|
|
805
|
-
gasLimit:
|
|
817
|
+
gasLimit: this.hooksGasLimit.post.toString(),
|
|
806
818
|
dappId
|
|
807
819
|
}
|
|
808
820
|
]
|
|
809
821
|
};
|
|
810
822
|
}
|
|
811
823
|
async adapterEIP1271Signature(chainId, instanceAddress, orderToSign, signer) {
|
|
812
|
-
const adapterFactoryAddress =
|
|
824
|
+
const adapterFactoryAddress = this.aaveAdapterFactory[chainId];
|
|
813
825
|
const encodedOrder = import_sdk_order_signing.OrderSigningUtils.encodeUnsignedOrder(orderToSign);
|
|
814
826
|
const domain = {
|
|
815
827
|
name: ADAPTER_DOMAIN_NAME,
|
package/dist/index.mjs
CHANGED
|
@@ -401,6 +401,9 @@ var repayWithCollateralAdapterAbi = [
|
|
|
401
401
|
// src/aave/AaveCollateralSwapSdk.ts
|
|
402
402
|
var AaveCollateralSwapSdk = class {
|
|
403
403
|
hookAdapterPerType;
|
|
404
|
+
aaveAdapterFactory;
|
|
405
|
+
aavePoolAddress;
|
|
406
|
+
hooksGasLimit;
|
|
404
407
|
/**
|
|
405
408
|
* Creates an instance of AaveCollateralSwapSdk.
|
|
406
409
|
*
|
|
@@ -408,9 +411,18 @@ var AaveCollateralSwapSdk = class {
|
|
|
408
411
|
* @param {Record<AaveFlashLoanType, Record<SupportedChainId, string>>} config.hookAdapterPerType -
|
|
409
412
|
* Mapping of flash loan types to chain-specific hook adapter addresses.
|
|
410
413
|
* Defaults to the predefined addresses from the constants.
|
|
414
|
+
* @param {Record<SupportedChainId, string>} config.aaveAdapterFactory -
|
|
415
|
+
* Mapping of chain IDs to Aave adapter factory addresses.
|
|
416
|
+
* Defaults to the predefined addresses from the constants.
|
|
417
|
+
* @param {Record<SupportedChainId, string>} config.aavePoolAddress -
|
|
418
|
+
* Mapping of chain IDs to Aave pool addresses.
|
|
419
|
+
* Defaults to the predefined addresses from the constants.
|
|
411
420
|
*/
|
|
412
421
|
constructor(config) {
|
|
413
422
|
this.hookAdapterPerType = config?.hookAdapterPerType ?? AAVE_HOOK_ADAPTER_PER_TYPE;
|
|
423
|
+
this.aaveAdapterFactory = config?.aaveAdapterFactory ?? AAVE_ADAPTER_FACTORY;
|
|
424
|
+
this.aavePoolAddress = config?.aavePoolAddress ?? AAVE_POOL_ADDRESS;
|
|
425
|
+
this.hooksGasLimit = config?.hooksGasLimit ?? DEFAULT_HOOK_GAS_LIMIT;
|
|
414
426
|
}
|
|
415
427
|
/**
|
|
416
428
|
* Executes a collateral swap using Aave flash loans.
|
|
@@ -553,9 +565,9 @@ var AaveCollateralSwapSdk = class {
|
|
|
553
565
|
const flashLoanHint = {
|
|
554
566
|
amount,
|
|
555
567
|
// this is actually in UNDERLYING but aave tokens are 1:1
|
|
556
|
-
receiver:
|
|
557
|
-
liquidityProvider:
|
|
558
|
-
protocolAdapter:
|
|
568
|
+
receiver: this.aaveAdapterFactory[chainId],
|
|
569
|
+
liquidityProvider: this.aavePoolAddress[chainId],
|
|
570
|
+
protocolAdapter: this.aaveAdapterFactory[chainId],
|
|
559
571
|
token: orderToSign.sellToken
|
|
560
572
|
};
|
|
561
573
|
const hooks = await this.getOrderHooks(
|
|
@@ -666,7 +678,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
666
678
|
async getExpectedInstanceAddress(flashLoanType, chainId, trader, hookAmounts, order) {
|
|
667
679
|
const hookData = this.buildHookOrderData(trader, hookAmounts, order);
|
|
668
680
|
return await getGlobalAdapter().readContract({
|
|
669
|
-
address:
|
|
681
|
+
address: this.aaveAdapterFactory[chainId],
|
|
670
682
|
args: [this.hookAdapterPerType[flashLoanType][chainId], hookData],
|
|
671
683
|
functionName: "getInstanceDeterministicAddress",
|
|
672
684
|
abi: aaveAdapterFactoryAbi
|
|
@@ -755,9 +767,9 @@ var AaveCollateralSwapSdk = class {
|
|
|
755
767
|
return {
|
|
756
768
|
pre: [
|
|
757
769
|
{
|
|
758
|
-
target:
|
|
770
|
+
target: this.aaveAdapterFactory[chainId],
|
|
759
771
|
callData: preHookCallData,
|
|
760
|
-
gasLimit:
|
|
772
|
+
gasLimit: this.hooksGasLimit.pre.toString(),
|
|
761
773
|
dappId
|
|
762
774
|
}
|
|
763
775
|
],
|
|
@@ -765,14 +777,14 @@ var AaveCollateralSwapSdk = class {
|
|
|
765
777
|
{
|
|
766
778
|
target: expectedInstanceAddress,
|
|
767
779
|
callData: postHookCallData,
|
|
768
|
-
gasLimit:
|
|
780
|
+
gasLimit: this.hooksGasLimit.post.toString(),
|
|
769
781
|
dappId
|
|
770
782
|
}
|
|
771
783
|
]
|
|
772
784
|
};
|
|
773
785
|
}
|
|
774
786
|
async adapterEIP1271Signature(chainId, instanceAddress, orderToSign, signer) {
|
|
775
|
-
const adapterFactoryAddress =
|
|
787
|
+
const adapterFactoryAddress = this.aaveAdapterFactory[chainId];
|
|
776
788
|
const encodedOrder = OrderSigningUtils.encodeUnsignedOrder(orderToSign);
|
|
777
789
|
const domain = {
|
|
778
790
|
name: ADAPTER_DOMAIN_NAME,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-flash-loans",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Flash loans for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@cowprotocol/sdk-app-data": "4.1.6",
|
|
18
|
+
"@cowprotocol/sdk-trading": "0.4.6",
|
|
18
19
|
"@cowprotocol/sdk-common": "0.3.0",
|
|
19
20
|
"@cowprotocol/sdk-order-book": "0.2.0",
|
|
20
|
-
"@cowprotocol/sdk-
|
|
21
|
-
"@cowprotocol/sdk-
|
|
22
|
-
"@cowprotocol/sdk-order-signing": "0.1.11"
|
|
21
|
+
"@cowprotocol/sdk-order-signing": "0.1.11",
|
|
22
|
+
"@cowprotocol/sdk-config": "0.3.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"ethers-v5": "npm:ethers@^5.7.2",
|