@gibs/bridge-sdk 1.7.1 → 1.7.3

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.
@@ -1,12 +1,41 @@
1
+ /**
2
+ * Sets the image root for the bridge
3
+ * @param root - the root
4
+ */
1
5
  export declare const setImageRoot: (root: string) => void;
6
+ /**
7
+ * Returns the image root for the bridge
8
+ * @returns the image root
9
+ */
2
10
  export declare const getImageRoot: () => string;
11
+ /** The minimal token info */
3
12
  interface MinimalTokenInfo {
4
13
  chainId: number;
5
14
  address: string;
6
15
  logoURI?: string | null;
7
16
  }
17
+ /**
18
+ * Returns the list image for the given path
19
+ * @param path - the path
20
+ * @returns the list image
21
+ */
8
22
  export declare const list: (path: string) => string;
23
+ /**
24
+ * Returns the network image for the given chain id
25
+ * @param chainId - the chain id
26
+ * @returns the network image
27
+ */
9
28
  export declare const network: (chainId: number) => string;
29
+ /**
30
+ * Returns the image url for the given token info
31
+ * @param t - the token info
32
+ * @returns the image url
33
+ */
10
34
  export declare const image: (t: MinimalTokenInfo) => string;
35
+ /**
36
+ * Returns a url that will lookup all sources for the given array
37
+ * @param sources - the sources
38
+ * @returns the images
39
+ */
11
40
  export declare const images: (sources: string[]) => string;
12
41
  export {};
@@ -1,17 +1,45 @@
1
1
  import { getAddress } from 'viem';
2
2
  let imageRoot = 'https://gib.show';
3
+ /**
4
+ * Sets the image root for the bridge
5
+ * @param root - the root
6
+ */
3
7
  export const setImageRoot = (root) => {
4
8
  imageRoot = root;
5
9
  };
10
+ /**
11
+ * Returns the image root for the bridge
12
+ * @returns the image root
13
+ */
6
14
  export const getImageRoot = () => imageRoot;
15
+ /**
16
+ * Returns the list image for the given path
17
+ * @param path - the path
18
+ * @returns the list image
19
+ */
7
20
  export const list = (path) => {
8
21
  return `${imageRoot}/list${path}`;
9
22
  };
23
+ /**
24
+ * Returns the network image for the given chain id
25
+ * @param chainId - the chain id
26
+ * @returns the network image
27
+ */
10
28
  export const network = (chainId) => {
11
29
  if (!chainId) {
12
30
  console.trace('network image');
13
31
  }
14
32
  return `${imageRoot}/image/${Number(chainId)}`;
15
33
  };
34
+ /**
35
+ * Returns the image url for the given token info
36
+ * @param t - the token info
37
+ * @returns the image url
38
+ */
16
39
  export const image = (t) => t.logoURI || `${network(t.chainId)}/${getAddress(t.address)}`;
40
+ /**
41
+ * Returns a url that will lookup all sources for the given array
42
+ * @param sources - the sources
43
+ * @returns the images
44
+ */
17
45
  export const images = (sources) => `${imageRoot}/image/?${sources.map((s) => `i=${s}`).join('&')}`;
@@ -5,3 +5,4 @@ export * from './chains.js';
5
5
  export * from './types.js';
6
6
  export * from './image-links.js';
7
7
  export * from './fee-type.js';
8
+ export * from './settings.js';
package/dist/src/index.js CHANGED
@@ -5,3 +5,4 @@ export * from './chains.js';
5
5
  export * from './types.js';
6
6
  export * from './image-links.js';
7
7
  export * from './fee-type.js';
8
+ export * from './settings.js';
@@ -0,0 +1,341 @@
1
+ import { type Hex } from "viem";
2
+ import { Chains, type Pathway } from "./config.js";
3
+ import { FeeType } from "./fee-type.js";
4
+ import type { BridgeKey, Token } from "./types.js";
5
+ import type { TokenBridgeInfo } from "./chain-info.js";
6
+ export declare const oneEther: bigint;
7
+ export declare const basisPoints = 10000n;
8
+ /**
9
+ * Returns the bridge pathway (configuration) for a given bridge key, asset in, and whether to use the production pathway
10
+ * @param bridgeKey - the bridge key to use
11
+ * @param isProd - whether to use the production pathway
12
+ * @param assetIn - the asset in to bridge
13
+ * @returns the bridge pathway
14
+ */
15
+ export declare const bridgePathway: ({ bridgeKey, isProd, assetIn, }: {
16
+ bridgeKey: BridgeKey;
17
+ isProd: boolean;
18
+ assetIn: Token | null;
19
+ }) => Pathway | null;
20
+ /**
21
+ * Retrieves the amount to bridge from the amount and asset in. If either of them is nil, returns 0n
22
+ * @param amountIn - the amount to bridge
23
+ * @param assetIn - the asset in to bridge
24
+ * @returns the amount to bridge
25
+ */
26
+ export declare const amountToBridge: ({ amountIn, assetIn, }: {
27
+ amountIn: bigint | null;
28
+ assetIn: Token | null;
29
+ }) => bigint;
30
+ /**
31
+ * Calculates the bridge cost from the amount to bridge and bridge fee
32
+ * @param amountToBridge - the amount to bridge
33
+ * @param bridgeFee - the bridge fee
34
+ * @returns the bridge cost
35
+ */
36
+ export declare const bridgeCost: ({ amountToBridge, bridgeFee, }: {
37
+ amountToBridge: bigint;
38
+ bridgeFee: bigint | null;
39
+ }) => bigint | null;
40
+ /**
41
+ * Calculates the amount after bridge fee from the amount to bridge and bridge cost
42
+ * @param amountToBridge - the amount to bridge
43
+ * @param bridgeCost - the bridge cost
44
+ * @returns the amount after bridge fee
45
+ */
46
+ export declare const amountAfterBridgeFee: ({ amountToBridge, bridgeCost, }: {
47
+ amountToBridge: bigint;
48
+ bridgeCost: bigint | null;
49
+ }) => bigint | null;
50
+ /**
51
+ * Calculates the estimated amount out from the amount after bridge fee and fee
52
+ * @param amountAfterBridgeFee - the amount after bridge fee
53
+ * @param fee - the fee
54
+ * @returns the estimated amount out
55
+ */
56
+ export declare const estimatedAmountOut: ({ amountAfterBridgeFee, fee, }: {
57
+ amountAfterBridgeFee: bigint | null;
58
+ fee: bigint | null;
59
+ }) => bigint | null;
60
+ /**
61
+ * Calculates the estimated fee from the amount after bridge fee, fee, percent fee, fee type, limit, and whether to deliver the costs
62
+ * @param amountAfterBridgeFee - the amount after bridge fee
63
+ * @param fee - the fee
64
+ * @param percentFee - the percent fee
65
+ * @param feeType - the fee type
66
+ * @param limit - the limit
67
+ * @param costsToDeliver - whether to deliver the costs
68
+ * @returns the estimated fee
69
+ */
70
+ export declare const estimatedFee: ({ amountAfterBridgeFee, fee, percentFee, feeType, limit, costsToDeliver, }: {
71
+ amountAfterBridgeFee: bigint | null;
72
+ fee: bigint;
73
+ percentFee: bigint;
74
+ feeType: FeeType;
75
+ limit: bigint | null;
76
+ costsToDeliver: boolean;
77
+ }) => bigint | null;
78
+ /**
79
+ * Calculates the estimated native network cost from the estimated gas and latest base fee per gas
80
+ * @param estimatedGas - the estimated gas
81
+ * @param latestBaseFeePerGas - the latest base fee per gas
82
+ * @param requiresDelivery - whether to deliver the costs
83
+ * @returns the estimated native network cost
84
+ */
85
+ export declare const estimatedNativeNetworkCost: ({ estimatedGas, latestBaseFeePerGas, requiresDelivery, }: {
86
+ estimatedGas: bigint | null;
87
+ latestBaseFeePerGas: bigint | null;
88
+ requiresDelivery: boolean;
89
+ }) => bigint | null;
90
+ /**
91
+ * Calculates the estimated token network cost from the estimated native
92
+ * network cost, price corrective, decimals, and one token int
93
+ * @param estimatedNativeNetworkCost - the estimated native network cost
94
+ * @param priceCorrective - the price corrective
95
+ * @param decimals - the decimals
96
+ * @param oneTokenInt - the one token int
97
+ * @returns the estimated token network cost
98
+ */
99
+ export declare const estimatedTokenNetworkCost: ({ estimatedNativeNetworkCost, priceCorrective, decimals, oneTokenInt, }: {
100
+ estimatedNativeNetworkCost: bigint | null;
101
+ priceCorrective: bigint | null;
102
+ decimals: number | null;
103
+ oneTokenInt: bigint | null;
104
+ }) => bigint | null;
105
+ /**
106
+ * Calculates one token of the asset in as an int
107
+ * @param assetIn - the asset in to bridge
108
+ * @returns the one token int
109
+ */
110
+ export declare const oneTokenInt: ({ assetIn, }: {
111
+ assetIn: Token | null;
112
+ }) => bigint;
113
+ /**
114
+ * Returns the limit as a bigint. Nil uses 0n
115
+ * @param lim - the limit
116
+ * @returns the limit
117
+ */
118
+ export declare const limit: (lim: bigint | null) => bigint;
119
+ /**
120
+ * Returns the network switch asset out address from the asset out, unwrap, and to chain
121
+ * @param assetOut - the asset out
122
+ * @param unwrap - whether to unwrap
123
+ * @param toChain - the chain to switch to
124
+ * @returns the network switch asset out address
125
+ */
126
+ export declare const networkSwitchAssetOutAddress: ({ assetOut, unwrap, toChain, }: {
127
+ assetOut: Token | null;
128
+ unwrap: boolean;
129
+ toChain: Chains;
130
+ }) => string | null;
131
+ /**
132
+ * Calculates the desired excess compensation basis points from the path, asset in, asset out, bridge key, fee type, list, and asset out address
133
+ * @param path - the path
134
+ * @param assetIn - the asset in to bridge
135
+ * @param assetOut - the asset out
136
+ * @param bridgeKey - the bridge key
137
+ * @param feeType - the fee type
138
+ * @param list - the list
139
+ * @param assetOutAddress - the asset out address
140
+ * @returns the desired excess compensation basis points
141
+ */
142
+ export declare const desiredExcessCompensationBasisPoints: ({ path, assetIn, assetOut, bridgeKey, feeType, list, assetOutAddress, }: {
143
+ path: Pathway | null;
144
+ assetIn: Token | null;
145
+ assetOut: Token | null;
146
+ bridgeKey: BridgeKey;
147
+ feeType: FeeType;
148
+ list: Set<string>;
149
+ assetOutAddress: string | null;
150
+ }) => 0n | 10000n | 1000n | 5000n;
151
+ /**
152
+ * Calculates the estimated cost from the should deliver, amount after bridge fee, percent fee,
153
+ * estimated token network cost, reasonable percent on top of gas fee, and fee type
154
+ * @param shouldDeliver - whether to deliver the costs
155
+ * @param amountAfterBridgeFee - the amount after bridge fee
156
+ * @param percentFee - the percent fee
157
+ * @param estimatedTokenNetworkCost - the estimated token network cost
158
+ * @param reasonablePercentOnTopOfGasFee - the reasonable percent on top of gas fee
159
+ * @param feeType - the fee type
160
+ * @returns the estimated cost
161
+ */
162
+ export declare const estimatedCost: ({ shouldDeliver, amountAfterBridgeFee, percentFee, estimatedTokenNetworkCost, reasonablePercentOnTopOfGasFee, feeType, }: {
163
+ shouldDeliver: boolean;
164
+ amountAfterBridgeFee: bigint | null;
165
+ percentFee: bigint | null;
166
+ estimatedTokenNetworkCost: bigint | null;
167
+ reasonablePercentOnTopOfGasFee: bigint | null;
168
+ feeType: FeeType;
169
+ }) => bigint | null;
170
+ /**
171
+ * Calculates the reasonable fixed fee from the estimated token network cost and desired excess compensation basis points
172
+ * @param estimatedTokenNetworkCost - the estimated token network cost
173
+ * @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
174
+ * @returns the reasonable fixed fee
175
+ */
176
+ export declare const reasonableFixedFee: ({ estimatedTokenNetworkCost, desiredExcessCompensationBasisPoints, }: {
177
+ estimatedTokenNetworkCost: bigint | null;
178
+ desiredExcessCompensationBasisPoints: bigint;
179
+ }) => bigint | null;
180
+ /**
181
+ * Calculates the reasonable percent on gas limit from the gas tip fee and estimated token network cost
182
+ * @param gasTipFee - the gas tip fee
183
+ * @param estimatedTokenNetworkCost - the estimated token network cost
184
+ * @returns the reasonable percent on gas limit
185
+ */
186
+ export declare const reasonablePercentOnGasLimit: ({ gasTipFee, estimatedTokenNetworkCost, }: {
187
+ gasTipFee: bigint | null;
188
+ estimatedTokenNetworkCost: bigint | null;
189
+ }) => bigint;
190
+ /**
191
+ * Calculates the reasonable percent fee from the reasonable fixed fee and amount after bridge fee
192
+ * @param reasonableFixedFee - the reasonable fixed fee
193
+ * @param amountAfterBridgeFee - the amount after bridge fee
194
+ * @returns the reasonable percent fee
195
+ */
196
+ export declare const reasonablePercentFee: ({ reasonableFixedFee, amountAfterBridgeFee, }: {
197
+ reasonableFixedFee: bigint | null;
198
+ amountAfterBridgeFee: bigint | null;
199
+ }) => bigint | null;
200
+ /**
201
+ * Returns whether the asset in address is interacting with a bridge token
202
+ * @param assetLink - the asset link
203
+ * @param assetInAddress - the asset in address
204
+ * @returns whether the asset in address is interacting with a bridge token
205
+ */
206
+ export declare const interactingWithBridgeToken: ({ assetLink, assetInAddress, }: {
207
+ assetLink: TokenBridgeInfo | null;
208
+ assetInAddress: string | null;
209
+ }) => boolean;
210
+ /**
211
+ * 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
212
+ * @param recipient - the recipient
213
+ * @param bridgePathway - the bridge pathway
214
+ * @param feeType - the fee type
215
+ * @param priceCorrective - the price corrective
216
+ * @param gasTipFee - the gas tip fee
217
+ * @param percentFee - the percent fee
218
+ * @param feeTypeSettings - the fee type settings
219
+ * @param limit - the limit
220
+ * @param assetOut - the asset out
221
+ * @returns the fee director struct encoded
222
+ */
223
+ export declare const feeDirectorStructEncoded: ({ recipient, bridgePathway, feeType, priceCorrective, gasTipFee, percentFee, feeTypeSettings, limit, assetOut, }: {
224
+ recipient: Hex | null;
225
+ feeType: FeeType;
226
+ priceCorrective: bigint | null;
227
+ gasTipFee: bigint | null;
228
+ percentFee: bigint | null;
229
+ feeTypeSettings: bigint;
230
+ limit: bigint;
231
+ bridgePathway: Pathway | null;
232
+ assetOut: Token | null;
233
+ }) => `0x${string}` | null;
234
+ /**
235
+ * Calculates the destination data param from the recipient, bridge pathway, asset in, destination router, fee director struct encoded, asset link, should deliver, and unwrap
236
+ * @param recipient - the recipient
237
+ * @param bridgePathway - the bridge pathway
238
+ * @param assetIn - the asset in to bridge
239
+ * @param destinationRouter - the destination router
240
+ * @param feeDirectorStructEncoded - the fee director struct encoded
241
+ * @param assetLink - the asset link
242
+ * @param shouldDeliver - whether to deliver the costs
243
+ * @param unwrap - whether to unwrap
244
+ * @returns the destination data param
245
+ */
246
+ export declare const destinationDataParam: ({ recipient, bridgePathway, assetIn, destinationRouter, feeDirectorStructEncoded, assetLink, shouldDeliver, unwrap, }: {
247
+ recipient: Hex | null;
248
+ bridgePathway: Pathway | null;
249
+ assetIn: Token | null;
250
+ destinationRouter: Hex | null;
251
+ feeDirectorStructEncoded: Hex | null;
252
+ assetLink: TokenBridgeInfo | null;
253
+ shouldDeliver: boolean;
254
+ unwrap: boolean;
255
+ }) => `0x${string}` | null;
256
+ /**
257
+ * Converts a desired excess compensation basis point value into a percentage as an integer, with the denominator assumed to be 1e18
258
+ * @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
259
+ * @returns the reasonable percent on top of gas fee
260
+ */
261
+ export declare const reasonablePercentOnTopOfGasFee: ({ desiredExcessCompensationBasisPoints, }: {
262
+ desiredExcessCompensationBasisPoints: bigint;
263
+ }) => bigint;
264
+ /**
265
+ * Calculates the desired compensation ratio from the desired excess compensation basis points
266
+ * @param desiredExcessCompensationBasisPoints - the desired excess compensation basis points
267
+ * @returns the desired compensation ratio
268
+ */
269
+ export declare const desiredCompensationRatio: ({ desiredExcessCompensationBasisPoints, }: {
270
+ desiredExcessCompensationBasisPoints: bigint;
271
+ }) => bigint;
272
+ /**
273
+ * Calculates the available compensation maximum from the amount after bridge fee, percent fee, fee type, fixed fee, and limit
274
+ * @param amountAfterBridgeFee - the amount after bridge fee
275
+ * @param percentFee - the percent fee
276
+ * @param feeType - the fee type
277
+ * @param fixedFee - the fixed fee
278
+ * @param limit - the limit
279
+ * @returns the available compensation maximum
280
+ */
281
+ export declare const availableCompensationMaximum: ({ amountAfterBridgeFee, percentFee, feeType, fixedFee, limit, }: {
282
+ amountAfterBridgeFee: bigint | null;
283
+ percentFee: bigint | null;
284
+ feeType: FeeType;
285
+ fixedFee: bigint | null;
286
+ limit: bigint;
287
+ }) => bigint | null;
288
+ /**
289
+ * 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
290
+ * @param bridgePathway - the bridge pathway to use
291
+ * @param assetIn - the asset in to bridge
292
+ * @param recipient - the recipient of the bridge
293
+ * @param account - the account to bridge from
294
+ * @param assetLink - the asset link to use
295
+ * @param destinationDataParam - the destination data param to use
296
+ * @param amountToBridge - the amount to bridge
297
+ * @param feeDirectorStructEncoded - the fee director struct encoded to use
298
+ * @param shouldDeliver - whether to deliver the tokens to the recipient
299
+ * @returns the transaction inputs
300
+ */
301
+ export declare const transactionInputs: ({ bridgePathway, assetIn, recipient, account, assetLink, destinationDataParam, amountToBridge, feeDirectorStructEncoded, shouldDeliver, }: {
302
+ bridgePathway: Pathway | null;
303
+ assetIn: Token | null;
304
+ recipient: Hex | null;
305
+ account: Hex | null;
306
+ assetLink: TokenBridgeInfo | null;
307
+ destinationDataParam: Hex | null;
308
+ amountToBridge: bigint;
309
+ feeDirectorStructEncoded: Hex | null;
310
+ shouldDeliver: boolean;
311
+ }) => {
312
+ to: `0x${string}`;
313
+ value: bigint;
314
+ data: `0x${string}`;
315
+ } | null;
316
+ /**
317
+ * Calculates the asset out key from the bridge key path, asset in address, and unwrap
318
+ * @param bridgeKeyPath - the bridge key path
319
+ * @param assetInAddress - the asset in address
320
+ * @param unwrap - whether to unwrap
321
+ * @returns the asset out key
322
+ */
323
+ export declare const assetOutKey: ({ bridgeKeyPath, assetInAddress, unwrap, }: {
324
+ bridgeKeyPath: string;
325
+ assetInAddress?: Hex | null;
326
+ unwrap: boolean;
327
+ }) => string | null;
328
+ /**
329
+ * Returns the asset out from the asset in address, assets out, bridge key path, and unwrap
330
+ * @param assetInAddress - the asset in address
331
+ * @param assetsOut - the assets out
332
+ * @param bridgeKeyPath - the bridge key path
333
+ * @param unwrap - whether to unwrap
334
+ * @returns the asset out
335
+ */
336
+ export declare const assetOut: ({ assetInAddress, assetsOut, bridgeKeyPath, unwrap, }: {
337
+ assetInAddress: Hex | null;
338
+ assetsOut: Map<string, Token>;
339
+ bridgeKeyPath: string;
340
+ unwrap: boolean;
341
+ }) => Token | null;