@1delta/trade-sdk 0.1.2 → 0.1.4

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.
Files changed (68) hide show
  1. package/dist/aggregator/fetchAggregatorTrade.d.ts.map +1 -1
  2. package/dist/aggregator/fetchAggregatorTrade.js +0 -3
  3. package/dist/bridge/fetchBridgeTrade.d.ts.map +1 -1
  4. package/dist/bridge/fetchBridgeTrade.js +1 -1
  5. package/dist/composedTrades/across/acrossWithSwap.d.ts +2 -2
  6. package/dist/composedTrades/across/acrossWithSwap.d.ts.map +1 -1
  7. package/dist/composedTrades/across/acrossWithSwap.js +47 -26
  8. package/dist/composedTrades/across/acrossWithSwaps.d.ts +2 -2
  9. package/dist/composedTrades/across/acrossWithSwaps.d.ts.map +1 -1
  10. package/dist/composedTrades/across/acrossWithSwaps.js +1 -1
  11. package/dist/composedTrades/across/calldata/createAcrossMessage.d.ts +5 -2
  12. package/dist/composedTrades/across/calldata/createAcrossMessage.d.ts.map +1 -1
  13. package/dist/composedTrades/across/calldata/createAcrossMessage.js +40 -4
  14. package/dist/composedTrades/axelar/axelarWithSwap.d.ts +2 -2
  15. package/dist/composedTrades/axelar/axelarWithSwap.d.ts.map +1 -1
  16. package/dist/composedTrades/axelar/axelarWithSwap.js +14 -11
  17. package/dist/composedTrades/axelar/axelarWithSwaps.d.ts +2 -2
  18. package/dist/composedTrades/axelar/axelarWithSwaps.d.ts.map +1 -1
  19. package/dist/composedTrades/axelar/axelarWithSwaps.js +1 -1
  20. package/dist/composedTrades/axelar/constants.d.ts +2 -0
  21. package/dist/composedTrades/axelar/constants.d.ts.map +1 -1
  22. package/dist/composedTrades/axelar/constants.js +2 -0
  23. package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts +22 -24
  24. package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts.map +1 -1
  25. package/dist/composedTrades/axelar/squid/createSquidPayload.js +57 -20
  26. package/dist/composedTrades/gaszip/gaszipWithSwaps.js +1 -1
  27. package/dist/composedTrades/utils/requireDeltaContracts.d.ts +5 -0
  28. package/dist/composedTrades/utils/requireDeltaContracts.d.ts.map +1 -0
  29. package/dist/composedTrades/utils/requireDeltaContracts.js +10 -0
  30. package/dist/deltaCall/createDeltaCallsCalldata.d.ts +10 -0
  31. package/dist/deltaCall/createDeltaCallsCalldata.d.ts.map +1 -0
  32. package/dist/deltaCall/createDeltaCallsCalldata.js +28 -0
  33. package/dist/deltaCall/index.d.ts +2 -0
  34. package/dist/deltaCall/index.d.ts.map +1 -0
  35. package/dist/deltaCall/index.js +1 -0
  36. package/dist/deltaCall/toComposerCall.d.ts +4 -0
  37. package/dist/deltaCall/toComposerCall.d.ts.map +1 -0
  38. package/dist/deltaCall/toComposerCall.js +26 -0
  39. package/dist/deltaCall/toForwarderCall.d.ts +4 -0
  40. package/dist/deltaCall/toForwarderCall.d.ts.map +1 -0
  41. package/dist/deltaCall/toForwarderCall.js +25 -0
  42. package/dist/index.d.ts +6 -5
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +3 -2
  45. package/dist/initialize.d.ts +34 -0
  46. package/dist/initialize.d.ts.map +1 -1
  47. package/dist/initialize.js +40 -5
  48. package/dist/registry/index.d.ts +7 -0
  49. package/dist/registry/index.d.ts.map +1 -0
  50. package/dist/registry/index.js +19 -0
  51. package/dist/types/aggregatorInput.d.ts +3 -0
  52. package/dist/types/aggregatorInput.d.ts.map +1 -0
  53. package/dist/types/bridgeInput.d.ts +18 -8
  54. package/dist/types/bridgeInput.d.ts.map +1 -1
  55. package/dist/types/deltaCall.d.ts +62 -0
  56. package/dist/types/deltaCall.d.ts.map +1 -0
  57. package/dist/types/deltaCall.js +16 -0
  58. package/dist/types/destinationSwapData.d.ts +8 -0
  59. package/dist/types/destinationSwapData.d.ts.map +1 -0
  60. package/dist/types/destinationSwapData.js +1 -0
  61. package/dist/types/index.d.ts +3 -1
  62. package/dist/types/index.d.ts.map +1 -1
  63. package/dist/types/index.js +3 -1
  64. package/dist/utils/utils.js +1 -1
  65. package/package.json +11 -11
  66. package/dist/types/aggregator.d.ts +0 -11
  67. package/dist/types/aggregator.d.ts.map +0 -1
  68. /package/dist/types/{aggregator.js → aggregatorInput.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"fetchAggregatorTrade.d.ts","sourceRoot":"","sources":["../../src/aggregator/fetchAggregatorTrade.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AAMtC,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,mBAAmB,CAAA;AAK1B,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,OAAO,kBAAkB,GAAG,aAAa,EACzC,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAgBlC,CAAA"}
1
+ {"version":3,"file":"fetchAggregatorTrade.d.ts","sourceRoot":"","sources":["../../src/aggregator/fetchAggregatorTrade.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AAMtC,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACd,MAAM,mBAAmB,CAAA;AAI1B,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,EAClB,OAAO,kBAAkB,GAAG,aAAa,EACzC,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAclC,CAAA"}
@@ -2,10 +2,7 @@ export * from './fetchAggregatorTrade';
2
2
  import { fetchAggregatorTrade as fetchAggregatorTradeWithoutConfigs, } from '@1delta/aggregators';
3
3
  import { getSwapAggregators } from '@1delta/bridge-configs';
4
4
  import { fetchBridgeTrade } from '../bridge';
5
- import { getAvailableAggregators } from './getAvailableAggregators';
6
5
  export const fetchAggregatorTrade = async (aggregator, input, controller) => {
7
- if (!getAvailableAggregators(input.chainId))
8
- return undefined;
9
6
  if (getSwapAggregators().includes(aggregator)) {
10
7
  return await fetchBridgeTrade(aggregator, { ...input, order: 'CHEAPEST' }, controller);
11
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"fetchBridgeTrade.d.ts","sourceRoot":"","sources":["../../src/bridge/fetchBridgeTrade.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAU/C,OAAO,EAKL,YAAY,EAWb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,EACd,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAiMlC,CAAA"}
1
+ {"version":3,"file":"fetchBridgeTrade.d.ts","sourceRoot":"","sources":["../../src/bridge/fetchBridgeTrade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAW/C,OAAO,EAKL,YAAY,EAWb,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,gBAAgB,GAC3B,QAAQ,MAAM,EACd,OAAO,eAAe,EACtB,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAiMlC,CAAA"}
@@ -1,6 +1,6 @@
1
- import { convertRawAmount } from '@1delta/aggregators';
2
1
  import { Bridge } from '@1delta/bridge-configs';
3
2
  import { buildTransactionData, getQuote, getRoute, getStatus, } from '@1delta/bridge-core';
3
+ import { convertRawAmount } from '@1delta/lib-utils';
4
4
  import { ChainType, ChainUtils, CurrencyHandler, isDirectlyPermittable, NATIVE_PLACEHOLDER, PermitShared, TradeType, } from '@1delta/lib-utils';
5
5
  export const fetchBridgeTrade = async (bridge, input, controller) => {
6
6
  const inputSlippage = input.slippage;
@@ -1,6 +1,6 @@
1
1
  import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
2
- import { BaseBridgeInput } from '../../types';
3
- export interface AcrossWithSwapInput extends BaseBridgeInput {
2
+ import { BaseComposedInput } from '../../types';
3
+ export interface AcrossWithSwapInput extends BaseComposedInput {
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,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAO9D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,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,CA6C/D,CAAA;AAED,eAAe,wBAAwB,CAAA"}
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,EAAmB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAOhE,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC5D,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,8 @@ 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
- if (toTokenIsBridgeToken) {
11
+ const needDestinationCalls = (input.additionalCalls?.length ?? 0) > 0 || !toTokenIsBridgeToken;
12
+ if (!needDestinationCalls) {
12
13
  const toTokenIsWNative = CurrencyHandler.isWNative(input.toCurrency);
13
14
  if (toTokenIsWNative) {
14
15
  // special case: to receive wrapped native receiver must be contract
@@ -28,7 +29,7 @@ export const fetchAcrossTradeWithSwap = async (input, controller) => {
28
29
  }
29
30
  }
30
31
  else {
31
- const acrossTrade = await fetchAcrossTradeWithDestinationSwap(input, controller);
32
+ const acrossTrade = await fetchAcrossTradeWithDestinationCalls(input, controller);
32
33
  return {
33
34
  trade: acrossTrade,
34
35
  receiver: getAcrossMulticallHandler(toChainId),
@@ -55,7 +56,7 @@ const fetchAcrossTradeWithSweep = async (input, controller) => {
55
56
  return undefined;
56
57
  return acrossTrade;
57
58
  };
58
- const fetchAcrossTradeWithDestinationSwap = async (input, controller) => {
59
+ const fetchAcrossTradeWithDestinationCalls = async (input, controller) => {
59
60
  if (!input.swapAmount)
60
61
  throw new Error('Swap amount undefined');
61
62
  if (!input.fromCurrency)
@@ -65,27 +66,43 @@ const fetchAcrossTradeWithDestinationSwap = async (input, controller) => {
65
66
  if (!input.bridgeToCurrency)
66
67
  throw new Error('BridgeToCurrency undefined');
67
68
  const toChainId = input.toCurrency.chainId;
69
+ const additionalCalls = input.additionalCalls ?? [];
70
+ const needsSwap = !CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
68
71
  const fetchSwapAndMessage = async (amount) => {
69
- const destinationSwapInput = {
70
- chainId: toChainId,
71
- tradeType: TradeType.EXACT_INPUT,
72
- fromCurrency: input.bridgeToCurrency,
73
- toCurrency: input.toCurrency,
74
- slippage: input.slippage,
75
- swapAmount: amount.toString(),
76
- txOrigin: getAcrossMulticallHandler(toChainId),
77
- caller: getAcrossMulticallHandler(toChainId),
78
- receiver: input.receiver,
79
- flashSwap: undefined,
80
- };
81
- const destinationSwapTrade = await fetchBestTrade(destinationSwapInput, controller);
82
- if (!destinationSwapTrade || !destinationSwapTrade.assemble)
83
- return undefined;
84
- const tx = await destinationSwapTrade.assemble();
85
- if (!tx?.EVM)
86
- return undefined;
87
- const message = createAcrossSwapMessage(getAcrossMulticallHandler(toChainId), destinationSwapTrade.inputAmount.currency.address, destinationSwapTrade.inputAmount.amount, destinationSwapTrade.target, [tx.EVM], input.receiver, [destinationSwapTrade.inputAmount.currency.address]);
88
- return { message, destinationSwapTrade };
72
+ if (needsSwap) {
73
+ // Handle destination swap case
74
+ const destinationSwapInput = {
75
+ chainId: toChainId,
76
+ tradeType: TradeType.EXACT_INPUT,
77
+ fromCurrency: input.bridgeToCurrency,
78
+ toCurrency: input.toCurrency,
79
+ slippage: input.slippage,
80
+ swapAmount: amount.toString(),
81
+ txOrigin: getAcrossMulticallHandler(toChainId),
82
+ caller: getAcrossMulticallHandler(toChainId),
83
+ receiver: input.receiver,
84
+ flashSwap: undefined,
85
+ };
86
+ const destinationSwapTrade = await fetchBestTrade(destinationSwapInput, controller);
87
+ if (!destinationSwapTrade || !destinationSwapTrade.assemble)
88
+ return undefined;
89
+ const tx = await destinationSwapTrade.assemble();
90
+ if (!tx?.EVM)
91
+ return undefined;
92
+ const message = createAcrossSwapMessage(getAcrossMulticallHandler(toChainId), toChainId, destinationSwapTrade.inputAmount.currency.address, destinationSwapTrade.outputAmount.currency.address, input.receiver, additionalCalls, {
93
+ tokenToApprove: destinationSwapTrade.inputAmount.currency.address,
94
+ amountToApprove: destinationSwapTrade.inputAmount.amount,
95
+ spender: destinationSwapTrade.target,
96
+ calls: [tx.EVM],
97
+ });
98
+ return { message, destinationSwapTrade };
99
+ }
100
+ else if (additionalCalls.length > 0) {
101
+ // Handle only destination calls case
102
+ const message = createAcrossSwapMessage(getAcrossMulticallHandler(toChainId), toChainId, undefined, input.bridgeToCurrency.address, input.receiver, additionalCalls);
103
+ return { message, destinationSwapTrade: undefined };
104
+ }
105
+ return undefined;
89
106
  };
90
107
  const destinationSwapAmount = normalizeDecimals(BigInt(input.swapAmount), input.fromCurrency.decimals, input.bridgeToCurrency.decimals);
91
108
  const swap = await fetchSwapAndMessage(destinationSwapAmount);
@@ -114,9 +131,13 @@ const fetchAcrossTradeWithDestinationSwap = async (input, controller) => {
114
131
  };
115
132
  return {
116
133
  ...updatedAcrossTrade,
117
- outputAmount: updatedSwap.destinationSwapTrade.outputAmount,
118
- outputAmountRealized: updatedSwap.destinationSwapTrade.outputAmountRealized,
119
- stringified: `${updatedAcrossTrade?.stringified}-${updatedSwap.destinationSwapTrade.stringified}`,
134
+ outputAmount: updatedSwap.destinationSwapTrade?.outputAmount ??
135
+ updatedAcrossTrade.outputAmount,
136
+ outputAmountRealized: updatedSwap.destinationSwapTrade?.outputAmountRealized ??
137
+ updatedAcrossTrade.outputAmountRealized,
138
+ stringified: updatedSwap.destinationSwapTrade
139
+ ? `${updatedAcrossTrade?.stringified}-${updatedSwap.destinationSwapTrade.stringified}`
140
+ : updatedAcrossTrade.stringified,
120
141
  refresh,
121
142
  };
122
143
  };
@@ -1,5 +1,5 @@
1
1
  import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
2
- import { BaseBridgeInput } from '../../types';
3
- export declare const fetchAcrossTradeWithSwaps: (input: BaseBridgeInput, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency | undefined, controller?: AbortController) => Promise<GenericTrade | undefined>;
2
+ import { BaseComposedInput } from '../../types';
3
+ export declare const fetchAcrossTradeWithSwaps: (input: BaseComposedInput, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency | undefined, 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,EAOZ,WAAW,EAGZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAmB,eAAe,EAAE,MAAM,aAAa,CAAA;AAsB9D,eAAO,MAAM,yBAAyB,GACpC,OAAO,eAAe,EACtB,aAAa,CACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,GAAG,SAAS,KAC7B,WAAW,GAAG,SAAS,EAC5B,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAoKlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
1
+ {"version":3,"file":"acrossWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/across/acrossWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EAOZ,WAAW,EAGZ,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAmB,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAsBhE,eAAO,MAAM,yBAAyB,GACpC,OAAO,iBAAiB,EACxB,aAAa,CACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,GAAG,SAAS,KAC7B,WAAW,GAAG,SAAS,EAC5B,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CAqKlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { convertRawAmount } from '@1delta/aggregators';
1
+ import { convertRawAmount } from '@1delta/lib-utils';
2
2
  import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, nativeOnChain, splitSlippage, TradeType, } from '@1delta/lib-utils';
3
3
  import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
4
4
  import { fetchBestTrade, increaseAmountBySlippage, } from '../utils/multichainUtils';
@@ -1,5 +1,7 @@
1
- import { EvmGenericCallInfo } from '@1delta/lib-utils';
2
1
  import { Hex } from 'viem';
2
+ import { DeltaCall } from '../../../types/deltaCall';
3
+ import { DestinationSwapData } from '../../../types/destinationSwapData';
4
+ import { AcrossCall } from './types';
3
5
  /**
4
6
  * Creates the ABI-encoded `message` for a complete "Approve -> Execute -> Drain" sequence
5
7
  * using the Across MulticallHandler.
@@ -18,6 +20,7 @@ import { Hex } from 'viem';
18
20
  * @param fallbackAndDrainAddress - The single address that serves as both the safety net (fallback) and the destination for the drained tokens. This should be your wallet.
19
21
  * @returns The final, ABI-encoded `message` as a hex string (`Hex`).
20
22
  */
21
- export declare function createAcrossSwapMessage(multicallHandlerAddress: string, tokenToApprove: string, amountToApprove: bigint, spender: string, calls: EvmGenericCallInfo[], fallbackAndDrainAddress: string, tokensToDrain: string[]): Hex;
23
+ export declare function createAcrossSwapMessage(multicallHandlerAddress: string, chainId: string, inputToken: string | undefined, outputToken: string, refundAndDrainAddress: string, additionalCalls: DeltaCall[], destinationSwapData?: DestinationSwapData): Hex;
24
+ export declare function createAcrossSwapCalls(destinationSwapData: DestinationSwapData): AcrossCall[];
22
25
  export declare function createAcrossDrainMessage(multicallHandlerAddress: string, fallbackAndDrainAddress: string, tokensToDrain: string[]): Hex;
23
26
  //# sourceMappingURL=createAcrossMessage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createAcrossMessage.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/across/calldata/createAcrossMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAA+B,GAAG,EAAY,MAAM,MAAM,CAAA;AAKjE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CACrC,uBAAuB,EAAE,MAAM,EAC/B,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,kBAAkB,EAAE,EAC3B,uBAAuB,EAAE,MAAM,EAC/B,aAAa,EAAE,MAAM,EAAE,GACtB,GAAG,CAsCL;AAED,wBAAgB,wBAAwB,CACtC,uBAAuB,EAAE,MAAM,EAC/B,uBAAuB,EAAE,MAAM,EAC/B,aAAa,EAAE,MAAM,EAAE,GACtB,GAAG,CAWL"}
1
+ {"version":3,"file":"createAcrossMessage.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/across/calldata/createAcrossMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,GAAG,EAAY,MAAM,MAAM,CAAA;AAGjE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,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,4 +1,6 @@
1
1
  import { encodeFunctionData, parseAbi } from 'viem';
2
+ import { createDeltaCallsCalldata } from '../../../deltaCall/createDeltaCallsCalldata';
3
+ import { requireDeltaContracts } from '../../utils/requireDeltaContracts';
2
4
  import { createAcrossMultiCallMessage } from './createAcrossMultiCallMessage';
3
5
  /**
4
6
  * Creates the ABI-encoded `message` for a complete "Approve -> Execute -> Drain" sequence
@@ -18,7 +20,43 @@ import { createAcrossMultiCallMessage } from './createAcrossMultiCallMessage';
18
20
  * @param fallbackAndDrainAddress - The single address that serves as both the safety net (fallback) and the destination for the drained tokens. This should be your wallet.
19
21
  * @returns The final, ABI-encoded `message` as a hex string (`Hex`).
20
22
  */
21
- export function createAcrossSwapMessage(multicallHandlerAddress, tokenToApprove, amountToApprove, spender, calls, fallbackAndDrainAddress, tokensToDrain) {
23
+ export function createAcrossSwapMessage(multicallHandlerAddress, chainId, inputToken, outputToken, refundAndDrainAddress, additionalCalls, destinationSwapData) {
24
+ const swapCalls = destinationSwapData
25
+ ? createAcrossSwapCalls(destinationSwapData)
26
+ : [];
27
+ if (additionalCalls.length === 0) {
28
+ // normal case: do calls and sweep to user
29
+ const tokensToDrain = inputToken ? [inputToken, outputToken] : [outputToken];
30
+ const drainCalls = createDrainCalls(multicallHandlerAddress, refundAndDrainAddress, tokensToDrain);
31
+ const allCalls = [...swapCalls, ...drainCalls];
32
+ return createAcrossMultiCallMessage(allCalls, refundAndDrainAddress);
33
+ }
34
+ else {
35
+ // composer case: do calls and continue in composer
36
+ const { forwarder } = requireDeltaContracts(chainId);
37
+ const tokensToDrain = inputToken ? [inputToken] : [];
38
+ const drainToUserCall = createDrainCalls(multicallHandlerAddress, refundAndDrainAddress, tokensToDrain);
39
+ const drainToForwarder = createDrainCalls(multicallHandlerAddress, forwarder, [outputToken]);
40
+ const deltaComposerCall = createDeltaCallsCalldata(chainId, additionalCalls, {
41
+ tokensToSweep: [outputToken],
42
+ receiver: refundAndDrainAddress,
43
+ });
44
+ const callToComposer = {
45
+ target: deltaComposerCall.to,
46
+ callData: deltaComposerCall.calldata,
47
+ value: 0n,
48
+ };
49
+ const allCalls = [
50
+ ...swapCalls,
51
+ ...drainToUserCall,
52
+ ...drainToForwarder,
53
+ callToComposer,
54
+ ];
55
+ return createAcrossMultiCallMessage(allCalls, refundAndDrainAddress);
56
+ }
57
+ }
58
+ export function createAcrossSwapCalls(destinationSwapData) {
59
+ const { tokenToApprove, amountToApprove, spender, calls } = destinationSwapData;
22
60
  if (calls.some((call) => !call.to || !call.calldata)) {
23
61
  throw new Error('Invalid call data');
24
62
  }
@@ -40,9 +78,7 @@ export function createAcrossSwapMessage(multicallHandlerAddress, tokenToApprove,
40
78
  callData: call.calldata,
41
79
  value: BigInt(call.value ?? 0n),
42
80
  }));
43
- const drainCalls = createDrainCalls(multicallHandlerAddress, fallbackAndDrainAddress, tokensToDrain);
44
- const allCalls = [approveCall, ...middleCalls, ...drainCalls];
45
- return createAcrossMultiCallMessage(allCalls, fallbackAndDrainAddress);
81
+ return [approveCall, ...middleCalls];
46
82
  }
47
83
  export function createAcrossDrainMessage(multicallHandlerAddress, fallbackAndDrainAddress, tokensToDrain) {
48
84
  const drainCalls = createDrainCalls(multicallHandlerAddress, fallbackAndDrainAddress, tokensToDrain);
@@ -1,6 +1,6 @@
1
1
  import { GenericTrade, RawCurrency, useGeneralPricesCallbackType } from '@1delta/lib-utils';
2
- import { BaseAxelarComposedInput } from '../../types';
3
- export interface AxelarWithSwapInput extends BaseAxelarComposedInput {
2
+ import { BaseComposedWithGasLimitInput } from '../../types';
3
+ export interface AxelarWithSwapInput extends BaseComposedWithGasLimitInput {
4
4
  bridgeToCurrency: RawCurrency | undefined;
5
5
  }
6
6
  export declare const fetchAxelarTradeWithSwap: (input: AxelarWithSwapInput, getPrices: useGeneralPricesCallbackType, controller?: AbortController) => Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"axelarWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwap.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EAGZ,WAAW,EAEX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAEL,uBAAuB,EAExB,MAAM,aAAa,CAAA;AAKpB,MAAM,WAAW,mBAAoB,SAAQ,uBAAuB;IAClE,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAA;CAC1C;AAED,eAAO,MAAM,wBAAwB,GACnC,OAAO,mBAAmB,EAC1B,WAAW,4BAA4B,EACvC,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,CA8CA,CAAA;AAED,eAAe,wBAAwB,CAAA"}
1
+ {"version":3,"file":"axelarWithSwap.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwap.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,YAAY,EAGZ,WAAW,EAEX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,6BAA6B,EAC9B,MAAM,aAAa,CAAA;AASpB,MAAM,WAAW,mBAAoB,SAAQ,6BAA6B;IACxE,gBAAgB,EAAE,WAAW,GAAG,SAAS,CAAA;CAC1C;AAED,eAAO,MAAM,wBAAwB,GACnC,OAAO,mBAAmB,EAC1B,WAAW,4BAA4B,EACvC,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,CA8CA,CAAA;AAED,eAAe,wBAAwB,CAAA"}
@@ -3,6 +3,7 @@ import { CurrencyHandler, normalizeDecimals, TradeType, } from '@1delta/lib-util
3
3
  import { fetchBridgeTrade } from '../../bridge/fetchBridgeTrade';
4
4
  import { fetchBridgeAndGasTrade } from '../utils/fetchBridgeAndGasTrade';
5
5
  import { fetchBestTrade } from '../utils/multichainUtils';
6
+ import { ADDITIONAL_CALLS_GAS_LIMIT, DESTINATION_SWAP_GAS_LIMIT, } from './constants';
6
7
  import { createSquidDestinationPayload } from './squid/createSquidPayload';
7
8
  export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) => {
8
9
  if (!input.bridgeToCurrency)
@@ -11,7 +12,7 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
11
12
  throw new Error('ToCurrency undefined');
12
13
  const toChainId = input.toCurrency.chainId;
13
14
  const toTokenIsBridgeToken = CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
14
- const needDestinationCalls = (input.additionalCalls?.length ?? 0) > 0 || !toTokenIsBridgeToken;
15
+ const needDestinationCalls = (input.additionalCalls?.calls.length ?? 0) > 0 || !toTokenIsBridgeToken;
15
16
  const squidRouter = await getRequiredSquidRouter(toChainId);
16
17
  if (!needDestinationCalls) {
17
18
  // direct case
@@ -45,7 +46,9 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
45
46
  throw new Error('BridgeToCurrency undefined');
46
47
  const toChainId = input.toCurrency.chainId;
47
48
  const squidMulticall = await getRequiredSquidMulticaller(toChainId);
48
- const additionalCalls = input.additionalCalls ?? [];
49
+ const additionalCallsGasLimit = input.additionalCalls?.gasLimit ?? ADDITIONAL_CALLS_GAS_LIMIT;
50
+ const additionalCalls = input.additionalCalls?.calls ?? [];
51
+ const needsAdditionalCalls = additionalCalls.length > 0;
49
52
  const needsSwap = !CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
50
53
  const fetchSwapAndMessage = async (amount) => {
51
54
  if (needsSwap) {
@@ -68,21 +71,21 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
68
71
  const tx = await destinationSwapTrade.assemble();
69
72
  if (!tx?.EVM)
70
73
  return undefined;
71
- const message = createSquidDestinationPayload(input.receiver, [
72
- destinationSwapTrade.inputAmount.currency.address,
73
- destinationSwapTrade.outputAmount.currency.address,
74
- ], additionalCalls, {
74
+ const message = createSquidDestinationPayload(toChainId, destinationSwapTrade.inputAmount.currency.address, destinationSwapTrade.outputAmount.currency.address, input.receiver, additionalCalls, {
75
75
  tokenToApprove: destinationSwapTrade.inputAmount.currency.address,
76
76
  amountToApprove: destinationSwapTrade.inputAmount.amount,
77
77
  spender: destinationSwapTrade.target,
78
78
  calls: [tx.EVM],
79
79
  });
80
- return { message, destinationSwapTrade };
80
+ const gasLimit = DESTINATION_SWAP_GAS_LIMIT +
81
+ (needsAdditionalCalls ? additionalCallsGasLimit : 0n);
82
+ return { message, destinationSwapTrade, gasLimit };
81
83
  }
82
- else if (additionalCalls.length > 0) {
84
+ else if (needsAdditionalCalls) {
83
85
  // Handle only destination calls case
84
- const message = createSquidDestinationPayload(input.receiver, [input.bridgeToCurrency.address], additionalCalls);
85
- return { message, destinationSwapTrade: undefined };
86
+ const message = createSquidDestinationPayload(toChainId, undefined, input.bridgeToCurrency.address, input.receiver, additionalCalls);
87
+ const gasLimit = additionalCallsGasLimit;
88
+ return { message, destinationSwapTrade: undefined, gasLimit };
86
89
  }
87
90
  return undefined;
88
91
  };
@@ -94,7 +97,7 @@ const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller
94
97
  ...input,
95
98
  toCurrency: input.bridgeToCurrency,
96
99
  message: swap.message,
97
- destinationGasLimit: 1000000n,
100
+ destinationGasLimit: swap.gasLimit,
98
101
  };
99
102
  const bridgeAndGasTrade = await fetchBridgeAndGasTrade(Bridge.AXELAR, axelarInput, getPrices, controller);
100
103
  if (!bridgeAndGasTrade)
@@ -1,5 +1,5 @@
1
1
  import { GenericTrade, RawCurrency, useGeneralPricesCallbackType } from '@1delta/lib-utils';
2
- import { BaseAxelarComposedInput } from '../../types';
3
- export declare const fetchAxelarTradeWithSwaps: (input: BaseAxelarComposedInput, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency | undefined, getPrices: useGeneralPricesCallbackType, controller?: AbortController) => Promise<GenericTrade | undefined>;
2
+ import { BaseComposedWithGasLimitInput } from '../../types';
3
+ export declare const fetchAxelarTradeWithSwaps: (input: BaseComposedWithGasLimitInput, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency | undefined, getPrices: useGeneralPricesCallbackType, 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,EAMZ,WAAW,EAGX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAmB,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAmBtE,eAAO,MAAM,yBAAyB,GACpC,OAAO,uBAAuB,EAC9B,aAAa,CACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,GAAG,SAAS,KAC7B,WAAW,GAAG,SAAS,EAC5B,WAAW,4BAA4B,EACvC,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CA8JlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
1
+ {"version":3,"file":"axelarWithSwaps.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/axelarWithSwaps.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,YAAY,EAMZ,WAAW,EAGX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAmB,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAmB5E,eAAO,MAAM,yBAAyB,GACpC,OAAO,6BAA6B,EACpC,aAAa,CACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,GAAG,SAAS,KAC7B,WAAW,GAAG,SAAS,EAC5B,WAAW,4BAA4B,EACvC,aAAa,eAAe,KAC3B,OAAO,CAAC,YAAY,GAAG,SAAS,CA8JlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
@@ -1,4 +1,4 @@
1
- import { convertRawAmount } from '@1delta/aggregators';
1
+ import { convertRawAmount } from '@1delta/lib-utils';
2
2
  import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, splitSlippage, TradeType, } from '@1delta/lib-utils';
3
3
  import { fetchBestTrade, increaseAmountBySlippage } from '../utils';
4
4
  import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
@@ -6,4 +6,6 @@ export declare enum AxelarTokenSymbol {
6
6
  axlWBTC = "wbtc-satoshi",
7
7
  axlETH = "weth-wei"
8
8
  }
9
+ export declare const DESTINATION_SWAP_GAS_LIMIT = 2000000n;
10
+ export declare const ADDITIONAL_CALLS_GAS_LIMIT = 1000000n;
9
11
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,OAAO,UAAU;IACjB,GAAG,SAAS;IACZ,MAAM,YAAY;IAClB,OAAO,UAAU;IACjB,OAAO,iBAAiB;IACxB,MAAM,aAAa;CACpB"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/axelar/constants.ts"],"names":[],"mappings":"AAAA,oBAAY,iBAAiB;IAC3B,OAAO,UAAU;IACjB,GAAG,SAAS;IACZ,MAAM,YAAY;IAClB,OAAO,UAAU;IACjB,OAAO,iBAAiB;IACxB,MAAM,aAAa;CACpB;AAED,eAAO,MAAM,0BAA0B,WAAa,CAAA;AAEpD,eAAO,MAAM,0BAA0B,WAAa,CAAA"}
@@ -7,3 +7,5 @@ export var AxelarTokenSymbol;
7
7
  AxelarTokenSymbol["axlWBTC"] = "wbtc-satoshi";
8
8
  AxelarTokenSymbol["axlETH"] = "weth-wei";
9
9
  })(AxelarTokenSymbol || (AxelarTokenSymbol = {}));
10
+ export const DESTINATION_SWAP_GAS_LIMIT = 2000000n;
11
+ export const ADDITIONAL_CALLS_GAS_LIMIT = 1000000n;
@@ -1,30 +1,28 @@
1
- import { EvmGenericCallInfo } from '@1delta/lib-utils';
2
1
  import { Hex } from 'viem';
3
- import { SimpleSquidCall } from './types';
2
+ import { DeltaCall } from '../../../types/deltaCall';
3
+ import { DestinationSwapData } from '../../../types/destinationSwapData';
4
4
  /**
5
- * Creates the final `payload` for a complete "Approve -> Execute -> Drain" sequence
6
- * using the Squid multicaller.
5
+ * Creates the final `payload` for a complete cross-chain swap using Squid.
7
6
  *
8
- * This is a high-level helper that orchestrates the entire flow:
9
- * 1. **TransferFrom** pull funds from caller to SquidMulticaller.
10
- * 1. **Approves** an ERC20 token for a spender.
11
- * 2. **Executes** a series of one or more "middle" calls (e.g., a swap).
12
- * 3. **Drains** the resulting tokens from the multicall contract back to a specified address.
7
+ * This function supports two main flows:
13
8
  *
14
- * @param tokenToApprove - The address of the ERC20 token to approve (the input token).
15
- * @param amountToApprove - The amount of the token to approve.
16
- * @param spender - The address that will spend the approved token (e.g., a DEX router).
17
- * @param calls - An array of generic call objects to execute after approval.
18
- * @param refundAndDrainAddress - The single address that serves as both the refund recipient (safety net) and the destination for the drained tokens.
19
- * @param tokensToDrain - An array of ERC20 token addresses expected as output from the middle calls.
20
- * @returns The final, ABI-encoded `payload` as a hex string (`Hex`).
9
+ * 1. **Normal Flow** (when no additional calls are provided):
10
+ * - Executes swap calls if destination swap data is provided
11
+ * - Drains all relevant tokens (input and output) to the refundAndDrainAddress
12
+ *
13
+ * 2. **Composer Flow** (when additional calls are provided):
14
+ * - Executes swap calls if destination swap data is provided
15
+ * - Drains input token (if any) to refundAndDrainAddress
16
+ * - Drains output token to the Delta Forwarder contract
17
+ * - Creates and appends a Delta Composer call to execute additional operations
18
+ *
19
+ * @param chainId - The ID of the destination chain
20
+ * @param inputToken - The address of the input token (optional)
21
+ * @param outputToken - The address of the output token
22
+ * @param refundAndDrainAddress - The address that receives refunds and drained tokens
23
+ * @param additionalCalls - Optional array of DeltaCall objects for the composer flow
24
+ * @param destinationSwapData - Optional swap data for destination chain swaps
25
+ * @returns The final, ABI-encoded `payload` as a hex string (`Hex`)
21
26
  */
22
- export declare function createSquidDestinationPayload(refundAndDrainAddress: string, tokensToDrain: string[], additionalCalls: SimpleSquidCall[], destinationSwapData?: DestinationSwapData): Hex;
23
- interface DestinationSwapData {
24
- tokenToApprove: string;
25
- amountToApprove: bigint;
26
- spender: string;
27
- calls: EvmGenericCallInfo[];
28
- }
29
- export {};
27
+ export declare function createSquidDestinationPayload(chainId: string, inputToken: string | undefined, outputToken: string, refundAndDrainAddress: string, additionalCalls: DeltaCall[], destinationSwapData?: DestinationSwapData): Hex;
30
28
  //# sourceMappingURL=createSquidPayload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createSquidPayload.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/createSquidPayload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAA+B,GAAG,EAAyB,MAAM,MAAM,CAAA;AAG9E,OAAO,EAAE,eAAe,EAAuB,MAAM,SAAS,CAAA;AAsD9D;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAC3C,qBAAqB,EAAE,MAAM,EAC7B,aAAa,EAAE,MAAM,EAAE,EACvB,eAAe,EAAE,eAAe,EAAE,EAClC,mBAAmB,CAAC,EAAE,mBAAmB,GACxC,GAAG,CAYL;AAED,UAAU,mBAAmB;IAC3B,cAAc,EAAE,MAAM,CAAA;IACtB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,kBAAkB,EAAE,CAAA;CAC5B"}
1
+ {"version":3,"file":"createSquidPayload.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/createSquidPayload.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,GAAG,EAAyB,MAAM,MAAM,CAAA;AAG9E,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,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,5 +1,8 @@
1
1
  import { createSquidPayload } from '@1delta/bridge-configs';
2
+ import { CurrencyHandler } from '@1delta/lib-utils';
2
3
  import { encodeFunctionData, parseAbi, zeroAddress } from 'viem';
4
+ import { createDeltaCallsCalldata } from '../../../deltaCall/createDeltaCallsCalldata';
5
+ import { requireDeltaContracts } from '../../utils/requireDeltaContracts';
3
6
  import { toSquidCall } from './simpleSquidCall';
4
7
  import { SimpleSquidCallType } from './types';
5
8
  /**
@@ -44,35 +47,69 @@ function createSquidDrainCalls(receiverAddress, tokensToDrain) {
44
47
  return drainCalls;
45
48
  }
46
49
  /**
47
- * Creates the final `payload` for a complete "Approve -> Execute -> Drain" sequence
48
- * using the Squid multicaller.
50
+ * Creates the final `payload` for a complete cross-chain swap using Squid.
49
51
  *
50
- * This is a high-level helper that orchestrates the entire flow:
51
- * 1. **TransferFrom** pull funds from caller to SquidMulticaller.
52
- * 1. **Approves** an ERC20 token for a spender.
53
- * 2. **Executes** a series of one or more "middle" calls (e.g., a swap).
54
- * 3. **Drains** the resulting tokens from the multicall contract back to a specified address.
52
+ * This function supports two main flows:
55
53
  *
56
- * @param tokenToApprove - The address of the ERC20 token to approve (the input token).
57
- * @param amountToApprove - The amount of the token to approve.
58
- * @param spender - The address that will spend the approved token (e.g., a DEX router).
59
- * @param calls - An array of generic call objects to execute after approval.
60
- * @param refundAndDrainAddress - The single address that serves as both the refund recipient (safety net) and the destination for the drained tokens.
61
- * @param tokensToDrain - An array of ERC20 token addresses expected as output from the middle calls.
62
- * @returns The final, ABI-encoded `payload` as a hex string (`Hex`).
54
+ * 1. **Normal Flow** (when no additional calls are provided):
55
+ * - Executes swap calls if destination swap data is provided
56
+ * - Drains all relevant tokens (input and output) to the refundAndDrainAddress
57
+ *
58
+ * 2. **Composer Flow** (when additional calls are provided):
59
+ * - Executes swap calls if destination swap data is provided
60
+ * - Drains input token (if any) to refundAndDrainAddress
61
+ * - Drains output token to the Delta Forwarder contract
62
+ * - Creates and appends a Delta Composer call to execute additional operations
63
+ *
64
+ * @param chainId - The ID of the destination chain
65
+ * @param inputToken - The address of the input token (optional)
66
+ * @param outputToken - The address of the output token
67
+ * @param refundAndDrainAddress - The address that receives refunds and drained tokens
68
+ * @param additionalCalls - Optional array of DeltaCall objects for the composer flow
69
+ * @param destinationSwapData - Optional swap data for destination chain swaps
70
+ * @returns The final, ABI-encoded `payload` as a hex string (`Hex`)
63
71
  */
64
- export function createSquidDestinationPayload(refundAndDrainAddress, tokensToDrain, additionalCalls, destinationSwapData) {
72
+ export function createSquidDestinationPayload(chainId, inputToken, outputToken, refundAndDrainAddress, additionalCalls, destinationSwapData) {
65
73
  const swapCalls = destinationSwapData
66
74
  ? createSquidSwapCalls(destinationSwapData)
67
75
  : [];
68
- const drainCalls = createSquidDrainCalls(refundAndDrainAddress, tokensToDrain);
69
- const allCalls = [...swapCalls, ...additionalCalls, ...drainCalls];
70
- const allSquidCalls = allCalls.map((call) => toSquidCall(call));
71
- return createSquidPayload(refundAndDrainAddress, allSquidCalls);
76
+ if (additionalCalls.length === 0) {
77
+ // normal case: do calls and sweep to user
78
+ const tokensToDrain = inputToken ? [inputToken, outputToken] : [outputToken];
79
+ const drainCalls = createSquidDrainCalls(refundAndDrainAddress, tokensToDrain);
80
+ const allCalls = [...swapCalls, ...drainCalls];
81
+ const allSquidCalls = allCalls.map((call) => toSquidCall(call));
82
+ return createSquidPayload(refundAndDrainAddress, allSquidCalls);
83
+ }
84
+ else {
85
+ // composer case: do calls and continue in composer
86
+ const { forwarder } = requireDeltaContracts(chainId);
87
+ const tokensToDrain = inputToken ? [inputToken] : [];
88
+ const drainToUserCall = createSquidDrainCalls(refundAndDrainAddress, tokensToDrain);
89
+ const drainToForwarder = CurrencyHandler.isNativeAddress(outputToken, chainId)
90
+ ? []
91
+ : createSquidDrainCalls(forwarder, [outputToken]);
92
+ const deltaComposerCall = createDeltaCallsCalldata(chainId, additionalCalls, {
93
+ tokensToSweep: [outputToken],
94
+ receiver: refundAndDrainAddress,
95
+ });
96
+ const callToComposer = {
97
+ callType: SimpleSquidCallType.FULL_NATIVE_BALANCE,
98
+ target: deltaComposerCall.to,
99
+ callData: deltaComposerCall.calldata,
100
+ };
101
+ const allCalls = [
102
+ ...swapCalls,
103
+ ...drainToUserCall,
104
+ ...drainToForwarder,
105
+ callToComposer,
106
+ ];
107
+ const allSquidCalls = allCalls.map((call) => toSquidCall(call));
108
+ return createSquidPayload(refundAndDrainAddress, allSquidCalls);
109
+ }
72
110
  }
73
111
  function createSquidSwapCalls(destinationSwapData) {
74
112
  const { tokenToApprove, amountToApprove, spender, calls } = destinationSwapData;
75
- console.log('Axelar destinationSwapData', destinationSwapData);
76
113
  if (calls.some((call) => !call.to || !call.calldata)) {
77
114
  throw new Error('Invalid call data');
78
115
  }
@@ -1,5 +1,5 @@
1
- import { convertRawAmount } from '@1delta/aggregators';
2
1
  import { Bridge } from '@1delta/bridge-configs';
2
+ import { convertRawAmount } from '@1delta/lib-utils';
3
3
  import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, nativeOnChain, splitSlippage, TradeType, } from '@1delta/lib-utils';
4
4
  import { fetchBridgeTrade } from '../../bridge';
5
5
  import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
@@ -0,0 +1,5 @@
1
+ export declare const requireDeltaContracts: (fromChainId: string) => {
2
+ forwarder: string;
3
+ composer: string;
4
+ };
5
+ //# sourceMappingURL=requireDeltaContracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requireDeltaContracts.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/requireDeltaContracts.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,GAAI,aAAa,MAAM;;;CAQxD,CAAA"}
@@ -0,0 +1,10 @@
1
+ import { getDeltaComposerProxyAddress, getForwarderAddress, } from '@1delta/lib-utils';
2
+ export const requireDeltaContracts = (fromChainId) => {
3
+ const forwarder = getForwarderAddress(fromChainId);
4
+ if (!forwarder)
5
+ throw new Error('Forwarder contract not found');
6
+ const composer = getDeltaComposerProxyAddress(fromChainId);
7
+ if (!composer)
8
+ throw new Error('Composer proxy contract not found');
9
+ return { forwarder, composer };
10
+ };
@@ -0,0 +1,10 @@
1
+ import { Address, Hex } from 'viem';
2
+ import { DeltaCall } from '../types/deltaCall';
3
+ export declare const createDeltaCallsCalldata: (chainId: string, calls: DeltaCall[], sweepProps?: {
4
+ tokensToSweep: string[];
5
+ receiver: string;
6
+ }) => {
7
+ calldata: Hex;
8
+ to: Address;
9
+ };
10
+ //# sourceMappingURL=createDeltaCallsCalldata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDeltaCallsCalldata.d.ts","sourceRoot":"","sources":["../../src/deltaCall/createDeltaCallsCalldata.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGnC,OAAO,EAAuB,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAInE,eAAO,MAAM,wBAAwB,GACnC,SAAS,MAAM,EACf,OAAO,SAAS,EAAE,EAClB,aAAa;IACX,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;CACjB,KACA;IACD,QAAQ,EAAE,GAAG,CAAA;IACb,EAAE,EAAE,OAAO,CAAA;CAuCZ,CAAA"}