@gibs/bridge-sdk 1.7.3 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gibs/bridge-sdk",
3
- "version": "1.7.3",
3
+ "version": "1.9.0",
4
4
  "main": "index.js",
5
5
  "access": "public",
6
6
  "type": "module",
@@ -16,15 +16,19 @@
16
16
  "./settings": "./src/settings.ts"
17
17
  },
18
18
  "scripts": {
19
- "build": "tsc"
19
+ "build": "npx tsc"
20
20
  },
21
21
  "keywords": [],
22
22
  "author": "",
23
23
  "license": "ISC",
24
24
  "description": "",
25
+ "devDependencies": {
26
+ "@types/node": "^22.12.0",
27
+ "typescript": "~5.7.2"
28
+ },
25
29
  "dependencies": {
26
30
  "@gibs/common": "^1.0.0",
27
31
  "lodash": "^4.17.21",
28
- "viem": "^2.31.0"
32
+ "viem": "^2.37.8"
29
33
  }
30
34
  }
package/src/abis.ts CHANGED
@@ -29,6 +29,7 @@ export const outputRouter = parseAbi([
29
29
  'function onTokenBridged(address _token, uint256 _value, bytes memory _data) external payable',
30
30
  'function WETH() external view returns(address)',
31
31
  'function bridge() external view returns(address)',
32
+ 'function safeExecuteSignaturesWithAutoGasLimit(address runner,bytes calldata _data,bytes calldata _signatures) external payable',
32
33
  ])
33
34
  /** the abi for the output bridge */
34
35
  export const outputBridge = parseAbi(['function bridgeContract() external view returns(address)'])
package/src/chain-info.ts CHANGED
@@ -30,7 +30,7 @@ export type TokenBridgeInfo = {
30
30
  */
31
31
  export const links = _.memoize(
32
32
  async ({ chainId, target, address, client }: { chainId: number; target: Hex; address: Hex, client: PublicClient }) => {
33
- return multicallRead<Hex[]>({
33
+ return multicallRead<[Hex, Hex]>({
34
34
  client,
35
35
  chain: chainsMetadata[toChain(chainId)],
36
36
  abi: abis.inputBridge,
@@ -295,7 +295,7 @@ export const fetchPriceCorrective = ({
295
295
  return 0n
296
296
  }
297
297
  // the last element is the amount of the output token
298
- const last = result[result.length - 1]
298
+ const last = result[result.length - 1]!
299
299
  return (last * oneToken) / amountIn
300
300
  }
301
301
  const max = (amountsOut: (bigint | undefined)[]) => {
package/src/chains.ts CHANGED
@@ -48,7 +48,7 @@ export const chainsMetadata = {
48
48
  alt: 'a gold cube with slits in the middle of each side',
49
49
  rpcUrls: {
50
50
  default: {
51
- http: ['https://bsc-pokt.nodies.app'],
51
+ http: ['https://bsc-rpc.publicnode.com'],
52
52
  },
53
53
  },
54
54
  },
package/src/config.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { getAddress, zeroAddress, type Hex } from "viem";
1
+ import { getAddress, keccak256, stringToHex, zeroAddress, type Hex } from "viem";
2
2
  import _ from 'lodash'
3
- import * as imageLinks from '@gibs/bridge-sdk/image-links'
4
3
  import type { BridgeKey, Token, TokenOut } from "./types.js";
5
4
 
6
5
  /**
@@ -38,11 +37,19 @@ export const toChain = (chainId: number | string) => `0x${Number(chainId).toStri
38
37
  */
39
38
  export const toChainKey = (chainId: number | string) => chainIdToKey.get(toChain(chainId))
40
39
 
41
- /** The provider of an omnibridge */
42
- export enum Provider {
43
- PULSECHAIN = 'pulsechain',
44
- TOKENSEX = 'tokensex',
45
- }
40
+ // /** The provider of an omnibridge */
41
+ // export enum Provider {
42
+ // PULSECHAIN = 'pulsechain',
43
+ // TOKENSEX = 'tokensex',
44
+ // }
45
+
46
+
47
+ export const Providers = {
48
+ PULSECHAIN: 'pulsechain',
49
+ TOKENSEX: 'tokensex',
50
+ } as const
51
+
52
+ export type Provider = typeof Providers[keyof typeof Providers]
46
53
 
47
54
  /** A map of chains to native asset out addresses */
48
55
  export const nativeAssetOut = {
@@ -122,7 +129,7 @@ const pulsechainPLSETHSettings = {
122
129
  }
123
130
 
124
131
  export const pathways = {
125
- [Provider.PULSECHAIN]: {
132
+ [Providers.PULSECHAIN]: {
126
133
  [Chains.PLS]: {
127
134
  [Chains.ETH]: {
128
135
  from: '0x4fD0aaa7506f3d9cB8274bdB946Ec42A1b8751Ef',
@@ -166,7 +173,7 @@ export const pathways = {
166
173
  },
167
174
  },
168
175
  },
169
- [Provider.TOKENSEX]: {
176
+ [Providers.TOKENSEX]: {
170
177
  [Chains.PLS]: {
171
178
  [Chains.BNB]: {
172
179
  from: '0xf1DFc63e10fF01b8c3d307529b47AefaD2154C0e',
@@ -201,7 +208,7 @@ export const pathways = {
201
208
  } as DeepPathwayConfig
202
209
 
203
210
  export const testnetPathways = {
204
- [Provider.TOKENSEX]: {
211
+ [Providers.TOKENSEX]: {
205
212
  // plsv4 to bnb home omnibridge: 0xfd0c07C376D27EA0E9fA64Ac5D2481439e36CF9C
206
213
  // [Chains.BNB]: {
207
214
  // [Chains.V4PLS]: {
@@ -224,7 +231,7 @@ export const testnetPathways = {
224
231
  // },
225
232
  // },
226
233
  },
227
- [Provider.PULSECHAIN]: {
234
+ [Providers.PULSECHAIN]: {
228
235
  [Chains.V4PLS]: {
229
236
  [Chains.SEP]: {
230
237
  from: '0x6B08a50865aDeCe6e3869D9AfbB316d0a0436B6c',
@@ -258,16 +265,16 @@ export const testnetPathways = {
258
265
 
259
266
  /** The mainnet bridge keys */
260
267
  const mainnetBridgeKeys = [
261
- [Provider.PULSECHAIN, Chains.PLS, Chains.ETH],
262
- [Provider.PULSECHAIN, Chains.ETH, Chains.PLS],
263
- [Provider.TOKENSEX, Chains.PLS, Chains.BNB],
264
- [Provider.TOKENSEX, Chains.BNB, Chains.PLS],
268
+ [Providers.PULSECHAIN, Chains.PLS, Chains.ETH],
269
+ [Providers.PULSECHAIN, Chains.ETH, Chains.PLS],
270
+ [Providers.TOKENSEX, Chains.PLS, Chains.BNB],
271
+ [Providers.TOKENSEX, Chains.BNB, Chains.PLS],
265
272
  ] as BridgeKey[]
266
273
 
267
274
  /** The testnet bridge keys */
268
275
  const testnetBridgeKeys = [
269
- [Provider.PULSECHAIN, Chains.SEP, Chains.V4PLS],
270
- [Provider.PULSECHAIN, Chains.V4PLS, Chains.SEP],
276
+ [Providers.PULSECHAIN, Chains.SEP, Chains.V4PLS],
277
+ [Providers.PULSECHAIN, Chains.V4PLS, Chains.SEP],
271
278
  ] as BridgeKey[]
272
279
 
273
280
  /** Returns the valid bridge keys for the given is prod */
@@ -391,3 +398,83 @@ export const isUnwrappable = (
391
398
  export const canChangeUnwrap = (bridgeKey: BridgeKey, assetIn: Token | null) => {
392
399
  return !!assetIn && isUnwrappable(bridgeKey, assetIn)
393
400
  }
401
+
402
+ export const chains = {
403
+ ethereum: 1,
404
+ bsc: 56,
405
+ pulsechain: 369,
406
+ pulsechainV4: 943,
407
+ sepolia: 11155111,
408
+ } as const
409
+
410
+ export const chainIds = Object.values(chains)
411
+
412
+ export type ChainId = (typeof chainIds)[number]
413
+
414
+ export type Side = 'home' | 'foreign'
415
+
416
+ export type MinimalKey = `${ChainId}-${Hex}`
417
+
418
+ // export const Providers = {
419
+ // PULSECHAIN: 'pulsechain',
420
+ // TOKENSEX: 'tokensex',
421
+ // } as const
422
+
423
+ export type PathwayInfo = {
424
+ pair: string
425
+ key: string
426
+ home: Hex
427
+ foreign: Hex
428
+ }
429
+
430
+ export type ProviderHomeChainEntry = Partial<Record<ChainId, PathwayInfo[]>>
431
+
432
+ export type ProviderEntries = Partial<Record<ChainId, ProviderHomeChainEntry>>
433
+
434
+ export type BridgeConfig = Record<Provider, ProviderEntries>
435
+
436
+ // provider -> home -> foreign
437
+ export const bridgeConfigs = {
438
+ [Providers.PULSECHAIN]: {
439
+ [chains.pulsechain]: {
440
+ [chains.ethereum]: [{
441
+ pair: 'mainnet',
442
+ key: 'erc20',
443
+ home: '0x4fD0aaa7506f3d9cB8274bdB946Ec42A1b8751Ef',
444
+ foreign: '0x1715a3e4a142d8b698131108995174f37aeba10d',
445
+ }, {
446
+ pair: 'mainnet',
447
+ key: 'native',
448
+ home: '0x0e18d0d556b652794EF12Bf68B2dC857EF5f3996',
449
+ foreign: '0xe20E337DB2a00b1C37139c873B92a0AAd3F468bF',
450
+ }],
451
+ },
452
+ [chains.pulsechainV4]: {
453
+ [chains.sepolia]: [{
454
+ pair: 'v4',
455
+ key: 'erc20',
456
+ home: '0x6B08a50865aDeCe6e3869D9AfbB316d0a0436B6c',
457
+ foreign: '0x546e37DAA15cdb82fd1a717E5dEEa4AF08D4349A',
458
+ }, {
459
+ pair: 'v4',
460
+ key: 'native',
461
+ home: '0x81c10846F40fA2B173FC47958D0a892529983F50',
462
+ foreign: '0x5e238ef968467cf443ef5ecb683b76c5a04a0421',
463
+ }],
464
+ },
465
+ },
466
+ [Providers.TOKENSEX]: {
467
+ [chains.pulsechain]: {
468
+ [chains.bsc]: [{
469
+ pair: 'bsctokensex',
470
+ key: 'erc20',
471
+ home: '0xf1DFc63e10fF01b8c3d307529b47AefaD2154C0e',
472
+ foreign: '0xb4005881e81a6ecd2c1f75d58e8e41f28d59c6b1',
473
+ }],
474
+ },
475
+ },
476
+ } as BridgeConfig
477
+
478
+
479
+ export const HOME_TO_FOREIGN_FEE = keccak256(stringToHex("homeToForeignFee"))
480
+ export const FOREIGN_TO_HOME_FEE = keccak256(stringToHex("foreignToHomeFee"))