@talismn/chaindata-provider 0.1.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/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/dist/ChaindataProvider.d.ts +18 -0
- package/dist/ChaindataProvider.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugins.d.ts +17 -0
- package/dist/plugins.js +1 -0
- package/dist/types/Chain.d.ts +39 -0
- package/dist/types/Chain.js +1 -0
- package/dist/types/EvmNetwork.d.ts +32 -0
- package/dist/types/EvmNetwork.js +1 -0
- package/dist/types/MultiChain.d.ts +9 -0
- package/dist/types/MultiChain.js +1 -0
- package/dist/types/Token.d.ts +74 -0
- package/dist/types/Token.js +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +15 -0
- package/package.json +48 -0
- package/plugins/package.json +5 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @talismn/chaindata-provider
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Chain, ChainId, ChainList, EvmNetwork, EvmNetworkId, EvmNetworkList, Token, TokenId, TokenList } from "./types";
|
|
2
|
+
export interface ChaindataChainProvider {
|
|
3
|
+
chainIds(): Promise<ChainId[]>;
|
|
4
|
+
chains(): Promise<ChainList>;
|
|
5
|
+
getChain(chainId: ChainId): Promise<Chain | null>;
|
|
6
|
+
}
|
|
7
|
+
export interface ChaindataEvmNetworkProvider {
|
|
8
|
+
evmNetworkIds(): Promise<EvmNetworkId[]>;
|
|
9
|
+
evmNetworks(): Promise<EvmNetworkList>;
|
|
10
|
+
getEvmNetwork(evmNetworkId: EvmNetworkId): Promise<EvmNetwork | null>;
|
|
11
|
+
}
|
|
12
|
+
export interface ChaindataTokenProvider {
|
|
13
|
+
tokenIds(): Promise<TokenId[]>;
|
|
14
|
+
tokens(): Promise<TokenList>;
|
|
15
|
+
getToken(tokenId: TokenId): Promise<Token | null>;
|
|
16
|
+
}
|
|
17
|
+
export interface ChaindataProvider extends ChaindataChainProvider, ChaindataEvmNetworkProvider, ChaindataTokenProvider {
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `PluginTokenTypes` is a collection of plugin-provided token definitions.
|
|
3
|
+
*
|
|
4
|
+
* By hacking declaration merging (typescript magic) we can add variants to this type from within other modules.
|
|
5
|
+
*
|
|
6
|
+
* For more details on this process, see:
|
|
7
|
+
* - https://www.typescriptlang.org/docs/handbook/declaration-merging.html
|
|
8
|
+
* - https://stackoverflow.com/a/58261244/3926156
|
|
9
|
+
* - https://stackoverflow.com/a/56099769/3926156
|
|
10
|
+
* - https://stackoverflow.com/a/56516998/3926156
|
|
11
|
+
* - https://pqina.nl/blog/typescript-interface-merging-and-extending-modules/
|
|
12
|
+
*
|
|
13
|
+
* As a result, consumers of this api will have type information for the `Token` type
|
|
14
|
+
* based on the selection of plugins they are using in their app.
|
|
15
|
+
*/
|
|
16
|
+
export interface PluginTokenTypes {
|
|
17
|
+
}
|
package/dist/plugins.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EvmNetworkId } from "./EvmNetwork";
|
|
2
|
+
import { TokenId } from "./Token";
|
|
3
|
+
export declare type ChainList = Record<ChainId, Chain>;
|
|
4
|
+
export declare type ChainId = string;
|
|
5
|
+
export declare type Chain = {
|
|
6
|
+
id: ChainId;
|
|
7
|
+
isTestnet: boolean;
|
|
8
|
+
sortIndex: number | null;
|
|
9
|
+
genesisHash: string | null;
|
|
10
|
+
prefix: number | null;
|
|
11
|
+
name: string | null;
|
|
12
|
+
chainName: string;
|
|
13
|
+
implName: string | null;
|
|
14
|
+
specName: string | null;
|
|
15
|
+
specVersion: string | null;
|
|
16
|
+
nativeToken: {
|
|
17
|
+
id: TokenId;
|
|
18
|
+
} | null;
|
|
19
|
+
tokens: Array<{
|
|
20
|
+
id: TokenId;
|
|
21
|
+
}> | null;
|
|
22
|
+
account: string | null;
|
|
23
|
+
subscanUrl: string | null;
|
|
24
|
+
rpcs: Array<SubstrateRpc> | null;
|
|
25
|
+
isHealthy: boolean;
|
|
26
|
+
evmNetworks: Array<{
|
|
27
|
+
id: EvmNetworkId;
|
|
28
|
+
}>;
|
|
29
|
+
parathreads?: Chain[];
|
|
30
|
+
paraId: number | null;
|
|
31
|
+
relay?: Chain;
|
|
32
|
+
};
|
|
33
|
+
export declare type CustomChain = Chain & {
|
|
34
|
+
isCustom: true;
|
|
35
|
+
};
|
|
36
|
+
export declare type SubstrateRpc = {
|
|
37
|
+
url: string;
|
|
38
|
+
isHealthy: boolean;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ChainId } from "./Chain";
|
|
2
|
+
import { TokenId } from "./Token";
|
|
3
|
+
export declare type EvmNetworkList = Record<EvmNetworkId, EvmNetwork | CustomEvmNetwork>;
|
|
4
|
+
/** TODO: Refactor to string */
|
|
5
|
+
export declare type EvmNetworkId = number;
|
|
6
|
+
export declare type EvmNetwork = {
|
|
7
|
+
id: EvmNetworkId;
|
|
8
|
+
isTestnet: boolean;
|
|
9
|
+
sortIndex: number | null;
|
|
10
|
+
name: string | null;
|
|
11
|
+
nativeToken: {
|
|
12
|
+
id: TokenId;
|
|
13
|
+
} | null;
|
|
14
|
+
tokens: Array<{
|
|
15
|
+
id: TokenId;
|
|
16
|
+
}> | null;
|
|
17
|
+
explorerUrl: string | null;
|
|
18
|
+
rpcs: Array<EthereumRpc> | null;
|
|
19
|
+
isHealthy: boolean;
|
|
20
|
+
substrateChain: {
|
|
21
|
+
id: ChainId;
|
|
22
|
+
} | null;
|
|
23
|
+
};
|
|
24
|
+
export declare type CustomEvmNetwork = EvmNetwork & {
|
|
25
|
+
isCustom: true;
|
|
26
|
+
explorerUrls: string[];
|
|
27
|
+
iconUrls: string[];
|
|
28
|
+
};
|
|
29
|
+
export declare type EthereumRpc = {
|
|
30
|
+
url: string;
|
|
31
|
+
isHealthy: boolean;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChainId } from "./Chain";
|
|
2
|
+
import { EvmNetworkId } from "./EvmNetwork";
|
|
3
|
+
export declare type MultiChainId = SubChainId | EvmChainId;
|
|
4
|
+
export declare type SubChainId = {
|
|
5
|
+
subChainId: ChainId;
|
|
6
|
+
};
|
|
7
|
+
export declare type EvmChainId = {
|
|
8
|
+
evmChainId: EvmNetworkId;
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { PluginTokenTypes } from "../plugins";
|
|
2
|
+
import { ChainId } from "./Chain";
|
|
3
|
+
import { EvmNetworkId } from "./EvmNetwork";
|
|
4
|
+
/**
|
|
5
|
+
* `TokenTypes` is an automatically determined sub-selection of `PluginTokenTypes`.
|
|
6
|
+
*
|
|
7
|
+
* It is the same list, but with any invalid `TokenType` definitions filtered out.
|
|
8
|
+
*/
|
|
9
|
+
export declare type TokenTypes = {
|
|
10
|
+
[TokenType in keyof PluginTokenTypes]: PluginTokenTypes[TokenType] extends IToken ? PluginTokenTypes[TokenType] : never;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The `Token` sum type, which is a union of all of the possible `TokenTypes`.
|
|
14
|
+
*
|
|
15
|
+
* Each variant comes from a plugin in use by the consuming app.
|
|
16
|
+
*
|
|
17
|
+
* For example, in an app with the `substrate-native`, `evm-native`, `substrate-orml` and `evm-erc20` plugins:
|
|
18
|
+
*
|
|
19
|
+
* type Token = SubNativeToken | EvmNativeToken | SubOrmlToken | EvmErc20Token
|
|
20
|
+
*
|
|
21
|
+
* If `TokenTypes` is empty then `Token` will fall back to the common `IToken` interface, which every token must implement.
|
|
22
|
+
*/
|
|
23
|
+
export declare type Token = TokenTypes[keyof TokenTypes] extends never ? IToken : TokenTypes[keyof TokenTypes];
|
|
24
|
+
/** A collection of `Token` objects */
|
|
25
|
+
export declare type TokenList = Record<TokenId, Token>;
|
|
26
|
+
export declare type TokenId = string;
|
|
27
|
+
/** `IToken` is a common interface which all tokens must implement. */
|
|
28
|
+
export declare type IToken = {
|
|
29
|
+
id: TokenId;
|
|
30
|
+
type: string;
|
|
31
|
+
isTestnet: boolean;
|
|
32
|
+
symbol: string;
|
|
33
|
+
decimals: number;
|
|
34
|
+
coingeckoId?: string;
|
|
35
|
+
chain?: {
|
|
36
|
+
id: ChainId;
|
|
37
|
+
} | null;
|
|
38
|
+
evmNetwork?: {
|
|
39
|
+
id: EvmNetworkId;
|
|
40
|
+
} | null;
|
|
41
|
+
rates?: TokenRates;
|
|
42
|
+
};
|
|
43
|
+
/** Used by plugins to help define their custom `TokenType` */
|
|
44
|
+
export declare type NewTokenType<ModuleType extends string, TokenParams extends Record<string, unknown>> = IToken & {
|
|
45
|
+
type: ModuleType;
|
|
46
|
+
} & TokenParams;
|
|
47
|
+
export declare type TokenRates = {
|
|
48
|
+
/** us dollar rate */
|
|
49
|
+
usd: number | null;
|
|
50
|
+
/** australian dollar rate */
|
|
51
|
+
aud: number | null;
|
|
52
|
+
/** new zealand dollar rate */
|
|
53
|
+
nzd: number | null;
|
|
54
|
+
/** canadian dollar rate */
|
|
55
|
+
cud: number | null;
|
|
56
|
+
/** hong kong dollar rate */
|
|
57
|
+
hkd: number | null;
|
|
58
|
+
/** euro rate */
|
|
59
|
+
eur: number | null;
|
|
60
|
+
/** british pound sterling rate */
|
|
61
|
+
gbp: number | null;
|
|
62
|
+
/** japanese yen rate */
|
|
63
|
+
jpy: number | null;
|
|
64
|
+
/** south korean won rate */
|
|
65
|
+
krw: number | null;
|
|
66
|
+
/** chinese yuan rate */
|
|
67
|
+
cny: number | null;
|
|
68
|
+
/** btc rate */
|
|
69
|
+
btc: number | null;
|
|
70
|
+
/** eth rate */
|
|
71
|
+
eth: number | null;
|
|
72
|
+
/** dot rate */
|
|
73
|
+
dot: number | null;
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// NOTE: Do not export `./plugins` from here!
|
|
3
|
+
// Doing so will introduce a circular dependency!
|
|
4
|
+
// It is a separate entrypoint meant to be used like this:
|
|
5
|
+
//
|
|
6
|
+
// import { PluginTokenTypes } from '@talismn/chaindata-provider/plugins'
|
|
7
|
+
//
|
|
8
|
+
// Not this:
|
|
9
|
+
//
|
|
10
|
+
// import { PluginTokenTypes } from '@talismn/chaindata-provider'
|
|
11
|
+
//
|
|
12
|
+
export * from "./Chain";
|
|
13
|
+
export * from "./EvmNetwork";
|
|
14
|
+
export * from "./MultiChain";
|
|
15
|
+
export * from "./Token";
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@talismn/chaindata-provider",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"author": "Talisman",
|
|
5
|
+
"homepage": "https://talisman.xyz",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"directory": "packages/chaindata-provider",
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/talismansociety/talisman.git"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"/dist",
|
|
19
|
+
"/plugins"
|
|
20
|
+
],
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=14"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "tsc --watch --declarationMap",
|
|
26
|
+
"build": "tsc --declarationMap",
|
|
27
|
+
"build:packages:prod": "rm -rf dist && tsc",
|
|
28
|
+
"prepack": "yarn build:packages:prod",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"lint": "eslint . --max-warnings 0",
|
|
31
|
+
"clean": "rm -rf dist && rm -rf .turbo rm -rf node_modules"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@talismn/eslint-config": "^0.0.0",
|
|
35
|
+
"@talismn/tsconfig": "^0.0.0",
|
|
36
|
+
"@types/jest": "^27.5.1",
|
|
37
|
+
"eslint": "^8.4.0",
|
|
38
|
+
"jest": "^28.1.0",
|
|
39
|
+
"ts-jest": "^28.0.2",
|
|
40
|
+
"typescript": "^4.6.4"
|
|
41
|
+
},
|
|
42
|
+
"eslintConfig": {
|
|
43
|
+
"root": true,
|
|
44
|
+
"extends": [
|
|
45
|
+
"@talismn/eslint-config"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
}
|