@rabby-wallet/rabby-bridge 0.0.13 → 0.0.14-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -1
- package/dist/calldata/abi.d.ts +29 -0
- package/dist/calldata/abi.js +160 -0
- package/dist/calldata/across/deposit.d.ts +2 -0
- package/dist/calldata/across/deposit.js +36 -0
- package/dist/calldata/across/depositNative.d.ts +2 -0
- package/dist/calldata/across/depositNative.js +45 -0
- package/dist/calldata/across/depositNow.d.ts +2 -0
- package/dist/calldata/across/depositNow.js +35 -0
- package/dist/calldata/across/depositV3.d.ts +2 -0
- package/dist/calldata/across/depositV3.js +35 -0
- package/dist/calldata/across/depositV3Now.d.ts +2 -0
- package/dist/calldata/across/depositV3Now.js +34 -0
- package/dist/calldata/across/index.d.ts +4 -0
- package/dist/calldata/across/index.js +31 -0
- package/dist/calldata/across/swapAndBridge.d.ts +2 -0
- package/dist/calldata/across/swapAndBridge.js +70 -0
- package/dist/calldata/across/validate.d.ts +3 -0
- package/dist/calldata/across/validate.js +34 -0
- package/dist/calldata/chains.d.ts +2 -0
- package/dist/calldata/chains.js +36 -0
- package/dist/calldata/destination.d.ts +6 -0
- package/dist/calldata/destination.js +227 -0
- package/dist/calldata/destinationSwap.d.ts +14 -0
- package/dist/calldata/destinationSwap.js +83 -0
- package/dist/calldata/destinationUniswap.d.ts +7 -0
- package/dist/calldata/destinationUniswap.js +57 -0
- package/dist/calldata/diagnostics.d.ts +4 -0
- package/dist/calldata/diagnostics.js +18 -0
- package/dist/calldata/expect.d.ts +29 -0
- package/dist/calldata/expect.js +157 -0
- package/dist/calldata/hex.d.ts +6 -0
- package/dist/calldata/hex.js +46 -0
- package/dist/calldata/index.d.ts +20 -0
- package/dist/calldata/index.js +88 -0
- package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +2 -0
- package/dist/calldata/lifi/across/acrossV4Erc20Min.js +27 -0
- package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +2 -0
- package/dist/calldata/lifi/across/acrossV4NativeMin.js +23 -0
- package/dist/calldata/lifi/across/index.d.ts +6 -0
- package/dist/calldata/lifi/across/index.js +19 -0
- package/dist/calldata/lifi/allbridge/index.d.ts +3 -0
- package/dist/calldata/lifi/allbridge/index.js +26 -0
- package/dist/calldata/lifi/celer/index.d.ts +4 -0
- package/dist/calldata/lifi/celer/index.js +10 -0
- package/dist/calldata/lifi/centrifuge/index.d.ts +3 -0
- package/dist/calldata/lifi/centrifuge/index.js +22 -0
- package/dist/calldata/lifi/destination.d.ts +5 -0
- package/dist/calldata/lifi/destination.js +40 -0
- package/dist/calldata/lifi/frax/index.d.ts +4 -0
- package/dist/calldata/lifi/frax/index.js +29 -0
- package/dist/calldata/lifi/garden/index.d.ts +3 -0
- package/dist/calldata/lifi/garden/index.js +22 -0
- package/dist/calldata/lifi/gaszip/index.d.ts +6 -0
- package/dist/calldata/lifi/gaszip/index.js +15 -0
- package/dist/calldata/lifi/index.d.ts +4 -0
- package/dist/calldata/lifi/index.js +62 -0
- package/dist/calldata/lifi/intents/index.d.ts +4 -0
- package/dist/calldata/lifi/intents/index.js +10 -0
- package/dist/calldata/lifi/layerswap/index.d.ts +4 -0
- package/dist/calldata/lifi/layerswap/index.js +10 -0
- package/dist/calldata/lifi/m0/index.d.ts +3 -0
- package/dist/calldata/lifi/m0/index.js +33 -0
- package/dist/calldata/lifi/mayan/index.d.ts +4 -0
- package/dist/calldata/lifi/mayan/index.js +10 -0
- package/dist/calldata/lifi/method.d.ts +6 -0
- package/dist/calldata/lifi/method.js +16 -0
- package/dist/calldata/lifi/native/index.d.ts +4 -0
- package/dist/calldata/lifi/native/index.js +80 -0
- package/dist/calldata/lifi/params.d.ts +28 -0
- package/dist/calldata/lifi/params.js +349 -0
- package/dist/calldata/lifi/paxos/index.d.ts +4 -0
- package/dist/calldata/lifi/paxos/index.js +10 -0
- package/dist/calldata/lifi/polymer/index.d.ts +4 -0
- package/dist/calldata/lifi/polymer/index.js +10 -0
- package/dist/calldata/lifi/relay/index.d.ts +6 -0
- package/dist/calldata/lifi/relay/index.js +15 -0
- package/dist/calldata/lifi/shape.d.ts +4 -0
- package/dist/calldata/lifi/shape.js +31 -0
- package/dist/calldata/lifi/squid/index.d.ts +6 -0
- package/dist/calldata/lifi/squid/index.js +15 -0
- package/dist/calldata/lifi/stargate/index.d.ts +5 -0
- package/dist/calldata/lifi/stargate/index.js +15 -0
- package/dist/calldata/lifi/swap/index.d.ts +5 -0
- package/dist/calldata/lifi/swap/index.js +18 -0
- package/dist/calldata/lifi/swap/swapMethod.d.ts +2 -0
- package/dist/calldata/lifi/swap/swapMethod.js +40 -0
- package/dist/calldata/lifi/swapData.d.ts +5 -0
- package/dist/calldata/lifi/swapData.js +33 -0
- package/dist/calldata/match.d.ts +3 -0
- package/dist/calldata/match.js +21 -0
- package/dist/calldata/mayan/destination.d.ts +2 -0
- package/dist/calldata/mayan/destination.js +13 -0
- package/dist/calldata/mayan/fastMctpBridge.d.ts +3 -0
- package/dist/calldata/mayan/fastMctpBridge.js +48 -0
- package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +3 -0
- package/dist/calldata/mayan/fastMctpCreateOrder.js +39 -0
- package/dist/calldata/mayan/forward.d.ts +8 -0
- package/dist/calldata/mayan/forward.js +35 -0
- package/dist/calldata/mayan/forwardERC20.d.ts +2 -0
- package/dist/calldata/mayan/forwardERC20.js +19 -0
- package/dist/calldata/mayan/forwardEth.d.ts +2 -0
- package/dist/calldata/mayan/forwardEth.js +16 -0
- package/dist/calldata/mayan/index.d.ts +4 -0
- package/dist/calldata/mayan/index.js +21 -0
- package/dist/calldata/mayan/mctp.d.ts +5 -0
- package/dist/calldata/mayan/mctp.js +41 -0
- package/dist/calldata/mayan/readProtocol.d.ts +2 -0
- package/dist/calldata/mayan/readProtocol.js +29 -0
- package/dist/calldata/mayan/swapAndForwardERC20.d.ts +2 -0
- package/dist/calldata/mayan/swapAndForwardERC20.js +24 -0
- package/dist/calldata/mayan/swapAndForwardEth.d.ts +2 -0
- package/dist/calldata/mayan/swapAndForwardEth.js +23 -0
- package/dist/calldata/mayan/swiftCreateOrder.d.ts +3 -0
- package/dist/calldata/mayan/swiftCreateOrder.js +49 -0
- package/dist/calldata/mayan/validate.d.ts +3 -0
- package/dist/calldata/mayan/validate.js +20 -0
- package/dist/calldata/protocols.d.ts +9 -0
- package/dist/calldata/protocols.js +58 -0
- package/dist/calldata/relay/calls.d.ts +13 -0
- package/dist/calldata/relay/calls.js +58 -0
- package/dist/calldata/relay/depositErc20.d.ts +2 -0
- package/dist/calldata/relay/depositErc20.js +22 -0
- package/dist/calldata/relay/depositErc20Allowance.d.ts +2 -0
- package/dist/calldata/relay/depositErc20Allowance.js +20 -0
- package/dist/calldata/relay/depositNative.d.ts +2 -0
- package/dist/calldata/relay/depositNative.js +20 -0
- package/dist/calldata/relay/index.d.ts +4 -0
- package/dist/calldata/relay/index.js +45 -0
- package/dist/calldata/relay/multicall.d.ts +2 -0
- package/dist/calldata/relay/multicall.js +15 -0
- package/dist/calldata/relay/nestedDeposit.d.ts +8 -0
- package/dist/calldata/relay/nestedDeposit.js +107 -0
- package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +2 -0
- package/dist/calldata/relay/permit2TransferAndMulticall.js +42 -0
- package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +2 -0
- package/dist/calldata/relay/permit3009TransferAndMulticall.js +41 -0
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +2 -0
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +40 -0
- package/dist/calldata/relay/permitTransferAndMulticall.d.ts +2 -0
- package/dist/calldata/relay/permitTransferAndMulticall.js +34 -0
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +2 -0
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +35 -0
- package/dist/calldata/relay/transferAndMulticall.d.ts +2 -0
- package/dist/calldata/relay/transferAndMulticall.js +26 -0
- package/dist/calldata/relay/validate.d.ts +3 -0
- package/dist/calldata/relay/validate.js +18 -0
- package/dist/calldata/resolve.d.ts +2 -0
- package/dist/calldata/resolve.js +28 -0
- package/dist/calldata/socket/addresses.d.ts +9 -0
- package/dist/calldata/socket/addresses.js +9 -0
- package/dist/calldata/socket/bridge.d.ts +2 -0
- package/dist/calldata/socket/bridge.js +28 -0
- package/dist/calldata/socket/exec.d.ts +2 -0
- package/dist/calldata/socket/exec.js +71 -0
- package/dist/calldata/socket/index.d.ts +4 -0
- package/dist/calldata/socket/index.js +13 -0
- package/dist/calldata/socket/params.d.ts +5 -0
- package/dist/calldata/socket/params.js +14 -0
- package/dist/calldata/socket/protocols/ccip.d.ts +2 -0
- package/dist/calldata/socket/protocols/ccip.js +32 -0
- package/dist/calldata/socket/protocols/cctp.d.ts +2 -0
- package/dist/calldata/socket/protocols/cctp.js +25 -0
- package/dist/calldata/socket/protocols/eco.d.ts +2 -0
- package/dist/calldata/socket/protocols/eco.js +49 -0
- package/dist/calldata/socket/protocols/index.d.ts +3 -0
- package/dist/calldata/socket/protocols/index.js +87 -0
- package/dist/calldata/socket/protocols/native.d.ts +2 -0
- package/dist/calldata/socket/protocols/native.js +71 -0
- package/dist/calldata/socket/protocols/oft.d.ts +2 -0
- package/dist/calldata/socket/protocols/oft.js +33 -0
- package/dist/calldata/socket/protocols/swapsXYZ.d.ts +2 -0
- package/dist/calldata/socket/protocols/swapsXYZ.js +62 -0
- package/dist/calldata/socket/swapAndBridge.d.ts +2 -0
- package/dist/calldata/socket/swapAndBridge.js +41 -0
- package/dist/calldata/socket/validate.d.ts +3 -0
- package/dist/calldata/socket/validate.js +24 -0
- package/dist/calldata/types.d.ts +86 -0
- package/dist/calldata/types.js +20 -0
- package/dist/errors/constants.d.ts +906 -0
- package/dist/errors/constants.js +913 -0
- package/dist/errors/index.d.ts +65 -0
- package/dist/errors/index.js +53 -0
- package/dist/errors/sanitize.d.ts +3 -0
- package/dist/errors/sanitize.js +74 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -0
- package/dist/providers/data.d.ts +23 -0
- package/dist/providers/data.js +116 -0
- package/dist/providers/errors.d.ts +7 -0
- package/dist/providers/errors.js +10 -0
- package/dist/providers/layerswap.d.ts +9 -0
- package/dist/providers/layerswap.js +95 -0
- package/dist/providers/relay.d.ts +62 -0
- package/dist/providers/relay.js +237 -0
- package/dist/providers/socket.d.ts +5 -0
- package/dist/providers/socket.js +58 -0
- package/dist/quote.d.ts +30 -3
- package/dist/quote.js +236 -66
- package/package.json +13 -3
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { knownCompare } from '../../expect.js';
|
|
2
|
+
import { bridgeShape } from '../shape.js';
|
|
3
|
+
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
+
import { applyPaxosData, paxosDataParam } from '../params.js';
|
|
5
|
+
export const methods = [
|
|
6
|
+
lifiBridgeMethod('startBridgeTokensViaPaxosTransit', '0x5080ffe2', [paxosDataParam], false, (parsed, args) => applyPaxosData(parsed, args.paxosData)),
|
|
7
|
+
lifiBridgeMethod('swapAndStartBridgeTokensViaPaxosTransit', '0x637f1d04', [paxosDataParam], true, (parsed, args) => applyPaxosData(parsed, args.paxosData)),
|
|
8
|
+
];
|
|
9
|
+
export const compare = knownCompare;
|
|
10
|
+
export const check = bridgeShape;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
+
export declare const methods: CalldataMethod[];
|
|
3
|
+
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
4
|
+
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { knownCompare } from '../../expect.js';
|
|
2
|
+
import { bridgeShape } from '../shape.js';
|
|
3
|
+
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
+
import { applyPolymerData, polymerDataParam } from '../params.js';
|
|
5
|
+
export const methods = [
|
|
6
|
+
lifiBridgeMethod('startBridgeTokensViaPolymerCCTP', '0xf434d6ca', [polymerDataParam], false, (parsed, args) => applyPolymerData(parsed, args.polymerData)),
|
|
7
|
+
lifiBridgeMethod('swapAndStartBridgeTokensViaPolymerCCTP', '0x17917a4e', [polymerDataParam], true, (parsed, args) => applyPolymerData(parsed, args.polymerData)),
|
|
8
|
+
];
|
|
9
|
+
export const compare = knownCompare;
|
|
10
|
+
export const check = bridgeShape;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
+
import type { CompareMask } from '../../expect.js';
|
|
3
|
+
import type { ParsedBridgeCall } from '../../types.js';
|
|
4
|
+
export declare const methods: CalldataMethod[];
|
|
5
|
+
export declare const compare: (parsed: ParsedBridgeCall) => CompareMask;
|
|
6
|
+
export declare const check: (parsed: ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bridgeShape } from '../shape.js';
|
|
2
|
+
import { applyRelayDepositoryData, relayDepositoryDataParam } from '../params.js';
|
|
3
|
+
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
+
export const methods = [
|
|
5
|
+
lifiBridgeMethod('startBridgeTokensViaRelayDepository', '0x092e8fa4', [relayDepositoryDataParam], false, (parsed, args) => applyRelayDepositoryData(parsed, args.relayDepositoryData)),
|
|
6
|
+
lifiBridgeMethod('swapAndStartBridgeTokensViaRelayDepository', '0xa3443faa', [relayDepositoryDataParam], true, (parsed, args) => applyRelayDepositoryData(parsed, args.relayDepositoryData)),
|
|
7
|
+
];
|
|
8
|
+
export const compare = (parsed) => ({
|
|
9
|
+
fromToken: parsed.sourceToken !== undefined,
|
|
10
|
+
fromAmount: parsed.sourceAmount !== undefined,
|
|
11
|
+
toToken: false,
|
|
12
|
+
toAmount: false,
|
|
13
|
+
receiver: true,
|
|
14
|
+
});
|
|
15
|
+
export const check = bridgeShape;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BridgeErrorDefinition } from '../../errors/index.js';
|
|
2
|
+
import type { ParsedBridgeCall } from '../types.js';
|
|
3
|
+
export declare const bridgeShape: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
|
|
4
|
+
export declare const swapShape: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS } from '../../errors/index.js';
|
|
2
|
+
import { isZeroWord } from '../hex.js';
|
|
3
|
+
export const bridgeShape = (parsed) => {
|
|
4
|
+
if (isZeroWord(parsed.receiver ?? parsed.bridgeReceiver)) {
|
|
5
|
+
return BRIDGE_ERRORS.MISSING_RECEIVER;
|
|
6
|
+
}
|
|
7
|
+
const hasDestination = (parsed.destinationChainId !== undefined && parsed.destinationChainId > 0n) ||
|
|
8
|
+
Boolean(parsed.destinationChainRef);
|
|
9
|
+
if (!hasDestination) {
|
|
10
|
+
return BRIDGE_ERRORS.MISSING_DESTINATION_CHAIN;
|
|
11
|
+
}
|
|
12
|
+
if (parsed.method.startsWith('swapAnd') && (parsed.sourceAmount ?? 0n) <= 0n) {
|
|
13
|
+
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
14
|
+
}
|
|
15
|
+
if (parsed.sourceToken === undefined) {
|
|
16
|
+
return BRIDGE_ERRORS.MISSING_SOURCE_TOKEN;
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
};
|
|
20
|
+
export const swapShape = (parsed) => {
|
|
21
|
+
if (!parsed.receiver || isZeroWord(parsed.receiver)) {
|
|
22
|
+
return BRIDGE_ERRORS.MISSING_RECEIVER;
|
|
23
|
+
}
|
|
24
|
+
if (parsed.minOutputAmount === undefined) {
|
|
25
|
+
return BRIDGE_ERRORS.MISSING_MIN_OUTPUT;
|
|
26
|
+
}
|
|
27
|
+
if ((parsed.sourceAmount ?? 0n) <= 0n) {
|
|
28
|
+
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
+
import type { CompareMask } from '../../expect.js';
|
|
3
|
+
import type { ParsedBridgeCall } from '../../types.js';
|
|
4
|
+
export declare const methods: CalldataMethod[];
|
|
5
|
+
export declare const compare: (parsed: ParsedBridgeCall) => CompareMask;
|
|
6
|
+
export declare const check: (parsed: ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bridgeShape } from '../shape.js';
|
|
2
|
+
import { applySquidData, squidDataParam } from '../params.js';
|
|
3
|
+
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
+
export const methods = [
|
|
5
|
+
lifiBridgeMethod('startBridgeTokensViaSquid', '0x3f313808', [squidDataParam], false, (parsed, args) => applySquidData(parsed, args.squidData)),
|
|
6
|
+
lifiBridgeMethod('swapAndStartBridgeTokensViaSquid', '0xa8f66666', [squidDataParam], true, (parsed, args) => applySquidData(parsed, args.squidData)),
|
|
7
|
+
];
|
|
8
|
+
export const compare = (parsed) => ({
|
|
9
|
+
fromToken: parsed.sourceToken !== undefined,
|
|
10
|
+
fromAmount: parsed.sourceAmount !== undefined,
|
|
11
|
+
toToken: false,
|
|
12
|
+
toAmount: false,
|
|
13
|
+
receiver: true,
|
|
14
|
+
});
|
|
15
|
+
export const check = bridgeShape;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
+
import type { CompareMask } from '../../expect.js';
|
|
3
|
+
export declare const methods: CalldataMethod[];
|
|
4
|
+
export declare const compare: () => CompareMask;
|
|
5
|
+
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { bridgeShape } from '../shape.js';
|
|
2
|
+
import { applyStargateData, stargateDataParam } from '../params.js';
|
|
3
|
+
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
+
export const methods = [
|
|
5
|
+
lifiBridgeMethod('startBridgeTokensViaStargate', '0x14d53077', [stargateDataParam], false, (parsed, args) => applyStargateData(parsed, args.stargateData)),
|
|
6
|
+
lifiBridgeMethod('swapAndStartBridgeTokensViaStargate', '0xa6010a66', [stargateDataParam], true, (parsed, args) => applyStargateData(parsed, args.stargateData)),
|
|
7
|
+
];
|
|
8
|
+
export const compare = () => ({
|
|
9
|
+
fromToken: true,
|
|
10
|
+
fromAmount: true,
|
|
11
|
+
toToken: false,
|
|
12
|
+
toAmount: true,
|
|
13
|
+
receiver: true,
|
|
14
|
+
});
|
|
15
|
+
export const check = bridgeShape;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
+
import type { CompareMask } from '../../expect.js';
|
|
3
|
+
export declare const methods: CalldataMethod[];
|
|
4
|
+
export declare const compare: () => CompareMask;
|
|
5
|
+
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { swapShape } from '../shape.js';
|
|
2
|
+
import { lifiSwapMethod } from './swapMethod.js';
|
|
3
|
+
export const methods = [
|
|
4
|
+
lifiSwapMethod('swapTokensSingleV3ERC20ToERC20', '0x4666fc80', false),
|
|
5
|
+
lifiSwapMethod('swapTokensSingleV3ERC20ToNative', '0x733214a3', false),
|
|
6
|
+
lifiSwapMethod('swapTokensSingleV3NativeToERC20', '0xaf7060fd', false),
|
|
7
|
+
lifiSwapMethod('swapTokensMultipleV3ERC20ToERC20', '0x5fd9ae2e', true),
|
|
8
|
+
lifiSwapMethod('swapTokensMultipleV3ERC20ToNative', '0x2c57e884', true),
|
|
9
|
+
lifiSwapMethod('swapTokensMultipleV3NativeToERC20', '0x736eac0b', true),
|
|
10
|
+
];
|
|
11
|
+
export const compare = () => ({
|
|
12
|
+
fromToken: true,
|
|
13
|
+
fromAmount: true,
|
|
14
|
+
toToken: true,
|
|
15
|
+
toAmount: true,
|
|
16
|
+
receiver: true,
|
|
17
|
+
});
|
|
18
|
+
export const check = swapShape;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { asArray, asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
+
import { applyFirstSwap, swapDataArrayParam, swapDataParam } from '../swapData.js';
|
|
3
|
+
const header = [
|
|
4
|
+
{ name: 'transactionId', kind: 'bytes', size: 32 },
|
|
5
|
+
{ name: 'integrator', kind: 'string' },
|
|
6
|
+
{ name: 'referrer', kind: 'string' },
|
|
7
|
+
{ name: 'receiver', kind: 'address' },
|
|
8
|
+
{ name: 'minAmountOut', kind: 'uint' },
|
|
9
|
+
];
|
|
10
|
+
export const lifiSwapMethod = (name, selector, multiple) => ({
|
|
11
|
+
name,
|
|
12
|
+
selector,
|
|
13
|
+
decode(data, value) {
|
|
14
|
+
const args = decodeCall([...header, multiple ? swapDataArrayParam : swapDataParam], data);
|
|
15
|
+
const parsed = {
|
|
16
|
+
aggregatorId: 'lifi',
|
|
17
|
+
method: name,
|
|
18
|
+
kind: 'swap',
|
|
19
|
+
receiver: asString(args.receiver),
|
|
20
|
+
referrer: asString(args.referrer),
|
|
21
|
+
minOutputAmount: asBigint(args.minAmountOut),
|
|
22
|
+
};
|
|
23
|
+
if (multiple) {
|
|
24
|
+
applyFirstSwap(parsed, args.swapData);
|
|
25
|
+
const swaps = asArray(args.swapData).map(asRecord);
|
|
26
|
+
if (swaps.length)
|
|
27
|
+
parsed.outputToken = asString(swaps[swaps.length - 1].receivingAssetId);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const swap = asRecord(args.swapData);
|
|
31
|
+
parsed.sourceToken = asString(swap.sendingAssetId);
|
|
32
|
+
parsed.sourceAmount = asBigint(swap.fromAmount);
|
|
33
|
+
parsed.outputToken = asString(swap.receivingAssetId);
|
|
34
|
+
}
|
|
35
|
+
if ((parsed.sourceAmount ?? 0n) === 0n && value > 0n) {
|
|
36
|
+
parsed.sourceAmount = value;
|
|
37
|
+
}
|
|
38
|
+
return parsed;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AbiParam, type AbiValue } from '../abi.js';
|
|
2
|
+
import type { ParsedBridgeCall } from '../types.js';
|
|
3
|
+
export declare const swapDataArrayParam: AbiParam;
|
|
4
|
+
export declare const swapDataParam: AbiParam;
|
|
5
|
+
export declare const applyFirstSwap: (parsed: ParsedBridgeCall, raw: AbiValue) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
|
|
2
|
+
import { asArray, asBigint, asRecord, asString } from '../abi.js';
|
|
3
|
+
const swapComponents = [
|
|
4
|
+
{ name: 'callTo', kind: 'address' },
|
|
5
|
+
{ name: 'approveTo', kind: 'address' },
|
|
6
|
+
{ name: 'sendingAssetId', kind: 'address' },
|
|
7
|
+
{ name: 'receivingAssetId', kind: 'address' },
|
|
8
|
+
{ name: 'fromAmount', kind: 'uint' },
|
|
9
|
+
{ name: 'callData', kind: 'bytes' },
|
|
10
|
+
{ name: 'requiresDeposit', kind: 'bool' },
|
|
11
|
+
];
|
|
12
|
+
export const swapDataArrayParam = {
|
|
13
|
+
name: 'swapData', kind: 'array',
|
|
14
|
+
item: { name: 'swap', kind: 'tuple', components: swapComponents },
|
|
15
|
+
};
|
|
16
|
+
export const swapDataParam = {
|
|
17
|
+
name: 'swapData', kind: 'tuple', components: swapComponents,
|
|
18
|
+
};
|
|
19
|
+
export const applyFirstSwap = (parsed, raw) => {
|
|
20
|
+
const swaps = asArray(raw);
|
|
21
|
+
const deposits = swaps.map(asRecord).filter((swap) => swap.requiresDeposit === true);
|
|
22
|
+
const first = deposits[0] ?? swaps[0];
|
|
23
|
+
if (!first)
|
|
24
|
+
return;
|
|
25
|
+
const swap = asRecord(first);
|
|
26
|
+
parsed.sourceToken = asString(swap.sendingAssetId);
|
|
27
|
+
if (deposits.some((deposit) => asString(deposit.sendingAssetId) !== parsed.sourceToken)) {
|
|
28
|
+
throw new BridgeError(BRIDGE_ERRORS.MULTIPLE_SOURCE_ASSETS_ARE_NOT_SUPPORTED);
|
|
29
|
+
}
|
|
30
|
+
parsed.sourceAmount = deposits.length
|
|
31
|
+
? deposits.reduce((sum, deposit) => sum + asBigint(deposit.fromAmount), 0n)
|
|
32
|
+
: asBigint(swap.fromAmount);
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, asBridgeError, bridgeFailure } from '../errors/index.js';
|
|
2
|
+
import { readSelector } from './hex.js';
|
|
3
|
+
import { resolveParsed } from './resolve.js';
|
|
4
|
+
import { calldataDiagnostics } from './diagnostics.js';
|
|
5
|
+
export const matchMethod = (methods, data, value) => {
|
|
6
|
+
const selector = readSelector(data);
|
|
7
|
+
const diagnostics = calldataDiagnostics(data);
|
|
8
|
+
if (!selector)
|
|
9
|
+
return bridgeFailure([{ ...(data && data !== '0x' ? BRIDGE_ERRORS.INVALID_SELECTOR : BRIDGE_ERRORS.MISSING_CALLDATA), ...diagnostics }]);
|
|
10
|
+
for (const method of methods) {
|
|
11
|
+
if (method.selector !== selector)
|
|
12
|
+
continue;
|
|
13
|
+
try {
|
|
14
|
+
return { ok: true, parsed: resolveParsed(method.decode(data, value)) };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
return { ...bridgeFailure(asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, { method: method.name, ...diagnostics }).errors), method: method.name };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return bridgeFailure([{ ...BRIDGE_ERRORS.UNSUPPORTED_METHOD, ...diagnostics }]);
|
|
21
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CCTP_CHAINS, WORMHOLE_CHAINS } from '../protocols.js';
|
|
2
|
+
export const mayanDestination = (system, id, token, normalizedAmount) => {
|
|
3
|
+
const destinationChainId = (system === 'cctp' ? CCTP_CHAINS : WORMHOLE_CHAINS)[id.toString()];
|
|
4
|
+
const destinationChainRef = `${system}:${id}`;
|
|
5
|
+
return {
|
|
6
|
+
destinationChainId, destinationChainRef,
|
|
7
|
+
outputToken: token,
|
|
8
|
+
outputAmountReference: token !== undefined && normalizedAmount !== undefined ? {
|
|
9
|
+
kind: 'normalized', amount: normalizedAmount, decimals: 8,
|
|
10
|
+
token: { protocol: 'token', token, destinationChainId, destinationChainRef },
|
|
11
|
+
} : undefined,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
|
|
2
|
+
import { asBigint, asString, decodeCall } from '../abi.js';
|
|
3
|
+
import { accountFromBytes32 } from '../hex.js';
|
|
4
|
+
import { mayanDestination } from './destination.js';
|
|
5
|
+
import { subtractFees } from '../protocols.js';
|
|
6
|
+
export const FAST_MCTP_BRIDGE = '0xf58b6de8';
|
|
7
|
+
export const decodeFastMctpBridge = (data, amountFloor) => {
|
|
8
|
+
const args = decodeCall([
|
|
9
|
+
{ name: 'tokenIn', kind: 'address' },
|
|
10
|
+
{ name: 'amountIn', kind: 'uint' },
|
|
11
|
+
{ name: 'redeemFee', kind: 'uint' },
|
|
12
|
+
{ name: 'circleMaxFee', kind: 'uint' },
|
|
13
|
+
{ name: 'gasDrop', kind: 'uint' },
|
|
14
|
+
{ name: 'destAddr', kind: 'bytes', size: 32 },
|
|
15
|
+
{ name: 'destDomain', kind: 'uint' },
|
|
16
|
+
{ name: 'referrerAddress', kind: 'bytes', size: 32 },
|
|
17
|
+
{ name: 'referrerBps', kind: 'uint' },
|
|
18
|
+
{ name: 'payloadType', kind: 'uint' },
|
|
19
|
+
{ name: 'minFinalityThreshold', kind: 'uint' },
|
|
20
|
+
{ name: 'customPayload', kind: 'bytes' },
|
|
21
|
+
], data);
|
|
22
|
+
const destination = mayanDestination('cctp', asBigint(args.destDomain));
|
|
23
|
+
const token = { protocol: 'cctp', destinationChainId: destination.destinationChainId };
|
|
24
|
+
const payloadType = asBigint(args.payloadType);
|
|
25
|
+
if (payloadType !== 1n && payloadType !== 2n)
|
|
26
|
+
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_MAYAN_PROTOCOL_CALLDATA);
|
|
27
|
+
// FastMCTP.bridge hashes customPayload only for type 2; type 1 is a direct
|
|
28
|
+
// payout even when the unused bytes are nonempty (verified FastMCTP.sol).
|
|
29
|
+
const custom = payloadType === 2n;
|
|
30
|
+
const net = subtractFees(amountFloor ?? asBigint(args.amountIn), asBigint(args.redeemFee), asBigint(args.circleMaxFee));
|
|
31
|
+
const referrerBps = asBigint(args.referrerBps);
|
|
32
|
+
if (referrerBps > 100n)
|
|
33
|
+
throw new BridgeError(BRIDGE_ERRORS.INVALID_FASTMCTP_REFERRER_FEE);
|
|
34
|
+
// redeem caps the destination protocol fee at 100 bps; it is not fixed by the source deposit.
|
|
35
|
+
const minimum = net * (10000n - 100n - referrerBps) / 10000n;
|
|
36
|
+
return {
|
|
37
|
+
protocolMethod: 'bridge',
|
|
38
|
+
sourceToken: asString(args.tokenIn),
|
|
39
|
+
sourceAmount: asBigint(args.amountIn),
|
|
40
|
+
...destination,
|
|
41
|
+
outputTokenReference: custom ? undefined : token,
|
|
42
|
+
minOutputAmount: custom ? undefined : minimum,
|
|
43
|
+
bridgeReceiver: accountFromBytes32(asString(args.destAddr)),
|
|
44
|
+
receiver: custom ? undefined : accountFromBytes32(asString(args.destAddr)),
|
|
45
|
+
destinationCallData: custom ? asString(args.customPayload) : undefined,
|
|
46
|
+
referrer: accountFromBytes32(asString(args.referrerAddress)),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
|
|
2
|
+
import { accountFromBytes32 } from '../hex.js';
|
|
3
|
+
import { mayanDestination } from './destination.js';
|
|
4
|
+
const orderPayload = {
|
|
5
|
+
name: 'orderPayload',
|
|
6
|
+
kind: 'tuple',
|
|
7
|
+
components: [
|
|
8
|
+
{ name: 'payloadType', kind: 'uint' },
|
|
9
|
+
{ name: 'destAddr', kind: 'bytes', size: 32 },
|
|
10
|
+
{ name: 'tokenOut', kind: 'bytes', size: 32 },
|
|
11
|
+
{ name: 'amountOutMin', kind: 'uint' },
|
|
12
|
+
{ name: 'gasDrop', kind: 'uint' },
|
|
13
|
+
{ name: 'redeemFee', kind: 'uint' },
|
|
14
|
+
{ name: 'refundFee', kind: 'uint' },
|
|
15
|
+
{ name: 'deadline', kind: 'uint' },
|
|
16
|
+
{ name: 'referrerAddr', kind: 'bytes', size: 32 },
|
|
17
|
+
{ name: 'referrerBps', kind: 'uint' },
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
export const FAST_MCTP_CREATE_ORDER = '0x2337e236';
|
|
21
|
+
export const decodeFastMctpCreateOrder = (data) => {
|
|
22
|
+
const args = decodeCall([
|
|
23
|
+
{ name: 'tokenIn', kind: 'address' },
|
|
24
|
+
{ name: 'amountIn', kind: 'uint' },
|
|
25
|
+
{ name: 'circleMaxFee', kind: 'uint' },
|
|
26
|
+
{ name: 'destDomain', kind: 'uint' },
|
|
27
|
+
{ name: 'minFinalityThreshold', kind: 'uint' },
|
|
28
|
+
orderPayload,
|
|
29
|
+
], data);
|
|
30
|
+
const order = asRecord(args.orderPayload);
|
|
31
|
+
return {
|
|
32
|
+
protocolMethod: 'createOrder',
|
|
33
|
+
sourceToken: asString(args.tokenIn),
|
|
34
|
+
sourceAmount: asBigint(args.amountIn),
|
|
35
|
+
...mayanDestination('cctp', asBigint(args.destDomain), accountFromBytes32(asString(order.tokenOut)), asBigint(order.amountOutMin)),
|
|
36
|
+
receiver: accountFromBytes32(asString(order.destAddr)),
|
|
37
|
+
referrer: accountFromBytes32(asString(order.referrerAddr)),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AbiParam } from '../abi.js';
|
|
2
|
+
import type { ParsedBridgeCall } from '../types.js';
|
|
3
|
+
export declare const permitParams: AbiParam;
|
|
4
|
+
export declare const finishForward: (method: string, protocol: string, protocolData: string, source: {
|
|
5
|
+
token?: string;
|
|
6
|
+
amount?: bigint;
|
|
7
|
+
protocolAmount?: bigint;
|
|
8
|
+
}) => ParsedBridgeCall;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { readMayanProtocol } from './readProtocol.js';
|
|
2
|
+
import { innerCallDiagnostics } from '../diagnostics.js';
|
|
3
|
+
export const permitParams = {
|
|
4
|
+
name: 'permitParams',
|
|
5
|
+
kind: 'tuple',
|
|
6
|
+
components: [
|
|
7
|
+
{ name: 'value', kind: 'uint' },
|
|
8
|
+
{ name: 'deadline', kind: 'uint' },
|
|
9
|
+
{ name: 'v', kind: 'uint' },
|
|
10
|
+
{ name: 'r', kind: 'bytes', size: 32 },
|
|
11
|
+
{ name: 's', kind: 'bytes', size: 32 },
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
export const finishForward = (method, protocol, protocolData, source) => {
|
|
15
|
+
const parsed = {
|
|
16
|
+
aggregatorId: 'mayan',
|
|
17
|
+
method,
|
|
18
|
+
kind: 'bridge',
|
|
19
|
+
innerTarget: protocol,
|
|
20
|
+
sourceToken: source.token,
|
|
21
|
+
sourceAmount: source.amount,
|
|
22
|
+
diagnostics: innerCallDiagnostics(protocolData, 'protocol'),
|
|
23
|
+
};
|
|
24
|
+
const order = readMayanProtocol(protocolData, source.protocolAmount ?? source.amount);
|
|
25
|
+
if (!order) {
|
|
26
|
+
return parsed;
|
|
27
|
+
}
|
|
28
|
+
const { sourceToken, sourceAmount, ...destination } = order;
|
|
29
|
+
Object.assign(parsed, destination);
|
|
30
|
+
parsed.sourceToken = parsed.sourceToken ?? order.sourceToken;
|
|
31
|
+
if ((parsed.sourceAmount ?? 0n) === 0n) {
|
|
32
|
+
parsed.sourceAmount = order.sourceAmount;
|
|
33
|
+
}
|
|
34
|
+
return parsed;
|
|
35
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { asBigint, asString, decodeCall } from '../abi.js';
|
|
2
|
+
import { finishForward, permitParams } from './forward.js';
|
|
3
|
+
export const forwardERC20 = {
|
|
4
|
+
name: 'forwardERC20',
|
|
5
|
+
selector: '0xe4269fc4',
|
|
6
|
+
decode(data) {
|
|
7
|
+
const args = decodeCall([
|
|
8
|
+
{ name: 'tokenIn', kind: 'address' },
|
|
9
|
+
{ name: 'amountIn', kind: 'uint' },
|
|
10
|
+
permitParams,
|
|
11
|
+
{ name: 'mayanProtocol', kind: 'address' },
|
|
12
|
+
{ name: 'protocolData', kind: 'bytes' },
|
|
13
|
+
], data);
|
|
14
|
+
return finishForward('forwardERC20', asString(args.mayanProtocol), asString(args.protocolData), {
|
|
15
|
+
token: asString(args.tokenIn),
|
|
16
|
+
amount: asBigint(args.amountIn),
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { asString, decodeCall } from '../abi.js';
|
|
2
|
+
import { finishForward } from './forward.js';
|
|
3
|
+
export const forwardEth = {
|
|
4
|
+
name: 'forwardEth',
|
|
5
|
+
selector: '0xb0f584ff',
|
|
6
|
+
decode(data, value) {
|
|
7
|
+
const args = decodeCall([
|
|
8
|
+
{ name: 'mayanProtocol', kind: 'address' },
|
|
9
|
+
{ name: 'protocolData', kind: 'bytes' },
|
|
10
|
+
], data);
|
|
11
|
+
return finishForward('forwardEth', asString(args.mayanProtocol), asString(args.protocolData), {
|
|
12
|
+
token: '0x0000000000000000000000000000000000000000',
|
|
13
|
+
amount: value,
|
|
14
|
+
});
|
|
15
|
+
},
|
|
16
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BridgeCallExpectation } from '../expect.js';
|
|
2
|
+
import type { BridgeCheck, DecodeHit } from '../types.js';
|
|
3
|
+
export declare const decodeMayan: (data: string, value: bigint) => DecodeHit;
|
|
4
|
+
export declare const validateMayan: (data: string, value: bigint, expectation?: BridgeCallExpectation, chainId?: string) => BridgeCheck;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { matchMethod } from '../match.js';
|
|
2
|
+
import { finishCheck, knownCompare } from '../expect.js';
|
|
3
|
+
import { forwardERC20 } from './forwardERC20.js';
|
|
4
|
+
import { forwardEth } from './forwardEth.js';
|
|
5
|
+
import { swapAndForwardERC20 } from './swapAndForwardERC20.js';
|
|
6
|
+
import { swapAndForwardEth } from './swapAndForwardEth.js';
|
|
7
|
+
import { mayanFailure } from './validate.js';
|
|
8
|
+
const METHODS = [
|
|
9
|
+
forwardERC20,
|
|
10
|
+
forwardEth,
|
|
11
|
+
swapAndForwardERC20,
|
|
12
|
+
swapAndForwardEth,
|
|
13
|
+
];
|
|
14
|
+
export const decodeMayan = (data, value) => matchMethod(METHODS, data, value);
|
|
15
|
+
export const validateMayan = (data, value, expectation, chainId = '') => {
|
|
16
|
+
const hit = decodeMayan(data, value);
|
|
17
|
+
if (!hit.ok) {
|
|
18
|
+
return { ...hit, aggregatorId: 'mayan' };
|
|
19
|
+
}
|
|
20
|
+
return finishCheck('mayan', hit.parsed, mayanFailure(hit.parsed), expectation, chainId, knownCompare(hit.parsed));
|
|
21
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ParsedBridgeCall } from '../types.js';
|
|
2
|
+
export declare const MCTP_BRIDGE_WITH_FEE = "0x2072197f";
|
|
3
|
+
export declare const MCTP_CREATE_ORDER = "0x1c59b7fc";
|
|
4
|
+
export declare const decodeMctpBridge: (data: string, amountFloor?: bigint) => Partial<ParsedBridgeCall>;
|
|
5
|
+
export declare const decodeMctpOrder: (data: string) => Partial<ParsedBridgeCall>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
|
|
2
|
+
import { accountFromBytes32 } from '../hex.js';
|
|
3
|
+
import { subtractFees } from '../protocols.js';
|
|
4
|
+
import { mayanDestination } from './destination.js';
|
|
5
|
+
export const MCTP_BRIDGE_WITH_FEE = '0x2072197f';
|
|
6
|
+
export const MCTP_CREATE_ORDER = '0x1c59b7fc';
|
|
7
|
+
export const decodeMctpBridge = (data, amountFloor) => {
|
|
8
|
+
const a = decodeCall([
|
|
9
|
+
{ name: 'tokenIn', kind: 'address' }, { name: 'amountIn', kind: 'uint' },
|
|
10
|
+
{ name: 'redeemFee', kind: 'uint' }, { name: 'gasDrop', kind: 'uint' },
|
|
11
|
+
{ name: 'destAddr', kind: 'bytes', size: 32 }, { name: 'destDomain', kind: 'uint' },
|
|
12
|
+
{ name: 'payloadType', kind: 'uint' }, { name: 'customPayload', kind: 'bytes' },
|
|
13
|
+
], data);
|
|
14
|
+
const destination = mayanDestination('cctp', asBigint(a.destDomain));
|
|
15
|
+
const custom = asString(a.customPayload) !== '0x';
|
|
16
|
+
return {
|
|
17
|
+
protocolMethod: 'bridgeWithFee', ...destination,
|
|
18
|
+
sourceToken: asString(a.tokenIn), sourceAmount: asBigint(a.amountIn),
|
|
19
|
+
bridgeReceiver: accountFromBytes32(asString(a.destAddr)),
|
|
20
|
+
receiver: custom ? undefined : accountFromBytes32(asString(a.destAddr)),
|
|
21
|
+
outputTokenReference: custom ? undefined : { protocol: 'cctp', destinationChainId: destination.destinationChainId },
|
|
22
|
+
minOutputAmount: custom ? undefined : subtractFees(amountFloor ?? asBigint(a.amountIn), asBigint(a.redeemFee)),
|
|
23
|
+
destinationCallData: custom ? asString(a.customPayload) : undefined,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const order = { name: 'params', kind: 'tuple', components: [
|
|
27
|
+
{ name: 'tokenIn', kind: 'address' }, { name: 'amountIn', kind: 'uint' },
|
|
28
|
+
{ name: 'gasDrop', kind: 'uint' }, { name: 'destAddr', kind: 'bytes', size: 32 },
|
|
29
|
+
{ name: 'destChain', kind: 'uint' }, { name: 'tokenOut', kind: 'bytes', size: 32 },
|
|
30
|
+
{ name: 'minAmountOut', kind: 'uint' }, { name: 'deadline', kind: 'uint' },
|
|
31
|
+
{ name: 'redeemFee', kind: 'uint' }, { name: 'referrerAddr', kind: 'bytes', size: 32 },
|
|
32
|
+
{ name: 'referrerBps', kind: 'uint' },
|
|
33
|
+
] };
|
|
34
|
+
export const decodeMctpOrder = (data) => {
|
|
35
|
+
const a = asRecord(decodeCall([order], data).params);
|
|
36
|
+
return {
|
|
37
|
+
protocolMethod: 'createOrder', sourceToken: asString(a.tokenIn), sourceAmount: asBigint(a.amountIn),
|
|
38
|
+
...mayanDestination('wormhole', asBigint(a.destChain), accountFromBytes32(asString(a.tokenOut)), asBigint(a.minAmountOut)),
|
|
39
|
+
receiver: accountFromBytes32(asString(a.destAddr)), referrer: accountFromBytes32(asString(a.referrerAddr)),
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, asBridgeError } from '../../errors/index.js';
|
|
2
|
+
import { readSelector } from '../hex.js';
|
|
3
|
+
import { innerCallDiagnostics } from '../diagnostics.js';
|
|
4
|
+
import { FAST_MCTP_BRIDGE, decodeFastMctpBridge } from './fastMctpBridge.js';
|
|
5
|
+
import { FAST_MCTP_CREATE_ORDER, decodeFastMctpCreateOrder } from './fastMctpCreateOrder.js';
|
|
6
|
+
import { SWIFT_CREATE_ORDER, decodeSwiftCreateOrder } from './swiftCreateOrder.js';
|
|
7
|
+
import { decodeMctpBridge, decodeMctpOrder, MCTP_BRIDGE_WITH_FEE, MCTP_CREATE_ORDER } from './mctp.js';
|
|
8
|
+
export const readMayanProtocol = (protocolData, amountFloor) => {
|
|
9
|
+
const selector = readSelector(protocolData);
|
|
10
|
+
try {
|
|
11
|
+
if (selector === SWIFT_CREATE_ORDER) {
|
|
12
|
+
return decodeSwiftCreateOrder(protocolData);
|
|
13
|
+
}
|
|
14
|
+
if (selector === FAST_MCTP_CREATE_ORDER) {
|
|
15
|
+
return decodeFastMctpCreateOrder(protocolData);
|
|
16
|
+
}
|
|
17
|
+
if (selector === FAST_MCTP_BRIDGE) {
|
|
18
|
+
return decodeFastMctpBridge(protocolData, amountFloor);
|
|
19
|
+
}
|
|
20
|
+
if (selector === MCTP_BRIDGE_WITH_FEE)
|
|
21
|
+
return decodeMctpBridge(protocolData, amountFloor);
|
|
22
|
+
if (selector === MCTP_CREATE_ORDER)
|
|
23
|
+
return decodeMctpOrder(protocolData);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, innerCallDiagnostics(protocolData, 'protocol'));
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { asBigint, asString, decodeCall } from '../abi.js';
|
|
2
|
+
import { finishForward, permitParams } from './forward.js';
|
|
3
|
+
export const swapAndForwardERC20 = {
|
|
4
|
+
name: 'swapAndForwardERC20',
|
|
5
|
+
selector: '0x30dedc57',
|
|
6
|
+
decode(data) {
|
|
7
|
+
const args = decodeCall([
|
|
8
|
+
{ name: 'tokenIn', kind: 'address' },
|
|
9
|
+
{ name: 'amountIn', kind: 'uint' },
|
|
10
|
+
permitParams,
|
|
11
|
+
{ name: 'swapProtocol', kind: 'address' },
|
|
12
|
+
{ name: 'swapData', kind: 'bytes' },
|
|
13
|
+
{ name: 'middleToken', kind: 'address' },
|
|
14
|
+
{ name: 'minMiddleAmount', kind: 'uint' },
|
|
15
|
+
{ name: 'mayanProtocol', kind: 'address' },
|
|
16
|
+
{ name: 'mayanData', kind: 'bytes' },
|
|
17
|
+
], data);
|
|
18
|
+
return finishForward('swapAndForwardERC20', asString(args.mayanProtocol), asString(args.mayanData), {
|
|
19
|
+
token: asString(args.tokenIn),
|
|
20
|
+
amount: asBigint(args.amountIn),
|
|
21
|
+
protocolAmount: asBigint(args.minMiddleAmount),
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
};
|