@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 { asString, decodeCall } from '../abi.js';
2
- export const depositNative = {
3
- name: 'depositNative',
4
- selector: '0x49290c1c',
5
- decode(data, value) {
6
- const args = decodeCall([
7
- { name: 'depositor', kind: 'address' },
8
- { name: 'id', kind: 'bytes', size: 32 },
9
- ], data);
10
- return {
11
- aggregatorId: 'relay',
12
- method: 'depositNative',
13
- kind: 'deposit',
14
- sourceToken: '0x0000000000000000000000000000000000000000',
15
- sourceAmount: value,
16
- orderId: asString(args.id),
17
- depositor: asString(args.depositor),
18
- };
19
- },
20
- };
@@ -1,4 +0,0 @@
1
- import type { BridgeCallExpectation } from '../expect.js';
2
- import type { BridgeCheck, DecodeHit } from '../types.js';
3
- export declare const decodeRelay: (data: string, value: bigint) => DecodeHit;
4
- export declare const validateRelay: (data: string, value: bigint, expectation?: BridgeCallExpectation, chainId?: string) => BridgeCheck;
@@ -1,42 +0,0 @@
1
- import { matchMethod } from '../match.js';
2
- import { finishCheck } from '../expect.js';
3
- import { depositErc20 } from './depositErc20.js';
4
- import { depositErc20Allowance } from './depositErc20Allowance.js';
5
- import { depositNative } from './depositNative.js';
6
- import { multicall } from './multicall.js';
7
- import { permit2TransferAndMulticall } from './permit2TransferAndMulticall.js';
8
- import { permit3009TransferAndMulticall } from './permit3009TransferAndMulticall.js';
9
- import { permit3009TransferAndMulticallSigned } from './permit3009TransferAndMulticallSigned.js';
10
- import { permitTransferAndMulticall } from './permitTransferAndMulticall.js';
11
- import { permitTransferAndMulticallLegacy } from './permitTransferAndMulticallLegacy.js';
12
- import { transferAndMulticall } from './transferAndMulticall.js';
13
- import { relayFailure } from './validate.js';
14
- import { BRIDGE_ERRORS } from '../../errors/index.js';
15
- const METHODS = [
16
- depositErc20,
17
- depositErc20Allowance,
18
- depositNative,
19
- multicall,
20
- transferAndMulticall,
21
- permit2TransferAndMulticall,
22
- permit3009TransferAndMulticall,
23
- permit3009TransferAndMulticallSigned,
24
- permitTransferAndMulticall,
25
- permitTransferAndMulticallLegacy,
26
- ];
27
- export const decodeRelay = (data, value) => matchMethod(METHODS, data, value);
28
- const relayCompareMask = (parsed) => ({
29
- fromToken: parsed.sourceToken !== undefined,
30
- fromAmount: parsed.sourceAmount !== undefined && parsed.sourceToken !== undefined,
31
- toToken: false,
32
- toAmount: false,
33
- receiver: false,
34
- });
35
- export const validateRelay = (data, value, expectation, chainId = '') => {
36
- const hit = decodeRelay(data, value);
37
- if (!hit.ok) {
38
- return { ...hit, aggregatorId: 'relay' };
39
- }
40
- return finishCheck('relay', hit.parsed, expectation && hit.parsed.depositor !== undefined && hit.parsed.depositor !== expectation.userAddress.toLowerCase()
41
- ? BRIDGE_ERRORS.DEPOSITOR_MISMATCH : relayFailure(hit.parsed), expectation, chainId, relayCompareMask(hit.parsed));
42
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const multicall: CalldataMethod;
@@ -1,15 +0,0 @@
1
- import { asString, decodeCall } from '../abi.js';
2
- import { callsParam, relayCall } from './calls.js';
3
- export const multicall = {
4
- name: 'multicall',
5
- selector: '0xcd6e13f7',
6
- decode(data, value) {
7
- const args = decodeCall([
8
- callsParam,
9
- { name: 'refundTo', kind: 'address' },
10
- { name: 'nftRecipient', kind: 'address' },
11
- { name: 'metadata', kind: 'bytes' },
12
- ], data);
13
- return relayCall('multicall', asString(args.metadata), value);
14
- },
15
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const permit2TransferAndMulticall: CalldataMethod;
@@ -1,42 +0,0 @@
1
- import { asArray, asRecord, asString, decodeCall } from '../abi.js';
2
- import { callsParam, firstPositive, relayCall } from './calls.js';
3
- const permit = {
4
- name: 'permit',
5
- kind: 'tuple',
6
- components: [
7
- {
8
- name: 'permitted',
9
- kind: 'array',
10
- item: {
11
- name: 'tokenPermissions',
12
- kind: 'tuple',
13
- components: [
14
- { name: 'token', kind: 'address' },
15
- { name: 'amount', kind: 'uint' },
16
- ],
17
- },
18
- },
19
- { name: 'nonce', kind: 'uint' },
20
- { name: 'deadline', kind: 'uint' },
21
- ],
22
- };
23
- export const permit2TransferAndMulticall = {
24
- name: 'permit2TransferAndMulticall',
25
- selector: '0x0a2b8f36',
26
- decode(data, value) {
27
- const args = decodeCall([
28
- { name: 'user', kind: 'address' },
29
- permit,
30
- callsParam,
31
- { name: 'refundTo', kind: 'address' },
32
- { name: 'nftRecipient', kind: 'address' },
33
- { name: 'metadata', kind: 'bytes' },
34
- { name: 'permitSignature', kind: 'bytes' },
35
- ], data);
36
- const source = firstPositive(asArray(asRecord(args.permit).permitted));
37
- return {
38
- ...relayCall('permit2TransferAndMulticall', asString(args.metadata), value, source),
39
- depositor: asString(args.user),
40
- };
41
- },
42
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const permit3009TransferAndMulticall: CalldataMethod;
@@ -1,41 +0,0 @@
1
- import { asArray, asString, decodeCall } from '../abi.js';
2
- import { callsParam, firstPositive, relayCall } from './calls.js';
3
- const permits = {
4
- name: 'permits',
5
- kind: 'array',
6
- item: {
7
- name: 'permit',
8
- kind: 'tuple',
9
- components: [
10
- { name: 'from', kind: 'address' },
11
- { name: 'value', kind: 'uint' },
12
- { name: 'validAfter', kind: 'uint' },
13
- { name: 'validBefore', kind: 'uint' },
14
- { name: 'v', kind: 'uint' },
15
- { name: 'r', kind: 'bytes', size: 32 },
16
- { name: 's', kind: 'bytes', size: 32 },
17
- ],
18
- },
19
- };
20
- const decodePermits = (name, selector, tail) => ({
21
- name,
22
- selector,
23
- decode(data, value) {
24
- const args = decodeCall([
25
- permits,
26
- { name: 'tokens', kind: 'array', item: { name: 'token', kind: 'address' } },
27
- callsParam,
28
- { name: 'refundTo', kind: 'address' },
29
- { name: 'nftRecipient', kind: 'address' },
30
- { name: 'metadata', kind: 'bytes' },
31
- ...tail,
32
- ], data);
33
- const source = firstPositive(asArray(args.permits));
34
- const tokens = asArray(args.tokens).map((token) => asString(token));
35
- return relayCall(name, asString(args.metadata), value, {
36
- token: tokens[0] ?? source.token,
37
- amount: source.amount,
38
- });
39
- },
40
- });
41
- export const permit3009TransferAndMulticall = decodePermits('permit3009TransferAndMulticall', '0xf80f00fb', []);
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const permit3009TransferAndMulticallSigned: CalldataMethod;
@@ -1,40 +0,0 @@
1
- import { asArray, asString, decodeCall } from '../abi.js';
2
- import { callsParam, firstPositive, relayCall } from './calls.js';
3
- const permits = {
4
- name: 'permits',
5
- kind: 'array',
6
- item: {
7
- name: 'permit',
8
- kind: 'tuple',
9
- components: [
10
- { name: 'from', kind: 'address' },
11
- { name: 'value', kind: 'uint' },
12
- { name: 'validAfter', kind: 'uint' },
13
- { name: 'validBefore', kind: 'uint' },
14
- { name: 'v', kind: 'uint' },
15
- { name: 'r', kind: 'bytes', size: 32 },
16
- { name: 's', kind: 'bytes', size: 32 },
17
- ],
18
- },
19
- };
20
- export const permit3009TransferAndMulticallSigned = {
21
- name: 'permit3009TransferAndMulticallSigned',
22
- selector: '0x745599f3',
23
- decode(data, value) {
24
- const args = decodeCall([
25
- permits,
26
- { name: 'tokens', kind: 'array', item: { name: 'token', kind: 'address' } },
27
- callsParam,
28
- { name: 'refundTo', kind: 'address' },
29
- { name: 'nftRecipient', kind: 'address' },
30
- { name: 'metadata', kind: 'bytes' },
31
- { name: 'multicallSignatures', kind: 'array', item: { name: 'signature', kind: 'bytes' } },
32
- ], data);
33
- const source = firstPositive(asArray(args.permits));
34
- const tokens = asArray(args.tokens).map((token) => asString(token));
35
- return relayCall('permit3009TransferAndMulticallSigned', asString(args.metadata), value, {
36
- token: tokens[0] ?? source.token,
37
- amount: source.amount,
38
- });
39
- },
40
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const permitTransferAndMulticall: CalldataMethod;
@@ -1,34 +0,0 @@
1
- import { asArray, asString, decodeCall } from '../abi.js';
2
- import { callsParam, firstPositive, relayCall } from './calls.js';
3
- const permits = {
4
- name: 'permits',
5
- kind: 'array',
6
- item: {
7
- name: 'permit',
8
- kind: 'tuple',
9
- components: [
10
- { name: 'token', kind: 'address' },
11
- { name: 'owner', kind: 'address' },
12
- { name: 'value', kind: 'uint' },
13
- { name: 'deadline', kind: 'uint' },
14
- { name: 'v', kind: 'uint' },
15
- { name: 'r', kind: 'bytes', size: 32 },
16
- { name: 's', kind: 'bytes', size: 32 },
17
- ],
18
- },
19
- };
20
- export const permitTransferAndMulticall = {
21
- name: 'permitTransferAndMulticall',
22
- selector: '0xbd4967a9',
23
- decode(data, value) {
24
- const args = decodeCall([
25
- permits,
26
- callsParam,
27
- { name: 'refundTo', kind: 'address' },
28
- { name: 'nftRecipient', kind: 'address' },
29
- { name: 'metadata', kind: 'bytes' },
30
- ], data);
31
- const source = firstPositive(asArray(args.permits));
32
- return relayCall('permitTransferAndMulticall', asString(args.metadata), value, source);
33
- },
34
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const permitTransferAndMulticallLegacy: CalldataMethod;
@@ -1,35 +0,0 @@
1
- import { asArray, asString, decodeCall } from '../abi.js';
2
- import { callsParam, firstPositive, relayCall } from './calls.js';
3
- const permits = {
4
- name: 'permits',
5
- kind: 'array',
6
- item: {
7
- name: 'permit',
8
- kind: 'tuple',
9
- components: [
10
- { name: 'token', kind: 'address' },
11
- { name: 'owner', kind: 'address' },
12
- { name: 'value', kind: 'uint' },
13
- { name: 'nonce', kind: 'uint' },
14
- { name: 'deadline', kind: 'uint' },
15
- { name: 'v', kind: 'uint' },
16
- { name: 'r', kind: 'bytes', size: 32 },
17
- { name: 's', kind: 'bytes', size: 32 },
18
- ],
19
- },
20
- };
21
- export const permitTransferAndMulticallLegacy = {
22
- name: 'permitTransferAndMulticallLegacy',
23
- selector: '0xfb68c293',
24
- decode(data, value) {
25
- const args = decodeCall([
26
- permits,
27
- callsParam,
28
- { name: 'refundTo', kind: 'address' },
29
- { name: 'nftRecipient', kind: 'address' },
30
- { name: 'metadata', kind: 'bytes' },
31
- ], data);
32
- const source = firstPositive(asArray(args.permits));
33
- return relayCall('permitTransferAndMulticallLegacy', asString(args.metadata), value, source);
34
- },
35
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const transferAndMulticall: CalldataMethod;
@@ -1,26 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
2
- import { asArray, asBigint, asString, decodeCall } from '../abi.js';
3
- import { callsParam, relayCall } from './calls.js';
4
- export const transferAndMulticall = {
5
- name: 'transferAndMulticall',
6
- selector: '0xf9e4bab4',
7
- decode(data, value) {
8
- const args = decodeCall([
9
- { name: 'tokens', kind: 'array', item: { name: 'token', kind: 'address' } },
10
- { name: 'amounts', kind: 'array', item: { name: 'amount', kind: 'uint' } },
11
- callsParam,
12
- { name: 'refundTo', kind: 'address' },
13
- { name: 'nftRecipient', kind: 'address' },
14
- { name: 'metadata', kind: 'bytes' },
15
- ], data);
16
- const tokens = asArray(args.tokens).map((token) => asString(token));
17
- const amounts = asArray(args.amounts).map((amount) => asBigint(amount));
18
- if (tokens.length !== amounts.length || new Set(tokens).size > 1) {
19
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_SOURCE_ASSET_LIST);
20
- }
21
- return relayCall('transferAndMulticall', asString(args.metadata), value, {
22
- token: tokens[0],
23
- amount: amounts.reduce((sum, amount) => sum + amount, 0n),
24
- });
25
- },
26
- };
@@ -1,3 +0,0 @@
1
- import type { BridgeErrorDefinition } from '../../errors/index.js';
2
- import type { ParsedBridgeCall } from '../types.js';
3
- export declare const relayFailure: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
@@ -1,18 +0,0 @@
1
- import { BRIDGE_ERRORS } from '../../errors/index.js';
2
- import { isZeroWord } from '../hex.js';
3
- const AMOUNT_OPTIONAL = new Set(['depositErc20Allowance', 'multicall']);
4
- export const relayFailure = (parsed) => {
5
- if (isZeroWord(parsed.orderId) && isZeroWord(parsed.requestId)) {
6
- return BRIDGE_ERRORS.MISSING_RELAY_ORDER_ID;
7
- }
8
- if (AMOUNT_OPTIONAL.has(parsed.method)) {
9
- return undefined;
10
- }
11
- if ((parsed.sourceAmount ?? 0n) <= 0n) {
12
- return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
13
- }
14
- if (parsed.sourceToken === undefined) {
15
- return BRIDGE_ERRORS.MISSING_SOURCE_TOKEN;
16
- }
17
- return undefined;
18
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from './types.js';
2
- export declare const resolveParsed: (parsed: ParsedBridgeCall) => ParsedBridgeCall;
@@ -1,28 +0,0 @@
1
- import { CCTP_USDC, isNative } from './protocols.js';
2
- const tokenInfo = (reference) => {
3
- if (reference.protocol === 'cctp' && reference.destinationChainId !== undefined) {
4
- const token = CCTP_USDC[reference.destinationChainId.toString()];
5
- if (token)
6
- return { token, decimals: 6 };
7
- }
8
- if (reference.protocol === 'token' && reference.token && isNative(reference.token)) {
9
- return { token: reference.token, decimals: 18 };
10
- }
11
- return undefined;
12
- };
13
- export const resolveParsed = (parsed) => {
14
- const info = parsed.outputTokenReference ? tokenInfo(parsed.outputTokenReference) : undefined;
15
- if (info)
16
- parsed.outputToken = info.token;
17
- const amount = parsed.outputAmountReference;
18
- if (amount?.kind === 'normalized' && parsed.minOutputAmount === undefined) {
19
- const metadata = tokenInfo(amount.token);
20
- if (metadata) {
21
- const sourceDecimals = Math.min(metadata.decimals, amount.decimals ?? 8);
22
- parsed.minOutputAmount = amount.amount * 10n ** BigInt(metadata.decimals - sourceDecimals);
23
- }
24
- }
25
- parsed.unresolvedFields = ['sourceToken', 'sourceAmount', 'outputToken', 'minOutputAmount', 'receiver']
26
- .filter((field) => parsed[field] === undefined);
27
- return parsed;
28
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const bridge: CalldataMethod;
@@ -1,28 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
2
- import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
3
- import { subtractFees } from '../protocols.js';
4
- import { bridgeData, fee, input } from './params.js';
5
- import { readSocketBridge } from './protocols/index.js';
6
- export const bridge = {
7
- name: 'bridge', selector: '0xb18248d5',
8
- decode(data) {
9
- const a = decodeCall([{ name: 'quoteId', kind: 'bytes', size: 32 }, input, fee, bridgeData,
10
- { name: 'bridgeCallData', kind: 'bytes' }], data);
11
- const source = asRecord(a.input);
12
- const hop = asRecord(a.bridgeData);
13
- const target = asString(hop.target);
14
- const token = asString(source.inputToken);
15
- const amount = subtractFees(asBigint(source.inputAmount), asBigint(asRecord(a.fee).amount));
16
- const protocol = readSocketBridge(asString(a.bridgeCallData), target, token, asBigint(hop.value), asString(hop.approvalSpender));
17
- if (['receiveERC20', 'receiveNative', 'depositForBurn'].includes(protocol?.protocolMethod ?? '') && protocol?.bridgeAmount !== amount) {
18
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_DEPOSIT_AMOUNT_MISMATCH, protocol?.diagnostics);
19
- }
20
- return {
21
- aggregatorId: 'socket', method: 'bridge', kind: 'bridge', quoteId: asString(a.quoteId),
22
- sourceToken: token, sourceAmount: asBigint(source.inputAmount), depositor: asString(source.user),
23
- bridgeToken: token, bridgeAmount: amount,
24
- referrer: asString(asRecord(a.fee).receiver), innerTarget: target,
25
- ...protocol,
26
- };
27
- },
28
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const exec: CalldataMethod;
@@ -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', 'receiveNative', '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>;