@1delta/trade-sdk 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aggregator/fetchAggregatorTrade.d.ts.map +1 -1
- package/dist/aggregator/fetchAggregatorTrade.js +3 -1
- package/dist/composedTrades/across/acrossAdapter.d.ts +5 -0
- package/dist/composedTrades/across/acrossAdapter.d.ts.map +1 -0
- package/dist/composedTrades/across/acrossAdapter.js +44 -0
- package/dist/composedTrades/across/acrossRoutes.d.ts +1 -2
- package/dist/composedTrades/across/acrossRoutes.d.ts.map +1 -1
- package/dist/composedTrades/across/acrossWithSwap.integration.spec.d.ts +1 -0
- package/dist/composedTrades/across/acrossWithSwap.integration.spec.js +122 -116
- package/dist/composedTrades/axelar/axelarAdapter.d.ts +5 -0
- package/dist/composedTrades/axelar/axelarAdapter.d.ts.map +1 -0
- package/dist/composedTrades/axelar/axelarAdapter.js +38 -0
- package/dist/composedTrades/axelar/axelarRoutes.d.ts +1 -2
- package/dist/composedTrades/axelar/axelarRoutes.d.ts.map +1 -1
- package/dist/composedTrades/gaszip/gaszipAdapter.d.ts +9 -0
- package/dist/composedTrades/gaszip/gaszipAdapter.d.ts.map +1 -0
- package/dist/composedTrades/gaszip/gaszipAdapter.js +46 -0
- package/dist/composedTrades/general/composableBridgeAdapter.d.ts +9 -0
- package/dist/composedTrades/general/composableBridgeAdapter.d.ts.map +1 -0
- package/dist/composedTrades/general/composableBridgeAdapter.js +39 -0
- package/dist/composedTrades/general/composeBridgeTrade.d.ts +5 -0
- package/dist/composedTrades/general/composeBridgeTrade.d.ts.map +1 -0
- package/dist/composedTrades/general/composeBridgeTrade.js +106 -0
- package/dist/composedTrades/general/index.d.ts +3 -0
- package/dist/composedTrades/general/index.d.ts.map +1 -0
- package/dist/composedTrades/general/index.js +2 -0
- package/dist/composedTrades/index.d.ts +3 -3
- package/dist/composedTrades/index.d.ts.map +1 -1
- package/dist/composedTrades/index.js +40 -3
- package/dist/composedTrades/utils/createSwapAndBridgeCalldata.d.ts.map +1 -1
- package/dist/composedTrades/utils/index.d.ts +1 -0
- package/dist/composedTrades/utils/index.d.ts.map +1 -1
- package/dist/composedTrades/utils/index.js +1 -0
- package/dist/composedTrades/utils/validateContracts.d.ts +5 -0
- package/dist/composedTrades/utils/validateContracts.d.ts.map +1 -0
- package/dist/composedTrades/utils/validateContracts.js +11 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +1 -13
- package/dist/deltaCall/toComposerCall.d.ts.map +1 -1
- package/dist/deltaCall/toComposerCall.js +2 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/initialize.d.ts +2 -2
- package/dist/initialize.d.ts.map +1 -1
- package/dist/registry/currency.d.ts +1 -1
- package/dist/registry/currency.d.ts.map +1 -1
- package/dist/registry/currency.js +2 -1
- package/dist/registry/price.d.ts +1 -1
- package/dist/registry/price.d.ts.map +1 -1
- package/dist/registry/price.js +2 -1
- package/dist/tradeExecution/getStatusFromTrade.d.ts +20 -0
- package/dist/tradeExecution/getStatusFromTrade.d.ts.map +1 -0
- package/dist/tradeExecution/getStatusFromTrade.js +71 -0
- package/dist/tradeExecution/getTransactionData.d.ts +13 -0
- package/dist/tradeExecution/getTransactionData.d.ts.map +1 -0
- package/dist/tradeExecution/getTransactionData.js +50 -0
- package/dist/tradeExecution/index.d.ts +13 -0
- package/dist/tradeExecution/index.d.ts.map +1 -0
- package/dist/tradeExecution/index.js +150 -0
- package/dist/tradeExecution/isBridge.d.ts +3 -0
- package/dist/tradeExecution/isBridge.d.ts.map +1 -0
- package/dist/tradeExecution/isBridge.js +3 -0
- package/dist/tradeExecution/signData.d.ts +4 -0
- package/dist/tradeExecution/signData.d.ts.map +1 -0
- package/dist/tradeExecution/signData.js +21 -0
- package/dist/tradeExecution/trackTradeCompletion.d.ts +9 -0
- package/dist/tradeExecution/trackTradeCompletion.d.ts.map +1 -0
- package/dist/tradeExecution/trackTradeCompletion.js +75 -0
- package/dist/tradeExecution/types.d.ts +30 -0
- package/dist/tradeExecution/types.d.ts.map +1 -0
- package/dist/tradeExecution/types.js +1 -0
- package/dist/types/bridgeInput.d.ts +30 -19
- package/dist/types/bridgeInput.d.ts.map +1 -1
- package/dist/types/bridgeInput.js +1 -1
- package/dist/types/composedBridgeAdapter.d.ts +33 -0
- package/dist/types/composedBridgeAdapter.d.ts.map +1 -0
- package/dist/types/composedBridgeAdapter.js +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/package.json +4 -4
- package/dist/composedTrades/across/acrossWithSwaps.d.ts +0 -5
- package/dist/composedTrades/across/acrossWithSwaps.d.ts.map +0 -1
- package/dist/composedTrades/across/acrossWithSwaps.integration.spec.d.ts +0 -1
- package/dist/composedTrades/across/acrossWithSwaps.integration.spec.d.ts.map +0 -1
- package/dist/composedTrades/across/acrossWithSwaps.integration.spec.js +0 -110
- package/dist/composedTrades/across/acrossWithSwaps.js +0 -124
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts +0 -5
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts.map +0 -1
- package/dist/composedTrades/axelar/axelarWithSwaps.js +0 -126
- package/dist/composedTrades/gaszip/gaszipWithSwaps.d.ts +0 -5
- package/dist/composedTrades/gaszip/gaszipWithSwaps.d.ts.map +0 -1
- package/dist/composedTrades/gaszip/gaszipWithSwaps.js +0 -115
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { convertRawAmount } from '@1delta/lib-utils';
|
|
2
|
-
import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, nativeOnChain, splitSlippage, TradeType, } from '@1delta/lib-utils';
|
|
3
|
-
import { getCurrencyGetter } from '../../registry';
|
|
4
|
-
import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
|
|
5
|
-
import { fetchBestTrade, increaseAmountBySlippage, } from '../utils/multichainUtils';
|
|
6
|
-
import { fetchAcrossRoutes, selectAcrossRoute } from './acrossRoutes';
|
|
7
|
-
import fetchAcrossTradeWithSwap from './acrossWithSwap';
|
|
8
|
-
// Extract contract address validation
|
|
9
|
-
const validateContracts = (fromChainId) => {
|
|
10
|
-
const forwarder = getForwarderAddress(fromChainId);
|
|
11
|
-
if (!forwarder)
|
|
12
|
-
throw new Error('Forwarder contract not found');
|
|
13
|
-
const composer = getDeltaComposerProxyAddress(fromChainId);
|
|
14
|
-
if (!composer)
|
|
15
|
-
throw new Error('Composer proxy contract not found');
|
|
16
|
-
return { forwarder, composer };
|
|
17
|
-
};
|
|
18
|
-
const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
19
|
-
export const fetchAcrossTradeWithSwaps = async (input, controller) => {
|
|
20
|
-
if (!input.fromCurrency || !input.toCurrency)
|
|
21
|
-
return undefined;
|
|
22
|
-
if (input.tradeType === TradeType.EXACT_OUTPUT)
|
|
23
|
-
throw new Error('Exact-out not supported for composed Across trade!');
|
|
24
|
-
// use a dummy to make across quote without a user address
|
|
25
|
-
// IMPORTANT: block assemble in this case
|
|
26
|
-
const isDummy = !input.receiver || !input.caller;
|
|
27
|
-
let sourceSwapTrade = undefined;
|
|
28
|
-
const fromChainId = getSafeChainId(input.fromCurrency?.chainId);
|
|
29
|
-
const toChainId = getSafeChainId(input.toCurrency?.chainId);
|
|
30
|
-
const { forwarder, composer } = validateContracts(fromChainId);
|
|
31
|
-
const routes = await fetchAcrossRoutes(fromChainId, toChainId);
|
|
32
|
-
const acrossRoute = selectAcrossRoute(routes, input.fromCurrency, input.toCurrency);
|
|
33
|
-
if (!acrossRoute)
|
|
34
|
-
return undefined;
|
|
35
|
-
const getCurrency = getCurrencyGetter();
|
|
36
|
-
const fromAcrossCurrency = getCurrency(acrossRoute.originChainId.toString(), acrossRoute.originToken);
|
|
37
|
-
const toAcrossCurrency = getCurrency(acrossRoute.destinationChainId.toString(), acrossRoute.destinationToken);
|
|
38
|
-
const outputIsAcrossAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.toCurrency), toAcrossCurrency);
|
|
39
|
-
const inputIsAcrossAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.fromCurrency), fromAcrossCurrency);
|
|
40
|
-
const [swapSlippage, acrossSlippage] = splitSlippage(input.slippage, inputIsAcrossAsset, outputIsAcrossAsset);
|
|
41
|
-
if (!inputIsAcrossAsset) {
|
|
42
|
-
const sourceSwapInput = {
|
|
43
|
-
chainId: fromChainId,
|
|
44
|
-
tradeType: TradeType.EXACT_INPUT,
|
|
45
|
-
fromCurrency: input.fromCurrency,
|
|
46
|
-
toCurrency: fromAcrossCurrency,
|
|
47
|
-
slippage: swapSlippage,
|
|
48
|
-
swapAmount: input.swapAmount,
|
|
49
|
-
txOrigin: input.caller,
|
|
50
|
-
caller: forwarder,
|
|
51
|
-
receiver: forwarder,
|
|
52
|
-
flashSwap: undefined,
|
|
53
|
-
disableComposer: true,
|
|
54
|
-
};
|
|
55
|
-
sourceSwapTrade = await fetchBestTrade(sourceSwapInput, controller);
|
|
56
|
-
}
|
|
57
|
-
const acrossExtendedAmount = sourceSwapTrade
|
|
58
|
-
? minimumAmountOutFromTrade(sourceSwapTrade, sourceSwapTrade.slippage).amount.toString()
|
|
59
|
-
: input.swapAmount;
|
|
60
|
-
const acrossExtendedInput = {
|
|
61
|
-
...input,
|
|
62
|
-
caller: isDummy ? DUMMY_ADDRESS : input.caller, // placeholder addresses if we have no connection
|
|
63
|
-
receiver: isDummy ? DUMMY_ADDRESS : input.receiver,
|
|
64
|
-
slippage: acrossSlippage,
|
|
65
|
-
swapAmount: acrossExtendedAmount,
|
|
66
|
-
fromCurrency: acrossRoute.isNative
|
|
67
|
-
? nativeOnChain(acrossRoute.originChainId.toString())
|
|
68
|
-
: fromAcrossCurrency,
|
|
69
|
-
bridgeToCurrency: toAcrossCurrency,
|
|
70
|
-
};
|
|
71
|
-
const { trade: acrossTradeWithSwap, receiver: bridgeReceiver } = await fetchAcrossTradeWithSwap(acrossExtendedInput, controller);
|
|
72
|
-
if (!acrossTradeWithSwap)
|
|
73
|
-
return undefined;
|
|
74
|
-
const trades = sourceSwapTrade
|
|
75
|
-
? [sourceSwapTrade, acrossTradeWithSwap]
|
|
76
|
-
: [acrossTradeWithSwap];
|
|
77
|
-
const assemble = async () => {
|
|
78
|
-
// block assemble if no user address
|
|
79
|
-
if (isDummy)
|
|
80
|
-
return undefined;
|
|
81
|
-
// otherwise continue
|
|
82
|
-
const fundsToPull = [
|
|
83
|
-
{
|
|
84
|
-
address: input.fromCurrency.address,
|
|
85
|
-
amount: BigInt(input.swapAmount),
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, false, fundsToPull, false, false, input.preCalls);
|
|
89
|
-
return {
|
|
90
|
-
EVM: {
|
|
91
|
-
to,
|
|
92
|
-
calldata,
|
|
93
|
-
value: value.toString(),
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
const refresh = async (inputOverride) => {
|
|
98
|
-
const newAggregatorInput = {
|
|
99
|
-
...input,
|
|
100
|
-
slippage: inputOverride?.slippage ?? input.slippage,
|
|
101
|
-
};
|
|
102
|
-
return fetchAcrossTradeWithSwaps(newAggregatorInput);
|
|
103
|
-
};
|
|
104
|
-
const outputAmount = !!sourceSwapTrade
|
|
105
|
-
? increaseAmountBySlippage(acrossTradeWithSwap.outputAmount.amount, Number(swapSlippage))
|
|
106
|
-
: acrossTradeWithSwap.outputAmount.amount;
|
|
107
|
-
return {
|
|
108
|
-
...acrossTradeWithSwap,
|
|
109
|
-
inputAmount: sourceSwapTrade?.inputAmount ?? acrossTradeWithSwap.inputAmount,
|
|
110
|
-
inputAmountRealized: sourceSwapTrade?.inputAmountRealized ??
|
|
111
|
-
acrossTradeWithSwap.inputAmountRealized,
|
|
112
|
-
outputAmount: CurrencyHandler.fromRawAmount(acrossTradeWithSwap.outputAmount.currency, outputAmount),
|
|
113
|
-
outputAmountRealized: convertRawAmount(outputAmount, acrossTradeWithSwap.outputAmount.currency.decimals),
|
|
114
|
-
stringified: sourceSwapTrade
|
|
115
|
-
? `${sourceSwapTrade?.stringified}-${acrossTradeWithSwap.stringified}`
|
|
116
|
-
: acrossTradeWithSwap.stringified,
|
|
117
|
-
target: composer,
|
|
118
|
-
approvalTarget: composer,
|
|
119
|
-
slippage: input.slippage,
|
|
120
|
-
assemble,
|
|
121
|
-
refresh,
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
export default fetchAcrossTradeWithSwaps;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { GenericTrade } from '@1delta/lib-utils';
|
|
2
|
-
import { AxelarBaseInput } from '../../types';
|
|
3
|
-
export declare const fetchAxelarTradeWithSwaps: (input: AxelarBaseInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
|
-
export default fetchAxelarTradeWithSwaps;
|
|
5
|
-
//# sourceMappingURL=axelarWithSwaps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,126 +0,0 @@
|
|
|
1
|
-
import { convertRawAmount, nativeOnChain } from '@1delta/lib-utils';
|
|
2
|
-
import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, splitSlippage, TradeType, } from '@1delta/lib-utils';
|
|
3
|
-
import { getCurrencyGetter } from '../../registry';
|
|
4
|
-
import { fetchBestTrade, increaseAmountBySlippage } from '../utils';
|
|
5
|
-
import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
|
|
6
|
-
import { fetchAxelarRoute } from './axelarRoutes';
|
|
7
|
-
import fetchAxelarTradeWithSwap from './axelarWithSwap';
|
|
8
|
-
// Extract contract address validation
|
|
9
|
-
const validateContracts = (fromChainId) => {
|
|
10
|
-
const forwarder = getForwarderAddress(fromChainId);
|
|
11
|
-
if (!forwarder)
|
|
12
|
-
throw new Error('Forwarder contract not found');
|
|
13
|
-
const composer = getDeltaComposerProxyAddress(fromChainId);
|
|
14
|
-
if (!composer)
|
|
15
|
-
throw new Error('Composer proxy contract not found');
|
|
16
|
-
return { forwarder, composer };
|
|
17
|
-
};
|
|
18
|
-
const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
19
|
-
export const fetchAxelarTradeWithSwaps = async (input, controller) => {
|
|
20
|
-
if (!input.fromCurrency || !input.toCurrency)
|
|
21
|
-
return undefined;
|
|
22
|
-
if (input.tradeType === TradeType.EXACT_OUTPUT)
|
|
23
|
-
throw new Error('Exact-out not supported for composed Axelar trade!');
|
|
24
|
-
// use a dummy to make axelar quote without a user address
|
|
25
|
-
// IMPORTANT: block assemble in this case
|
|
26
|
-
const isDummy = !input.receiver || !input.caller;
|
|
27
|
-
let sourceSwapTrade = undefined;
|
|
28
|
-
const fromChainId = getSafeChainId(input.fromCurrency?.chainId);
|
|
29
|
-
const toChainId = getSafeChainId(input.toCurrency?.chainId);
|
|
30
|
-
const { forwarder, composer } = validateContracts(fromChainId);
|
|
31
|
-
const route = await fetchAxelarRoute(fromChainId, toChainId);
|
|
32
|
-
if (!route)
|
|
33
|
-
return undefined;
|
|
34
|
-
const getCurrency = getCurrencyGetter();
|
|
35
|
-
const fromBridgeCurrency = getCurrency(fromChainId, route.fromBridgeToken);
|
|
36
|
-
const toBridgeCurrency = getCurrency(toChainId, route.toBridgeToken);
|
|
37
|
-
const outputIsBridgeAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.toCurrency), toBridgeCurrency);
|
|
38
|
-
const inputIsBridgeAsset = CurrencyHandler.equal(CurrencyHandler.wrapped(input.fromCurrency), fromBridgeCurrency);
|
|
39
|
-
const [swapSlippage, bridgeSlippage] = splitSlippage(input.slippage, inputIsBridgeAsset, outputIsBridgeAsset);
|
|
40
|
-
if (!inputIsBridgeAsset) {
|
|
41
|
-
const sourceSwapInput = {
|
|
42
|
-
chainId: fromChainId,
|
|
43
|
-
tradeType: TradeType.EXACT_INPUT,
|
|
44
|
-
fromCurrency: input.fromCurrency,
|
|
45
|
-
toCurrency: fromBridgeCurrency,
|
|
46
|
-
slippage: swapSlippage,
|
|
47
|
-
swapAmount: input.swapAmount,
|
|
48
|
-
txOrigin: input.caller,
|
|
49
|
-
caller: forwarder,
|
|
50
|
-
receiver: forwarder,
|
|
51
|
-
flashSwap: undefined,
|
|
52
|
-
disableComposer: true,
|
|
53
|
-
};
|
|
54
|
-
sourceSwapTrade = await fetchBestTrade(sourceSwapInput, controller);
|
|
55
|
-
}
|
|
56
|
-
const bridgeExtendedAmount = sourceSwapTrade
|
|
57
|
-
? minimumAmountOutFromTrade(sourceSwapTrade, sourceSwapTrade.slippage).amount.toString()
|
|
58
|
-
: input.swapAmount;
|
|
59
|
-
const bridgeExtendedInput = {
|
|
60
|
-
...input,
|
|
61
|
-
slippage: bridgeSlippage,
|
|
62
|
-
swapAmount: bridgeExtendedAmount,
|
|
63
|
-
fromCurrency: fromBridgeCurrency,
|
|
64
|
-
bridgeToCurrency: toBridgeCurrency,
|
|
65
|
-
caller: forwarder,
|
|
66
|
-
receiver: isDummy ? DUMMY_ADDRESS : input.receiver,
|
|
67
|
-
};
|
|
68
|
-
const { trade: bridgeTradeWithSwap, gasTrade, receiver: bridgeReceiver, } = await fetchAxelarTradeWithSwap(bridgeExtendedInput, controller);
|
|
69
|
-
if (!bridgeTradeWithSwap)
|
|
70
|
-
return undefined;
|
|
71
|
-
const trades = [];
|
|
72
|
-
if (sourceSwapTrade)
|
|
73
|
-
trades.push(sourceSwapTrade);
|
|
74
|
-
if (gasTrade)
|
|
75
|
-
trades.push(gasTrade);
|
|
76
|
-
trades.push(bridgeTradeWithSwap);
|
|
77
|
-
const assemble = async () => {
|
|
78
|
-
if (isDummy)
|
|
79
|
-
return undefined;
|
|
80
|
-
const fundsToPull = [
|
|
81
|
-
{
|
|
82
|
-
address: input.fromCurrency.address,
|
|
83
|
-
amount: BigInt(input.swapAmount),
|
|
84
|
-
},
|
|
85
|
-
];
|
|
86
|
-
if (!gasTrade && bridgeTradeWithSwap.gasAmount) {
|
|
87
|
-
fundsToPull.push({
|
|
88
|
-
address: nativeOnChain(fromChainId).address,
|
|
89
|
-
amount: bridgeTradeWithSwap.gasAmount,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, bridgeReceiver, true, fundsToPull, false, true, input.preCalls);
|
|
93
|
-
return {
|
|
94
|
-
EVM: {
|
|
95
|
-
to,
|
|
96
|
-
calldata,
|
|
97
|
-
value: value.toString(),
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
const refresh = async (inputOverride) => {
|
|
102
|
-
const newAggregatorInput = {
|
|
103
|
-
...input,
|
|
104
|
-
slippage: inputOverride?.slippage ?? input.slippage,
|
|
105
|
-
};
|
|
106
|
-
return fetchAxelarTradeWithSwaps(newAggregatorInput);
|
|
107
|
-
};
|
|
108
|
-
const outputAmount = !!sourceSwapTrade
|
|
109
|
-
? increaseAmountBySlippage(bridgeTradeWithSwap.outputAmount.amount, Number(swapSlippage))
|
|
110
|
-
: bridgeTradeWithSwap.outputAmount.amount;
|
|
111
|
-
return {
|
|
112
|
-
...bridgeTradeWithSwap,
|
|
113
|
-
inputAmount: CurrencyHandler.fromRawAmount(input.fromCurrency, input.swapAmount),
|
|
114
|
-
inputAmountRealized: convertRawAmount(input.swapAmount, input.fromCurrency.decimals),
|
|
115
|
-
outputAmount: CurrencyHandler.fromRawAmount(bridgeTradeWithSwap.outputAmount.currency, outputAmount),
|
|
116
|
-
outputAmountRealized: convertRawAmount(outputAmount, bridgeTradeWithSwap.outputAmount.currency.decimals),
|
|
117
|
-
stringified: trades.map((t) => t.stringified).join('-'),
|
|
118
|
-
target: composer,
|
|
119
|
-
approvalTarget: composer,
|
|
120
|
-
slippage: input.slippage,
|
|
121
|
-
assemble,
|
|
122
|
-
refresh,
|
|
123
|
-
gasAmount: gasTrade ? undefined : bridgeTradeWithSwap.gasAmount,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
export default fetchAxelarTradeWithSwaps;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { GenericTrade } from '@1delta/lib-utils';
|
|
2
|
-
import { BaseBridgeInput } from '../../types';
|
|
3
|
-
export declare const fetchGaszipTradeWithSwaps: (input: BaseBridgeInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
|
-
export default fetchGaszipTradeWithSwaps;
|
|
5
|
-
//# sourceMappingURL=gaszipWithSwaps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,115 +0,0 @@
|
|
|
1
|
-
import { Bridge } from '@1delta/bridge-configs';
|
|
2
|
-
import { convertRawAmount } from '@1delta/lib-utils';
|
|
3
|
-
import { CurrencyHandler, getDeltaComposerProxyAddress, getForwarderAddress, getSafeChainId, minimumAmountOutFromTrade, nativeOnChain, splitSlippage, TradeType, } from '@1delta/lib-utils';
|
|
4
|
-
import { fetchBridgeTrade } from '../../bridge';
|
|
5
|
-
import { createSwapAndBridgeCalldata } from '../utils/createSwapAndBridgeCalldata';
|
|
6
|
-
import { fetchBestTrade, increaseAmountBySlippage, } from '../utils/multichainUtils';
|
|
7
|
-
// Extract contract address validation
|
|
8
|
-
const validateContracts = (fromChainId) => {
|
|
9
|
-
const forwarder = getForwarderAddress(fromChainId);
|
|
10
|
-
if (!forwarder)
|
|
11
|
-
throw new Error('Forwarder contract not found');
|
|
12
|
-
const composer = getDeltaComposerProxyAddress(fromChainId);
|
|
13
|
-
if (!composer)
|
|
14
|
-
throw new Error('Composer proxy contract not found');
|
|
15
|
-
return { forwarder, composer };
|
|
16
|
-
};
|
|
17
|
-
const DUMMY_ADDRESS = '0x0000000000000000000000000000000000000001';
|
|
18
|
-
export const fetchGaszipTradeWithSwaps = async (input, controller) => {
|
|
19
|
-
if (!input.fromCurrency || !input.toCurrency)
|
|
20
|
-
return undefined;
|
|
21
|
-
// if (input.tradeType === TradeType.EXACT_OUTPUT)
|
|
22
|
-
// throw new Error('Exact-out not supported for composed Gaszip trade!')
|
|
23
|
-
if (!CurrencyHandler.isNative(input.toCurrency))
|
|
24
|
-
throw new Error('Gaszip only supports Native as output token!');
|
|
25
|
-
// use a dummy to make gaszip quote without a user address
|
|
26
|
-
// IMPORTANT: block assemble in this case
|
|
27
|
-
const isDummy = !input.receiver || !input.caller;
|
|
28
|
-
let sourceSwapTrade = undefined;
|
|
29
|
-
const fromChainId = getSafeChainId(input.fromCurrency?.chainId);
|
|
30
|
-
const toChainId = getSafeChainId(input.toCurrency?.chainId);
|
|
31
|
-
const { forwarder, composer } = validateContracts(fromChainId);
|
|
32
|
-
const fromGaszipCurrency = nativeOnChain(fromChainId);
|
|
33
|
-
const toGaszipCurrency = nativeOnChain(toChainId);
|
|
34
|
-
const inputIsGaszipAsset = CurrencyHandler.equal(input.fromCurrency, fromGaszipCurrency);
|
|
35
|
-
const [swapSlippage, gaszipSlippage] = splitSlippage(input.slippage, inputIsGaszipAsset, true);
|
|
36
|
-
if (!inputIsGaszipAsset) {
|
|
37
|
-
const sourceSwapInput = {
|
|
38
|
-
chainId: fromChainId,
|
|
39
|
-
tradeType: TradeType.EXACT_INPUT,
|
|
40
|
-
fromCurrency: input.fromCurrency,
|
|
41
|
-
toCurrency: fromGaszipCurrency,
|
|
42
|
-
slippage: swapSlippage,
|
|
43
|
-
swapAmount: input.swapAmount,
|
|
44
|
-
txOrigin: input.caller,
|
|
45
|
-
caller: forwarder,
|
|
46
|
-
receiver: forwarder,
|
|
47
|
-
flashSwap: undefined,
|
|
48
|
-
disableComposer: true,
|
|
49
|
-
};
|
|
50
|
-
sourceSwapTrade = await fetchBestTrade(sourceSwapInput, controller);
|
|
51
|
-
}
|
|
52
|
-
const gaszipExtendedAmount = sourceSwapTrade
|
|
53
|
-
? minimumAmountOutFromTrade(sourceSwapTrade, sourceSwapTrade.slippage).amount.toString()
|
|
54
|
-
: input.swapAmount;
|
|
55
|
-
const gaszipInput = {
|
|
56
|
-
tradeType: TradeType.EXACT_INPUT,
|
|
57
|
-
caller: isDummy ? DUMMY_ADDRESS : input.caller,
|
|
58
|
-
receiver: isDummy ? DUMMY_ADDRESS : input.receiver,
|
|
59
|
-
slippage: gaszipSlippage,
|
|
60
|
-
swapAmount: gaszipExtendedAmount,
|
|
61
|
-
fromCurrency: fromGaszipCurrency,
|
|
62
|
-
toCurrency: toGaszipCurrency,
|
|
63
|
-
order: 'CHEAPEST',
|
|
64
|
-
};
|
|
65
|
-
const gaszipTrade = await fetchBridgeTrade(Bridge.GASZIP, gaszipInput, controller);
|
|
66
|
-
if (!gaszipTrade)
|
|
67
|
-
return undefined;
|
|
68
|
-
const trades = sourceSwapTrade
|
|
69
|
-
? [sourceSwapTrade, gaszipTrade]
|
|
70
|
-
: [gaszipTrade];
|
|
71
|
-
const assemble = async () => {
|
|
72
|
-
if (isDummy)
|
|
73
|
-
return undefined;
|
|
74
|
-
const fundsToPull = [
|
|
75
|
-
{
|
|
76
|
-
address: input.fromCurrency.address,
|
|
77
|
-
amount: BigInt(input.swapAmount),
|
|
78
|
-
},
|
|
79
|
-
];
|
|
80
|
-
const { calldata, value, to } = await createSwapAndBridgeCalldata(trades, input.caller, input.receiver, false, fundsToPull, false);
|
|
81
|
-
return {
|
|
82
|
-
EVM: {
|
|
83
|
-
to,
|
|
84
|
-
calldata,
|
|
85
|
-
value: value.toString(),
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
const refresh = async (inputOverride) => {
|
|
90
|
-
const newAggregatorInput = {
|
|
91
|
-
...input,
|
|
92
|
-
slippage: inputOverride?.slippage ?? input.slippage,
|
|
93
|
-
};
|
|
94
|
-
return fetchGaszipTradeWithSwaps(newAggregatorInput);
|
|
95
|
-
};
|
|
96
|
-
const outputAmount = !!sourceSwapTrade
|
|
97
|
-
? increaseAmountBySlippage(gaszipTrade.outputAmount.amount, Number(swapSlippage))
|
|
98
|
-
: gaszipTrade.outputAmount.amount;
|
|
99
|
-
return {
|
|
100
|
-
...gaszipTrade,
|
|
101
|
-
inputAmount: sourceSwapTrade?.inputAmount ?? gaszipTrade.inputAmount,
|
|
102
|
-
inputAmountRealized: sourceSwapTrade?.inputAmountRealized ?? gaszipTrade.inputAmountRealized,
|
|
103
|
-
outputAmount: CurrencyHandler.fromRawAmount(gaszipTrade.outputAmount.currency, outputAmount),
|
|
104
|
-
outputAmountRealized: convertRawAmount(outputAmount, gaszipTrade.outputAmount.currency.decimals),
|
|
105
|
-
stringified: sourceSwapTrade
|
|
106
|
-
? `${sourceSwapTrade?.stringified}-${gaszipTrade.stringified}`
|
|
107
|
-
: gaszipTrade.stringified,
|
|
108
|
-
target: composer,
|
|
109
|
-
approvalTarget: composer,
|
|
110
|
-
slippage: input.slippage,
|
|
111
|
-
assemble,
|
|
112
|
-
refresh,
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
export default fetchGaszipTradeWithSwaps;
|