@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gibs/bridge-sdk",
3
- "version": "1.7.1",
3
+ "version": "1.7.3",
4
4
  "main": "index.js",
5
5
  "access": "public",
6
6
  "type": "module",
@@ -12,7 +12,8 @@
12
12
  "./image-links": "./src/image-links.ts",
13
13
  "./chains": "./src/chains.ts",
14
14
  "./chain-info": "./src/chain-info.ts",
15
- "./fee-type": "./src/fee-type.ts"
15
+ "./fee-type": "./src/fee-type.ts",
16
+ "./settings": "./src/settings.ts"
16
17
  },
17
18
  "scripts": {
18
19
  "build": "tsc"
package/src/abis.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { parseAbi, parseAbiParameters } from 'viem'
2
2
 
3
- /** the abi for the bridge */
3
+ /** the abi for the input bridge */
4
4
  export const inputBridge = parseAbi([
5
5
  'function minPerTx(address token) external view returns(uint256)',
6
6
  'function foreignTokenAddress(address token) external view returns(address)',
@@ -11,47 +11,59 @@ export const inputBridge = parseAbi([
11
11
  'function relayTokensAndCall(address token, address _receiver, uint256 _value, bytes memory _data) external',
12
12
  'function relayTokens(address token, address _receiver, uint256 _value) external',
13
13
  ])
14
+ /** the abi for the input bridge with extra input for the sender origin (tokensex) */
14
15
  export const inputBridgeExtraInput = parseAbi([
15
16
  'function relayTokensAndCall(address token, address _receiver, uint256 _value, bytes memory _data, address _senderOrigin) external',
16
17
  'function relayTokens(address token, address _receiver, uint256 _value, address _senderOrigin) external',
17
18
  ])
19
+ /** the abi for erc677 tokens */
18
20
  export const erc677 = parseAbi([
19
21
  'function transferAndCall(address, uint256, bytes calldata) external',
20
22
  ])
23
+ /** the abi for erc677 tokens bridge with extra input for the sender origin (tokensex) */
21
24
  export const erc677ExtraInput = parseAbi([
22
25
  'function transferAndCall(address, uint256, bytes calldata, address sender) external',
23
26
  ])
27
+ /** the abi to read data from the output router */
24
28
  export const outputRouter = parseAbi([
25
29
  'function onTokenBridged(address _token, uint256 _value, bytes memory _data) external payable',
26
30
  'function WETH() external view returns(address)',
27
31
  'function bridge() external view returns(address)',
28
32
  ])
33
+ /** the abi for the output bridge */
29
34
  export const outputBridge = parseAbi(['function bridgeContract() external view returns(address)'])
35
+ /** the abi for the fee manager */
30
36
  export const feeManager = parseAbi([
31
37
  'function HOME_TO_FOREIGN_FEE() public view returns(bytes32)',
32
38
  'function FOREIGN_TO_HOME_FEE() public view returns(bytes32)',
33
39
  'function getFee(bytes32, address) public view returns(uint256)',
34
40
  ])
41
+ /** the abi for the native router */
35
42
  export const nativeRouter = parseAbi([
36
43
  'function wrapAndRelayTokens(address receiver) external payable',
37
44
  'function relayTokensAndCall(address receiver, bytes calldata data) external payable',
38
45
  ])
46
+ /** the abi for the native router with extra input for the sender origin (tokensex) */
39
47
  export const nativeRouterExtraInput = parseAbi([
40
48
  'function wrapAndRelayTokens(address receiver, address sender) external payable',
41
49
  'function relayTokensAndCall(address receiver, bytes calldata data, address sender) external payable',
42
50
  ])
51
+ /** the abi for the univ2 router */
43
52
  export const univ2Router = parseAbi([
44
53
  'function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns(uint256[] memory)',
45
54
  ])
55
+ /** the abi for the fee delivery struct */
46
56
  export const feeDeliveryStruct = parseAbiParameters('(address, uint256, uint256, uint256)')
47
-
57
+ /** the abi for the relay tokens direct */
48
58
  export const relayTokensDirect = parseAbi([
49
59
  'function safeExecuteSignaturesWithAutoGasLimit(bytes calldata data, bytes calldata signatures) external',
50
60
  ])
61
+ /** the abi for the home amb */
51
62
  export const homeAmb = parseAbi([
52
63
  'function submitSignature(bytes message, bytes signature) external',
53
64
  ])
54
65
 
66
+ /** the abi for the univ2 pair */
55
67
  export const pair = parseAbi([
56
68
  'function getReserves() view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast)',
57
69
  ])
package/src/chain-info.ts CHANGED
@@ -20,6 +20,14 @@ export type TokenBridgeInfo = {
20
20
  }
21
21
  }
22
22
 
23
+ /**
24
+ * Returns the bridged token address and native token address
25
+ * @param chainId - the chain id being targeted
26
+ * @param target - the target
27
+ * @param address - the address
28
+ * @param client - the client
29
+ * @returns the bridged token address and native token address
30
+ */
23
31
  export const links = _.memoize(
24
32
  async ({ chainId, target, address, client }: { chainId: number; target: Hex; address: Hex, client: PublicClient }) => {
25
33
  return multicallRead<Hex[]>({
@@ -36,6 +44,15 @@ export const links = _.memoize(
36
44
  ({ chainId, target, address }) => `${chainId}-${target}-${address}`.toLowerCase(),
37
45
  )
38
46
 
47
+ /**
48
+ * Returns the token bridge info for the given bridge key, asset in, is prod, from chain client, and to chain client
49
+ * @param bridgeKey - the bridge key
50
+ * @param assetIn - the asset in
51
+ * @param isProd - whether to use the production pathway
52
+ * @param fromChainClient - the from chain client
53
+ * @param toChainClient - the to chain client
54
+ * @returns the token bridge info
55
+ */
39
56
  export const tokenBridgeInfo = async ({
40
57
  bridgeKey,
41
58
  assetIn,
@@ -72,11 +89,7 @@ export const tokenBridgeInfo = async ({
72
89
  }),
73
90
  ])
74
91
  const [toBridged, toNative] = toMappings
75
- // const notGas = !Object.values(nativeAssetOut).find(
76
- // (v) => v.toLowerCase() === assetInAddress.toLowerCase(),
77
- // )
78
92
  if (toBridged !== zeroAddress) {
79
- // if (notGas) console.log('toBridged')
80
93
  return {
81
94
  originationChainId: fromChain,
82
95
  assetInAddress: assetInAddress as Hex,
@@ -88,8 +101,6 @@ export const tokenBridgeInfo = async ({
88
101
  }
89
102
  }
90
103
  if (toNative !== zeroAddress) {
91
- // if (notGas) console.log('toNative')
92
- console.log('toNative', toNative)
93
104
  return {
94
105
  originationChainId: toChain,
95
106
  assetInAddress: assetInAddress as Hex,
@@ -102,8 +113,6 @@ export const tokenBridgeInfo = async ({
102
113
  }
103
114
  const [fromBridged, fromNative] = fromMappings
104
115
  if (fromNative !== zeroAddress) {
105
- // if (notGas) console.log('fromNative')
106
- console.log('fromNative', fromNative)
107
116
  return {
108
117
  originationChainId: toChain,
109
118
  assetInAddress: assetInAddress as Hex,
@@ -115,7 +124,6 @@ export const tokenBridgeInfo = async ({
115
124
  }
116
125
  }
117
126
  if (fromBridged !== zeroAddress) {
118
- // if (notGas) console.log('fromBridged')
119
127
  return {
120
128
  originationChainId: fromChain,
121
129
  assetInAddress: assetInAddress as Hex,
@@ -146,9 +154,10 @@ export const tokenBridgeInfo = async ({
146
154
  }),
147
155
  }
148
156
  }
157
+ /** The result of reading the amount out from a router */
149
158
  export type FetchResult = bigint[] | Hex
150
159
  /**
151
- * check the prices that each router offers for the given paths
160
+ * Check the prices that each router offers for the given paths
152
161
  * @param assetInAddress the address of the asset going into the bridge
153
162
  * @param oneTokenInt the number of tokens to push into the bridge (before fees)
154
163
  * @param chain the chain of the asset going into the bridge
@@ -186,10 +195,19 @@ const readAmountOut = ({
186
195
  })
187
196
  }
188
197
 
198
+ /**
199
+ * Fetch the price corrective for the given bridge key, asset out, measurement token, from chain client, to chain client, asset link, amount in, and is prod
200
+ * @param bridgeKeyPartner - the bridge key partner
201
+ * @param assetOut - the asset out
202
+ * @param measurementToken - the measurement token
203
+ * @param fromChainClient - the from chain client
204
+ * @param toChainClient - the to chain client
205
+ * @param assetLink - the asset link
206
+ * @param amountIn - the amount in
207
+ * @param isProd - whether to use the production pathway
208
+ * @returns the price corrective
209
+ */
189
210
  export const fetchPriceCorrective = ({
190
- // bridgeKey,
191
- // assetIn,
192
- // isProd,
193
211
  bridgeKeyPartner,
194
212
  assetOut,
195
213
  measurementToken,
@@ -300,6 +318,14 @@ export const fetchPriceCorrective = ({
300
318
  }
301
319
  }
302
320
 
321
+ /**
322
+ * Fetch the minimum bridge amount in for the given asset in, pathway, from public client, and to public client
323
+ * @param assetIn - the asset in
324
+ * @param pathway - the pathway
325
+ * @param fromPublicClient - the from public client
326
+ * @param toPublicClient - the to public client
327
+ * @returns the minimum bridge amount in
328
+ */
303
329
  export const minBridgeAmountIn = async ({
304
330
  assetIn,
305
331
  pathway,
@@ -324,18 +350,24 @@ export const nativeSymbol = (asset: { address: string, symbol: string, chainId:
324
350
  return asset ? (unwrap && asset.address === nativeAssetOut[toChain(asset.chainId)] ? asset.symbol.slice(1) : asset.symbol) : ''
325
351
  }
326
352
 
353
+ /** The input for loading the bridge fees */
327
354
  export type InputLoadFeeFor = {
328
355
  pathway: Pathway
329
356
  fromChainClient: PublicClient
330
357
  toChainClient: PublicClient
331
358
  }
332
359
 
360
+ /** The fee configuration for a given pathway */
333
361
  export type PathwayExtendableConfig = {
334
362
  feeManager: Hex
335
363
  feeH2F: bigint
336
364
  feeF2H: bigint
337
365
  }
338
-
366
+ /**
367
+ * Returns the chain multicall for the given client
368
+ * @param client - the client
369
+ * @returns the chain multicall
370
+ */
339
371
  export const chainMulticall = (client: PublicClient) => {
340
372
  const chainId = client.chain!.id
341
373
  const metadata = chainsMetadata[toChain(chainId)]
@@ -345,7 +377,13 @@ export const chainMulticall = (client: PublicClient) => {
345
377
  address: metadata.contracts!.multicall3!.address,
346
378
  }) as any
347
379
  }
348
-
380
+ /**
381
+ * Load the bridge fees for the given pathway, from chain client, and to chain client
382
+ * @param pathway - the pathway
383
+ * @param fromChainClient - the from chain client
384
+ * @param toChainClient - the to chain client
385
+ * @returns the bridge fees
386
+ */
349
387
  export const loadBridgeFees = async ({ pathway, fromChainClient, toChainClient }: InputLoadFeeFor) => {
350
388
  const multicall = pathway.feeManager === 'from'
351
389
  ? chainMulticall(fromChainClient)
package/src/config.ts CHANGED
@@ -16,21 +16,35 @@ export enum Chains {
16
16
  // TBNB = '0x61',
17
17
  }
18
18
 
19
+ /** The key of a chain - human readable for query params */
19
20
  export type ChainKey = keyof typeof Chains
20
21
 
22
+ /** A map of chain ids to chain keys */
21
23
  export const chainIdToKey = new Map<Chains, ChainKey>(
22
24
  Object.entries(Chains).map(([key, chain]) => [chain, key] as [Chains, ChainKey]),
23
25
  )
24
26
 
27
+ /**
28
+ * Converts a chain id to a chain key
29
+ * @param chainId - the chain id
30
+ * @returns the chain key
31
+ */
25
32
  export const toChain = (chainId: number | string) => `0x${Number(chainId).toString(16)}` as Chains
26
33
 
34
+ /**
35
+ * Converts a chain id to a chain key
36
+ * @param chainId - the chain id
37
+ * @returns the chain key
38
+ */
27
39
  export const toChainKey = (chainId: number | string) => chainIdToKey.get(toChain(chainId))
28
40
 
41
+ /** The provider of an omnibridge */
29
42
  export enum Provider {
30
43
  PULSECHAIN = 'pulsechain',
31
44
  TOKENSEX = 'tokensex',
32
45
  }
33
46
 
47
+ /** A map of chains to native asset out addresses */
34
48
  export const nativeAssetOut = {
35
49
  [Chains.ETH]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
36
50
  [Chains.BNB]: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
@@ -39,10 +53,12 @@ export const nativeAssetOut = {
39
53
  [Chains.V4PLS]: '0x70499adEBB11Efd915E3b69E700c331778628707',
40
54
  } as Record<Chains, Hex>
41
55
 
56
+ /** A map of chains to deprecated native asset out addresses */
42
57
  export const deprecatedNativeAssetOut = {
43
58
  [Chains.PLS]: new Set(['0x97Ac4a2439A47c07ad535bb1188c989dae755341']),
44
59
  } as Partial<Record<Chains, Set<Hex>>>
45
60
 
61
+ /** A map of chains to uni v2 router addresses */
46
62
  export const uniV2Routers = {
47
63
  [Chains.PLS]: [
48
64
  '0x98bf93ebf5c380C0e6Ae8e192A7e2AE08edAcc02',
@@ -57,6 +73,7 @@ export const uniV2Routers = {
57
73
  ],
58
74
  } as Record<Chains, Hex[]>
59
75
 
76
+ /** A map of chains to native token symbols */
60
77
  export const nativeTokenSymbol = {
61
78
  [Chains.PLS]: 'PLS',
62
79
  [Chains.V4PLS]: 'V4PLS',
@@ -65,6 +82,7 @@ export const nativeTokenSymbol = {
65
82
  [Chains.BNB]: 'BNB',
66
83
  } as Record<Chains, string>
67
84
 
85
+ /** A map of chains to native token names */
68
86
  export const nativeTokenName = {
69
87
  [Chains.PLS]: 'Pulse',
70
88
  [Chains.V4PLS]: 'V4 Pulse',
@@ -73,13 +91,14 @@ export const nativeTokenName = {
73
91
  [Chains.BNB]: 'BNB',
74
92
  } as Record<Chains, string>
75
93
 
94
+ /** The pathway of a bridge */
76
95
  export type Pathway = {
77
96
  from: Hex
78
97
  to: Hex
79
98
  destinationRouter: Hex | null
80
99
  nativeRouter: Hex
81
100
  validator: Hex
82
- defaultAssetIn: Token
101
+ // defaultAssetIn: Token
83
102
  usesExtraParam: boolean
84
103
  feeManager: 'from' | 'to'
85
104
  toHome: boolean
@@ -88,11 +107,13 @@ export type Pathway = {
88
107
  settingOverrides?: Record<Hex, Partial<Pathway>>
89
108
  }
90
109
 
110
+ /** A map of providers to pathways */
91
111
  export type DeepPathwayConfig = Record<
92
112
  Provider,
93
113
  Partial<Record<Chains, Partial<Record<Chains, Pathway>>>>
94
114
  >
95
115
 
116
+ /** The settings for the pulsechain pls eth pathway */
96
117
  const pulsechainPLSETHSettings = {
97
118
  from: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
98
119
  to: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
@@ -119,21 +140,6 @@ export const pathways = {
119
140
  [zeroAddress]: pulsechainPLSETHSettings,
120
141
  [getAddress(nativeAssetOut[Chains.PLS])]: pulsechainPLSETHSettings,
121
142
  },
122
- defaultAssetIn: {
123
- symbol: 'WETH',
124
- name: 'Wrapped Ether from Ethereum',
125
- address: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
126
- decimals: 18,
127
- chainId: 369,
128
- logoURI: imageLinks.network(369),
129
- extensions: {
130
- bridgeInfo: {
131
- '1': {
132
- tokenAddress: nativeAssetOut[Chains.ETH],
133
- },
134
- },
135
- },
136
- },
137
143
  },
138
144
  },
139
145
  [Chains.ETH]: {
@@ -157,21 +163,6 @@ export const pathways = {
157
163
  nativeRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
158
164
  },
159
165
  },
160
- defaultAssetIn: {
161
- chainId: 1,
162
- address: nativeAssetOut[Chains.ETH],
163
- name: 'Wrapped Ether',
164
- symbol: 'WETH',
165
- decimals: 18,
166
- logoURI: imageLinks.network(1),
167
- extensions: {
168
- bridgeInfo: {
169
- '369': {
170
- tokenAddress: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
171
- },
172
- },
173
- },
174
- },
175
166
  },
176
167
  },
177
168
  },
@@ -189,21 +180,6 @@ export const pathways = {
189
180
  requiresDelivery: true,
190
181
  // wbnb from bsc on pulsechain (tokensex)
191
182
  bridgedNativeAssetOut: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
192
- defaultAssetIn: {
193
- symbol: 'WBNB',
194
- name: 'Wrapped BNB',
195
- address: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
196
- decimals: 18,
197
- chainId: 369,
198
- logoURI: imageLinks.network(369),
199
- extensions: {
200
- bridgeInfo: {
201
- '56': {
202
- tokenAddress: nativeAssetOut[Chains.BNB],
203
- },
204
- },
205
- },
206
- },
207
183
  },
208
184
  },
209
185
  [Chains.BNB]: {
@@ -219,21 +195,6 @@ export const pathways = {
219
195
  requiresDelivery: false,
220
196
  // wpls from pulsechain on bsc (tokensex)
221
197
  bridgedNativeAssetOut: '0xF6088134D28eeBEF7128BA41FaDb2FCA0666c64C',
222
- defaultAssetIn: {
223
- chainId: 56,
224
- address: nativeAssetOut[Chains.BNB],
225
- name: 'Wrapped BNB from BSC',
226
- symbol: 'WBNB',
227
- decimals: 18,
228
- logoURI: imageLinks.network(56),
229
- extensions: {
230
- bridgeInfo: {
231
- '369': {
232
- tokenAddress: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
233
- },
234
- },
235
- },
236
- },
237
198
  },
238
199
  },
239
200
  },
@@ -276,21 +237,6 @@ export const testnetPathways = {
276
237
  toHome: false,
277
238
  feeManager: 'from',
278
239
  bridgedNativeAssetOut: '0x3677bd78ccf4d299328ecfba61790cf8dbfcf686',
279
- defaultAssetIn: {
280
- chainId: 943,
281
- address: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
282
- name: 'Wrapped Ether from Sepolia',
283
- symbol: 'WsepETH',
284
- decimals: 18,
285
- logoURI: imageLinks.network(943),
286
- extensions: {
287
- bridgeInfo: {
288
- '11155111': {
289
- tokenAddress: nativeAssetOut[Chains.SEP],
290
- },
291
- },
292
- },
293
- },
294
240
  },
295
241
  },
296
242
  [Chains.SEP]: {
@@ -305,26 +251,12 @@ export const testnetPathways = {
305
251
  toHome: true,
306
252
  feeManager: 'to',
307
253
  bridgedNativeAssetOut: '0x35807560aD0597E23F452cdc82D4Fb0e7E3c6590',
308
- defaultAssetIn: {
309
- chainId: 11_155_111,
310
- address: nativeAssetOut[Chains.SEP],
311
- name: 'Wrapped Ether',
312
- symbol: 'sepWETH',
313
- decimals: 18,
314
- logoURI: imageLinks.network(11_155_111),
315
- extensions: {
316
- bridgeInfo: {
317
- '943': {
318
- tokenAddress: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
319
- },
320
- },
321
- },
322
- },
323
254
  },
324
255
  },
325
256
  },
326
257
  } as DeepPathwayConfig
327
258
 
259
+ /** The mainnet bridge keys */
328
260
  const mainnetBridgeKeys = [
329
261
  [Provider.PULSECHAIN, Chains.PLS, Chains.ETH],
330
262
  [Provider.PULSECHAIN, Chains.ETH, Chains.PLS],
@@ -332,16 +264,26 @@ const mainnetBridgeKeys = [
332
264
  [Provider.TOKENSEX, Chains.BNB, Chains.PLS],
333
265
  ] as BridgeKey[]
334
266
 
267
+ /** The testnet bridge keys */
335
268
  const testnetBridgeKeys = [
336
269
  [Provider.PULSECHAIN, Chains.SEP, Chains.V4PLS],
337
270
  [Provider.PULSECHAIN, Chains.V4PLS, Chains.SEP],
338
271
  ] as BridgeKey[]
339
272
 
273
+ /** Returns the valid bridge keys for the given is prod */
340
274
  export const validBridgeKeys = (isProd: boolean) => [
341
275
  ...mainnetBridgeKeys,
342
276
  ...(isProd ? [] : testnetBridgeKeys),
343
277
  ]
344
278
 
279
+ /**
280
+ * Infers the bridge key from the current key, provider, from chain, and to chain
281
+ * @param currentKey - the current bridge key
282
+ * @param provider - the provider
283
+ * @param fromChain - the from chain
284
+ * @param toChain - the to chain
285
+ * @returns the inferred bridge key
286
+ */
345
287
  export const inferBridgeKey = ({
346
288
  currentKey,
347
289
  provider,
@@ -367,6 +309,13 @@ export const inferBridgeKey = ({
367
309
  return [provider, nextFromChain, nextToChain] as BridgeKey
368
310
  }
369
311
 
312
+ /**
313
+ * Returns the pathway for the given bridge key, is prod, and asset in address
314
+ * @param bridgeKey - the bridge key
315
+ * @param isProd - whether to use the production pathway
316
+ * @param assetInAddress - the asset in address
317
+ * @returns the pathway
318
+ */
370
319
  export const pathway = (bridgeKey: BridgeKey | null, isProd: boolean, assetInAddress?: string | Hex | null | undefined) => {
371
320
  if (!bridgeKey) return
372
321
  let pathway = _.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined)
@@ -382,12 +331,25 @@ export const pathway = (bridgeKey: BridgeKey | null, isProd: boolean, assetInAdd
382
331
  return pathway
383
332
  }
384
333
 
334
+ /**
335
+ * Returns the default asset in for the given bridge key and is prod
336
+ * @param bridgeKey - the bridge key
337
+ * @param isProd - whether to use the production pathway
338
+ * @returns the default asset in
339
+ */
385
340
  export const defaultAssetIn = ($bridgeKey: BridgeKey | null, isProd: boolean) => {
341
+ if (!$bridgeKey) return null
386
342
  const conf = pathway($bridgeKey, isProd)
387
- const defaultAssetIn = _.get(conf, ['defaultAssetIn']) as Token | undefined
343
+ const defaultAssetIn = _.get(conf, ['bridgedNativeAssetOut']) as Hex | undefined
388
344
  return defaultAssetIn
389
345
  }
390
346
 
347
+ /**
348
+ * Returns whether the given asset is the native asset for the given bridge key
349
+ * @param asset - the asset
350
+ * @param bridgeKey - the bridge key
351
+ * @returns whether the given asset is the native asset for the given bridge key
352
+ */
391
353
  export const isNative = (asset: Token | TokenOut | null, bridgeKey: BridgeKey | null) => {
392
354
  if (!bridgeKey || !asset) {
393
355
  return false
@@ -401,6 +363,12 @@ export const isNative = (asset: Token | TokenOut | null, bridgeKey: BridgeKey |
401
363
  )
402
364
  }
403
365
 
366
+ /**
367
+ * Returns whether the given asset is unwrappable for the given bridge key
368
+ * @param bridgeKey - the bridge key
369
+ * @param assetIn - the asset in
370
+ * @returns whether the given asset is unwrappable for the given bridge key
371
+ */
404
372
  export const isUnwrappable = (
405
373
  bridgeKey: BridgeKey | null,
406
374
  assetIn: Pick<Token, 'address'> | null,
@@ -414,6 +382,12 @@ export const isUnwrappable = (
414
382
  return path.bridgedNativeAssetOut === getAddress(addr)
415
383
  }
416
384
 
385
+ /**
386
+ * Returns whether the given asset can be unwrapped for the given bridge key
387
+ * @param bridgeKey - the bridge key
388
+ * @param assetIn - the asset in
389
+ * @returns boolean
390
+ */
417
391
  export const canChangeUnwrap = (bridgeKey: BridgeKey, assetIn: Token | null) => {
418
392
  return !!assetIn && isUnwrappable(bridgeKey, assetIn)
419
393
  }
package/src/fee-type.ts CHANGED
@@ -1,12 +1,14 @@
1
-
1
+ /** The type of fee to use for the bridge */
2
2
  export enum FeeType {
3
3
  PERCENT = '%',
4
4
  GAS_TIP = 'gas+%',
5
5
  FIXED = 'fixed',
6
6
  }
7
7
 
8
+ /** The keys of the fee type */
8
9
  export type FeeTypeKeys = keyof typeof FeeType
9
10
 
11
+ /** A map of fee type values to keys */
10
12
  export const feeTypeValToKeyMap = new Map<FeeType, FeeTypeKeys>(
11
13
  (Object.keys(FeeType) as FeeTypeKeys[]).map((key) => [FeeType[key], key]),
12
14
  )
@@ -2,22 +2,41 @@ import { getAddress } from 'viem'
2
2
 
3
3
  let imageRoot = 'https://gib.show'
4
4
 
5
+ /**
6
+ * Sets the image root for the bridge
7
+ * @param root - the root
8
+ */
5
9
  export const setImageRoot = (root: string) => {
6
10
  imageRoot = root
7
11
  }
8
12
 
13
+ /**
14
+ * Returns the image root for the bridge
15
+ * @returns the image root
16
+ */
9
17
  export const getImageRoot = () => imageRoot
10
18
 
19
+ /** The minimal token info */
11
20
  interface MinimalTokenInfo {
12
21
  chainId: number
13
22
  address: string
14
23
  logoURI?: string | null
15
24
  }
16
25
 
26
+ /**
27
+ * Returns the list image for the given path
28
+ * @param path - the path
29
+ * @returns the list image
30
+ */
17
31
  export const list = (path: string) => {
18
32
  return `${imageRoot}/list${path}`
19
33
  }
20
34
 
35
+ /**
36
+ * Returns the network image for the given chain id
37
+ * @param chainId - the chain id
38
+ * @returns the network image
39
+ */
21
40
  export const network = (chainId: number) => {
22
41
  if (!chainId) {
23
42
  console.trace('network image')
@@ -25,8 +44,18 @@ export const network = (chainId: number) => {
25
44
  return `${imageRoot}/image/${Number(chainId)}`
26
45
  }
27
46
 
47
+ /**
48
+ * Returns the image url for the given token info
49
+ * @param t - the token info
50
+ * @returns the image url
51
+ */
28
52
  export const image = (t: MinimalTokenInfo) =>
29
53
  t.logoURI || `${network(t.chainId)}/${getAddress(t.address)}`
30
54
 
55
+ /**
56
+ * Returns a url that will lookup all sources for the given array
57
+ * @param sources - the sources
58
+ * @returns the images
59
+ */
31
60
  export const images = (sources: string[]) =>
32
61
  `${imageRoot}/image/?${sources.map((s) => `i=${s}`).join('&')}`
package/src/index.ts 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'