@rabby-wallet/rabby-bridge 0.0.13-alpha.0 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +1 -131
  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 -7
  7. package/dist/index.js +0 -3
  8. package/dist/quote.d.ts +4 -18
  9. package/dist/quote.js +65 -282
  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 -30
  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 -148
  33. package/dist/calldata/diagnostics.d.ts +0 -4
  34. package/dist/calldata/diagnostics.js +0 -18
  35. package/dist/calldata/expect.d.ts +0 -25
  36. package/dist/calldata/expect.js +0 -129
  37. package/dist/calldata/hex.d.ts +0 -6
  38. package/dist/calldata/hex.js +0 -46
  39. package/dist/calldata/index.d.ts +0 -20
  40. package/dist/calldata/index.js +0 -85
  41. package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +0 -2
  42. package/dist/calldata/lifi/across/acrossV4Erc20Min.js +0 -26
  43. package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +0 -2
  44. package/dist/calldata/lifi/across/acrossV4NativeMin.js +0 -22
  45. package/dist/calldata/lifi/across/index.d.ts +0 -6
  46. package/dist/calldata/lifi/across/index.js +0 -19
  47. package/dist/calldata/lifi/allbridge/index.d.ts +0 -3
  48. package/dist/calldata/lifi/allbridge/index.js +0 -26
  49. package/dist/calldata/lifi/celer/index.d.ts +0 -4
  50. package/dist/calldata/lifi/celer/index.js +0 -10
  51. package/dist/calldata/lifi/centrifuge/index.d.ts +0 -3
  52. package/dist/calldata/lifi/centrifuge/index.js +0 -22
  53. package/dist/calldata/lifi/frax/index.d.ts +0 -4
  54. package/dist/calldata/lifi/frax/index.js +0 -29
  55. package/dist/calldata/lifi/garden/index.d.ts +0 -3
  56. package/dist/calldata/lifi/garden/index.js +0 -22
  57. package/dist/calldata/lifi/gaszip/index.d.ts +0 -6
  58. package/dist/calldata/lifi/gaszip/index.js +0 -15
  59. package/dist/calldata/lifi/index.d.ts +0 -4
  60. package/dist/calldata/lifi/index.js +0 -60
  61. package/dist/calldata/lifi/intents/index.d.ts +0 -4
  62. package/dist/calldata/lifi/intents/index.js +0 -10
  63. package/dist/calldata/lifi/layerswap/index.d.ts +0 -4
  64. package/dist/calldata/lifi/layerswap/index.js +0 -10
  65. package/dist/calldata/lifi/m0/index.d.ts +0 -3
  66. package/dist/calldata/lifi/m0/index.js +0 -33
  67. package/dist/calldata/lifi/mayan/index.d.ts +0 -4
  68. package/dist/calldata/lifi/mayan/index.js +0 -10
  69. package/dist/calldata/lifi/method.d.ts +0 -6
  70. package/dist/calldata/lifi/method.js +0 -16
  71. package/dist/calldata/lifi/native/index.d.ts +0 -4
  72. package/dist/calldata/lifi/native/index.js +0 -80
  73. package/dist/calldata/lifi/params.d.ts +0 -30
  74. package/dist/calldata/lifi/params.js +0 -370
  75. package/dist/calldata/lifi/paxos/index.d.ts +0 -4
  76. package/dist/calldata/lifi/paxos/index.js +0 -10
  77. package/dist/calldata/lifi/polymer/index.d.ts +0 -4
  78. package/dist/calldata/lifi/polymer/index.js +0 -10
  79. package/dist/calldata/lifi/relay/index.d.ts +0 -6
  80. package/dist/calldata/lifi/relay/index.js +0 -15
  81. package/dist/calldata/lifi/shape.d.ts +0 -4
  82. package/dist/calldata/lifi/shape.js +0 -31
  83. package/dist/calldata/lifi/squid/index.d.ts +0 -6
  84. package/dist/calldata/lifi/squid/index.js +0 -15
  85. package/dist/calldata/lifi/stargate/index.d.ts +0 -5
  86. package/dist/calldata/lifi/stargate/index.js +0 -15
  87. package/dist/calldata/lifi/swap/index.d.ts +0 -5
  88. package/dist/calldata/lifi/swap/index.js +0 -18
  89. package/dist/calldata/lifi/swap/swapMethod.d.ts +0 -2
  90. package/dist/calldata/lifi/swap/swapMethod.js +0 -40
  91. package/dist/calldata/match.d.ts +0 -3
  92. package/dist/calldata/match.js +0 -21
  93. package/dist/calldata/mayan/destination.d.ts +0 -2
  94. package/dist/calldata/mayan/destination.js +0 -13
  95. package/dist/calldata/mayan/fastMctpBridge.d.ts +0 -3
  96. package/dist/calldata/mayan/fastMctpBridge.js +0 -43
  97. package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +0 -3
  98. package/dist/calldata/mayan/fastMctpCreateOrder.js +0 -39
  99. package/dist/calldata/mayan/forward.d.ts +0 -8
  100. package/dist/calldata/mayan/forward.js +0 -35
  101. package/dist/calldata/mayan/forwardERC20.d.ts +0 -2
  102. package/dist/calldata/mayan/forwardERC20.js +0 -19
  103. package/dist/calldata/mayan/forwardEth.d.ts +0 -2
  104. package/dist/calldata/mayan/forwardEth.js +0 -16
  105. package/dist/calldata/mayan/index.d.ts +0 -4
  106. package/dist/calldata/mayan/index.js +0 -21
  107. package/dist/calldata/mayan/mctp.d.ts +0 -5
  108. package/dist/calldata/mayan/mctp.js +0 -41
  109. package/dist/calldata/mayan/readProtocol.d.ts +0 -2
  110. package/dist/calldata/mayan/readProtocol.js +0 -29
  111. package/dist/calldata/mayan/swapAndForwardERC20.d.ts +0 -2
  112. package/dist/calldata/mayan/swapAndForwardERC20.js +0 -24
  113. package/dist/calldata/mayan/swapAndForwardEth.d.ts +0 -2
  114. package/dist/calldata/mayan/swapAndForwardEth.js +0 -23
  115. package/dist/calldata/mayan/swiftCreateOrder.d.ts +0 -3
  116. package/dist/calldata/mayan/swiftCreateOrder.js +0 -49
  117. package/dist/calldata/mayan/validate.d.ts +0 -3
  118. package/dist/calldata/mayan/validate.js +0 -20
  119. package/dist/calldata/protocols.d.ts +0 -9
  120. package/dist/calldata/protocols.js +0 -56
  121. package/dist/calldata/relay/calls.d.ts +0 -13
  122. package/dist/calldata/relay/calls.js +0 -54
  123. package/dist/calldata/relay/depositErc20.d.ts +0 -2
  124. package/dist/calldata/relay/depositErc20.js +0 -22
  125. package/dist/calldata/relay/depositErc20Allowance.d.ts +0 -2
  126. package/dist/calldata/relay/depositErc20Allowance.js +0 -20
  127. package/dist/calldata/relay/depositNative.d.ts +0 -2
  128. package/dist/calldata/relay/depositNative.js +0 -20
  129. package/dist/calldata/relay/index.d.ts +0 -4
  130. package/dist/calldata/relay/index.js +0 -40
  131. package/dist/calldata/relay/multicall.d.ts +0 -2
  132. package/dist/calldata/relay/multicall.js +0 -15
  133. package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +0 -2
  134. package/dist/calldata/relay/permit2TransferAndMulticall.js +0 -42
  135. package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +0 -2
  136. package/dist/calldata/relay/permit3009TransferAndMulticall.js +0 -41
  137. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +0 -2
  138. package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +0 -40
  139. package/dist/calldata/relay/permitTransferAndMulticall.d.ts +0 -2
  140. package/dist/calldata/relay/permitTransferAndMulticall.js +0 -34
  141. package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +0 -2
  142. package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +0 -35
  143. package/dist/calldata/relay/transferAndMulticall.d.ts +0 -2
  144. package/dist/calldata/relay/transferAndMulticall.js +0 -26
  145. package/dist/calldata/relay/validate.d.ts +0 -3
  146. package/dist/calldata/relay/validate.js +0 -18
  147. package/dist/calldata/resolve.d.ts +0 -2
  148. package/dist/calldata/resolve.js +0 -28
  149. package/dist/calldata/socket/bridge.d.ts +0 -2
  150. package/dist/calldata/socket/bridge.js +0 -28
  151. package/dist/calldata/socket/exec.d.ts +0 -2
  152. package/dist/calldata/socket/exec.js +0 -71
  153. package/dist/calldata/socket/index.d.ts +0 -4
  154. package/dist/calldata/socket/index.js +0 -13
  155. package/dist/calldata/socket/params.d.ts +0 -5
  156. package/dist/calldata/socket/params.js +0 -14
  157. package/dist/calldata/socket/protocols/ccip.d.ts +0 -2
  158. package/dist/calldata/socket/protocols/ccip.js +0 -32
  159. package/dist/calldata/socket/protocols/cctp.d.ts +0 -2
  160. package/dist/calldata/socket/protocols/cctp.js +0 -24
  161. package/dist/calldata/socket/protocols/eco.d.ts +0 -2
  162. package/dist/calldata/socket/protocols/eco.js +0 -20
  163. package/dist/calldata/socket/protocols/index.d.ts +0 -3
  164. package/dist/calldata/socket/protocols/index.js +0 -81
  165. package/dist/calldata/socket/protocols/native.d.ts +0 -2
  166. package/dist/calldata/socket/protocols/native.js +0 -70
  167. package/dist/calldata/socket/protocols/oft.d.ts +0 -2
  168. package/dist/calldata/socket/protocols/oft.js +0 -31
  169. package/dist/calldata/socket/protocols/swapsXYZ.d.ts +0 -2
  170. package/dist/calldata/socket/protocols/swapsXYZ.js +0 -62
  171. package/dist/calldata/socket/swapAndBridge.d.ts +0 -2
  172. package/dist/calldata/socket/swapAndBridge.js +0 -37
  173. package/dist/calldata/socket/validate.d.ts +0 -3
  174. package/dist/calldata/socket/validate.js +0 -21
  175. package/dist/calldata/types.d.ts +0 -82
  176. package/dist/calldata/types.js +0 -20
  177. package/dist/errors/constants.d.ts +0 -876
  178. package/dist/errors/constants.js +0 -883
  179. package/dist/errors/index.d.ts +0 -61
  180. package/dist/errors/index.js +0 -53
  181. package/dist/errors/sanitize.d.ts +0 -3
  182. package/dist/errors/sanitize.js +0 -75
  183. package/dist/providers/data.d.ts +0 -23
  184. package/dist/providers/data.js +0 -116
  185. package/dist/providers/errors.d.ts +0 -7
  186. package/dist/providers/errors.js +0 -10
  187. package/dist/providers/index.d.ts +0 -7
  188. package/dist/providers/index.js +0 -340
  189. package/dist/providers/layerswap.d.ts +0 -9
  190. package/dist/providers/layerswap.js +0 -95
  191. package/dist/providers/relay.d.ts +0 -59
  192. package/dist/providers/relay.js +0 -185
  193. package/dist/providers/request.d.ts +0 -23
  194. package/dist/providers/request.js +0 -69
  195. package/dist/providers/socket.d.ts +0 -5
  196. package/dist/providers/socket.js +0 -57
  197. package/dist/providers/types.d.ts +0 -36
  198. package/dist/providers/types.js +0 -1
@@ -1,71 +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 { bridge } from './bridge.js';
6
- import { swapAndBridge } from './swapAndBridge.js';
7
- import { isNative, NATIVE_TOKEN } from '../protocols.js';
8
- const readInner = (data, value) => {
9
- const selector = readSelector(data);
10
- if (selector === bridge.selector) {
11
- return bridge.decode(data, value);
12
- }
13
- if (selector === swapAndBridge.selector) {
14
- return swapAndBridge.decode(data, value);
15
- }
16
- return undefined;
17
- };
18
- export const exec = {
19
- name: 'exec',
20
- selector: '0x2213bc0b',
21
- decode(data, value) {
22
- const args = decodeCall([
23
- { name: 'operator', kind: 'address' },
24
- { name: 'token', kind: 'address' },
25
- { name: 'amount', kind: 'uint' },
26
- { name: 'target', kind: 'address' },
27
- { name: 'data', kind: 'bytes' },
28
- ], data);
29
- const target = asString(args.target);
30
- const diagnostics = innerCallDiagnostics(asString(args.data), 'router');
31
- if (target !== '0x50cfe7c1938db66a1a6d2e86d36f39fbef3d5c4a' || asString(args.operator) !== target) {
32
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_OPERATOR_OR_ROUTER, diagnostics);
33
- }
34
- let inner;
35
- try {
36
- inner = readInner(asString(args.data), value);
37
- }
38
- catch (error) {
39
- throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, diagnostics);
40
- }
41
- if (!inner) {
42
- return {
43
- aggregatorId: 'socket',
44
- method: 'exec',
45
- kind: 'bridge',
46
- sourceToken: asString(args.token),
47
- sourceAmount: asBigint(args.amount),
48
- innerTarget: asString(args.target),
49
- diagnostics,
50
- };
51
- }
52
- const token = asString(args.token);
53
- if (inner.sourceToken !== token && !(isNative(token) && isNative(inner.sourceToken ?? ''))) {
54
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_ALLOWANCE_TOKEN_MISMATCH, { ...inner.diagnostics, ...diagnostics });
55
- }
56
- if (!isNative(token) && asBigint(args.amount) !== inner.sourceAmount) {
57
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_ALLOWANCE_AMOUNT_MISMATCH, { ...inner.diagnostics, ...diagnostics });
58
- }
59
- if (['receiveERC20', 'depositForBurn'].includes(inner.protocolMethod ?? '') &&
60
- value !== (isNative(token) ? inner.sourceAmount : 0n)) {
61
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_NATIVE_VALUE_MISMATCH, { ...inner.diagnostics, ...diagnostics });
62
- }
63
- return {
64
- ...inner,
65
- diagnostics: { ...inner.diagnostics, ...diagnostics },
66
- sourceToken: isNative(inner.sourceToken ?? token) ? NATIVE_TOKEN : inner.sourceToken ?? token,
67
- sourceAmount: inner.sourceAmount ?? asBigint(args.amount),
68
- innerTarget: inner.innerTarget ?? asString(args.target),
69
- };
70
- },
71
- };
@@ -1,4 +0,0 @@
1
- import type { BridgeCallExpectation } from '../expect.js';
2
- import type { BridgeCheck, DecodeHit } from '../types.js';
3
- export declare const decodeSocket: (data: string, value: bigint) => DecodeHit;
4
- export declare const validateSocket: (data: string, value: bigint, expectation?: BridgeCallExpectation, chainId?: string) => BridgeCheck;
@@ -1,13 +0,0 @@
1
- import { matchMethod } from '../match.js';
2
- import { finishCheck, knownCompare } from '../expect.js';
3
- import { exec } from './exec.js';
4
- import { socketFailure } from './validate.js';
5
- const METHODS = [exec];
6
- export const decodeSocket = (data, value) => matchMethod(METHODS, data, value);
7
- export const validateSocket = (data, value, expectation, chainId = '') => {
8
- const hit = decodeSocket(data, value);
9
- if (!hit.ok) {
10
- return { ...hit, aggregatorId: 'socket' };
11
- }
12
- return finishCheck('socket', hit.parsed, socketFailure(hit.parsed, expectation?.userAddress), expectation, chainId, knownCompare(hit.parsed));
13
- };
@@ -1,5 +0,0 @@
1
- import type { AbiParam } from '../abi.js';
2
- export declare const input: AbiParam;
3
- export declare const fee: AbiParam;
4
- export declare const swapData: AbiParam;
5
- export declare const bridgeData: AbiParam;
@@ -1,14 +0,0 @@
1
- export const input = { name: 'input', kind: 'tuple', components: [
2
- { name: 'user', kind: 'address' }, { name: 'inputToken', kind: 'address' }, { name: 'inputAmount', kind: 'uint' },
3
- ] };
4
- export const fee = { name: 'fee', kind: 'tuple', components: [
5
- { name: 'receiver', kind: 'address' }, { name: 'amount', kind: 'uint' },
6
- ] };
7
- export const swapData = { name: 'swapData', kind: 'tuple', components: [
8
- { name: 'target', kind: 'address' }, { name: 'approvalSpender', kind: 'address' },
9
- { name: 'outputToken', kind: 'address' }, { name: 'value', kind: 'uint' },
10
- { name: 'minOutput', kind: 'uint' }, { name: 'returnDataWordOffset', kind: 'uint' },
11
- ] };
12
- export const bridgeData = { name: 'bridgeData', kind: 'tuple', components: [
13
- { name: 'target', kind: 'address' }, { name: 'approvalSpender', kind: 'address' }, { name: 'value', kind: 'uint' },
14
- ] };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readCcip: (data: string, target: string) => Partial<ParsedBridgeCall>;
@@ -1,32 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../../../errors/index.js';
2
- import { asArray, asBigint, asRecord, asString, decodeCall, decodeParameters } from '../../abi.js';
3
- import { CCIP_CHAINS } from '../../protocols.js';
4
- const message = { name: 'message', kind: 'tuple', components: [
5
- { name: 'receiver', kind: 'bytes' }, { name: 'data', kind: 'bytes' },
6
- { name: 'tokenAmounts', kind: 'array', item: { name: 'tokenAmount', kind: 'tuple', components: [
7
- { name: 'token', kind: 'address' }, { name: 'amount', kind: 'uint' },
8
- ] } },
9
- { name: 'feeToken', kind: 'address' }, { name: 'extraArgs', kind: 'bytes' },
10
- ] };
11
- export const readCcip = (data, target) => {
12
- const a = decodeCall([{ name: 'destinationChainSelector', kind: 'uint' }, message], data);
13
- const m = asRecord(a.message);
14
- const amounts = asArray(m.tokenAmounts);
15
- if (amounts.length !== 1)
16
- throw new BridgeError(BRIDGE_ERRORS.CCIP_REQUIRES_ONE_BRIDGE_ASSET);
17
- const token = asRecord(amounts[0]);
18
- const ref = { protocol: 'ccip', contract: target, token: asString(token.token),
19
- destinationChainId: CCIP_CHAINS[asBigint(a.destinationChainSelector).toString()],
20
- destinationChainRef: `ccip:${asBigint(a.destinationChainSelector)}` };
21
- const receiverData = asString(m.receiver);
22
- const receiver = receiverData.length === 66
23
- ? asString(decodeParameters([{ name: 'receiver', kind: 'address' }], receiverData).receiver) : undefined;
24
- const extra = asString(m.extraArgs);
25
- const direct = asString(m.data) === '0x' && (extra === '0x' || ['0x97a657c9', '0x181dcf10'].includes(extra.slice(0, 10)));
26
- return { protocolMethod: 'ccipSend', destinationChainId: ref.destinationChainId,
27
- destinationChainRef: ref.destinationChainRef, bridgeReceiver: receiver, receiver: direct ? receiver : undefined,
28
- outputTokenReference: direct ? ref : undefined,
29
- outputAmountReference: direct ? { kind: 'decimals', amount: asBigint(token.amount), token: ref } : undefined,
30
- destinationCallData: direct ? undefined : asString(m.data),
31
- };
32
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readCctp: (data: string) => Partial<ParsedBridgeCall>;
@@ -1,24 +0,0 @@
1
- import { asBigint, asString, decodeCall } from '../../abi.js';
2
- import { accountFromBytes32 } from '../../hex.js';
3
- import { CCTP_CHAINS, CCTP_USDC, subtractFees } from '../../protocols.js';
4
- export const readCctp = (data) => {
5
- const a = decodeCall([
6
- { name: 'amount', kind: 'uint' }, { name: 'destinationDomain', kind: 'uint' },
7
- { name: 'mintRecipient', kind: 'bytes', size: 32 }, { name: 'burnToken', kind: 'address' },
8
- { name: 'destinationCaller', kind: 'bytes', size: 32 }, { name: 'maxFee', kind: 'uint' },
9
- { name: 'minFinalityThreshold', kind: 'uint' },
10
- ], data);
11
- const id = asBigint(a.destinationDomain);
12
- const destinationChainId = CCTP_CHAINS[id.toString()];
13
- const receiver = accountFromBytes32(asString(a.mintRecipient));
14
- const intermediary = receiver === '0x424a31a57f7c63918ecaa2fac38016a8af5a6ec2';
15
- return { protocolMethod: 'depositForBurn', destinationChainId, destinationChainRef: `cctp:${id}`,
16
- bridgeReceiver: receiver, receiver: intermediary ? undefined : receiver,
17
- bridgeToken: asString(a.burnToken), bridgeAmount: asBigint(a.amount),
18
- bridgeOutputToken: CCTP_USDC[destinationChainId?.toString() ?? ''],
19
- bridgeOutputAmount: subtractFees(asBigint(a.amount), asBigint(a.maxFee)),
20
- outputToken: CCTP_USDC[destinationChainId?.toString() ?? ''],
21
- minOutputAmount: intermediary ? undefined : subtractFees(asBigint(a.amount), asBigint(a.maxFee)),
22
- // ClaimExecutor's recipient and relay fee are signed on the destination, outside this calldata.
23
- };
24
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../../types.js';
2
- export declare const readEco: (data: string) => Partial<ParsedBridgeCall>;
@@ -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,81 +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 { readCcip } from './ccip.js';
6
- import { readCctp } from './cctp.js';
7
- import { readEco } from './eco.js';
8
- import { readNativeBridge } from './native.js';
9
- import { readOft } from './oft.js';
10
- import { readSwapsXYZ } from './swapsXYZ.js';
11
- const decodeSocketBridge = (data, target, token, value, spender) => {
12
- const selector = readSelector(data);
13
- const native = readNativeBridge(data, target, value);
14
- if (native)
15
- return native;
16
- if (selector === '0x96f4e9f9')
17
- return readCcip(data, target);
18
- if (selector === '0x8e0250ee') {
19
- if (target !== '0x28b5a0e9c621a5badaa536219b3a228c8168cf5d' || spender !== target || value !== 0n) {
20
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_CCTP_TARGET_SPENDER_OR_VALUE);
21
- }
22
- const parsed = readCctp(data);
23
- if (parsed.bridgeToken !== token)
24
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_CCTP_TOKEN_DOES_NOT_MATCH_BRIDGE_ASSET);
25
- return parsed;
26
- }
27
- if (selector === '0xdf00f8fa')
28
- return readEco(data);
29
- if (selector === '0xc7c7f5b3' || selector === '0x2cdf0b95')
30
- return readOft(data, target, token);
31
- if (selector === '0x0c751e0b' || selector === '0x9be111d1')
32
- return readSwapsXYZ(data);
33
- if (selector === '0x823b01f9') {
34
- if (target !== '0x97caca78ac2a94c67643d07843f85afaa44a3ea5' || spender !== target || value !== 0n) {
35
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_RFQ_TARGET_SPENDER_OR_VALUE);
36
- }
37
- const a = decodeCall([{ name: 'quoteId', kind: 'bytes', size: 32 }, { name: 'token', kind: 'address' }, { name: 'amount', kind: 'uint' }], data);
38
- if (asString(a.token) !== token)
39
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_RFQ_TOKEN_DOES_NOT_MATCH_BRIDGE_ASSET);
40
- return { protocolMethod: 'receiveERC20', orderId: asString(a.quoteId), bridgeToken: asString(a.token), bridgeAmount: asBigint(a.amount) };
41
- }
42
- return undefined;
43
- };
44
- export const readSocketBridge = (data, target, token, value, spender) => {
45
- const diagnostics = innerCallDiagnostics(data, 'protocol');
46
- try {
47
- const parsed = decodeSocketBridge(data, target, token, value, spender);
48
- return { ...parsed, diagnostics: { ...parsed?.diagnostics, ...diagnostics } };
49
- }
50
- catch (error) {
51
- throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, diagnostics);
52
- }
53
- };
54
- const word = (data, offset) => {
55
- const raw = data.slice(2 + offset * 2, 2 + (offset + 32) * 2);
56
- if (raw.length !== 64)
57
- throw new BridgeError(BRIDGE_ERRORS.INVALID_BRIDGE_OFFSET);
58
- const n = BigInt(`0x${raw}`);
59
- if (n > BigInt(data.length / 2))
60
- throw new BridgeError(BRIDGE_ERRORS.BRIDGE_OFFSET_EXCEEDS_CALLDATA);
61
- return Number(n);
62
- };
63
- export const spliceBridgeAmount = (data, flags, amount) => {
64
- if ((flags & 8n) === 0n)
65
- return data;
66
- const position = Number(flags >> 16n & 65535n);
67
- const selector = readSelector(data);
68
- let expected = {
69
- '0xd2ce7d65': 68, '0xad58bdd1': 68, '0x8b9e4f93': 68,
70
- '0x838b2520': 100, '0x8e0250ee': 4, '0x823b01f9': 68, '0x2cdf0b95': 100,
71
- }[selector ?? ''];
72
- if (selector === '0xc7c7f5b3')
73
- expected = 4 + word(data, 4) + 64;
74
- if (selector === '0x96f4e9f9') {
75
- const message = 4 + word(data, 36);
76
- expected = message + word(data, message + 64) + 64;
77
- }
78
- if (position !== expected || 2 + (position + 32) * 2 > data.length)
79
- throw new BridgeError(BRIDGE_ERRORS.BRIDGE_SPLICE_DOES_NOT_TARGET_THE_INPUT_AMOUNT);
80
- return data.slice(0, 2 + position * 2) + amount.toString(16).padStart(64, '0') + data.slice(2 + (position + 32) * 2);
81
- };
@@ -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,31 +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
- const direct = legacy || (asString(a.composeMsg) === '0x' && asString(a.oftCmd) === '0x');
24
- return { protocolMethod: legacy ? 'sendFrom' : 'send', destinationChainId: ref.destinationChainId,
25
- destinationChainRef: ref.destinationChainRef, bridgeReceiver: accountFromBytes32(asString(a.to)),
26
- receiver: direct ? accountFromBytes32(asString(a.to)) : undefined,
27
- outputTokenReference: direct ? ref : undefined,
28
- outputAmountReference: direct ? { kind: 'decimals', amount: asBigint(a.minAmountLD), token: ref } : undefined,
29
- destinationCallData: direct ? undefined : asString(a.composeMsg),
30
- };
31
- };
@@ -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,37 +0,0 @@
1
- import { BRIDGE_ERRORS, 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
- return {
30
- aggregatorId: 'socket', method: 'swapAndBridge', kind: 'bridge', quoteId: asString(a.quoteId),
31
- sourceToken: asString(source.inputToken), sourceAmount: asBigint(source.inputAmount), depositor: asString(source.user),
32
- bridgeToken: token, bridgeAmount: amount,
33
- referrer: asString(asRecord(a.fee).receiver), innerTarget: target,
34
- ...readSocketBridge(callData, target, token, value, asString(hop.approvalSpender)),
35
- };
36
- },
37
- };
@@ -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,21 +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 (!parsed.protocolMethod)
13
- return BRIDGE_ERRORS.UNRECOGNIZED_SOCKET_BRIDGE_CALLDATA;
14
- if (parsed.sourceToken === undefined) {
15
- return BRIDGE_ERRORS.MISSING_SOURCE_TOKEN;
16
- }
17
- if ((parsed.sourceAmount ?? 0n) <= 0n) {
18
- return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
19
- }
20
- return undefined;
21
- };
@@ -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;