@cowprotocol/sdk-flash-loans 1.5.12 → 1.6.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/README.md +58 -0
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +7 -5
- package/dist/index.mjs +7 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -352,6 +352,64 @@ const result = await flashLoanSdk.collateralSwap(
|
|
|
352
352
|
)
|
|
353
353
|
```
|
|
354
354
|
|
|
355
|
+
## Custom Hook Gas Limits
|
|
356
|
+
|
|
357
|
+
The SDK uses default gas limits for pre and post-execution hooks (300,000 and 600,000 respectively). You can customize these limits per operation if needed.
|
|
358
|
+
|
|
359
|
+
### Default Gas Limits
|
|
360
|
+
|
|
361
|
+
- **Pre-hook**: 300,000 gas (deploys adapter and sets up flash loan)
|
|
362
|
+
- **Post-hook**: 600,000 gas (executes swap and repays flash loan)
|
|
363
|
+
|
|
364
|
+
### Customizing Gas Limits
|
|
365
|
+
|
|
366
|
+
You can override gas limits in two ways:
|
|
367
|
+
|
|
368
|
+
#### 1. Per-Operation Override
|
|
369
|
+
|
|
370
|
+
Pass `hooksGasLimit` in the trade parameters:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
const result = await flashLoanSdk.collateralSwap(
|
|
374
|
+
{
|
|
375
|
+
chainId: SupportedChainId.GNOSIS_CHAIN,
|
|
376
|
+
tradeParameters: {
|
|
377
|
+
sellToken: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
|
|
378
|
+
sellTokenDecimals: 18,
|
|
379
|
+
buyToken: '0x2a22f9c3b484c3629090FeED35F17Ff8F88f76F0',
|
|
380
|
+
buyTokenDecimals: 6,
|
|
381
|
+
amount: '20000000000000000000',
|
|
382
|
+
kind: OrderKind.SELL,
|
|
383
|
+
validFor: 600,
|
|
384
|
+
slippageBps: 50,
|
|
385
|
+
},
|
|
386
|
+
settings: {
|
|
387
|
+
hooksGasLimit: {
|
|
388
|
+
preHookGasLimit: 500000n, // Custom pre-hook gas limit
|
|
389
|
+
postHookGasLimit: 800000n, // Custom post-hook gas limit
|
|
390
|
+
},
|
|
391
|
+
},
|
|
392
|
+
collateralToken: '0xd0Dd6cEF72143E22cCED4867eb0d5F2328715533',
|
|
393
|
+
},
|
|
394
|
+
tradingSdk
|
|
395
|
+
)
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
#### 2. SDK-Wide Default Override
|
|
399
|
+
|
|
400
|
+
Set custom defaults when initializing the SDK:
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
const flashLoanSdk = new AaveCollateralSwapSdk({
|
|
404
|
+
hooksGasLimit: {
|
|
405
|
+
pre: 500000n, // Custom default pre-hook gas limit
|
|
406
|
+
post: 800000n, // Custom default post-hook gas limit
|
|
407
|
+
},
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
// All operations will now use these defaults unless overridden per-operation
|
|
411
|
+
```
|
|
412
|
+
|
|
355
413
|
## How Hooks Work
|
|
356
414
|
|
|
357
415
|
The SDK uses CoW Protocol hooks to orchestrate the flash loan:
|
package/dist/index.d.mts
CHANGED
|
@@ -33,6 +33,10 @@ interface CollateralOrderData {
|
|
|
33
33
|
hookBuyTokenAmount: string;
|
|
34
34
|
}
|
|
35
35
|
type EncodedOrder = Record<string, string | number>;
|
|
36
|
+
interface CollateralSwapHooksGasLimit {
|
|
37
|
+
preHookGasLimit?: bigint;
|
|
38
|
+
postHookGasLimit?: bigint;
|
|
39
|
+
}
|
|
36
40
|
/**
|
|
37
41
|
* Parameters for executing a collateral swap using Aave flash loans.
|
|
38
42
|
*/
|
|
@@ -51,6 +55,7 @@ interface CollateralSwapParams {
|
|
|
51
55
|
preventApproval?: boolean;
|
|
52
56
|
/** EIP-2612 permit data for gasless approval. If provided, uses permit instead of approve. */
|
|
53
57
|
collateralPermit?: CollateralPermitData;
|
|
58
|
+
hooksGasLimit?: CollateralSwapHooksGasLimit;
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
61
|
interface CollateralSwapTradeParams {
|
|
@@ -58,6 +63,7 @@ interface CollateralSwapTradeParams {
|
|
|
58
63
|
validTo: number;
|
|
59
64
|
owner: AccountAddress;
|
|
60
65
|
flashLoanFeeAmount: bigint;
|
|
66
|
+
hooksGasLimit?: CollateralSwapHooksGasLimit;
|
|
61
67
|
}
|
|
62
68
|
interface CollateralSwapOrder {
|
|
63
69
|
sellAmount: bigint;
|
|
@@ -310,8 +316,8 @@ declare class AaveCollateralSwapSdk {
|
|
|
310
316
|
getCollateralSwapPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
311
317
|
getDebtSwapPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
312
318
|
getRepayPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
313
|
-
getOrderHooks(flashLoanType: AaveFlashLoanType, chainId: SupportedChainId, trader: AccountAddress, expectedInstanceAddress: AccountAddress, hookAmounts: FlashLoanHookAmounts, order: EncodedOrder, collateralPermit?: CollateralPermitData): Promise<LatestAppDataDocVersion['metadata']['hooks']>;
|
|
319
|
+
getOrderHooks(flashLoanType: AaveFlashLoanType, chainId: SupportedChainId, trader: AccountAddress, expectedInstanceAddress: AccountAddress, hookAmounts: FlashLoanHookAmounts, order: EncodedOrder, collateralPermit?: CollateralPermitData, hooksGasLimit?: CollateralSwapHooksGasLimit): Promise<LatestAppDataDocVersion['metadata']['hooks']>;
|
|
314
320
|
private adapterEIP1271Signature;
|
|
315
321
|
}
|
|
316
322
|
|
|
317
|
-
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 };
|
|
323
|
+
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 CollateralSwapHooksGasLimit, 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
|
@@ -33,6 +33,10 @@ interface CollateralOrderData {
|
|
|
33
33
|
hookBuyTokenAmount: string;
|
|
34
34
|
}
|
|
35
35
|
type EncodedOrder = Record<string, string | number>;
|
|
36
|
+
interface CollateralSwapHooksGasLimit {
|
|
37
|
+
preHookGasLimit?: bigint;
|
|
38
|
+
postHookGasLimit?: bigint;
|
|
39
|
+
}
|
|
36
40
|
/**
|
|
37
41
|
* Parameters for executing a collateral swap using Aave flash loans.
|
|
38
42
|
*/
|
|
@@ -51,6 +55,7 @@ interface CollateralSwapParams {
|
|
|
51
55
|
preventApproval?: boolean;
|
|
52
56
|
/** EIP-2612 permit data for gasless approval. If provided, uses permit instead of approve. */
|
|
53
57
|
collateralPermit?: CollateralPermitData;
|
|
58
|
+
hooksGasLimit?: CollateralSwapHooksGasLimit;
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
61
|
interface CollateralSwapTradeParams {
|
|
@@ -58,6 +63,7 @@ interface CollateralSwapTradeParams {
|
|
|
58
63
|
validTo: number;
|
|
59
64
|
owner: AccountAddress;
|
|
60
65
|
flashLoanFeeAmount: bigint;
|
|
66
|
+
hooksGasLimit?: CollateralSwapHooksGasLimit;
|
|
61
67
|
}
|
|
62
68
|
interface CollateralSwapOrder {
|
|
63
69
|
sellAmount: bigint;
|
|
@@ -310,8 +316,8 @@ declare class AaveCollateralSwapSdk {
|
|
|
310
316
|
getCollateralSwapPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
311
317
|
getDebtSwapPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
312
318
|
getRepayPostHookCallData(collateralPermit?: CollateralPermitData): string;
|
|
313
|
-
getOrderHooks(flashLoanType: AaveFlashLoanType, chainId: SupportedChainId, trader: AccountAddress, expectedInstanceAddress: AccountAddress, hookAmounts: FlashLoanHookAmounts, order: EncodedOrder, collateralPermit?: CollateralPermitData): Promise<LatestAppDataDocVersion['metadata']['hooks']>;
|
|
319
|
+
getOrderHooks(flashLoanType: AaveFlashLoanType, chainId: SupportedChainId, trader: AccountAddress, expectedInstanceAddress: AccountAddress, hookAmounts: FlashLoanHookAmounts, order: EncodedOrder, collateralPermit?: CollateralPermitData, hooksGasLimit?: CollateralSwapHooksGasLimit): Promise<LatestAppDataDocVersion['metadata']['hooks']>;
|
|
314
320
|
private adapterEIP1271Signature;
|
|
315
321
|
}
|
|
316
322
|
|
|
317
|
-
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 };
|
|
323
|
+
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 CollateralSwapHooksGasLimit, 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
|
@@ -547,7 +547,8 @@ var AaveCollateralSwapSdk = class {
|
|
|
547
547
|
chainId,
|
|
548
548
|
owner: trader,
|
|
549
549
|
amount: sellAmountToSign.toString(),
|
|
550
|
-
validTo
|
|
550
|
+
validTo,
|
|
551
|
+
hooksGasLimit: params.settings?.hooksGasLimit
|
|
551
552
|
};
|
|
552
553
|
}
|
|
553
554
|
/**
|
|
@@ -617,7 +618,8 @@ var AaveCollateralSwapSdk = class {
|
|
|
617
618
|
...encodedOrder,
|
|
618
619
|
receiver: instanceAddress
|
|
619
620
|
},
|
|
620
|
-
collateralPermit
|
|
621
|
+
collateralPermit,
|
|
622
|
+
params.hooksGasLimit
|
|
621
623
|
);
|
|
622
624
|
const swapSettings = {
|
|
623
625
|
quoteRequest: {
|
|
@@ -790,7 +792,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
790
792
|
collateralPermit
|
|
791
793
|
]);
|
|
792
794
|
}
|
|
793
|
-
async getOrderHooks(flashLoanType, chainId, trader, expectedInstanceAddress, hookAmounts, order, collateralPermit) {
|
|
795
|
+
async getOrderHooks(flashLoanType, chainId, trader, expectedInstanceAddress, hookAmounts, order, collateralPermit, hooksGasLimit) {
|
|
794
796
|
const preHookCallData = this.getPreHookCallData(
|
|
795
797
|
flashLoanType,
|
|
796
798
|
chainId,
|
|
@@ -806,7 +808,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
806
808
|
{
|
|
807
809
|
target: this.aaveAdapterFactory[chainId],
|
|
808
810
|
callData: preHookCallData,
|
|
809
|
-
gasLimit: this.hooksGasLimit.pre.toString(),
|
|
811
|
+
gasLimit: (hooksGasLimit?.preHookGasLimit ?? this.hooksGasLimit.pre).toString(),
|
|
810
812
|
dappId
|
|
811
813
|
}
|
|
812
814
|
],
|
|
@@ -814,7 +816,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
814
816
|
{
|
|
815
817
|
target: expectedInstanceAddress,
|
|
816
818
|
callData: postHookCallData,
|
|
817
|
-
gasLimit: this.hooksGasLimit.post.toString(),
|
|
819
|
+
gasLimit: (hooksGasLimit?.postHookGasLimit ?? this.hooksGasLimit.post).toString(),
|
|
818
820
|
dappId
|
|
819
821
|
}
|
|
820
822
|
]
|
package/dist/index.mjs
CHANGED
|
@@ -510,7 +510,8 @@ var AaveCollateralSwapSdk = class {
|
|
|
510
510
|
chainId,
|
|
511
511
|
owner: trader,
|
|
512
512
|
amount: sellAmountToSign.toString(),
|
|
513
|
-
validTo
|
|
513
|
+
validTo,
|
|
514
|
+
hooksGasLimit: params.settings?.hooksGasLimit
|
|
514
515
|
};
|
|
515
516
|
}
|
|
516
517
|
/**
|
|
@@ -580,7 +581,8 @@ var AaveCollateralSwapSdk = class {
|
|
|
580
581
|
...encodedOrder,
|
|
581
582
|
receiver: instanceAddress
|
|
582
583
|
},
|
|
583
|
-
collateralPermit
|
|
584
|
+
collateralPermit,
|
|
585
|
+
params.hooksGasLimit
|
|
584
586
|
);
|
|
585
587
|
const swapSettings = {
|
|
586
588
|
quoteRequest: {
|
|
@@ -753,7 +755,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
753
755
|
collateralPermit
|
|
754
756
|
]);
|
|
755
757
|
}
|
|
756
|
-
async getOrderHooks(flashLoanType, chainId, trader, expectedInstanceAddress, hookAmounts, order, collateralPermit) {
|
|
758
|
+
async getOrderHooks(flashLoanType, chainId, trader, expectedInstanceAddress, hookAmounts, order, collateralPermit, hooksGasLimit) {
|
|
757
759
|
const preHookCallData = this.getPreHookCallData(
|
|
758
760
|
flashLoanType,
|
|
759
761
|
chainId,
|
|
@@ -769,7 +771,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
769
771
|
{
|
|
770
772
|
target: this.aaveAdapterFactory[chainId],
|
|
771
773
|
callData: preHookCallData,
|
|
772
|
-
gasLimit: this.hooksGasLimit.pre.toString(),
|
|
774
|
+
gasLimit: (hooksGasLimit?.preHookGasLimit ?? this.hooksGasLimit.pre).toString(),
|
|
773
775
|
dappId
|
|
774
776
|
}
|
|
775
777
|
],
|
|
@@ -777,7 +779,7 @@ var AaveCollateralSwapSdk = class {
|
|
|
777
779
|
{
|
|
778
780
|
target: expectedInstanceAddress,
|
|
779
781
|
callData: postHookCallData,
|
|
780
|
-
gasLimit: this.hooksGasLimit.post.toString(),
|
|
782
|
+
gasLimit: (hooksGasLimit?.postHookGasLimit ?? this.hooksGasLimit.post).toString(),
|
|
781
783
|
dappId
|
|
782
784
|
}
|
|
783
785
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cowprotocol/sdk-flash-loans",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "Flash loans for CoW Protocol",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@cowprotocol/sdk-common": "0.4.0",
|
|
18
18
|
"@cowprotocol/sdk-app-data": "4.3.5",
|
|
19
|
-
"@cowprotocol/sdk-trading": "0.
|
|
19
|
+
"@cowprotocol/sdk-trading": "0.7.0",
|
|
20
|
+
"@cowprotocol/sdk-order-signing": "0.1.20",
|
|
20
21
|
"@cowprotocol/sdk-order-book": "0.4.3",
|
|
21
|
-
"@cowprotocol/sdk-order-signing": "0.1.19",
|
|
22
22
|
"@cowprotocol/sdk-config": "0.6.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"ethers": "^5.7.2",
|
|
36
36
|
"viem": "2.30.5",
|
|
37
37
|
"@cow-sdk/typescript-config": "0.0.0-beta.0",
|
|
38
|
-
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.0",
|
|
39
38
|
"@cowprotocol/sdk-ethers-v5-adapter": "0.3.0",
|
|
39
|
+
"@cowprotocol/sdk-ethers-v6-adapter": "0.3.0",
|
|
40
40
|
"@cowprotocol/sdk-viem-adapter": "0.3.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|