@gibs/bridge-sdk 1.6.36 → 1.7.2

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,6 +1,5 @@
1
- import { zeroAddress } from "viem";
1
+ import { getAddress, zeroAddress } from "viem";
2
2
  import _ from 'lodash';
3
- import * as imageLinks from '@gibs/bridge-sdk/image-links';
4
3
  /**
5
4
  * Add here your chain id as hex, be sure to add your chain in the chainsMetadata object too
6
5
  */
@@ -14,14 +13,27 @@ export var Chains;
14
13
  Chains["V4PLS"] = "0x3af";
15
14
  // TBNB = '0x61',
16
15
  })(Chains || (Chains = {}));
16
+ /** A map of chain ids to chain keys */
17
17
  export const chainIdToKey = new Map(Object.entries(Chains).map(([key, chain]) => [chain, key]));
18
+ /**
19
+ * Converts a chain id to a chain key
20
+ * @param chainId - the chain id
21
+ * @returns the chain key
22
+ */
18
23
  export const toChain = (chainId) => `0x${Number(chainId).toString(16)}`;
24
+ /**
25
+ * Converts a chain id to a chain key
26
+ * @param chainId - the chain id
27
+ * @returns the chain key
28
+ */
19
29
  export const toChainKey = (chainId) => chainIdToKey.get(toChain(chainId));
30
+ /** The provider of an omnibridge */
20
31
  export var Provider;
21
32
  (function (Provider) {
22
33
  Provider["PULSECHAIN"] = "pulsechain";
23
34
  Provider["TOKENSEX"] = "tokensex";
24
35
  })(Provider || (Provider = {}));
36
+ /** A map of chains to native asset out addresses */
25
37
  export const nativeAssetOut = {
26
38
  [Chains.ETH]: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
27
39
  [Chains.BNB]: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
@@ -29,6 +41,11 @@ export const nativeAssetOut = {
29
41
  [Chains.SEP]: '0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9',
30
42
  [Chains.V4PLS]: '0x70499adEBB11Efd915E3b69E700c331778628707',
31
43
  };
44
+ /** A map of chains to deprecated native asset out addresses */
45
+ export const deprecatedNativeAssetOut = {
46
+ [Chains.PLS]: new Set(['0x97Ac4a2439A47c07ad535bb1188c989dae755341']),
47
+ };
48
+ /** A map of chains to uni v2 router addresses */
32
49
  export const uniV2Routers = {
33
50
  [Chains.PLS]: [
34
51
  '0x98bf93ebf5c380C0e6Ae8e192A7e2AE08edAcc02',
@@ -42,6 +59,7 @@ export const uniV2Routers = {
42
59
  '0x636f6407B90661b73b1C0F7e24F4C79f624d0738',
43
60
  ],
44
61
  };
62
+ /** A map of chains to native token symbols */
45
63
  export const nativeTokenSymbol = {
46
64
  [Chains.PLS]: 'PLS',
47
65
  [Chains.V4PLS]: 'V4PLS',
@@ -49,6 +67,7 @@ export const nativeTokenSymbol = {
49
67
  [Chains.SEP]: 'sepETH',
50
68
  [Chains.BNB]: 'BNB',
51
69
  };
70
+ /** A map of chains to native token names */
52
71
  export const nativeTokenName = {
53
72
  [Chains.PLS]: 'Pulse',
54
73
  [Chains.V4PLS]: 'V4 Pulse',
@@ -56,6 +75,13 @@ export const nativeTokenName = {
56
75
  [Chains.SEP]: 'Sepolia Ether',
57
76
  [Chains.BNB]: 'BNB',
58
77
  };
78
+ /** The settings for the pulsechain pls eth pathway */
79
+ const pulsechainPLSETHSettings = {
80
+ from: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
81
+ to: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
82
+ destinationRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
83
+ nativeRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
84
+ };
59
85
  export const pathways = {
60
86
  [Provider.PULSECHAIN]: {
61
87
  [Chains.PLS]: {
@@ -69,20 +95,11 @@ export const pathways = {
69
95
  feeManager: 'from',
70
96
  toHome: false,
71
97
  requiresDelivery: true,
72
- defaultAssetIn: {
73
- symbol: 'WETH',
74
- name: 'Wrapped Ether from Ethereum',
75
- address: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
76
- decimals: 18,
77
- chainId: 369,
78
- logoURI: imageLinks.network(369),
79
- extensions: {
80
- bridgeInfo: {
81
- '1': {
82
- tokenAddress: nativeAssetOut[Chains.ETH],
83
- },
84
- },
85
- },
98
+ // weth from ethereum on pulsechain
99
+ bridgedNativeAssetOut: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
100
+ settingOverrides: {
101
+ [zeroAddress]: pulsechainPLSETHSettings,
102
+ [getAddress(nativeAssetOut[Chains.PLS])]: pulsechainPLSETHSettings,
86
103
  },
87
104
  },
88
105
  },
@@ -97,19 +114,14 @@ export const pathways = {
97
114
  usesExtraParam: false,
98
115
  toHome: true,
99
116
  requiresDelivery: false,
100
- defaultAssetIn: {
101
- chainId: 1,
102
- address: nativeAssetOut[Chains.ETH],
103
- name: 'Wrapped Ether',
104
- symbol: 'WETH',
105
- decimals: 18,
106
- logoURI: imageLinks.network(1),
107
- extensions: {
108
- bridgeInfo: {
109
- '369': {
110
- tokenAddress: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
111
- },
112
- },
117
+ // wpls from pulsechain on ethereum
118
+ bridgedNativeAssetOut: '0xA882606494D86804B5514E07e6Bd2D6a6eE6d68A',
119
+ settingOverrides: {
120
+ [getAddress('0xa882606494d86804b5514e07e6bd2d6a6ee6d68a')]: {
121
+ from: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
122
+ to: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
123
+ destinationRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
124
+ nativeRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
113
125
  },
114
126
  },
115
127
  },
@@ -127,21 +139,8 @@ export const pathways = {
127
139
  usesExtraParam: true,
128
140
  toHome: false,
129
141
  requiresDelivery: true,
130
- defaultAssetIn: {
131
- symbol: 'WBNB',
132
- name: 'Wrapped BNB',
133
- address: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
134
- decimals: 18,
135
- chainId: 369,
136
- logoURI: imageLinks.network(369),
137
- extensions: {
138
- bridgeInfo: {
139
- '56': {
140
- tokenAddress: nativeAssetOut[Chains.BNB],
141
- },
142
- },
143
- },
144
- },
142
+ // wbnb from bsc on pulsechain (tokensex)
143
+ bridgedNativeAssetOut: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
145
144
  },
146
145
  },
147
146
  [Chains.BNB]: {
@@ -155,21 +154,8 @@ export const pathways = {
155
154
  usesExtraParam: true,
156
155
  toHome: true,
157
156
  requiresDelivery: false,
158
- defaultAssetIn: {
159
- chainId: 56,
160
- address: nativeAssetOut[Chains.BNB],
161
- name: 'Wrapped BNB from BSC',
162
- symbol: 'WBNB',
163
- decimals: 18,
164
- logoURI: imageLinks.network(56),
165
- extensions: {
166
- bridgeInfo: {
167
- '369': {
168
- tokenAddress: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
169
- },
170
- },
171
- },
172
- },
157
+ // wpls from pulsechain on bsc (tokensex)
158
+ bridgedNativeAssetOut: '0xF6088134D28eeBEF7128BA41FaDb2FCA0666c64C',
173
159
  },
174
160
  },
175
161
  },
@@ -210,21 +196,7 @@ export const testnetPathways = {
210
196
  requiresDelivery: true,
211
197
  toHome: false,
212
198
  feeManager: 'from',
213
- defaultAssetIn: {
214
- chainId: 943,
215
- address: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
216
- name: 'Wrapped Ether from Sepolia',
217
- symbol: 'WsepETH',
218
- decimals: 18,
219
- logoURI: imageLinks.network(943),
220
- extensions: {
221
- bridgeInfo: {
222
- '11155111': {
223
- tokenAddress: nativeAssetOut[Chains.SEP],
224
- },
225
- },
226
- },
227
- },
199
+ bridgedNativeAssetOut: '0x3677bd78ccf4d299328ecfba61790cf8dbfcf686',
228
200
  },
229
201
  },
230
202
  [Chains.SEP]: {
@@ -238,39 +210,36 @@ export const testnetPathways = {
238
210
  requiresDelivery: false,
239
211
  toHome: true,
240
212
  feeManager: 'to',
241
- defaultAssetIn: {
242
- chainId: 11_155_111,
243
- address: nativeAssetOut[Chains.SEP],
244
- name: 'Wrapped Ether',
245
- symbol: 'sepWETH',
246
- decimals: 18,
247
- logoURI: imageLinks.network(11_155_111),
248
- extensions: {
249
- bridgeInfo: {
250
- '943': {
251
- tokenAddress: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
252
- },
253
- },
254
- },
255
- },
213
+ bridgedNativeAssetOut: '0x35807560aD0597E23F452cdc82D4Fb0e7E3c6590',
256
214
  },
257
215
  },
258
216
  },
259
217
  };
218
+ /** The mainnet bridge keys */
260
219
  const mainnetBridgeKeys = [
261
220
  [Provider.PULSECHAIN, Chains.PLS, Chains.ETH],
262
221
  [Provider.PULSECHAIN, Chains.ETH, Chains.PLS],
263
222
  [Provider.TOKENSEX, Chains.PLS, Chains.BNB],
264
223
  [Provider.TOKENSEX, Chains.BNB, Chains.PLS],
265
224
  ];
225
+ /** The testnet bridge keys */
266
226
  const testnetBridgeKeys = [
267
227
  [Provider.PULSECHAIN, Chains.SEP, Chains.V4PLS],
268
228
  [Provider.PULSECHAIN, Chains.V4PLS, Chains.SEP],
269
229
  ];
230
+ /** Returns the valid bridge keys for the given is prod */
270
231
  export const validBridgeKeys = (isProd) => [
271
232
  ...mainnetBridgeKeys,
272
233
  ...(isProd ? [] : testnetBridgeKeys),
273
234
  ];
235
+ /**
236
+ * Infers the bridge key from the current key, provider, from chain, and to chain
237
+ * @param currentKey - the current bridge key
238
+ * @param provider - the provider
239
+ * @param fromChain - the from chain
240
+ * @param toChain - the to chain
241
+ * @returns the inferred bridge key
242
+ */
274
243
  export const inferBridgeKey = ({ currentKey, provider, fromChain, toChain, }) => {
275
244
  const [, fromChainKey, toChainKey] = currentKey;
276
245
  const from = fromChain ?? fromChainKey;
@@ -285,29 +254,79 @@ export const inferBridgeKey = ({ currentKey, provider, fromChain, toChain, }) =>
285
254
  : Object.keys(pathways[provider][nextFromChain])[0];
286
255
  return [provider, nextFromChain, nextToChain];
287
256
  };
288
- export const pathway = (bridgeKey, isProd) => {
257
+ /**
258
+ * Returns the pathway for the given bridge key, is prod, and asset in address
259
+ * @param bridgeKey - the bridge key
260
+ * @param isProd - whether to use the production pathway
261
+ * @param assetInAddress - the asset in address
262
+ * @returns the pathway
263
+ */
264
+ export const pathway = (bridgeKey, isProd, assetInAddress) => {
289
265
  if (!bridgeKey)
290
266
  return;
291
- return _.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined);
267
+ let pathway = _.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined);
268
+ if (assetInAddress) {
269
+ const addr = getAddress(assetInAddress);
270
+ if (pathway?.settingOverrides?.[addr]) {
271
+ pathway = {
272
+ ...pathway,
273
+ ...pathway.settingOverrides[addr],
274
+ };
275
+ }
276
+ }
277
+ return pathway;
292
278
  };
279
+ /**
280
+ * Returns the default asset in for the given bridge key and is prod
281
+ * @param bridgeKey - the bridge key
282
+ * @param isProd - whether to use the production pathway
283
+ * @returns the default asset in
284
+ */
293
285
  export const defaultAssetIn = ($bridgeKey, isProd) => {
286
+ if (!$bridgeKey)
287
+ return null;
294
288
  const conf = pathway($bridgeKey, isProd);
295
- const defaultAssetIn = _.get(conf, ['defaultAssetIn']);
289
+ const defaultAssetIn = _.get(conf, ['bridgedNativeAssetOut']);
296
290
  return defaultAssetIn;
297
291
  };
292
+ /**
293
+ * Returns whether the given asset is the native asset for the given bridge key
294
+ * @param asset - the asset
295
+ * @param bridgeKey - the bridge key
296
+ * @returns whether the given asset is the native asset for the given bridge key
297
+ */
298
298
  export const isNative = (asset, bridgeKey) => {
299
299
  if (!bridgeKey || !asset) {
300
300
  return false;
301
301
  }
302
- return ((asset.address === zeroAddress ||
303
- nativeAssetOut[toChain(asset.chainId)]?.toLowerCase() === asset.address?.toLowerCase()) &&
304
- !asset.name.includes(' from Pulsechain'));
302
+ const path = pathway(bridgeKey, false);
303
+ return (getAddress(asset.address) === getAddress(path.bridgedNativeAssetOut) ||
304
+ (asset.address === zeroAddress ||
305
+ nativeAssetOut[toChain(asset.chainId)]?.toLowerCase() === asset.address?.toLowerCase()) &&
306
+ !asset.name.includes(' from Pulsechain'));
305
307
  };
306
- export const isUnwrappable = (asset, bridgeKey) => {
307
- if (!bridgeKey || !asset) {
308
+ /**
309
+ * Returns whether the given asset is unwrappable for the given bridge key
310
+ * @param bridgeKey - the bridge key
311
+ * @param assetIn - the asset in
312
+ * @returns whether the given asset is unwrappable for the given bridge key
313
+ */
314
+ export const isUnwrappable = (bridgeKey, assetIn) => {
315
+ if (!bridgeKey || !assetIn) {
308
316
  return false;
309
317
  }
310
- const [, , toChain] = bridgeKey;
311
- return nativeAssetOut[toChain] === asset.extensions?.bridgeInfo?.[Number(toChain)]?.tokenAddress;
318
+ const addr = getAddress(assetIn.address);
319
+ const path = pathway(bridgeKey, false);
320
+ if (!path)
321
+ return false;
322
+ return path.bridgedNativeAssetOut === getAddress(addr);
323
+ };
324
+ /**
325
+ * Returns whether the given asset can be unwrapped for the given bridge key
326
+ * @param bridgeKey - the bridge key
327
+ * @param assetIn - the asset in
328
+ * @returns boolean
329
+ */
330
+ export const canChangeUnwrap = (bridgeKey, assetIn) => {
331
+ return !!assetIn && isUnwrappable(bridgeKey, assetIn);
312
332
  };
313
- export const canChangeUnwrap = (bridgeKey, assetIn) => !!assetIn && isUnwrappable(assetIn, bridgeKey);
@@ -1,7 +1,10 @@
1
+ /** The type of fee to use for the bridge */
1
2
  export declare enum FeeType {
2
3
  PERCENT = "%",
3
4
  GAS_TIP = "gas+%",
4
5
  FIXED = "fixed"
5
6
  }
7
+ /** The keys of the fee type */
6
8
  export type FeeTypeKeys = keyof typeof FeeType;
9
+ /** A map of fee type values to keys */
7
10
  export declare const feeTypeValToKeyMap: Map<FeeType, "PERCENT" | "GAS_TIP" | "FIXED">;
@@ -1,7 +1,9 @@
1
+ /** The type of fee to use for the bridge */
1
2
  export var FeeType;
2
3
  (function (FeeType) {
3
4
  FeeType["PERCENT"] = "%";
4
5
  FeeType["GAS_TIP"] = "gas+%";
5
6
  FeeType["FIXED"] = "fixed";
6
7
  })(FeeType || (FeeType = {}));
8
+ /** A map of fee type values to keys */
7
9
  export const feeTypeValToKeyMap = new Map(Object.keys(FeeType).map((key) => [FeeType[key], key]));
@@ -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';