@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.
Files changed (200) hide show
  1. package/README.md +163 -1
  2. package/dist/calldata/abi.d.ts +29 -0
  3. package/dist/calldata/abi.js +160 -0
  4. package/dist/calldata/across/deposit.d.ts +2 -0
  5. package/dist/calldata/across/deposit.js +36 -0
  6. package/dist/calldata/across/depositNative.d.ts +2 -0
  7. package/dist/calldata/across/depositNative.js +45 -0
  8. package/dist/calldata/across/depositNow.d.ts +2 -0
  9. package/dist/calldata/across/depositNow.js +35 -0
  10. package/dist/calldata/across/depositV3.d.ts +2 -0
  11. package/dist/calldata/across/depositV3.js +35 -0
  12. package/dist/calldata/across/depositV3Now.d.ts +2 -0
  13. package/dist/calldata/across/depositV3Now.js +34 -0
  14. package/dist/calldata/across/index.d.ts +4 -0
  15. package/dist/calldata/across/index.js +31 -0
  16. package/dist/calldata/across/swapAndBridge.d.ts +2 -0
  17. package/dist/calldata/across/swapAndBridge.js +70 -0
  18. package/dist/calldata/across/validate.d.ts +3 -0
  19. package/dist/calldata/across/validate.js +34 -0
  20. package/dist/calldata/chains.d.ts +2 -0
  21. package/dist/calldata/chains.js +36 -0
  22. package/dist/calldata/destination.d.ts +6 -0
  23. package/dist/calldata/destination.js +227 -0
  24. package/dist/calldata/destinationSwap.d.ts +14 -0
  25. package/dist/calldata/destinationSwap.js +83 -0
  26. package/dist/calldata/destinationUniswap.d.ts +7 -0
  27. package/dist/calldata/destinationUniswap.js +57 -0
  28. package/dist/calldata/diagnostics.d.ts +4 -0
  29. package/dist/calldata/diagnostics.js +18 -0
  30. package/dist/calldata/expect.d.ts +29 -0
  31. package/dist/calldata/expect.js +157 -0
  32. package/dist/calldata/hex.d.ts +6 -0
  33. package/dist/calldata/hex.js +46 -0
  34. package/dist/calldata/index.d.ts +20 -0
  35. package/dist/calldata/index.js +88 -0
  36. package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +2 -0
  37. package/dist/calldata/lifi/across/acrossV4Erc20Min.js +27 -0
  38. package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +2 -0
  39. package/dist/calldata/lifi/across/acrossV4NativeMin.js +23 -0
  40. package/dist/calldata/lifi/across/index.d.ts +6 -0
  41. package/dist/calldata/lifi/across/index.js +19 -0
  42. package/dist/calldata/lifi/allbridge/index.d.ts +3 -0
  43. package/dist/calldata/lifi/allbridge/index.js +26 -0
  44. package/dist/calldata/lifi/celer/index.d.ts +4 -0
  45. package/dist/calldata/lifi/celer/index.js +10 -0
  46. package/dist/calldata/lifi/centrifuge/index.d.ts +3 -0
  47. package/dist/calldata/lifi/centrifuge/index.js +22 -0
  48. package/dist/calldata/lifi/destination.d.ts +5 -0
  49. package/dist/calldata/lifi/destination.js +40 -0
  50. package/dist/calldata/lifi/frax/index.d.ts +4 -0
  51. package/dist/calldata/lifi/frax/index.js +29 -0
  52. package/dist/calldata/lifi/garden/index.d.ts +3 -0
  53. package/dist/calldata/lifi/garden/index.js +22 -0
  54. package/dist/calldata/lifi/gaszip/index.d.ts +6 -0
  55. package/dist/calldata/lifi/gaszip/index.js +15 -0
  56. package/dist/calldata/lifi/index.d.ts +4 -0
  57. package/dist/calldata/lifi/index.js +62 -0
  58. package/dist/calldata/lifi/intents/index.d.ts +4 -0
  59. package/dist/calldata/lifi/intents/index.js +10 -0
  60. package/dist/calldata/lifi/layerswap/index.d.ts +4 -0
  61. package/dist/calldata/lifi/layerswap/index.js +10 -0
  62. package/dist/calldata/lifi/m0/index.d.ts +3 -0
  63. package/dist/calldata/lifi/m0/index.js +33 -0
  64. package/dist/calldata/lifi/mayan/index.d.ts +4 -0
  65. package/dist/calldata/lifi/mayan/index.js +10 -0
  66. package/dist/calldata/lifi/method.d.ts +6 -0
  67. package/dist/calldata/lifi/method.js +16 -0
  68. package/dist/calldata/lifi/native/index.d.ts +4 -0
  69. package/dist/calldata/lifi/native/index.js +80 -0
  70. package/dist/calldata/lifi/params.d.ts +28 -0
  71. package/dist/calldata/lifi/params.js +349 -0
  72. package/dist/calldata/lifi/paxos/index.d.ts +4 -0
  73. package/dist/calldata/lifi/paxos/index.js +10 -0
  74. package/dist/calldata/lifi/polymer/index.d.ts +4 -0
  75. package/dist/calldata/lifi/polymer/index.js +10 -0
  76. package/dist/calldata/lifi/relay/index.d.ts +6 -0
  77. package/dist/calldata/lifi/relay/index.js +15 -0
  78. package/dist/calldata/lifi/shape.d.ts +4 -0
  79. package/dist/calldata/lifi/shape.js +31 -0
  80. package/dist/calldata/lifi/squid/index.d.ts +6 -0
  81. package/dist/calldata/lifi/squid/index.js +15 -0
  82. package/dist/calldata/lifi/stargate/index.d.ts +5 -0
  83. package/dist/calldata/lifi/stargate/index.js +15 -0
  84. package/dist/calldata/lifi/swap/index.d.ts +5 -0
  85. package/dist/calldata/lifi/swap/index.js +18 -0
  86. package/dist/calldata/lifi/swap/swapMethod.d.ts +2 -0
  87. package/dist/calldata/lifi/swap/swapMethod.js +40 -0
  88. package/dist/calldata/lifi/swapData.d.ts +5 -0
  89. package/dist/calldata/lifi/swapData.js +33 -0
  90. package/dist/calldata/match.d.ts +3 -0
  91. package/dist/calldata/match.js +21 -0
  92. package/dist/calldata/mayan/destination.d.ts +2 -0
  93. package/dist/calldata/mayan/destination.js +13 -0
  94. package/dist/calldata/mayan/fastMctpBridge.d.ts +3 -0
  95. package/dist/calldata/mayan/fastMctpBridge.js +48 -0
  96. package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +3 -0
  97. package/dist/calldata/mayan/fastMctpCreateOrder.js +39 -0
  98. package/dist/calldata/mayan/forward.d.ts +8 -0
  99. package/dist/calldata/mayan/forward.js +35 -0
  100. package/dist/calldata/mayan/forwardERC20.d.ts +2 -0
  101. package/dist/calldata/mayan/forwardERC20.js +19 -0
  102. package/dist/calldata/mayan/forwardEth.d.ts +2 -0
  103. package/dist/calldata/mayan/forwardEth.js +16 -0
  104. package/dist/calldata/mayan/index.d.ts +4 -0
  105. package/dist/calldata/mayan/index.js +21 -0
  106. package/dist/calldata/mayan/mctp.d.ts +5 -0
  107. package/dist/calldata/mayan/mctp.js +41 -0
  108. package/dist/calldata/mayan/readProtocol.d.ts +2 -0
  109. package/dist/calldata/mayan/readProtocol.js +29 -0
  110. package/dist/calldata/mayan/swapAndForwardERC20.d.ts +2 -0
  111. package/dist/calldata/mayan/swapAndForwardERC20.js +24 -0
  112. package/dist/calldata/mayan/swapAndForwardEth.d.ts +2 -0
  113. package/dist/calldata/mayan/swapAndForwardEth.js +23 -0
  114. package/dist/calldata/mayan/swiftCreateOrder.d.ts +3 -0
  115. package/dist/calldata/mayan/swiftCreateOrder.js +49 -0
  116. package/dist/calldata/mayan/validate.d.ts +3 -0
  117. package/dist/calldata/mayan/validate.js +20 -0
  118. package/dist/calldata/protocols.d.ts +9 -0
  119. package/dist/calldata/protocols.js +58 -0
  120. package/dist/calldata/relay/calls.d.ts +13 -0
  121. package/dist/calldata/relay/calls.js +58 -0
  122. package/dist/calldata/relay/depositErc20.d.ts +2 -0
  123. package/dist/calldata/relay/depositErc20.js +22 -0
  124. package/dist/calldata/relay/depositErc20Allowance.d.ts +2 -0
  125. package/dist/calldata/relay/depositErc20Allowance.js +20 -0
  126. package/dist/calldata/relay/depositNative.d.ts +2 -0
  127. package/dist/calldata/relay/depositNative.js +20 -0
  128. package/dist/calldata/relay/index.d.ts +4 -0
  129. package/dist/calldata/relay/index.js +45 -0
  130. package/dist/calldata/relay/multicall.d.ts +2 -0
  131. package/dist/calldata/relay/multicall.js +15 -0
  132. package/dist/calldata/relay/nestedDeposit.d.ts +8 -0
  133. package/dist/calldata/relay/nestedDeposit.js +107 -0
  134. package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +2 -0
  135. package/dist/calldata/relay/permit2TransferAndMulticall.js +42 -0
  136. package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +2 -0
  137. package/dist/calldata/relay/permit3009TransferAndMulticall.js +41 -0
  138. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +2 -0
  139. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +40 -0
  140. package/dist/calldata/relay/permitTransferAndMulticall.d.ts +2 -0
  141. package/dist/calldata/relay/permitTransferAndMulticall.js +34 -0
  142. package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +2 -0
  143. package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +35 -0
  144. package/dist/calldata/relay/transferAndMulticall.d.ts +2 -0
  145. package/dist/calldata/relay/transferAndMulticall.js +26 -0
  146. package/dist/calldata/relay/validate.d.ts +3 -0
  147. package/dist/calldata/relay/validate.js +18 -0
  148. package/dist/calldata/resolve.d.ts +2 -0
  149. package/dist/calldata/resolve.js +28 -0
  150. package/dist/calldata/socket/addresses.d.ts +9 -0
  151. package/dist/calldata/socket/addresses.js +9 -0
  152. package/dist/calldata/socket/bridge.d.ts +2 -0
  153. package/dist/calldata/socket/bridge.js +28 -0
  154. package/dist/calldata/socket/exec.d.ts +2 -0
  155. package/dist/calldata/socket/exec.js +71 -0
  156. package/dist/calldata/socket/index.d.ts +4 -0
  157. package/dist/calldata/socket/index.js +13 -0
  158. package/dist/calldata/socket/params.d.ts +5 -0
  159. package/dist/calldata/socket/params.js +14 -0
  160. package/dist/calldata/socket/protocols/ccip.d.ts +2 -0
  161. package/dist/calldata/socket/protocols/ccip.js +32 -0
  162. package/dist/calldata/socket/protocols/cctp.d.ts +2 -0
  163. package/dist/calldata/socket/protocols/cctp.js +25 -0
  164. package/dist/calldata/socket/protocols/eco.d.ts +2 -0
  165. package/dist/calldata/socket/protocols/eco.js +49 -0
  166. package/dist/calldata/socket/protocols/index.d.ts +3 -0
  167. package/dist/calldata/socket/protocols/index.js +87 -0
  168. package/dist/calldata/socket/protocols/native.d.ts +2 -0
  169. package/dist/calldata/socket/protocols/native.js +71 -0
  170. package/dist/calldata/socket/protocols/oft.d.ts +2 -0
  171. package/dist/calldata/socket/protocols/oft.js +33 -0
  172. package/dist/calldata/socket/protocols/swapsXYZ.d.ts +2 -0
  173. package/dist/calldata/socket/protocols/swapsXYZ.js +62 -0
  174. package/dist/calldata/socket/swapAndBridge.d.ts +2 -0
  175. package/dist/calldata/socket/swapAndBridge.js +41 -0
  176. package/dist/calldata/socket/validate.d.ts +3 -0
  177. package/dist/calldata/socket/validate.js +24 -0
  178. package/dist/calldata/types.d.ts +86 -0
  179. package/dist/calldata/types.js +20 -0
  180. package/dist/errors/constants.d.ts +906 -0
  181. package/dist/errors/constants.js +913 -0
  182. package/dist/errors/index.d.ts +65 -0
  183. package/dist/errors/index.js +53 -0
  184. package/dist/errors/sanitize.d.ts +3 -0
  185. package/dist/errors/sanitize.js +74 -0
  186. package/dist/index.d.ts +6 -1
  187. package/dist/index.js +3 -0
  188. package/dist/providers/data.d.ts +23 -0
  189. package/dist/providers/data.js +116 -0
  190. package/dist/providers/errors.d.ts +7 -0
  191. package/dist/providers/errors.js +10 -0
  192. package/dist/providers/layerswap.d.ts +9 -0
  193. package/dist/providers/layerswap.js +95 -0
  194. package/dist/providers/relay.d.ts +62 -0
  195. package/dist/providers/relay.js +237 -0
  196. package/dist/providers/socket.d.ts +5 -0
  197. package/dist/providers/socket.js +58 -0
  198. package/dist/quote.d.ts +30 -3
  199. package/dist/quote.js +236 -66
  200. 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,2 @@
1
+ import type { ParsedBridgeCall } from '../../types.js';
2
+ export declare const readOft: (data: string, target: string, token: string) => Partial<ParsedBridgeCall>;
@@ -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,2 @@
1
+ import type { ParsedBridgeCall } from '../../types.js';
2
+ export declare const readSwapsXYZ: (data: string) => Partial<ParsedBridgeCall>;
@@ -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,2 @@
1
+ import type { CalldataMethod } from '../abi.js';
2
+ export declare const swapAndBridge: CalldataMethod;
@@ -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,3 @@
1
+ import type { BridgeErrorDefinition } from '../../errors/index.js';
2
+ import type { ParsedBridgeCall } from '../types.js';
3
+ export declare const socketFailure: (parsed: ParsedBridgeCall, expectedUser?: string) => BridgeErrorDefinition | undefined;
@@ -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
+ };