@rabby-wallet/rabby-bridge 0.0.13-alpha.1 → 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.
Files changed (198) hide show
  1. package/README.md +1 -159
  2. package/dist/chains.d.ts +2 -1
  3. package/dist/chains.js +2 -0
  4. package/dist/data.d.ts +3 -0
  5. package/dist/data.js +3 -0
  6. package/dist/index.d.ts +1 -6
  7. package/dist/index.js +0 -3
  8. package/dist/quote.d.ts +4 -26
  9. package/dist/quote.js +67 -200
  10. package/package.json +3 -13
  11. package/dist/calldata/abi.d.ts +0 -29
  12. package/dist/calldata/abi.js +0 -160
  13. package/dist/calldata/across/deposit.d.ts +0 -2
  14. package/dist/calldata/across/deposit.js +0 -36
  15. package/dist/calldata/across/depositNative.d.ts +0 -2
  16. package/dist/calldata/across/depositNative.js +0 -45
  17. package/dist/calldata/across/depositNow.d.ts +0 -2
  18. package/dist/calldata/across/depositNow.js +0 -35
  19. package/dist/calldata/across/depositV3.d.ts +0 -2
  20. package/dist/calldata/across/depositV3.js +0 -35
  21. package/dist/calldata/across/depositV3Now.d.ts +0 -2
  22. package/dist/calldata/across/depositV3Now.js +0 -34
  23. package/dist/calldata/across/index.d.ts +0 -4
  24. package/dist/calldata/across/index.js +0 -31
  25. package/dist/calldata/across/swapAndBridge.d.ts +0 -2
  26. package/dist/calldata/across/swapAndBridge.js +0 -70
  27. package/dist/calldata/across/validate.d.ts +0 -3
  28. package/dist/calldata/across/validate.js +0 -34
  29. package/dist/calldata/chains.d.ts +0 -2
  30. package/dist/calldata/chains.js +0 -35
  31. package/dist/calldata/destination.d.ts +0 -6
  32. package/dist/calldata/destination.js +0 -211
  33. package/dist/calldata/destinationSwap.d.ts +0 -14
  34. package/dist/calldata/destinationSwap.js +0 -80
  35. package/dist/calldata/diagnostics.d.ts +0 -4
  36. package/dist/calldata/diagnostics.js +0 -18
  37. package/dist/calldata/expect.d.ts +0 -27
  38. package/dist/calldata/expect.js +0 -158
  39. package/dist/calldata/hex.d.ts +0 -6
  40. package/dist/calldata/hex.js +0 -46
  41. package/dist/calldata/index.d.ts +0 -20
  42. package/dist/calldata/index.js +0 -88
  43. package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +0 -2
  44. package/dist/calldata/lifi/across/acrossV4Erc20Min.js +0 -26
  45. package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +0 -2
  46. package/dist/calldata/lifi/across/acrossV4NativeMin.js +0 -22
  47. package/dist/calldata/lifi/across/index.d.ts +0 -6
  48. package/dist/calldata/lifi/across/index.js +0 -19
  49. package/dist/calldata/lifi/allbridge/index.d.ts +0 -3
  50. package/dist/calldata/lifi/allbridge/index.js +0 -26
  51. package/dist/calldata/lifi/celer/index.d.ts +0 -4
  52. package/dist/calldata/lifi/celer/index.js +0 -10
  53. package/dist/calldata/lifi/centrifuge/index.d.ts +0 -3
  54. package/dist/calldata/lifi/centrifuge/index.js +0 -22
  55. package/dist/calldata/lifi/destination.d.ts +0 -5
  56. package/dist/calldata/lifi/destination.js +0 -40
  57. package/dist/calldata/lifi/frax/index.d.ts +0 -4
  58. package/dist/calldata/lifi/frax/index.js +0 -29
  59. package/dist/calldata/lifi/garden/index.d.ts +0 -3
  60. package/dist/calldata/lifi/garden/index.js +0 -22
  61. package/dist/calldata/lifi/gaszip/index.d.ts +0 -6
  62. package/dist/calldata/lifi/gaszip/index.js +0 -15
  63. package/dist/calldata/lifi/index.d.ts +0 -4
  64. package/dist/calldata/lifi/index.js +0 -62
  65. package/dist/calldata/lifi/intents/index.d.ts +0 -4
  66. package/dist/calldata/lifi/intents/index.js +0 -10
  67. package/dist/calldata/lifi/layerswap/index.d.ts +0 -4
  68. package/dist/calldata/lifi/layerswap/index.js +0 -10
  69. package/dist/calldata/lifi/m0/index.d.ts +0 -3
  70. package/dist/calldata/lifi/m0/index.js +0 -33
  71. package/dist/calldata/lifi/mayan/index.d.ts +0 -4
  72. package/dist/calldata/lifi/mayan/index.js +0 -10
  73. package/dist/calldata/lifi/method.d.ts +0 -6
  74. package/dist/calldata/lifi/method.js +0 -16
  75. package/dist/calldata/lifi/native/index.d.ts +0 -4
  76. package/dist/calldata/lifi/native/index.js +0 -80
  77. package/dist/calldata/lifi/params.d.ts +0 -28
  78. package/dist/calldata/lifi/params.js +0 -347
  79. package/dist/calldata/lifi/paxos/index.d.ts +0 -4
  80. package/dist/calldata/lifi/paxos/index.js +0 -10
  81. package/dist/calldata/lifi/polymer/index.d.ts +0 -4
  82. package/dist/calldata/lifi/polymer/index.js +0 -10
  83. package/dist/calldata/lifi/relay/index.d.ts +0 -6
  84. package/dist/calldata/lifi/relay/index.js +0 -15
  85. package/dist/calldata/lifi/shape.d.ts +0 -4
  86. package/dist/calldata/lifi/shape.js +0 -31
  87. package/dist/calldata/lifi/squid/index.d.ts +0 -6
  88. package/dist/calldata/lifi/squid/index.js +0 -15
  89. package/dist/calldata/lifi/stargate/index.d.ts +0 -5
  90. package/dist/calldata/lifi/stargate/index.js +0 -15
  91. package/dist/calldata/lifi/swap/index.d.ts +0 -5
  92. package/dist/calldata/lifi/swap/index.js +0 -18
  93. package/dist/calldata/lifi/swap/swapMethod.d.ts +0 -2
  94. package/dist/calldata/lifi/swap/swapMethod.js +0 -40
  95. package/dist/calldata/lifi/swapData.d.ts +0 -5
  96. package/dist/calldata/lifi/swapData.js +0 -33
  97. package/dist/calldata/match.d.ts +0 -3
  98. package/dist/calldata/match.js +0 -21
  99. package/dist/calldata/mayan/destination.d.ts +0 -2
  100. package/dist/calldata/mayan/destination.js +0 -13
  101. package/dist/calldata/mayan/fastMctpBridge.d.ts +0 -3
  102. package/dist/calldata/mayan/fastMctpBridge.js +0 -48
  103. package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +0 -3
  104. package/dist/calldata/mayan/fastMctpCreateOrder.js +0 -39
  105. package/dist/calldata/mayan/forward.d.ts +0 -8
  106. package/dist/calldata/mayan/forward.js +0 -35
  107. package/dist/calldata/mayan/forwardERC20.d.ts +0 -2
  108. package/dist/calldata/mayan/forwardERC20.js +0 -19
  109. package/dist/calldata/mayan/forwardEth.d.ts +0 -2
  110. package/dist/calldata/mayan/forwardEth.js +0 -16
  111. package/dist/calldata/mayan/index.d.ts +0 -4
  112. package/dist/calldata/mayan/index.js +0 -21
  113. package/dist/calldata/mayan/mctp.d.ts +0 -5
  114. package/dist/calldata/mayan/mctp.js +0 -41
  115. package/dist/calldata/mayan/readProtocol.d.ts +0 -2
  116. package/dist/calldata/mayan/readProtocol.js +0 -29
  117. package/dist/calldata/mayan/swapAndForwardERC20.d.ts +0 -2
  118. package/dist/calldata/mayan/swapAndForwardERC20.js +0 -24
  119. package/dist/calldata/mayan/swapAndForwardEth.d.ts +0 -2
  120. package/dist/calldata/mayan/swapAndForwardEth.js +0 -23
  121. package/dist/calldata/mayan/swiftCreateOrder.d.ts +0 -3
  122. package/dist/calldata/mayan/swiftCreateOrder.js +0 -49
  123. package/dist/calldata/mayan/validate.d.ts +0 -3
  124. package/dist/calldata/mayan/validate.js +0 -20
  125. package/dist/calldata/protocols.d.ts +0 -9
  126. package/dist/calldata/protocols.js +0 -57
  127. package/dist/calldata/relay/calls.d.ts +0 -13
  128. package/dist/calldata/relay/calls.js +0 -54
  129. package/dist/calldata/relay/depositErc20.d.ts +0 -2
  130. package/dist/calldata/relay/depositErc20.js +0 -22
  131. package/dist/calldata/relay/depositErc20Allowance.d.ts +0 -2
  132. package/dist/calldata/relay/depositErc20Allowance.js +0 -20
  133. package/dist/calldata/relay/depositNative.d.ts +0 -2
  134. package/dist/calldata/relay/depositNative.js +0 -20
  135. package/dist/calldata/relay/index.d.ts +0 -4
  136. package/dist/calldata/relay/index.js +0 -42
  137. package/dist/calldata/relay/multicall.d.ts +0 -2
  138. package/dist/calldata/relay/multicall.js +0 -15
  139. package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +0 -2
  140. package/dist/calldata/relay/permit2TransferAndMulticall.js +0 -42
  141. package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +0 -2
  142. package/dist/calldata/relay/permit3009TransferAndMulticall.js +0 -41
  143. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +0 -2
  144. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +0 -40
  145. package/dist/calldata/relay/permitTransferAndMulticall.d.ts +0 -2
  146. package/dist/calldata/relay/permitTransferAndMulticall.js +0 -34
  147. package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +0 -2
  148. package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +0 -35
  149. package/dist/calldata/relay/transferAndMulticall.d.ts +0 -2
  150. package/dist/calldata/relay/transferAndMulticall.js +0 -26
  151. package/dist/calldata/relay/validate.d.ts +0 -3
  152. package/dist/calldata/relay/validate.js +0 -18
  153. package/dist/calldata/resolve.d.ts +0 -2
  154. package/dist/calldata/resolve.js +0 -28
  155. package/dist/calldata/socket/bridge.d.ts +0 -2
  156. package/dist/calldata/socket/bridge.js +0 -28
  157. package/dist/calldata/socket/exec.d.ts +0 -2
  158. package/dist/calldata/socket/exec.js +0 -71
  159. package/dist/calldata/socket/index.d.ts +0 -4
  160. package/dist/calldata/socket/index.js +0 -13
  161. package/dist/calldata/socket/params.d.ts +0 -5
  162. package/dist/calldata/socket/params.js +0 -14
  163. package/dist/calldata/socket/protocols/ccip.d.ts +0 -2
  164. package/dist/calldata/socket/protocols/ccip.js +0 -32
  165. package/dist/calldata/socket/protocols/cctp.d.ts +0 -2
  166. package/dist/calldata/socket/protocols/cctp.js +0 -24
  167. package/dist/calldata/socket/protocols/eco.d.ts +0 -2
  168. package/dist/calldata/socket/protocols/eco.js +0 -20
  169. package/dist/calldata/socket/protocols/index.d.ts +0 -3
  170. package/dist/calldata/socket/protocols/index.js +0 -86
  171. package/dist/calldata/socket/protocols/native.d.ts +0 -2
  172. package/dist/calldata/socket/protocols/native.js +0 -70
  173. package/dist/calldata/socket/protocols/oft.d.ts +0 -2
  174. package/dist/calldata/socket/protocols/oft.js +0 -33
  175. package/dist/calldata/socket/protocols/swapsXYZ.d.ts +0 -2
  176. package/dist/calldata/socket/protocols/swapsXYZ.js +0 -62
  177. package/dist/calldata/socket/swapAndBridge.d.ts +0 -2
  178. package/dist/calldata/socket/swapAndBridge.js +0 -41
  179. package/dist/calldata/socket/validate.d.ts +0 -3
  180. package/dist/calldata/socket/validate.js +0 -24
  181. package/dist/calldata/types.d.ts +0 -82
  182. package/dist/calldata/types.js +0 -20
  183. package/dist/errors/constants.d.ts +0 -891
  184. package/dist/errors/constants.js +0 -898
  185. package/dist/errors/index.d.ts +0 -66
  186. package/dist/errors/index.js +0 -53
  187. package/dist/errors/sanitize.d.ts +0 -3
  188. package/dist/errors/sanitize.js +0 -74
  189. package/dist/providers/data.d.ts +0 -23
  190. package/dist/providers/data.js +0 -116
  191. package/dist/providers/errors.d.ts +0 -7
  192. package/dist/providers/errors.js +0 -10
  193. package/dist/providers/layerswap.d.ts +0 -9
  194. package/dist/providers/layerswap.js +0 -95
  195. package/dist/providers/relay.d.ts +0 -59
  196. package/dist/providers/relay.js +0 -185
  197. package/dist/providers/socket.d.ts +0 -5
  198. package/dist/providers/socket.js +0 -57
@@ -1,20 +0,0 @@
1
- import { asArray, asBigint, asRecord, asString, decodeCall, decodeParameters } from '../../abi.js';
2
- import { destinationCall, readDestinationTransfers } from '../../destination.js';
3
- const tokens = { name: 'tokens', kind: 'array', item: { name: 'token', kind: 'tuple', components: [
4
- { name: 'token', kind: 'address' }, { name: 'amount', kind: 'uint' },
5
- ] } };
6
- const reward = { name: 'reward', kind: 'tuple', components: [
7
- { name: 'deadline', kind: 'uint' }, { name: 'creator', kind: 'address' }, { name: 'prover', kind: 'address' },
8
- { name: 'nativeAmount', kind: 'uint' }, tokens,
9
- ] };
10
- const route = { name: 'route', kind: 'tuple', components: [
11
- { name: 'salt', kind: 'bytes', size: 32 }, { name: 'deadline', kind: 'uint' }, { name: 'portal', kind: 'address' },
12
- { name: 'nativeAmount', kind: 'uint' }, tokens, { name: 'calls', kind: 'array', item: destinationCall },
13
- ] };
14
- export const readEco = (data) => {
15
- const a = decodeCall([{ name: 'destination', kind: 'uint' }, { name: 'route', kind: 'bytes' }, reward,
16
- { name: 'allowPartial', kind: 'bool' }], data);
17
- const r = asRecord(decodeParameters([route], asString(a.route)).route);
18
- return { protocolMethod: 'publishAndFund', destinationChainId: asBigint(a.destination),
19
- destinationCallData: asString(a.route), ...readDestinationTransfers(asArray(r.calls)) };
20
- };
@@ -1,3 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readSocketBridge: (data: string, target: string, token: string, value: bigint, spender: string) => Partial<ParsedBridgeCall>;
3
- export declare const spliceBridgeAmount: (data: string, flags: bigint, amount: bigint) => string;
@@ -1,86 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError, asBridgeError } from '../../../errors/index.js';
2
- import { innerCallDiagnostics } from '../../diagnostics.js';
3
- import { asBigint, asString, decodeCall } from '../../abi.js';
4
- import { readSelector } from '../../hex.js';
5
- import { isNative, NATIVE_TOKEN } from '../../protocols.js';
6
- import { readCcip } from './ccip.js';
7
- import { readCctp } from './cctp.js';
8
- import { readEco } from './eco.js';
9
- import { readNativeBridge } from './native.js';
10
- import { readOft } from './oft.js';
11
- import { readSwapsXYZ } from './swapsXYZ.js';
12
- const decodeSocketBridge = (data, target, token, value, spender) => {
13
- const selector = readSelector(data);
14
- const native = readNativeBridge(data, target, value);
15
- if (native)
16
- return native;
17
- if (selector === '0x96f4e9f9')
18
- return readCcip(data, target);
19
- if (selector === '0x8e0250ee') {
20
- if (target !== '0x28b5a0e9c621a5badaa536219b3a228c8168cf5d' || spender !== target || value !== 0n) {
21
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_CCTP_TARGET_SPENDER_OR_VALUE);
22
- }
23
- const parsed = readCctp(data);
24
- if (parsed.bridgeToken !== token)
25
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_CCTP_TOKEN_DOES_NOT_MATCH_BRIDGE_ASSET);
26
- return parsed;
27
- }
28
- if (selector === '0xdf00f8fa')
29
- return readEco(data);
30
- if (selector === '0xc7c7f5b3' || selector === '0x2cdf0b95')
31
- return readOft(data, target, token);
32
- if (selector === '0x0c751e0b' || selector === '0x9be111d1')
33
- return readSwapsXYZ(data);
34
- if (selector === '0x823b01f9' || selector === '0x3345e738') {
35
- const native = selector === '0x3345e738';
36
- if (target !== '0x97caca78ac2a94c67643d07843f85afaa44a3ea5' || spender !== target ||
37
- (native ? !isNative(token) : value !== 0n)) {
38
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_RFQ_TARGET_SPENDER_OR_VALUE);
39
- }
40
- const a = decodeCall([{ name: 'quoteId', kind: 'bytes', size: 32 },
41
- ...(native ? [] : [{ name: 'token', kind: 'address' }, { name: 'amount', kind: 'uint' }])], data);
42
- if (!native && asString(a.token) !== token)
43
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_RFQ_TOKEN_DOES_NOT_MATCH_BRIDGE_ASSET);
44
- return { protocolMethod: native ? 'receiveNative' : 'receiveERC20', orderId: asString(a.quoteId),
45
- bridgeToken: native ? NATIVE_TOKEN : asString(a.token), bridgeAmount: native ? value : asBigint(a.amount) };
46
- }
47
- return undefined;
48
- };
49
- export const readSocketBridge = (data, target, token, value, spender) => {
50
- const diagnostics = innerCallDiagnostics(data, 'protocol');
51
- try {
52
- const parsed = decodeSocketBridge(data, target, token, value, spender);
53
- return { ...parsed, diagnostics: { ...parsed?.diagnostics, ...diagnostics } };
54
- }
55
- catch (error) {
56
- throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, diagnostics);
57
- }
58
- };
59
- const word = (data, offset) => {
60
- const raw = data.slice(2 + offset * 2, 2 + (offset + 32) * 2);
61
- if (raw.length !== 64)
62
- throw new BridgeError(BRIDGE_ERRORS.INVALID_BRIDGE_OFFSET);
63
- const n = BigInt(`0x${raw}`);
64
- if (n > BigInt(data.length / 2))
65
- throw new BridgeError(BRIDGE_ERRORS.BRIDGE_OFFSET_EXCEEDS_CALLDATA);
66
- return Number(n);
67
- };
68
- export const spliceBridgeAmount = (data, flags, amount) => {
69
- if ((flags & 8n) === 0n)
70
- return data;
71
- const position = Number(flags >> 16n & 65535n);
72
- const selector = readSelector(data);
73
- let expected = {
74
- '0xd2ce7d65': 68, '0xad58bdd1': 68, '0x8b9e4f93': 68,
75
- '0x838b2520': 100, '0x8e0250ee': 4, '0x823b01f9': 68, '0x2cdf0b95': 100,
76
- }[selector ?? ''];
77
- if (selector === '0xc7c7f5b3')
78
- expected = 4 + word(data, 4) + 64;
79
- if (selector === '0x96f4e9f9') {
80
- const message = 4 + word(data, 36);
81
- expected = message + word(data, message + 64) + 64;
82
- }
83
- if (position !== expected || 2 + (position + 32) * 2 > data.length)
84
- throw new BridgeError(BRIDGE_ERRORS.BRIDGE_SPLICE_DOES_NOT_TARGET_THE_INPUT_AMOUNT);
85
- return data.slice(0, 2 + position * 2) + amount.toString(16).padStart(64, '0') + data.slice(2 + (position + 32) * 2);
86
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readNativeBridge: (data: string, target: string, value: bigint) => Partial<ParsedBridgeCall> | undefined;
@@ -1,70 +0,0 @@
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
- receiver: callData === '0x' ? asString(a.to) : undefined, bridgeReceiver: asString(a.to),
17
- outputToken: callData === '0x' ? NATIVE_TOKEN : undefined,
18
- minOutputAmount: callData === '0x' ? asBigint(a.l2CallValue) : undefined,
19
- destinationCallData: callData === '0x' ? undefined : callData };
20
- }
21
- if (selector === '0xd2ce7d65') {
22
- const a = decodeCall([
23
- { name: 'token', kind: 'address' }, { name: 'to', kind: 'address' }, { name: 'amount', kind: 'uint' },
24
- { name: 'maxGas', kind: 'uint' }, { name: 'gasPriceBid', kind: 'uint' }, { name: 'data', kind: 'bytes' },
25
- ], data);
26
- const ref = { protocol: 'arbitrum', contract: target, token: asString(a.token), destinationChainId: target === '0x72ce9c846789fdb6fc1f34ac4ad25dd9ef7031ef' ? 42161n : undefined };
27
- return { protocolMethod: 'outboundTransfer', receiver: asString(a.to),
28
- destinationChainId: ref.destinationChainId, outputTokenReference: ref, minOutputAmount: asBigint(a.amount) };
29
- }
30
- if (selector === '0x838b2520' || selector === '0x9a2ac6d5') {
31
- const erc20 = selector === '0x838b2520';
32
- const a = decodeCall([
33
- ...(erc20 ? [{ name: 'localToken', kind: 'address' }, { name: 'remoteToken', kind: 'address' }] : []),
34
- { name: 'to', kind: 'address' }, ...(erc20 ? [{ name: 'amount', kind: 'uint' }] : []),
35
- { name: 'minGasLimit', kind: 'uint' }, { name: 'extraData', kind: 'bytes' },
36
- ], data);
37
- return { protocolMethod: erc20 ? 'depositERC20To' : 'depositETHTo',
38
- destinationChainId: target === '0x3154cf16ccdb4c6d922629664174b904d80f2c35' ? 8453n : undefined,
39
- receiver: asString(a.to), outputToken: erc20 ? asString(a.remoteToken) : NATIVE_TOKEN,
40
- minOutputAmount: erc20 ? asBigint(a.amount) : value };
41
- }
42
- if (selector === '0x4faa8a26') {
43
- const a = decodeCall([{ name: 'user', kind: 'address' }], data);
44
- return { protocolMethod: 'depositEtherFor', destinationChainId: 137n, receiver: asString(a.user),
45
- outputToken: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', minOutputAmount: value };
46
- }
47
- if (selector === '0xe3dec8fb') {
48
- const a = decodeCall([{ name: 'user', kind: 'address' }, { name: 'rootToken', kind: 'address' }, { name: 'depositData', kind: 'bytes' }], data);
49
- const amount = asBigint(decodeParameters([{ name: 'amount', kind: 'uint' }], asString(a.depositData)).amount);
50
- return { protocolMethod: 'depositFor', destinationChainId: 137n, receiver: asString(a.user), minOutputAmount: amount,
51
- outputTokenReference: { protocol: 'polygon', contract: target, token: asString(a.rootToken), destinationChainId: 137n } };
52
- }
53
- if (selector === '0x8b9e4f93' || selector === '0xad58bdd1') {
54
- const polygon = selector === '0x8b9e4f93';
55
- const a = decodeCall([{ name: 'token', kind: 'address' }, { name: 'receiver', kind: 'address' }, { name: 'amount', kind: 'uint' }], data);
56
- const token = asString(a.token);
57
- const destinationChainId = polygon ? 137n : 100n;
58
- let outputToken;
59
- if (polygon && ['0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', '0x455e53cbb86018ac2b8092fdcd39d8444affc3f6'].includes(token))
60
- outputToken = NATIVE_TOKEN;
61
- if (!polygon && ['0x6b175474e89094c44da98b954eedeac495271d0f', '0xdc035d45d973e3ec169d2276ddab16f1e407384f'].includes(token))
62
- outputToken = NATIVE_TOKEN;
63
- if (!polygon && isNative(token))
64
- outputToken = '0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1';
65
- return { protocolMethod: polygon ? 'depositERC20ForUser' : 'relayTokens', destinationChainId,
66
- receiver: asString(a.receiver), minOutputAmount: asBigint(a.amount), outputToken,
67
- outputTokenReference: outputToken ? undefined : { protocol: polygon ? 'polygon' : 'gnosis', contract: target, token, destinationChainId } };
68
- }
69
- return undefined;
70
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readOft: (data: string, target: string, token: string) => Partial<ParsedBridgeCall>;
@@ -1,33 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readSwapsXYZ: (data: string) => Partial<ParsedBridgeCall>;
@@ -1,62 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const swapAndBridge: CalldataMethod;
@@ -1,41 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
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;
@@ -1,24 +0,0 @@
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
- };
@@ -1,82 +0,0 @@
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
- outputToken?: string;
29
- minOutputAmount?: bigint;
30
- orderId?: string;
31
- quoteId?: string;
32
- referrer?: string;
33
- protocolMethod?: string;
34
- spokePool?: string;
35
- innerTarget?: string;
36
- depositor?: string;
37
- bridgeToken?: string;
38
- bridgeAmount?: bigint;
39
- bridgeReceiver?: string;
40
- bridgeOutputToken?: string;
41
- bridgeOutputAmount?: bigint;
42
- requestId?: string;
43
- outputTokenReference?: BridgeTokenReference;
44
- outputAmountReference?: BridgeAmountReference;
45
- destinationCallData?: string;
46
- hasDestinationCall?: boolean;
47
- unresolvedFields?: string[];
48
- /** Non-personal call structure retained for unsupported-path diagnostics. */
49
- diagnostics?: BridgeErrorContext;
50
- };
51
- export type DecodeHit = {
52
- ok: true;
53
- parsed: ParsedBridgeCall;
54
- } | {
55
- ok: false;
56
- method?: string;
57
- reason: string;
58
- error_code: BridgeErrorCode;
59
- stage: BridgeErrorStage;
60
- errors: BridgeErrorDetail[];
61
- };
62
- export type BridgeCheck = {
63
- ok: boolean;
64
- aggregatorId: string;
65
- method?: string;
66
- reason?: string;
67
- parsed?: ParsedBridgeCall;
68
- unverifiedFields?: string[];
69
- error_code?: BridgeErrorCode;
70
- stage?: BridgeErrorStage;
71
- errors: BridgeErrorDetail[];
72
- };
73
- export type BridgeCalldataTx = {
74
- to?: string;
75
- from?: string;
76
- chainId?: string | number | bigint;
77
- data?: string;
78
- input?: string;
79
- value?: string | number | bigint;
80
- };
81
- export declare const txCalldata: (tx: BridgeCalldataTx) => string;
82
- export declare const txValue: (tx: BridgeCalldataTx) => bigint;
@@ -1,20 +0,0 @@
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
- };