@uniswap/token-list-bridge-utils 0.1.1-beta.1 → 1.0.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/README.md +102 -5
- package/dist/arbitrum/gateway.d.ts +2 -0
- package/dist/{arb-token-lists/src/lib → arbitrum}/instantiate_bridge.d.ts +3 -4
- package/dist/constants/types.d.ts +30 -0
- package/dist/fixtures/index.d.ts +9 -0
- package/dist/providers/ArbitrumMappingProvider.d.ts +7 -6
- package/dist/providers/MappingProvider.d.ts +4 -2
- package/dist/providers/OptimismMappingProvider.d.ts +5 -4
- package/dist/providers/PolygonMappingProvider.d.ts +4 -2
- package/dist/providers/index.d.ts +2 -4
- package/dist/token-list-bridge-utils.cjs.development.js +327 -906
- 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 +329 -902
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/package.json +7 -4
- package/src/.DS_Store +0 -0
- package/src/arbitrum/gateway.ts +25 -0
- package/src/{arb-token-lists/src/lib → arbitrum}/instantiate_bridge.ts +11 -15
- package/src/constants/types.ts +28 -0
- package/src/fixtures/index.ts +40 -5
- package/src/index.test.ts +60 -18
- package/src/index.ts +5 -7
- package/src/providers/ArbitrumMappingProvider.ts +31 -21
- package/src/providers/MappingProvider.ts +4 -2
- package/src/providers/OptimismMappingProvider.ts +21 -5
- package/src/providers/PolygonMappingProvider.ts +22 -114
- package/src/providers/index.ts +82 -2
- package/src/utils.ts +71 -1
- package/dist/arb-token-lists/server/app.d.ts +0 -1
- package/dist/arb-token-lists/src/lib/getClargs.d.ts +0 -8
- package/dist/arb-token-lists/src/lib/graph.d.ts +0 -2
- package/dist/arb-token-lists/src/lib/token_list_gen.d.ts +0 -23
- package/dist/arb-token-lists/src/lib/types.d.ts +0 -36
- package/dist/arb-token-lists/src/lib/utils.d.ts +0 -18
- package/dist/arb-token-lists/src/main.d.ts +0 -1
- package/src/arb-token-lists/.env.sample +0 -4
- package/src/arb-token-lists/.eslintrc.js +0 -43
- package/src/arb-token-lists/.gitignore +0 -4
- package/src/arb-token-lists/package.json +0 -40
- package/src/arb-token-lists/readme.md +0 -14
- package/src/arb-token-lists/server/app.ts +0 -21
- package/src/arb-token-lists/src/Assets/coingecko_uris.json +0 -5108
- package/src/arb-token-lists/src/Assets/logo_uris.json +0 -44
- package/src/arb-token-lists/src/WarningList/warningTokens.json +0 -290
- package/src/arb-token-lists/src/lib/getClargs.ts +0 -32
- package/src/arb-token-lists/src/lib/graph.ts +0 -116
- package/src/arb-token-lists/src/lib/token_list_gen.ts +0 -334
- package/src/arb-token-lists/src/lib/types.ts +0 -44
- package/src/arb-token-lists/src/lib/utils.ts +0 -285
- package/src/arb-token-lists/src/main.ts +0 -54
- package/src/arb-token-lists/tsconfig.json +0 -20
- package/src/arb-token-lists/update_all +0 -6
- package/src/arb-token-lists/yarn.lock +0 -4273
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TokenInfo, TokenList } from '@uniswap/token-lists'
|
|
2
|
-
import {
|
|
2
|
+
import { readFileSync, existsSync } from 'fs'
|
|
3
|
+
import axios from 'axios'
|
|
3
4
|
|
|
4
5
|
export type TokenListOrFetchableTokenList = TokenList | string
|
|
5
6
|
|
|
@@ -10,6 +11,8 @@ export function compareTokenInfos(t1: TokenInfo, t2: TokenInfo) {
|
|
|
10
11
|
return t1.chainId < t2.chainId ? -1 : 1
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
// ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/utils.ts
|
|
15
|
+
|
|
13
16
|
export async function getTokenList(
|
|
14
17
|
l1TokenListOrPathOrUrl: TokenListOrFetchableTokenList
|
|
15
18
|
): Promise<TokenList> {
|
|
@@ -19,3 +22,70 @@ export async function getTokenList(
|
|
|
19
22
|
return l1TokenListOrPathOrUrl
|
|
20
23
|
}
|
|
21
24
|
}
|
|
25
|
+
|
|
26
|
+
export const getTokenListObjFromUrl = async (url: string) => {
|
|
27
|
+
return (await axios.get(url)).data as TokenList
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const getTokenListObjFromLocalPath = async (path: string) => {
|
|
31
|
+
return JSON.parse(readFileSync(path).toString()) as TokenList
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const getTokenListObj = async (pathOrUrl: string) => {
|
|
35
|
+
const tokenList: TokenList = await (async (pathOrUrl: string) => {
|
|
36
|
+
const localFileExists = existsSync(pathOrUrl)
|
|
37
|
+
const looksLikeUrl = isValidHttpUrl(pathOrUrl)
|
|
38
|
+
if (localFileExists) {
|
|
39
|
+
return getTokenListObjFromLocalPath(pathOrUrl)
|
|
40
|
+
} else if (looksLikeUrl) {
|
|
41
|
+
return await getTokenListObjFromUrl(pathOrUrl)
|
|
42
|
+
} else {
|
|
43
|
+
throw new Error('Could not find token list')
|
|
44
|
+
}
|
|
45
|
+
})(pathOrUrl)
|
|
46
|
+
isTokenList(tokenList)
|
|
47
|
+
return tokenList
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
|
|
51
|
+
|
|
52
|
+
function isValidHttpUrl(urlString: string) {
|
|
53
|
+
let url
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
url = new URL(urlString)
|
|
57
|
+
} catch (_) {
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return url.protocol === 'http:' || url.protocol === 'https:'
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// typeguard:
|
|
65
|
+
export const isTokenList = (obj: any) => {
|
|
66
|
+
const expectedListKeys = ['name', 'timestamp', 'version', 'tokens']
|
|
67
|
+
const actualListKeys = new Set(Object.keys(obj))
|
|
68
|
+
if (!expectedListKeys.every((key) => actualListKeys.has(key))) {
|
|
69
|
+
throw new Error('tokenlist typeguard error: required list key not included')
|
|
70
|
+
}
|
|
71
|
+
const { version, tokens } = obj
|
|
72
|
+
if (
|
|
73
|
+
!['major', 'minor', 'patch'].every((key) => {
|
|
74
|
+
return typeof version[key] === 'number'
|
|
75
|
+
})
|
|
76
|
+
) {
|
|
77
|
+
throw new Error('tokenlist typeguard error: invalid version')
|
|
78
|
+
}
|
|
79
|
+
if (
|
|
80
|
+
!tokens.every((token: any) => {
|
|
81
|
+
const tokenKeys = new Set(Object.keys(token))
|
|
82
|
+
return ['chainId', 'address', 'name', 'decimals', 'symbol'].every(
|
|
83
|
+
(key) => {
|
|
84
|
+
return tokenKeys.has(key)
|
|
85
|
+
}
|
|
86
|
+
)
|
|
87
|
+
})
|
|
88
|
+
) {
|
|
89
|
+
throw new Error('tokenlist typeguard error: token missing required key')
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TokenList } from '@uniswap/token-lists';
|
|
2
|
-
import { ArbTokenList, EtherscanList } from './types';
|
|
3
|
-
export interface ArbificationOptions {
|
|
4
|
-
overwriteCurrentList: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface L2ToL1GatewayAddresses {
|
|
7
|
-
[contractAddress: string]: string;
|
|
8
|
-
}
|
|
9
|
-
export declare const generateTokenList: (l1TokenList: TokenList, prevArbTokenList?: ArbTokenList | undefined, options?: {
|
|
10
|
-
/**
|
|
11
|
-
* Append all tokens from the original l1TokenList to the output list.
|
|
12
|
-
*/
|
|
13
|
-
includeAllL1Tokens?: boolean | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Append all unbridged tokens from original l1TokenList to the output list.
|
|
16
|
-
*/
|
|
17
|
-
includeUnbridgedL1Tokens?: boolean | undefined;
|
|
18
|
-
getAllTokensInNetwork?: boolean | undefined;
|
|
19
|
-
} | undefined) => Promise<ArbTokenList>;
|
|
20
|
-
export declare const arbifyL1List: (pathOrUrl: string) => Promise<void>;
|
|
21
|
-
export declare const updateArbifiedList: (pathOrUrl: string) => Promise<void>;
|
|
22
|
-
export declare const updateLogoURIs: (path: string) => Promise<void>;
|
|
23
|
-
export declare const arbListtoEtherscanList: (arbList: ArbTokenList) => EtherscanList;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { TokenInfo, TokenList } from '@uniswap/token-lists';
|
|
2
|
-
export interface ArbTokenInfo extends Omit<TokenInfo, 'extensions'> {
|
|
3
|
-
extensions?: {
|
|
4
|
-
bridgeInfo: {
|
|
5
|
-
[destinationChainID: string]: {
|
|
6
|
-
tokenAddress: string;
|
|
7
|
-
originBridgeAddress: string;
|
|
8
|
-
destBridgeAddress: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export interface ArbTokenList extends Omit<TokenList, 'tokens'> {
|
|
14
|
-
tokens: ArbTokenInfo[];
|
|
15
|
-
}
|
|
16
|
-
export interface EtherscanToken {
|
|
17
|
-
l1Address: string | null;
|
|
18
|
-
l2Address: string;
|
|
19
|
-
l1GatewayAddress: string | null;
|
|
20
|
-
l2GatewayAddress: string | null;
|
|
21
|
-
}
|
|
22
|
-
export declare type EtherscanList = EtherscanToken[];
|
|
23
|
-
export interface GraphTokenResult {
|
|
24
|
-
l2Address: string | null;
|
|
25
|
-
joinTableEntry: [
|
|
26
|
-
{
|
|
27
|
-
gateway: {
|
|
28
|
-
gatewayAddr: string;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
];
|
|
32
|
-
l1TokenAddr: string;
|
|
33
|
-
}
|
|
34
|
-
export interface GraphTokensResult {
|
|
35
|
-
tokens: GraphTokenResult[];
|
|
36
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { TokenList } from '@uniswap/token-lists';
|
|
2
|
-
import { MultiCaller } from 'arb-ts';
|
|
3
|
-
import { ArbTokenList } from './types';
|
|
4
|
-
export declare const listNameToFileName: (name: string) => string;
|
|
5
|
-
export declare const listNameToArbifiedListName: (name: string) => string;
|
|
6
|
-
export declare const getL2TokenAddressesFromL1: (l1TokenAddresses: string[], multiCaller: MultiCaller, l1GatewayRouterAddress: string) => Promise<(string | undefined)[]>;
|
|
7
|
-
export declare const getL2TokenAddressesFromL2: (l1TokenAddresses: string[], multiCaller: MultiCaller, l2GatewayRouterAddress: string) => Promise<(string | undefined)[]>;
|
|
8
|
-
export declare const getLogoUri: (l1TokenAddress: string) => Promise<string | undefined>;
|
|
9
|
-
export declare const getTokenListObjFromUrl: (url: string) => Promise<TokenList>;
|
|
10
|
-
export declare const getTokenListObjFromLocalPath: (path: string) => Promise<TokenList>;
|
|
11
|
-
export declare const tokenListIsValid: (tokenList: ArbTokenList | TokenList) => boolean;
|
|
12
|
-
export declare const validateTokenListWithErrorThrowing: (tokenList: ArbTokenList | TokenList) => boolean;
|
|
13
|
-
export declare const removeInvalidTokensFromList: (tokenList: ArbTokenList | TokenList) => ArbTokenList | TokenList;
|
|
14
|
-
export declare const getTokenListObj: (pathOrUrl: string) => Promise<TokenList>;
|
|
15
|
-
export declare const isArbTokenList: (obj: any) => void;
|
|
16
|
-
export declare const isTokenList: (obj: any) => void;
|
|
17
|
-
export declare const sanitizeString: (str: string) => string;
|
|
18
|
-
export declare const excludeList: string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
commonjs: true,
|
|
4
|
-
es6: true,
|
|
5
|
-
node: true,
|
|
6
|
-
},
|
|
7
|
-
plugins: ["prettier"],
|
|
8
|
-
extends: [
|
|
9
|
-
"eslint:recommended",
|
|
10
|
-
"plugin:prettier/recommended", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
|
|
11
|
-
],
|
|
12
|
-
parserOptions: {
|
|
13
|
-
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
|
|
14
|
-
sourceType: "module", // Allows for the use of imports
|
|
15
|
-
},
|
|
16
|
-
rules: {
|
|
17
|
-
"prettier/prettier": "error",
|
|
18
|
-
"no-unused-vars": "warn",
|
|
19
|
-
"prefer-const": [2, { destructuring: "all" }],
|
|
20
|
-
"object-curly-spacing": ["error", "always"],
|
|
21
|
-
},
|
|
22
|
-
overrides: [
|
|
23
|
-
{
|
|
24
|
-
files: ["*.ts", "*.tsx"],
|
|
25
|
-
parser: "@typescript-eslint/parser",
|
|
26
|
-
extends: [
|
|
27
|
-
"eslint:recommended",
|
|
28
|
-
"plugin:@typescript-eslint/recommended",
|
|
29
|
-
"plugin:prettier/recommended",
|
|
30
|
-
],
|
|
31
|
-
plugins: ["@typescript-eslint", "prettier"],
|
|
32
|
-
rules: {
|
|
33
|
-
"no-empty-pattern": "warn",
|
|
34
|
-
"prettier/prettier": ["error", { singleQuote: true }],
|
|
35
|
-
"@typescript-eslint/member-delimiter-style": ["off"],
|
|
36
|
-
"@typescript-eslint/no-explicit-any": ["warn"],
|
|
37
|
-
"@typescript-eslint/no-use-before-define": ["off"],
|
|
38
|
-
"@typescript-eslint/no-non-null-assertion": ["off"],
|
|
39
|
-
"@typescript-eslint/ban-ts-comment": ["warn"],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "arb-token-lists",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"main": "index.js",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"main": "ts-node src/main.ts",
|
|
8
|
-
"lint": "eslint .",
|
|
9
|
-
"format": "prettier './**/*.{js,json,md,ts,yml}' --write && yarn run lint --fix",
|
|
10
|
-
"update": "yarn ts-node src/main.ts --action update",
|
|
11
|
-
"arbify": "yarn ts-node src/main.ts --action arbify",
|
|
12
|
-
"fullList": "yarn ts-node src/main.ts --action full",
|
|
13
|
-
"start_server": "yarn ts-node server/app.ts"
|
|
14
|
-
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"@uniswap/token-lists": "^1.0.0-beta.27",
|
|
17
|
-
"ajv": "^8.6.3",
|
|
18
|
-
"ajv-formats": "^2.1.1",
|
|
19
|
-
"arb-ts": "2.0.0-beta.10",
|
|
20
|
-
"axios": "^0.23.0",
|
|
21
|
-
"better-ajv-errors": "^1.1.2",
|
|
22
|
-
"eslint-config-prettier": "^8.3.0",
|
|
23
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
24
|
-
"express": "^4.17.1",
|
|
25
|
-
"graphql": "^15.6.1",
|
|
26
|
-
"graphql-request": "^3.6.1",
|
|
27
|
-
"prettier": "^2.4.1",
|
|
28
|
-
"ts-node": "^10.3.0",
|
|
29
|
-
"typescript": "^4.4.4",
|
|
30
|
-
"yargs": "^17.2.1"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@types/express": "^4.17.13",
|
|
34
|
-
"@types/node": "^16.11.1",
|
|
35
|
-
"@types/yargs": "^17.0.4",
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^5.1.0",
|
|
37
|
-
"@typescript-eslint/parser": "^5.1.0",
|
|
38
|
-
"eslint": "^8.0.1"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
### Setup
|
|
2
|
-
From root:
|
|
3
|
-
|
|
4
|
-
1. `cp .env.sample .env`
|
|
5
|
-
2. In `.env`, set `MAINNET_RPC` var (i.e., set infura key or use different endpoint)
|
|
6
|
-
3. `yarn install`
|
|
7
|
-
|
|
8
|
-
### Arbify an L1 Token Lost
|
|
9
|
-
|
|
10
|
-
yarn arbify --tokenList https://gateway.ipfs.io/ipns/tokens.uniswap.org
|
|
11
|
-
|
|
12
|
-
### Generate Full List
|
|
13
|
-
|
|
14
|
-
`yarn fullList`
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
const app = express();
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
import { readFileSync } from 'fs'
|
|
5
|
-
dotenv.config();
|
|
6
|
-
const port = process.env.PORT || 8080
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
app.get( "/", ( req, res ) => {
|
|
10
|
-
res.send( "ping" );
|
|
11
|
-
} );
|
|
12
|
-
|
|
13
|
-
app.get("/all_tokens", (req, res)=>{
|
|
14
|
-
const tokenData = readFileSync("./src/FullList/all_tokens.json")
|
|
15
|
-
|
|
16
|
-
res.send(JSON.parse(tokenData.toString()))
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
app.listen( port, () => {
|
|
20
|
-
console.log( `server started at port ${ port }` );
|
|
21
|
-
} );
|