@rabby-wallet/rabby-bridge 0.0.13-alpha.0 → 0.0.13
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 +1 -131
- package/dist/chains.d.ts +2 -1
- package/dist/chains.js +2 -0
- package/dist/data.d.ts +3 -0
- package/dist/data.js +3 -0
- package/dist/index.d.ts +1 -7
- package/dist/index.js +0 -3
- package/dist/quote.d.ts +4 -18
- package/dist/quote.js +65 -282
- package/package.json +3 -13
- package/dist/calldata/abi.d.ts +0 -29
- package/dist/calldata/abi.js +0 -160
- package/dist/calldata/across/deposit.d.ts +0 -2
- package/dist/calldata/across/deposit.js +0 -36
- package/dist/calldata/across/depositNative.d.ts +0 -2
- package/dist/calldata/across/depositNative.js +0 -45
- package/dist/calldata/across/depositNow.d.ts +0 -2
- package/dist/calldata/across/depositNow.js +0 -35
- package/dist/calldata/across/depositV3.d.ts +0 -2
- package/dist/calldata/across/depositV3.js +0 -35
- package/dist/calldata/across/depositV3Now.d.ts +0 -2
- package/dist/calldata/across/depositV3Now.js +0 -34
- package/dist/calldata/across/index.d.ts +0 -4
- package/dist/calldata/across/index.js +0 -31
- package/dist/calldata/across/swapAndBridge.d.ts +0 -2
- package/dist/calldata/across/swapAndBridge.js +0 -70
- package/dist/calldata/across/validate.d.ts +0 -3
- package/dist/calldata/across/validate.js +0 -30
- package/dist/calldata/chains.d.ts +0 -2
- package/dist/calldata/chains.js +0 -35
- package/dist/calldata/destination.d.ts +0 -6
- package/dist/calldata/destination.js +0 -148
- package/dist/calldata/diagnostics.d.ts +0 -4
- package/dist/calldata/diagnostics.js +0 -18
- package/dist/calldata/expect.d.ts +0 -25
- package/dist/calldata/expect.js +0 -129
- package/dist/calldata/hex.d.ts +0 -6
- package/dist/calldata/hex.js +0 -46
- package/dist/calldata/index.d.ts +0 -20
- package/dist/calldata/index.js +0 -85
- package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +0 -2
- package/dist/calldata/lifi/across/acrossV4Erc20Min.js +0 -26
- package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +0 -2
- package/dist/calldata/lifi/across/acrossV4NativeMin.js +0 -22
- package/dist/calldata/lifi/across/index.d.ts +0 -6
- package/dist/calldata/lifi/across/index.js +0 -19
- package/dist/calldata/lifi/allbridge/index.d.ts +0 -3
- package/dist/calldata/lifi/allbridge/index.js +0 -26
- package/dist/calldata/lifi/celer/index.d.ts +0 -4
- package/dist/calldata/lifi/celer/index.js +0 -10
- package/dist/calldata/lifi/centrifuge/index.d.ts +0 -3
- package/dist/calldata/lifi/centrifuge/index.js +0 -22
- package/dist/calldata/lifi/frax/index.d.ts +0 -4
- package/dist/calldata/lifi/frax/index.js +0 -29
- package/dist/calldata/lifi/garden/index.d.ts +0 -3
- package/dist/calldata/lifi/garden/index.js +0 -22
- package/dist/calldata/lifi/gaszip/index.d.ts +0 -6
- package/dist/calldata/lifi/gaszip/index.js +0 -15
- package/dist/calldata/lifi/index.d.ts +0 -4
- package/dist/calldata/lifi/index.js +0 -60
- package/dist/calldata/lifi/intents/index.d.ts +0 -4
- package/dist/calldata/lifi/intents/index.js +0 -10
- package/dist/calldata/lifi/layerswap/index.d.ts +0 -4
- package/dist/calldata/lifi/layerswap/index.js +0 -10
- package/dist/calldata/lifi/m0/index.d.ts +0 -3
- package/dist/calldata/lifi/m0/index.js +0 -33
- package/dist/calldata/lifi/mayan/index.d.ts +0 -4
- package/dist/calldata/lifi/mayan/index.js +0 -10
- package/dist/calldata/lifi/method.d.ts +0 -6
- package/dist/calldata/lifi/method.js +0 -16
- package/dist/calldata/lifi/native/index.d.ts +0 -4
- package/dist/calldata/lifi/native/index.js +0 -80
- package/dist/calldata/lifi/params.d.ts +0 -30
- package/dist/calldata/lifi/params.js +0 -370
- package/dist/calldata/lifi/paxos/index.d.ts +0 -4
- package/dist/calldata/lifi/paxos/index.js +0 -10
- package/dist/calldata/lifi/polymer/index.d.ts +0 -4
- package/dist/calldata/lifi/polymer/index.js +0 -10
- package/dist/calldata/lifi/relay/index.d.ts +0 -6
- package/dist/calldata/lifi/relay/index.js +0 -15
- package/dist/calldata/lifi/shape.d.ts +0 -4
- package/dist/calldata/lifi/shape.js +0 -31
- package/dist/calldata/lifi/squid/index.d.ts +0 -6
- package/dist/calldata/lifi/squid/index.js +0 -15
- package/dist/calldata/lifi/stargate/index.d.ts +0 -5
- package/dist/calldata/lifi/stargate/index.js +0 -15
- package/dist/calldata/lifi/swap/index.d.ts +0 -5
- package/dist/calldata/lifi/swap/index.js +0 -18
- package/dist/calldata/lifi/swap/swapMethod.d.ts +0 -2
- package/dist/calldata/lifi/swap/swapMethod.js +0 -40
- package/dist/calldata/match.d.ts +0 -3
- package/dist/calldata/match.js +0 -21
- package/dist/calldata/mayan/destination.d.ts +0 -2
- package/dist/calldata/mayan/destination.js +0 -13
- package/dist/calldata/mayan/fastMctpBridge.d.ts +0 -3
- package/dist/calldata/mayan/fastMctpBridge.js +0 -43
- package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +0 -3
- package/dist/calldata/mayan/fastMctpCreateOrder.js +0 -39
- package/dist/calldata/mayan/forward.d.ts +0 -8
- package/dist/calldata/mayan/forward.js +0 -35
- package/dist/calldata/mayan/forwardERC20.d.ts +0 -2
- package/dist/calldata/mayan/forwardERC20.js +0 -19
- package/dist/calldata/mayan/forwardEth.d.ts +0 -2
- package/dist/calldata/mayan/forwardEth.js +0 -16
- package/dist/calldata/mayan/index.d.ts +0 -4
- package/dist/calldata/mayan/index.js +0 -21
- package/dist/calldata/mayan/mctp.d.ts +0 -5
- package/dist/calldata/mayan/mctp.js +0 -41
- package/dist/calldata/mayan/readProtocol.d.ts +0 -2
- package/dist/calldata/mayan/readProtocol.js +0 -29
- package/dist/calldata/mayan/swapAndForwardERC20.d.ts +0 -2
- package/dist/calldata/mayan/swapAndForwardERC20.js +0 -24
- package/dist/calldata/mayan/swapAndForwardEth.d.ts +0 -2
- package/dist/calldata/mayan/swapAndForwardEth.js +0 -23
- package/dist/calldata/mayan/swiftCreateOrder.d.ts +0 -3
- package/dist/calldata/mayan/swiftCreateOrder.js +0 -49
- package/dist/calldata/mayan/validate.d.ts +0 -3
- package/dist/calldata/mayan/validate.js +0 -20
- package/dist/calldata/protocols.d.ts +0 -9
- package/dist/calldata/protocols.js +0 -56
- package/dist/calldata/relay/calls.d.ts +0 -13
- package/dist/calldata/relay/calls.js +0 -54
- package/dist/calldata/relay/depositErc20.d.ts +0 -2
- package/dist/calldata/relay/depositErc20.js +0 -22
- package/dist/calldata/relay/depositErc20Allowance.d.ts +0 -2
- package/dist/calldata/relay/depositErc20Allowance.js +0 -20
- package/dist/calldata/relay/depositNative.d.ts +0 -2
- package/dist/calldata/relay/depositNative.js +0 -20
- package/dist/calldata/relay/index.d.ts +0 -4
- package/dist/calldata/relay/index.js +0 -40
- package/dist/calldata/relay/multicall.d.ts +0 -2
- package/dist/calldata/relay/multicall.js +0 -15
- package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permit2TransferAndMulticall.js +0 -42
- package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permit3009TransferAndMulticall.js +0 -41
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +0 -2
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +0 -40
- package/dist/calldata/relay/permitTransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permitTransferAndMulticall.js +0 -34
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +0 -2
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +0 -35
- package/dist/calldata/relay/transferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/transferAndMulticall.js +0 -26
- package/dist/calldata/relay/validate.d.ts +0 -3
- package/dist/calldata/relay/validate.js +0 -18
- package/dist/calldata/resolve.d.ts +0 -2
- package/dist/calldata/resolve.js +0 -28
- package/dist/calldata/socket/bridge.d.ts +0 -2
- package/dist/calldata/socket/bridge.js +0 -28
- package/dist/calldata/socket/exec.d.ts +0 -2
- package/dist/calldata/socket/exec.js +0 -71
- package/dist/calldata/socket/index.d.ts +0 -4
- package/dist/calldata/socket/index.js +0 -13
- package/dist/calldata/socket/params.d.ts +0 -5
- package/dist/calldata/socket/params.js +0 -14
- package/dist/calldata/socket/protocols/ccip.d.ts +0 -2
- package/dist/calldata/socket/protocols/ccip.js +0 -32
- package/dist/calldata/socket/protocols/cctp.d.ts +0 -2
- package/dist/calldata/socket/protocols/cctp.js +0 -24
- package/dist/calldata/socket/protocols/eco.d.ts +0 -2
- package/dist/calldata/socket/protocols/eco.js +0 -20
- package/dist/calldata/socket/protocols/index.d.ts +0 -3
- package/dist/calldata/socket/protocols/index.js +0 -81
- package/dist/calldata/socket/protocols/native.d.ts +0 -2
- package/dist/calldata/socket/protocols/native.js +0 -70
- package/dist/calldata/socket/protocols/oft.d.ts +0 -2
- package/dist/calldata/socket/protocols/oft.js +0 -31
- package/dist/calldata/socket/protocols/swapsXYZ.d.ts +0 -2
- package/dist/calldata/socket/protocols/swapsXYZ.js +0 -62
- package/dist/calldata/socket/swapAndBridge.d.ts +0 -2
- package/dist/calldata/socket/swapAndBridge.js +0 -37
- package/dist/calldata/socket/validate.d.ts +0 -3
- package/dist/calldata/socket/validate.js +0 -21
- package/dist/calldata/types.d.ts +0 -82
- package/dist/calldata/types.js +0 -20
- package/dist/errors/constants.d.ts +0 -876
- package/dist/errors/constants.js +0 -883
- package/dist/errors/index.d.ts +0 -61
- package/dist/errors/index.js +0 -53
- package/dist/errors/sanitize.d.ts +0 -3
- package/dist/errors/sanitize.js +0 -75
- package/dist/providers/data.d.ts +0 -23
- package/dist/providers/data.js +0 -116
- package/dist/providers/errors.d.ts +0 -7
- package/dist/providers/errors.js +0 -10
- package/dist/providers/index.d.ts +0 -7
- package/dist/providers/index.js +0 -340
- package/dist/providers/layerswap.d.ts +0 -9
- package/dist/providers/layerswap.js +0 -95
- package/dist/providers/relay.d.ts +0 -59
- package/dist/providers/relay.js +0 -185
- package/dist/providers/request.d.ts +0 -23
- package/dist/providers/request.js +0 -69
- package/dist/providers/socket.d.ts +0 -5
- package/dist/providers/socket.js +0 -57
- package/dist/providers/types.d.ts +0 -36
- package/dist/providers/types.js +0 -1
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { asArray, asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
-
import { applyFirstSwap, swapDataArrayParam, swapDataParam } from '../params.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
|
-
});
|
package/dist/calldata/match.d.ts
DELETED
package/dist/calldata/match.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
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 custom = asString(args.customPayload) !== '0x';
|
|
25
|
-
const net = subtractFees(amountFloor ?? asBigint(args.amountIn), asBigint(args.redeemFee), asBigint(args.circleMaxFee));
|
|
26
|
-
const referrerBps = asBigint(args.referrerBps);
|
|
27
|
-
if (referrerBps > 100n)
|
|
28
|
-
throw new BridgeError(BRIDGE_ERRORS.INVALID_FASTMCTP_REFERRER_FEE);
|
|
29
|
-
// redeem caps the destination protocol fee at 100 bps; it is not fixed by the source deposit.
|
|
30
|
-
const minimum = net * (10000n - 100n - referrerBps) / 10000n;
|
|
31
|
-
return {
|
|
32
|
-
protocolMethod: 'bridge',
|
|
33
|
-
sourceToken: asString(args.tokenIn),
|
|
34
|
-
sourceAmount: asBigint(args.amountIn),
|
|
35
|
-
...destination,
|
|
36
|
-
outputTokenReference: custom ? undefined : token,
|
|
37
|
-
minOutputAmount: custom ? undefined : minimum,
|
|
38
|
-
bridgeReceiver: accountFromBytes32(asString(args.destAddr)),
|
|
39
|
-
receiver: custom ? undefined : accountFromBytes32(asString(args.destAddr)),
|
|
40
|
-
destinationCallData: custom ? asString(args.customPayload) : undefined,
|
|
41
|
-
referrer: accountFromBytes32(asString(args.referrerAddress)),
|
|
42
|
-
};
|
|
43
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { asBigint, asString, decodeCall } from '../abi.js';
|
|
2
|
-
import { finishForward } from './forward.js';
|
|
3
|
-
export const swapAndForwardEth = {
|
|
4
|
-
name: 'swapAndForwardEth',
|
|
5
|
-
selector: '0xfa74fd43',
|
|
6
|
-
decode(data, value) {
|
|
7
|
-
const args = decodeCall([
|
|
8
|
-
{ name: 'amountIn', kind: 'uint' },
|
|
9
|
-
{ name: 'swapProtocol', kind: 'address' },
|
|
10
|
-
{ name: 'swapData', kind: 'bytes' },
|
|
11
|
-
{ name: 'middleToken', kind: 'address' },
|
|
12
|
-
{ name: 'minMiddleAmount', kind: 'uint' },
|
|
13
|
-
{ name: 'mayanProtocol', kind: 'address' },
|
|
14
|
-
{ name: 'mayanData', kind: 'bytes' },
|
|
15
|
-
], data);
|
|
16
|
-
const amount = asBigint(args.amountIn);
|
|
17
|
-
return finishForward('swapAndForwardEth', asString(args.mayanProtocol), asString(args.mayanData), {
|
|
18
|
-
token: '0x0000000000000000000000000000000000000000',
|
|
19
|
-
amount: amount > 0n ? amount : value,
|
|
20
|
-
protocolAmount: asBigint(args.minMiddleAmount),
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
|
|
2
|
-
import { accountFromBytes32 } from '../hex.js';
|
|
3
|
-
import { mayanDestination } from './destination.js';
|
|
4
|
-
const params = {
|
|
5
|
-
name: 'params',
|
|
6
|
-
kind: 'tuple',
|
|
7
|
-
components: [
|
|
8
|
-
{ name: 'payloadType', kind: 'uint' },
|
|
9
|
-
{ name: 'trader', kind: 'bytes', size: 32 },
|
|
10
|
-
{ name: 'destAddr', kind: 'bytes', size: 32 },
|
|
11
|
-
{ name: 'destChainId', kind: 'uint' },
|
|
12
|
-
{ name: 'referrerAddr', kind: 'bytes', size: 32 },
|
|
13
|
-
{ name: 'tokenOut', kind: 'bytes', size: 32 },
|
|
14
|
-
{ name: 'minAmountOut', kind: 'uint' },
|
|
15
|
-
{ name: 'gasDrop', kind: 'uint' },
|
|
16
|
-
{ name: 'cancelFee', kind: 'uint' },
|
|
17
|
-
{ name: 'refundFee', kind: 'uint' },
|
|
18
|
-
{ name: 'deadline', kind: 'uint' },
|
|
19
|
-
{ name: 'referrerBps', kind: 'uint' },
|
|
20
|
-
{ name: 'auctionMode', kind: 'uint' },
|
|
21
|
-
{ name: 'random', kind: 'bytes', size: 32 },
|
|
22
|
-
],
|
|
23
|
-
};
|
|
24
|
-
export const SWIFT_CREATE_ORDER = '0xa3a30834';
|
|
25
|
-
export const decodeSwiftCreateOrder = (data) => {
|
|
26
|
-
const args = decodeCall([
|
|
27
|
-
{ name: 'tokenIn', kind: 'address' },
|
|
28
|
-
{ name: 'amountIn', kind: 'uint' },
|
|
29
|
-
params,
|
|
30
|
-
{ name: 'customPayload', kind: 'bytes' },
|
|
31
|
-
], data);
|
|
32
|
-
const order = asRecord(args.params);
|
|
33
|
-
const customPayload = asString(args.customPayload);
|
|
34
|
-
const destination = mayanDestination('wormhole', asBigint(order.destChainId), accountFromBytes32(asString(order.tokenOut)), asBigint(order.minAmountOut));
|
|
35
|
-
if (customPayload !== '0x') {
|
|
36
|
-
delete destination.outputToken;
|
|
37
|
-
delete destination.outputAmountReference;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
protocolMethod: 'createOrderWithToken',
|
|
41
|
-
sourceToken: asString(args.tokenIn),
|
|
42
|
-
sourceAmount: asBigint(args.amountIn),
|
|
43
|
-
...destination,
|
|
44
|
-
bridgeReceiver: accountFromBytes32(asString(order.destAddr)),
|
|
45
|
-
receiver: customPayload === '0x' ? accountFromBytes32(asString(order.destAddr)) : undefined,
|
|
46
|
-
destinationCallData: customPayload === '0x' ? undefined : customPayload,
|
|
47
|
-
referrer: accountFromBytes32(asString(order.referrerAddr)),
|
|
48
|
-
};
|
|
49
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS } from '../../errors/index.js';
|
|
2
|
-
import { isZeroWord } from '../hex.js';
|
|
3
|
-
export const mayanFailure = (parsed) => {
|
|
4
|
-
if (!parsed.protocolMethod) {
|
|
5
|
-
return BRIDGE_ERRORS.UNRECOGNIZED_MAYAN_PROTOCOL_CALLDATA;
|
|
6
|
-
}
|
|
7
|
-
if (parsed.destinationChainId === undefined && !parsed.destinationChainRef) {
|
|
8
|
-
return BRIDGE_ERRORS.MISSING_DESTINATION;
|
|
9
|
-
}
|
|
10
|
-
if (isZeroWord(parsed.receiver ?? parsed.bridgeReceiver)) {
|
|
11
|
-
return BRIDGE_ERRORS.MISSING_RECEIVER;
|
|
12
|
-
}
|
|
13
|
-
if ((parsed.sourceAmount ?? 0n) <= 0n) {
|
|
14
|
-
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
15
|
-
}
|
|
16
|
-
if (parsed.protocolMethod !== 'bridge' && parsed.outputToken === undefined && !parsed.outputTokenReference && !parsed.destinationCallData) {
|
|
17
|
-
return BRIDGE_ERRORS.MISSING_OUTPUT_TOKEN;
|
|
18
|
-
}
|
|
19
|
-
return undefined;
|
|
20
|
-
};
|