@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,185 +0,0 @@
1
- import { BRIDGE_ERRORS, BridgeError } from '../errors/index.js';
2
- import { _TypedDataEncoder } from '@ethersproject/hash';
3
- import { getBridgeRouter } from '../list.js';
4
- import { decodeBridgeCalldataResult } from '../calldata/index.js';
5
- import { asBigint, asString, decodeCall } from '../calldata/abi.js';
6
- import { address, array, bytes, chain, object, text, tokenAddress, transaction, uint } from './data.js';
7
- // Relay settlement-sdk 0.0.152 ORDER_EIP712_TYPES. EVM addresses are 20-byte
8
- // dynamic bytes, not bytes32. Unknown order versions/VMs fail closed.
9
- // Deadlines remain part of the order hash; they are not checked against the clock.
10
- const ORDER_TYPES = {
11
- Order: [
12
- { name: 'version', type: 'string' }, { name: 'solverChainId', type: 'string' },
13
- { name: 'solver', type: 'address' }, { name: 'salt', type: 'uint256' },
14
- { name: 'inputs', type: 'Input[]' }, { name: 'output', type: 'Output' }, { name: 'fees', type: 'Fee[]' },
15
- ],
16
- Input: [{ name: 'payment', type: 'InputPayment' }, { name: 'refunds', type: 'InputRefund[]' }],
17
- InputPayment: [
18
- { name: 'chainId', type: 'string' }, { name: 'currency', type: 'bytes' },
19
- { name: 'amount', type: 'uint256' }, { name: 'weight', type: 'uint256' },
20
- ],
21
- InputRefund: [
22
- { name: 'chainId', type: 'string' }, { name: 'recipient', type: 'bytes' }, { name: 'currency', type: 'bytes' },
23
- { name: 'minimumAmount', type: 'uint256' }, { name: 'deadline', type: 'uint32' }, { name: 'extraData', type: 'bytes' },
24
- ],
25
- Output: [
26
- { name: 'chainId', type: 'string' }, { name: 'payments', type: 'OutputPayment[]' },
27
- { name: 'deadline', type: 'uint32' }, { name: 'calls', type: 'bytes[]' }, { name: 'extraData', type: 'bytes' },
28
- ],
29
- OutputPayment: [
30
- { name: 'recipient', type: 'bytes' }, { name: 'currency', type: 'bytes' },
31
- { name: 'minimumAmount', type: 'uint256' }, { name: 'expectedAmount', type: 'uint256' },
32
- ],
33
- Fee: [
34
- { name: 'recipientChainId', type: 'string' }, { name: 'recipient', type: 'bytes' },
35
- { name: 'currencyChainId', type: 'string' }, { name: 'currency', type: 'bytes' }, { name: 'amount', type: 'uint256' },
36
- ],
37
- };
38
- // Pin protocol identifiers independently of the service's mutable /chains response.
39
- const RELAY_EVM_CHAIN_IDS = {
40
- ethereum: 1n, optimism: 10n, cronos: 25n, bnb: 56n, gnosis: 100n, unichain: 130n,
41
- polygon: 137n, monad: 143n, sonic: 146n, manta: 169n, xlayer: 196n, boba: 288n,
42
- zksync: 324n, shape: 360n, worldchain: 480n, flow: 747n, stable: 988n, hyperevm: 999n,
43
- metis: 1088n, soneium: 1868n, ronin: 2020n, abstract: 2741n, morph: 2818n,
44
- tempo: 4217n, megaeth: 4326n, robinhood: 4663n, mantle: 5000n, somnia: 5031n,
45
- arc: 5042n, base: 8453n, plasma: 9745n, apechain: 33139n, mode: 34443n,
46
- mythos: 42018n, arbitrum: 42161n, celo: 42220n, avalanche: 43114n, zircuit: 48900n,
47
- ink: 57073n, linea: 59144n, bob: 60808n, berachain: 80094n, doma: 97477n,
48
- plume: 98866n, scroll: 534352n, gensyn: 685689n, katana: 747474n,
49
- ethereal: 5064014n, zora: 7777777n,
50
- };
51
- export const relayChains = (value) => {
52
- const result = [];
53
- for (const raw of array(object(value).chains)) {
54
- const c = object(raw);
55
- if (c.vmType !== 'evm' || !c.protocol)
56
- continue;
57
- const v2 = object(c.protocol).v2;
58
- if (!v2)
59
- continue;
60
- const protocol = object(v2);
61
- const entry = { evmId: uint(c.id), protocolId: text(protocol.chainId), depository: address(protocol.depository) };
62
- if (!Object.prototype.hasOwnProperty.call(RELAY_EVM_CHAIN_IDS, entry.protocolId))
63
- continue;
64
- if (RELAY_EVM_CHAIN_IDS[entry.protocolId] !== entry.evmId)
65
- throw new BridgeError(BRIDGE_ERRORS.RELAY_PROTOCOL_CHAIN_MISMATCH);
66
- if (result.some((other) => other.evmId === entry.evmId || other.protocolId === entry.protocolId))
67
- throw new BridgeError(BRIDGE_ERRORS.AMBIGUOUS_RELAY_CHAIN);
68
- result.push(entry);
69
- }
70
- return result;
71
- };
72
- export const relayOrder = (raw, metadata) => {
73
- const o = object(raw);
74
- if (o.version !== 'v1')
75
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_ORDER_VERSION);
76
- const evm = (id) => {
77
- const protocolId = text(id);
78
- if (!metadata.some((c) => c.protocolId === protocolId))
79
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_VM);
80
- return protocolId;
81
- };
82
- const output = object(o.output);
83
- return {
84
- version: o.version,
85
- solverChainId: evm(o.solverChainId), solver: address(o.solver), salt: uint(o.salt).toString(),
86
- inputs: array(o.inputs).map((rawInput) => {
87
- const input = object(rawInput), payment = object(input.payment);
88
- return {
89
- payment: { chainId: evm(payment.chainId), currency: address(payment.currency), amount: uint(payment.amount).toString(), weight: uint(payment.weight).toString() },
90
- refunds: array(input.refunds).map((rawRefund) => {
91
- const r = object(rawRefund);
92
- return { chainId: evm(r.chainId), recipient: address(r.recipient), currency: address(r.currency),
93
- minimumAmount: uint(r.minimumAmount).toString(), deadline: uint(r.deadline, 32).toString(), extraData: bytes(r.extraData) };
94
- }),
95
- };
96
- }),
97
- output: {
98
- chainId: evm(output.chainId), deadline: uint(output.deadline, 32).toString(), extraData: bytes(output.extraData),
99
- calls: array(output.calls).map((call) => bytes(call)),
100
- payments: array(output.payments).map((rawPayment) => {
101
- const p = object(rawPayment);
102
- return { recipient: address(p.recipient), currency: address(p.currency),
103
- minimumAmount: uint(p.minimumAmount).toString(), expectedAmount: uint(p.expectedAmount).toString() };
104
- }),
105
- },
106
- fees: array(o.fees).map((rawFee) => {
107
- const f = object(rawFee);
108
- return { recipientChainId: evm(f.recipientChainId), recipient: address(f.recipient),
109
- currencyChainId: evm(f.currencyChainId), currency: address(f.currency), amount: uint(f.amount).toString() };
110
- }),
111
- };
112
- };
113
- export const readRelayQuote = (raw, params, metadata) => {
114
- const q = object(raw);
115
- const protocol = object(object(q.protocol).v2);
116
- const order = relayOrder(protocol.orderData, metadata);
117
- const orderId = _TypedDataEncoder.hashStruct('Order', ORDER_TYPES, order).toLowerCase();
118
- if (orderId !== bytes(protocol.orderId, 32))
119
- throw new BridgeError(BRIDGE_ERRORS.RELAY_ORDER_HASH_MISMATCH);
120
- if (order.inputs.length !== 1 || order.output.payments.length !== 1 || order.output.calls.length !== 0)
121
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_ORDER_SHAPE);
122
- const source = metadata.find((c) => c.evmId === chain(params.fromChainId));
123
- const destination = metadata.find((c) => c.evmId === chain(params.toChainId));
124
- if (!source || !destination || order.inputs[0].payment.chainId !== source.protocolId || order.output.chainId !== destination.protocolId)
125
- throw new BridgeError(BRIDGE_ERRORS.RELAY_ORDER_CHAIN_MISMATCH);
126
- if (source.depository !== getBridgeRouter('relay', params.fromChainId)?.toLowerCase()) {
127
- throw new BridgeError(BRIDGE_ERRORS.RELAY_CANONICAL_DEPOSITORY_MISMATCH);
128
- }
129
- for (const refund of order.inputs[0].refunds) {
130
- if (refund.recipient !== address(params.userAddress))
131
- throw new BridgeError(BRIDGE_ERRORS.RELAY_REFUND_RECIPIENT_MISMATCH);
132
- }
133
- const steps = array(q.steps).map(object);
134
- const deposits = steps.filter((step) => step.id === 'deposit');
135
- if (deposits.length !== 1 || deposits[0].kind !== 'transaction' || deposits[0].depositAddress)
136
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_DEPOSIT);
137
- const items = array(deposits[0].items);
138
- if (items.length !== 1)
139
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_DEPOSIT_COUNT);
140
- const tx = transaction(object(items[0]).data, params);
141
- const decodedResult = decodeBridgeCalldataResult('relay', tx);
142
- if (!decodedResult.ok)
143
- throw new BridgeError(BRIDGE_ERRORS.INVALID_CALLDATA, {}, decodedResult.errors);
144
- const decoded = decodedResult.parsed;
145
- if (!decoded || !['depositNative', 'depositErc20'].includes(decoded.method))
146
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_DEPOSIT_METHOD);
147
- const payment = order.inputs[0].payment;
148
- const paymentDetails = object(protocol.paymentDetails);
149
- if (tx.to.toLowerCase() !== source.depository || address(paymentDetails.depository) !== source.depository ||
150
- paymentDetails.chainId !== source.protocolId || address(paymentDetails.currency) !== payment.currency ||
151
- uint(paymentDetails.amount) !== uint(payment.amount) ||
152
- decoded.orderId !== orderId || decoded.depositor !== address(params.userAddress) ||
153
- decoded.sourceToken !== payment.currency || decoded.sourceAmount !== uint(payment.amount))
154
- throw new BridgeError(BRIDGE_ERRORS.RELAY_SOURCE_PAYMENT_MISMATCH);
155
- if (payment.currency !== tokenAddress(params.fromTokenId, params.fromChainId) ||
156
- uint(tx.value) !== (payment.currency === '0x0000000000000000000000000000000000000000' ? uint(payment.amount) : 0n))
157
- throw new BridgeError(BRIDGE_ERRORS.RELAY_SOURCE_VALUE_MISMATCH);
158
- // Approval steps are never executed from the response. Verify their semantics,
159
- // then expose only the spender so the host can build its own approval.
160
- const approvals = steps.filter((step) => step.id === 'approve');
161
- if (approvals.length > 1)
162
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_APPROVAL_COUNT);
163
- for (const step of steps) {
164
- if (!['approve', 'deposit'].includes(text(step.id)))
165
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_STEP);
166
- }
167
- for (const step of approvals) {
168
- const approvalsItems = array(step.items);
169
- if (step.kind !== 'transaction' || approvalsItems.length !== 1)
170
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_RELAY_APPROVAL);
171
- const approval = transaction(object(approvalsItems[0]).data, params);
172
- if (!approval.data.startsWith('0x095ea7b3') || approval.to !== payment.currency || uint(approval.value) !== 0n)
173
- throw new BridgeError(BRIDGE_ERRORS.RELAY_APPROVAL_MISMATCH);
174
- const args = decodeCall([{ name: 'spender', kind: 'address' }, { name: 'amount', kind: 'uint' }], approval.data);
175
- if (asString(args.spender) !== source.depository || asBigint(args.amount) !== uint(payment.amount))
176
- throw new BridgeError(BRIDGE_ERRORS.RELAY_APPROVAL_MISMATCH);
177
- }
178
- const output = order.output.payments[0];
179
- return {
180
- tx, orderId, requestId: bytes(deposits[0].requestId, 32), expectedAmount: uint(output.expectedAmount),
181
- approveAddress: payment.currency === '0x0000000000000000000000000000000000000000' ? '' : source.depository,
182
- parsed: { ...decoded, destinationChainId: destination.evmId, outputToken: output.currency,
183
- minOutputAmount: uint(output.minimumAmount), receiver: output.recipient, unresolvedFields: [] },
184
- };
185
- };
@@ -1,5 +0,0 @@
1
- import type { BridgeQuoteListParams } from '../quote.js';
2
- import type { ProviderQuoteData } from './relay.js';
3
- export declare const SOCKET_PROVIDER_ROUTES: readonly string[];
4
- export declare const socketBridgeId: (value: unknown) => string;
5
- export declare const readSocketQuote: (raw: unknown, rawRoute: unknown, params: BridgeQuoteListParams) => ProviderQuoteData;
@@ -1,57 +0,0 @@
1
- import { sourceAmountMatches } from '../calldata/expect.js';
2
- import { BRIDGE_ERRORS, BridgeError } from '../errors/index.js';
3
- import { decodeBridgeCalldataResult } from '../calldata/index.js';
4
- import { address, bytes, chain, object, text, tokenAddress, transaction, uint } from './data.js';
5
- export const SOCKET_PROVIDER_ROUTES = Object.freeze(['rfq-vault-executor', 'cctp-v2', 'cctp-v2-slow']);
6
- export const socketBridgeId = (value) => text(value).trim().toLowerCase().replace(/ /g, '-').replace(/^circle-cctp/, 'cctp');
7
- export const readSocketQuote = (raw, rawRoute, params) => {
8
- const result = object(raw), route = object(rawRoute);
9
- const details = object(object(route.routeDetails).bridgeDetails);
10
- const bridgeId = socketBridgeId(object(details.protocol).name);
11
- if (!SOCKET_PROVIDER_ROUTES.includes(bridgeId) || route.userOp !== 'tx')
12
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_SERVICE_ROUTE);
13
- const input = object(result.input), inputToken = object(input.token);
14
- const output = object(route.output), outputToken = object(output.token);
15
- if (uint(result.originChainId) !== chain(params.fromChainId) || uint(result.destinationChainId) !== chain(params.toChainId) ||
16
- uint(inputToken.chainId) !== chain(params.fromChainId) || uint(outputToken.chainId) !== chain(params.toChainId) ||
17
- address(result.userAddress) !== address(params.userAddress) || address(result.receiverAddress) !== address(params.userAddress) ||
18
- tokenAddress(text(inputToken.address), params.fromChainId) !== tokenAddress(params.fromTokenId, params.fromChainId) ||
19
- !sourceAmountMatches(uint(input.amount), uint(params.fromTokenRawAmount)))
20
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_QUOTE_INPUT_MISMATCH);
21
- const txData = object(route.txData);
22
- if (txData.kind !== 'evm_tx')
23
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_TRANSACTION);
24
- const tx = transaction(txData.object, params);
25
- const decodedResult = decodeBridgeCalldataResult('socket', tx);
26
- if (!decodedResult.ok)
27
- throw new BridgeError(BRIDGE_ERRORS.INVALID_CALLDATA, {}, decodedResult.errors);
28
- const parsed = decodedResult.parsed;
29
- const quoteId = bytes(route.quoteId, 32);
30
- if (!parsed || parsed.quoteId !== quoteId || parsed.depositor !== address(params.userAddress) ||
31
- parsed.sourceAmount !== uint(input.amount))
32
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_SOURCE_QUOTE_MISMATCH);
33
- if (bridgeId === 'rfq-vault-executor') {
34
- if (parsed.protocolMethod !== 'receiveERC20' || parsed.orderId !== quoteId)
35
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_RFQ_ORDER_MISMATCH);
36
- }
37
- else if (parsed.protocolMethod !== 'depositForBurn' || parsed.bridgeReceiver !== '0x424a31a57f7c63918ecaa2fac38016a8af5a6ec2') {
38
- throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_SOCKET_CCTP_RECEIVER);
39
- }
40
- const destinationToken = tokenAddress(text(outputToken.address), params.toChainId);
41
- if (parsed.outputToken && tokenAddress(parsed.outputToken, params.toChainId) !== destinationToken)
42
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_BRIDGE_OUTPUT_MISMATCH);
43
- if (parsed.destinationChainId !== undefined && parsed.destinationChainId !== chain(params.toChainId))
44
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_BRIDGE_CHAIN_MISMATCH);
45
- const approval = route.approval ? object(route.approval) : undefined;
46
- const native = tokenAddress(params.fromTokenId, params.fromChainId) === '0x0000000000000000000000000000000000000000';
47
- if (!native && (!approval || address(approval.tokenAddress) !== tokenAddress(params.fromTokenId, params.fromChainId) ||
48
- address(approval.userAddress) !== address(params.userAddress) || uint(approval.amount) !== uint(input.amount)))
49
- throw new BridgeError(BRIDGE_ERRORS.SOCKET_APPROVAL_MISMATCH);
50
- return {
51
- tx, orderId: quoteId, requestId: quoteId,
52
- approveAddress: native ? '' : address(approval.spenderAddress),
53
- expectedAmount: uint(output.amount),
54
- parsed: { ...parsed, destinationChainId: chain(params.toChainId), outputToken: destinationToken,
55
- minOutputAmount: uint(output.minAmountOut), receiver: address(result.receiverAddress), unresolvedFields: [] },
56
- };
57
- };