@uniswap/token-list-bridge-utils 1.2.0 → 1.3.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.
@@ -1,11 +1,11 @@
1
1
  import { MappingProvider } from './MappingProvider'
2
- import { GenericMappedTokenData } from '../constants/types'
2
+ import { BnbMappedTokenData, GenericMappedTokenData } from '../constants/types'
3
3
  import bnbmappings from '../local_mappings/bnb.json'
4
4
 
5
5
  // barring a better external source, we use a local source of mappings for bnb
6
6
  export class BnbMappingProvider implements MappingProvider {
7
- async provide(): Promise<GenericMappedTokenData> {
8
- const tokens = bnbmappings as GenericMappedTokenData
7
+ async provide(): Promise<BnbMappedTokenData> {
8
+ const tokens = bnbmappings as BnbMappedTokenData
9
9
  return tokens
10
10
  }
11
11
  }
@@ -1,7 +1,11 @@
1
- import { GenericMappedTokenData, PolygonMappedTokenData } from '../constants/types'
1
+ import {
2
+ BnbMappedTokenData,
3
+ GenericMappedTokenData,
4
+ PolygonMappedTokenData,
5
+ } from '../constants/types'
2
6
 
3
7
  export interface MappingProvider {
4
8
  provide(): Promise<
5
- PolygonMappedTokenData | GenericMappedTokenData
9
+ PolygonMappedTokenData | GenericMappedTokenData | BnbMappedTokenData
6
10
  >
7
11
  }
@@ -17,6 +17,8 @@ import Web3 from 'web3'
17
17
  import {
18
18
  GenericMappedTokenData,
19
19
  PolygonMappedTokenData,
20
+ BnbMappedTokenData,
21
+ BnbMappedToken,
20
22
  } from '../constants/types'
21
23
 
22
24
  const web3 = new Web3()
@@ -44,6 +46,7 @@ export async function buildList(
44
46
  [key: number]: {
45
47
  childTokenValid: boolean
46
48
  childTokenAddress: string | undefined
49
+ decimals?: number
47
50
  }
48
51
  } = {}
49
52
  const l2MappingExtension = {
@@ -88,6 +91,9 @@ export async function buildList(
88
91
  } as unknown as TokenInfo)
89
92
  : ({
90
93
  ...l1Token,
94
+ decimals:
95
+ chainIdToChildTokenDetailsMap[chainId].decimals ??
96
+ l1Token.decimals,
91
97
  chainId: chainId,
92
98
  address:
93
99
  chainIdToChildTokenDetailsMap[chainId].childTokenAddress,
@@ -150,7 +156,10 @@ async function generateTokenMappings(
150
156
  l1TokenList: TokenList
151
157
  ) {
152
158
  const chainIdToMappingsMap: {
153
- [key: number]: PolygonMappedTokenData | GenericMappedTokenData
159
+ [key: number]:
160
+ | PolygonMappedTokenData
161
+ | GenericMappedTokenData
162
+ | BnbMappedTokenData
154
163
  } = {}
155
164
 
156
165
  for (const chainId of chainIds) {
@@ -170,11 +179,15 @@ async function getChildTokenDetails(
170
179
  l1Token: TokenInfo,
171
180
  chainId: ChainId,
172
181
  chainIdToMappingsMap: {
173
- [key: number]: PolygonMappedTokenData | GenericMappedTokenData
182
+ [key: number]:
183
+ | PolygonMappedTokenData
184
+ | GenericMappedTokenData
185
+ | BnbMappedTokenData
174
186
  }
175
187
  ): Promise<{
176
188
  childTokenValid: boolean
177
189
  childTokenAddress: string | undefined
190
+ decimals?: number | undefined
178
191
  }> {
179
192
  const existingMapping: undefined | string =
180
193
  l1Token?.extensions?.bridgeInfo?.[chainId]?.tokenAddress
@@ -193,9 +206,14 @@ async function getChildTokenDetails(
193
206
  childTokenAddress &&
194
207
  (await hasExistingTokenContract(childTokenAddress, chainId))
195
208
  )
209
+ const decimals =
210
+ chainId === ChainId.BNB
211
+ ? (childToken as BnbMappedToken).decimals
212
+ : undefined
196
213
  return {
197
214
  childTokenValid: childTokenValid,
198
215
  childTokenAddress: childTokenAddress,
216
+ decimals: decimals,
199
217
  }
200
218
  }
201
219
  return {