@1delta/trade-sdk 0.1.0 → 0.1.2
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 +12 -9
- package/dist/aggregator/fetchAggregatorTrade.d.ts +1 -3
- package/dist/aggregator/fetchAggregatorTrade.d.ts.map +1 -1
- package/dist/aggregator/fetchAggregatorTrade.js +2 -1
- package/dist/bridge/fetchBridgeTrade.d.ts +2 -2
- package/dist/bridge/fetchBridgeTrade.d.ts.map +1 -1
- package/dist/composedTrades/across/acrossWithSwap.d.ts +2 -2
- package/dist/composedTrades/across/acrossWithSwap.d.ts.map +1 -1
- package/dist/composedTrades/across/acrossWithSwaps.d.ts +2 -2
- package/dist/composedTrades/across/acrossWithSwaps.d.ts.map +1 -1
- package/dist/composedTrades/axelar/axelarWithSwap.d.ts +2 -2
- package/dist/composedTrades/axelar/axelarWithSwap.d.ts.map +1 -1
- package/dist/composedTrades/axelar/axelarWithSwap.js +60 -34
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts +5 -0
- package/dist/composedTrades/axelar/axelarWithSwaps.d.ts.map +1 -0
- package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts +9 -1
- package/dist/composedTrades/axelar/squid/createSquidPayload.d.ts.map +1 -1
- package/dist/composedTrades/axelar/squid/createSquidPayload.js +24 -32
- package/dist/composedTrades/axelar/squid/simpleSquidCall.d.ts +3 -0
- package/dist/composedTrades/axelar/squid/simpleSquidCall.d.ts.map +1 -0
- package/dist/composedTrades/axelar/squid/simpleSquidCall.js +47 -0
- package/dist/composedTrades/axelar/squid/types.d.ts +27 -0
- package/dist/composedTrades/axelar/squid/types.d.ts.map +1 -1
- package/dist/composedTrades/axelar/squid/types.js +7 -0
- package/dist/composedTrades/gaszip/gaszipWithSwaps.d.ts +2 -2
- package/dist/composedTrades/gaszip/gaszipWithSwaps.d.ts.map +1 -1
- package/dist/composedTrades/index.d.ts +1 -1
- package/dist/composedTrades/index.js +1 -1
- package/dist/composedTrades/utils/fetchBridgeAndGasTrade.d.ts +2 -2
- package/dist/composedTrades/utils/fetchBridgeAndGasTrade.d.ts.map +1 -1
- package/dist/composedTrades/utils/multichainUtils.d.ts.map +1 -1
- package/dist/composedTrades/utils/multichainUtils.js +3 -3
- package/dist/core.d.ts +1 -2
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +6 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/types/bridgeInput.d.ts +16 -18
- package/dist/types/bridgeInput.d.ts.map +1 -1
- package/package.json +5 -5
- 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 → axelarWithSwaps.js} +0 -0
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ pnpm add @1delta/trade-sdk
|
|
|
18
18
|
## Basic Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
-
import { initialize, fetchBridgeTrade, fetchAggregatorTrade } from '@1delta/trade-sdk';
|
|
21
|
+
import { initialize, fetchBridgeTrade, fetchAggregatorTrade, Bridge } from '@1delta/trade-sdk';
|
|
22
22
|
import { WalletClient } from 'viem';
|
|
23
23
|
|
|
24
24
|
// Initialize the SDK
|
|
@@ -34,13 +34,16 @@ const walletClient: WalletClient = /* your wallet client */;
|
|
|
34
34
|
setWalletClient(walletClient);
|
|
35
35
|
|
|
36
36
|
// Fetch a bridge trade
|
|
37
|
-
const trade = await fetchBridgeTrade(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
const trade = await fetchBridgeTrade({
|
|
38
|
+
bridge: Bridge.ACROSS,
|
|
39
|
+
input: {
|
|
40
|
+
fromCurrency: fromToken,
|
|
41
|
+
toCurrency: toToken,
|
|
42
|
+
amount: '1000000000000000000', // 1.0 in wei
|
|
43
|
+
receiver: '0x...',
|
|
44
|
+
caller: '0x...',
|
|
45
|
+
slippage: 0.5, // 0.5%
|
|
46
|
+
}
|
|
44
47
|
});
|
|
45
48
|
```
|
|
46
49
|
|
|
@@ -54,7 +57,7 @@ Initializes the SDK with the given configuration.
|
|
|
54
57
|
|
|
55
58
|
Sets the wallet client for transaction signing.
|
|
56
59
|
|
|
57
|
-
### `fetchBridgeTrade(
|
|
60
|
+
### `fetchBridgeTrade(input: BridgeInput): Promise<GenericTrade>`
|
|
58
61
|
|
|
59
62
|
Fetches a bridge trade quote.
|
|
60
63
|
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from './fetchAggregatorTrade';
|
|
2
|
-
import { TradeAggregator } from '@1delta/aggregators';
|
|
3
|
-
import { Bridge } from '@1delta/bridge-configs';
|
|
4
2
|
import { AggregatorApiInput, GenericTrade, OneDeltaInput } from '@1delta/lib-utils';
|
|
5
|
-
export declare const fetchAggregatorTrade: (aggregator:
|
|
3
|
+
export declare const fetchAggregatorTrade: (aggregator: string, input: AggregatorApiInput | OneDeltaInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
6
4
|
//# sourceMappingURL=fetchAggregatorTrade.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchAggregatorTrade.d.ts","sourceRoot":"","sources":["../../src/aggregator/fetchAggregatorTrade.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,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;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,7 +1,8 @@
|
|
|
1
1
|
export * from './fetchAggregatorTrade';
|
|
2
|
-
import { fetchAggregatorTrade as fetchAggregatorTradeWithoutConfigs,
|
|
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';
|
|
5
6
|
export const fetchAggregatorTrade = async (aggregator, input, controller) => {
|
|
6
7
|
if (!getAvailableAggregators(input.chainId))
|
|
7
8
|
return undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Bridge } from '@1delta/bridge-configs';
|
|
2
2
|
import { GenericTrade } from '@1delta/lib-utils';
|
|
3
|
-
import {
|
|
4
|
-
export declare const fetchBridgeTrade: (bridge: Bridge, input:
|
|
3
|
+
import { BaseBridgeInput } from '../types';
|
|
4
|
+
export declare const fetchBridgeTrade: (bridge: Bridge, input: BaseBridgeInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
5
5
|
//# sourceMappingURL=fetchBridgeTrade.d.ts.map
|
|
@@ -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,
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
|
|
2
|
-
import {
|
|
3
|
-
export interface AcrossWithSwapInput extends
|
|
2
|
+
import { BaseBridgeInput } from '../../types';
|
|
3
|
+
export interface AcrossWithSwapInput extends BaseBridgeInput {
|
|
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,
|
|
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,5 +1,5 @@
|
|
|
1
1
|
import { GenericTrade, RawCurrency } from '@1delta/lib-utils';
|
|
2
|
-
import {
|
|
3
|
-
export declare const fetchAcrossTradeWithSwaps: (input:
|
|
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>;
|
|
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,
|
|
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,6 +1,6 @@
|
|
|
1
1
|
import { GenericTrade, RawCurrency, useGeneralPricesCallbackType } from '@1delta/lib-utils';
|
|
2
|
-
import {
|
|
3
|
-
export interface AxelarWithSwapInput extends
|
|
2
|
+
import { BaseAxelarComposedInput } from '../../types';
|
|
3
|
+
export interface AxelarWithSwapInput extends BaseAxelarComposedInput {
|
|
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,
|
|
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"}
|
|
@@ -3,7 +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 {
|
|
6
|
+
import { createSquidDestinationPayload } from './squid/createSquidPayload';
|
|
7
7
|
export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) => {
|
|
8
8
|
if (!input.bridgeToCurrency)
|
|
9
9
|
throw new Error('BridgeToCurrency undefined');
|
|
@@ -11,8 +11,9 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
|
|
|
11
11
|
throw new Error('ToCurrency undefined');
|
|
12
12
|
const toChainId = input.toCurrency.chainId;
|
|
13
13
|
const toTokenIsBridgeToken = CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
|
|
14
|
+
const needDestinationCalls = (input.additionalCalls?.length ?? 0) > 0 || !toTokenIsBridgeToken;
|
|
14
15
|
const squidRouter = await getRequiredSquidRouter(toChainId);
|
|
15
|
-
if (
|
|
16
|
+
if (!needDestinationCalls) {
|
|
16
17
|
// direct case
|
|
17
18
|
const message = createSquidPayload(input.receiver);
|
|
18
19
|
const bridgeAndGasTrade = await fetchBridgeAndGasTrade(Bridge.AXELAR, { ...input, message }, getPrices, controller);
|
|
@@ -23,8 +24,8 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
|
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
//
|
|
27
|
-
const bridgeAndGasTrade = await
|
|
27
|
+
// destination calls case
|
|
28
|
+
const bridgeAndGasTrade = await fetchAxelarTradeWithDestinationCalls(input, getPrices, controller);
|
|
28
29
|
return {
|
|
29
30
|
trade: bridgeAndGasTrade?.bridgeTrade,
|
|
30
31
|
gasTrade: bridgeAndGasTrade?.gasTrade,
|
|
@@ -33,7 +34,7 @@ export const fetchAxelarTradeWithSwap = async (input, getPrices, controller) =>
|
|
|
33
34
|
}
|
|
34
35
|
};
|
|
35
36
|
export default fetchAxelarTradeWithSwap;
|
|
36
|
-
const
|
|
37
|
+
const fetchAxelarTradeWithDestinationCalls = async (input, getPrices, controller) => {
|
|
37
38
|
if (!input.swapAmount)
|
|
38
39
|
throw new Error('Swap amount undefined');
|
|
39
40
|
if (!input.fromCurrency)
|
|
@@ -44,30 +45,46 @@ const fetchAxelarTradeWithDestinationSwap = async (input, getPrices, controller)
|
|
|
44
45
|
throw new Error('BridgeToCurrency undefined');
|
|
45
46
|
const toChainId = input.toCurrency.chainId;
|
|
46
47
|
const squidMulticall = await getRequiredSquidMulticaller(toChainId);
|
|
48
|
+
const additionalCalls = input.additionalCalls ?? [];
|
|
49
|
+
const needsSwap = !CurrencyHandler.equal(input.bridgeToCurrency, input.toCurrency);
|
|
47
50
|
const fetchSwapAndMessage = async (amount) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
if (needsSwap) {
|
|
52
|
+
// Handle destination swap case
|
|
53
|
+
const destinationSwapInput = {
|
|
54
|
+
chainId: toChainId,
|
|
55
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
56
|
+
fromCurrency: input.bridgeToCurrency,
|
|
57
|
+
toCurrency: input.toCurrency,
|
|
58
|
+
slippage: input.slippage,
|
|
59
|
+
swapAmount: amount.toString(),
|
|
60
|
+
txOrigin: squidMulticall,
|
|
61
|
+
caller: squidMulticall,
|
|
62
|
+
receiver: squidMulticall,
|
|
63
|
+
flashSwap: undefined,
|
|
64
|
+
};
|
|
65
|
+
const destinationSwapTrade = await fetchBestTrade(destinationSwapInput, controller);
|
|
66
|
+
if (!destinationSwapTrade || !destinationSwapTrade.assemble)
|
|
67
|
+
return undefined;
|
|
68
|
+
const tx = await destinationSwapTrade.assemble();
|
|
69
|
+
if (!tx?.EVM)
|
|
70
|
+
return undefined;
|
|
71
|
+
const message = createSquidDestinationPayload(input.receiver, [
|
|
72
|
+
destinationSwapTrade.inputAmount.currency.address,
|
|
73
|
+
destinationSwapTrade.outputAmount.currency.address,
|
|
74
|
+
], additionalCalls, {
|
|
75
|
+
tokenToApprove: destinationSwapTrade.inputAmount.currency.address,
|
|
76
|
+
amountToApprove: destinationSwapTrade.inputAmount.amount,
|
|
77
|
+
spender: destinationSwapTrade.target,
|
|
78
|
+
calls: [tx.EVM],
|
|
79
|
+
});
|
|
80
|
+
return { message, destinationSwapTrade };
|
|
81
|
+
}
|
|
82
|
+
else if (additionalCalls.length > 0) {
|
|
83
|
+
// Handle only destination calls case
|
|
84
|
+
const message = createSquidDestinationPayload(input.receiver, [input.bridgeToCurrency.address], additionalCalls);
|
|
85
|
+
return { message, destinationSwapTrade: undefined };
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
71
88
|
};
|
|
72
89
|
const destinationSwapAmount = normalizeDecimals(BigInt(input.swapAmount), input.fromCurrency.decimals, input.bridgeToCurrency.decimals);
|
|
73
90
|
const swap = await fetchSwapAndMessage(destinationSwapAmount);
|
|
@@ -83,9 +100,14 @@ const fetchAxelarTradeWithDestinationSwap = async (input, getPrices, controller)
|
|
|
83
100
|
if (!bridgeAndGasTrade)
|
|
84
101
|
return undefined;
|
|
85
102
|
const { bridgeTrade, gasTrade } = bridgeAndGasTrade;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
103
|
+
// Only update swap if we actually need a swap
|
|
104
|
+
let updatedSwap = swap;
|
|
105
|
+
if (needsSwap) {
|
|
106
|
+
const newSwap = await fetchSwapAndMessage(bridgeTrade.outputAmount.amount);
|
|
107
|
+
if (!newSwap)
|
|
108
|
+
return undefined;
|
|
109
|
+
updatedSwap = newSwap;
|
|
110
|
+
}
|
|
89
111
|
const updatedAxelarTrade = await fetchBridgeTrade(Bridge.AXELAR, { ...axelarInput, message: updatedSwap.message }, controller);
|
|
90
112
|
if (!updatedAxelarTrade)
|
|
91
113
|
return undefined;
|
|
@@ -98,9 +120,13 @@ const fetchAxelarTradeWithDestinationSwap = async (input, getPrices, controller)
|
|
|
98
120
|
};
|
|
99
121
|
const composedTrade = {
|
|
100
122
|
...updatedAxelarTrade,
|
|
101
|
-
outputAmount: updatedSwap.destinationSwapTrade
|
|
102
|
-
|
|
103
|
-
|
|
123
|
+
outputAmount: updatedSwap.destinationSwapTrade?.outputAmount ??
|
|
124
|
+
updatedAxelarTrade.outputAmount,
|
|
125
|
+
outputAmountRealized: updatedSwap.destinationSwapTrade?.outputAmountRealized ??
|
|
126
|
+
updatedAxelarTrade.outputAmountRealized,
|
|
127
|
+
stringified: updatedSwap.destinationSwapTrade
|
|
128
|
+
? `${updatedAxelarTrade?.stringified}-${updatedSwap.destinationSwapTrade.stringified}`
|
|
129
|
+
: updatedAxelarTrade.stringified,
|
|
104
130
|
refresh,
|
|
105
131
|
};
|
|
106
132
|
return { bridgeTrade: composedTrade, gasTrade };
|
|
@@ -0,0 +1,5 @@
|
|
|
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>;
|
|
4
|
+
export default fetchAxelarTradeWithSwaps;
|
|
5
|
+
//# sourceMappingURL=axelarWithSwaps.d.ts.map
|
|
@@ -0,0 +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,5 +1,6 @@
|
|
|
1
1
|
import { EvmGenericCallInfo } from '@1delta/lib-utils';
|
|
2
2
|
import { Hex } from 'viem';
|
|
3
|
+
import { SimpleSquidCall } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Creates the final `payload` for a complete "Approve -> Execute -> Drain" sequence
|
|
5
6
|
* using the Squid multicaller.
|
|
@@ -18,5 +19,12 @@ import { Hex } from 'viem';
|
|
|
18
19
|
* @param tokensToDrain - An array of ERC20 token addresses expected as output from the middle calls.
|
|
19
20
|
* @returns The final, ABI-encoded `payload` as a hex string (`Hex`).
|
|
20
21
|
*/
|
|
21
|
-
export declare function
|
|
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 {};
|
|
22
30
|
//# 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,
|
|
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,6 +1,7 @@
|
|
|
1
1
|
import { createSquidPayload } from '@1delta/bridge-configs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { encodeFunctionData, parseAbi, zeroAddress } from 'viem';
|
|
3
|
+
import { toSquidCall } from './simpleSquidCall';
|
|
4
|
+
import { SimpleSquidCallType } from './types';
|
|
4
5
|
/**
|
|
5
6
|
* [Helper] Creates the specific "drain" calls for the SquidMulticall contract.
|
|
6
7
|
*
|
|
@@ -10,22 +11,19 @@ import { SquidCallType } from './types';
|
|
|
10
11
|
*
|
|
11
12
|
* @param receiverAddress - The destination address for the drained tokens.
|
|
12
13
|
* @param tokensToDrain - An array of ERC20 token addresses to drain from the multicall contract.
|
|
13
|
-
* @returns An array of `
|
|
14
|
+
* @returns An array of `SimpleSquidCall` objects configured for draining.
|
|
14
15
|
*/
|
|
15
16
|
function createSquidDrainCalls(receiverAddress, tokensToDrain) {
|
|
16
17
|
const erc20TransferAbi = parseAbi([
|
|
17
18
|
'function transfer(address recipient, uint256 amount)',
|
|
18
19
|
]);
|
|
19
|
-
const fullTokenBalancePayloadAbi = parseAbiParameters('address, uint256');
|
|
20
20
|
const drainCalls = tokensToDrain.map((tokenToDrain) => {
|
|
21
21
|
const isNative = tokenToDrain === zeroAddress;
|
|
22
22
|
if (isNative) {
|
|
23
23
|
const nativeDrainCall = {
|
|
24
|
-
callType:
|
|
24
|
+
callType: SimpleSquidCallType.FULL_NATIVE_BALANCE,
|
|
25
25
|
target: receiverAddress,
|
|
26
|
-
value: 0n,
|
|
27
26
|
callData: '0x',
|
|
28
|
-
payload: '0x',
|
|
29
27
|
};
|
|
30
28
|
return nativeDrainCall;
|
|
31
29
|
}
|
|
@@ -34,16 +32,12 @@ function createSquidDrainCalls(receiverAddress, tokensToDrain) {
|
|
|
34
32
|
functionName: 'transfer',
|
|
35
33
|
args: [receiverAddress, 0n], // Amount is a placeholder
|
|
36
34
|
});
|
|
37
|
-
const specialPayload = encodeAbiParameters(fullTokenBalancePayloadAbi, [
|
|
38
|
-
tokenToDrain,
|
|
39
|
-
1n, // The `amount` is the parameter at index 1
|
|
40
|
-
]);
|
|
41
35
|
const drainCall = {
|
|
42
|
-
callType:
|
|
36
|
+
callType: SimpleSquidCallType.FULL_TOKEN_BALANCE,
|
|
43
37
|
target: tokenToDrain,
|
|
44
38
|
value: 0n,
|
|
45
39
|
callData: transferCalldata,
|
|
46
|
-
|
|
40
|
+
balanceOfInjectIndex: 1,
|
|
47
41
|
};
|
|
48
42
|
return drainCall;
|
|
49
43
|
});
|
|
@@ -67,17 +61,24 @@ function createSquidDrainCalls(receiverAddress, tokensToDrain) {
|
|
|
67
61
|
* @param tokensToDrain - An array of ERC20 token addresses expected as output from the middle calls.
|
|
68
62
|
* @returns The final, ABI-encoded `payload` as a hex string (`Hex`).
|
|
69
63
|
*/
|
|
70
|
-
export function
|
|
64
|
+
export function createSquidDestinationPayload(refundAndDrainAddress, tokensToDrain, additionalCalls, destinationSwapData) {
|
|
65
|
+
const swapCalls = destinationSwapData
|
|
66
|
+
? createSquidSwapCalls(destinationSwapData)
|
|
67
|
+
: [];
|
|
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);
|
|
72
|
+
}
|
|
73
|
+
function createSquidSwapCalls(destinationSwapData) {
|
|
74
|
+
const { tokenToApprove, amountToApprove, spender, calls } = destinationSwapData;
|
|
75
|
+
console.log('Axelar destinationSwapData', destinationSwapData);
|
|
71
76
|
if (calls.some((call) => !call.to || !call.calldata)) {
|
|
72
77
|
throw new Error('Invalid call data');
|
|
73
78
|
}
|
|
74
|
-
const tokenAddressPayload = encodeAbiParameters(parseAbiParameters('address'), [tokenToApprove]);
|
|
75
79
|
const transferFromCall = {
|
|
76
|
-
callType:
|
|
77
|
-
|
|
78
|
-
value: 0n,
|
|
79
|
-
callData: '0x',
|
|
80
|
-
payload: tokenAddressPayload,
|
|
80
|
+
callType: SimpleSquidCallType.COLLECT_TOKEN_BALANCE,
|
|
81
|
+
tokenAddress: tokenToApprove,
|
|
81
82
|
};
|
|
82
83
|
const erc20ApproveAbi = parseAbi([
|
|
83
84
|
'function approve(address spender, uint256 amount)',
|
|
@@ -88,25 +89,16 @@ export function createSquidSwapPayload(tokenToApprove, amountToApprove, spender,
|
|
|
88
89
|
args: [spender, amountToApprove],
|
|
89
90
|
});
|
|
90
91
|
const approveCall = {
|
|
91
|
-
callType:
|
|
92
|
+
callType: SimpleSquidCallType.DEFAULT,
|
|
92
93
|
target: tokenToApprove,
|
|
93
94
|
value: 0n,
|
|
94
95
|
callData: approveCalldata,
|
|
95
|
-
payload: '0x',
|
|
96
96
|
};
|
|
97
97
|
const middleCalls = calls.map((call) => ({
|
|
98
|
-
callType:
|
|
98
|
+
callType: SimpleSquidCallType.DEFAULT,
|
|
99
99
|
target: call.to,
|
|
100
100
|
callData: call.calldata,
|
|
101
101
|
value: BigInt(call.value ?? 0n),
|
|
102
|
-
payload: '0x',
|
|
103
102
|
}));
|
|
104
|
-
|
|
105
|
-
const allCalls = [
|
|
106
|
-
transferFromCall,
|
|
107
|
-
approveCall,
|
|
108
|
-
...middleCalls,
|
|
109
|
-
...drainCalls,
|
|
110
|
-
];
|
|
111
|
-
return createSquidPayload(refundAndDrainAddress, allCalls);
|
|
103
|
+
return [transferFromCall, approveCall, ...middleCalls];
|
|
112
104
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simpleSquidCall.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/simpleSquidCall.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,eAAe,EAEf,SAAS,EAEV,MAAM,SAAS,CAAA;AAEhB,wBAAgB,WAAW,CAAC,UAAU,EAAE,eAAe,GAAG,SAAS,CA4ClE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { encodeAbiParameters, parseAbiParameters, zeroAddress, } from 'viem';
|
|
2
|
+
import { SimpleSquidCallType, SquidCallType, } from './types';
|
|
3
|
+
export function toSquidCall(simpleCall) {
|
|
4
|
+
switch (simpleCall.callType) {
|
|
5
|
+
case SimpleSquidCallType.FULL_TOKEN_BALANCE: {
|
|
6
|
+
return {
|
|
7
|
+
callType: SquidCallType.FULL_TOKEN_BALANCE,
|
|
8
|
+
target: simpleCall.target,
|
|
9
|
+
value: simpleCall.value ?? 0n,
|
|
10
|
+
callData: simpleCall.callData,
|
|
11
|
+
payload: encodeAbiParameters(parseAbiParameters('address, uint256'), [
|
|
12
|
+
simpleCall.target,
|
|
13
|
+
BigInt(simpleCall.balanceOfInjectIndex),
|
|
14
|
+
]),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
case SimpleSquidCallType.FULL_NATIVE_BALANCE: {
|
|
18
|
+
return {
|
|
19
|
+
callType: SquidCallType.FULL_NATIVE_BALANCE,
|
|
20
|
+
target: simpleCall.target,
|
|
21
|
+
value: 0n,
|
|
22
|
+
callData: simpleCall.callData,
|
|
23
|
+
payload: '0x',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
case SimpleSquidCallType.COLLECT_TOKEN_BALANCE: {
|
|
27
|
+
return {
|
|
28
|
+
callType: SquidCallType.COLLECT_TOKEN_BALANCE,
|
|
29
|
+
target: zeroAddress,
|
|
30
|
+
value: 0n,
|
|
31
|
+
callData: '0x',
|
|
32
|
+
payload: encodeAbiParameters(parseAbiParameters('address'), [
|
|
33
|
+
simpleCall.tokenAddress,
|
|
34
|
+
]),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
default: {
|
|
38
|
+
return {
|
|
39
|
+
callType: SquidCallType.DEFAULT,
|
|
40
|
+
target: simpleCall.target,
|
|
41
|
+
value: simpleCall.value ?? 0n,
|
|
42
|
+
callData: simpleCall.callData,
|
|
43
|
+
payload: '0x',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -12,4 +12,31 @@ export interface SquidCall {
|
|
|
12
12
|
callData: Hex;
|
|
13
13
|
payload: Hex;
|
|
14
14
|
}
|
|
15
|
+
export declare enum SimpleSquidCallType {
|
|
16
|
+
DEFAULT = 0,
|
|
17
|
+
FULL_TOKEN_BALANCE = 1,
|
|
18
|
+
FULL_NATIVE_BALANCE = 2,
|
|
19
|
+
COLLECT_TOKEN_BALANCE = 3
|
|
20
|
+
}
|
|
21
|
+
interface BaseSquidCall {
|
|
22
|
+
target: string;
|
|
23
|
+
value?: bigint;
|
|
24
|
+
callData: Hex;
|
|
25
|
+
}
|
|
26
|
+
interface FullTokenBalanceSquidCall extends BaseSquidCall {
|
|
27
|
+
callType: SimpleSquidCallType.FULL_TOKEN_BALANCE;
|
|
28
|
+
balanceOfInjectIndex: number;
|
|
29
|
+
}
|
|
30
|
+
interface FullNativeBalanceSquidCall extends Omit<BaseSquidCall, 'value'> {
|
|
31
|
+
callType: SimpleSquidCallType.FULL_NATIVE_BALANCE;
|
|
32
|
+
}
|
|
33
|
+
interface CollectTokenBalanceSquidCall extends Omit<BaseSquidCall, 'target' | 'callData' | 'value'> {
|
|
34
|
+
callType: SimpleSquidCallType.COLLECT_TOKEN_BALANCE;
|
|
35
|
+
tokenAddress: string;
|
|
36
|
+
}
|
|
37
|
+
interface DefaultSquidCall extends BaseSquidCall {
|
|
38
|
+
callType: SimpleSquidCallType.DEFAULT;
|
|
39
|
+
}
|
|
40
|
+
export type SimpleSquidCall = FullTokenBalanceSquidCall | FullNativeBalanceSquidCall | CollectTokenBalanceSquidCall | DefaultSquidCall;
|
|
41
|
+
export {};
|
|
15
42
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAEnC,oBAAY,aAAa;IACvB,OAAO,IAAI;IACX,kBAAkB,IAAI;IACtB,mBAAmB,IAAI;IACvB,qBAAqB,IAAI;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,aAAa,CAAA;IACvB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,GAAG,CAAA;CACb"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/composedTrades/axelar/squid/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAEnC,oBAAY,aAAa;IACvB,OAAO,IAAI;IACX,kBAAkB,IAAI;IACtB,mBAAmB,IAAI;IACvB,qBAAqB,IAAI;CAC1B;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,aAAa,CAAA;IACvB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,GAAG,CAAA;CACb;AAED,oBAAY,mBAAmB;IAC7B,OAAO,IAAwB;IAC/B,kBAAkB,IAAmC;IACrD,mBAAmB,IAAoC;IACvD,qBAAqB,IAAsC;CAC5D;AAED,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,GAAG,CAAA;CACd;AAED,UAAU,yBAA0B,SAAQ,aAAa;IACvD,QAAQ,EAAE,mBAAmB,CAAC,kBAAkB,CAAA;IAChD,oBAAoB,EAAE,MAAM,CAAA;CAC7B;AAED,UAAU,0BAA2B,SAAQ,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC;IACvE,QAAQ,EAAE,mBAAmB,CAAC,mBAAmB,CAAA;CAClD;AAED,UAAU,4BACR,SAAQ,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;IAC5D,QAAQ,EAAE,mBAAmB,CAAC,qBAAqB,CAAA;IACnD,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,UAAU,gBAAiB,SAAQ,aAAa;IAC9C,QAAQ,EAAE,mBAAmB,CAAC,OAAO,CAAA;CACtC;AAED,MAAM,MAAM,eAAe,GACvB,yBAAyB,GACzB,0BAA0B,GAC1B,4BAA4B,GAC5B,gBAAgB,CAAA"}
|
|
@@ -5,3 +5,10 @@ export var SquidCallType;
|
|
|
5
5
|
SquidCallType[SquidCallType["FULL_NATIVE_BALANCE"] = 2] = "FULL_NATIVE_BALANCE";
|
|
6
6
|
SquidCallType[SquidCallType["COLLECT_TOKEN_BALANCE"] = 3] = "COLLECT_TOKEN_BALANCE";
|
|
7
7
|
})(SquidCallType || (SquidCallType = {}));
|
|
8
|
+
export var SimpleSquidCallType;
|
|
9
|
+
(function (SimpleSquidCallType) {
|
|
10
|
+
SimpleSquidCallType[SimpleSquidCallType["DEFAULT"] = 0] = "DEFAULT";
|
|
11
|
+
SimpleSquidCallType[SimpleSquidCallType["FULL_TOKEN_BALANCE"] = 1] = "FULL_TOKEN_BALANCE";
|
|
12
|
+
SimpleSquidCallType[SimpleSquidCallType["FULL_NATIVE_BALANCE"] = 2] = "FULL_NATIVE_BALANCE";
|
|
13
|
+
SimpleSquidCallType[SimpleSquidCallType["COLLECT_TOKEN_BALANCE"] = 3] = "COLLECT_TOKEN_BALANCE";
|
|
14
|
+
})(SimpleSquidCallType || (SimpleSquidCallType = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { GenericTrade } from '@1delta/lib-utils';
|
|
2
|
-
import {
|
|
3
|
-
export declare const fetchGaszipTradeWithSwaps: (input:
|
|
2
|
+
import { BaseBridgeInput } from '../../types';
|
|
3
|
+
export declare const fetchGaszipTradeWithSwaps: (input: BaseBridgeInput, controller?: AbortController) => Promise<GenericTrade | undefined>;
|
|
4
4
|
export default fetchGaszipTradeWithSwaps;
|
|
5
5
|
//# sourceMappingURL=gaszipWithSwaps.d.ts.map
|
|
@@ -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,
|
|
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,CAkJlC,CAAA;AAED,eAAe,yBAAyB,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Bridge } from '@1delta/bridge-configs';
|
|
2
2
|
import { GenericTrade, useGeneralPricesCallbackType } from '@1delta/lib-utils';
|
|
3
|
-
import {
|
|
4
|
-
export declare const fetchBridgeAndGasTrade: (aggregator: Bridge, input:
|
|
3
|
+
import { BaseBridgeInput } from '../../types';
|
|
4
|
+
export declare const fetchBridgeAndGasTrade: (aggregator: Bridge, input: BaseBridgeInput, getPrices: useGeneralPricesCallbackType, 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,EAEL,YAAY,EAEZ,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,
|
|
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,EAEL,YAAY,EAEZ,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAG7C,eAAO,MAAM,sBAAsB,GACjC,YAAY,MAAM,EAClB,OAAO,eAAe,EACtB,WAAW,4BAA4B,EACvC,aAAa,eAAe,KAC3B,OAAO,CACR;IAAE,WAAW,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAA;CAAE,GAAG,SAAS,CAwE9E,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multichainUtils.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/multichainUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"multichainUtils.d.ts","sourceRoot":"","sources":["../../../src/composedTrades/utils/multichainUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACZ,aAAa,EAEb,WAAW,EAEX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAK7C,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,YAAY,CAAA;IACzB,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAA;CACnC;AAWD,wBAAsB,cAAc,CAClC,KAAK,EAAE,eAAe,EACtB,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,YAAY,CAAC,CAyEvB;AAED,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,WAAW,EACvB,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,4BAA4B,EACvC,UAAU,CAAC,EAAE,eAAe,GAC3B,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAwCpC;AAID,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,MAAM,CAKR"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TradeAggregator } from '@1delta/aggregators';
|
|
2
2
|
import { devLog, PricePriority, TradeType, } from '@1delta/lib-utils';
|
|
3
|
+
import { fetchAggregatorTrade, getAvailableAggregators } from '../../aggregator';
|
|
3
4
|
import { reverseQuote } from '../../utils';
|
|
4
5
|
// --- Fetching Logic ---
|
|
5
|
-
const AGGREGATOR_TIMEOUT_MS =
|
|
6
|
+
const AGGREGATOR_TIMEOUT_MS = 750;
|
|
6
7
|
const PRIORITY_AGGREGATORS = [
|
|
7
8
|
TradeAggregator.Odos,
|
|
8
9
|
TradeAggregator.Kyberswap,
|
|
9
10
|
];
|
|
10
11
|
export async function fetchBestTrade(input, controller) {
|
|
11
12
|
const allAggregators = getAvailableAggregators(input.chainId).filter((aggregator) => aggregator !== TradeAggregator.Bebop &&
|
|
12
|
-
aggregator !== TradeAggregator.OneDelta &&
|
|
13
13
|
aggregator !== TradeAggregator.Wowmax);
|
|
14
14
|
const trades = [];
|
|
15
15
|
let timeout;
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Bridge } from '@1delta/bridge-configs';
|
|
2
1
|
import { GenericTrade, RawCurrency, useGeneralPricesCallbackType } from '@1delta/lib-utils';
|
|
3
2
|
import { BridgeInput } from './types';
|
|
4
|
-
export declare const fetchBridgeTrade: (
|
|
3
|
+
export declare const fetchBridgeTrade: (input: BridgeInput, getPrices: useGeneralPricesCallbackType, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency, controller: AbortController) => Promise<GenericTrade | undefined>;
|
|
5
4
|
//# sourceMappingURL=core.d.ts.map
|
package/dist/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,WAAW,EACX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAS1B,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAErC,eAAO,MAAM,gBAAgB,GAC3B,OAAO,WAAW,EAClB,WAAW,4BAA4B,EACvC,aAAa,CACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,YAAY,EAAE,MAAM,GAAG,SAAS,KAC7B,WAAW,EAChB,YAAY,eAAe,KAC1B,OAAO,CAAC,YAAY,GAAG,SAAS,CAiBlC,CAAA"}
|
package/dist/core.js
CHANGED
|
@@ -2,12 +2,13 @@ import { Bridge } from '@1delta/bridge-configs';
|
|
|
2
2
|
import { isProductionEnv } from '@1delta/lib-utils';
|
|
3
3
|
import { fetchBridgeTrade as fetchBridgeTradeInternal } from './bridge';
|
|
4
4
|
import { fetchAcrossTradeWithSwaps, fetchAxelarTradeWithSwaps, fetchGaszipTradeWithSwaps, } from './composedTrades';
|
|
5
|
-
export const fetchBridgeTrade = async (
|
|
5
|
+
export const fetchBridgeTrade = async (input, getPrices, getCurrency, controller) => {
|
|
6
|
+
const { bridge, input: internalInput } = input;
|
|
6
7
|
if (bridge === Bridge.ACROSS)
|
|
7
|
-
return fetchAcrossTradeWithSwaps(
|
|
8
|
+
return fetchAcrossTradeWithSwaps(internalInput, getCurrency, controller);
|
|
8
9
|
if (bridge === Bridge.AXELAR)
|
|
9
|
-
return fetchAxelarTradeWithSwaps(
|
|
10
|
+
return fetchAxelarTradeWithSwaps(internalInput, getCurrency, getPrices, controller);
|
|
10
11
|
if (bridge === Bridge.GASZIP && !isProductionEnv())
|
|
11
|
-
return fetchGaszipTradeWithSwaps(
|
|
12
|
-
return fetchBridgeTradeInternal(bridge,
|
|
12
|
+
return fetchGaszipTradeWithSwaps(internalInput, controller);
|
|
13
|
+
return fetchBridgeTradeInternal(bridge, internalInput, controller);
|
|
13
14
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export { fetchAggregatorTrade, getAvailableAggregators } from './aggregator';
|
|
2
2
|
export { fetchBridgeTrade as fetchBridgeTradeWithoutComposed } from './bridge';
|
|
3
|
+
export type { SimpleSquidCall, SimpleSquidCallType, } from './composedTrades/axelar/squid/types';
|
|
3
4
|
export * from './core';
|
|
4
5
|
export * from './initialize';
|
|
6
|
+
export type { BridgeInput } from './types';
|
|
5
7
|
export { TradeAggregator } from '@1delta/aggregators';
|
|
6
8
|
export { Bridge } from '@1delta/bridge-configs';
|
|
7
9
|
export { getStatus as getBridgeStatus } from '@1delta/bridge-core';
|
|
10
|
+
export type { useGeneralPricesCallbackType } from '@1delta/lib-utils';
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,gBAAgB,IAAI,+BAA+B,EAAE,MAAM,UAAU,CAAA;AAC9E,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAC5E,OAAO,EAAE,gBAAgB,IAAI,+BAA+B,EAAE,MAAM,UAAU,CAAA;AAC9E,YAAY,EACV,eAAe,EACf,mBAAmB,GACpB,MAAM,qCAAqC,CAAA;AAC5C,cAAc,QAAQ,CAAA;AACtB,cAAc,cAAc,CAAA;AAC5B,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAClE,YAAY,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
tradeType: TradeType;
|
|
6
|
-
fromCurrencies: RawCurrency[];
|
|
7
|
-
toCurrency: RawCurrency | undefined;
|
|
8
|
-
swapAmounts: string[];
|
|
9
|
-
caller: string;
|
|
10
|
-
receiver: string;
|
|
11
|
-
order: 'CHEAPEST' | 'FASTEST';
|
|
12
|
-
parsedAmount: RawCurrencyAmount | undefined;
|
|
13
|
-
usePermit?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export interface BridgeInput {
|
|
1
|
+
import { Bridge } from '@1delta/bridge-configs';
|
|
2
|
+
import { RawCurrency, TradeType } from '@1delta/lib-utils';
|
|
3
|
+
import { SimpleSquidCall } from '../composedTrades/axelar/squid/types';
|
|
4
|
+
export interface BaseBridgeInput {
|
|
16
5
|
slippage: number;
|
|
17
6
|
tradeType: TradeType;
|
|
18
7
|
fromCurrency: RawCurrency | undefined;
|
|
@@ -25,8 +14,17 @@ export interface BridgeInput {
|
|
|
25
14
|
usePermit?: boolean;
|
|
26
15
|
destinationGasLimit?: bigint;
|
|
27
16
|
}
|
|
28
|
-
export interface
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
export interface BaseAxelarComposedInput extends BaseBridgeInput {
|
|
18
|
+
additionalCalls?: SimpleSquidCall[];
|
|
19
|
+
}
|
|
20
|
+
interface AxelarComposedInput {
|
|
21
|
+
bridge: Bridge.AXELAR;
|
|
22
|
+
input: BaseAxelarComposedInput;
|
|
23
|
+
}
|
|
24
|
+
interface DefaultBridgeInput extends BaseBridgeInput {
|
|
25
|
+
bridge: Exclude<Bridge, Bridge.AXELAR>;
|
|
26
|
+
input: BaseBridgeInput;
|
|
31
27
|
}
|
|
28
|
+
export type BridgeInput = AxelarComposedInput | DefaultBridgeInput;
|
|
29
|
+
export {};
|
|
32
30
|
//# sourceMappingURL=bridgeInput.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridgeInput.d.ts","sourceRoot":"","sources":["../../src/types/bridgeInput.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bridgeInput.d.ts","sourceRoot":"","sources":["../../src/types/bridgeInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAA;AAEtE,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,EAAE,WAAW,GAAG,SAAS,CAAA;IACrC,UAAU,EAAE,WAAW,GAAG,SAAS,CAAA;IACnC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,UAAU,GAAG,SAAS,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,eAAe,CAAC,EAAE,eAAe,EAAE,CAAA;CACpC;AAED,UAAU,mBAAmB;IAC3B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAA;IACrB,KAAK,EAAE,uBAAuB,CAAA;CAC/B;AAED,UAAU,kBAAmB,SAAQ,eAAe;IAClD,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IACtC,KAAK,EAAE,eAAe,CAAA;CACvB;AAED,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,kBAAkB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1delta/trade-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "1Delta Trade SDK for handling cross-chain swaps and bridges",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"@1delta/calldatalib": "^0.0.42",
|
|
11
11
|
"viem": "^2.33.0",
|
|
12
12
|
"@1delta/data-sdk": "^0.0.8",
|
|
13
|
-
"@1delta/
|
|
14
|
-
"@1delta/
|
|
15
|
-
"@1delta/bridge-
|
|
16
|
-
"@1delta/lib-utils": "0.1.
|
|
13
|
+
"@1delta/bridge-configs": "0.1.2",
|
|
14
|
+
"@1delta/aggregators": "0.1.2",
|
|
15
|
+
"@1delta/bridge-core": "0.1.1",
|
|
16
|
+
"@1delta/lib-utils": "0.1.3"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^18.0.0",
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { GenericTrade, RawCurrency, useGeneralPricesCallbackType } from '@1delta/lib-utils';
|
|
2
|
-
import { BridgeInput } from '../../types';
|
|
3
|
-
export declare const fetchAxelarTradeWithSwaps: (input: BridgeInput, getCurrency: (chainId: string | undefined, tokenAddress: string | undefined) => RawCurrency | undefined, getPrices: useGeneralPricesCallbackType, 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,EAMZ,WAAW,EAGX,4BAA4B,EAC7B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAmB,WAAW,EAAE,MAAM,aAAa,CAAA;AAmB1D,eAAO,MAAM,yBAAyB,GACpC,OAAO,WAAW,EAClB,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"}
|
|
File without changes
|