@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.
- package/dist/constants/tokens.d.ts +2 -0
- package/dist/constants/types.d.ts +7 -0
- package/dist/fixtures/index.d.ts +10 -0
- package/dist/providers/BnbMappingProvider.d.ts +2 -2
- package/dist/providers/MappingProvider.d.ts +2 -2
- package/dist/token-list-bridge-utils.cjs.development.js +3445 -863
- package/dist/token-list-bridge-utils.cjs.development.js.map +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -1
- package/dist/token-list-bridge-utils.esm.js +3445 -863
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/constants/tokens.ts +16 -0
- package/src/constants/types.ts +7 -0
- package/src/fixtures/index.ts +42 -0
- package/src/index.test.ts +18 -1
- package/src/local_mappings/bnb.json +3436 -857
- package/src/providers/BnbMappingProvider.ts +3 -3
- package/src/providers/MappingProvider.ts +6 -2
- package/src/providers/index.ts +20 -2
|
@@ -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<
|
|
8
|
-
const tokens = bnbmappings as
|
|
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 {
|
|
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
|
}
|
package/src/providers/index.ts
CHANGED
|
@@ -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]:
|
|
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]:
|
|
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 {
|