@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
package/dist/calldata/expect.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, bridgeFailure } from '../errors/index.js';
|
|
2
|
-
import { evmChainId } from './chains.js';
|
|
3
|
-
const NATIVE_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
4
|
-
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
5
|
-
const RATIO_SCALE = 1000000n;
|
|
6
|
-
export const knownCompare = (parsed) => ({
|
|
7
|
-
fromToken: parsed.sourceToken !== undefined,
|
|
8
|
-
fromAmount: parsed.sourceAmount !== undefined,
|
|
9
|
-
toToken: parsed.outputToken !== undefined,
|
|
10
|
-
toAmount: parsed.minOutputAmount !== undefined,
|
|
11
|
-
receiver: parsed.receiver !== undefined,
|
|
12
|
-
});
|
|
13
|
-
const isHexAddress = (value) => /^0x[0-9a-f]{40}$/i.test(value);
|
|
14
|
-
const isNativeToken = (value, chainId) => {
|
|
15
|
-
const normalized = value.toLowerCase();
|
|
16
|
-
const network = evmChainId(normalized);
|
|
17
|
-
return (normalized === NATIVE_ADDRESS ||
|
|
18
|
-
normalized === ZERO_ADDRESS ||
|
|
19
|
-
normalized === chainId.toLowerCase() ||
|
|
20
|
-
(network !== undefined && network === evmChainId(chainId)));
|
|
21
|
-
};
|
|
22
|
-
const sameToken = (actual, expected, chainId) => {
|
|
23
|
-
if (!actual) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (isNativeToken(actual, chainId) && isNativeToken(expected, chainId)) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (!isHexAddress(actual) || !isHexAddress(expected)) {
|
|
30
|
-
return actual.toLowerCase() === expected.toLowerCase();
|
|
31
|
-
}
|
|
32
|
-
return actual.toLowerCase() === expected.toLowerCase();
|
|
33
|
-
};
|
|
34
|
-
const parseAmount = (amount) => {
|
|
35
|
-
try {
|
|
36
|
-
return BigInt(amount);
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
/** Actual source payment may exceed local intent by at most 0.1%; lower payments still reject. */
|
|
43
|
-
export const sourceAmountMatches = (actual, expected) => actual !== undefined && expected >= 0n && actual >= expected && (actual - expected) * 1000n <= expected;
|
|
44
|
-
/** Allow a 5% relative difference from the quote's slippage-adjusted minimum. */
|
|
45
|
-
const minReceiveMatches = (minReceive, quoted, slippage) => {
|
|
46
|
-
if (minReceive <= 0n || quoted <= 0n || slippage < 0 || slippage >= 1) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
const ratioScaled = BigInt(Math.round((1 - slippage) * Number(RATIO_SCALE)));
|
|
50
|
-
const minimum = (quoted * ratioScaled) / RATIO_SCALE;
|
|
51
|
-
if (minimum <= 0n) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
if (minReceive === minimum) {
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
const difference = minReceive > minimum ? minReceive - minimum : minimum - minReceive;
|
|
58
|
-
return difference * 20n <= minimum;
|
|
59
|
-
};
|
|
60
|
-
export const expectationFailures = (parsed, expectation, chainId, mask) => {
|
|
61
|
-
const reasons = [];
|
|
62
|
-
if (expectation.toChainId && parsed.destinationChainRef && parsed.destinationChainId === undefined) {
|
|
63
|
-
reasons.push(BRIDGE_ERRORS.TO_CHAIN_MISMATCH);
|
|
64
|
-
}
|
|
65
|
-
if (expectation.toChainId && parsed.destinationChainId !== undefined) {
|
|
66
|
-
const expectedChain = evmChainId(expectation.toChainId);
|
|
67
|
-
if (expectedChain !== undefined && parsed.destinationChainId !== expectedChain)
|
|
68
|
-
reasons.push(BRIDGE_ERRORS.TO_CHAIN_MISMATCH);
|
|
69
|
-
}
|
|
70
|
-
if (mask.fromToken && !sameToken(parsed.sourceToken, expectation.fromTokenId, chainId)) {
|
|
71
|
-
reasons.push(BRIDGE_ERRORS.FROM_TOKEN_MISMATCH);
|
|
72
|
-
}
|
|
73
|
-
if (mask.fromAmount) {
|
|
74
|
-
const expectedAmount = parseAmount(expectation.fromTokenRawAmount);
|
|
75
|
-
if (expectedAmount === undefined || !sourceAmountMatches(parsed.sourceAmount, expectedAmount)) {
|
|
76
|
-
reasons.push(BRIDGE_ERRORS.FROM_AMOUNT_MISMATCH);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (mask.toToken &&
|
|
80
|
-
!sameToken(parsed.outputToken, expectation.toTokenId, expectation.toChainId || chainId)) {
|
|
81
|
-
reasons.push(BRIDGE_ERRORS.TO_TOKEN_MISMATCH);
|
|
82
|
-
}
|
|
83
|
-
if (mask.toAmount && expectation.toTokenRawAmount !== undefined) {
|
|
84
|
-
const quoted = parseAmount(expectation.toTokenRawAmount);
|
|
85
|
-
const slippage = Number(expectation.slippage);
|
|
86
|
-
if (quoted === undefined ||
|
|
87
|
-
parsed.minOutputAmount === undefined ||
|
|
88
|
-
!Number.isFinite(slippage) ||
|
|
89
|
-
!minReceiveMatches(parsed.minOutputAmount, quoted, slippage)) {
|
|
90
|
-
reasons.push(BRIDGE_ERRORS.MIN_RECEIVE_MISMATCH);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (mask.receiver && !sameToken(parsed.receiver, expectation.userAddress, chainId)) {
|
|
94
|
-
reasons.push(BRIDGE_ERRORS.RECEIVER_MISMATCH);
|
|
95
|
-
}
|
|
96
|
-
return reasons;
|
|
97
|
-
};
|
|
98
|
-
export const finishCheck = (aggregatorId, parsed, structural, expectation, chainId, mask) => {
|
|
99
|
-
mask = {
|
|
100
|
-
...mask,
|
|
101
|
-
toToken: mask.toToken && !(parsed.outputToken === undefined && parsed.outputTokenReference),
|
|
102
|
-
toAmount: mask.toAmount && !(parsed.minOutputAmount === undefined && parsed.outputAmountReference),
|
|
103
|
-
};
|
|
104
|
-
const expected = expectation
|
|
105
|
-
? expectationFailures(parsed, expectation, chainId, mask)
|
|
106
|
-
: [];
|
|
107
|
-
const unsupportedCall = (parsed.hasDestinationCall || parsed.destinationCallData !== undefined) &&
|
|
108
|
-
(parsed.receiver === undefined ||
|
|
109
|
-
(parsed.outputToken === undefined && !parsed.outputTokenReference) ||
|
|
110
|
-
(parsed.minOutputAmount === undefined && !parsed.outputAmountReference));
|
|
111
|
-
const errors = [
|
|
112
|
-
...(structural ? [structural] : []),
|
|
113
|
-
...(unsupportedCall ? [BRIDGE_ERRORS.UNSUPPORTED_DESTINATION_CALL] : []),
|
|
114
|
-
...expected,
|
|
115
|
-
].map((error) => ({ ...error, ...parsed.diagnostics, aggregatorId, chainId, method: parsed.method,
|
|
116
|
-
hasDestinationCall: Boolean(parsed.hasDestinationCall || parsed.destinationCallData !== undefined) }));
|
|
117
|
-
const unverifiedFields = Object.entries({
|
|
118
|
-
sourceToken: mask.fromToken, sourceAmount: mask.fromAmount, outputToken: mask.toToken,
|
|
119
|
-
minOutputAmount: mask.toAmount && expectation?.toTokenRawAmount !== undefined,
|
|
120
|
-
receiver: mask.receiver,
|
|
121
|
-
}).filter(([, checked]) => !expectation || !checked).map(([field]) => field);
|
|
122
|
-
if (expectation?.toChainId && (parsed.destinationChainId === undefined || evmChainId(expectation.toChainId) === undefined)) {
|
|
123
|
-
unverifiedFields.push('destinationChainId');
|
|
124
|
-
}
|
|
125
|
-
if (errors.length) {
|
|
126
|
-
return { ...bridgeFailure(errors), aggregatorId, method: parsed.method, parsed, unverifiedFields };
|
|
127
|
-
}
|
|
128
|
-
return { ok: true, aggregatorId, method: parsed.method, parsed, unverifiedFields, errors: [] };
|
|
129
|
-
};
|
package/dist/calldata/hex.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const normalizeHex: (value: string) => string;
|
|
2
|
-
export declare const hexToBytes: (value: string) => Uint8Array;
|
|
3
|
-
export declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
4
|
-
export declare const readSelector: (data: string) => string | null;
|
|
5
|
-
export declare const isZeroWord: (value?: string) => boolean;
|
|
6
|
-
export declare const accountFromBytes32: (word: string) => string;
|
package/dist/calldata/hex.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../errors/index.js';
|
|
2
|
-
const HEX = '0123456789abcdef';
|
|
3
|
-
export const normalizeHex = (value) => {
|
|
4
|
-
const hex = value.startsWith('0x') || value.startsWith('0X') ? value.slice(2) : value;
|
|
5
|
-
if (hex.length % 2 !== 0 || /[^0-9a-fA-F]/.test(hex)) {
|
|
6
|
-
throw new BridgeError(BRIDGE_ERRORS.INVALID_HEX);
|
|
7
|
-
}
|
|
8
|
-
return hex.toLowerCase();
|
|
9
|
-
};
|
|
10
|
-
export const hexToBytes = (value) => {
|
|
11
|
-
const hex = normalizeHex(value);
|
|
12
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
13
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
14
|
-
bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
15
|
-
}
|
|
16
|
-
return bytes;
|
|
17
|
-
};
|
|
18
|
-
export const bytesToHex = (bytes) => {
|
|
19
|
-
let hex = '0x';
|
|
20
|
-
for (const byte of bytes) {
|
|
21
|
-
hex += HEX[byte >> 4] + HEX[byte & 15];
|
|
22
|
-
}
|
|
23
|
-
return hex;
|
|
24
|
-
};
|
|
25
|
-
export const readSelector = (data) => {
|
|
26
|
-
try {
|
|
27
|
-
const hex = normalizeHex(data || '0x');
|
|
28
|
-
if (hex.length < 8 || /^0+$/.test(hex.slice(0, 8))) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
return `0x${hex.slice(0, 8)}`;
|
|
32
|
-
}
|
|
33
|
-
catch {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
export const isZeroWord = (value) => {
|
|
38
|
-
return !value || /^0x0*$/i.test(value);
|
|
39
|
-
};
|
|
40
|
-
export const accountFromBytes32 = (word) => {
|
|
41
|
-
const body = word.toLowerCase().replace(/^0x/, '').padStart(64, '0');
|
|
42
|
-
if (body.slice(0, 24) === '0'.repeat(24)) {
|
|
43
|
-
return `0x${body.slice(24)}`;
|
|
44
|
-
}
|
|
45
|
-
return `0x${body}`;
|
|
46
|
-
};
|
package/dist/calldata/index.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { BridgeError } from '../errors/index.js';
|
|
2
|
-
import type { BridgeErrorDetail } from '../errors/index.js';
|
|
3
|
-
import type { BridgeAggregatorId } from '../consts.js';
|
|
4
|
-
import type { BridgeCallExpectation } from './expect.js';
|
|
5
|
-
import type { BridgeCalldataTx, BridgeCheck, DecodeHit, ParsedBridgeCall } from './types.js';
|
|
6
|
-
export declare const CALLDATA_AGGREGATORS: BridgeAggregatorId[];
|
|
7
|
-
export declare class InvalidBridgeCalldataError extends BridgeError {
|
|
8
|
-
readonly aggregatorId: string;
|
|
9
|
-
readonly chainId: string;
|
|
10
|
-
readonly method: string | undefined;
|
|
11
|
-
readonly reason: string;
|
|
12
|
-
constructor(aggregatorId: string, chainId: string, method: string | undefined, reason: string, errors?: BridgeErrorDetail[]);
|
|
13
|
-
}
|
|
14
|
-
export declare const hasBridgeCalldata: (tx: BridgeCalldataTx) => boolean;
|
|
15
|
-
/** Detailed decoding for callers that need failures instead of a nullable result. */
|
|
16
|
-
export declare const decodeBridgeCalldataResult: (aggregatorId: string, tx: BridgeCalldataTx) => DecodeHit;
|
|
17
|
-
export declare const decodeBridgeCalldata: (aggregatorId: string, tx: BridgeCalldataTx) => ParsedBridgeCall | null;
|
|
18
|
-
export declare const validateBridgeCalldata: (aggregatorId: string, chainId: string, tx: BridgeCalldataTx, expectation?: BridgeCallExpectation) => BridgeCheck;
|
|
19
|
-
export type { BridgeCallExpectation } from './expect.js';
|
|
20
|
-
export type { BridgeCalldataTx, BridgeCheck, BridgeTokenReference, BridgeAmountReference, ParsedBridgeCall, DecodeHit } from './types.js';
|
package/dist/calldata/index.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError, asBridgeError, bridgeFailure } from '../errors/index.js';
|
|
2
|
-
import { decodeAcross, validateAcross } from './across/index.js';
|
|
3
|
-
import { readSelector } from './hex.js';
|
|
4
|
-
import { decodeLifi, validateLifi } from './lifi/index.js';
|
|
5
|
-
import { decodeMayan, validateMayan } from './mayan/index.js';
|
|
6
|
-
import { decodeRelay, validateRelay } from './relay/index.js';
|
|
7
|
-
import { decodeSocket, validateSocket } from './socket/index.js';
|
|
8
|
-
import { txCalldata, txValue } from './types.js';
|
|
9
|
-
import { sourceChainMismatch } from './chains.js';
|
|
10
|
-
import { calldataDiagnostics } from './diagnostics.js';
|
|
11
|
-
import { sanitizeBridgeError } from '../errors/sanitize.js';
|
|
12
|
-
const DECODERS = {
|
|
13
|
-
across: decodeAcross,
|
|
14
|
-
lifi: decodeLifi,
|
|
15
|
-
mayan: decodeMayan,
|
|
16
|
-
relay: decodeRelay,
|
|
17
|
-
socket: decodeSocket,
|
|
18
|
-
};
|
|
19
|
-
const VALIDATORS = {
|
|
20
|
-
across: validateAcross,
|
|
21
|
-
lifi: validateLifi,
|
|
22
|
-
mayan: validateMayan,
|
|
23
|
-
relay: validateRelay,
|
|
24
|
-
socket: validateSocket,
|
|
25
|
-
};
|
|
26
|
-
export const CALLDATA_AGGREGATORS = Object.keys(VALIDATORS);
|
|
27
|
-
export class InvalidBridgeCalldataError extends BridgeError {
|
|
28
|
-
constructor(aggregatorId, chainId, method, reason, errors) {
|
|
29
|
-
super(BRIDGE_ERRORS.INVALID_CALLDATA, { aggregatorId, chainId, method }, errors);
|
|
30
|
-
this.aggregatorId = aggregatorId;
|
|
31
|
-
this.chainId = chainId;
|
|
32
|
-
this.method = method;
|
|
33
|
-
this.reason = reason;
|
|
34
|
-
this.message = `Invalid bridge calldata for ${aggregatorId} on ${chainId}: ${reason}`;
|
|
35
|
-
this.name = 'InvalidBridgeCalldataError';
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export const hasBridgeCalldata = (tx) => {
|
|
39
|
-
return readSelector(txCalldata(tx)) !== null;
|
|
40
|
-
};
|
|
41
|
-
/** Detailed decoding for callers that need failures instead of a nullable result. */
|
|
42
|
-
export const decodeBridgeCalldataResult = (aggregatorId, tx) => {
|
|
43
|
-
const context = { aggregatorId, ...calldataDiagnostics(tx.data || tx.input) };
|
|
44
|
-
const decode = DECODERS[aggregatorId];
|
|
45
|
-
if (!decode)
|
|
46
|
-
return bridgeFailure([{ ...BRIDGE_ERRORS.UNSUPPORTED_CALLDATA_AGGREGATOR, ...context }]);
|
|
47
|
-
let value;
|
|
48
|
-
try {
|
|
49
|
-
value = txValue(tx);
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
return bridgeFailure(asBridgeError(error, BRIDGE_ERRORS.INVALID_TRANSACTION_VALUE, context).errors);
|
|
53
|
-
}
|
|
54
|
-
const hit = decode(txCalldata(tx), value);
|
|
55
|
-
return hit.ok ? hit : { ...hit, errors: hit.errors.map((error) => sanitizeBridgeError({ ...error, ...context })) };
|
|
56
|
-
};
|
|
57
|
-
export const decodeBridgeCalldata = (aggregatorId, tx) => {
|
|
58
|
-
const hit = decodeBridgeCalldataResult(aggregatorId, tx);
|
|
59
|
-
return hit.ok ? hit.parsed : null;
|
|
60
|
-
};
|
|
61
|
-
export const validateBridgeCalldata = (aggregatorId, chainId, tx, expectation) => {
|
|
62
|
-
const context = { aggregatorId, chainId, toChainId: expectation?.toChainId, ...calldataDiagnostics(tx.data || tx.input) };
|
|
63
|
-
if (sourceChainMismatch(chainId, tx.chainId))
|
|
64
|
-
return { ...bridgeFailure([{ ...BRIDGE_ERRORS.FROM_CHAIN_MISMATCH, ...context }]), aggregatorId };
|
|
65
|
-
if (expectation && tx.from !== undefined &&
|
|
66
|
-
(typeof tx.from !== 'string' || tx.from.toLowerCase() !== expectation.userAddress.toLowerCase())) {
|
|
67
|
-
return { ...bridgeFailure([{ ...BRIDGE_ERRORS.FROM_ADDRESS_MISMATCH, ...context }]), aggregatorId };
|
|
68
|
-
}
|
|
69
|
-
const validate = VALIDATORS[aggregatorId];
|
|
70
|
-
if (!validate) {
|
|
71
|
-
return {
|
|
72
|
-
...bridgeFailure([{ ...BRIDGE_ERRORS.UNSUPPORTED_CALLDATA_AGGREGATOR, ...context }]),
|
|
73
|
-
aggregatorId,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
let value;
|
|
77
|
-
try {
|
|
78
|
-
value = txValue(tx);
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return { ...bridgeFailure(asBridgeError(error, BRIDGE_ERRORS.INVALID_TRANSACTION_VALUE, context).errors), aggregatorId };
|
|
82
|
-
}
|
|
83
|
-
const check = validate(txCalldata(tx), value, expectation, chainId);
|
|
84
|
-
return { ...check, errors: check.errors.map((error) => sanitizeBridgeError({ ...error, ...context })) };
|
|
85
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
-
import { accountFromBytes32 } from '../../hex.js';
|
|
3
|
-
import { acrossPackedParam } from '../params.js';
|
|
4
|
-
export const startBridgeTokensViaAcrossV4ERC20Min = {
|
|
5
|
-
name: 'startBridgeTokensViaAcrossV4ERC20Min',
|
|
6
|
-
selector: '0x7260352d',
|
|
7
|
-
decode(data) {
|
|
8
|
-
const args = decodeCall([
|
|
9
|
-
acrossPackedParam,
|
|
10
|
-
{ name: 'sendingAssetId', kind: 'bytes', size: 32 },
|
|
11
|
-
{ name: 'inputAmount', kind: 'uint' },
|
|
12
|
-
], data);
|
|
13
|
-
const parameters = asRecord(args.parameters);
|
|
14
|
-
return {
|
|
15
|
-
aggregatorId: 'lifi',
|
|
16
|
-
method: 'startBridgeTokensViaAcrossV4ERC20Min',
|
|
17
|
-
kind: 'bridge',
|
|
18
|
-
sourceToken: accountFromBytes32(asString(args.sendingAssetId)),
|
|
19
|
-
sourceAmount: asBigint(args.inputAmount),
|
|
20
|
-
destinationChainId: asBigint(parameters.destinationChainId),
|
|
21
|
-
receiver: accountFromBytes32(asString(parameters.receiver)),
|
|
22
|
-
outputToken: accountFromBytes32(asString(parameters.receivingAssetId)),
|
|
23
|
-
minOutputAmount: asBigint(parameters.outputAmount),
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
-
import { accountFromBytes32 } from '../../hex.js';
|
|
3
|
-
import { acrossPackedParam } from '../params.js';
|
|
4
|
-
export const startBridgeTokensViaAcrossV4NativeMin = {
|
|
5
|
-
name: 'startBridgeTokensViaAcrossV4NativeMin',
|
|
6
|
-
selector: '0x72dd147e',
|
|
7
|
-
decode(data, value) {
|
|
8
|
-
const args = decodeCall([acrossPackedParam], data);
|
|
9
|
-
const parameters = asRecord(args.parameters);
|
|
10
|
-
return {
|
|
11
|
-
aggregatorId: 'lifi',
|
|
12
|
-
method: 'startBridgeTokensViaAcrossV4NativeMin',
|
|
13
|
-
kind: 'bridge',
|
|
14
|
-
sourceToken: '0x0000000000000000000000000000000000000000',
|
|
15
|
-
sourceAmount: value,
|
|
16
|
-
destinationChainId: asBigint(parameters.destinationChainId),
|
|
17
|
-
receiver: accountFromBytes32(asString(parameters.receiver)),
|
|
18
|
-
outputToken: accountFromBytes32(asString(parameters.receivingAssetId)),
|
|
19
|
-
minOutputAmount: asBigint(parameters.outputAmount),
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
};
|
|
@@ -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,19 +0,0 @@
|
|
|
1
|
-
import { bridgeShape } from '../shape.js';
|
|
2
|
-
import { startBridgeTokensViaAcrossV4ERC20Min } from './acrossV4Erc20Min.js';
|
|
3
|
-
import { startBridgeTokensViaAcrossV4NativeMin } from './acrossV4NativeMin.js';
|
|
4
|
-
import { acrossDataParam, applyAcrossData } from '../params.js';
|
|
5
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
6
|
-
export const methods = [
|
|
7
|
-
lifiBridgeMethod('startBridgeTokensViaAcrossV4', '0xa1f1ce43', [acrossDataParam], false, (parsed, args) => applyAcrossData(parsed, args.acrossData)),
|
|
8
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaAcrossV4', '0x1794958f', [acrossDataParam], true, (parsed, args) => applyAcrossData(parsed, args.acrossData)),
|
|
9
|
-
startBridgeTokensViaAcrossV4ERC20Min,
|
|
10
|
-
startBridgeTokensViaAcrossV4NativeMin,
|
|
11
|
-
];
|
|
12
|
-
export const compare = (parsed) => ({
|
|
13
|
-
fromToken: parsed.sourceToken !== undefined,
|
|
14
|
-
fromAmount: parsed.sourceAmount !== undefined,
|
|
15
|
-
toToken: true,
|
|
16
|
-
toAmount: true,
|
|
17
|
-
receiver: true,
|
|
18
|
-
});
|
|
19
|
-
export const check = bridgeShape;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const methods: import("../../abi.js").CalldataMethod[];
|
|
2
|
-
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
3
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../errors/constants.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../../../errors/index.js';
|
|
2
|
-
import { asRecord, asString } from '../../abi.js';
|
|
3
|
-
import { accountFromBytes32 } from '../../hex.js';
|
|
4
|
-
import { knownCompare } from '../../expect.js';
|
|
5
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
6
|
-
import { bridgeShape } from '../shape.js';
|
|
7
|
-
const allBridgeData = { name: 'allBridgeData', kind: 'tuple', components: [
|
|
8
|
-
{ name: 'recipient', kind: 'bytes', size: 32 }, { name: 'fees', kind: 'uint' },
|
|
9
|
-
{ name: 'receiveToken', kind: 'bytes', size: 32 }, { name: 'nonce', kind: 'uint' },
|
|
10
|
-
{ name: 'messenger', kind: 'uint' }, { name: 'payFeeWithSendingAsset', kind: 'bool' },
|
|
11
|
-
] };
|
|
12
|
-
const fill = (parsed, args) => {
|
|
13
|
-
const data = asRecord(args.allBridgeData);
|
|
14
|
-
const receiver = accountFromBytes32(asString(data.recipient));
|
|
15
|
-
if (receiver !== parsed.receiver)
|
|
16
|
-
throw new BridgeError(BRIDGE_ERRORS.ALLBRIDGE_RECEIVER_MISMATCH);
|
|
17
|
-
parsed.receiver = receiver;
|
|
18
|
-
parsed.outputToken = accountFromBytes32(asString(data.receiveToken));
|
|
19
|
-
// The destination pool prices vUSD when redeeming; there is no signed output minimum.
|
|
20
|
-
};
|
|
21
|
-
export const methods = [
|
|
22
|
-
lifiBridgeMethod('startBridgeTokensViaAllBridge', '0x6a51e9a9', [allBridgeData], false, fill),
|
|
23
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaAllBridge', '0x63267469', [allBridgeData], true, fill),
|
|
24
|
-
];
|
|
25
|
-
export const compare = knownCompare;
|
|
26
|
-
export const check = bridgeShape;
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { knownCompare } from '../../expect.js';
|
|
2
|
-
import { bridgeShape } from '../shape.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
import { applyCelerCircleData, celerCircleDataParam } from '../params.js';
|
|
5
|
-
export const methods = [
|
|
6
|
-
lifiBridgeMethod('startBridgeTokensViaCelerCircleBridge', '0xe0a4201c', [celerCircleDataParam], false, (parsed, args) => applyCelerCircleData(parsed, args.celerCircleData)),
|
|
7
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaCelerCircleBridge', '0x4f3b0759', [celerCircleDataParam], true, (parsed, args) => applyCelerCircleData(parsed, args.celerCircleData)),
|
|
8
|
-
];
|
|
9
|
-
export const compare = knownCompare;
|
|
10
|
-
export const check = bridgeShape;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const methods: import("../../abi.js").CalldataMethod[];
|
|
2
|
-
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
3
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../errors/constants.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../../../errors/index.js';
|
|
2
|
-
import { asRecord, asString } from '../../abi.js';
|
|
3
|
-
import { knownCompare } from '../../expect.js';
|
|
4
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
5
|
-
import { bridgeShape } from '../shape.js';
|
|
6
|
-
const centrifugeData = { name: 'centrifugeData', kind: 'tuple', components: [
|
|
7
|
-
{ name: 'nativeFee', kind: 'uint' }, { name: 'refundRecipient', kind: 'address' },
|
|
8
|
-
] };
|
|
9
|
-
const fill = (parsed, args) => {
|
|
10
|
-
if (asString(asRecord(args.centrifugeData).refundRecipient) !== parsed.receiver) {
|
|
11
|
-
throw new BridgeError(BRIDGE_ERRORS.CENTRIFUGE_REFUND_RECIPIENT_MISMATCH);
|
|
12
|
-
}
|
|
13
|
-
parsed.minOutputAmount = parsed.bridgeAmount;
|
|
14
|
-
parsed.outputTokenReference = { protocol: 'centrifuge', token: parsed.bridgeToken,
|
|
15
|
-
destinationChainId: parsed.destinationChainId };
|
|
16
|
-
};
|
|
17
|
-
export const methods = [
|
|
18
|
-
lifiBridgeMethod('startBridgeTokensViaCentrifuge', '0x0315138f', [centrifugeData], false, fill),
|
|
19
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaCentrifuge', '0x8fd4d4dd', [centrifugeData], true, fill),
|
|
20
|
-
];
|
|
21
|
-
export const compare = knownCompare;
|
|
22
|
-
export const check = bridgeShape;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ParsedBridgeCall } from '../../types.js';
|
|
2
|
-
export declare const methods: import("../../abi.js").CalldataMethod[];
|
|
3
|
-
export declare const compare: (parsed: ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
4
|
-
export declare const check: (parsed: ParsedBridgeCall) => import("../../../errors/constants.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../../../errors/index.js';
|
|
2
|
-
import { asBigint, asRecord, asString } from '../../abi.js';
|
|
3
|
-
import { knownCompare } from '../../expect.js';
|
|
4
|
-
import { LAYERZERO_CHAINS } from '../../protocols.js';
|
|
5
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
6
|
-
import { bridgeShape } from '../shape.js';
|
|
7
|
-
const fraxData = { name: 'fraxData', kind: 'tuple', components: [
|
|
8
|
-
{ name: 'oft', kind: 'address' }, { name: 'dstEid', kind: 'uint' },
|
|
9
|
-
{ name: 'nativeFee', kind: 'uint' }, { name: 'refundRecipient', kind: 'address' },
|
|
10
|
-
{ name: 'nonEVMReceiver', kind: 'bytes', size: 32 },
|
|
11
|
-
] };
|
|
12
|
-
const fill = (parsed, args) => {
|
|
13
|
-
const data = asRecord(args.fraxData);
|
|
14
|
-
const eid = asBigint(data.dstEid);
|
|
15
|
-
parsed.destinationChainRef = `layerzero:${eid}`;
|
|
16
|
-
parsed.destinationChainId = LAYERZERO_CHAINS[eid.toString()];
|
|
17
|
-
if (!/^0x0*$/.test(asString(data.nonEVMReceiver)))
|
|
18
|
-
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_NON_EVM_FRAX_RECEIVER);
|
|
19
|
-
const token = { protocol: 'frax', contract: asString(data.oft), token: parsed.bridgeToken,
|
|
20
|
-
destinationChainId: parsed.destinationChainId, destinationChainRef: parsed.destinationChainRef };
|
|
21
|
-
parsed.outputTokenReference = token;
|
|
22
|
-
parsed.outputAmountReference = { kind: 'dust', amount: parsed.bridgeAmount, token };
|
|
23
|
-
};
|
|
24
|
-
export const methods = [
|
|
25
|
-
lifiBridgeMethod('startBridgeTokensViaFrax', '0x678786ea', [fraxData], false, fill),
|
|
26
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaFrax', '0x07b8e4c7', [fraxData], true, fill),
|
|
27
|
-
];
|
|
28
|
-
export const compare = knownCompare;
|
|
29
|
-
export const check = bridgeShape;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const methods: import("../../abi.js").CalldataMethod[];
|
|
2
|
-
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
3
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { asRecord, asString } from '../../abi.js';
|
|
2
|
-
import { knownCompare } from '../../expect.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
import { bridgeShape } from '../shape.js';
|
|
5
|
-
const gardenData = { name: 'gardenData', kind: 'tuple', components: [
|
|
6
|
-
{ name: 'redeemer', kind: 'address' }, { name: 'refundAddress', kind: 'address' },
|
|
7
|
-
{ name: 'timelock', kind: 'uint' }, { name: 'secretHash', kind: 'bytes', size: 32 },
|
|
8
|
-
{ name: 'nonEvmReceiver', kind: 'bytes', size: 32 },
|
|
9
|
-
] };
|
|
10
|
-
const fill = (parsed, args) => {
|
|
11
|
-
parsed.requestId = asString(asRecord(args.gardenData).secretHash);
|
|
12
|
-
// Garden locks only the source HTLC; BridgeData's destination fields are event metadata.
|
|
13
|
-
delete parsed.receiver;
|
|
14
|
-
delete parsed.destinationChainId;
|
|
15
|
-
parsed.destinationChainRef = 'garden:offchain';
|
|
16
|
-
};
|
|
17
|
-
export const methods = [
|
|
18
|
-
lifiBridgeMethod('startBridgeTokensViaGarden', '0x5f9af35d', [gardenData], false, fill),
|
|
19
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaGarden', '0x76ad76fe', [gardenData], true, fill),
|
|
20
|
-
];
|
|
21
|
-
export const compare = knownCompare;
|
|
22
|
-
export const check = bridgeShape;
|
|
@@ -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 { applyGasZipData, gasZipDataParam } from '../params.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
export const methods = [
|
|
5
|
-
lifiBridgeMethod('startBridgeTokensViaGasZip', '0xfc5f1003', [gasZipDataParam], false, (parsed, args) => applyGasZipData(parsed, args.gasZipData)),
|
|
6
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaGasZip', '0x606326ff', [gasZipDataParam], true, (parsed, args) => applyGasZipData(parsed, args.gasZipData)),
|
|
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,4 +0,0 @@
|
|
|
1
|
-
import type { BridgeCallExpectation } from '../expect.js';
|
|
2
|
-
import type { BridgeCheck, DecodeHit } from '../types.js';
|
|
3
|
-
export declare const decodeLifi: (data: string, value: bigint) => DecodeHit;
|
|
4
|
-
export declare const validateLifi: (data: string, value: bigint, expectation?: BridgeCallExpectation, chainId?: string) => BridgeCheck;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, bridgeFailure } from '../../errors/index.js';
|
|
2
|
-
import { finishCheck } from '../expect.js';
|
|
3
|
-
import { matchMethod } from '../match.js';
|
|
4
|
-
import * as across from './across/index.js';
|
|
5
|
-
import * as allbridge from './allbridge/index.js';
|
|
6
|
-
import * as celer from './celer/index.js';
|
|
7
|
-
import * as centrifuge from './centrifuge/index.js';
|
|
8
|
-
import * as frax from './frax/index.js';
|
|
9
|
-
import * as gaszip from './gaszip/index.js';
|
|
10
|
-
import * as garden from './garden/index.js';
|
|
11
|
-
import * as intents from './intents/index.js';
|
|
12
|
-
import * as layerswap from './layerswap/index.js';
|
|
13
|
-
import * as mayan from './mayan/index.js';
|
|
14
|
-
import * as m0 from './m0/index.js';
|
|
15
|
-
import * as native from './native/index.js';
|
|
16
|
-
import * as paxos from './paxos/index.js';
|
|
17
|
-
import * as polymer from './polymer/index.js';
|
|
18
|
-
import * as relay from './relay/index.js';
|
|
19
|
-
import * as squid from './squid/index.js';
|
|
20
|
-
import * as stargate from './stargate/index.js';
|
|
21
|
-
import * as swap from './swap/index.js';
|
|
22
|
-
const ROUTES = [
|
|
23
|
-
across,
|
|
24
|
-
allbridge,
|
|
25
|
-
centrifuge,
|
|
26
|
-
garden,
|
|
27
|
-
m0,
|
|
28
|
-
native,
|
|
29
|
-
frax,
|
|
30
|
-
stargate,
|
|
31
|
-
intents,
|
|
32
|
-
polymer,
|
|
33
|
-
layerswap,
|
|
34
|
-
mayan,
|
|
35
|
-
celer,
|
|
36
|
-
paxos,
|
|
37
|
-
relay,
|
|
38
|
-
gaszip,
|
|
39
|
-
squid,
|
|
40
|
-
swap,
|
|
41
|
-
];
|
|
42
|
-
const METHODS = ROUTES.flatMap((route) => route.methods);
|
|
43
|
-
const routeFor = (method) => ROUTES.find((route) => route.methods.some((item) => item.name === method));
|
|
44
|
-
export const decodeLifi = (data, value) => matchMethod(METHODS, data, value);
|
|
45
|
-
export const validateLifi = (data, value, expectation, chainId = '') => {
|
|
46
|
-
const hit = decodeLifi(data, value);
|
|
47
|
-
if (!hit.ok) {
|
|
48
|
-
return { ...hit, aggregatorId: 'lifi' };
|
|
49
|
-
}
|
|
50
|
-
const route = routeFor(hit.parsed.method);
|
|
51
|
-
if (!route) {
|
|
52
|
-
return {
|
|
53
|
-
...bridgeFailure([BRIDGE_ERRORS.UNSUPPORTED_METHOD]),
|
|
54
|
-
aggregatorId: 'lifi',
|
|
55
|
-
method: hit.parsed.method,
|
|
56
|
-
parsed: hit.parsed,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return finishCheck('lifi', hit.parsed, route.check(hit.parsed), expectation, chainId, route.compare(hit.parsed));
|
|
60
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { knownCompare } from '../../expect.js';
|
|
2
|
-
import { bridgeShape } from '../shape.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
import { applyLifiIntentData, lifiIntentDataParam } from '../params.js';
|
|
5
|
-
export const methods = [
|
|
6
|
-
lifiBridgeMethod('startBridgeTokensViaLiFiIntentEscrowV2', '0x7dbcf1d9', [lifiIntentDataParam], false, (parsed, args) => applyLifiIntentData(parsed, args.lifiIntentData)),
|
|
7
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaLiFiIntentEscrowV2', '0x6d21c5df', [lifiIntentDataParam], true, (parsed, args) => applyLifiIntentData(parsed, args.lifiIntentData)),
|
|
8
|
-
];
|
|
9
|
-
export const compare = knownCompare;
|
|
10
|
-
export const check = bridgeShape;
|
|
@@ -1,4 +0,0 @@
|
|
|
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;
|