@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,71 @@
|
|
|
1
|
+
import { asBigint, asString, decodeCall, decodeParameters } from '../../abi.js';
|
|
2
|
+
import { NATIVE_TOKEN, isNative } from '../../protocols.js';
|
|
3
|
+
import { readSelector } from '../../hex.js';
|
|
4
|
+
export const readNativeBridge = (data, target, value) => {
|
|
5
|
+
const selector = readSelector(data);
|
|
6
|
+
if (selector === '0x679b6ded') {
|
|
7
|
+
const a = decodeCall([
|
|
8
|
+
{ name: 'to', kind: 'address' }, { name: 'l2CallValue', kind: 'uint' }, { name: 'maxSubmissionCost', kind: 'uint' },
|
|
9
|
+
{ name: 'excessFeeRefundAddress', kind: 'address' }, { name: 'callValueRefundAddress', kind: 'address' },
|
|
10
|
+
{ name: 'gasLimit', kind: 'uint' }, { name: 'maxFeePerGas', kind: 'uint' }, { name: 'data', kind: 'bytes' },
|
|
11
|
+
], data);
|
|
12
|
+
const destinationChainId = target === '0x4dbd4fc535ac27206064b68ffcf827b0a60bab3f' ? 42161n
|
|
13
|
+
: target === '0x1a07cc4bd17e0118bdb54d70990d2158abad7a2d' ? 4663n : undefined;
|
|
14
|
+
const callData = asString(a.data);
|
|
15
|
+
return { protocolMethod: 'createRetryableTicket', destinationChainId,
|
|
16
|
+
refundRecipients: [asString(a.callValueRefundAddress), asString(a.excessFeeRefundAddress)],
|
|
17
|
+
receiver: callData === '0x' ? asString(a.to) : undefined, bridgeReceiver: asString(a.to),
|
|
18
|
+
outputToken: callData === '0x' ? NATIVE_TOKEN : undefined,
|
|
19
|
+
minOutputAmount: callData === '0x' ? asBigint(a.l2CallValue) : undefined,
|
|
20
|
+
destinationCallData: callData === '0x' ? undefined : callData };
|
|
21
|
+
}
|
|
22
|
+
if (selector === '0xd2ce7d65') {
|
|
23
|
+
const a = decodeCall([
|
|
24
|
+
{ name: 'token', kind: 'address' }, { name: 'to', kind: 'address' }, { name: 'amount', kind: 'uint' },
|
|
25
|
+
{ name: 'maxGas', kind: 'uint' }, { name: 'gasPriceBid', kind: 'uint' }, { name: 'data', kind: 'bytes' },
|
|
26
|
+
], data);
|
|
27
|
+
const ref = { protocol: 'arbitrum', contract: target, token: asString(a.token), destinationChainId: target === '0x72ce9c846789fdb6fc1f34ac4ad25dd9ef7031ef' ? 42161n : undefined };
|
|
28
|
+
return { protocolMethod: 'outboundTransfer', receiver: asString(a.to),
|
|
29
|
+
destinationChainId: ref.destinationChainId, outputTokenReference: ref, minOutputAmount: asBigint(a.amount) };
|
|
30
|
+
}
|
|
31
|
+
if (selector === '0x838b2520' || selector === '0x9a2ac6d5') {
|
|
32
|
+
const erc20 = selector === '0x838b2520';
|
|
33
|
+
const a = decodeCall([
|
|
34
|
+
...(erc20 ? [{ name: 'localToken', kind: 'address' }, { name: 'remoteToken', kind: 'address' }] : []),
|
|
35
|
+
{ name: 'to', kind: 'address' }, ...(erc20 ? [{ name: 'amount', kind: 'uint' }] : []),
|
|
36
|
+
{ name: 'minGasLimit', kind: 'uint' }, { name: 'extraData', kind: 'bytes' },
|
|
37
|
+
], data);
|
|
38
|
+
return { protocolMethod: erc20 ? 'depositERC20To' : 'depositETHTo',
|
|
39
|
+
destinationChainId: target === '0x3154cf16ccdb4c6d922629664174b904d80f2c35' ? 8453n : undefined,
|
|
40
|
+
receiver: asString(a.to), outputToken: erc20 ? asString(a.remoteToken) : NATIVE_TOKEN,
|
|
41
|
+
minOutputAmount: erc20 ? asBigint(a.amount) : value };
|
|
42
|
+
}
|
|
43
|
+
if (selector === '0x4faa8a26') {
|
|
44
|
+
const a = decodeCall([{ name: 'user', kind: 'address' }], data);
|
|
45
|
+
return { protocolMethod: 'depositEtherFor', destinationChainId: 137n, receiver: asString(a.user),
|
|
46
|
+
outputToken: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', minOutputAmount: value };
|
|
47
|
+
}
|
|
48
|
+
if (selector === '0xe3dec8fb') {
|
|
49
|
+
const a = decodeCall([{ name: 'user', kind: 'address' }, { name: 'rootToken', kind: 'address' }, { name: 'depositData', kind: 'bytes' }], data);
|
|
50
|
+
const amount = asBigint(decodeParameters([{ name: 'amount', kind: 'uint' }], asString(a.depositData)).amount);
|
|
51
|
+
return { protocolMethod: 'depositFor', destinationChainId: 137n, receiver: asString(a.user), minOutputAmount: amount,
|
|
52
|
+
outputTokenReference: { protocol: 'polygon', contract: target, token: asString(a.rootToken), destinationChainId: 137n } };
|
|
53
|
+
}
|
|
54
|
+
if (selector === '0x8b9e4f93' || selector === '0xad58bdd1') {
|
|
55
|
+
const polygon = selector === '0x8b9e4f93';
|
|
56
|
+
const a = decodeCall([{ name: 'token', kind: 'address' }, { name: 'receiver', kind: 'address' }, { name: 'amount', kind: 'uint' }], data);
|
|
57
|
+
const token = asString(a.token);
|
|
58
|
+
const destinationChainId = polygon ? 137n : 100n;
|
|
59
|
+
let outputToken;
|
|
60
|
+
if (polygon && ['0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', '0x455e53cbb86018ac2b8092fdcd39d8444affc3f6'].includes(token))
|
|
61
|
+
outputToken = NATIVE_TOKEN;
|
|
62
|
+
if (!polygon && ['0x6b175474e89094c44da98b954eedeac495271d0f', '0xdc035d45d973e3ec169d2276ddab16f1e407384f'].includes(token))
|
|
63
|
+
outputToken = NATIVE_TOKEN;
|
|
64
|
+
if (!polygon && isNative(token))
|
|
65
|
+
outputToken = '0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1';
|
|
66
|
+
return { protocolMethod: polygon ? 'depositERC20ForUser' : 'relayTokens', destinationChainId,
|
|
67
|
+
receiver: asString(a.receiver), minOutputAmount: asBigint(a.amount), outputToken,
|
|
68
|
+
outputTokenReference: outputToken ? undefined : { protocol: polygon ? 'polygon' : 'gnosis', contract: target, token, destinationChainId } };
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
+
import { accountFromBytes32, readSelector } from '../../hex.js';
|
|
3
|
+
import { LAYERZERO_CHAINS } from '../../protocols.js';
|
|
4
|
+
const send = { name: 'send', kind: 'tuple', components: [
|
|
5
|
+
{ name: 'dstEid', kind: 'uint' }, { name: 'to', kind: 'bytes', size: 32 },
|
|
6
|
+
{ name: 'amountLD', kind: 'uint' }, { name: 'minAmountLD', kind: 'uint' },
|
|
7
|
+
{ name: 'extraOptions', kind: 'bytes' }, { name: 'composeMsg', kind: 'bytes' }, { name: 'oftCmd', kind: 'bytes' },
|
|
8
|
+
] };
|
|
9
|
+
export const readOft = (data, target, token) => {
|
|
10
|
+
const legacy = readSelector(data) === '0x2cdf0b95';
|
|
11
|
+
const a = legacy ? decodeCall([
|
|
12
|
+
{ name: 'from', kind: 'address' }, { name: 'dstEid', kind: 'uint' }, { name: 'to', kind: 'bytes', size: 32 },
|
|
13
|
+
{ name: 'amountLD', kind: 'uint' }, { name: 'minAmountLD', kind: 'uint' },
|
|
14
|
+
{ name: 'callParams', kind: 'tuple', components: [
|
|
15
|
+
{ name: 'refundAddress', kind: 'address' }, { name: 'zroPaymentAddress', kind: 'address' }, { name: 'adapterParams', kind: 'bytes' },
|
|
16
|
+
] },
|
|
17
|
+
], data) : asRecord(decodeCall([send, { name: 'fee', kind: 'tuple', components: [
|
|
18
|
+
{ name: 'nativeFee', kind: 'uint' }, { name: 'lzTokenFee', kind: 'uint' },
|
|
19
|
+
] }, { name: 'refundAddress', kind: 'address' }], data).send);
|
|
20
|
+
const id = asBigint(a.dstEid);
|
|
21
|
+
const ref = { protocol: 'oft', contract: target, token,
|
|
22
|
+
destinationChainId: LAYERZERO_CHAINS[id.toString()], destinationChainRef: `layerzero:${id}` };
|
|
23
|
+
// Stargate's one-byte bus command changes transport, not the recipient. Compose
|
|
24
|
+
// can execute arbitrary destination code and still needs a dedicated decoder.
|
|
25
|
+
const direct = legacy || (asString(a.composeMsg) === '0x' && ['0x', '0x01'].includes(asString(a.oftCmd)));
|
|
26
|
+
return { protocolMethod: legacy ? 'sendFrom' : 'send', destinationChainId: ref.destinationChainId,
|
|
27
|
+
destinationChainRef: ref.destinationChainRef, bridgeReceiver: accountFromBytes32(asString(a.to)),
|
|
28
|
+
receiver: direct ? accountFromBytes32(asString(a.to)) : undefined,
|
|
29
|
+
outputTokenReference: direct ? ref : undefined,
|
|
30
|
+
outputAmountReference: direct ? { kind: 'decimals', amount: asBigint(a.minAmountLD), token: ref } : undefined,
|
|
31
|
+
destinationCallData: direct ? undefined : asString(a.composeMsg),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, BridgeError } from '../../../errors/index.js';
|
|
2
|
+
import { asArray, asBigint, asRecord, asString, decodeCall, decodeParameters } from '../../abi.js';
|
|
3
|
+
import { accountFromBytes32, readSelector } from '../../hex.js';
|
|
4
|
+
const swap = { name: 'swap', kind: 'tuple', components: [
|
|
5
|
+
{ name: 'swapperId', kind: 'uint' }, { name: 'params', kind: 'tuple', components: [
|
|
6
|
+
{ name: 'amountIn', kind: 'uint' }, { name: 'amountOut', kind: 'uint' }, { name: 'dustOut', kind: 'uint' },
|
|
7
|
+
{ name: 'tokenIn', kind: 'address' }, { name: 'tokenOut', kind: 'address' }, { name: 'direction', kind: 'uint' },
|
|
8
|
+
{ name: 'refund', kind: 'address' }, { name: 'additionalArgs', kind: 'bytes' },
|
|
9
|
+
] },
|
|
10
|
+
] };
|
|
11
|
+
const instructions = { name: 'instructions', kind: 'tuple', components: [
|
|
12
|
+
swap, { name: 'target', kind: 'address' }, { name: 'paymentOperator', kind: 'address' }, { name: 'refund', kind: 'address' },
|
|
13
|
+
{ name: 'executionFee', kind: 'uint' }, { name: 'payload', kind: 'bytes' }, { name: 'txId', kind: 'bytes', size: 32 },
|
|
14
|
+
] };
|
|
15
|
+
const fee = { name: 'fee', kind: 'tuple', components: [
|
|
16
|
+
{ name: 'appId', kind: 'bytes', size: 4 }, { name: 'affiliateId', kind: 'bytes', size: 4 },
|
|
17
|
+
{ name: 'bridgeFee', kind: 'uint' }, { name: 'deadline', kind: 'uint' }, { name: 'chainId', kind: 'uint' },
|
|
18
|
+
{ name: 'fees', kind: 'array', item: { name: 'fee', kind: 'tuple', components: [
|
|
19
|
+
{ name: 'recipient', kind: 'address' }, { name: 'token', kind: 'address' }, { name: 'amount', kind: 'uint' },
|
|
20
|
+
] } },
|
|
21
|
+
] };
|
|
22
|
+
export const readSwapsXYZ = (data) => {
|
|
23
|
+
const a = decodeCall([instructions, fee, { name: 'feeSignature', kind: 'bytes' },
|
|
24
|
+
...(readSelector(data) === '0x0c751e0b' ? [{ name: 'executionSignature', kind: 'bytes' }] : [])], data);
|
|
25
|
+
const payload = asString(asRecord(a.instructions).payload);
|
|
26
|
+
if (readSelector(payload) !== '0x24856bc3')
|
|
27
|
+
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SWAPS_XYZ_EXECUTION);
|
|
28
|
+
const commandData = decodeCall([{ name: 'commands', kind: 'bytes' },
|
|
29
|
+
{ name: 'inputs', kind: 'array', item: { name: 'input', kind: 'bytes' } }], payload);
|
|
30
|
+
const commands = asString(commandData.commands).slice(2).match(/../g) ?? [];
|
|
31
|
+
const inputs = asArray(commandData.inputs);
|
|
32
|
+
if (commands.length !== inputs.length)
|
|
33
|
+
throw new BridgeError(BRIDGE_ERRORS.HYPERLANE_COMMAND_LENGTH_MISMATCH, { commandCount: commands.length });
|
|
34
|
+
let result;
|
|
35
|
+
for (let i = 0; i < commands.length; i += 1) {
|
|
36
|
+
const command = Number.parseInt(commands[i], 16);
|
|
37
|
+
if ([0, 1, 2, 3, 8].includes(command))
|
|
38
|
+
continue;
|
|
39
|
+
if (![4, 5].includes(command) || result)
|
|
40
|
+
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_HYPERLANE_OPERATION, { commandByte: command, commandCount: commands.length });
|
|
41
|
+
const p = decodeParameters([
|
|
42
|
+
{ name: 'router', kind: 'address' }, { name: 'destination', kind: 'uint' }, { name: 'recipient', kind: 'bytes', size: 32 },
|
|
43
|
+
{ name: 'amount', kind: 'uint' }, ...(command === 5 ? [{ name: 'targetRouter', kind: 'bytes', size: 32 }] : []),
|
|
44
|
+
{ name: 'value', kind: 'uint' }, { name: 'token', kind: 'address' }, { name: 'approval', kind: 'uint' },
|
|
45
|
+
], asString(inputs[i]));
|
|
46
|
+
const domain = asBigint(p.destination);
|
|
47
|
+
const ref = { protocol: 'hyperlane', contract: asString(p.router), token: asString(p.token),
|
|
48
|
+
destinationChainRef: `hyperlane:${domain}`,
|
|
49
|
+
destinationChainId: [1n, 56n, 42161n, 8453n].includes(domain) ? domain : undefined,
|
|
50
|
+
destinationContract: command === 5 ? accountFromBytes32(asString(p.targetRouter)) : undefined };
|
|
51
|
+
const amount = asBigint(p.amount);
|
|
52
|
+
if (amount === 1n << 255n)
|
|
53
|
+
throw new BridgeError(BRIDGE_ERRORS.HYPERLANE_BALANCE_AMOUNT_REQUIRES_EXECUTION_STATE);
|
|
54
|
+
result = { protocolMethod: `swaps-xyz/execute/${command === 5 ? 'transferRemoteTo' : 'transferRemote'}`,
|
|
55
|
+
destinationChainId: ref.destinationChainId, destinationChainRef: ref.destinationChainRef,
|
|
56
|
+
receiver: accountFromBytes32(asString(p.recipient)), outputTokenReference: ref,
|
|
57
|
+
outputAmountReference: { kind: 'scale', amount, token: ref } };
|
|
58
|
+
}
|
|
59
|
+
if (!result)
|
|
60
|
+
throw new BridgeError(BRIDGE_ERRORS.MISSING_HYPERLANE_TRANSFER);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, BridgeError, asBridgeError } from '../../errors/index.js';
|
|
2
|
+
import { innerCallDiagnostics } from '../diagnostics.js';
|
|
3
|
+
import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
|
|
4
|
+
import { subtractFees } from '../protocols.js';
|
|
5
|
+
import { bridgeData, fee, input, swapData } from './params.js';
|
|
6
|
+
import { readSocketBridge, spliceBridgeAmount } from './protocols/index.js';
|
|
7
|
+
export const swapAndBridge = {
|
|
8
|
+
name: 'swapAndBridge', selector: '0x324012e2',
|
|
9
|
+
decode(data) {
|
|
10
|
+
const a = decodeCall([{ name: 'quoteId', kind: 'bytes', size: 32 }, { name: 'flags', kind: 'uint' },
|
|
11
|
+
input, fee, swapData, { name: 'swapCallData', kind: 'bytes' }, bridgeData,
|
|
12
|
+
{ name: 'bridgeCallData', kind: 'bytes' }], data);
|
|
13
|
+
const source = asRecord(a.input);
|
|
14
|
+
const swap = asRecord(a.swapData);
|
|
15
|
+
const hop = asRecord(a.bridgeData);
|
|
16
|
+
const flags = asBigint(a.flags);
|
|
17
|
+
const amount = subtractFees(asBigint(swap.minOutput), (flags & 1n) !== 0n ? asBigint(asRecord(a.fee).amount) : 0n);
|
|
18
|
+
const value = asBigint(hop.value) + ((flags & 4n) !== 0n ? amount : 0n);
|
|
19
|
+
const token = asString(swap.outputToken);
|
|
20
|
+
const target = asString(hop.target);
|
|
21
|
+
const bridgeCallData = asString(a.bridgeCallData);
|
|
22
|
+
let callData;
|
|
23
|
+
try {
|
|
24
|
+
callData = spliceBridgeAmount(bridgeCallData, flags, amount);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, innerCallDiagnostics(bridgeCallData, 'protocol'));
|
|
28
|
+
}
|
|
29
|
+
const protocol = readSocketBridge(callData, target, token, value, asString(hop.approvalSpender));
|
|
30
|
+
if (protocol.protocolMethod === 'receiveNative' && protocol.bridgeAmount !== amount) {
|
|
31
|
+
throw new BridgeError(BRIDGE_ERRORS.SOCKET_DEPOSIT_AMOUNT_MISMATCH, protocol.diagnostics);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
aggregatorId: 'socket', method: 'swapAndBridge', kind: 'bridge', quoteId: asString(a.quoteId),
|
|
35
|
+
sourceToken: asString(source.inputToken), sourceAmount: asBigint(source.inputAmount), depositor: asString(source.user),
|
|
36
|
+
bridgeToken: token, bridgeAmount: amount,
|
|
37
|
+
referrer: asString(asRecord(a.fee).receiver), innerTarget: target,
|
|
38
|
+
...protocol,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS } from '../../errors/index.js';
|
|
2
|
+
import { isZeroWord } from '../hex.js';
|
|
3
|
+
export const socketFailure = (parsed, expectedUser) => {
|
|
4
|
+
if (expectedUser && parsed.depositor !== expectedUser.toLowerCase())
|
|
5
|
+
return BRIDGE_ERRORS.DEPOSITOR_MISMATCH;
|
|
6
|
+
if (parsed.method === 'exec') {
|
|
7
|
+
return BRIDGE_ERRORS.UNRECOGNIZED_SOCKET_ROUTER_CALLDATA;
|
|
8
|
+
}
|
|
9
|
+
if (!parsed.quoteId || isZeroWord(parsed.quoteId)) {
|
|
10
|
+
return BRIDGE_ERRORS.MISSING_QUOTE_ID;
|
|
11
|
+
}
|
|
12
|
+
if (['receiveERC20', 'receiveNative'].includes(parsed.protocolMethod ?? '') && parsed.orderId !== parsed.quoteId) {
|
|
13
|
+
return BRIDGE_ERRORS.SOCKET_RFQ_QUOTE_ID_MISMATCH;
|
|
14
|
+
}
|
|
15
|
+
if (!parsed.protocolMethod)
|
|
16
|
+
return BRIDGE_ERRORS.UNRECOGNIZED_SOCKET_BRIDGE_CALLDATA;
|
|
17
|
+
if (parsed.sourceToken === undefined) {
|
|
18
|
+
return BRIDGE_ERRORS.MISSING_SOURCE_TOKEN;
|
|
19
|
+
}
|
|
20
|
+
if ((parsed.sourceAmount ?? 0n) <= 0n) {
|
|
21
|
+
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { BridgeErrorCode, BridgeErrorStage, BridgeErrorDetail, BridgeErrorContext } from '../errors/index.js';
|
|
2
|
+
import type { BridgeAggregatorId } from '../consts.js';
|
|
3
|
+
export type BridgeTokenReference = {
|
|
4
|
+
protocol: 'token' | 'cctp' | 'oft' | 'frax' | 'ccip' | 'polygon' | 'gnosis' | 'arbitrum' | 'superset' | 'hyperlane' | 'across-native' | 'centrifuge';
|
|
5
|
+
contract?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
destinationChainId?: bigint;
|
|
8
|
+
destinationChainRef?: string;
|
|
9
|
+
destinationContract?: string;
|
|
10
|
+
tokenId?: string;
|
|
11
|
+
};
|
|
12
|
+
export type BridgeAmountReference = {
|
|
13
|
+
kind: 'decimals' | 'normalized' | 'dust' | 'scale' | 'fees';
|
|
14
|
+
amount: bigint;
|
|
15
|
+
token: BridgeTokenReference;
|
|
16
|
+
decimals?: number;
|
|
17
|
+
maxFee?: bigint;
|
|
18
|
+
};
|
|
19
|
+
export type ParsedBridgeCall = {
|
|
20
|
+
aggregatorId: BridgeAggregatorId;
|
|
21
|
+
method: string;
|
|
22
|
+
kind: 'bridge' | 'swap' | 'deposit';
|
|
23
|
+
sourceToken?: string;
|
|
24
|
+
sourceAmount?: bigint;
|
|
25
|
+
destinationChainId?: bigint;
|
|
26
|
+
destinationChainRef?: string;
|
|
27
|
+
receiver?: string;
|
|
28
|
+
/** Refund beneficiaries encoded in this transaction, independent of final delivery. */
|
|
29
|
+
refundRecipients?: string[];
|
|
30
|
+
/** Set when a fixed allowlisted contract satisfies the receiver check. */
|
|
31
|
+
fixedReceiver?: boolean;
|
|
32
|
+
outputToken?: string;
|
|
33
|
+
minOutputAmount?: bigint;
|
|
34
|
+
orderId?: string;
|
|
35
|
+
quoteId?: string;
|
|
36
|
+
referrer?: string;
|
|
37
|
+
protocolMethod?: string;
|
|
38
|
+
spokePool?: string;
|
|
39
|
+
innerTarget?: string;
|
|
40
|
+
depositor?: string;
|
|
41
|
+
bridgeToken?: string;
|
|
42
|
+
bridgeAmount?: bigint;
|
|
43
|
+
bridgeReceiver?: string;
|
|
44
|
+
bridgeOutputToken?: string;
|
|
45
|
+
bridgeOutputAmount?: bigint;
|
|
46
|
+
requestId?: string;
|
|
47
|
+
outputTokenReference?: BridgeTokenReference;
|
|
48
|
+
outputAmountReference?: BridgeAmountReference;
|
|
49
|
+
destinationCallData?: string;
|
|
50
|
+
hasDestinationCall?: boolean;
|
|
51
|
+
unresolvedFields?: string[];
|
|
52
|
+
/** Non-personal call structure retained for unsupported-path diagnostics. */
|
|
53
|
+
diagnostics?: BridgeErrorContext;
|
|
54
|
+
};
|
|
55
|
+
export type DecodeHit = {
|
|
56
|
+
ok: true;
|
|
57
|
+
parsed: ParsedBridgeCall;
|
|
58
|
+
} | {
|
|
59
|
+
ok: false;
|
|
60
|
+
method?: string;
|
|
61
|
+
reason: string;
|
|
62
|
+
error_code: BridgeErrorCode;
|
|
63
|
+
stage: BridgeErrorStage;
|
|
64
|
+
errors: BridgeErrorDetail[];
|
|
65
|
+
};
|
|
66
|
+
export type BridgeCheck = {
|
|
67
|
+
ok: boolean;
|
|
68
|
+
aggregatorId: string;
|
|
69
|
+
method?: string;
|
|
70
|
+
reason?: string;
|
|
71
|
+
parsed?: ParsedBridgeCall;
|
|
72
|
+
unverifiedFields?: string[];
|
|
73
|
+
error_code?: BridgeErrorCode;
|
|
74
|
+
stage?: BridgeErrorStage;
|
|
75
|
+
errors: BridgeErrorDetail[];
|
|
76
|
+
};
|
|
77
|
+
export type BridgeCalldataTx = {
|
|
78
|
+
to?: string;
|
|
79
|
+
from?: string;
|
|
80
|
+
chainId?: string | number | bigint;
|
|
81
|
+
data?: string;
|
|
82
|
+
input?: string;
|
|
83
|
+
value?: string | number | bigint;
|
|
84
|
+
};
|
|
85
|
+
export declare const txCalldata: (tx: BridgeCalldataTx) => string;
|
|
86
|
+
export declare const txValue: (tx: BridgeCalldataTx) => bigint;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BRIDGE_ERRORS, BridgeError } from '../errors/index.js';
|
|
2
|
+
export const txCalldata = (tx) => tx.data || tx.input || '0x';
|
|
3
|
+
export const txValue = (tx) => {
|
|
4
|
+
const { value } = tx;
|
|
5
|
+
if (value === undefined || value === null || value === '') {
|
|
6
|
+
return 0n;
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === 'number' && !Number.isSafeInteger(value))
|
|
9
|
+
throw new BridgeError(BRIDGE_ERRORS.INVALID_TRANSACTION_VALUE);
|
|
10
|
+
let amount;
|
|
11
|
+
try {
|
|
12
|
+
amount = BigInt(value);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
throw new BridgeError(BRIDGE_ERRORS.INVALID_TRANSACTION_VALUE);
|
|
16
|
+
}
|
|
17
|
+
if (amount < 0n)
|
|
18
|
+
throw new BridgeError(BRIDGE_ERRORS.INVALID_TRANSACTION_VALUE);
|
|
19
|
+
return amount;
|
|
20
|
+
};
|