@gibs/bridge-sdk 1.19.0 → 1.20.0
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/dist/abis.js +0 -2
- package/dist/bridge-limits.js +0 -38
- package/dist/chain-info.js +0 -116
- package/dist/chain-names.js +0 -151
- package/dist/chains.js +0 -198
- package/dist/cjs/abis.js +0 -2
- package/dist/cjs/bridge-limits.js +0 -38
- package/dist/cjs/chain-info.js +0 -116
- package/dist/cjs/chain-names.js +0 -151
- package/dist/cjs/chains.js +0 -198
- package/dist/cjs/claims.js +0 -60
- package/dist/cjs/config.js +1 -208
- package/dist/cjs/consolidated-quote.js +0 -465
- package/dist/cjs/destination-calldata.js +0 -71
- package/dist/cjs/ecosystems.js +0 -183
- package/dist/cjs/execution.js +0 -92
- package/dist/cjs/fee-type.js +0 -1
- package/dist/cjs/hyperliquid-execution.js +0 -98
- package/dist/cjs/image-links.js +0 -108
- package/dist/cjs/lifi-execution-guard.js +65 -172
- package/dist/cjs/near-intents-conformance.js +0 -110
- package/dist/cjs/near-intents-route.js +0 -149
- package/dist/cjs/near-intents.js +0 -562
- package/dist/cjs/origin-deposit.js +0 -56
- package/dist/cjs/pre-quote.js +0 -80
- package/dist/cjs/prices.js +0 -113
- package/dist/cjs/providers.js +0 -83
- package/dist/cjs/quote-fees.js +0 -80
- package/dist/cjs/referral.js +0 -75
- package/dist/cjs/relay-currencies.js +0 -31
- package/dist/cjs/relay-depository.js +52 -77
- package/dist/cjs/relay-quote.js +0 -394
- package/dist/cjs/route-steps.js +0 -100
- package/dist/cjs/routing/amounts.js +0 -83
- package/dist/cjs/routing/candidate-route.js +0 -73
- package/dist/cjs/routing/candidate.js +0 -46
- package/dist/cjs/routing/carrier-provider-key.js +0 -27
- package/dist/cjs/routing/carriers/omnibridge.js +0 -120
- package/dist/cjs/routing/carriers/pulsex-paths.js +0 -57
- package/dist/cjs/routing/carriers/pulsex-split.js +0 -92
- package/dist/cjs/routing/carriers/pulsex.js +0 -279
- package/dist/cjs/routing/carriers/wrap.js +0 -57
- package/dist/cjs/routing/composed-route-quality.js +0 -95
- package/dist/cjs/routing/entry-chain-anchor.js +0 -27
- package/dist/cjs/routing/format.js +0 -50
- package/dist/cjs/routing/index.js +0 -28
- package/dist/cjs/routing/producers.js +0 -854
- package/dist/cjs/routing/providers.js +0 -27
- package/dist/cjs/routing/search/compose.js +0 -56
- package/dist/cjs/routing/search/graph.js +0 -364
- package/dist/cjs/routing/search/plan-route-data.js +0 -508
- package/dist/cjs/routing/search/score.js +0 -344
- package/dist/cjs/routing/swap-transactions.js +0 -74
- package/dist/cjs/routing/usd-value.js +0 -12
- package/dist/cjs/settings.js +1 -456
- package/dist/cjs/swap-venues.js +0 -17
- package/dist/cjs/ton-connect.js +0 -82
- package/dist/cjs/ton-execution.js +0 -6
- package/dist/cjs/ton.js +0 -42
- package/dist/cjs/tron-execution.js +0 -145
- package/dist/claims.js +0 -60
- package/dist/config.js +1 -211
- package/dist/consolidated-quote.js +0 -465
- package/dist/destination-calldata.js +0 -71
- package/dist/ecosystems.js +0 -183
- package/dist/execution.js +0 -92
- package/dist/fee-type.js +0 -2
- package/dist/hyperliquid-execution.js +0 -98
- package/dist/image-links.js +0 -108
- package/dist/lifi-execution-guard.js +65 -172
- package/dist/near-intents-conformance.js +0 -110
- package/dist/near-intents-route.js +0 -149
- package/dist/near-intents.js +0 -562
- package/dist/origin-deposit.js +0 -56
- package/dist/pre-quote.js +0 -80
- package/dist/prices.js +0 -113
- package/dist/providers.js +0 -83
- package/dist/quote-fees.js +0 -80
- package/dist/referral.js +0 -75
- package/dist/relay-currencies.js +0 -31
- package/dist/relay-depository.js +52 -77
- package/dist/relay-quote.js +0 -394
- package/dist/route-steps.js +0 -100
- package/dist/routing/amounts.js +0 -83
- package/dist/routing/candidate-route.js +0 -73
- package/dist/routing/candidate.js +0 -46
- package/dist/routing/carrier-provider-key.js +0 -27
- package/dist/routing/carriers/omnibridge.js +0 -120
- package/dist/routing/carriers/pulsex-paths.js +0 -57
- package/dist/routing/carriers/pulsex-split.js +0 -92
- package/dist/routing/carriers/pulsex.js +0 -279
- package/dist/routing/carriers/wrap.js +0 -57
- package/dist/routing/composed-route-quality.js +0 -95
- package/dist/routing/entry-chain-anchor.js +0 -27
- package/dist/routing/format.js +0 -50
- package/dist/routing/index.js +0 -28
- package/dist/routing/producers.js +0 -854
- package/dist/routing/providers.js +0 -27
- package/dist/routing/search/compose.js +0 -56
- package/dist/routing/search/graph.js +0 -364
- package/dist/routing/search/plan-route-data.js +0 -508
- package/dist/routing/search/score.js +0 -344
- package/dist/routing/swap-transactions.js +0 -74
- package/dist/routing/usd-value.js +0 -12
- package/dist/settings.js +1 -456
- package/dist/swap-venues.js +0 -17
- package/dist/ton-connect.js +0 -82
- package/dist/ton-execution.js +0 -6
- package/dist/ton.js +0 -42
- package/dist/tron-execution.js +0 -145
- package/package.json +3 -3
package/dist/settings.js
CHANGED
|
@@ -4,43 +4,18 @@ import { isNative, nativeAssetOut, pathway } from './config.js';
|
|
|
4
4
|
import { FeeType } from './fee-type.js';
|
|
5
5
|
export const oneEther = 10n ** 18n;
|
|
6
6
|
export const basisPoints = 10000n;
|
|
7
|
-
/**
|
|
8
|
-
* Returns the bridge pathway (configuration) for a given bridge key, asset in, and whether to use the production pathway
|
|
9
|
-
* @param bridgeKey - the bridge key to use
|
|
10
|
-
* @param isProd - whether to use the production pathway
|
|
11
|
-
* @param assetIn - the asset in to bridge
|
|
12
|
-
* @returns the bridge pathway
|
|
13
|
-
*/
|
|
14
7
|
export const bridgePathway = ({ bridgeKey, isProd, assetIn, }) => pathway(bridgeKey, isProd, assetIn?.address) ?? null;
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves the amount to bridge from the amount and asset in. If either of them is nil, returns 0n
|
|
17
|
-
* @param amountIn - the amount to bridge
|
|
18
|
-
* @param assetIn - the asset in to bridge
|
|
19
|
-
* @returns the amount to bridge
|
|
20
|
-
*/
|
|
21
8
|
export const amountToBridge = ({ amountIn, assetIn, }) => {
|
|
22
9
|
if (!amountIn || amountIn === 0n || !assetIn) {
|
|
23
10
|
return 0n;
|
|
24
11
|
}
|
|
25
12
|
return amountIn;
|
|
26
13
|
};
|
|
27
|
-
/**
|
|
28
|
-
* Calculates the bridge cost from the amount to bridge and bridge fee
|
|
29
|
-
* @param amountToBridge - the amount to bridge
|
|
30
|
-
* @param bridgeFee - the bridge fee
|
|
31
|
-
* @returns the bridge cost
|
|
32
|
-
*/
|
|
33
14
|
export const bridgeCost = ({ amountToBridge, bridgeFee, }) => {
|
|
34
15
|
if (bridgeFee === null)
|
|
35
16
|
return null;
|
|
36
17
|
return (amountToBridge * bridgeFee) / oneEther;
|
|
37
18
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Calculates the amount after bridge fee from the amount to bridge and bridge cost
|
|
40
|
-
* @param amountToBridge - the amount to bridge
|
|
41
|
-
* @param bridgeCost - the bridge cost
|
|
42
|
-
* @returns the amount after bridge fee
|
|
43
|
-
*/
|
|
44
19
|
export const amountAfterBridgeFee = ({ amountToBridge, bridgeCost, }) => {
|
|
45
20
|
if (bridgeCost === null)
|
|
46
21
|
return null;
|
|
@@ -49,12 +24,6 @@ export const amountAfterBridgeFee = ({ amountToBridge, bridgeCost, }) => {
|
|
|
49
24
|
return 0n;
|
|
50
25
|
return afterFee;
|
|
51
26
|
};
|
|
52
|
-
/**
|
|
53
|
-
* Calculates the estimated amount out from the amount after bridge fee and fee
|
|
54
|
-
* @param amountAfterBridgeFee - the amount after bridge fee
|
|
55
|
-
* @param fee - the fee
|
|
56
|
-
* @returns the estimated amount out
|
|
57
|
-
*/
|
|
58
27
|
export const estimatedAmountOut = ({ amountAfterBridgeFee, fee, }) => {
|
|
59
28
|
if (typeof fee !== 'bigint')
|
|
60
29
|
return null;
|
|
@@ -64,16 +33,6 @@ export const estimatedAmountOut = ({ amountAfterBridgeFee, fee, }) => {
|
|
|
64
33
|
return 0n;
|
|
65
34
|
return amountAfterBridgeFee - fee;
|
|
66
35
|
};
|
|
67
|
-
/**
|
|
68
|
-
* Calculates the estimated fee from the amount after bridge fee, fee, percent fee, fee type, limit, and whether to deliver the costs
|
|
69
|
-
* @param amountAfterBridgeFee - the amount after bridge fee
|
|
70
|
-
* @param fee - the fee
|
|
71
|
-
* @param percentFee - the percent fee
|
|
72
|
-
* @param feeType - the fee type
|
|
73
|
-
* @param limit - the limit
|
|
74
|
-
* @param costsToDeliver - whether to deliver the costs
|
|
75
|
-
* @returns the estimated fee
|
|
76
|
-
*/
|
|
77
36
|
export const estimatedFee = ({ amountAfterBridgeFee, fee, percentFee, feeType, limit, costsToDeliver, }) => {
|
|
78
37
|
const fixedFee = amountAfterBridgeFee ? (amountAfterBridgeFee * percentFee) / oneEther : null;
|
|
79
38
|
if (!costsToDeliver) {
|
|
@@ -92,28 +51,12 @@ export const estimatedFee = ({ amountAfterBridgeFee, fee, percentFee, feeType, l
|
|
|
92
51
|
}
|
|
93
52
|
return null;
|
|
94
53
|
};
|
|
95
|
-
/**
|
|
96
|
-
* Calculates the estimated native network cost from the estimated gas and latest base fee per gas
|
|
97
|
-
* @param estimatedGas - the estimated gas
|
|
98
|
-
* @param latestBaseFeePerGas - the latest base fee per gas
|
|
99
|
-
* @param requiresDelivery - whether to deliver the costs
|
|
100
|
-
* @returns the estimated native network cost
|
|
101
|
-
*/
|
|
102
54
|
export const estimatedNativeNetworkCost = ({ estimatedGas, latestBaseFeePerGas, requiresDelivery, }) => {
|
|
103
55
|
if (!estimatedGas || !latestBaseFeePerGas || !requiresDelivery) {
|
|
104
56
|
return null;
|
|
105
57
|
}
|
|
106
58
|
return BigInt(estimatedGas * latestBaseFeePerGas);
|
|
107
59
|
};
|
|
108
|
-
/**
|
|
109
|
-
* Calculates the estimated token network cost from the estimated native
|
|
110
|
-
* network cost, price corrective, decimals, and one token int
|
|
111
|
-
* @param estimatedNativeNetworkCost - the estimated native network cost
|
|
112
|
-
* @param priceCorrective - the price corrective
|
|
113
|
-
* @param decimals - the decimals
|
|
114
|
-
* @param oneTokenInt - the one token int
|
|
115
|
-
* @returns the estimated token network cost
|
|
116
|
-
*/
|
|
117
60
|
export const estimatedTokenNetworkCost = ({ estimatedNativeNetworkCost, priceCorrective, decimals, oneTokenInt, }) => {
|
|
118
61
|
if (!priceCorrective || !oneTokenInt || !estimatedNativeNetworkCost || !decimals) {
|
|
119
62
|
return null;
|
|
@@ -121,56 +64,26 @@ export const estimatedTokenNetworkCost = ({ estimatedNativeNetworkCost, priceCor
|
|
|
121
64
|
const tokenCost = (estimatedNativeNetworkCost * oneTokenInt) / priceCorrective;
|
|
122
65
|
return tokenCost;
|
|
123
66
|
};
|
|
124
|
-
/**
|
|
125
|
-
* Calculates one token of the asset in as an int
|
|
126
|
-
* @param assetIn - the asset in to bridge
|
|
127
|
-
* @returns the one token int
|
|
128
|
-
*/
|
|
129
67
|
export const oneTokenInt = ({ assetIn }) => {
|
|
130
68
|
if (!assetIn)
|
|
131
69
|
return 1n;
|
|
132
70
|
return 10n ** BigInt(assetIn.decimals);
|
|
133
71
|
};
|
|
134
|
-
/**
|
|
135
|
-
* Returns the limit as a bigint. Nil uses 0n
|
|
136
|
-
* @param lim - the limit
|
|
137
|
-
* @returns the limit
|
|
138
|
-
*/
|
|
139
72
|
export const limit = (lim) => {
|
|
140
73
|
if (!lim) {
|
|
141
74
|
return 0n;
|
|
142
75
|
}
|
|
143
76
|
return lim;
|
|
144
77
|
};
|
|
145
|
-
/**
|
|
146
|
-
* Returns the network switch asset out address from the asset out, unwrap, and to chain
|
|
147
|
-
* @param assetOut - the asset out
|
|
148
|
-
* @param unwrap - whether to unwrap
|
|
149
|
-
* @param toChain - the chain to switch to
|
|
150
|
-
* @returns the network switch asset out address
|
|
151
|
-
*/
|
|
152
78
|
export const networkSwitchAssetOutAddress = ({ assetOut, unwrap, toChain, }) => {
|
|
153
79
|
if (!assetOut)
|
|
154
80
|
return null;
|
|
155
81
|
if (!unwrap)
|
|
156
82
|
return assetOut.address;
|
|
157
83
|
const wrappedNative = nativeAssetOut[toChain];
|
|
158
|
-
// Addresses arrive in whatever case their source used (a checksummed literal
|
|
159
|
-
// here, a lower-cased list entry there), so equality must ignore case.
|
|
160
84
|
const isWrappedNative = !!wrappedNative && isAddress(assetOut.address, { strict: false }) && isAddressEqual(wrappedNative, assetOut.address);
|
|
161
85
|
return isWrappedNative ? zeroAddress : assetOut.address;
|
|
162
86
|
};
|
|
163
|
-
/**
|
|
164
|
-
* Calculates the desired excess compensation basis points from the path, asset in, asset out, bridge key, fee type, list, and asset out address
|
|
165
|
-
* @param path - the path
|
|
166
|
-
* @param assetIn - the asset in to bridge
|
|
167
|
-
* @param assetOut - the asset out
|
|
168
|
-
* @param bridgeKey - the bridge key
|
|
169
|
-
* @param feeType - the fee type
|
|
170
|
-
* @param list - the list
|
|
171
|
-
* @param assetOutAddress - the asset out address
|
|
172
|
-
* @returns the desired excess compensation basis points
|
|
173
|
-
*/
|
|
174
87
|
export const desiredExcessCompensationBasisPoints = ({ path, assetIn, assetOut, bridgeKey, feeType, list, assetOutAddress, }) => {
|
|
175
88
|
if (!path?.requiresDelivery) {
|
|
176
89
|
return 0n;
|
|
@@ -186,31 +99,6 @@ export const desiredExcessCompensationBasisPoints = ({ path, assetIn, assetOut,
|
|
|
186
99
|
? 5000n
|
|
187
100
|
: 10000n;
|
|
188
101
|
};
|
|
189
|
-
/**
|
|
190
|
-
* Works out the Gibs delivery fee for a transfer, as a {@link DeliveryFee}.
|
|
191
|
-
*
|
|
192
|
-
* Each mode reads the SAME figure the delivered estimate subtracts
|
|
193
|
-
* ({@link estimatedFee}), so a route's cost and its delivered value reconcile:
|
|
194
|
-
*
|
|
195
|
-
* - percent: the arriving value times the rate. The router computes
|
|
196
|
-
* `value * multiplier / 1 ether`.
|
|
197
|
-
* - fixed: the fixed amount. The router takes `limit` as the fee.
|
|
198
|
-
* - gas: the limit. The router takes the gas cost, capped at the limit, so the
|
|
199
|
-
* limit is the most the reader pays and the figure the delivered estimate
|
|
200
|
-
* already assumes.
|
|
201
|
-
*
|
|
202
|
-
* `percentFee` must be null when the rate is not known. Passing a zero stand-in
|
|
203
|
-
* would state a free delivery.
|
|
204
|
-
*
|
|
205
|
-
* @param options.shouldDeliver - whether the reader asked for delivery
|
|
206
|
-
* @param options.routeOffersDelivery - whether this pathway delivers for a fee at all
|
|
207
|
-
* @param options.feeType - the delivery fee mode
|
|
208
|
-
* @param options.amountAfterBridgeFee - the value that reaches the destination router, or null
|
|
209
|
-
* @param options.percentFee - the percent rate as a fraction of one ether, or null when unknown
|
|
210
|
-
* @param options.fixedFee - the fixed fee in base units, or null when unknown
|
|
211
|
-
* @param options.limit - the gas mode cap in base units, or null when unknown
|
|
212
|
-
* @returns the delivery fee
|
|
213
|
-
*/
|
|
214
102
|
export const deliveryFee = ({ shouldDeliver, routeOffersDelivery, feeType, amountAfterBridgeFee, percentFee, fixedFee, limit, }) => {
|
|
215
103
|
if (!shouldDeliver || !routeOffersDelivery) {
|
|
216
104
|
return { status: 'not-requested' };
|
|
@@ -230,18 +118,6 @@ export const deliveryFee = ({ shouldDeliver, routeOffersDelivery, feeType, amoun
|
|
|
230
118
|
rate: percentFee,
|
|
231
119
|
};
|
|
232
120
|
};
|
|
233
|
-
/**
|
|
234
|
-
* The four-bit fee-type settings word a fee director carries.
|
|
235
|
-
*
|
|
236
|
-
* - bit 0: fixed fee mode.
|
|
237
|
-
* - bit 1: unwrap the delivered token to the native coin.
|
|
238
|
-
* - bit 2: exclude the priority fee from the delivery cost. Always set.
|
|
239
|
-
* - bit 3: percent fee mode.
|
|
240
|
-
*
|
|
241
|
-
* @param options.feeType - the delivery fee mode
|
|
242
|
-
* @param options.unwrap - whether the delivery unwraps to the native coin
|
|
243
|
-
* @returns the settings word for {@link feeDirectorStructEncoded}
|
|
244
|
-
*/
|
|
245
121
|
export const feeTypeSettings = ({ feeType, unwrap }) => {
|
|
246
122
|
const fixedBit = feeType === FeeType.FIXED ? 1n : 0n;
|
|
247
123
|
const unwrapBit = unwrap ? 1n : 0n;
|
|
@@ -249,42 +125,11 @@ export const feeTypeSettings = ({ feeType, unwrap }) => {
|
|
|
249
125
|
const percentBit = feeType === FeeType.PERCENT ? 1n : 0n;
|
|
250
126
|
return (percentBit << 3n) | (excludePriorityBit << 2n) | (unwrapBit << 1n) | fixedBit;
|
|
251
127
|
};
|
|
252
|
-
/**
|
|
253
|
-
* The ERC-20 `approve` call, as a target, a value and calldata. The
|
|
254
|
-
* interface's approval broadcast and the SDK's execution planner both build it
|
|
255
|
-
* here.
|
|
256
|
-
*
|
|
257
|
-
* @param options.token - the token to approve
|
|
258
|
-
* @param options.spender - the address allowed to pull it
|
|
259
|
-
* @param options.amount - the allowance to set
|
|
260
|
-
* @returns the call
|
|
261
|
-
*/
|
|
262
128
|
export const approveCall = ({ token, spender, amount, }) => ({
|
|
263
129
|
to: token,
|
|
264
130
|
value: 0n,
|
|
265
131
|
data: encodeFunctionData({ abi: erc20Abi, functionName: 'approve', args: [spender, amount] }),
|
|
266
132
|
});
|
|
267
|
-
/**
|
|
268
|
-
* The `approve` amounts to send, in order, so the spender may pull exactly
|
|
269
|
-
* `minimum`. Empty when the allowance on chain already covers it.
|
|
270
|
-
*
|
|
271
|
-
* EXACT, NEVER UNLIMITED. An unlimited approval lets the spender pull the
|
|
272
|
-
* reader's whole balance for as long as the approval stands, so a later fault
|
|
273
|
-
* in that contract, or a spender a compromised quote named, costs everything
|
|
274
|
-
* rather than one transfer. The owner chose exact approvals everywhere
|
|
275
|
-
* (2026-10-07); the interface and the SDK's execution planner both decide
|
|
276
|
-
* here.
|
|
277
|
-
*
|
|
278
|
-
* A SHORT, NON-ZERO ALLOWANCE IS RESET TO ZERO FIRST. Some tokens (Tether on
|
|
279
|
-
* Ethereum is the known one) revert an `approve` that changes one non-zero
|
|
280
|
-
* allowance into another. Exact approvals leave such remainders more often,
|
|
281
|
-
* because an aggregator may spend less than it was allowed. A reset first
|
|
282
|
-
* works for every token, at the cost of one extra transaction in that case.
|
|
283
|
-
*
|
|
284
|
-
* @param options.allowance - the allowance on chain now
|
|
285
|
-
* @param options.minimum - the amount the next transaction pulls
|
|
286
|
-
* @returns the amounts to approve, in order: none, `[minimum]`, or `[0n, minimum]`
|
|
287
|
-
*/
|
|
288
133
|
export const approvalAmounts = ({ allowance, minimum, }) => {
|
|
289
134
|
if (allowance >= minimum)
|
|
290
135
|
return [];
|
|
@@ -292,21 +137,6 @@ export const approvalAmounts = ({ allowance, minimum, }) => {
|
|
|
292
137
|
return [minimum];
|
|
293
138
|
return [0n, minimum];
|
|
294
139
|
};
|
|
295
|
-
/**
|
|
296
|
-
* The allowance a direct omnibridge crossing needs, or null when it needs none.
|
|
297
|
-
*
|
|
298
|
-
* Reads the SAME predicate {@link transactionInputs} uses to pick the call: a
|
|
299
|
-
* token the bridge minted ({@link interactingWithBridgeToken}) is burned by
|
|
300
|
-
* `transferAndCall` and needs no allowance, and the native coin is sent as
|
|
301
|
-
* value. Every other token is pulled by the pathway's `from` mediator through
|
|
302
|
-
* `relayTokens` or `relayTokensAndCall`.
|
|
303
|
-
*
|
|
304
|
-
* @param options.bridgePathway - the crossing's pathway
|
|
305
|
-
* @param options.assetIn - the token the crossing spends
|
|
306
|
-
* @param options.assetLink - the token's bridge link
|
|
307
|
-
* @param options.amountToBridge - the amount the crossing pulls
|
|
308
|
-
* @returns the approval the crossing needs, or null
|
|
309
|
-
*/
|
|
310
140
|
export const omnibridgeApproval = ({ bridgePathway, assetIn, assetLink, amountToBridge, }) => {
|
|
311
141
|
if (assetIn.address === zeroAddress)
|
|
312
142
|
return null;
|
|
@@ -319,34 +149,16 @@ export const omnibridgeApproval = ({ bridgePathway, assetIn, assetLink, amountTo
|
|
|
319
149
|
minimum: amountToBridge,
|
|
320
150
|
};
|
|
321
151
|
};
|
|
322
|
-
/**
|
|
323
|
-
* Calculates the reasonable fixed fee from the estimated token network cost and desired excess compensation basis points
|
|
324
|
-
* @param estimatedTokenNetworkCost - the estimated token network cost
|
|
325
|
-
* @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
|
|
326
|
-
* @returns the reasonable fixed fee
|
|
327
|
-
*/
|
|
328
152
|
export const reasonableFixedFee = ({ estimatedTokenNetworkCost, desiredExcessCompensationBasisPoints, }) => {
|
|
329
153
|
if (!estimatedTokenNetworkCost) {
|
|
330
154
|
return null;
|
|
331
155
|
}
|
|
332
156
|
return ((estimatedTokenNetworkCost * (25000n + desiredExcessCompensationBasisPoints)) / basisPoints);
|
|
333
157
|
};
|
|
334
|
-
/**
|
|
335
|
-
* Calculates the reasonable percent on gas limit from the gas tip fee and estimated token network cost
|
|
336
|
-
* @param gasTipFee - the gas tip fee
|
|
337
|
-
* @param estimatedTokenNetworkCost - the estimated token network cost
|
|
338
|
-
* @returns the reasonable percent on gas limit
|
|
339
|
-
*/
|
|
340
158
|
export const reasonablePercentOnGasLimit = ({ gasTipFee, estimatedTokenNetworkCost, }) => {
|
|
341
159
|
return ((25000n * ((oneEther + (gasTipFee ?? 0n)) * (estimatedTokenNetworkCost ?? 0n))) /
|
|
342
160
|
(oneEther * basisPoints));
|
|
343
161
|
};
|
|
344
|
-
/**
|
|
345
|
-
* Calculates the reasonable percent fee from the reasonable fixed fee and amount after bridge fee
|
|
346
|
-
* @param reasonableFixedFee - the reasonable fixed fee
|
|
347
|
-
* @param amountAfterBridgeFee - the amount after bridge fee
|
|
348
|
-
* @returns the reasonable percent fee
|
|
349
|
-
*/
|
|
350
162
|
export const reasonablePercentFee = ({ reasonableFixedFee, amountAfterBridgeFee, }) => {
|
|
351
163
|
if (!reasonableFixedFee) {
|
|
352
164
|
return null;
|
|
@@ -359,7 +171,7 @@ export const reasonablePercentFee = ({ reasonableFixedFee, amountAfterBridgeFee,
|
|
|
359
171
|
const max = 1000n * basisFeeTruncator;
|
|
360
172
|
const min = 5n * basisFeeTruncator;
|
|
361
173
|
if (highFee < reasonableFixedFee) {
|
|
362
|
-
return max;
|
|
174
|
+
return max;
|
|
363
175
|
}
|
|
364
176
|
const highResPercent = (reasonableFixedFee * oneEther) / amountAfterBridgeFee;
|
|
365
177
|
if (highResPercent < min) {
|
|
@@ -371,12 +183,6 @@ export const reasonablePercentFee = ({ reasonableFixedFee, amountAfterBridgeFee,
|
|
|
371
183
|
const basisPoint = highResPercent / basisFeeTruncator;
|
|
372
184
|
return basisPoint * basisFeeTruncator;
|
|
373
185
|
};
|
|
374
|
-
/**
|
|
375
|
-
* Returns whether the asset in address is interacting with a bridge token
|
|
376
|
-
* @param assetLink - the asset link
|
|
377
|
-
* @param assetInAddress - the asset in address
|
|
378
|
-
* @returns whether the asset in address is interacting with a bridge token
|
|
379
|
-
*/
|
|
380
186
|
export const interactingWithBridgeToken = ({ assetLink, assetInAddress, }) => {
|
|
381
187
|
const { toForeign, toHome } = assetLink || {};
|
|
382
188
|
const { foreign } = toForeign || {};
|
|
@@ -386,19 +192,6 @@ export const interactingWithBridgeToken = ({ assetLink, assetInAddress, }) => {
|
|
|
386
192
|
return !!((foreign && getAddress(foreign) === getAddress(assetInAddress)) ||
|
|
387
193
|
(home && getAddress(home) === getAddress(assetInAddress)));
|
|
388
194
|
};
|
|
389
|
-
/**
|
|
390
|
-
* Calculates the fee director struct encoded from the recipient, bridge pathway, fee type, price corrective, gas tip fee, percent fee, fee type settings, limit, and asset out
|
|
391
|
-
* @param recipient - the recipient
|
|
392
|
-
* @param bridgePathway - the bridge pathway
|
|
393
|
-
* @param feeType - the fee type
|
|
394
|
-
* @param priceCorrective - the price corrective
|
|
395
|
-
* @param gasTipFee - the gas tip fee
|
|
396
|
-
* @param percentFee - the percent fee
|
|
397
|
-
* @param feeTypeSettings - the fee type settings
|
|
398
|
-
* @param limit - the limit
|
|
399
|
-
* @param assetOut - the asset out
|
|
400
|
-
* @returns the fee director struct encoded
|
|
401
|
-
*/
|
|
402
195
|
export const feeDirectorStructEncoded = ({ recipient, bridgePathway, feeType, priceCorrective, gasTipFee, percentFee, feeTypeSettings, limit, assetOut, }) => {
|
|
403
196
|
if (!assetOut || !bridgePathway) {
|
|
404
197
|
return null;
|
|
@@ -424,20 +217,7 @@ export const feeDirectorStructEncoded = ({ recipient, bridgePathway, feeType, pr
|
|
|
424
217
|
[recipient, feeTypeSettings, limit, multiplier],
|
|
425
218
|
]);
|
|
426
219
|
};
|
|
427
|
-
/**
|
|
428
|
-
* Calculates the destination data param from the recipient, bridge pathway, asset in, destination router, fee director struct encoded, asset link, should deliver, and unwrap
|
|
429
|
-
* @param recipient - the recipient
|
|
430
|
-
* @param bridgePathway - the bridge pathway
|
|
431
|
-
* @param assetIn - the asset in to bridge
|
|
432
|
-
* @param destinationRouter - the destination router
|
|
433
|
-
* @param feeDirectorStructEncoded - the fee director struct encoded
|
|
434
|
-
* @param assetLink - the asset link
|
|
435
|
-
* @param shouldDeliver - whether to deliver the costs
|
|
436
|
-
* @param unwrap - whether to unwrap
|
|
437
|
-
* @returns the destination data param
|
|
438
|
-
*/
|
|
439
220
|
export const destinationDataParam = ({ recipient, bridgePathway, assetIn, destinationRouter, feeDirectorStructEncoded, assetLink, shouldDeliver, unwrap, }) => {
|
|
440
|
-
// const recipient = input.recipient.value
|
|
441
221
|
if (!recipient) {
|
|
442
222
|
return null;
|
|
443
223
|
}
|
|
@@ -447,8 +227,6 @@ export const destinationDataParam = ({ recipient, bridgePathway, assetIn, destin
|
|
|
447
227
|
if (!destinationRouter) {
|
|
448
228
|
return null;
|
|
449
229
|
}
|
|
450
|
-
// Only a delivery needs the fee director. A crossing without delivery sends
|
|
451
|
-
// to the recipient, whatever the fee director would have said.
|
|
452
230
|
if (bridgePathway.requiresDelivery && shouldDeliver && !feeDirectorStructEncoded) {
|
|
453
231
|
return null;
|
|
454
232
|
}
|
|
@@ -456,12 +234,9 @@ export const destinationDataParam = ({ recipient, bridgePathway, assetIn, destin
|
|
|
456
234
|
return null;
|
|
457
235
|
}
|
|
458
236
|
if (bridgePathway.requiresDelivery) {
|
|
459
|
-
// going from home to foreign
|
|
460
237
|
if (!shouldDeliver) {
|
|
461
|
-
// act like a regular bridge
|
|
462
238
|
return recipient;
|
|
463
239
|
}
|
|
464
|
-
// going from foreign to home
|
|
465
240
|
if (feeDirectorStructEncoded) {
|
|
466
241
|
return concatHex([destinationRouter, feeDirectorStructEncoded]);
|
|
467
242
|
}
|
|
@@ -470,34 +245,14 @@ export const destinationDataParam = ({ recipient, bridgePathway, assetIn, destin
|
|
|
470
245
|
if (!unwrap) {
|
|
471
246
|
return recipient;
|
|
472
247
|
}
|
|
473
|
-
// unwrap wpls->pls
|
|
474
248
|
return concatHex([destinationRouter, recipient]);
|
|
475
249
|
};
|
|
476
|
-
/**
|
|
477
|
-
* Converts a desired excess compensation basis point value into a percentage as an integer, with the denominator assumed to be 1e18
|
|
478
|
-
* @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
|
|
479
|
-
* @returns the reasonable percent on top of gas fee
|
|
480
|
-
*/
|
|
481
250
|
export const reasonablePercentOnTopOfGasFee = ({ desiredExcessCompensationBasisPoints, }) => {
|
|
482
251
|
return desiredExcessCompensationBasisPoints * (oneEther / basisPoints);
|
|
483
252
|
};
|
|
484
|
-
/**
|
|
485
|
-
* Calculates the desired compensation ratio from the desired excess compensation basis points
|
|
486
|
-
* @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
|
|
487
|
-
* @returns the desired compensation ratio
|
|
488
|
-
*/
|
|
489
253
|
export const desiredCompensationRatio = ({ desiredExcessCompensationBasisPoints, }) => {
|
|
490
254
|
return oneEther + (desiredExcessCompensationBasisPoints * oneEther) / basisPoints;
|
|
491
255
|
};
|
|
492
|
-
/**
|
|
493
|
-
* Calculates the available compensation maximum from the amount after bridge fee, percent fee, fee type, fixed fee, and limit
|
|
494
|
-
* @param amountAfterBridgeFee - the amount after bridge fee
|
|
495
|
-
* @param percentFee - the percent fee
|
|
496
|
-
* @param feeType - the fee type
|
|
497
|
-
* @param fixedFee - the fixed fee
|
|
498
|
-
* @param limit - the limit
|
|
499
|
-
* @returns the available compensation maximum
|
|
500
|
-
*/
|
|
501
256
|
export const availableCompensationMaximum = ({ amountAfterBridgeFee, percentFee, feeType, fixedFee, limit, }) => {
|
|
502
257
|
if (feeType === FeeType.PERCENT) {
|
|
503
258
|
if (amountAfterBridgeFee === null)
|
|
@@ -512,71 +267,21 @@ export const availableCompensationMaximum = ({ amountAfterBridgeFee, percentFee,
|
|
|
512
267
|
}
|
|
513
268
|
return 0n;
|
|
514
269
|
};
|
|
515
|
-
/**
|
|
516
|
-
* Determines if the bridge is undercompensated based on network costs vs compensation limit using desired compensation rate
|
|
517
|
-
* @param estimatedTokenNetworkCost - the estimated token network cost
|
|
518
|
-
* @param feeType - the fee type
|
|
519
|
-
* @param limit - the maximum compensation limit
|
|
520
|
-
* @param amountAfterBridgeFee - the amount after bridge fee
|
|
521
|
-
* @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
|
|
522
|
-
* @returns whether the bridge is undercompensated
|
|
523
|
-
*/
|
|
524
270
|
export const isUndercompensated = ({ estimatedTokenNetworkCost, feeType, limit, amountAfterBridgeFee, desiredExcessCompensationBasisPoints, }) => {
|
|
525
|
-
// No undercompensation if no amount to bridge
|
|
526
271
|
if (!amountAfterBridgeFee || amountAfterBridgeFee <= 0n) {
|
|
527
272
|
return false;
|
|
528
273
|
}
|
|
529
|
-
// GAS_TIP fee type doesn't have undercompensation issues
|
|
530
274
|
if (feeType === FeeType.GAS_TIP) {
|
|
531
275
|
return false;
|
|
532
276
|
}
|
|
533
|
-
// No network cost estimate means we can't determine undercompensation
|
|
534
277
|
if (!estimatedTokenNetworkCost) {
|
|
535
278
|
return false;
|
|
536
279
|
}
|
|
537
|
-
// Calculate desired compensation using the actual desired compensation ratio
|
|
538
280
|
const desiredCompensationRatio = oneEther + (desiredExcessCompensationBasisPoints * oneEther) / basisPoints;
|
|
539
281
|
const desiredCompensationForNetworkCost = (estimatedTokenNetworkCost * desiredCompensationRatio) / oneEther;
|
|
540
|
-
// Undercompensated if desired compensation exceeds the limit
|
|
541
282
|
return desiredCompensationForNetworkCost > limit;
|
|
542
283
|
};
|
|
543
|
-
/**
|
|
544
|
-
* Why a bridge key must not be built into a transaction for the pair on screen,
|
|
545
|
-
* or null when the two agree.
|
|
546
|
-
*
|
|
547
|
-
* WHY THIS EXISTS, in the reader's words: "i just tried to swap from weth from
|
|
548
|
-
* ethereum on pls, to pls, and the calldata that i must have signed was to
|
|
549
|
-
* bridge back from pls to eth". A selection of PulseChain on BOTH sides is a
|
|
550
|
-
* swap; it has no pathway, so the bridge key kept whatever crossing it last
|
|
551
|
-
* held — or the address bar was repaired to a crossing — and the settings
|
|
552
|
-
* cascade went on building a real, signable transfer of the reader's bridged
|
|
553
|
-
* wrapped ether to Ethereum while the screen still named PulseChain.
|
|
554
|
-
*
|
|
555
|
-
* Three refusals, and each one is a separate way the two can part company:
|
|
556
|
-
*
|
|
557
|
-
* - A SAME-CHAIN SELECTION IS NEVER A CROSSING. Origin and destination on one
|
|
558
|
-
* chain describes a swap. No omnibridge pathway can serve it, so any pathway
|
|
559
|
-
* reached for here belongs to some other journey.
|
|
560
|
-
* - THE PATHWAY MUST LEAVE THE CHAIN THE READER'S FUNDS ARE ON. A key whose
|
|
561
|
-
* source chain differs spends a token the reader is not looking at.
|
|
562
|
-
* - THE PATHWAY MUST LAND WHERE THE READER ASKED. This is the reported defect:
|
|
563
|
-
* the destination silently became Ethereum.
|
|
564
|
-
*
|
|
565
|
-
* `signedCrossing` is `null` for a call no reader composed — the aggregator's
|
|
566
|
-
* executor call built by `buildDestinationCalldata`, where the chain pair IS
|
|
567
|
-
* the pathway and there is no screen to disagree with. Nullable rather than
|
|
568
|
-
* optional so every caller has to decide, and the decision is visible at the
|
|
569
|
-
* call site.
|
|
570
|
-
*
|
|
571
|
-
* @param bridgeKey - the key the pathway was resolved from
|
|
572
|
-
* @param signedCrossing - the pair on screen, or null when no surface composed it
|
|
573
|
-
* @returns the reason to refuse, or null when the two agree
|
|
574
|
-
*/
|
|
575
284
|
export const crossingRefusal = ({ bridgeKey, signedCrossing, }) => {
|
|
576
|
-
// `undefined` is treated as `null` here, and only here. The field is REQUIRED
|
|
577
|
-
// by the type, so no compiled caller can omit it — but a test double that
|
|
578
|
-
// returns a partial object can, and a crash inside the settings cascade blanks
|
|
579
|
-
// the page rather than refusing a transaction.
|
|
580
285
|
if (signedCrossing === null || signedCrossing === undefined) {
|
|
581
286
|
return null;
|
|
582
287
|
}
|
|
@@ -597,48 +302,13 @@ export const crossingRefusal = ({ bridgeKey, signedCrossing, }) => {
|
|
|
597
302
|
}
|
|
598
303
|
return null;
|
|
599
304
|
};
|
|
600
|
-
/**
|
|
601
|
-
* Throws when the bridge key and the pair on screen describe different journeys.
|
|
602
|
-
*
|
|
603
|
-
* The LOUD half of {@link crossingRefusal}. {@link transactionInputs} runs
|
|
604
|
-
* during render, where a throw would blank the application, so it refuses
|
|
605
|
-
* quietly by returning null and the button it feeds stays inert. This is for
|
|
606
|
-
* the broadcast funnel, where a disagreement means something reconstructed the
|
|
607
|
-
* call another way and the reader is one signature from a transfer they never
|
|
608
|
-
* asked for — there, silence is the worse failure.
|
|
609
|
-
*
|
|
610
|
-
* @param bridgeKey - the key the pathway was resolved from
|
|
611
|
-
* @param signedCrossing - the pair on screen, or null when no surface composed it
|
|
612
|
-
* @throws when the two describe different journeys
|
|
613
|
-
*/
|
|
614
305
|
export const assertCrossingAgrees = ({ bridgeKey, signedCrossing, }) => {
|
|
615
306
|
const refusal = crossingRefusal({ bridgeKey, signedCrossing });
|
|
616
307
|
if (refusal !== null) {
|
|
617
308
|
throw new Error(refusal);
|
|
618
309
|
}
|
|
619
310
|
};
|
|
620
|
-
/**
|
|
621
|
-
* Why a same-chain PulseX swap transaction must not be built for the leg on
|
|
622
|
-
* screen, or null when they agree. The swap-side sibling of
|
|
623
|
-
* {@link crossingRefusal}.
|
|
624
|
-
*
|
|
625
|
-
* Two refusals, each a separate way the two can part company:
|
|
626
|
-
*
|
|
627
|
-
* - THE LEG ON SCREEN NAMES A CROSSING. A caller building a swap transaction
|
|
628
|
-
* while the reader is looking at a two-chain crossing would sign the wrong
|
|
629
|
-
* kind of thing for what is on screen.
|
|
630
|
-
* - THE SWAP DOES NOT EXECUTE ON THE CHAIN THE READER IS LOOKING AT. A stale
|
|
631
|
-
* candidate built for a chain the address bar has since left.
|
|
632
|
-
*
|
|
633
|
-
* @param signedLeg - what the surface believes this signature does, or null
|
|
634
|
-
* when no surface composed it
|
|
635
|
-
* @param chainId - the chain the candidate swap transaction actually executes on
|
|
636
|
-
* @returns the reason to refuse, or null when the two agree
|
|
637
|
-
*/
|
|
638
311
|
export const swapRefusal = ({ signedLeg, chainId, }) => {
|
|
639
|
-
// `undefined` treated as `null`, matching `crossingRefusal`'s own guard: the
|
|
640
|
-
// field is required by the type, so only a test double or a crash inside the
|
|
641
|
-
// cascade could omit it.
|
|
642
312
|
if (signedLeg === null || signedLeg === undefined) {
|
|
643
313
|
return null;
|
|
644
314
|
}
|
|
@@ -653,42 +323,12 @@ export const swapRefusal = ({ signedLeg, chainId, }) => {
|
|
|
653
323
|
}
|
|
654
324
|
return null;
|
|
655
325
|
};
|
|
656
|
-
/**
|
|
657
|
-
* Throws when the leg on screen and the candidate swap transaction describe
|
|
658
|
-
* different journeys. The swap-side sibling of {@link assertCrossingAgrees} —
|
|
659
|
-
* loud where {@link swapRefusal} is quiet, for the same reason: this runs one
|
|
660
|
-
* step before the wallet, where silence is what lets a reader sign.
|
|
661
|
-
*
|
|
662
|
-
* @param signedLeg - what the surface believes this signature does, or null
|
|
663
|
-
* @param chainId - the chain the candidate swap transaction actually executes on
|
|
664
|
-
* @throws when the two describe different journeys
|
|
665
|
-
*/
|
|
666
326
|
export const assertSwapAgrees = ({ signedLeg, chainId, }) => {
|
|
667
327
|
const refusal = swapRefusal({ signedLeg, chainId });
|
|
668
328
|
if (refusal !== null) {
|
|
669
329
|
throw new Error(refusal);
|
|
670
330
|
}
|
|
671
331
|
};
|
|
672
|
-
/**
|
|
673
|
-
* Why a candidate must not be signed for the leg and section a caller is
|
|
674
|
-
* about to build calldata for, or null when they agree. The candidate-pick
|
|
675
|
-
* sibling of {@link crossingRefusal}/{@link swapRefusal}.
|
|
676
|
-
*
|
|
677
|
-
* UNLIKE THOSE TWO, A MISSING PICK IS ITSELF A REFUSAL. `crossingRefusal` and
|
|
678
|
-
* `swapRefusal` let a null leg through because some calls compose no screen at
|
|
679
|
-
* all (the aggregator's own executor call). A candidate-signing sender always
|
|
680
|
-
* has a screen — the route the reader picked — so a candidate id with no
|
|
681
|
-
* recorded leg is exactly the gap this type exists to close: `candidateId`
|
|
682
|
-
* alone used to be treated as sufficient identity, and this function is what
|
|
683
|
-
* stops it from being treated that way again.
|
|
684
|
-
*
|
|
685
|
-
* @param pick - what the route recorded it picked, or null/undefined when the
|
|
686
|
-
* producer that built the route never set one
|
|
687
|
-
* @param leg - the leg the caller is about to build calldata for
|
|
688
|
-
* @param sectionIndex - the route section the caller is about to build
|
|
689
|
-
* calldata for
|
|
690
|
-
* @returns the reason to refuse, or null when they agree
|
|
691
|
-
*/
|
|
692
332
|
export const candidatePickRefusal = ({ pick, leg, sectionIndex, }) => {
|
|
693
333
|
if (pick === null || pick === undefined) {
|
|
694
334
|
return `Refusing to sign a ${leg} at section ${sectionIndex}: the route named no candidate to sign.`;
|
|
@@ -701,62 +341,13 @@ export const candidatePickRefusal = ({ pick, leg, sectionIndex, }) => {
|
|
|
701
341
|
}
|
|
702
342
|
return null;
|
|
703
343
|
};
|
|
704
|
-
/**
|
|
705
|
-
* Throws when a candidate pick and the leg/section a caller is about to build
|
|
706
|
-
* calldata for describe different signatures. The candidate-pick sibling of
|
|
707
|
-
* {@link assertCrossingAgrees}/{@link assertSwapAgrees} — loud where {@link
|
|
708
|
-
* candidatePickRefusal} is quiet, for the same reason: this runs one step
|
|
709
|
-
* before the wallet, where silence is what lets a reader sign the wrong thing.
|
|
710
|
-
*
|
|
711
|
-
* @param pick - what the route recorded it picked, or null
|
|
712
|
-
* @param leg - the leg the caller is about to build calldata for
|
|
713
|
-
* @param sectionIndex - the route section the caller is about to build
|
|
714
|
-
* calldata for
|
|
715
|
-
* @throws when the pick and the leg/section being built describe different
|
|
716
|
-
* signatures
|
|
717
|
-
*/
|
|
718
344
|
export const assertCandidatePickAgrees = ({ pick, leg, sectionIndex, }) => {
|
|
719
345
|
const refusal = candidatePickRefusal({ pick, leg, sectionIndex });
|
|
720
346
|
if (refusal !== null) {
|
|
721
347
|
throw new Error(refusal);
|
|
722
348
|
}
|
|
723
349
|
};
|
|
724
|
-
/**
|
|
725
|
-
* Calculates the same-chain PulseX swap transaction inputs, or null when the
|
|
726
|
-
* inputs cannot form a call — including when the leg on screen and the swap's
|
|
727
|
-
* own chain disagree. The swap-side sibling of {@link transactionInputs}.
|
|
728
|
-
*
|
|
729
|
-
* SAME SHAPE AS `transactionInputs`, deliberately: `{ to, value, data } | null`,
|
|
730
|
-
* so a caller can dispatch either builder's result through one `sendTransaction`
|
|
731
|
-
* without a second shape to handle.
|
|
732
|
-
*
|
|
733
|
-
* WRAPPING AND UNWRAPPING THE NATIVE COIN USE THE ROUTER'S OWN NATIVE-COIN
|
|
734
|
-
* FUNCTIONS, not a separate deposit/withdraw step — one router contract wraps
|
|
735
|
-
* on the way in (`swapExactETHForTokens`) and unwraps on the way out
|
|
736
|
-
* (`swapExactTokensForETH`), the same contract `swapExactTokensForTokens`
|
|
737
|
-
* already targets when neither side is native.
|
|
738
|
-
*
|
|
739
|
-
* @param signedLeg - what the surface believes this signature does, or null
|
|
740
|
-
* @param chainId - the chain the swap actually executes on
|
|
741
|
-
* @param routerAddress - the PulseX router this swap is sent to, or null when
|
|
742
|
-
* none is deployed for this chain
|
|
743
|
-
* @param fromTokenAddress - the input token address, or the zero address for
|
|
744
|
-
* the chain's native coin
|
|
745
|
-
* @param toTokenAddress - the output token address, or the zero address for
|
|
746
|
-
* the chain's native coin
|
|
747
|
-
* @param swapPath - the ordered swap path — for a route-search hop, the one
|
|
748
|
-
* its quote was priced along (`pulseXSwapPathForHop`),
|
|
749
|
-
* already expressed in the router's own token addresses — the wrapped-native
|
|
750
|
-
* token stands in for either native end
|
|
751
|
-
* @param amountIn - the amount to swap, in the input token's base units
|
|
752
|
-
* @param minAmountOut - the minimum acceptable output after slippage, in the
|
|
753
|
-
* output token's base units
|
|
754
|
-
* @param recipient - the address the swap delivers to
|
|
755
|
-
* @param deadline - the unix-seconds deadline the router enforces
|
|
756
|
-
* @returns the transaction inputs, or null when the inputs cannot form a call
|
|
757
|
-
*/
|
|
758
350
|
export const pulseXSwapTransactionInputs = ({ signedLeg, chainId, routerAddress, fromTokenAddress, toTokenAddress, swapPath, amountIn, minAmountOut, recipient, deadline, }) => {
|
|
759
|
-
// FIRST, BEFORE ANY ENCODING — see `transactionInputs`'s identical note.
|
|
760
351
|
if (swapRefusal({ signedLeg, chainId }) !== null) {
|
|
761
352
|
return null;
|
|
762
353
|
}
|
|
@@ -774,7 +365,6 @@ export const pulseXSwapTransactionInputs = ({ signedLeg, chainId, routerAddress,
|
|
|
774
365
|
}
|
|
775
366
|
const fromIsNative = fromTokenAddress === zeroAddress;
|
|
776
367
|
const toIsNative = toTokenAddress === zeroAddress;
|
|
777
|
-
// Native-to-native names no real swap — there is nothing for the router to do.
|
|
778
368
|
if (fromIsNative && toIsNative) {
|
|
779
369
|
return null;
|
|
780
370
|
}
|
|
@@ -810,50 +400,26 @@ export const pulseXSwapTransactionInputs = ({ signedLeg, chainId, routerAddress,
|
|
|
810
400
|
}),
|
|
811
401
|
};
|
|
812
402
|
};
|
|
813
|
-
/**
|
|
814
|
-
* Calculates the transaction inputs from the bridge pathway, asset in, recipient, account, asset link, destination data param, amount to bridge, fee director struct encoded, and should deliver
|
|
815
|
-
* @param bridgeKey - the key the pathway was resolved from, for {@link crossingRefusal}
|
|
816
|
-
* @param signedCrossing - the chain pair on screen, or null when no surface composed it
|
|
817
|
-
* @param bridgePathway - the bridge pathway to use
|
|
818
|
-
* @param assetIn - the asset in to bridge
|
|
819
|
-
* @param recipient - the recipient of the bridge
|
|
820
|
-
* @param account - the account to bridge from
|
|
821
|
-
* @param assetLink - the asset link to use
|
|
822
|
-
* @param destinationDataParam - the destination data param to use
|
|
823
|
-
* @param amountToBridge - the amount to bridge
|
|
824
|
-
* @param feeDirectorStructEncoded - the fee director struct encoded to use
|
|
825
|
-
* @param shouldDeliver - whether to deliver the tokens to the recipient
|
|
826
|
-
* @returns the transaction inputs, or null when the inputs cannot form a call —
|
|
827
|
-
* including when the pathway crosses somewhere other than the pair on screen
|
|
828
|
-
*/
|
|
829
403
|
export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, assetIn, recipient, account, assetLink, destinationDataParam, amountToBridge, feeDirectorStructEncoded, shouldDeliver, }) => {
|
|
830
|
-
// FIRST, BEFORE ANY ENCODING. Every branch below writes a real mediator call;
|
|
831
|
-
// by the time one is chosen the disagreement is already encoded.
|
|
832
404
|
if (crossingRefusal({ bridgeKey, signedCrossing }) !== null) {
|
|
833
405
|
return null;
|
|
834
406
|
}
|
|
835
407
|
if (!bridgePathway) {
|
|
836
408
|
return null;
|
|
837
409
|
}
|
|
838
|
-
// check that recipient is valid
|
|
839
410
|
if (!recipient || !isAddress(recipient) || recipient === zeroAddress) {
|
|
840
411
|
return null;
|
|
841
412
|
}
|
|
842
|
-
// check that wallet account is valid
|
|
843
413
|
if (!account || !isAddress(account) || account === zeroAddress) {
|
|
844
414
|
return null;
|
|
845
415
|
}
|
|
846
|
-
// check that asset in is valid
|
|
847
416
|
if (!assetIn) {
|
|
848
417
|
return null;
|
|
849
418
|
}
|
|
850
|
-
// check that asset link is valid
|
|
851
419
|
if (!assetLink) {
|
|
852
420
|
return null;
|
|
853
421
|
}
|
|
854
422
|
let value = 0n;
|
|
855
|
-
// we are moving "from" this side, so we need to call a function on the "from" address
|
|
856
|
-
// only relevant for the relayTokens(AndCall) pathway outside of native tokens
|
|
857
423
|
let toAddress = bridgePathway.from;
|
|
858
424
|
let data = '0x';
|
|
859
425
|
const inputIsBridgeToken = interactingWithBridgeToken({
|
|
@@ -861,11 +427,8 @@ export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, as
|
|
|
861
427
|
assetInAddress: assetIn.address,
|
|
862
428
|
});
|
|
863
429
|
if (inputIsBridgeToken) {
|
|
864
|
-
// when interacting with a bridged token, we need to call the token address directly
|
|
865
430
|
toAddress = assetIn.address;
|
|
866
431
|
value = 0n;
|
|
867
|
-
// if we want delivery of the tokens (going from home to foreign) then we need to have the foreign data param
|
|
868
|
-
// and it needs to start with the destination router
|
|
869
432
|
if (!destinationDataParam) {
|
|
870
433
|
return null;
|
|
871
434
|
}
|
|
@@ -885,7 +448,6 @@ export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, as
|
|
|
885
448
|
value = amountToBridge;
|
|
886
449
|
toAddress = bridgePathway.nativeRouter;
|
|
887
450
|
if (bridgePathway.feeManager === 'from' && shouldDeliver) {
|
|
888
|
-
// transferring native to foreign
|
|
889
451
|
if (!feeDirectorStructEncoded)
|
|
890
452
|
return null;
|
|
891
453
|
if (!bridgePathway.destinationRouter)
|
|
@@ -903,7 +465,6 @@ export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, as
|
|
|
903
465
|
});
|
|
904
466
|
}
|
|
905
467
|
else {
|
|
906
|
-
// delivery always occurs when moving from foreign to home
|
|
907
468
|
data = bridgePathway.usesExtraParam
|
|
908
469
|
? encodeFunctionData({
|
|
909
470
|
abi: abis.nativeRouterExtraInput,
|
|
@@ -918,7 +479,6 @@ export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, as
|
|
|
918
479
|
}
|
|
919
480
|
}
|
|
920
481
|
else {
|
|
921
|
-
// tokens native to this side, entering the bridge
|
|
922
482
|
if (shouldDeliver && bridgePathway.requiresDelivery) {
|
|
923
483
|
if (!feeDirectorStructEncoded)
|
|
924
484
|
return null;
|
|
@@ -967,26 +527,11 @@ export const transactionInputs = ({ bridgeKey, signedCrossing, bridgePathway, as
|
|
|
967
527
|
data,
|
|
968
528
|
};
|
|
969
529
|
};
|
|
970
|
-
/**
|
|
971
|
-
* Calculates the asset out key from the bridge key path, asset in address, and unwrap
|
|
972
|
-
* @param bridgeKeyPath - the bridge key path
|
|
973
|
-
* @param assetInAddress - the asset in address
|
|
974
|
-
* @param unwrap - whether to unwrap
|
|
975
|
-
* @returns the asset out key
|
|
976
|
-
*/
|
|
977
530
|
export const assetOutKey = ({ bridgeKeyPath, assetInAddress, unwrap, }) => {
|
|
978
531
|
if (!bridgeKeyPath || !assetInAddress)
|
|
979
532
|
return null;
|
|
980
533
|
return `${bridgeKeyPath}/${unwrap ? 'native' : 'erc20'}/${assetInAddress.toLowerCase()}`;
|
|
981
534
|
};
|
|
982
|
-
/**
|
|
983
|
-
* Returns the asset out from the asset in address, assets out, bridge key path, and unwrap
|
|
984
|
-
* @param assetInAddress - the asset in address
|
|
985
|
-
* @param assetsOut - the assets out
|
|
986
|
-
* @param bridgeKeyPath - the bridge key path
|
|
987
|
-
* @param unwrap - whether to unwrap
|
|
988
|
-
* @returns the asset out
|
|
989
|
-
*/
|
|
990
535
|
export const assetOut = ({ assetInAddress, assetsOut, bridgeKeyPath, unwrap, }) => {
|
|
991
536
|
if (!assetInAddress)
|
|
992
537
|
return null;
|