@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,48 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
2
- import { asBigint, asString, decodeCall } from '../abi.js';
3
- import { accountFromBytes32 } from '../hex.js';
4
- import { mayanDestination } from './destination.js';
5
- import { subtractFees } from '../protocols.js';
6
- export const FAST_MCTP_BRIDGE = '0xf58b6de8';
7
- export const decodeFastMctpBridge = (data, amountFloor) => {
8
- const args = decodeCall([
9
- { name: 'tokenIn', kind: 'address' },
10
- { name: 'amountIn', kind: 'uint' },
11
- { name: 'redeemFee', kind: 'uint' },
12
- { name: 'circleMaxFee', kind: 'uint' },
13
- { name: 'gasDrop', kind: 'uint' },
14
- { name: 'destAddr', kind: 'bytes', size: 32 },
15
- { name: 'destDomain', kind: 'uint' },
16
- { name: 'referrerAddress', kind: 'bytes', size: 32 },
17
- { name: 'referrerBps', kind: 'uint' },
18
- { name: 'payloadType', kind: 'uint' },
19
- { name: 'minFinalityThreshold', kind: 'uint' },
20
- { name: 'customPayload', kind: 'bytes' },
21
- ], data);
22
- const destination = mayanDestination('cctp', asBigint(args.destDomain));
23
- const token = { protocol: 'cctp', destinationChainId: destination.destinationChainId };
24
- const payloadType = asBigint(args.payloadType);
25
- if (payloadType !== 1n && payloadType !== 2n)
26
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_MAYAN_PROTOCOL_CALLDATA);
27
- // FastMCTP.bridge hashes customPayload only for type 2; type 1 is a direct
28
- // payout even when the unused bytes are nonempty (verified FastMCTP.sol).
29
- const custom = payloadType === 2n;
30
- const net = subtractFees(amountFloor ?? asBigint(args.amountIn), asBigint(args.redeemFee), asBigint(args.circleMaxFee));
31
- const referrerBps = asBigint(args.referrerBps);
32
- if (referrerBps > 100n)
33
- throw new BridgeError(BRIDGE_ERRORS.INVALID_FASTMCTP_REFERRER_FEE);
34
- // redeem caps the destination protocol fee at 100 bps; it is not fixed by the source deposit.
35
- const minimum = net * (10000n - 100n - referrerBps) / 10000n;
36
- return {
37
- protocolMethod: 'bridge',
38
- sourceToken: asString(args.tokenIn),
39
- sourceAmount: asBigint(args.amountIn),
40
- ...destination,
41
- outputTokenReference: custom ? undefined : token,
42
- minOutputAmount: custom ? undefined : minimum,
43
- bridgeReceiver: accountFromBytes32(asString(args.destAddr)),
44
- receiver: custom ? undefined : accountFromBytes32(asString(args.destAddr)),
45
- destinationCallData: custom ? asString(args.customPayload) : undefined,
46
- referrer: accountFromBytes32(asString(args.referrerAddress)),
47
- };
48
- };
@@ -1,3 +0,0 @@
1
- import type { ParsedBridgeCall } from '../types.js';
2
- export declare const FAST_MCTP_CREATE_ORDER = "0x2337e236";
3
- export declare const decodeFastMctpCreateOrder: (data: string) => Partial<ParsedBridgeCall>;
@@ -1,39 +0,0 @@
1
- import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
2
- import { accountFromBytes32 } from '../hex.js';
3
- import { mayanDestination } from './destination.js';
4
- const orderPayload = {
5
- name: 'orderPayload',
6
- kind: 'tuple',
7
- components: [
8
- { name: 'payloadType', kind: 'uint' },
9
- { name: 'destAddr', kind: 'bytes', size: 32 },
10
- { name: 'tokenOut', kind: 'bytes', size: 32 },
11
- { name: 'amountOutMin', kind: 'uint' },
12
- { name: 'gasDrop', kind: 'uint' },
13
- { name: 'redeemFee', kind: 'uint' },
14
- { name: 'refundFee', kind: 'uint' },
15
- { name: 'deadline', kind: 'uint' },
16
- { name: 'referrerAddr', kind: 'bytes', size: 32 },
17
- { name: 'referrerBps', kind: 'uint' },
18
- ],
19
- };
20
- export const FAST_MCTP_CREATE_ORDER = '0x2337e236';
21
- export const decodeFastMctpCreateOrder = (data) => {
22
- const args = decodeCall([
23
- { name: 'tokenIn', kind: 'address' },
24
- { name: 'amountIn', kind: 'uint' },
25
- { name: 'circleMaxFee', kind: 'uint' },
26
- { name: 'destDomain', kind: 'uint' },
27
- { name: 'minFinalityThreshold', kind: 'uint' },
28
- orderPayload,
29
- ], data);
30
- const order = asRecord(args.orderPayload);
31
- return {
32
- protocolMethod: 'createOrder',
33
- sourceToken: asString(args.tokenIn),
34
- sourceAmount: asBigint(args.amountIn),
35
- ...mayanDestination('cctp', asBigint(args.destDomain), accountFromBytes32(asString(order.tokenOut)), asBigint(order.amountOutMin)),
36
- receiver: accountFromBytes32(asString(order.destAddr)),
37
- referrer: accountFromBytes32(asString(order.referrerAddr)),
38
- };
39
- };
@@ -1,8 +0,0 @@
1
- import type { AbiParam } from '../abi.js';
2
- import type { ParsedBridgeCall } from '../types.js';
3
- export declare const permitParams: AbiParam;
4
- export declare const finishForward: (method: string, protocol: string, protocolData: string, source: {
5
- token?: string;
6
- amount?: bigint;
7
- protocolAmount?: bigint;
8
- }) => ParsedBridgeCall;
@@ -1,35 +0,0 @@
1
- import { readMayanProtocol } from './readProtocol.js';
2
- import { innerCallDiagnostics } from '../diagnostics.js';
3
- export const permitParams = {
4
- name: 'permitParams',
5
- kind: 'tuple',
6
- components: [
7
- { name: 'value', kind: 'uint' },
8
- { name: 'deadline', kind: 'uint' },
9
- { name: 'v', kind: 'uint' },
10
- { name: 'r', kind: 'bytes', size: 32 },
11
- { name: 's', kind: 'bytes', size: 32 },
12
- ],
13
- };
14
- export const finishForward = (method, protocol, protocolData, source) => {
15
- const parsed = {
16
- aggregatorId: 'mayan',
17
- method,
18
- kind: 'bridge',
19
- innerTarget: protocol,
20
- sourceToken: source.token,
21
- sourceAmount: source.amount,
22
- diagnostics: innerCallDiagnostics(protocolData, 'protocol'),
23
- };
24
- const order = readMayanProtocol(protocolData, source.protocolAmount ?? source.amount);
25
- if (!order) {
26
- return parsed;
27
- }
28
- const { sourceToken, sourceAmount, ...destination } = order;
29
- Object.assign(parsed, destination);
30
- parsed.sourceToken = parsed.sourceToken ?? order.sourceToken;
31
- if ((parsed.sourceAmount ?? 0n) === 0n) {
32
- parsed.sourceAmount = order.sourceAmount;
33
- }
34
- return parsed;
35
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const forwardERC20: CalldataMethod;
@@ -1,19 +0,0 @@
1
- import { asBigint, asString, decodeCall } from '../abi.js';
2
- import { finishForward, permitParams } from './forward.js';
3
- export const forwardERC20 = {
4
- name: 'forwardERC20',
5
- selector: '0xe4269fc4',
6
- decode(data) {
7
- const args = decodeCall([
8
- { name: 'tokenIn', kind: 'address' },
9
- { name: 'amountIn', kind: 'uint' },
10
- permitParams,
11
- { name: 'mayanProtocol', kind: 'address' },
12
- { name: 'protocolData', kind: 'bytes' },
13
- ], data);
14
- return finishForward('forwardERC20', asString(args.mayanProtocol), asString(args.protocolData), {
15
- token: asString(args.tokenIn),
16
- amount: asBigint(args.amountIn),
17
- });
18
- },
19
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const forwardEth: CalldataMethod;
@@ -1,16 +0,0 @@
1
- import { asString, decodeCall } from '../abi.js';
2
- import { finishForward } from './forward.js';
3
- export const forwardEth = {
4
- name: 'forwardEth',
5
- selector: '0xb0f584ff',
6
- decode(data, value) {
7
- const args = decodeCall([
8
- { name: 'mayanProtocol', kind: 'address' },
9
- { name: 'protocolData', kind: 'bytes' },
10
- ], data);
11
- return finishForward('forwardEth', asString(args.mayanProtocol), asString(args.protocolData), {
12
- token: '0x0000000000000000000000000000000000000000',
13
- amount: value,
14
- });
15
- },
16
- };
@@ -1,4 +0,0 @@
1
- import type { BridgeCallExpectation } from '../expect.js';
2
- import type { BridgeCheck, DecodeHit } from '../types.js';
3
- export declare const decodeMayan: (data: string, value: bigint) => DecodeHit;
4
- export declare const validateMayan: (data: string, value: bigint, expectation?: BridgeCallExpectation, chainId?: string) => BridgeCheck;
@@ -1,21 +0,0 @@
1
- import { matchMethod } from '../match.js';
2
- import { finishCheck, knownCompare } from '../expect.js';
3
- import { forwardERC20 } from './forwardERC20.js';
4
- import { forwardEth } from './forwardEth.js';
5
- import { swapAndForwardERC20 } from './swapAndForwardERC20.js';
6
- import { swapAndForwardEth } from './swapAndForwardEth.js';
7
- import { mayanFailure } from './validate.js';
8
- const METHODS = [
9
- forwardERC20,
10
- forwardEth,
11
- swapAndForwardERC20,
12
- swapAndForwardEth,
13
- ];
14
- export const decodeMayan = (data, value) => matchMethod(METHODS, data, value);
15
- export const validateMayan = (data, value, expectation, chainId = '') => {
16
- const hit = decodeMayan(data, value);
17
- if (!hit.ok) {
18
- return { ...hit, aggregatorId: 'mayan' };
19
- }
20
- return finishCheck('mayan', hit.parsed, mayanFailure(hit.parsed), expectation, chainId, knownCompare(hit.parsed));
21
- };
@@ -1,5 +0,0 @@
1
- import type { ParsedBridgeCall } from '../types.js';
2
- export declare const MCTP_BRIDGE_WITH_FEE = "0x2072197f";
3
- export declare const MCTP_CREATE_ORDER = "0x1c59b7fc";
4
- export declare const decodeMctpBridge: (data: string, amountFloor?: bigint) => Partial<ParsedBridgeCall>;
5
- export declare const decodeMctpOrder: (data: string) => Partial<ParsedBridgeCall>;
@@ -1,41 +0,0 @@
1
- import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
2
- import { accountFromBytes32 } from '../hex.js';
3
- import { subtractFees } from '../protocols.js';
4
- import { mayanDestination } from './destination.js';
5
- export const MCTP_BRIDGE_WITH_FEE = '0x2072197f';
6
- export const MCTP_CREATE_ORDER = '0x1c59b7fc';
7
- export const decodeMctpBridge = (data, amountFloor) => {
8
- const a = decodeCall([
9
- { name: 'tokenIn', kind: 'address' }, { name: 'amountIn', kind: 'uint' },
10
- { name: 'redeemFee', kind: 'uint' }, { name: 'gasDrop', kind: 'uint' },
11
- { name: 'destAddr', kind: 'bytes', size: 32 }, { name: 'destDomain', kind: 'uint' },
12
- { name: 'payloadType', kind: 'uint' }, { name: 'customPayload', kind: 'bytes' },
13
- ], data);
14
- const destination = mayanDestination('cctp', asBigint(a.destDomain));
15
- const custom = asString(a.customPayload) !== '0x';
16
- return {
17
- protocolMethod: 'bridgeWithFee', ...destination,
18
- sourceToken: asString(a.tokenIn), sourceAmount: asBigint(a.amountIn),
19
- bridgeReceiver: accountFromBytes32(asString(a.destAddr)),
20
- receiver: custom ? undefined : accountFromBytes32(asString(a.destAddr)),
21
- outputTokenReference: custom ? undefined : { protocol: 'cctp', destinationChainId: destination.destinationChainId },
22
- minOutputAmount: custom ? undefined : subtractFees(amountFloor ?? asBigint(a.amountIn), asBigint(a.redeemFee)),
23
- destinationCallData: custom ? asString(a.customPayload) : undefined,
24
- };
25
- };
26
- const order = { name: 'params', kind: 'tuple', components: [
27
- { name: 'tokenIn', kind: 'address' }, { name: 'amountIn', kind: 'uint' },
28
- { name: 'gasDrop', kind: 'uint' }, { name: 'destAddr', kind: 'bytes', size: 32 },
29
- { name: 'destChain', kind: 'uint' }, { name: 'tokenOut', kind: 'bytes', size: 32 },
30
- { name: 'minAmountOut', kind: 'uint' }, { name: 'deadline', kind: 'uint' },
31
- { name: 'redeemFee', kind: 'uint' }, { name: 'referrerAddr', kind: 'bytes', size: 32 },
32
- { name: 'referrerBps', kind: 'uint' },
33
- ] };
34
- export const decodeMctpOrder = (data) => {
35
- const a = asRecord(decodeCall([order], data).params);
36
- return {
37
- protocolMethod: 'createOrder', sourceToken: asString(a.tokenIn), sourceAmount: asBigint(a.amountIn),
38
- ...mayanDestination('wormhole', asBigint(a.destChain), accountFromBytes32(asString(a.tokenOut)), asBigint(a.minAmountOut)),
39
- receiver: accountFromBytes32(asString(a.destAddr)), referrer: accountFromBytes32(asString(a.referrerAddr)),
40
- };
41
- };
@@ -1,2 +0,0 @@
1
- import type { ParsedBridgeCall } from '../types.js';
2
- export declare const readMayanProtocol: (protocolData: string, amountFloor?: bigint) => Partial<ParsedBridgeCall> | undefined;
@@ -1,29 +0,0 @@
1
- import { BRIDGE_ERRORS, asBridgeError } from '../../errors/index.js';
2
- import { readSelector } from '../hex.js';
3
- import { innerCallDiagnostics } from '../diagnostics.js';
4
- import { FAST_MCTP_BRIDGE, decodeFastMctpBridge } from './fastMctpBridge.js';
5
- import { FAST_MCTP_CREATE_ORDER, decodeFastMctpCreateOrder } from './fastMctpCreateOrder.js';
6
- import { SWIFT_CREATE_ORDER, decodeSwiftCreateOrder } from './swiftCreateOrder.js';
7
- import { decodeMctpBridge, decodeMctpOrder, MCTP_BRIDGE_WITH_FEE, MCTP_CREATE_ORDER } from './mctp.js';
8
- export const readMayanProtocol = (protocolData, amountFloor) => {
9
- const selector = readSelector(protocolData);
10
- try {
11
- if (selector === SWIFT_CREATE_ORDER) {
12
- return decodeSwiftCreateOrder(protocolData);
13
- }
14
- if (selector === FAST_MCTP_CREATE_ORDER) {
15
- return decodeFastMctpCreateOrder(protocolData);
16
- }
17
- if (selector === FAST_MCTP_BRIDGE) {
18
- return decodeFastMctpBridge(protocolData, amountFloor);
19
- }
20
- if (selector === MCTP_BRIDGE_WITH_FEE)
21
- return decodeMctpBridge(protocolData, amountFloor);
22
- if (selector === MCTP_CREATE_ORDER)
23
- return decodeMctpOrder(protocolData);
24
- }
25
- catch (error) {
26
- throw asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, innerCallDiagnostics(protocolData, 'protocol'));
27
- }
28
- return undefined;
29
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const swapAndForwardERC20: CalldataMethod;
@@ -1,24 +0,0 @@
1
- import { asBigint, asString, decodeCall } from '../abi.js';
2
- import { finishForward, permitParams } from './forward.js';
3
- export const swapAndForwardERC20 = {
4
- name: 'swapAndForwardERC20',
5
- selector: '0x30dedc57',
6
- decode(data) {
7
- const args = decodeCall([
8
- { name: 'tokenIn', kind: 'address' },
9
- { name: 'amountIn', kind: 'uint' },
10
- permitParams,
11
- { name: 'swapProtocol', kind: 'address' },
12
- { name: 'swapData', kind: 'bytes' },
13
- { name: 'middleToken', kind: 'address' },
14
- { name: 'minMiddleAmount', kind: 'uint' },
15
- { name: 'mayanProtocol', kind: 'address' },
16
- { name: 'mayanData', kind: 'bytes' },
17
- ], data);
18
- return finishForward('swapAndForwardERC20', asString(args.mayanProtocol), asString(args.mayanData), {
19
- token: asString(args.tokenIn),
20
- amount: asBigint(args.amountIn),
21
- protocolAmount: asBigint(args.minMiddleAmount),
22
- });
23
- },
24
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const swapAndForwardEth: CalldataMethod;
@@ -1,23 +0,0 @@
1
- import { asBigint, asString, decodeCall } from '../abi.js';
2
- import { finishForward } from './forward.js';
3
- export const swapAndForwardEth = {
4
- name: 'swapAndForwardEth',
5
- selector: '0xfa74fd43',
6
- decode(data, value) {
7
- const args = decodeCall([
8
- { name: 'amountIn', kind: 'uint' },
9
- { name: 'swapProtocol', kind: 'address' },
10
- { name: 'swapData', kind: 'bytes' },
11
- { name: 'middleToken', kind: 'address' },
12
- { name: 'minMiddleAmount', kind: 'uint' },
13
- { name: 'mayanProtocol', kind: 'address' },
14
- { name: 'mayanData', kind: 'bytes' },
15
- ], data);
16
- const amount = asBigint(args.amountIn);
17
- return finishForward('swapAndForwardEth', asString(args.mayanProtocol), asString(args.mayanData), {
18
- token: '0x0000000000000000000000000000000000000000',
19
- amount: amount > 0n ? amount : value,
20
- protocolAmount: asBigint(args.minMiddleAmount),
21
- });
22
- },
23
- };
@@ -1,3 +0,0 @@
1
- import type { ParsedBridgeCall } from '../types.js';
2
- export declare const SWIFT_CREATE_ORDER = "0xa3a30834";
3
- export declare const decodeSwiftCreateOrder: (data: string) => Partial<ParsedBridgeCall>;
@@ -1,49 +0,0 @@
1
- import { asBigint, asRecord, asString, decodeCall } from '../abi.js';
2
- import { accountFromBytes32 } from '../hex.js';
3
- import { mayanDestination } from './destination.js';
4
- const params = {
5
- name: 'params',
6
- kind: 'tuple',
7
- components: [
8
- { name: 'payloadType', kind: 'uint' },
9
- { name: 'trader', kind: 'bytes', size: 32 },
10
- { name: 'destAddr', kind: 'bytes', size: 32 },
11
- { name: 'destChainId', kind: 'uint' },
12
- { name: 'referrerAddr', kind: 'bytes', size: 32 },
13
- { name: 'tokenOut', kind: 'bytes', size: 32 },
14
- { name: 'minAmountOut', kind: 'uint' },
15
- { name: 'gasDrop', kind: 'uint' },
16
- { name: 'cancelFee', kind: 'uint' },
17
- { name: 'refundFee', kind: 'uint' },
18
- { name: 'deadline', kind: 'uint' },
19
- { name: 'referrerBps', kind: 'uint' },
20
- { name: 'auctionMode', kind: 'uint' },
21
- { name: 'random', kind: 'bytes', size: 32 },
22
- ],
23
- };
24
- export const SWIFT_CREATE_ORDER = '0xa3a30834';
25
- export const decodeSwiftCreateOrder = (data) => {
26
- const args = decodeCall([
27
- { name: 'tokenIn', kind: 'address' },
28
- { name: 'amountIn', kind: 'uint' },
29
- params,
30
- { name: 'customPayload', kind: 'bytes' },
31
- ], data);
32
- const order = asRecord(args.params);
33
- const customPayload = asString(args.customPayload);
34
- const destination = mayanDestination('wormhole', asBigint(order.destChainId), accountFromBytes32(asString(order.tokenOut)), asBigint(order.minAmountOut));
35
- if (customPayload !== '0x') {
36
- delete destination.outputToken;
37
- delete destination.outputAmountReference;
38
- }
39
- return {
40
- protocolMethod: 'createOrderWithToken',
41
- sourceToken: asString(args.tokenIn),
42
- sourceAmount: asBigint(args.amountIn),
43
- ...destination,
44
- bridgeReceiver: accountFromBytes32(asString(order.destAddr)),
45
- receiver: customPayload === '0x' ? accountFromBytes32(asString(order.destAddr)) : undefined,
46
- destinationCallData: customPayload === '0x' ? undefined : customPayload,
47
- referrer: accountFromBytes32(asString(order.referrerAddr)),
48
- };
49
- };
@@ -1,3 +0,0 @@
1
- import type { BridgeErrorDefinition } from '../../errors/index.js';
2
- import type { ParsedBridgeCall } from '../types.js';
3
- export declare const mayanFailure: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
@@ -1,20 +0,0 @@
1
- import { BRIDGE_ERRORS } from '../../errors/index.js';
2
- import { isZeroWord } from '../hex.js';
3
- export const mayanFailure = (parsed) => {
4
- if (!parsed.protocolMethod) {
5
- return BRIDGE_ERRORS.UNRECOGNIZED_MAYAN_PROTOCOL_CALLDATA;
6
- }
7
- if (parsed.destinationChainId === undefined && !parsed.destinationChainRef) {
8
- return BRIDGE_ERRORS.MISSING_DESTINATION;
9
- }
10
- if (isZeroWord(parsed.receiver ?? parsed.bridgeReceiver)) {
11
- return BRIDGE_ERRORS.MISSING_RECEIVER;
12
- }
13
- if ((parsed.sourceAmount ?? 0n) <= 0n) {
14
- return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
15
- }
16
- if (parsed.protocolMethod !== 'bridge' && parsed.outputToken === undefined && !parsed.outputTokenReference && !parsed.destinationCallData) {
17
- return BRIDGE_ERRORS.MISSING_OUTPUT_TOKEN;
18
- }
19
- return undefined;
20
- };
@@ -1,9 +0,0 @@
1
- export declare const NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
2
- export declare const WRAPPED_NATIVE_TOKENS: Record<string, string>;
3
- export declare const isNative: (token: string) => boolean;
4
- export declare const CCTP_CHAINS: Record<string, bigint>;
5
- export declare const WORMHOLE_CHAINS: Record<string, bigint>;
6
- export declare const LAYERZERO_CHAINS: Record<string, bigint>;
7
- export declare const CCIP_CHAINS: Record<string, bigint>;
8
- export declare const CCTP_USDC: Record<string, string>;
9
- export declare const subtractFees: (amount: bigint, ...fees: bigint[]) => bigint;
@@ -1,57 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../errors/index.js';
2
- export const NATIVE_TOKEN = '0x0000000000000000000000000000000000000000';
3
- export const WRAPPED_NATIVE_TOKENS = {
4
- 1: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
5
- 10: '0x4200000000000000000000000000000000000006',
6
- 56: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
7
- 130: '0x4200000000000000000000000000000000000006',
8
- 137: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270',
9
- 4663: '0x0bd7d308f8e1639fab988df18a8011f41eacad73',
10
- 8453: '0x4200000000000000000000000000000000000006',
11
- 42161: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
12
- 43114: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
13
- 57073: '0x4200000000000000000000000000000000000006',
14
- };
15
- export const isNative = (token) => token === NATIVE_TOKEN || token.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
16
- // Circle CCTP domains and Wormhole IDs are different namespaces from EVM chain IDs.
17
- export const CCTP_CHAINS = {
18
- 0: 1n, 1: 43114n, 2: 10n, 3: 42161n, 6: 8453n, 7: 137n,
19
- 10: 130n, 11: 59144n, 13: 146n, 15: 143n, 19: 999n,
20
- };
21
- export const WORMHOLE_CHAINS = {
22
- 2: 1n, 4: 56n, 5: 137n, 6: 43114n, 23: 42161n, 24: 10n,
23
- 30: 8453n, 38: 59144n, 44: 130n, 47: 999n, 48: 143n, 52: 146n,
24
- };
25
- // Mainnet endpoint IDs from LayerZero's network metadata; v1 and v2 IDs coexist.
26
- export const LAYERZERO_CHAINS = {
27
- 101: 1n, 30101: 1n, 102: 56n, 30102: 56n, 106: 43114n, 30106: 43114n,
28
- 109: 137n, 30109: 137n, 110: 42161n, 30110: 42161n, 111: 10n, 30111: 10n,
29
- 184: 8453n, 30184: 8453n, 183: 59144n, 30183: 59144n, 181: 5000n, 30181: 5000n,
30
- 320: 130n, 30320: 130n, 332: 146n, 30332: 146n, 340: 1868n, 30340: 1868n,
31
- 367: 999n, 30367: 999n, 370: 98866n, 30370: 98866n, 383: 9745n, 30383: 9745n,
32
- 390: 143n, 30390: 143n, 416: 4663n, 30416: 4663n,
33
- 255: 252n, 30255: 252n, 280: 1329n, 30280: 1329n,
34
- };
35
- export const CCIP_CHAINS = {
36
- '5009297550715157269': 1n, '15971525489660198786': 8453n, '11344663589394136015': 56n,
37
- };
38
- // Canonical Circle USDC, not a symbol-based or quote-provided token mapping.
39
- export const CCTP_USDC = {
40
- 1: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
41
- 10: '0x0b2c639c533813f4aa9d7837caf62653d097ff85',
42
- 137: '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359',
43
- 8453: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
44
- 42161: '0xaf88d065e77c8cc2239327c5edb3a432268e5831',
45
- 43114: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
46
- 130: '0x078d782b760474a361dda0af3839290b0ef57ad6',
47
- 143: '0x754704bc059f8c67012fed69bc8a327a5aafb603',
48
- 146: '0x29219dd400f2bf60e5a23d13be72b486d4038894',
49
- 999: '0xb88339cb7199b77e23db6e890353e22632ba630f',
50
- 59144: '0x176211869ca2b568f2a7d4ee941e073a821ee1ff',
51
- };
52
- export const subtractFees = (amount, ...fees) => {
53
- const total = fees.reduce((sum, fee) => sum + fee, 0n);
54
- if (total > amount)
55
- throw new BridgeError(BRIDGE_ERRORS.BRIDGE_FEES_EXCEED_THE_INPUT_AMOUNT);
56
- return amount - total;
57
- };
@@ -1,13 +0,0 @@
1
- import { type AbiParam, type AbiValue } from '../abi.js';
2
- import type { ParsedBridgeCall } from '../types.js';
3
- export declare const callTuple: AbiParam;
4
- export declare const callsParam: AbiParam;
5
- export declare const requestIdFromMetadata: (metadata: string) => string | undefined;
6
- export declare const relayCall: (method: string, metadata: string, value: bigint, source?: {
7
- token?: string;
8
- amount?: bigint;
9
- }) => ParsedBridgeCall;
10
- export declare const firstPositive: (values: AbiValue[]) => {
11
- token?: string;
12
- amount: bigint;
13
- };
@@ -1,54 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
2
- import { asBigint, asRecord, asString } from '../abi.js';
3
- import { isZeroWord } from '../hex.js';
4
- import { NATIVE_TOKEN } from '../protocols.js';
5
- export const callTuple = {
6
- name: 'call',
7
- kind: 'tuple',
8
- components: [
9
- { name: 'target', kind: 'address' },
10
- { name: 'allowFailure', kind: 'bool' },
11
- { name: 'value', kind: 'uint' },
12
- { name: 'callData', kind: 'bytes' },
13
- ],
14
- };
15
- export const callsParam = {
16
- name: 'calls',
17
- kind: 'array',
18
- item: callTuple,
19
- };
20
- export const requestIdFromMetadata = (metadata) => {
21
- const body = metadata.toLowerCase().replace(/^0x/, '');
22
- if (body.length < 64) {
23
- return undefined;
24
- }
25
- const requestId = `0x${body.slice(0, 64)}`;
26
- return isZeroWord(requestId) ? undefined : requestId;
27
- };
28
- export const relayCall = (method, metadata, value, source) => ({
29
- aggregatorId: 'relay',
30
- method,
31
- kind: 'deposit',
32
- requestId: requestIdFromMetadata(metadata),
33
- sourceToken: source?.token ?? (value > 0n ? NATIVE_TOKEN : undefined),
34
- sourceAmount: source?.amount && source.amount > 0n ? source.amount : value,
35
- });
36
- const amountOf = (record) => {
37
- const amount = record.amount ?? record.value;
38
- return asBigint(amount);
39
- };
40
- export const firstPositive = (values) => {
41
- let amount = 0n;
42
- let token;
43
- for (const value of values) {
44
- const record = asRecord(value);
45
- amount += amountOf(record);
46
- if (record.token) {
47
- const current = asString(record.token);
48
- if (token && token !== current)
49
- throw new BridgeError(BRIDGE_ERRORS.MULTIPLE_SOURCE_ASSETS_ARE_NOT_SUPPORTED);
50
- token = current;
51
- }
52
- }
53
- return { token, amount };
54
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const depositErc20: CalldataMethod;
@@ -1,22 +0,0 @@
1
- import { asBigint, asString, decodeCall } from '../abi.js';
2
- export const depositErc20 = {
3
- name: 'depositErc20',
4
- selector: '0xe8017952',
5
- decode(data) {
6
- const args = decodeCall([
7
- { name: 'depositor', kind: 'address' },
8
- { name: 'token', kind: 'address' },
9
- { name: 'amount', kind: 'uint' },
10
- { name: 'id', kind: 'bytes', size: 32 },
11
- ], data);
12
- return {
13
- aggregatorId: 'relay',
14
- method: 'depositErc20',
15
- kind: 'deposit',
16
- sourceToken: asString(args.token),
17
- sourceAmount: asBigint(args.amount),
18
- orderId: asString(args.id),
19
- depositor: asString(args.depositor),
20
- };
21
- },
22
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const depositErc20Allowance: CalldataMethod;
@@ -1,20 +0,0 @@
1
- import { asString, decodeCall } from '../abi.js';
2
- export const depositErc20Allowance = {
3
- name: 'depositErc20Allowance',
4
- selector: '0x5a1ee3ac',
5
- decode(data) {
6
- const args = decodeCall([
7
- { name: 'depositor', kind: 'address' },
8
- { name: 'token', kind: 'address' },
9
- { name: 'id', kind: 'bytes', size: 32 },
10
- ], data);
11
- return {
12
- aggregatorId: 'relay',
13
- method: 'depositErc20Allowance',
14
- kind: 'deposit',
15
- sourceToken: asString(args.token),
16
- orderId: asString(args.id),
17
- depositor: asString(args.depositor),
18
- };
19
- },
20
- };
@@ -1,2 +0,0 @@
1
- import type { CalldataMethod } from '../abi.js';
2
- export declare const depositNative: CalldataMethod;