@lifi/data-types 1.0.0-alpha.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.
Files changed (39) hide show
  1. package/LICENSE.md +201 -0
  2. package/README.md +31 -0
  3. package/dist/chains/index.d.ts +2 -0
  4. package/dist/chains/index.js +2 -0
  5. package/dist/chains/supportedChains.d.ts +6 -0
  6. package/dist/chains/supportedChains.js +1174 -0
  7. package/dist/chains/supportedChains.unit.spec.d.ts +1 -0
  8. package/dist/chains/supportedChains.unit.spec.js +79 -0
  9. package/dist/chains/utils.d.ts +1 -0
  10. package/dist/chains/utils.js +4 -0
  11. package/dist/cjs/chains/index.d.ts +2 -0
  12. package/dist/cjs/chains/index.js +18 -0
  13. package/dist/cjs/chains/supportedChains.d.ts +6 -0
  14. package/dist/cjs/chains/supportedChains.js +1179 -0
  15. package/dist/cjs/chains/supportedChains.unit.spec.d.ts +1 -0
  16. package/dist/cjs/chains/supportedChains.unit.spec.js +81 -0
  17. package/dist/cjs/chains/utils.d.ts +1 -0
  18. package/dist/cjs/chains/utils.js +8 -0
  19. package/dist/cjs/coins/coins.d.ts +26 -0
  20. package/dist/cjs/coins/coins.int.spec.d.ts +1 -0
  21. package/dist/cjs/coins/coins.int.spec.js +31 -0
  22. package/dist/cjs/coins/coins.js +1842 -0
  23. package/dist/cjs/coins/index.d.ts +1 -0
  24. package/dist/cjs/coins/index.js +17 -0
  25. package/dist/cjs/index.d.ts +3 -0
  26. package/dist/cjs/index.js +19 -0
  27. package/dist/cjs/multicall.d.ts +3 -0
  28. package/dist/cjs/multicall.js +79 -0
  29. package/dist/coins/coins.d.ts +26 -0
  30. package/dist/coins/coins.int.spec.d.ts +1 -0
  31. package/dist/coins/coins.int.spec.js +29 -0
  32. package/dist/coins/coins.js +1835 -0
  33. package/dist/coins/index.d.ts +1 -0
  34. package/dist/coins/index.js +1 -0
  35. package/dist/index.d.ts +3 -0
  36. package/dist/index.js +3 -0
  37. package/dist/multicall.d.ts +3 -0
  38. package/dist/multicall.js +76 -0
  39. package/package.json +90 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const types_1 = require("@lifi/types");
4
+ const coins_1 = require("../coins");
5
+ const supportedChains_1 = require("./supportedChains");
6
+ const utils_1 = require("./utils");
7
+ test('getChainById', () => {
8
+ expect((0, supportedChains_1.getChainById)(types_1.ChainId.ETH)).toBeDefined();
9
+ });
10
+ test('getChainByKey', () => {
11
+ expect((0, supportedChains_1.getChainByKey)(types_1.ChainKey.ETH)).toBeDefined();
12
+ });
13
+ test('native token defined for all chains', () => {
14
+ // currently unused chains
15
+ const ignoredChains = [
16
+ types_1.ChainId.FSN,
17
+ types_1.ChainId.EXP,
18
+ types_1.ChainId.TCH,
19
+ types_1.ChainId.UBQ,
20
+ types_1.ChainId.MET,
21
+ types_1.ChainId.DIO,
22
+ types_1.ChainId.TLO,
23
+ types_1.ChainId.SHI,
24
+ types_1.ChainId.GL1,
25
+ types_1.ChainId.RSK,
26
+ types_1.ChainId.TBW,
27
+ types_1.ChainId.METT,
28
+ types_1.ChainId.DIOT,
29
+ types_1.ChainId.HECT,
30
+ types_1.ChainId.FUST,
31
+ types_1.ChainId.TLOT,
32
+ types_1.ChainId.RSKT,
33
+ ];
34
+ for (const chain of supportedChains_1.supportedEVMChains) {
35
+ if (ignoredChains.includes(chain.id))
36
+ continue;
37
+ try {
38
+ const gasToken = (0, coins_1.findDefaultToken)(chain.coin, chain.id);
39
+ expect(gasToken).toBeDefined();
40
+ }
41
+ catch (e) {
42
+ throw new Error(`Failed to load gas token for ${chain.name}(${chain.id})`);
43
+ }
44
+ try {
45
+ const wrappedGasToken = (0, coins_1.findWrappedGasOnChain)(chain.id);
46
+ expect(wrappedGasToken).toBeDefined();
47
+ }
48
+ catch (e) {
49
+ throw new Error(`Failed to load wrapped gas token for ${chain.name}(${chain.id})`);
50
+ }
51
+ }
52
+ });
53
+ describe('findTokenByChainIdAndAddress', () => {
54
+ describe('token has no name override', () => {
55
+ it('returns a token with the coin name', () => {
56
+ expect((0, coins_1.findTokenByChainIdAndAddress)(types_1.ChainId.LNAT, '0xb706319d37b945727e71ae0d4353699d19112576').name).toEqual(types_1.CoinKey.CXTT);
57
+ });
58
+ });
59
+ describe('token has a name override', () => {
60
+ it('returns a token with the overrode name', () => {
61
+ expect((0, coins_1.findTokenByChainIdAndAddress)(types_1.ChainId.GOR, '0x7ea6eA49B0b0Ae9c5db7907d139D9Cd3439862a1').name).toEqual('Goerli CXTT');
62
+ });
63
+ });
64
+ });
65
+ describe('validate chains', () => {
66
+ supportedChains_1.supportedEVMChains.forEach((chain) => {
67
+ it(`validate chain ${chain.name}`, () => {
68
+ // blockExplorerUrls
69
+ expect(chain.metamask.blockExplorerUrls.length).toBeGreaterThan(0);
70
+ chain.metamask.blockExplorerUrls.forEach((blockExplorerUrl) => {
71
+ expect(blockExplorerUrl.startsWith('https://')).toBeTruthy();
72
+ expect(blockExplorerUrl.endsWith('/')).toBeTruthy();
73
+ });
74
+ const chainId = (0, utils_1.prefixChainId)(chain.id);
75
+ // chain ids match
76
+ expect(chainId).toEqual(chain.metamask.chainId);
77
+ // rpcs defined
78
+ expect(chain.metamask.rpcUrls.length).toBeGreaterThan(0);
79
+ });
80
+ });
81
+ });
@@ -0,0 +1 @@
1
+ export declare const prefixChainId: (chainId: number) => string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prefixChainId = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const prefixChainId = (chainId) => {
6
+ return '0x' + ethers_1.BigNumber.from(chainId)._hex.split('0x')[1].replace(/\b0+/g, '');
7
+ };
8
+ exports.prefixChainId = prefixChainId;
@@ -0,0 +1,26 @@
1
+ import { ChainId, Coin, CoinKey, StaticToken } from '@lifi/types';
2
+ type BasicToken = {
3
+ address: string;
4
+ decimals: number;
5
+ name?: string;
6
+ symbol?: string;
7
+ };
8
+ type BasicCoin = {
9
+ key: CoinKey;
10
+ name: string;
11
+ logoURI: string;
12
+ verified: boolean;
13
+ chains: {
14
+ [key: number]: BasicToken;
15
+ };
16
+ };
17
+ export declare const basicCoins: BasicCoin[];
18
+ export declare const defaultCoins: Array<Coin>;
19
+ export declare const wrappedTokens: {
20
+ [ChainId: string]: StaticToken;
21
+ };
22
+ export declare const findDefaultCoin: (coinKey: CoinKey) => Coin;
23
+ export declare const findDefaultToken: (coinKey: CoinKey, chainId: ChainId) => StaticToken;
24
+ export declare const findWrappedGasOnChain: (chainId: ChainId) => StaticToken;
25
+ export declare const findTokenByChainIdAndAddress: (chainId: number, tokenAddress: string) => StaticToken | null;
26
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const coins_1 = require("./coins");
13
+ jest.setTimeout(20000);
14
+ describe('Coin logo test', () => {
15
+ const allImages = [];
16
+ // default coins
17
+ allImages.push(...coins_1.defaultCoins
18
+ .map((coin) => {
19
+ const baseURL = coin.logoURI;
20
+ const tokenSpecificURLs = Object.values(coin.chains).flatMap(({ logoURI }) => (logoURI ? [logoURI] : []));
21
+ return [baseURL, ...tokenSpecificURLs];
22
+ })
23
+ .flat());
24
+ // wrapped tokens
25
+ allImages.push(...Object.values(coins_1.wrappedTokens).map((token) => token.logoURI));
26
+ test.each([...new Set(allImages)])('check that logoURI %s is valid', (image) => __awaiter(void 0, void 0, void 0, function* () {
27
+ expect(image.startsWith('https://')).toBeTruthy();
28
+ const response = yield fetch(image);
29
+ expect(response.status).toEqual(200);
30
+ }), 2000);
31
+ });