@1delta/trade-sdk 0.1.6 → 0.1.8
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 +7 -4
- package/dist/aggregator/fetchAggregatorTrade.d.ts +0 -1
- package/dist/aggregator/fetchAggregatorTrade.d.ts.map +1 -1
- package/dist/aggregator/fetchAggregatorTrade.js +88 -4
- package/dist/composedTrades/across/acrossWithSwap.d.ts +1 -1
- package/dist/composedTrades/across/acrossWithSwap.d.ts.map +1 -1
- package/dist/composedTrades/across/acrossWithSwap.js +3 -2
- package/dist/composedTrades/across/acrossWithSwaps.d.ts +2 -2
- package/dist/composedTrades/across/acrossWithSwaps.d.ts.map +1 -1
- package/dist/composedTrades/across/acrossWithSwaps.js +6 -3
- package/dist/composedTrades/across/calldata/createAcrossMessage.d.ts +1 -1
- package/dist/composedTrades/across/calldata/createAcrossMessage.d.ts.map +1 -1
- package/dist/composedTrades/axelar/axelarWithSwap.d.ts +3 -3
- package/dist/composedTrades/axelar/axelarWithSwap.d.ts.map +1 -1
- package/dist/composedTrades/axelar/axelarWithSwap.js +12 -11
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts +2 -2
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts.map +1 -1
- package/dist/composedTrades/axelar/axelarWithSwaps.js +7 -4
- package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts +1 -1
- package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts.map +1 -1
- package/dist/composedTrades/gaszip/gaszipWithSwaps.d.ts.map +1 -1
- package/dist/composedTrades/gaszip/gaszipWithSwaps.js +1 -0
- package/dist/composedTrades/utils/createSwapAndBridgeCalldata.d.ts +2 -2
- package/dist/composedTrades/utils/createSwapAndBridgeCalldata.d.ts.map +1 -1
- package/dist/composedTrades/utils/createSwapAndBridgeCalldata.js +34 -6
- package/dist/composedTrades/utils/fetchBridgeAndGasTrade.d.ts +2 -2
- package/dist/composedTrades/utils/fetchBridgeAndGasTrade.d.ts.map +1 -1
- package/dist/composedTrades/utils/fetchBridgeAndGasTrade.js +10 -10
- package/dist/composedTrades/utils/index.d.ts +2 -0
- package/dist/composedTrades/utils/index.d.ts.map +1 -1
- package/dist/composedTrades/utils/index.js +2 -0
- package/dist/composedTrades/utils/multichainUtils.d.ts +2 -2
- package/dist/composedTrades/utils/multichainUtils.d.ts.map +1 -1
- package/dist/composedTrades/utils/multichainUtils.js +4 -17
- package/dist/core.d.ts +6 -2
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +29 -3
- package/dist/deltaCall/createDeltaCallsCalldata.d.ts +5 -1
- package/dist/deltaCall/createDeltaCallsCalldata.d.ts.map +1 -1
- package/dist/deltaCall/createDeltaCallsCalldata.js +46 -14
- package/dist/deltaCall/toComposerCall.d.ts +1 -1
- package/dist/deltaCall/toComposerCall.d.ts.map +1 -1
- package/dist/deltaCall/toComposerCall.js +75 -5
- package/dist/deltaCall/toForwarderCall.d.ts +2 -2
- package/dist/deltaCall/toForwarderCall.d.ts.map +1 -1
- package/dist/deltaCall/toForwarderCall.js +8 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/initialize.d.ts +14 -9
- package/dist/initialize.d.ts.map +1 -1
- package/dist/initialize.js +22 -18
- package/dist/registry/config.d.ts +7 -0
- package/dist/registry/config.d.ts.map +1 -0
- package/dist/registry/config.js +19 -0
- package/dist/registry/currency.d.ts +4 -0
- package/dist/registry/currency.d.ts.map +1 -0
- package/dist/registry/currency.js +19 -0
- package/dist/registry/index.d.ts +3 -6
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +3 -19
- package/dist/registry/price.d.ts +4 -0
- package/dist/registry/price.d.ts.map +1 -0
- package/dist/registry/price.js +23 -0
- package/dist/types/bridgeInput.d.ts +19 -11
- package/dist/types/bridgeInput.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +0 -1
- package/dist/utils/utils.d.ts +2 -27
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +13 -27
- package/package.json +10 -9
- package/dist/types/deltaCall.d.ts +0 -62
- package/dist/types/deltaCall.d.ts.map +0 -1
- package/dist/types/deltaCall.js +0 -16
package/README.md
CHANGED
|
@@ -18,15 +18,18 @@ pnpm add @1delta/trade-sdk
|
|
|
18
18
|
## Basic Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import { initialize, fetchBridgeTrade, fetchAggregatorTrade, Bridge } from '@1delta/trade-sdk';
|
|
21
|
+
import { initialize, fetchBridgeTrade, fetchAggregatorTrade, Bridge, PriceGetter, CurrencyGetter } from '@1delta/trade-sdk';
|
|
22
22
|
import { WalletClient } from 'viem';
|
|
23
23
|
|
|
24
24
|
// Initialize the SDK
|
|
25
|
+
const getPrice: PriceGetter = ...;
|
|
26
|
+
|
|
27
|
+
const getCurrency: CurrencyGetter = ...;
|
|
28
|
+
|
|
25
29
|
await initialize({
|
|
26
30
|
isProductionEnv: true,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
load1deltaConfigs: true
|
|
31
|
+
priceGetter: getPrice,
|
|
32
|
+
currencyGetter: getCurrency,
|
|
30
33
|
});
|
|
31
34
|
|
|
32
35
|
// Set up wallet client
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export * from './fetchAggregatorTrade';
|
|
2
1
|
import { AggregatorApiInput, GenericTrade, OneDeltaInput } from '@1delta/lib-utils';
|
|
3
2
|
export declare const fetchAggregatorTrade: (aggregator: string, input: AggregatorApiInput | OneDeltaInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
3
|
//# sourceMappingURL=fetchAggregatorTrade.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAggregatorTrade.d.ts","sourceRoot":"","sources":["../../src/aggregator/fetchAggregatorTrade.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fetchAggregatorTrade.d.ts","sourceRoot":"","sources":["../../src/aggregator/fetchAggregatorTrade.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,kBAAkB,EAIlB,YAAY,EACZ,aAAa,EAEd,MAAM,mBAAmB,CAAA;AAe1B,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,OAAO,kBAAkB,GAAG,aAAa,EACzC,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAelC,CAAA"}
|
|
@@ -1,12 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
import { fetchAggregatorTrade as fetchAggregatorTradeWithoutConfigs, } from '@1delta/aggregators';
|
|
1
|
+
import { fetchAggregatorTrade as fetchAggregatorTradeWithoutConfigs, TradeAggregator, } from '@1delta/aggregators';
|
|
3
2
|
import { getSwapAggregators } from '@1delta/bridge-configs';
|
|
4
|
-
import {
|
|
3
|
+
import { ChainType, ChainUtils, TradeType, } from '@1delta/lib-utils';
|
|
4
|
+
import { fetchBridgeTrade } from '../bridge/fetchBridgeTrade';
|
|
5
|
+
import { createSwapAndBridgeCalldata, requireDeltaContracts, } from '../composedTrades/utils';
|
|
6
|
+
import { getPriceGetter } from '../registry';
|
|
7
|
+
import { reverseQuote } from '../utils';
|
|
8
|
+
const SUPPORT_EXACT_OUT = [
|
|
9
|
+
TradeAggregator.NativeWrapper,
|
|
10
|
+
TradeAggregator.ERC20Wrapper,
|
|
11
|
+
];
|
|
5
12
|
export const fetchAggregatorTrade = async (aggregator, input, controller) => {
|
|
13
|
+
const needsAdditionalCalls = (!!input.postCalls && input.postCalls.length > 0) ||
|
|
14
|
+
(!!input.preCalls && input.preCalls.length > 0);
|
|
15
|
+
if (input.disableComposer) {
|
|
16
|
+
if (needsAdditionalCalls)
|
|
17
|
+
throw new Error(`Aggregator ${aggregator.toString()} does not support additional calls without composer`);
|
|
18
|
+
return fetchSwapTrade(aggregator, input, controller);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return fetchAggregatorWithComposerTrade(aggregator, input, controller);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const fetchAggregatorWithComposerTrade = async (aggregator, input, controller) => {
|
|
25
|
+
let trade = undefined;
|
|
26
|
+
const { forwarder, composer } = requireDeltaContracts(input.chainId);
|
|
27
|
+
trade = await fetchSwapTrade(aggregator, { ...input, caller: forwarder, receiver: forwarder }, controller);
|
|
28
|
+
if (!trade)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (!trade.assemble)
|
|
31
|
+
throw new Error(`Aggregator ${aggregator.toString()} does not support composer`);
|
|
32
|
+
const assemble = async () => {
|
|
33
|
+
try {
|
|
34
|
+
const chainId = trade.inputAmount.currency.chainId;
|
|
35
|
+
if (ChainUtils.isEvm(chainId)) {
|
|
36
|
+
const fundsToPull = [
|
|
37
|
+
{
|
|
38
|
+
address: trade.inputAmount.currency.address,
|
|
39
|
+
amount: trade.inputAmount.amount,
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
const tx = await createSwapAndBridgeCalldata([trade], input.caller, input.receiver, true, fundsToPull, false, true, input.preCalls, input.postCalls);
|
|
43
|
+
return {
|
|
44
|
+
[ChainType.EVM]: {
|
|
45
|
+
calldata: tx.calldata,
|
|
46
|
+
value: tx.value.toString(),
|
|
47
|
+
to: tx.to,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.log(`cannot compose ${aggregator.toString()} swap tx:`, error);
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
...trade,
|
|
60
|
+
assemble,
|
|
61
|
+
approvalTarget: composer,
|
|
62
|
+
target: composer,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const fetchSwapTrade = async (aggregator, input, controller) => {
|
|
66
|
+
const reverseQuoteNeeded = input.tradeType === TradeType.EXACT_OUTPUT &&
|
|
67
|
+
!SUPPORT_EXACT_OUT.includes(aggregator);
|
|
68
|
+
if (reverseQuoteNeeded) {
|
|
69
|
+
const swapAmount = reverseQuote(input.fromCurrency, input.toCurrency, input.swapAmount).amount.toString();
|
|
70
|
+
return fetchExactInSwapTrade(aggregator, {
|
|
71
|
+
...input,
|
|
72
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
73
|
+
swapAmount,
|
|
74
|
+
}, controller);
|
|
75
|
+
}
|
|
76
|
+
return fetchExactInSwapTrade(aggregator, input, controller);
|
|
77
|
+
};
|
|
78
|
+
const fetchExactInSwapTrade = async (aggregator, input, controller) => {
|
|
6
79
|
if (getSwapAggregators().includes(aggregator)) {
|
|
7
80
|
return await fetchBridgeTrade(aggregator, { ...input, order: 'CHEAPEST' }, controller);
|
|
8
81
|
}
|
|
9
82
|
else {
|
|
10
|
-
|
|
83
|
+
const getPrice = getPriceGetter();
|
|
84
|
+
const [priceIn, priceOut] = getPrice([
|
|
85
|
+
{
|
|
86
|
+
chainId: input.fromCurrency.chainId,
|
|
87
|
+
tokenAddress: input.fromCurrency.address,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
chainId: input.toCurrency.chainId,
|
|
91
|
+
tokenAddress: input.toCurrency.address,
|
|
92
|
+
},
|
|
93
|
+
]);
|
|
94
|
+
return await fetchAggregatorTradeWithoutConfigs(aggregator, { ...input, priceIn, priceOut }, controller);
|
|
11
95
|
}
|
|
12
96
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
|
|
2
2
|
import { AcrossBaseInput } from '../../types';
|
|
3
|
-
export interface AcrossWithSwapInput extends AcrossBaseInput {
|
|
3
|
+
export interface AcrossWithSwapInput extends Omit<AcrossBaseInput, 'preCalls'> {
|
|
4
4
|
bridgeToCurrency: RawCurrency | undefined;
|
|
5
5
|
}
|
|
6
6
|
export declare const fetchAcrossTradeWithSwap: (input: AcrossWithSwapInput, controller?: AbortController) => Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acrossWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/across/acrossWithSwap.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EAKZ,WAAW,EAEZ,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAA;AAO9D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;
|
|
1
|
+
{"version":3,"file":"acrossWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/across/acrossWithSwap.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EAKZ,WAAW,EAEZ,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAA;AAO9D,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC;IAC5E,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAA;CAC1C;AAED,eAAO,MAAM,wBAAwB,GACnC,OAAO,mBAAmB,EAC1B,aAAa,eAAe,KAC3B,OAAO,CAAC;IAAE,KAAK,EAAE,YAAY,GAAG,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAgD/D,CAAA;AAED,eAAe,wBAAwB,CAAA"}
|
|
@@ -8,7 +8,7 @@ export const fetchAcrossTradeWithSwap = async (input, controller) => {
|
|
|
8
8
|
throw new Error('BridgeToCurrency undefined');
|
|
9
9
|
const toChainId = getSafeChainId(input.toCurrency?.chainId);
|
|
10
10
|
const toTokenIsBridgeToken = CurrencyHandler.equal(input.bridgeToCurrency, CurrencyHandler.wrapped(input.toCurrency));
|
|
11
|
-
const needDestinationCalls = (input.
|
|
11
|
+
const needDestinationCalls = (input.postCalls?.length ?? 0) > 0 || !toTokenIsBridgeToken;
|
|
12
12
|
if (!needDestinationCalls) {
|
|
13
13
|
const toTokenIsWNative = CurrencyHandler.isWNative(input.toCurrency);
|
|
14
14
|
if (toTokenIsWNative) {
|
|
@@ -66,7 +66,7 @@ const fetchAcrossTradeWithDestinationCalls = async (input, controller) => {
|
|
|
66
66
|
if (!input.bridgeToCurrency)
|
|
67
67
|
throw new Error('BridgeToCurrency undefined');
|
|
68
68
|
const toChainId = input.toCurrency.chainId;
|
|
69
|
-
const additionalCalls = input.
|
|
69
|
+
const additionalCalls = input.postCalls ?? [];
|
|
70
70
|
const needsSwap = !CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
|
|
71
71
|
const fetchSwapAndMessage = async (amount) => {
|
|
72
72
|
if (needsSwap) {
|
|
@@ -82,6 +82,7 @@ const fetchAcrossTradeWithDestinationCalls = async (input, controller) => {
|
|
|
82
82
|
caller: getAcrossMulticallHandler(toChainId),
|
|
83
83
|
receiver: input.receiver,
|
|
84
84
|
flashSwap: undefined,
|
|
85
|
+
disableComposer: true,
|
|
85
86
|
};
|
|
86
87
|
const destinationSwapTrade = await fetchBestTrade(destinationSwapInput, controller);
|
|
87
88
|
if (!destinationSwapTrade || !destinationSwapTrade.assemble)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericTrade
|
|
1
|
+
import { GenericTrade } from '@1delta/lib-utils';
|
|
2
2
|
import { AcrossBaseInput } from '../../types';
|
|
3
|
-
export declare const fetchAcrossTradeWithSwaps: (input: AcrossBaseInput,
|
|
3
|
+
export declare const fetchAcrossTradeWithSwaps: (input: AcrossBaseInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
4
|
export default fetchAcrossTradeWithSwaps;
|
|
5
5
|
//# sourceMappingURL=acrossWithSwaps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acrossWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/across/acrossWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,
|
|
1
|
+
{"version":3,"file":"acrossWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/across/acrossWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EASb,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAmB,MAAM,aAAa,CAAA;AAsB9D,eAAO,MAAM,yBAAyB,GACpC,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAyKlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { convertRawAmount } from '@1delta/lib-utils';
|
|
2
2
|
import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, nativeOnChain, splitSlippage, TradeType, } from '@1delta/lib-utils';
|
|
3
|
+
import { getCurrencyGetter } from '../../registry';
|
|
3
4
|
import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
|
|
4
5
|
import { fetchBestTrade, increaseAmountBySlippage, } from '../utils/multichainUtils';
|
|
5
6
|
import { fetchAcrossRoutes, selectAcrossRoute } from './acrossRoutes';
|
|
@@ -15,7 +16,7 @@ const validateContracts = (fromChainId) => {
|
|
|
15
16
|
return { forwarder, composer };
|
|
16
17
|
};
|
|
17
18
|
const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
18
|
-
export const fetchAcrossTradeWithSwaps = async (input,
|
|
19
|
+
export const fetchAcrossTradeWithSwaps = async (input, controller) => {
|
|
19
20
|
if (!input.fromCurrency || !input.toCurrency)
|
|
20
21
|
return undefined;
|
|
21
22
|
if (input.tradeType === TradeType.EXACT_OUTPUT)
|
|
@@ -31,6 +32,7 @@ export const fetchAcrossTradeWithSwaps = async (input, getCurrency, controller)
|
|
|
31
32
|
const acrossRoute = selectAcrossRoute(routes, input.fromCurrency, input.toCurrency);
|
|
32
33
|
if (!acrossRoute)
|
|
33
34
|
return undefined;
|
|
35
|
+
const getCurrency = getCurrencyGetter();
|
|
34
36
|
const fromAcrossCurrency = getCurrency(acrossRoute.originChainId.toString(), acrossRoute.originToken);
|
|
35
37
|
const toAcrossCurrency = getCurrency(acrossRoute.destinationChainId.toString(), acrossRoute.destinationToken);
|
|
36
38
|
const outputIsAcrossAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.toCurrency), toAcrossCurrency);
|
|
@@ -48,6 +50,7 @@ export const fetchAcrossTradeWithSwaps = async (input, getCurrency, controller)
|
|
|
48
50
|
caller: forwarder,
|
|
49
51
|
receiver: forwarder,
|
|
50
52
|
flashSwap: undefined,
|
|
53
|
+
disableComposer: true,
|
|
51
54
|
};
|
|
52
55
|
sourceSwapTrade = await fetchBestTrade(sourceSwapInput, controller);
|
|
53
56
|
}
|
|
@@ -82,7 +85,7 @@ export const fetchAcrossTradeWithSwaps = async (input, getCurrency, controller)
|
|
|
82
85
|
amount: BigInt(input.swapAmount),
|
|
83
86
|
},
|
|
84
87
|
];
|
|
85
|
-
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, false, fundsToPull, false);
|
|
88
|
+
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, false, fundsToPull, false, false, input.preCalls);
|
|
86
89
|
return {
|
|
87
90
|
EVM: {
|
|
88
91
|
to,
|
|
@@ -96,7 +99,7 @@ export const fetchAcrossTradeWithSwaps = async (input, getCurrency, controller)
|
|
|
96
99
|
...input,
|
|
97
100
|
slippage: inputOverride?.slippage ?? input.slippage,
|
|
98
101
|
};
|
|
99
|
-
return fetchAcrossTradeWithSwaps(newAggregatorInput
|
|
102
|
+
return fetchAcrossTradeWithSwaps(newAggregatorInput);
|
|
100
103
|
};
|
|
101
104
|
const outputAmount = !!sourceSwapTrade
|
|
102
105
|
? increaseAmountBySlippage(acrossTradeWithSwap.outputAmount.amount, Number(swapSlippage))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAcrossMessage.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/across/calldata/createAcrossMessage.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"createAcrossMessage.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/across/calldata/createAcrossMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAA+B,GAAG,EAAY,MAAM,MAAM,CAAA;AAGjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAGxE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,uBAAuB,EAAE,MAAM,EAC/B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM,EAC7B,eAAe,EAAE,SAAS,EAAE,EAC5B,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,GAAG,CA4DL;AAED,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,mBAAmB,GACvC,UAAU,EAAE,CA8Bd;AAED,wBAAgB,wBAAwB,CACtC,uBAAuB,EAAE,MAAM,EAC/B,uBAAuB,EAAE,MAAM,EAC/B,aAAa,EAAE,MAAM,EAAE,GACtB,GAAG,CAWL"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { GenericTrade, RawCurrency
|
|
1
|
+
import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
|
|
2
2
|
import { AxelarBaseInput } from '../../types';
|
|
3
|
-
export interface AxelarWithSwapInput extends AxelarBaseInput {
|
|
3
|
+
export interface AxelarWithSwapInput extends Omit<AxelarBaseInput, 'preCalls'> {
|
|
4
4
|
bridgeToCurrency: RawCurrency | undefined;
|
|
5
5
|
}
|
|
6
|
-
export declare const fetchAxelarTradeWithSwap: (input: AxelarWithSwapInput,
|
|
6
|
+
export declare const fetchAxelarTradeWithSwap: (input: AxelarWithSwapInput, controller?: AbortController) => Promise<{
|
|
7
7
|
trade: GenericTrade | undefined;
|
|
8
8
|
gasTrade: GenericTrade | undefined;
|
|
9
9
|
receiver: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axelarWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwap.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EAGZ,WAAW,
|
|
1
|
+
{"version":3,"file":"axelarWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwap.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EAGZ,WAAW,EAEZ,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAAmB,eAAe,EAAmB,MAAM,aAAa,CAAA;AAS/E,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC;IAC5E,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAA;CAC1C;AAED,eAAO,MAAM,wBAAwB,GACnC,OAAO,mBAAmB,EAC1B,aAAa,eAAe,KAC3B,OAAO,CAAC;IACT,KAAK,EAAE,YAAY,GAAG,SAAS,CAAA;IAC/B,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAA;IAClC,QAAQ,EAAE,MAAM,CAAA;CACjB,CA4CA,CAAA;AAED,eAAe,wBAAwB,CAAA"}
|
|
@@ -5,19 +5,19 @@ import { fetchBridgeAndGasTrade } from '../utils/fetchBridgeAndGasTrade';
|
|
|
5
5
|
import { fetchBestTrade } from '../utils/multichainUtils';
|
|
6
6
|
import { ADDITIONAL_CALLS_GAS_LIMIT, DESTINATION_SWAP_GAS_LIMIT, } from './constants';
|
|
7
7
|
import { createSquidDestinationPayload } from './squid/createSquidPayload';
|
|
8
|
-
export const fetchAxelarTradeWithSwap = async (input,
|
|
8
|
+
export const fetchAxelarTradeWithSwap = async (input, controller) => {
|
|
9
9
|
if (!input.bridgeToCurrency)
|
|
10
10
|
throw new Error('BridgeToCurrency undefined');
|
|
11
11
|
if (!input.toCurrency)
|
|
12
12
|
throw new Error('ToCurrency undefined');
|
|
13
13
|
const toChainId = input.toCurrency.chainId;
|
|
14
14
|
const toTokenIsBridgeToken = CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
|
|
15
|
-
const needDestinationCalls = (input.
|
|
15
|
+
const needDestinationCalls = (input.postCalls?.calls.length ?? 0) > 0 || !toTokenIsBridgeToken;
|
|
16
16
|
const squidRouter = await getRequiredSquidRouter(toChainId);
|
|
17
17
|
if (!needDestinationCalls) {
|
|
18
18
|
// direct case
|
|
19
19
|
const message = createSquidPayload(input.receiver);
|
|
20
|
-
const bridgeAndGasTrade = await fetchAxelarTrade(input.payFeeWithNative, { ...input, message },
|
|
20
|
+
const bridgeAndGasTrade = await fetchAxelarTrade(input.payFeeWithNative, { ...input, message }, controller);
|
|
21
21
|
return {
|
|
22
22
|
trade: bridgeAndGasTrade?.bridgeTrade,
|
|
23
23
|
gasTrade: bridgeAndGasTrade?.gasTrade,
|
|
@@ -26,7 +26,7 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
|
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
28
|
// destination calls case
|
|
29
|
-
const bridgeAndGasTrade = await fetchAxelarTradeWithDestinationCalls(input,
|
|
29
|
+
const bridgeAndGasTrade = await fetchAxelarTradeWithDestinationCalls(input, controller);
|
|
30
30
|
return {
|
|
31
31
|
trade: bridgeAndGasTrade?.bridgeTrade,
|
|
32
32
|
gasTrade: bridgeAndGasTrade?.gasTrade,
|
|
@@ -35,7 +35,7 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
export default fetchAxelarTradeWithSwap;
|
|
38
|
-
const fetchAxelarTradeWithDestinationCalls = async (input,
|
|
38
|
+
const fetchAxelarTradeWithDestinationCalls = async (input, controller) => {
|
|
39
39
|
if (!input.swapAmount)
|
|
40
40
|
throw new Error('Swap amount undefined');
|
|
41
41
|
if (!input.fromCurrency)
|
|
@@ -46,8 +46,8 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
|
|
|
46
46
|
throw new Error('BridgeToCurrency undefined');
|
|
47
47
|
const toChainId = input.toCurrency.chainId;
|
|
48
48
|
const squidMulticall = await getRequiredSquidMulticaller(toChainId);
|
|
49
|
-
const additionalCallsGasLimit = input.
|
|
50
|
-
const additionalCalls = input.
|
|
49
|
+
const additionalCallsGasLimit = input.postCalls?.gasLimit ?? ADDITIONAL_CALLS_GAS_LIMIT;
|
|
50
|
+
const additionalCalls = input.postCalls?.calls ?? [];
|
|
51
51
|
const needsAdditionalCalls = additionalCalls.length > 0;
|
|
52
52
|
const needsSwap = !CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
|
|
53
53
|
const fetchSwapAndMessage = async (amount) => {
|
|
@@ -64,6 +64,7 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
|
|
|
64
64
|
caller: squidMulticall,
|
|
65
65
|
receiver: squidMulticall,
|
|
66
66
|
flashSwap: undefined,
|
|
67
|
+
disableComposer: true,
|
|
67
68
|
};
|
|
68
69
|
const destinationSwapTrade = await fetchBestTrade(destinationSwapInput, controller);
|
|
69
70
|
if (!destinationSwapTrade || !destinationSwapTrade.assemble)
|
|
@@ -99,7 +100,7 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
|
|
|
99
100
|
message: swap.message,
|
|
100
101
|
destinationGasLimit: swap.gasLimit,
|
|
101
102
|
};
|
|
102
|
-
const bridgeAndGasTrade = await fetchAxelarTrade(input.payFeeWithNative, axelarInput,
|
|
103
|
+
const bridgeAndGasTrade = await fetchAxelarTrade(input.payFeeWithNative, axelarInput, controller);
|
|
103
104
|
if (!bridgeAndGasTrade)
|
|
104
105
|
return undefined;
|
|
105
106
|
const { bridgeTrade, gasTrade } = bridgeAndGasTrade;
|
|
@@ -119,7 +120,7 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
|
|
|
119
120
|
...input,
|
|
120
121
|
slippage: inputOverride?.slippage ?? input.slippage,
|
|
121
122
|
};
|
|
122
|
-
return (await fetchAxelarTradeWithSwap(newAggregatorInput
|
|
123
|
+
return (await fetchAxelarTradeWithSwap(newAggregatorInput)).trade;
|
|
123
124
|
};
|
|
124
125
|
const composedTrade = {
|
|
125
126
|
...updatedAxelarTrade,
|
|
@@ -134,13 +135,13 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
|
|
|
134
135
|
};
|
|
135
136
|
return { bridgeTrade: composedTrade, gasTrade };
|
|
136
137
|
};
|
|
137
|
-
const fetchAxelarTrade = async (payFeeWithNative, input,
|
|
138
|
+
const fetchAxelarTrade = async (payFeeWithNative, input, controller) => {
|
|
138
139
|
if (payFeeWithNative) {
|
|
139
140
|
const bridgeTrade = await fetchBridgeTrade(Bridge.AXELAR, input, controller);
|
|
140
141
|
return bridgeTrade ? { bridgeTrade, gasTrade: undefined } : undefined;
|
|
141
142
|
}
|
|
142
143
|
else {
|
|
143
|
-
const bridgeAndGasTrade = await fetchBridgeAndGasTrade(Bridge.AXELAR, input,
|
|
144
|
+
const bridgeAndGasTrade = await fetchBridgeAndGasTrade(Bridge.AXELAR, input, controller);
|
|
144
145
|
return bridgeAndGasTrade;
|
|
145
146
|
}
|
|
146
147
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenericTrade
|
|
1
|
+
import { GenericTrade } from '@1delta/lib-utils';
|
|
2
2
|
import { AxelarBaseInput } from '../../types';
|
|
3
|
-
export declare const fetchAxelarTradeWithSwaps: (input: AxelarBaseInput,
|
|
3
|
+
export declare const fetchAxelarTradeWithSwaps: (input: AxelarBaseInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
4
|
export default fetchAxelarTradeWithSwaps;
|
|
5
5
|
//# sourceMappingURL=axelarWithSwaps.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"axelarWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,
|
|
1
|
+
{"version":3,"file":"axelarWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EAQb,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAmB9D,eAAO,MAAM,yBAAyB,GACpC,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAwKlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { convertRawAmount, nativeOnChain } from '@1delta/lib-utils';
|
|
2
2
|
import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, splitSlippage, TradeType, } from '@1delta/lib-utils';
|
|
3
|
+
import { getCurrencyGetter } from '../../registry';
|
|
3
4
|
import { fetchBestTrade, increaseAmountBySlippage } from '../utils';
|
|
4
5
|
import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
|
|
5
6
|
import { fetchAxelarRoute } from './axelarRoutes';
|
|
@@ -15,7 +16,7 @@ const validateContracts = (fromChainId) => {
|
|
|
15
16
|
return { forwarder, composer };
|
|
16
17
|
};
|
|
17
18
|
const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
18
|
-
export const fetchAxelarTradeWithSwaps = async (input,
|
|
19
|
+
export const fetchAxelarTradeWithSwaps = async (input, controller) => {
|
|
19
20
|
if (!input.fromCurrency || !input.toCurrency)
|
|
20
21
|
return undefined;
|
|
21
22
|
if (input.tradeType === TradeType.EXACT_OUTPUT)
|
|
@@ -30,6 +31,7 @@ export const fetchAxelarTradeWithSwaps = async (input, getCurrency, getPrices, c
|
|
|
30
31
|
const route = await fetchAxelarRoute(fromChainId, toChainId);
|
|
31
32
|
if (!route)
|
|
32
33
|
return undefined;
|
|
34
|
+
const getCurrency = getCurrencyGetter();
|
|
33
35
|
const fromBridgeCurrency = getCurrency(fromChainId, route.fromBridgeToken);
|
|
34
36
|
const toBridgeCurrency = getCurrency(toChainId, route.toBridgeToken);
|
|
35
37
|
const outputIsBridgeAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.toCurrency), toBridgeCurrency);
|
|
@@ -47,6 +49,7 @@ export const fetchAxelarTradeWithSwaps = async (input, getCurrency, getPrices, c
|
|
|
47
49
|
caller: forwarder,
|
|
48
50
|
receiver: forwarder,
|
|
49
51
|
flashSwap: undefined,
|
|
52
|
+
disableComposer: true,
|
|
50
53
|
};
|
|
51
54
|
sourceSwapTrade = await fetchBestTrade(sourceSwapInput, controller);
|
|
52
55
|
}
|
|
@@ -62,7 +65,7 @@ export const fetchAxelarTradeWithSwaps = async (input, getCurrency, getPrices, c
|
|
|
62
65
|
caller: forwarder,
|
|
63
66
|
receiver: isDummy ? DUMMY_ADDRESS : input.receiver,
|
|
64
67
|
};
|
|
65
|
-
const { trade: bridgeTradeWithSwap, gasTrade, receiver: bridgeReceiver, } = await fetchAxelarTradeWithSwap(bridgeExtendedInput,
|
|
68
|
+
const { trade: bridgeTradeWithSwap, gasTrade, receiver: bridgeReceiver, } = await fetchAxelarTradeWithSwap(bridgeExtendedInput, controller);
|
|
66
69
|
if (!bridgeTradeWithSwap)
|
|
67
70
|
return undefined;
|
|
68
71
|
const trades = [];
|
|
@@ -86,7 +89,7 @@ export const fetchAxelarTradeWithSwaps = async (input, getCurrency, getPrices, c
|
|
|
86
89
|
amount: bridgeTradeWithSwap.gasAmount,
|
|
87
90
|
});
|
|
88
91
|
}
|
|
89
|
-
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, true, fundsToPull, false, true);
|
|
92
|
+
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, true, fundsToPull, false, true, input.preCalls);
|
|
90
93
|
return {
|
|
91
94
|
EVM: {
|
|
92
95
|
to,
|
|
@@ -100,7 +103,7 @@ export const fetchAxelarTradeWithSwaps = async (input, getCurrency, getPrices, c
|
|
|
100
103
|
...input,
|
|
101
104
|
slippage: inputOverride?.slippage ?? input.slippage,
|
|
102
105
|
};
|
|
103
|
-
return fetchAxelarTradeWithSwaps(newAggregatorInput
|
|
106
|
+
return fetchAxelarTradeWithSwaps(newAggregatorInput);
|
|
104
107
|
};
|
|
105
108
|
const outputAmount = !!sourceSwapTrade
|
|
106
109
|
? increaseAmountBySlippage(bridgeTradeWithSwap.outputAmount.amount, Number(swapSlippage))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { DeltaCall } from '@1delta/lib-utils';
|
|
1
2
|
import { Hex } from 'viem';
|
|
2
|
-
import { DeltaCall } from '../../../types/deltaCall';
|
|
3
3
|
import { DestinationSwapData } from '../../../types/destinationSwapData';
|
|
4
4
|
/**
|
|
5
5
|
* Creates the final `payload` for a complete cross-chain swap using Squid.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSquidPayload.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/createSquidPayload.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"createSquidPayload.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/createSquidPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAA+B,GAAG,EAAyB,MAAM,MAAM,CAAA;AAG9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AAyDxE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,WAAW,EAAE,MAAM,EACnB,qBAAqB,EAAE,MAAM,EAC7B,eAAe,EAAE,SAAS,EAAE,EAC5B,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,GAAG,CA6DL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gaszipWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/gaszip/gaszipWithSwaps.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,YAAY,EASb,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAoB9D,eAAO,MAAM,yBAAyB,GACpC,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"gaszipWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/gaszip/gaszipWithSwaps.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,YAAY,EASb,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAoB9D,eAAO,MAAM,yBAAyB,GACpC,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAmJlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { InternalTrade } from '@1delta/lib-utils';
|
|
1
|
+
import { InternalTrade, PostDeltaCall, PreDeltaCall } from '@1delta/lib-utils';
|
|
2
2
|
export declare function createSwapAndBridgeCalldata(trades: InternalTrade[], account: string, bridgeReceiver: string, sweep: boolean, fundsToPull?: {
|
|
3
3
|
address: string;
|
|
4
4
|
amount: bigint;
|
|
5
|
-
}[], catchRevert?: boolean, sweepDust?: boolean): Promise<{
|
|
5
|
+
}[], catchRevert?: boolean, sweepDust?: boolean, preCalls?: PreDeltaCall[], postCalls?: PostDeltaCall[]): Promise<{
|
|
6
6
|
calldata: `0x${string}`;
|
|
7
7
|
value: bigint;
|
|
8
8
|
to: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSwapAndBridgeCalldata.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/createSwapAndBridgeCalldata.ts"],"names":[],"mappings":"AAcA,OAAO,EAOL,aAAa,
|
|
1
|
+
{"version":3,"file":"createSwapAndBridgeCalldata.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/createSwapAndBridgeCalldata.ts"],"names":[],"mappings":"AAcA,OAAO,EAOL,aAAa,EAGb,aAAa,EACb,YAAY,EAGb,MAAM,mBAAmB,CAAA;AAK1B,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,aAAa,EAAE,EACvB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,OAAO,EACd,WAAW,GAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAO,EACvD,WAAW,GAAE,OAAc,EAC3B,SAAS,GAAE,OAAe,EAC1B,QAAQ,GAAE,YAAY,EAAO,EAC7B,SAAS,GAAE,aAAa,EAAO;;;;GAiRhC"}
|
|
@@ -2,10 +2,15 @@ import { Bridge } from '@1delta/bridge-configs';
|
|
|
2
2
|
import { encodeAcrossBridgeNative, encodeAcrossBridgeToken, encodeApprove, encodeExternalCall, encodeGasZipEvmBridge, encodeSquidRouterCall, encodeStargateV2BridgeSimpleTaxi, encodeSweep, encodeTransferIn, encodeTryExternalCall, SweepType, } from '@1delta/calldatalib';
|
|
3
3
|
import { buildMetaSwapParams, CurrencyHandler, encodeComposerCompose, getDeltaComposerProxyAddress, getForwarderAddress, minimumAmountInFromAmount, packCommands, TradeUtils, } from '@1delta/lib-utils';
|
|
4
4
|
import { encodePacked, pad } from 'viem';
|
|
5
|
-
|
|
5
|
+
import { createDeltaCalls } from '../../deltaCall';
|
|
6
|
+
export async function createSwapAndBridgeCalldata(trades, account, bridgeReceiver, sweep, fundsToPull = [], catchRevert = true, sweepDust = false, preCalls = [], postCalls = []) {
|
|
6
7
|
if (!trades || trades.length === 0 || !isSameSourceChainId(trades))
|
|
7
8
|
throw new Error(`Invalid trades array. Must have at least one trade and all trades must be on the same chain`);
|
|
8
9
|
const sourceChainId = trades[0].inputAmount.currency.chainId;
|
|
10
|
+
const destChainId = trades[trades.length - 1].outputAmount.currency.chainId;
|
|
11
|
+
const isCrossChain = sourceChainId !== destChainId;
|
|
12
|
+
if (isCrossChain && postCalls.length > 0)
|
|
13
|
+
throw new Error('Post-calls are not supported for cross-chain trades');
|
|
9
14
|
const forwarder = getForwarderAddress(sourceChainId);
|
|
10
15
|
if (!forwarder)
|
|
11
16
|
throw new Error(`CallForwarder contract does not exist on chain ${sourceChainId}`);
|
|
@@ -95,6 +100,10 @@ export async function createSwapAndBridgeCalldata(trades, account, bridgeReceive
|
|
|
95
100
|
sweepTokens.push(sweepOutputToken);
|
|
96
101
|
}
|
|
97
102
|
}
|
|
103
|
+
const { composerCommands: preComposerCommands } = createDeltaCalls(sourceChainId, preCalls);
|
|
104
|
+
const { forwarderCommands: postForwarderCommands, composerCommands: postComposerCommands, } = createDeltaCalls(sourceChainId, postCalls);
|
|
105
|
+
const forwarderSweepCommands = [];
|
|
106
|
+
const composerSweepCommands = [];
|
|
98
107
|
if (sweep) {
|
|
99
108
|
const sameChainTrades = trades.filter((t) => t.inputAmount.currency.chainId === t.outputAmount.currency.chainId);
|
|
100
109
|
const currencyToAmount = TradeUtils.groupAmountByCurrency({
|
|
@@ -102,9 +111,21 @@ export async function createSwapAndBridgeCalldata(trades, account, bridgeReceive
|
|
|
102
111
|
getCurrency: (t) => t.outputAmount.currency,
|
|
103
112
|
getAmount: (t) => minimumAmountInFromAmount(t.outputAmount, t.slippage),
|
|
104
113
|
});
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
114
|
+
if (postComposerCommands.length > 0) {
|
|
115
|
+
// special case: first sweep to composer and after post composer calls sweep dust to receiver
|
|
116
|
+
for (const [currency, amount] of currencyToAmount.entries()) {
|
|
117
|
+
const forwarderSweepCall = encodeSweep(currency.address, composerProxy, sweepDust ? 0n : amount, SweepType.VALIDATE);
|
|
118
|
+
forwarderSweepCommands.push(forwarderSweepCall);
|
|
119
|
+
const composerSweepCall = encodeSweep(currency.address, account, 0n, SweepType.VALIDATE);
|
|
120
|
+
composerSweepCommands.push(composerSweepCall);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// normal case: sweep directly to receiver after forwarder calls
|
|
125
|
+
for (const [currency, amount] of currencyToAmount.entries()) {
|
|
126
|
+
const forwarderSweepCall = encodeSweep(currency.address, account, sweepDust ? 0n : amount, SweepType.VALIDATE);
|
|
127
|
+
forwarderSweepCommands.push(forwarderSweepCall);
|
|
128
|
+
}
|
|
108
129
|
}
|
|
109
130
|
}
|
|
110
131
|
let value = 0n;
|
|
@@ -115,9 +136,16 @@ export async function createSwapAndBridgeCalldata(trades, account, bridgeReceive
|
|
|
115
136
|
else
|
|
116
137
|
transferInCommands.push(encodeTransferIn(address, forwarder, amount));
|
|
117
138
|
}
|
|
139
|
+
const preCommands = preComposerCommands.length > 0 ? preComposerCommands : transferInCommands;
|
|
118
140
|
const calldata = encodeComposerCompose(packCommands([
|
|
119
|
-
...
|
|
120
|
-
encodeExternalCall(forwarder,
|
|
141
|
+
...preCommands,
|
|
142
|
+
encodeExternalCall(forwarder, 0n, true, packCommands([
|
|
143
|
+
...commands,
|
|
144
|
+
...postForwarderCommands,
|
|
145
|
+
...forwarderSweepCommands,
|
|
146
|
+
])),
|
|
147
|
+
...postComposerCommands,
|
|
148
|
+
...composerSweepCommands,
|
|
121
149
|
]));
|
|
122
150
|
return { calldata, value, to: composerProxy };
|
|
123
151
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bridge } from '@1delta/bridge-configs';
|
|
2
|
-
import { GenericTrade
|
|
2
|
+
import { GenericTrade } from '@1delta/lib-utils';
|
|
3
3
|
import { BaseBridgeInput } from '../../types';
|
|
4
|
-
export declare const fetchBridgeAndGasTrade: (aggregator: Bridge, input: BaseBridgeInput,
|
|
4
|
+
export declare const fetchBridgeAndGasTrade: (aggregator: Bridge, input: BaseBridgeInput, controller?: AbortController) => Promise<{
|
|
5
5
|
bridgeTrade: GenericTrade;
|
|
6
6
|
gasTrade: GenericTrade | undefined;
|
|
7
7
|
} | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchBridgeAndGasTrade.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/fetchBridgeAndGasTrade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"fetchBridgeAndGasTrade.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/fetchBridgeAndGasTrade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAmB,YAAY,EAAiB,MAAM,mBAAmB,CAAA;AAGhF,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,eAAO,MAAM,sBAAsB,GACjC,YAAY,MAAM,EAClB,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CACR;IAAE,WAAW,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,CA2E9E,CAAA"}
|