@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.
- package/README.md +1 -159
- package/dist/chains.d.ts +2 -1
- package/dist/chains.js +2 -0
- package/dist/data.d.ts +3 -0
- package/dist/data.js +3 -0
- package/dist/index.d.ts +1 -6
- package/dist/index.js +0 -3
- package/dist/quote.d.ts +4 -26
- package/dist/quote.js +67 -200
- package/package.json +3 -13
- package/dist/calldata/abi.d.ts +0 -29
- package/dist/calldata/abi.js +0 -160
- package/dist/calldata/across/deposit.d.ts +0 -2
- package/dist/calldata/across/deposit.js +0 -36
- package/dist/calldata/across/depositNative.d.ts +0 -2
- package/dist/calldata/across/depositNative.js +0 -45
- package/dist/calldata/across/depositNow.d.ts +0 -2
- package/dist/calldata/across/depositNow.js +0 -35
- package/dist/calldata/across/depositV3.d.ts +0 -2
- package/dist/calldata/across/depositV3.js +0 -35
- package/dist/calldata/across/depositV3Now.d.ts +0 -2
- package/dist/calldata/across/depositV3Now.js +0 -34
- package/dist/calldata/across/index.d.ts +0 -4
- package/dist/calldata/across/index.js +0 -31
- package/dist/calldata/across/swapAndBridge.d.ts +0 -2
- package/dist/calldata/across/swapAndBridge.js +0 -70
- package/dist/calldata/across/validate.d.ts +0 -3
- package/dist/calldata/across/validate.js +0 -34
- package/dist/calldata/chains.d.ts +0 -2
- package/dist/calldata/chains.js +0 -35
- package/dist/calldata/destination.d.ts +0 -6
- package/dist/calldata/destination.js +0 -211
- package/dist/calldata/destinationSwap.d.ts +0 -14
- package/dist/calldata/destinationSwap.js +0 -80
- package/dist/calldata/diagnostics.d.ts +0 -4
- package/dist/calldata/diagnostics.js +0 -18
- package/dist/calldata/expect.d.ts +0 -27
- package/dist/calldata/expect.js +0 -158
- package/dist/calldata/hex.d.ts +0 -6
- package/dist/calldata/hex.js +0 -46
- package/dist/calldata/index.d.ts +0 -20
- package/dist/calldata/index.js +0 -88
- package/dist/calldata/lifi/across/acrossV4Erc20Min.d.ts +0 -2
- package/dist/calldata/lifi/across/acrossV4Erc20Min.js +0 -26
- package/dist/calldata/lifi/across/acrossV4NativeMin.d.ts +0 -2
- package/dist/calldata/lifi/across/acrossV4NativeMin.js +0 -22
- package/dist/calldata/lifi/across/index.d.ts +0 -6
- package/dist/calldata/lifi/across/index.js +0 -19
- package/dist/calldata/lifi/allbridge/index.d.ts +0 -3
- package/dist/calldata/lifi/allbridge/index.js +0 -26
- package/dist/calldata/lifi/celer/index.d.ts +0 -4
- package/dist/calldata/lifi/celer/index.js +0 -10
- package/dist/calldata/lifi/centrifuge/index.d.ts +0 -3
- package/dist/calldata/lifi/centrifuge/index.js +0 -22
- package/dist/calldata/lifi/destination.d.ts +0 -5
- package/dist/calldata/lifi/destination.js +0 -40
- package/dist/calldata/lifi/frax/index.d.ts +0 -4
- package/dist/calldata/lifi/frax/index.js +0 -29
- package/dist/calldata/lifi/garden/index.d.ts +0 -3
- package/dist/calldata/lifi/garden/index.js +0 -22
- package/dist/calldata/lifi/gaszip/index.d.ts +0 -6
- package/dist/calldata/lifi/gaszip/index.js +0 -15
- package/dist/calldata/lifi/index.d.ts +0 -4
- package/dist/calldata/lifi/index.js +0 -62
- package/dist/calldata/lifi/intents/index.d.ts +0 -4
- package/dist/calldata/lifi/intents/index.js +0 -10
- package/dist/calldata/lifi/layerswap/index.d.ts +0 -4
- package/dist/calldata/lifi/layerswap/index.js +0 -10
- package/dist/calldata/lifi/m0/index.d.ts +0 -3
- package/dist/calldata/lifi/m0/index.js +0 -33
- package/dist/calldata/lifi/mayan/index.d.ts +0 -4
- package/dist/calldata/lifi/mayan/index.js +0 -10
- package/dist/calldata/lifi/method.d.ts +0 -6
- package/dist/calldata/lifi/method.js +0 -16
- package/dist/calldata/lifi/native/index.d.ts +0 -4
- package/dist/calldata/lifi/native/index.js +0 -80
- package/dist/calldata/lifi/params.d.ts +0 -28
- package/dist/calldata/lifi/params.js +0 -347
- package/dist/calldata/lifi/paxos/index.d.ts +0 -4
- package/dist/calldata/lifi/paxos/index.js +0 -10
- package/dist/calldata/lifi/polymer/index.d.ts +0 -4
- package/dist/calldata/lifi/polymer/index.js +0 -10
- package/dist/calldata/lifi/relay/index.d.ts +0 -6
- package/dist/calldata/lifi/relay/index.js +0 -15
- package/dist/calldata/lifi/shape.d.ts +0 -4
- package/dist/calldata/lifi/shape.js +0 -31
- package/dist/calldata/lifi/squid/index.d.ts +0 -6
- package/dist/calldata/lifi/squid/index.js +0 -15
- package/dist/calldata/lifi/stargate/index.d.ts +0 -5
- package/dist/calldata/lifi/stargate/index.js +0 -15
- package/dist/calldata/lifi/swap/index.d.ts +0 -5
- package/dist/calldata/lifi/swap/index.js +0 -18
- package/dist/calldata/lifi/swap/swapMethod.d.ts +0 -2
- package/dist/calldata/lifi/swap/swapMethod.js +0 -40
- package/dist/calldata/lifi/swapData.d.ts +0 -5
- package/dist/calldata/lifi/swapData.js +0 -33
- package/dist/calldata/match.d.ts +0 -3
- package/dist/calldata/match.js +0 -21
- package/dist/calldata/mayan/destination.d.ts +0 -2
- package/dist/calldata/mayan/destination.js +0 -13
- package/dist/calldata/mayan/fastMctpBridge.d.ts +0 -3
- package/dist/calldata/mayan/fastMctpBridge.js +0 -48
- package/dist/calldata/mayan/fastMctpCreateOrder.d.ts +0 -3
- package/dist/calldata/mayan/fastMctpCreateOrder.js +0 -39
- package/dist/calldata/mayan/forward.d.ts +0 -8
- package/dist/calldata/mayan/forward.js +0 -35
- package/dist/calldata/mayan/forwardERC20.d.ts +0 -2
- package/dist/calldata/mayan/forwardERC20.js +0 -19
- package/dist/calldata/mayan/forwardEth.d.ts +0 -2
- package/dist/calldata/mayan/forwardEth.js +0 -16
- package/dist/calldata/mayan/index.d.ts +0 -4
- package/dist/calldata/mayan/index.js +0 -21
- package/dist/calldata/mayan/mctp.d.ts +0 -5
- package/dist/calldata/mayan/mctp.js +0 -41
- package/dist/calldata/mayan/readProtocol.d.ts +0 -2
- package/dist/calldata/mayan/readProtocol.js +0 -29
- package/dist/calldata/mayan/swapAndForwardERC20.d.ts +0 -2
- package/dist/calldata/mayan/swapAndForwardERC20.js +0 -24
- package/dist/calldata/mayan/swapAndForwardEth.d.ts +0 -2
- package/dist/calldata/mayan/swapAndForwardEth.js +0 -23
- package/dist/calldata/mayan/swiftCreateOrder.d.ts +0 -3
- package/dist/calldata/mayan/swiftCreateOrder.js +0 -49
- package/dist/calldata/mayan/validate.d.ts +0 -3
- package/dist/calldata/mayan/validate.js +0 -20
- package/dist/calldata/protocols.d.ts +0 -9
- package/dist/calldata/protocols.js +0 -57
- package/dist/calldata/relay/calls.d.ts +0 -13
- package/dist/calldata/relay/calls.js +0 -54
- package/dist/calldata/relay/depositErc20.d.ts +0 -2
- package/dist/calldata/relay/depositErc20.js +0 -22
- package/dist/calldata/relay/depositErc20Allowance.d.ts +0 -2
- package/dist/calldata/relay/depositErc20Allowance.js +0 -20
- package/dist/calldata/relay/depositNative.d.ts +0 -2
- package/dist/calldata/relay/depositNative.js +0 -20
- package/dist/calldata/relay/index.d.ts +0 -4
- package/dist/calldata/relay/index.js +0 -42
- package/dist/calldata/relay/multicall.d.ts +0 -2
- package/dist/calldata/relay/multicall.js +0 -15
- package/dist/calldata/relay/permit2TransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permit2TransferAndMulticall.js +0 -42
- package/dist/calldata/relay/permit3009TransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permit3009TransferAndMulticall.js +0 -41
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.d.ts +0 -2
- package/dist/calldata/relay/permit3009TransferAndMulticallSigned.js +0 -40
- package/dist/calldata/relay/permitTransferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/permitTransferAndMulticall.js +0 -34
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.d.ts +0 -2
- package/dist/calldata/relay/permitTransferAndMulticallLegacy.js +0 -35
- package/dist/calldata/relay/transferAndMulticall.d.ts +0 -2
- package/dist/calldata/relay/transferAndMulticall.js +0 -26
- package/dist/calldata/relay/validate.d.ts +0 -3
- package/dist/calldata/relay/validate.js +0 -18
- package/dist/calldata/resolve.d.ts +0 -2
- package/dist/calldata/resolve.js +0 -28
- package/dist/calldata/socket/bridge.d.ts +0 -2
- package/dist/calldata/socket/bridge.js +0 -28
- package/dist/calldata/socket/exec.d.ts +0 -2
- package/dist/calldata/socket/exec.js +0 -71
- package/dist/calldata/socket/index.d.ts +0 -4
- package/dist/calldata/socket/index.js +0 -13
- package/dist/calldata/socket/params.d.ts +0 -5
- package/dist/calldata/socket/params.js +0 -14
- package/dist/calldata/socket/protocols/ccip.d.ts +0 -2
- package/dist/calldata/socket/protocols/ccip.js +0 -32
- package/dist/calldata/socket/protocols/cctp.d.ts +0 -2
- package/dist/calldata/socket/protocols/cctp.js +0 -24
- package/dist/calldata/socket/protocols/eco.d.ts +0 -2
- package/dist/calldata/socket/protocols/eco.js +0 -20
- package/dist/calldata/socket/protocols/index.d.ts +0 -3
- package/dist/calldata/socket/protocols/index.js +0 -86
- package/dist/calldata/socket/protocols/native.d.ts +0 -2
- package/dist/calldata/socket/protocols/native.js +0 -70
- package/dist/calldata/socket/protocols/oft.d.ts +0 -2
- package/dist/calldata/socket/protocols/oft.js +0 -33
- package/dist/calldata/socket/protocols/swapsXYZ.d.ts +0 -2
- package/dist/calldata/socket/protocols/swapsXYZ.js +0 -62
- package/dist/calldata/socket/swapAndBridge.d.ts +0 -2
- package/dist/calldata/socket/swapAndBridge.js +0 -41
- package/dist/calldata/socket/validate.d.ts +0 -3
- package/dist/calldata/socket/validate.js +0 -24
- package/dist/calldata/types.d.ts +0 -82
- package/dist/calldata/types.js +0 -20
- package/dist/errors/constants.d.ts +0 -891
- package/dist/errors/constants.js +0 -898
- package/dist/errors/index.d.ts +0 -66
- package/dist/errors/index.js +0 -53
- package/dist/errors/sanitize.d.ts +0 -3
- package/dist/errors/sanitize.js +0 -74
- package/dist/providers/data.d.ts +0 -23
- package/dist/providers/data.js +0 -116
- package/dist/providers/errors.d.ts +0 -7
- package/dist/providers/errors.js +0 -10
- package/dist/providers/layerswap.d.ts +0 -9
- package/dist/providers/layerswap.js +0 -95
- package/dist/providers/relay.d.ts +0 -59
- package/dist/providers/relay.js +0 -185
- package/dist/providers/socket.d.ts +0 -5
- package/dist/providers/socket.js +0 -57
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
|
|
2
|
-
import { innerCallDiagnostics } from '../diagnostics.js';
|
|
3
|
-
import { asArray, asBigint, asRecord, asString, } from '../abi.js';
|
|
4
|
-
import { accountFromBytes32 } from '../hex.js';
|
|
5
|
-
import { readMayanProtocol } from '../mayan/readProtocol.js';
|
|
6
|
-
import { LAYERZERO_CHAINS, subtractFees } from '../protocols.js';
|
|
7
|
-
import { readLifiDestination } from './destination.js';
|
|
8
|
-
import { swapDataParam } from './swapData.js';
|
|
9
|
-
export { applyFirstSwap, swapDataArrayParam, swapDataParam } from './swapData.js';
|
|
10
|
-
export const bridgeDataParam = {
|
|
11
|
-
name: 'bridgeData',
|
|
12
|
-
kind: 'tuple',
|
|
13
|
-
components: [
|
|
14
|
-
{ name: 'transactionId', kind: 'bytes', size: 32 },
|
|
15
|
-
{ name: 'bridge', kind: 'string' },
|
|
16
|
-
{ name: 'integrator', kind: 'string' },
|
|
17
|
-
{ name: 'referrer', kind: 'address' },
|
|
18
|
-
{ name: 'sendingAssetId', kind: 'address' },
|
|
19
|
-
{ name: 'receiver', kind: 'address' },
|
|
20
|
-
{ name: 'minAmount', kind: 'uint' },
|
|
21
|
-
{ name: 'destinationChainId', kind: 'uint' },
|
|
22
|
-
{ name: 'hasSourceSwaps', kind: 'bool' },
|
|
23
|
-
{ name: 'hasDestinationCall', kind: 'bool' },
|
|
24
|
-
],
|
|
25
|
-
};
|
|
26
|
-
export const acrossDataParam = {
|
|
27
|
-
name: 'acrossData',
|
|
28
|
-
kind: 'tuple',
|
|
29
|
-
components: [
|
|
30
|
-
{ name: 'receiverAddress', kind: 'bytes', size: 32 },
|
|
31
|
-
{ name: 'refundAddress', kind: 'bytes', size: 32 },
|
|
32
|
-
{ name: 'sendingAssetId', kind: 'bytes', size: 32 },
|
|
33
|
-
{ name: 'receivingAssetId', kind: 'bytes', size: 32 },
|
|
34
|
-
{ name: 'outputAmount', kind: 'uint' },
|
|
35
|
-
{ name: 'outputAmountMultiplier', kind: 'uint' },
|
|
36
|
-
{ name: 'exclusiveRelayer', kind: 'bytes', size: 32 },
|
|
37
|
-
{ name: 'quoteTimestamp', kind: 'uint' },
|
|
38
|
-
{ name: 'fillDeadline', kind: 'uint' },
|
|
39
|
-
{ name: 'exclusivityParameter', kind: 'uint' },
|
|
40
|
-
{ name: 'message', kind: 'bytes' },
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
export const stargateDataParam = {
|
|
44
|
-
name: 'stargateData',
|
|
45
|
-
kind: 'tuple',
|
|
46
|
-
components: [
|
|
47
|
-
{ name: 'assetId', kind: 'uint' },
|
|
48
|
-
{
|
|
49
|
-
name: 'sendParams',
|
|
50
|
-
kind: 'tuple',
|
|
51
|
-
components: [
|
|
52
|
-
{ name: 'dstEid', kind: 'uint' },
|
|
53
|
-
{ name: 'to', kind: 'bytes', size: 32 },
|
|
54
|
-
{ name: 'amountLD', kind: 'uint' },
|
|
55
|
-
{ name: 'minAmountLD', kind: 'uint' },
|
|
56
|
-
{ name: 'extraOptions', kind: 'bytes' },
|
|
57
|
-
{ name: 'composeMsg', kind: 'bytes' },
|
|
58
|
-
{ name: 'oftCmd', kind: 'bytes' },
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: 'fee',
|
|
63
|
-
kind: 'tuple',
|
|
64
|
-
components: [
|
|
65
|
-
{ name: 'nativeFee', kind: 'uint' },
|
|
66
|
-
{ name: 'lzTokenFee', kind: 'uint' },
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
{ name: 'refundAddress', kind: 'address' },
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
export const relayDepositoryDataParam = {
|
|
73
|
-
name: 'relayDepositoryData',
|
|
74
|
-
kind: 'tuple',
|
|
75
|
-
components: [
|
|
76
|
-
{ name: 'orderId', kind: 'bytes', size: 32 },
|
|
77
|
-
{ name: 'depositorAddress', kind: 'address' },
|
|
78
|
-
],
|
|
79
|
-
};
|
|
80
|
-
export const mayanDataParam = {
|
|
81
|
-
name: 'mayanData',
|
|
82
|
-
kind: 'tuple',
|
|
83
|
-
components: [
|
|
84
|
-
{ name: 'nonEVMReceiver', kind: 'bytes', size: 32 },
|
|
85
|
-
{ name: 'mayanProtocol', kind: 'address' },
|
|
86
|
-
{ name: 'protocolData', kind: 'bytes' },
|
|
87
|
-
{ name: 'swapProtocol', kind: 'address' },
|
|
88
|
-
{ name: 'swapData', kind: 'bytes' },
|
|
89
|
-
{ name: 'middleToken', kind: 'address' },
|
|
90
|
-
{ name: 'minMiddleAmount', kind: 'uint' },
|
|
91
|
-
{ name: 'refundRecipient', kind: 'address' },
|
|
92
|
-
{ name: 'mayanAmountIn', kind: 'uint' },
|
|
93
|
-
],
|
|
94
|
-
};
|
|
95
|
-
export const gasZipDataParam = {
|
|
96
|
-
name: 'gasZipData',
|
|
97
|
-
kind: 'tuple',
|
|
98
|
-
components: [
|
|
99
|
-
{ name: 'receiverAddress', kind: 'bytes', size: 32 },
|
|
100
|
-
{ name: 'destinationChains', kind: 'uint' },
|
|
101
|
-
],
|
|
102
|
-
};
|
|
103
|
-
export const squidDataParam = {
|
|
104
|
-
name: 'squidData',
|
|
105
|
-
kind: 'tuple',
|
|
106
|
-
components: [
|
|
107
|
-
{ name: 'routeType', kind: 'uint' },
|
|
108
|
-
{ name: 'destinationChain', kind: 'string' },
|
|
109
|
-
{ name: 'destinationAddress', kind: 'string' },
|
|
110
|
-
{ name: 'bridgedTokenSymbol', kind: 'string' },
|
|
111
|
-
{ name: 'depositAssetId', kind: 'address' },
|
|
112
|
-
{
|
|
113
|
-
name: 'sourceCalls',
|
|
114
|
-
kind: 'array',
|
|
115
|
-
item: {
|
|
116
|
-
name: 'call',
|
|
117
|
-
kind: 'tuple',
|
|
118
|
-
components: [
|
|
119
|
-
{ name: 'callType', kind: 'uint' },
|
|
120
|
-
{ name: 'target', kind: 'address' },
|
|
121
|
-
{ name: 'value', kind: 'uint' },
|
|
122
|
-
{ name: 'callData', kind: 'bytes' },
|
|
123
|
-
{ name: 'payload', kind: 'bytes' },
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
{ name: 'payload', kind: 'bytes' },
|
|
128
|
-
{ name: 'fee', kind: 'uint' },
|
|
129
|
-
{ name: 'enableExpress', kind: 'bool' },
|
|
130
|
-
],
|
|
131
|
-
};
|
|
132
|
-
export const acrossPackedParam = {
|
|
133
|
-
name: 'parameters',
|
|
134
|
-
kind: 'tuple',
|
|
135
|
-
components: [
|
|
136
|
-
{ name: 'transactionId', kind: 'bytes', size: 8 },
|
|
137
|
-
{ name: 'receiver', kind: 'bytes', size: 32 },
|
|
138
|
-
{ name: 'depositor', kind: 'bytes', size: 32 },
|
|
139
|
-
{ name: 'destinationChainId', kind: 'uint' },
|
|
140
|
-
{ name: 'receivingAssetId', kind: 'bytes', size: 32 },
|
|
141
|
-
{ name: 'outputAmount', kind: 'uint' },
|
|
142
|
-
{ name: 'exclusiveRelayer', kind: 'bytes', size: 32 },
|
|
143
|
-
{ name: 'quoteTimestamp', kind: 'uint' },
|
|
144
|
-
{ name: 'fillDeadline', kind: 'uint' },
|
|
145
|
-
{ name: 'exclusivityParameter', kind: 'uint' },
|
|
146
|
-
{ name: 'message', kind: 'bytes' },
|
|
147
|
-
],
|
|
148
|
-
};
|
|
149
|
-
export const applyBridgeData = (method, raw) => {
|
|
150
|
-
const data = asRecord(raw);
|
|
151
|
-
return {
|
|
152
|
-
aggregatorId: 'lifi',
|
|
153
|
-
method,
|
|
154
|
-
kind: 'bridge',
|
|
155
|
-
sourceToken: asString(data.sendingAssetId),
|
|
156
|
-
sourceAmount: asBigint(data.minAmount),
|
|
157
|
-
bridgeToken: asString(data.sendingAssetId),
|
|
158
|
-
bridgeAmount: asBigint(data.minAmount),
|
|
159
|
-
destinationChainId: asBigint(data.destinationChainId),
|
|
160
|
-
receiver: asString(data.receiver),
|
|
161
|
-
bridgeReceiver: asString(data.receiver),
|
|
162
|
-
referrer: asString(data.referrer),
|
|
163
|
-
};
|
|
164
|
-
};
|
|
165
|
-
export const applyAcrossData = (parsed, raw) => {
|
|
166
|
-
const data = asRecord(raw);
|
|
167
|
-
parsed.receiver = accountFromBytes32(asString(data.receiverAddress));
|
|
168
|
-
parsed.outputToken = accountFromBytes32(asString(data.receivingAssetId));
|
|
169
|
-
parsed.minOutputAmount = asBigint(data.outputAmount);
|
|
170
|
-
};
|
|
171
|
-
export const applyStargateData = (parsed, raw) => {
|
|
172
|
-
const send = asRecord(asRecord(raw).sendParams);
|
|
173
|
-
parsed.receiver = accountFromBytes32(asString(send.to));
|
|
174
|
-
parsed.minOutputAmount = asBigint(send.minAmountLD);
|
|
175
|
-
};
|
|
176
|
-
export const applyRelayDepositoryData = (parsed, raw) => {
|
|
177
|
-
parsed.orderId = asString(asRecord(raw).orderId);
|
|
178
|
-
};
|
|
179
|
-
export const applyMayanData = (parsed, raw) => {
|
|
180
|
-
const data = asRecord(raw);
|
|
181
|
-
const receiver = accountFromBytes32(asString(data.nonEVMReceiver));
|
|
182
|
-
if (!/^0x0*$/.test(receiver)) {
|
|
183
|
-
parsed.receiver = receiver;
|
|
184
|
-
}
|
|
185
|
-
parsed.innerTarget = asString(data.mayanProtocol);
|
|
186
|
-
parsed.diagnostics = innerCallDiagnostics(asString(data.protocolData), 'protocol');
|
|
187
|
-
const protocol = readMayanProtocol(asString(data.protocolData), asBigint(data.minMiddleAmount) > 0n ? asBigint(data.minMiddleAmount) : parsed.bridgeAmount);
|
|
188
|
-
if (!protocol)
|
|
189
|
-
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_MAYAN_PROTOCOL_CALLDATA, parsed.diagnostics);
|
|
190
|
-
const { sourceToken, sourceAmount, aggregatorId, method, kind, ...destination } = protocol;
|
|
191
|
-
Object.assign(parsed, destination);
|
|
192
|
-
};
|
|
193
|
-
export const applyGasZipData = (parsed, raw) => {
|
|
194
|
-
const data = asRecord(raw);
|
|
195
|
-
parsed.receiver = accountFromBytes32(asString(data.receiverAddress));
|
|
196
|
-
parsed.destinationChainRef = asBigint(data.destinationChains).toString();
|
|
197
|
-
};
|
|
198
|
-
export const applySquidData = (parsed, raw) => {
|
|
199
|
-
const data = asRecord(raw);
|
|
200
|
-
parsed.destinationChainRef = asString(data.destinationChain);
|
|
201
|
-
parsed.receiver = asString(data.destinationAddress);
|
|
202
|
-
parsed.sourceToken = asString(data.depositAssetId);
|
|
203
|
-
};
|
|
204
|
-
export const polymerDataParam = {
|
|
205
|
-
name: 'polymerData',
|
|
206
|
-
kind: 'tuple',
|
|
207
|
-
components: [
|
|
208
|
-
{ name: 'polymerTokenFee', kind: 'uint' },
|
|
209
|
-
{ name: 'maxCCTPFee', kind: 'uint' },
|
|
210
|
-
{ name: 'nonEVMReceiver', kind: 'bytes', size: 32 },
|
|
211
|
-
{ name: 'solanaReceiverATA', kind: 'bytes', size: 32 },
|
|
212
|
-
{ name: 'minFinalityThreshold', kind: 'uint' },
|
|
213
|
-
{ name: 'refundRecipient', kind: 'address' },
|
|
214
|
-
{ name: 'hookData', kind: 'bytes' },
|
|
215
|
-
],
|
|
216
|
-
};
|
|
217
|
-
export const lifiIntentDataParam = {
|
|
218
|
-
name: 'lifiIntentData',
|
|
219
|
-
kind: 'tuple',
|
|
220
|
-
components: [
|
|
221
|
-
{ name: 'dstCallReceiver', kind: 'bytes', size: 32 },
|
|
222
|
-
{ name: 'recipient', kind: 'bytes', size: 32 },
|
|
223
|
-
{ name: 'depositAndRefundAddress', kind: 'address' },
|
|
224
|
-
{ name: 'nonce', kind: 'uint' },
|
|
225
|
-
{ name: 'expires', kind: 'uint' },
|
|
226
|
-
{ name: 'fillDeadline', kind: 'uint' },
|
|
227
|
-
{ name: 'inputOracle', kind: 'address' },
|
|
228
|
-
{ name: 'outputOracle', kind: 'bytes', size: 32 },
|
|
229
|
-
{ name: 'outputSettler', kind: 'bytes', size: 32 },
|
|
230
|
-
{ name: 'outputToken', kind: 'bytes', size: 32 },
|
|
231
|
-
{ name: 'outputAmountMultiplier', kind: 'uint' },
|
|
232
|
-
{ name: 'dstCallSwapData', kind: 'array', item: swapDataParam },
|
|
233
|
-
{ name: 'outputContext', kind: 'bytes' },
|
|
234
|
-
],
|
|
235
|
-
};
|
|
236
|
-
export const layerSwapDataParam = {
|
|
237
|
-
name: 'layerSwapData',
|
|
238
|
-
kind: 'tuple',
|
|
239
|
-
components: [
|
|
240
|
-
{ name: 'requestId', kind: 'bytes', size: 32 },
|
|
241
|
-
{ name: 'depositoryReceiver', kind: 'address' },
|
|
242
|
-
{ name: 'refundRecipient', kind: 'address' },
|
|
243
|
-
{ name: 'nonEVMReceiver', kind: 'bytes', size: 32 },
|
|
244
|
-
{ name: 'signature', kind: 'bytes' },
|
|
245
|
-
{ name: 'deadline', kind: 'uint' },
|
|
246
|
-
],
|
|
247
|
-
};
|
|
248
|
-
export const applyPolymerData = (parsed, raw) => {
|
|
249
|
-
const data = asRecord(raw);
|
|
250
|
-
parsed.outputTokenReference = { protocol: 'cctp', destinationChainId: parsed.destinationChainId };
|
|
251
|
-
parsed.minOutputAmount = subtractFees(parsed.bridgeAmount ?? 0n, asBigint(data.polymerTokenFee), asBigint(data.maxCCTPFee));
|
|
252
|
-
if (asString(data.hookData) !== '0x') {
|
|
253
|
-
parsed.destinationCallData = asString(data.hookData);
|
|
254
|
-
delete parsed.receiver;
|
|
255
|
-
delete parsed.outputTokenReference;
|
|
256
|
-
delete parsed.minOutputAmount;
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
export const applyLifiIntentData = (parsed, raw) => {
|
|
260
|
-
const data = asRecord(raw);
|
|
261
|
-
parsed.receiver = accountFromBytes32(asString(data.recipient));
|
|
262
|
-
parsed.outputToken = accountFromBytes32(asString(data.outputToken));
|
|
263
|
-
parsed.minOutputAmount = (parsed.bridgeAmount ?? 0n) * asBigint(data.outputAmountMultiplier) / 10n ** 18n;
|
|
264
|
-
if (asArray(data.dstCallSwapData).length) {
|
|
265
|
-
const destination = readLifiDestination(parsed, data);
|
|
266
|
-
parsed.hasDestinationCall = true;
|
|
267
|
-
parsed.bridgeReceiver = accountFromBytes32(asString(data.dstCallReceiver));
|
|
268
|
-
parsed.bridgeOutputToken = parsed.outputToken;
|
|
269
|
-
parsed.bridgeOutputAmount = parsed.minOutputAmount;
|
|
270
|
-
delete parsed.receiver;
|
|
271
|
-
delete parsed.outputToken;
|
|
272
|
-
delete parsed.minOutputAmount;
|
|
273
|
-
// Unknown deployments and arbitrary calls remain unverified.
|
|
274
|
-
if (destination)
|
|
275
|
-
Object.assign(parsed, destination);
|
|
276
|
-
}
|
|
277
|
-
parsed.orderId = asBigint(data.nonce).toString(16).padStart(64, '0');
|
|
278
|
-
parsed.orderId = `0x${parsed.orderId}`;
|
|
279
|
-
};
|
|
280
|
-
export const celerCircleDataParam = {
|
|
281
|
-
name: 'celerCircleData',
|
|
282
|
-
kind: 'tuple',
|
|
283
|
-
components: [
|
|
284
|
-
{ name: 'maxFee', kind: 'uint' },
|
|
285
|
-
{ name: 'minFinalityThreshold', kind: 'uint' },
|
|
286
|
-
],
|
|
287
|
-
};
|
|
288
|
-
const paxosRouteParam = {
|
|
289
|
-
name: 'route',
|
|
290
|
-
kind: 'tuple',
|
|
291
|
-
components: [
|
|
292
|
-
{ name: 'destEID', kind: 'uint' },
|
|
293
|
-
{ name: 'offerAsset', kind: 'address' },
|
|
294
|
-
{ name: 'wantAsset', kind: 'address' },
|
|
295
|
-
],
|
|
296
|
-
};
|
|
297
|
-
export const paxosDataParam = {
|
|
298
|
-
name: 'paxosData',
|
|
299
|
-
kind: 'tuple',
|
|
300
|
-
components: [
|
|
301
|
-
{
|
|
302
|
-
name: 'quote',
|
|
303
|
-
kind: 'tuple',
|
|
304
|
-
components: [
|
|
305
|
-
paxosRouteParam,
|
|
306
|
-
{ name: 'offerAmount', kind: 'uint' },
|
|
307
|
-
{ name: 'receiver', kind: 'address' },
|
|
308
|
-
{ name: 'protocolFee', kind: 'uint' },
|
|
309
|
-
{ name: 'integratorFee', kind: 'uint' },
|
|
310
|
-
{ name: 'integratorFeeReceiver', kind: 'address' },
|
|
311
|
-
{ name: 'distributorCode', kind: 'bytes', size: 32 },
|
|
312
|
-
{ name: 'deadline', kind: 'uint' },
|
|
313
|
-
{ name: 'salt', kind: 'bytes', size: 32 },
|
|
314
|
-
],
|
|
315
|
-
},
|
|
316
|
-
{ name: 'signature', kind: 'bytes' },
|
|
317
|
-
{ name: 'nativeFee', kind: 'uint' },
|
|
318
|
-
{ name: 'refundRecipient', kind: 'address' },
|
|
319
|
-
],
|
|
320
|
-
};
|
|
321
|
-
export const applyPaxosData = (parsed, raw) => {
|
|
322
|
-
const quote = asRecord(asRecord(raw).quote);
|
|
323
|
-
const route = asRecord(quote.route);
|
|
324
|
-
parsed.destinationChainRef = `layerzero:${asBigint(route.destEID)}`;
|
|
325
|
-
parsed.destinationChainId = LAYERZERO_CHAINS[asBigint(route.destEID).toString()];
|
|
326
|
-
parsed.outputToken = asString(route.wantAsset);
|
|
327
|
-
const offerAmount = asBigint(quote.offerAmount);
|
|
328
|
-
parsed.minOutputAmount = subtractFees(offerAmount, asBigint(quote.protocolFee), asBigint(quote.integratorFee));
|
|
329
|
-
const receiver = asString(quote.receiver);
|
|
330
|
-
parsed.receiver = receiver;
|
|
331
|
-
};
|
|
332
|
-
export const applyLayerSwapData = (parsed, raw) => {
|
|
333
|
-
const data = asRecord(raw);
|
|
334
|
-
if (asString(data.refundRecipient) !== parsed.receiver)
|
|
335
|
-
throw new BridgeError(BRIDGE_ERRORS.LAYERSWAP_REFUND_RECIPIENT_MISMATCH);
|
|
336
|
-
if (!/^0x0*$/.test(asString(data.nonEVMReceiver)))
|
|
337
|
-
throw new BridgeError(BRIDGE_ERRORS.UNSUPPORTED_LAYERSWAP_NON_EVM_RECEIVER);
|
|
338
|
-
parsed.orderId = asString(data.requestId);
|
|
339
|
-
// The LayerSwap signature binds bridgeData.receiver to this request ID.
|
|
340
|
-
};
|
|
341
|
-
export const applyCelerCircleData = (parsed, raw) => {
|
|
342
|
-
parsed.outputTokenReference = { protocol: 'cctp', destinationChainId: parsed.destinationChainId };
|
|
343
|
-
parsed.outputAmountReference = {
|
|
344
|
-
kind: 'fees', amount: parsed.bridgeAmount ?? 0n,
|
|
345
|
-
token: parsed.outputTokenReference, maxFee: asBigint(asRecord(raw).maxFee),
|
|
346
|
-
};
|
|
347
|
-
};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
export declare const methods: CalldataMethod[];
|
|
3
|
-
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
4
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { knownCompare } from '../../expect.js';
|
|
2
|
-
import { bridgeShape } from '../shape.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
import { applyPaxosData, paxosDataParam } from '../params.js';
|
|
5
|
-
export const methods = [
|
|
6
|
-
lifiBridgeMethod('startBridgeTokensViaPaxosTransit', '0x5080ffe2', [paxosDataParam], false, (parsed, args) => applyPaxosData(parsed, args.paxosData)),
|
|
7
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaPaxosTransit', '0x637f1d04', [paxosDataParam], true, (parsed, args) => applyPaxosData(parsed, args.paxosData)),
|
|
8
|
-
];
|
|
9
|
-
export const compare = knownCompare;
|
|
10
|
-
export const check = bridgeShape;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
export declare const methods: CalldataMethod[];
|
|
3
|
-
export declare const compare: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../expect.js").CompareMask;
|
|
4
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { knownCompare } from '../../expect.js';
|
|
2
|
-
import { bridgeShape } from '../shape.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
import { applyPolymerData, polymerDataParam } from '../params.js';
|
|
5
|
-
export const methods = [
|
|
6
|
-
lifiBridgeMethod('startBridgeTokensViaPolymerCCTP', '0xf434d6ca', [polymerDataParam], false, (parsed, args) => applyPolymerData(parsed, args.polymerData)),
|
|
7
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaPolymerCCTP', '0x17917a4e', [polymerDataParam], true, (parsed, args) => applyPolymerData(parsed, args.polymerData)),
|
|
8
|
-
];
|
|
9
|
-
export const compare = knownCompare;
|
|
10
|
-
export const check = bridgeShape;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
import type { CompareMask } from '../../expect.js';
|
|
3
|
-
import type { ParsedBridgeCall } from '../../types.js';
|
|
4
|
-
export declare const methods: CalldataMethod[];
|
|
5
|
-
export declare const compare: (parsed: ParsedBridgeCall) => CompareMask;
|
|
6
|
-
export declare const check: (parsed: ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { bridgeShape } from '../shape.js';
|
|
2
|
-
import { applyRelayDepositoryData, relayDepositoryDataParam } from '../params.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
export const methods = [
|
|
5
|
-
lifiBridgeMethod('startBridgeTokensViaRelayDepository', '0x092e8fa4', [relayDepositoryDataParam], false, (parsed, args) => applyRelayDepositoryData(parsed, args.relayDepositoryData)),
|
|
6
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaRelayDepository', '0xa3443faa', [relayDepositoryDataParam], true, (parsed, args) => applyRelayDepositoryData(parsed, args.relayDepositoryData)),
|
|
7
|
-
];
|
|
8
|
-
export const compare = (parsed) => ({
|
|
9
|
-
fromToken: parsed.sourceToken !== undefined,
|
|
10
|
-
fromAmount: parsed.sourceAmount !== undefined,
|
|
11
|
-
toToken: false,
|
|
12
|
-
toAmount: false,
|
|
13
|
-
receiver: true,
|
|
14
|
-
});
|
|
15
|
-
export const check = bridgeShape;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { BridgeErrorDefinition } from '../../errors/index.js';
|
|
2
|
-
import type { ParsedBridgeCall } from '../types.js';
|
|
3
|
-
export declare const bridgeShape: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
|
|
4
|
-
export declare const swapShape: (parsed: ParsedBridgeCall) => BridgeErrorDefinition | undefined;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS } from '../../errors/index.js';
|
|
2
|
-
import { isZeroWord } from '../hex.js';
|
|
3
|
-
export const bridgeShape = (parsed) => {
|
|
4
|
-
if (isZeroWord(parsed.receiver ?? parsed.bridgeReceiver)) {
|
|
5
|
-
return BRIDGE_ERRORS.MISSING_RECEIVER;
|
|
6
|
-
}
|
|
7
|
-
const hasDestination = (parsed.destinationChainId !== undefined && parsed.destinationChainId > 0n) ||
|
|
8
|
-
Boolean(parsed.destinationChainRef);
|
|
9
|
-
if (!hasDestination) {
|
|
10
|
-
return BRIDGE_ERRORS.MISSING_DESTINATION_CHAIN;
|
|
11
|
-
}
|
|
12
|
-
if (parsed.method.startsWith('swapAnd') && (parsed.sourceAmount ?? 0n) <= 0n) {
|
|
13
|
-
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
14
|
-
}
|
|
15
|
-
if (parsed.sourceToken === undefined) {
|
|
16
|
-
return BRIDGE_ERRORS.MISSING_SOURCE_TOKEN;
|
|
17
|
-
}
|
|
18
|
-
return undefined;
|
|
19
|
-
};
|
|
20
|
-
export const swapShape = (parsed) => {
|
|
21
|
-
if (!parsed.receiver || isZeroWord(parsed.receiver)) {
|
|
22
|
-
return BRIDGE_ERRORS.MISSING_RECEIVER;
|
|
23
|
-
}
|
|
24
|
-
if (parsed.minOutputAmount === undefined) {
|
|
25
|
-
return BRIDGE_ERRORS.MISSING_MIN_OUTPUT;
|
|
26
|
-
}
|
|
27
|
-
if ((parsed.sourceAmount ?? 0n) <= 0n) {
|
|
28
|
-
return BRIDGE_ERRORS.MISSING_SOURCE_AMOUNT;
|
|
29
|
-
}
|
|
30
|
-
return undefined;
|
|
31
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
import type { CompareMask } from '../../expect.js';
|
|
3
|
-
import type { ParsedBridgeCall } from '../../types.js';
|
|
4
|
-
export declare const methods: CalldataMethod[];
|
|
5
|
-
export declare const compare: (parsed: ParsedBridgeCall) => CompareMask;
|
|
6
|
-
export declare const check: (parsed: ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { bridgeShape } from '../shape.js';
|
|
2
|
-
import { applySquidData, squidDataParam } from '../params.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
export const methods = [
|
|
5
|
-
lifiBridgeMethod('startBridgeTokensViaSquid', '0x3f313808', [squidDataParam], false, (parsed, args) => applySquidData(parsed, args.squidData)),
|
|
6
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaSquid', '0xa8f66666', [squidDataParam], true, (parsed, args) => applySquidData(parsed, args.squidData)),
|
|
7
|
-
];
|
|
8
|
-
export const compare = (parsed) => ({
|
|
9
|
-
fromToken: parsed.sourceToken !== undefined,
|
|
10
|
-
fromAmount: parsed.sourceAmount !== undefined,
|
|
11
|
-
toToken: false,
|
|
12
|
-
toAmount: false,
|
|
13
|
-
receiver: true,
|
|
14
|
-
});
|
|
15
|
-
export const check = bridgeShape;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
import type { CompareMask } from '../../expect.js';
|
|
3
|
-
export declare const methods: CalldataMethod[];
|
|
4
|
-
export declare const compare: () => CompareMask;
|
|
5
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { bridgeShape } from '../shape.js';
|
|
2
|
-
import { applyStargateData, stargateDataParam } from '../params.js';
|
|
3
|
-
import { lifiBridgeMethod } from '../method.js';
|
|
4
|
-
export const methods = [
|
|
5
|
-
lifiBridgeMethod('startBridgeTokensViaStargate', '0x14d53077', [stargateDataParam], false, (parsed, args) => applyStargateData(parsed, args.stargateData)),
|
|
6
|
-
lifiBridgeMethod('swapAndStartBridgeTokensViaStargate', '0xa6010a66', [stargateDataParam], true, (parsed, args) => applyStargateData(parsed, args.stargateData)),
|
|
7
|
-
];
|
|
8
|
-
export const compare = () => ({
|
|
9
|
-
fromToken: true,
|
|
10
|
-
fromAmount: true,
|
|
11
|
-
toToken: false,
|
|
12
|
-
toAmount: true,
|
|
13
|
-
receiver: true,
|
|
14
|
-
});
|
|
15
|
-
export const check = bridgeShape;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { CalldataMethod } from '../../abi.js';
|
|
2
|
-
import type { CompareMask } from '../../expect.js';
|
|
3
|
-
export declare const methods: CalldataMethod[];
|
|
4
|
-
export declare const compare: () => CompareMask;
|
|
5
|
-
export declare const check: (parsed: import("../../types.js").ParsedBridgeCall) => import("../../../index.js").BridgeErrorDefinition | undefined;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { swapShape } from '../shape.js';
|
|
2
|
-
import { lifiSwapMethod } from './swapMethod.js';
|
|
3
|
-
export const methods = [
|
|
4
|
-
lifiSwapMethod('swapTokensSingleV3ERC20ToERC20', '0x4666fc80', false),
|
|
5
|
-
lifiSwapMethod('swapTokensSingleV3ERC20ToNative', '0x733214a3', false),
|
|
6
|
-
lifiSwapMethod('swapTokensSingleV3NativeToERC20', '0xaf7060fd', false),
|
|
7
|
-
lifiSwapMethod('swapTokensMultipleV3ERC20ToERC20', '0x5fd9ae2e', true),
|
|
8
|
-
lifiSwapMethod('swapTokensMultipleV3ERC20ToNative', '0x2c57e884', true),
|
|
9
|
-
lifiSwapMethod('swapTokensMultipleV3NativeToERC20', '0x736eac0b', true),
|
|
10
|
-
];
|
|
11
|
-
export const compare = () => ({
|
|
12
|
-
fromToken: true,
|
|
13
|
-
fromAmount: true,
|
|
14
|
-
toToken: true,
|
|
15
|
-
toAmount: true,
|
|
16
|
-
receiver: true,
|
|
17
|
-
});
|
|
18
|
-
export const check = swapShape;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { asArray, asBigint, asRecord, asString, decodeCall } from '../../abi.js';
|
|
2
|
-
import { applyFirstSwap, swapDataArrayParam, swapDataParam } from '../swapData.js';
|
|
3
|
-
const header = [
|
|
4
|
-
{ name: 'transactionId', kind: 'bytes', size: 32 },
|
|
5
|
-
{ name: 'integrator', kind: 'string' },
|
|
6
|
-
{ name: 'referrer', kind: 'string' },
|
|
7
|
-
{ name: 'receiver', kind: 'address' },
|
|
8
|
-
{ name: 'minAmountOut', kind: 'uint' },
|
|
9
|
-
];
|
|
10
|
-
export const lifiSwapMethod = (name, selector, multiple) => ({
|
|
11
|
-
name,
|
|
12
|
-
selector,
|
|
13
|
-
decode(data, value) {
|
|
14
|
-
const args = decodeCall([...header, multiple ? swapDataArrayParam : swapDataParam], data);
|
|
15
|
-
const parsed = {
|
|
16
|
-
aggregatorId: 'lifi',
|
|
17
|
-
method: name,
|
|
18
|
-
kind: 'swap',
|
|
19
|
-
receiver: asString(args.receiver),
|
|
20
|
-
referrer: asString(args.referrer),
|
|
21
|
-
minOutputAmount: asBigint(args.minAmountOut),
|
|
22
|
-
};
|
|
23
|
-
if (multiple) {
|
|
24
|
-
applyFirstSwap(parsed, args.swapData);
|
|
25
|
-
const swaps = asArray(args.swapData).map(asRecord);
|
|
26
|
-
if (swaps.length)
|
|
27
|
-
parsed.outputToken = asString(swaps[swaps.length - 1].receivingAssetId);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const swap = asRecord(args.swapData);
|
|
31
|
-
parsed.sourceToken = asString(swap.sendingAssetId);
|
|
32
|
-
parsed.sourceAmount = asBigint(swap.fromAmount);
|
|
33
|
-
parsed.outputToken = asString(swap.receivingAssetId);
|
|
34
|
-
}
|
|
35
|
-
if ((parsed.sourceAmount ?? 0n) === 0n && value > 0n) {
|
|
36
|
-
parsed.sourceAmount = value;
|
|
37
|
-
}
|
|
38
|
-
return parsed;
|
|
39
|
-
},
|
|
40
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type AbiParam, type AbiValue } from '../abi.js';
|
|
2
|
-
import type { ParsedBridgeCall } from '../types.js';
|
|
3
|
-
export declare const swapDataArrayParam: AbiParam;
|
|
4
|
-
export declare const swapDataParam: AbiParam;
|
|
5
|
-
export declare const applyFirstSwap: (parsed: ParsedBridgeCall, raw: AbiValue) => void;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, BridgeError } from '../../errors/index.js';
|
|
2
|
-
import { asArray, asBigint, asRecord, asString } from '../abi.js';
|
|
3
|
-
const swapComponents = [
|
|
4
|
-
{ name: 'callTo', kind: 'address' },
|
|
5
|
-
{ name: 'approveTo', kind: 'address' },
|
|
6
|
-
{ name: 'sendingAssetId', kind: 'address' },
|
|
7
|
-
{ name: 'receivingAssetId', kind: 'address' },
|
|
8
|
-
{ name: 'fromAmount', kind: 'uint' },
|
|
9
|
-
{ name: 'callData', kind: 'bytes' },
|
|
10
|
-
{ name: 'requiresDeposit', kind: 'bool' },
|
|
11
|
-
];
|
|
12
|
-
export const swapDataArrayParam = {
|
|
13
|
-
name: 'swapData', kind: 'array',
|
|
14
|
-
item: { name: 'swap', kind: 'tuple', components: swapComponents },
|
|
15
|
-
};
|
|
16
|
-
export const swapDataParam = {
|
|
17
|
-
name: 'swapData', kind: 'tuple', components: swapComponents,
|
|
18
|
-
};
|
|
19
|
-
export const applyFirstSwap = (parsed, raw) => {
|
|
20
|
-
const swaps = asArray(raw);
|
|
21
|
-
const deposits = swaps.map(asRecord).filter((swap) => swap.requiresDeposit === true);
|
|
22
|
-
const first = deposits[0] ?? swaps[0];
|
|
23
|
-
if (!first)
|
|
24
|
-
return;
|
|
25
|
-
const swap = asRecord(first);
|
|
26
|
-
parsed.sourceToken = asString(swap.sendingAssetId);
|
|
27
|
-
if (deposits.some((deposit) => asString(deposit.sendingAssetId) !== parsed.sourceToken)) {
|
|
28
|
-
throw new BridgeError(BRIDGE_ERRORS.MULTIPLE_SOURCE_ASSETS_ARE_NOT_SUPPORTED);
|
|
29
|
-
}
|
|
30
|
-
parsed.sourceAmount = deposits.length
|
|
31
|
-
? deposits.reduce((sum, deposit) => sum + asBigint(deposit.fromAmount), 0n)
|
|
32
|
-
: asBigint(swap.fromAmount);
|
|
33
|
-
};
|
package/dist/calldata/match.d.ts
DELETED
package/dist/calldata/match.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BRIDGE_ERRORS, asBridgeError, bridgeFailure } from '../errors/index.js';
|
|
2
|
-
import { readSelector } from './hex.js';
|
|
3
|
-
import { resolveParsed } from './resolve.js';
|
|
4
|
-
import { calldataDiagnostics } from './diagnostics.js';
|
|
5
|
-
export const matchMethod = (methods, data, value) => {
|
|
6
|
-
const selector = readSelector(data);
|
|
7
|
-
const diagnostics = calldataDiagnostics(data);
|
|
8
|
-
if (!selector)
|
|
9
|
-
return bridgeFailure([{ ...(data && data !== '0x' ? BRIDGE_ERRORS.INVALID_SELECTOR : BRIDGE_ERRORS.MISSING_CALLDATA), ...diagnostics }]);
|
|
10
|
-
for (const method of methods) {
|
|
11
|
-
if (method.selector !== selector)
|
|
12
|
-
continue;
|
|
13
|
-
try {
|
|
14
|
-
return { ok: true, parsed: resolveParsed(method.decode(data, value)) };
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
return { ...bridgeFailure(asBridgeError(error, BRIDGE_ERRORS.CALLDATA_DECODE_FAILED, { method: method.name, ...diagnostics }).errors), method: method.name };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return bridgeFailure([{ ...BRIDGE_ERRORS.UNSUPPORTED_METHOD, ...diagnostics }]);
|
|
21
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CCTP_CHAINS, WORMHOLE_CHAINS } from '../protocols.js';
|
|
2
|
-
export const mayanDestination = (system, id, token, normalizedAmount) => {
|
|
3
|
-
const destinationChainId = (system === 'cctp' ? CCTP_CHAINS : WORMHOLE_CHAINS)[id.toString()];
|
|
4
|
-
const destinationChainRef = `${system}:${id}`;
|
|
5
|
-
return {
|
|
6
|
-
destinationChainId, destinationChainRef,
|
|
7
|
-
outputToken: token,
|
|
8
|
-
outputAmountReference: token !== undefined && normalizedAmount !== undefined ? {
|
|
9
|
-
kind: 'normalized', amount: normalizedAmount, decimals: 8,
|
|
10
|
-
token: { protocol: 'token', token, destinationChainId, destinationChainRef },
|
|
11
|
-
} : undefined,
|
|
12
|
-
};
|
|
13
|
-
};
|