@uniswap/token-list-bridge-utils 0.1.1-beta.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.
Files changed (61) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +17 -0
  3. package/dist/arb-token-lists/server/app.d.ts +1 -0
  4. package/dist/arb-token-lists/src/lib/getClargs.d.ts +8 -0
  5. package/dist/arb-token-lists/src/lib/graph.d.ts +2 -0
  6. package/dist/arb-token-lists/src/lib/instantiate_bridge.d.ts +15 -0
  7. package/dist/arb-token-lists/src/lib/token_list_gen.d.ts +23 -0
  8. package/dist/arb-token-lists/src/lib/types.d.ts +36 -0
  9. package/dist/arb-token-lists/src/lib/utils.d.ts +18 -0
  10. package/dist/arb-token-lists/src/main.d.ts +1 -0
  11. package/dist/constants/chainId.d.ts +10 -0
  12. package/dist/constants/tokens.d.ts +5 -0
  13. package/dist/fixtures/index.d.ts +24 -0
  14. package/dist/index.d.ts +18 -0
  15. package/dist/index.js +8 -0
  16. package/dist/providers/ArbitrumMappingProvider.d.ts +11 -0
  17. package/dist/providers/MappingProvider.d.ts +4 -0
  18. package/dist/providers/OptimismMappingProvider.d.ts +10 -0
  19. package/dist/providers/PolygonMappingProvider.d.ts +9 -0
  20. package/dist/providers/index.d.ts +5 -0
  21. package/dist/token-list-bridge-utils.cjs.development.js +2217 -0
  22. package/dist/token-list-bridge-utils.cjs.development.js.map +1 -0
  23. package/dist/token-list-bridge-utils.cjs.production.min.js +2 -0
  24. package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -0
  25. package/dist/token-list-bridge-utils.esm.js +2201 -0
  26. package/dist/token-list-bridge-utils.esm.js.map +1 -0
  27. package/dist/utils.d.ts +4 -0
  28. package/dist/verify.d.ts +9 -0
  29. package/package.json +68 -0
  30. package/src/arb-token-lists/.env.sample +4 -0
  31. package/src/arb-token-lists/.eslintrc.js +43 -0
  32. package/src/arb-token-lists/.gitignore +4 -0
  33. package/src/arb-token-lists/package.json +40 -0
  34. package/src/arb-token-lists/readme.md +14 -0
  35. package/src/arb-token-lists/server/app.ts +21 -0
  36. package/src/arb-token-lists/src/Assets/coingecko_uris.json +5108 -0
  37. package/src/arb-token-lists/src/Assets/logo_uris.json +44 -0
  38. package/src/arb-token-lists/src/WarningList/warningTokens.json +290 -0
  39. package/src/arb-token-lists/src/lib/getClargs.ts +32 -0
  40. package/src/arb-token-lists/src/lib/graph.ts +116 -0
  41. package/src/arb-token-lists/src/lib/instantiate_bridge.ts +35 -0
  42. package/src/arb-token-lists/src/lib/token_list_gen.ts +334 -0
  43. package/src/arb-token-lists/src/lib/types.ts +44 -0
  44. package/src/arb-token-lists/src/lib/utils.ts +285 -0
  45. package/src/arb-token-lists/src/main.ts +54 -0
  46. package/src/arb-token-lists/tsconfig.json +20 -0
  47. package/src/arb-token-lists/update_all +6 -0
  48. package/src/arb-token-lists/yarn.lock +4273 -0
  49. package/src/constants/chainId.ts +13 -0
  50. package/src/constants/tokens.ts +31 -0
  51. package/src/fixtures/index.ts +104 -0
  52. package/src/index.test.ts +211 -0
  53. package/src/index.ts +92 -0
  54. package/src/providers/ArbitrumMappingProvider.ts +28 -0
  55. package/src/providers/MappingProvider.ts +5 -0
  56. package/src/providers/OptimismMappingProvider.ts +13 -0
  57. package/src/providers/PolygonMappingProvider.ts +127 -0
  58. package/src/providers/index.ts +17 -0
  59. package/src/utils.ts +21 -0
  60. package/src/verify.test.ts +19 -0
  61. package/src/verify.ts +60 -0
package/src/verify.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { TokenList } from '@uniswap/token-lists'
2
+
3
+ /**
4
+ * Verifies that for each token with extensions.bridgeInfo defined, for every
5
+ * chainId there exists a token with that chainId at the root-level of the
6
+ * token list.
7
+ *
8
+ * @returns input TokenList if valid, throws otherwise
9
+ */
10
+ export function verifyExtensions(tokenList: TokenList) {
11
+ for (const token of tokenList.tokens) {
12
+ if (!token.extensions?.bridgeInfo) continue
13
+
14
+ // if has extension, make sure that:
15
+ // 1/ other token has root-level entry
16
+ // 2/ other root entry has extension pointing to it
17
+ for (const destChainId of Object.keys(token.extensions.bridgeInfo)) {
18
+ const destTokens = tokenList.tokens.filter(
19
+ (t) =>
20
+ t.chainId === Number(destChainId) &&
21
+ t.address ===
22
+ // @ts-expect-error TokenList schema does not allow bridgeInfo objetcs yet
23
+ token.extensions.bridgeInfo[destChainId].tokenAddress
24
+ )
25
+
26
+ if (destTokens.length > 1) {
27
+ throw new Error(
28
+ `TokenList has duplicate root-level tokens for ${token.symbol} ${token.chainId}`
29
+ )
30
+ }
31
+
32
+ const destToken = destTokens[0]
33
+
34
+ if (!destToken) {
35
+ throw new Error(
36
+ `TokenList is missing root-level TokenInfo for ${token.symbol} ${token.chainId}`
37
+ )
38
+ }
39
+
40
+ // ensure destToken has an extension pointing back to this
41
+ const srcToken: { tokenAddress: string } | undefined =
42
+ // @ts-expect-error TokenList schema does not allow bridgeInfo objects yet
43
+ destToken.extensions?.bridgeInfo[token.chainId]
44
+
45
+ if (!srcToken) {
46
+ throw new Error(
47
+ `TokenList is missing root-level TokenInfo.extensions.bridgeInfo for ${token.symbol} ${token.chainId}`
48
+ )
49
+ }
50
+
51
+ if (srcToken.tokenAddress !== token.address) {
52
+ throw new Error(
53
+ `TokenList has invalid root-level TokenInfo.extensions.bridgeInfo for ${token.symbol} ${token.chainId}. Expected ${token.address} but got ${srcToken.tokenAddress}`
54
+ )
55
+ }
56
+ }
57
+ }
58
+
59
+ return tokenList
60
+ }