@gibs/bridge-sdk 1.6.36 → 1.7.1

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.6.36",
3
+ "version": "1.7.1",
4
4
  "main": "index.js",
5
5
  "access": "public",
6
6
  "type": "module",
package/src/chain-info.ts CHANGED
@@ -49,7 +49,7 @@ export const tokenBridgeInfo = async ({
49
49
  fromChainClient: PublicClient,
50
50
  toChainClient: PublicClient,
51
51
  }): Promise<null | TokenBridgeInfo> => {
52
- const bridgePathway = pathway(bridgeKey, isProd)
52
+ const bridgePathway = pathway(bridgeKey, isProd, assetIn?.address as Hex | null)
53
53
  if (!assetIn || !bridgePathway) {
54
54
  console.log('missing asset in or bridge pathway')
55
55
  return null
@@ -81,19 +81,20 @@ export const tokenBridgeInfo = async ({
81
81
  originationChainId: fromChain,
82
82
  assetInAddress: assetInAddress as Hex,
83
83
  assetOutAddress: toBridged,
84
- toForeign: {
85
- foreign: toBridged,
86
- home: assetInAddress as Hex,
84
+ toHome: {
85
+ home: toBridged,
86
+ foreign: assetInAddress as Hex,
87
87
  },
88
88
  }
89
89
  }
90
90
  if (toNative !== zeroAddress) {
91
91
  // if (notGas) console.log('toNative')
92
+ console.log('toNative', toNative)
92
93
  return {
93
94
  originationChainId: toChain,
94
95
  assetInAddress: assetInAddress as Hex,
95
96
  assetOutAddress: toNative,
96
- toHome: {
97
+ toForeign: {
97
98
  home: toNative,
98
99
  foreign: assetInAddress as Hex,
99
100
  },
@@ -102,6 +103,7 @@ export const tokenBridgeInfo = async ({
102
103
  const [fromBridged, fromNative] = fromMappings
103
104
  if (fromNative !== zeroAddress) {
104
105
  // if (notGas) console.log('fromNative')
106
+ console.log('fromNative', fromNative)
105
107
  return {
106
108
  originationChainId: toChain,
107
109
  assetInAddress: assetInAddress as Hex,
@@ -318,7 +320,7 @@ export const minBridgeAmountIn = async ({
318
320
  })
319
321
  }
320
322
  /** get the symbol of the native asset, unwrap it if it needs to be */
321
- export const nativeSymbol = (asset: { address: Hex, symbol: string, chainId: number } | null, unwrap = false) => {
323
+ export const nativeSymbol = (asset: { address: string, symbol: string, chainId: number } | null, unwrap = false) => {
322
324
  return asset ? (unwrap && asset.address === nativeAssetOut[toChain(asset.chainId)] ? asset.symbol.slice(1) : asset.symbol) : ''
323
325
  }
324
326
 
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { zeroAddress, type Hex } from "viem";
1
+ import { getAddress, zeroAddress, type Hex } from "viem";
2
2
  import _ from 'lodash'
3
3
  import * as imageLinks from '@gibs/bridge-sdk/image-links'
4
4
  import type { BridgeKey, Token, TokenOut } from "./types.js";
@@ -39,6 +39,10 @@ export const nativeAssetOut = {
39
39
  [Chains.V4PLS]: '0x70499adEBB11Efd915E3b69E700c331778628707',
40
40
  } as Record<Chains, Hex>
41
41
 
42
+ export const deprecatedNativeAssetOut = {
43
+ [Chains.PLS]: new Set(['0x97Ac4a2439A47c07ad535bb1188c989dae755341']),
44
+ } as Partial<Record<Chains, Set<Hex>>>
45
+
42
46
  export const uniV2Routers = {
43
47
  [Chains.PLS]: [
44
48
  '0x98bf93ebf5c380C0e6Ae8e192A7e2AE08edAcc02',
@@ -80,6 +84,8 @@ export type Pathway = {
80
84
  feeManager: 'from' | 'to'
81
85
  toHome: boolean
82
86
  requiresDelivery: boolean
87
+ bridgedNativeAssetOut: Hex
88
+ settingOverrides?: Record<Hex, Partial<Pathway>>
83
89
  }
84
90
 
85
91
  export type DeepPathwayConfig = Record<
@@ -87,6 +93,13 @@ export type DeepPathwayConfig = Record<
87
93
  Partial<Record<Chains, Partial<Record<Chains, Pathway>>>>
88
94
  >
89
95
 
96
+ const pulsechainPLSETHSettings = {
97
+ from: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
98
+ to: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
99
+ destinationRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
100
+ nativeRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
101
+ }
102
+
90
103
  export const pathways = {
91
104
  [Provider.PULSECHAIN]: {
92
105
  [Chains.PLS]: {
@@ -100,6 +113,12 @@ export const pathways = {
100
113
  feeManager: 'from',
101
114
  toHome: false,
102
115
  requiresDelivery: true,
116
+ // weth from ethereum on pulsechain
117
+ bridgedNativeAssetOut: '0x02DcdD04e3F455D838cd1249292C58f3B79e3C3C',
118
+ settingOverrides: {
119
+ [zeroAddress]: pulsechainPLSETHSettings,
120
+ [getAddress(nativeAssetOut[Chains.PLS])]: pulsechainPLSETHSettings,
121
+ },
103
122
  defaultAssetIn: {
104
123
  symbol: 'WETH',
105
124
  name: 'Wrapped Ether from Ethereum',
@@ -128,6 +147,16 @@ export const pathways = {
128
147
  usesExtraParam: false,
129
148
  toHome: true,
130
149
  requiresDelivery: false,
150
+ // wpls from pulsechain on ethereum
151
+ bridgedNativeAssetOut: '0xA882606494D86804B5514E07e6Bd2D6a6eE6d68A',
152
+ settingOverrides: {
153
+ [getAddress('0xa882606494d86804b5514e07e6bd2d6a6ee6d68a')]: {
154
+ from: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
155
+ to: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
156
+ destinationRouter: '0xE66877Cfe4CEc10ffBbBB3092B7001321AB5809D',
157
+ nativeRouter: '0x1F0144Ce3BDaf11944Fe0beF6444599a0500695B',
158
+ },
159
+ },
131
160
  defaultAssetIn: {
132
161
  chainId: 1,
133
162
  address: nativeAssetOut[Chains.ETH],
@@ -158,6 +187,8 @@ export const pathways = {
158
187
  usesExtraParam: true,
159
188
  toHome: false,
160
189
  requiresDelivery: true,
190
+ // wbnb from bsc on pulsechain (tokensex)
191
+ bridgedNativeAssetOut: '0x518076CCE3729eF1a3877EA3647a26e278e764FE',
161
192
  defaultAssetIn: {
162
193
  symbol: 'WBNB',
163
194
  name: 'Wrapped BNB',
@@ -186,6 +217,8 @@ export const pathways = {
186
217
  usesExtraParam: true,
187
218
  toHome: true,
188
219
  requiresDelivery: false,
220
+ // wpls from pulsechain on bsc (tokensex)
221
+ bridgedNativeAssetOut: '0xF6088134D28eeBEF7128BA41FaDb2FCA0666c64C',
189
222
  defaultAssetIn: {
190
223
  chainId: 56,
191
224
  address: nativeAssetOut[Chains.BNB],
@@ -242,6 +275,7 @@ export const testnetPathways = {
242
275
  requiresDelivery: true,
243
276
  toHome: false,
244
277
  feeManager: 'from',
278
+ bridgedNativeAssetOut: '0x3677bd78ccf4d299328ecfba61790cf8dbfcf686',
245
279
  defaultAssetIn: {
246
280
  chainId: 943,
247
281
  address: '0x3677bd78CCf4d299328ECFBa61790cf8dBfcF686',
@@ -270,6 +304,7 @@ export const testnetPathways = {
270
304
  requiresDelivery: false,
271
305
  toHome: true,
272
306
  feeManager: 'to',
307
+ bridgedNativeAssetOut: '0x35807560aD0597E23F452cdc82D4Fb0e7E3c6590',
273
308
  defaultAssetIn: {
274
309
  chainId: 11_155_111,
275
310
  address: nativeAssetOut[Chains.SEP],
@@ -332,9 +367,19 @@ export const inferBridgeKey = ({
332
367
  return [provider, nextFromChain, nextToChain] as BridgeKey
333
368
  }
334
369
 
335
- export const pathway = (bridgeKey: BridgeKey | null, isProd: boolean) => {
370
+ export const pathway = (bridgeKey: BridgeKey | null, isProd: boolean, assetInAddress?: string | Hex | null | undefined) => {
336
371
  if (!bridgeKey) return
337
- return _.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined)
372
+ let pathway = _.get(pathways, bridgeKey) || (!isProd ? _.get(testnetPathways, bridgeKey) : undefined)
373
+ if (assetInAddress) {
374
+ const addr = getAddress(assetInAddress)
375
+ if (pathway?.settingOverrides?.[addr]) {
376
+ pathway = {
377
+ ...pathway,
378
+ ...pathway.settingOverrides[addr],
379
+ }
380
+ }
381
+ }
382
+ return pathway
338
383
  }
339
384
 
340
385
  export const defaultAssetIn = ($bridgeKey: BridgeKey | null, isProd: boolean) => {
@@ -347,7 +392,9 @@ export const isNative = (asset: Token | TokenOut | null, bridgeKey: BridgeKey |
347
392
  if (!bridgeKey || !asset) {
348
393
  return false
349
394
  }
395
+ const path = pathway(bridgeKey, false)
350
396
  return (
397
+ getAddress(asset.address!) === getAddress(path!.bridgedNativeAssetOut!) ||
351
398
  (asset.address === zeroAddress ||
352
399
  nativeAssetOut[toChain(asset.chainId)]?.toLowerCase() === asset.address?.toLowerCase()) &&
353
400
  !asset.name.includes(' from Pulsechain')
@@ -355,15 +402,18 @@ export const isNative = (asset: Token | TokenOut | null, bridgeKey: BridgeKey |
355
402
  }
356
403
 
357
404
  export const isUnwrappable = (
358
- asset: Pick<Token, 'extensions'> | null,
359
405
  bridgeKey: BridgeKey | null,
406
+ assetIn: Pick<Token, 'address'> | null,
360
407
  ) => {
361
- if (!bridgeKey || !asset) {
408
+ if (!bridgeKey || !assetIn) {
362
409
  return false
363
410
  }
364
- const [, , toChain] = bridgeKey
365
- return nativeAssetOut[toChain] === asset.extensions?.bridgeInfo?.[Number(toChain)]?.tokenAddress
411
+ const addr = getAddress(assetIn.address)
412
+ const path = pathway(bridgeKey, false)
413
+ if (!path) return false
414
+ return path.bridgedNativeAssetOut === getAddress(addr)
366
415
  }
367
416
 
368
- export const canChangeUnwrap = (bridgeKey: BridgeKey, assetIn: Token | null) =>
369
- !!assetIn && isUnwrappable(assetIn, bridgeKey)
417
+ export const canChangeUnwrap = (bridgeKey: BridgeKey, assetIn: Token | null) => {
418
+ return !!assetIn && isUnwrappable(bridgeKey, assetIn)
419
+ }