@coinmasters/types 1.0.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.
@@ -0,0 +1,132 @@
1
+ import type { FixedNumber } from 'ethers';
2
+
3
+ import type { Chain, CosmosChain, EVMChain, UTXOChain } from './network.ts';
4
+ import type { WalletOption } from './wallet.ts';
5
+
6
+ type ConnectMethodNames =
7
+ | 'connectEVMWallet'
8
+ | 'connectKeplr'
9
+ | 'connectKeystore'
10
+ | 'connectKeepkey'
11
+ | 'connectLedger'
12
+ | 'connectOkx'
13
+ | 'connectTrezor'
14
+ | 'connectWalletconnect'
15
+ | 'connectXDEFI';
16
+
17
+ type ChainWallet = {
18
+ address: string;
19
+ balance: any[];
20
+ walletType: WalletOption;
21
+ };
22
+
23
+ export type ConnectConfig = {
24
+ stagenet?: boolean;
25
+ /**
26
+ * @required for AVAX & BSC
27
+ */
28
+ covalentApiKey?: string;
29
+ /**
30
+ * @required for ETH
31
+ */
32
+ ethplorerApiKey?: string;
33
+ /**
34
+ * @required for BTC, LTC, DOGE & BCH
35
+ */
36
+ utxoApiKey?: string;
37
+ /**
38
+ * @required for Walletconnect
39
+ */
40
+ walletConnectProjectId?: string;
41
+ /**
42
+ * @optional for Trezor config
43
+ */
44
+ trezorManifest?: {
45
+ email: string;
46
+ appUrl: string;
47
+ };
48
+ };
49
+
50
+ export type AddChainWalletParams = {
51
+ chain: Chain;
52
+ wallet: ChainWallet;
53
+ walletMethods: any;
54
+ };
55
+
56
+ export type Witness = {
57
+ value: number;
58
+ script: Buffer;
59
+ };
60
+
61
+ export type FixedNumberish = string | number | FixedNumber;
62
+
63
+ type ApisType = { [key in UTXOChain]?: string | any } & {
64
+ [key in EVMChain]?: string | any;
65
+ } & {
66
+ [key in CosmosChain]?: string;
67
+ };
68
+
69
+ export type ConnectWalletParams = {
70
+ addChain: (params: AddChainWalletParams) => void;
71
+ config: ConnectConfig;
72
+ rpcUrls: { [chain in Chain]?: string };
73
+ apis: ApisType;
74
+ };
75
+
76
+ export type ExtendParams<WalletConnectMethodNames = ''> = {
77
+ excludedChains?: Chain[];
78
+ config?: ConnectConfig;
79
+ rpcUrls?: { [chain in Chain]?: string };
80
+ apis?: ApisType;
81
+ wallets: {
82
+ connectMethodName: ConnectMethodNames | WalletConnectMethodNames;
83
+ connect: (params: ConnectWalletParams) => (...params: any) => Promise<any>;
84
+ }[];
85
+ };
86
+
87
+ export enum QuoteMode {
88
+ TC_SUPPORTED_TO_TC_SUPPORTED = 'TC-TC',
89
+ TC_SUPPORTED_TO_ETH = 'TC-ERC20',
90
+ TC_SUPPORTED_TO_AVAX = 'TC-ARC20',
91
+ TC_SUPPORTED_TO_BSC = 'TC-BEP20',
92
+ ETH_TO_TC_SUPPORTED = 'ERC20-TC',
93
+ ETH_TO_ETH = 'ERC20-ERC20',
94
+ ETH_TO_AVAX = 'ERC20-ARC20',
95
+ ETH_TO_BSC = 'ERC20-BEP20',
96
+ AVAX_TO_TC_SUPPORTED = 'ARC20-TC',
97
+ AVAX_TO_ETH = 'ARC20-ERC20',
98
+ AVAX_TO_AVAX = 'ARC20-ARC20',
99
+ AVAX_TO_BSC = 'ARC20-BEP20',
100
+ BSC_TO_TC_SUPPORTED = 'BEP20-TC',
101
+ BSC_TO_ETH = 'BEP20-ERC20',
102
+ BSC_TO_AVAX = 'BEP20-ARC20',
103
+ BSC_TO_BSC = 'BEP20-BEP20',
104
+ }
105
+
106
+ export type Asset = {
107
+ chain: Chain;
108
+ symbol: string;
109
+ ticker: string;
110
+ synth?: boolean;
111
+ };
112
+
113
+ export const AGG_SWAP = [QuoteMode.ETH_TO_ETH, QuoteMode.AVAX_TO_AVAX, QuoteMode.BSC_TO_BSC];
114
+
115
+ export const SWAP_IN = [
116
+ QuoteMode.ETH_TO_TC_SUPPORTED,
117
+ QuoteMode.ETH_TO_AVAX,
118
+ QuoteMode.ETH_TO_BSC,
119
+ QuoteMode.AVAX_TO_TC_SUPPORTED,
120
+ QuoteMode.AVAX_TO_ETH,
121
+ QuoteMode.AVAX_TO_BSC,
122
+ QuoteMode.BSC_TO_TC_SUPPORTED,
123
+ QuoteMode.BSC_TO_ETH,
124
+ QuoteMode.BSC_TO_AVAX,
125
+ ];
126
+
127
+ export const SWAP_OUT = [
128
+ QuoteMode.TC_SUPPORTED_TO_TC_SUPPORTED,
129
+ QuoteMode.TC_SUPPORTED_TO_ETH,
130
+ QuoteMode.TC_SUPPORTED_TO_AVAX,
131
+ QuoteMode.TC_SUPPORTED_TO_BSC,
132
+ ];
@@ -0,0 +1,75 @@
1
+ import { getDisplayMessage } from './displayMessages.ts';
2
+ import type { ApiErrorOptions, ERROR_CODE, ERROR_MODULE, ErrorInfo } from './types.ts';
3
+ import { ERROR_TYPE } from './types.ts';
4
+
5
+ export class ApiError extends Error {
6
+ public readonly status: number;
7
+ public readonly revision: string;
8
+ public readonly type?: ERROR_TYPE;
9
+ public readonly module: ERROR_MODULE;
10
+ public readonly code: ERROR_CODE;
11
+ public readonly message: string;
12
+ public readonly display: string;
13
+ public readonly stack?: string;
14
+ public readonly options: ApiErrorOptions;
15
+ public readonly displayMessageParams?: string[];
16
+
17
+ constructor({
18
+ status,
19
+ revision,
20
+ module,
21
+ code,
22
+ message,
23
+ type,
24
+ options: { shouldLog, shouldThrow, shouldTrace } = {
25
+ shouldLog: true,
26
+ shouldThrow: true,
27
+ shouldTrace: true,
28
+ },
29
+ displayMessageParams,
30
+ }: ErrorInfo) {
31
+ const safeMessage = message || getDisplayMessage(code, displayMessageParams || []) || '';
32
+ super(safeMessage);
33
+
34
+ this.status = status;
35
+ this.revision = revision || 'NO_REVISION';
36
+ this.module = module;
37
+ this.message = safeMessage;
38
+ this.display = getDisplayMessage(code, displayMessageParams || []);
39
+ this.code = code;
40
+ this.type = type || ERROR_TYPE.UNHANDLED_ERROR;
41
+ this.options = {
42
+ shouldLog: shouldLog || true,
43
+ shouldTrace: shouldTrace || true,
44
+ shouldThrow: shouldThrow || false,
45
+ };
46
+ this.displayMessageParams = displayMessageParams || [];
47
+
48
+ if (this.options.shouldTrace) Error.captureStackTrace(this);
49
+ }
50
+
51
+ public static fromErrorInfo(errorInfo: ErrorInfo): ApiError {
52
+ return new ApiError(errorInfo);
53
+ }
54
+
55
+ public toErrorInfo(): ErrorInfo {
56
+ return { ...this, identifier: this.identifier };
57
+ }
58
+
59
+ public get identifier(): string {
60
+ return `${this.revision}-${this.type || 'NO_TYPE'}-${this.module}-${this.code}`;
61
+ }
62
+
63
+ public get displayMessage(): string {
64
+ return getDisplayMessage(this.code, this.displayMessageParams || []);
65
+ }
66
+
67
+ public handle() {
68
+ const message = `[${this.identifier}]: ${this.message}`;
69
+
70
+ if (this.options.shouldLog) console.error(message, '\n', this.stack || '');
71
+ if (this.options.shouldThrow) throw Error(message, { cause: this.stack });
72
+
73
+ return this.toErrorInfo();
74
+ }
75
+ }
@@ -0,0 +1,68 @@
1
+ import { ERROR_CODE } from './types.ts';
2
+
3
+ export const ERROR_DISPLAY_MESSAGES: Record<string, string> = {
4
+ [ERROR_CODE.INVALID_INPUT_PARAMETERS]: 'Invalid input parameters: {0}.',
5
+ [ERROR_CODE.UNKNOWN_PROVIDERS]: 'Unknown providers: {0}.',
6
+ [ERROR_CODE.CANNOT_FIND_INBOUND_ADDRESS]: 'Cannot find inbound address.',
7
+ [ERROR_CODE.NO_INBOUND_ADDRESSES]: 'No inbound addresses.',
8
+ [ERROR_CODE.CHAIN_HALTED_OR_UNSUPPORTED]: 'Chain {0} halted or unsupported.',
9
+ [ERROR_CODE.MISSING_INPUT_PARAMETER]: 'Missing input parameter: {0}.',
10
+ [ERROR_CODE.INVALID_TYPE_GENERIC]: 'Invalid type',
11
+ [ERROR_CODE.INVALID_NUMBER_STRING]: 'Invalid number string.',
12
+ [ERROR_CODE.INVALID_NUMBER]: 'Invalid number.',
13
+ [ERROR_CODE.INVALID_BOOLEAN]: 'Invalid boolean.',
14
+ [ERROR_CODE.INVALID_OBJECT]: 'Invalid object.',
15
+ [ERROR_CODE.INVALID_ARRAY]: 'Invalid array.',
16
+ [ERROR_CODE.SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER]: 'Sell amount must be a positive integer.',
17
+ [ERROR_CODE.SELL_BUY_ASSETS_ARE_THE_SAME]: 'Sell and buy assets are the same.',
18
+ [ERROR_CODE.MISSING_SOURCE_ADDRESS_FOR_SYNTH]: 'Source address is required for synth quote.',
19
+ [ERROR_CODE.AFF_ADDRESS_AND_BPS_OR_NEITHER]:
20
+ 'Must provide affiliateAddress and affiliateBasisPoints params, or neither.',
21
+ [ERROR_CODE.AFF_ADDRESS_TOO_LONG]: 'affiliateAddress too long: 3 characters max.',
22
+ [ERROR_CODE.AFF_BPS_INTEGER_0_100]: 'affiliateBasisPoints must be an integer between 0 and 100.',
23
+ [ERROR_CODE.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN]: 'Source address {0} invalid for sell chain.',
24
+ [ERROR_CODE.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN]:
25
+ 'Destination address {0} invalid for buy chain.',
26
+ [ERROR_CODE.PREFERRED_PROFVIDER_NOT_SUPPORTED]: 'Preferred provider not supported.',
27
+ [ERROR_CODE.DESTINATION_ADDRESS_SMART_CONTRACT]: 'Destination address is a smart contract.',
28
+ [ERROR_CODE.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER]: 'Buy amount must be a positive integer.',
29
+ [ERROR_CODE.INVALID_PROVIDER]: 'Invalid provider {0}.',
30
+ [ERROR_CODE.MISSING_CROSS_CHAIN_PROVIDER]: 'Missing cross-chain provider.',
31
+ [ERROR_CODE.MISSING_AVAX_PROVIDER]: 'Missing AVAX provider.',
32
+ [ERROR_CODE.MISSING_BSC_PROVIDER]: 'Missing BSC provider.',
33
+ [ERROR_CODE.MISSING_ETH_PROVIDER]: 'Missing ETH provider.',
34
+ [ERROR_CODE.MISSING_ARB_PROVIDER]: 'Missing ARB provider.',
35
+ [ERROR_CODE.INVALID_PROVIDER_FOR_SWAP_OUT]: 'Invalid provider for swap out.',
36
+ [ERROR_CODE.INVALID_CHAIN]: 'Invalid chain {0}.',
37
+ [ERROR_CODE.INVALID_ASSET]: 'Invalid asset {0}.',
38
+ [ERROR_CODE.UNSUPPORTED_CHAIN]: 'Unsupported chain {0}.',
39
+ [ERROR_CODE.UNSUPPORTED_ASSET]: 'Unsupported asset {0}.',
40
+ [ERROR_CODE.UNSUPPORTED_ASSET_FOR_SWAPOUT]: 'Unsupported asset {0} for swap out.',
41
+ [ERROR_CODE.THORNODE_QUOTE_GENERIC_ERROR]: 'ThorNode quote generic error.',
42
+ [ERROR_CODE.INVALID_SOURCE_ADDRESS]: 'Invalid source address {0}',
43
+ [ERROR_CODE.INVALID_DESTINATION_ADDRESS]: 'Invalid destination address {0}',
44
+ [ERROR_CODE.NOT_ENOUGH_SYNTH_BALANCE]:
45
+ "Source address doesn't have enough synth balance for this quote.",
46
+ [ERROR_CODE.SYNTH_MINTING_CAP_REACHED]: 'Synth minting cap reached.',
47
+ [ERROR_CODE.INVALID_QUOTE_MODE]: 'Invalid quote mode.',
48
+ [ERROR_CODE.NO_QUOTES]: 'No quotes to service this request.',
49
+ [ERROR_CODE.SERVICE_UNAVAILABLE_GENERIC]: 'Service unavailable.',
50
+ [ERROR_CODE.MISSING_GAS_DATA_GENERIC]: 'Missing gas data.',
51
+ [ERROR_CODE.MISSING_TOKEN_INFO_GENERIC]: 'Missing token info.',
52
+ [ERROR_CODE.CANT_FIND_TOKEN_LIST]: "Can't find tokenlist {0}.",
53
+ [ERROR_CODE.NO_PRICE]: 'No price for asset {0}.',
54
+ [ERROR_CODE.PRICE_IS_STALE]: 'Price is stale for asset {0}.',
55
+ [ERROR_CODE.ADDRESS_NOT_WHITELISTED]: 'Address {0} not whitelisted for airdrop.',
56
+ [ERROR_CODE.ADDRESS_ALREADY_CLAIMED]: 'Address {0} already claimed the airdrop.',
57
+ };
58
+
59
+ export const getDisplayMessage = (code: ERROR_CODE, displayMessageParams: string[]) => {
60
+ let displayMessage = ERROR_DISPLAY_MESSAGES[code];
61
+
62
+ for (let i = 0; i < displayMessageParams.length; i++) {
63
+ displayMessage = displayMessage.replace(`{${i}}`, displayMessageParams[i]);
64
+ }
65
+
66
+ if (displayMessageParams.length === 0) return displayMessage.replace('{0}', '');
67
+ else return displayMessage;
68
+ };
@@ -0,0 +1,2 @@
1
+ export * from './apiError.ts';
2
+ export * from './types.ts';
@@ -0,0 +1,144 @@
1
+ export enum ERROR_TYPE {
2
+ VALIDATION_ERROR = 'VALIDATION_ERROR',
3
+ REQUEST_PARAMETER_ERROR = 'REQUEST_PARAMETER_ERROR',
4
+ RESPONSE_PARSING_ERROR = 'RESPONSE_PARSING_ERROR',
5
+ UNSUPPORTED = 'UNSUPPORTED',
6
+ NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
7
+ INCOMPATIBLE_ASSETS_OPERATIONS = 'INCOMPATIBLE_ASSETS_OPERATIONS',
8
+ SERVICE_UNAVAILABLE = 'SERVICE_UNAVAILABLE',
9
+ DOWN_FOR_MAINTENANCE = 'DOWN_FOR_MAINTENANCE',
10
+ MISSING_INBOUND_INFO = 'MISSING_INBOUND_INFO',
11
+ QUOTE_FETCHING_ERROR = 'QUOTE_FETCHING_ERROR',
12
+ AIRDROP_ERROR = 'AIRDROP_ERROR',
13
+ UNHANDLED_ERROR = 'UNHANDLED_ERROR',
14
+ }
15
+
16
+ export enum ERROR_MODULE {
17
+ // Controllers
18
+ HEALTH_CONTROLLER = '1000',
19
+ LIQUIDITY_CONTROLLER = '1001',
20
+ PROVIDER_CONTROLLER = '1002',
21
+ QUOTE_CONTROLLER = '1003',
22
+ SWAP_CONTROLLER = '1004',
23
+ UTIL_CONTROLLER = '1005',
24
+ AIRDROP_CONTROLLER = '1006',
25
+ // Entities
26
+ PROVIDER = '2000',
27
+ ASSET = '2001',
28
+ TOKEN_LIST = '2002',
29
+ // Quote entities
30
+ QUOTE = '2100',
31
+ QUOTE_TXN_DETAILS = '2101',
32
+ // Providers
33
+ THORCHAIN_PROVIDER = '3000',
34
+ UNISWAPV2_ETH_PROVIDER = '3001',
35
+ UNISWAPV3_ETH_PROVIDER = '3002',
36
+ SUSHISWAP_ETH_PROVIDER = '3003',
37
+ PANCAKESWAP_BSC_PROVIDER = '3004',
38
+ PANCAKESWAP_ETH_PROVIDER = '3005',
39
+ ONEINCH_ETH_PROVIDER = '3006',
40
+ ONEINCH_BSC_PROVIDER = '3007',
41
+ ONEINCH_AVAX_PROVIDER = '3008',
42
+ ZEROX_ETH_PROVIDER = '3009',
43
+ WOOFI_AVAX_PROVIDER = '3010',
44
+ PANGOLIN_AVAX_PROVIDER = '3011',
45
+ TRADERJOE_AVAX_PROVIDER = '3012',
46
+ KYBER_ETH_PROVIDER = '3013',
47
+ KYBER_AVAX_PROVIDER = '3014',
48
+ WOOFI_BSC_PROVIDER = '3015',
49
+ STARGATE_PROVIDER = '3016',
50
+ // Utilities
51
+ PROVIDER_UTIL = '4000',
52
+ // Aggregator
53
+ TXN_DETAILS = '5000',
54
+ // AirDrop
55
+ AIRDROP_UTIL = '6000',
56
+ }
57
+
58
+ export enum ERROR_CODE {
59
+ // 10xx - Generic
60
+ INVALID_INPUT_PARAMETERS = '1000',
61
+ UNKNOWN_PROVIDERS = '1001',
62
+ CANNOT_FIND_INBOUND_ADDRESS = '1002',
63
+ NO_INBOUND_ADDRESSES = '1003',
64
+ CHAIN_HALTED_OR_UNSUPPORTED = '1004',
65
+ MISSING_INPUT_PARAMETER = '1005',
66
+ // 11xx - Type error
67
+ INVALID_TYPE_GENERIC = '1100',
68
+ INVALID_NUMBER_STRING = '1101',
69
+ INVALID_NUMBER = '1102',
70
+ INVALID_BOOLEAN = '1103',
71
+ INVALID_OBJECT = '1104',
72
+ INVALID_ARRAY = '1105',
73
+ // 20xx - Quote request parameters
74
+ SELL_AMOUNT_MUST_BE_POSITIVE_INTEGER = '2000',
75
+ SELL_BUY_ASSETS_ARE_THE_SAME = '2001',
76
+ MISSING_SOURCE_ADDRESS_FOR_SYNTH = '2002',
77
+ AFF_ADDRESS_AND_BPS_OR_NEITHER = '2003',
78
+ AFF_ADDRESS_TOO_LONG = '2004',
79
+ AFF_BPS_INTEGER_0_100 = '2005',
80
+ SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = '2006',
81
+ DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = '2007',
82
+ PREFERRED_PROFVIDER_NOT_SUPPORTED = '2008',
83
+ DESTINATION_ADDRESS_SMART_CONTRACT = '2009',
84
+ BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER = '2010',
85
+ SOURCE_ADDRESS_SMART_CONTRACT = '2011',
86
+ // 21xx - Quote request providers issue
87
+ INVALID_PROVIDER = '2100',
88
+ MISSING_CROSS_CHAIN_PROVIDER = '2101',
89
+ MISSING_AVAX_PROVIDER = '2102',
90
+ MISSING_BSC_PROVIDER = '2103',
91
+ MISSING_ETH_PROVIDER = '2104',
92
+ INVALID_PROVIDER_FOR_SWAP_OUT = '2105',
93
+ MISSING_ARB_PROVIDER = '2106',
94
+ // 22xx - Quote request assets issue
95
+ INVALID_CHAIN = '2200',
96
+ INVALID_ASSET = '2201',
97
+ INVALID_ASSET_IDENTIFIER = '2202',
98
+ UNSUPPORTED_CHAIN = '2204',
99
+ UNSUPPORTED_ASSET = '2203',
100
+ UNSUPPORTED_ASSET_FOR_SWAPOUT = '2205',
101
+ // 23xx - Invalid addresses
102
+ INVALID_SOURCE_ADDRESS = '2300',
103
+ INVALID_DESTINATION_ADDRESS = '2301',
104
+ // 30xx - Thorchain
105
+ THORNODE_QUOTE_GENERIC_ERROR = '3000',
106
+ NOT_ENOUGH_SYNTH_BALANCE = '3001',
107
+ SYNTH_MINTING_CAP_REACHED = '3002',
108
+ // 40xx - Code logic error (not the client's fault)
109
+ INVALID_QUOTE_MODE = '4000',
110
+ NO_QUOTES = '4001',
111
+ // 50xx - Service unavailable
112
+ SERVICE_UNAVAILABLE_GENERIC = '5000',
113
+ // 51xx - Missing gas data
114
+ MISSING_GAS_DATA_GENERIC = '5100',
115
+ // 52xx - Missing token info
116
+ MISSING_TOKEN_INFO_GENERIC = '5200',
117
+ CANT_FIND_TOKEN_LIST = '5201',
118
+ NO_PRICE = '5202',
119
+ PRICE_IS_STALE = '5203',
120
+ // 60xx - Airdrop
121
+ ADDRESS_NOT_WHITELISTED = '6000',
122
+ ADDRESS_ALREADY_CLAIMED = '6001',
123
+ // 90xx - Unhandled
124
+ TEMPORARY_ERROR = '9999', // use only when waiting for a PR to be merged
125
+ }
126
+
127
+ export type ErrorInfo = {
128
+ status: number;
129
+ revision: string;
130
+ type?: ERROR_TYPE;
131
+ module: ERROR_MODULE;
132
+ code: ERROR_CODE;
133
+ message?: string | undefined;
134
+ stack?: string;
135
+ identifier?: string;
136
+ options?: ApiErrorOptions;
137
+ displayMessageParams?: string[];
138
+ };
139
+
140
+ export type ApiErrorOptions = {
141
+ shouldLog?: boolean;
142
+ shouldTrace?: boolean;
143
+ shouldThrow?: boolean;
144
+ };
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { erc20ABI } from './abis/erc20.ts';
2
+ export { TCAvalancheDepositABI, TCBscDepositABI, TCEthereumVaultAbi } from './abis/tcEthVault.ts';
3
+ export * from './commonTypes.ts';
4
+ export * from './errors/index.ts';
5
+ export * from './network.ts';
6
+ export * from './thorchain.ts';
7
+ export * from './transactions.ts';
8
+ export * from './wallet.ts';
package/src/network.ts ADDED
@@ -0,0 +1,253 @@
1
+ export enum Chain {
2
+ Arbitrum = 'ARB',
3
+ Avalanche = 'AVAX',
4
+ Binance = 'BNB',
5
+ BinanceSmartChain = 'BSC',
6
+ Bitcoin = 'BTC',
7
+ BitcoinCash = 'BCH',
8
+ Cosmos = 'GAIA',
9
+ Dogecoin = 'DOGE',
10
+ Ethereum = 'ETH',
11
+ Litecoin = 'LTC',
12
+ Maya = 'MAYA',
13
+ Optimism = 'OP',
14
+ Polygon = 'MATIC',
15
+ THORChain = 'THOR',
16
+ }
17
+ type ChainNameType = keyof typeof Chain;
18
+
19
+ export enum ContractAddress {
20
+ ARB = '0x0000000000000000000000000000000000000000',
21
+ AVAX = '0x0000000000000000000000000000000000000000',
22
+ ETH = '0x0000000000000000000000000000000000000000',
23
+ BSC = '0x0000000000000000000000000000000000000000',
24
+ MATIC = '0x0000000000000000000000000000000000001010',
25
+ OP = '0x4200000000000000000000000000000000000042',
26
+ }
27
+
28
+ export enum NetworkId {
29
+ Ethereum = 60,
30
+ Binance = 714,
31
+ THORChain = 931,
32
+ }
33
+
34
+ export enum DerivationPath {
35
+ ARB = "m/44'/60'/0'/0",
36
+ AVAX = "m/44'/60'/0'/0",
37
+ BCH = "m/44'/145'/0'/0",
38
+ BNB = "m/44'/714'/0'/0",
39
+ BSC = "m/44'/60'/0'/0",
40
+ BTC = "m/84'/0'/0'/0",
41
+ DOGE = "m/44'/3'/0'/0",
42
+ ETH = "m/44'/60'/0'/0",
43
+ GAIA = "m/44'/118'/0'/0",
44
+ LTC = "m/84'/2'/0'/0",
45
+ MATIC = "m/44'/60'/0'/0",
46
+ MAYA = "m/44'/931'/0'/0",
47
+ OP = "m/44'/60'/0'/0",
48
+ THOR = "m/44'/931'/0'/0",
49
+ }
50
+
51
+ export type DerivationPathArray = [number, number, number, number, number];
52
+
53
+ export const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {
54
+ ARB: [44, 60, 0, 0, 0],
55
+ AVAX: [44, 60, 0, 0, 0],
56
+ BCH: [44, 145, 0, 0, 0],
57
+ BNB: [44, 714, 0, 0, 0],
58
+ BSC: [44, 60, 0, 0, 0],
59
+ BTC: [84, 0, 0, 0, 0],
60
+ DOGE: [44, 3, 0, 0, 0],
61
+ ETH: [44, 60, 0, 0, 0],
62
+ GAIA: [44, 118, 0, 0, 0],
63
+ LTC: [84, 2, 0, 0, 0],
64
+ MATIC: [44, 60, 0, 0, 0],
65
+ MAYA: [44, 931, 0, 0, 0],
66
+ OP: [44, 60, 0, 0, 0],
67
+ THOR: [44, 931, 0, 0, 0],
68
+ };
69
+
70
+ export enum BaseDecimal {
71
+ ARB = 18,
72
+ AVAX = 18,
73
+ BCH = 8,
74
+ BNB = 8,
75
+ BSC = 18,
76
+ BTC = 8,
77
+ DASH = 8,
78
+ DOGE = 8,
79
+ ETH = 18,
80
+ GAIA = 6,
81
+ KUJI = 6,
82
+ LTC = 8,
83
+ MATIC = 18,
84
+ MAYA = 10,
85
+ OP = 18,
86
+ THOR = 8,
87
+ }
88
+
89
+ export type EVMChain =
90
+ | Chain.Ethereum
91
+ | Chain.Avalanche
92
+ | Chain.BinanceSmartChain
93
+ | Chain.Arbitrum
94
+ | Chain.Optimism
95
+ | Chain.Polygon;
96
+
97
+ export const EVMChainList: EVMChain[] = [
98
+ Chain.Ethereum,
99
+ Chain.Avalanche,
100
+ Chain.BinanceSmartChain,
101
+ Chain.Arbitrum,
102
+ Chain.Optimism,
103
+ Chain.Polygon,
104
+ ];
105
+
106
+ export type UTXOChain = Chain.Bitcoin | Chain.BitcoinCash | Chain.Dogecoin | Chain.Litecoin;
107
+
108
+ export const UTXOChainList: Chain[] = [
109
+ Chain.Bitcoin,
110
+ Chain.BitcoinCash,
111
+ Chain.Dogecoin,
112
+ Chain.Litecoin,
113
+ ];
114
+
115
+ export type CosmosChain = Chain.Cosmos | Chain.THORChain | Chain.Binance;
116
+
117
+ export const CosmosChainList: CosmosChain[] = [Chain.Cosmos, Chain.THORChain, Chain.Binance];
118
+
119
+ export enum ChainId {
120
+ Arbitrum = '42161',
121
+ ArbitrumHex = '0xa4b1',
122
+ Avalanche = '43114',
123
+ AvalancheHex = '0xa86a',
124
+ Binance = 'Binance-Chain-Tigris',
125
+ BinanceSmartChain = '56',
126
+ BinanceSmartChainHex = '0x38',
127
+ Bitcoin = 'bitcoin',
128
+ BitcoinCash = 'bitcoincash',
129
+ Cosmos = 'cosmoshub-4',
130
+ Dogecoin = 'dogecoin',
131
+ Ethereum = '1',
132
+ EthereumHex = '0x1',
133
+ Litecoin = 'litecoin',
134
+ Maya = 'mayachain-mainnet-v1',
135
+ MayaStagenet = 'mayachain-stagenet-v1',
136
+ Optimism = '10',
137
+ OptimismHex = '0xa',
138
+ Polygon = '137',
139
+ PolygonHex = '0x89',
140
+ THORChain = 'thorchain-mainnet-v1',
141
+ THORChainStagenet = 'thorchain-stagenet-v2',
142
+ }
143
+
144
+ export enum RPCUrl {
145
+ Arbitrum = 'https://arb1.arbitrum.io/rpc',
146
+ Avalanche = 'https://node-router.thorswap.net/avalanche-c',
147
+ Binance = '',
148
+ BinanceSmartChain = 'https://bsc-dataseed.binance.org',
149
+ Bitcoin = 'https://node-router.thorswap.net/bitcoin',
150
+ BitcoinCash = 'https://node-router.thorswap.net/bitcoin-cash',
151
+ Cosmos = 'https://node-router.thorswap.net/cosmos/rpc',
152
+ Dogecoin = 'https://node-router.thorswap.net/dogecoin',
153
+ Ethereum = 'https://node-router.thorswap.net/ethereum',
154
+ Litecoin = 'https://node-router.thorswap.net/litecoin',
155
+ Maya = 'https://tendermint.mayachain.info',
156
+ MayaStagenet = 'https://stagenet.tendermint.mayachain.info',
157
+ Optimism = 'https://mainnet.optimism.io',
158
+ Polygon = 'https://polygon-rpc.com',
159
+ THORChain = 'https://rpc.thorswap.net',
160
+ THORChainStagenet = 'https://stagenet-rpc.ninerealms.com',
161
+ }
162
+
163
+ export enum ApiUrl {
164
+ Cosmos = 'https://node-router.thorswap.net/cosmos/rest',
165
+ MayanodeMainnet = 'https://mayanode.mayachain.info',
166
+ MayanodeStagenet = 'https://stagenet.mayanode.mayachain.info',
167
+ ThornodeMainnet = 'https://thornode.thorswap.net',
168
+ ThornodeStagenet = 'https://stagenet-thornode.ninerealms.com',
169
+ ThorswapApi = 'https://api.thorswap.finance',
170
+ ThorswapStatic = 'https://static.thorswap.net',
171
+ }
172
+
173
+ const chains = Object.values(Chain) as Chain[];
174
+ const chainNames = Object.keys(Chain) as ChainNameType[];
175
+
176
+ const ChainToChainName = chains.reduce(
177
+ (acc, chain) => {
178
+ const chainName = chainNames.find((key) => Chain[key as ChainNameType] === chain);
179
+
180
+ if (chainName) acc[chain] = chainName;
181
+
182
+ return acc;
183
+ },
184
+ {} as { [key in Chain]: ChainNameType },
185
+ );
186
+
187
+ export const ChainToChainId = chains.reduce(
188
+ (acc, chain) => {
189
+ acc[chain] = ChainId[ChainToChainName[chain]];
190
+ return acc;
191
+ },
192
+ {} as { [key in Chain]: ChainId },
193
+ );
194
+
195
+ export const ChainToRPC = chains.reduce(
196
+ (acc, chain) => {
197
+ acc[chain] = RPCUrl[ChainToChainName[chain]];
198
+ return acc;
199
+ },
200
+ {} as { [key in Chain]: RPCUrl },
201
+ );
202
+
203
+ export const ChainToHexChainId = chains.reduce(
204
+ (acc, chain) => {
205
+ const chainString = `${ChainToChainName[chain]}Hex` as keyof typeof ChainId;
206
+
207
+ acc[chain] = ChainId[chainString];
208
+ return acc;
209
+ },
210
+ {} as { [key in Chain]: ChainId },
211
+ );
212
+
213
+ export const ChainIdToChain: Record<ChainId, Chain> = {
214
+ [ChainId.ArbitrumHex]: Chain.Arbitrum,
215
+ [ChainId.Arbitrum]: Chain.Arbitrum,
216
+ [ChainId.AvalancheHex]: Chain.Avalanche,
217
+ [ChainId.Avalanche]: Chain.Avalanche,
218
+ [ChainId.BinanceSmartChainHex]: Chain.BinanceSmartChain,
219
+ [ChainId.BinanceSmartChain]: Chain.BinanceSmartChain,
220
+ [ChainId.Binance]: Chain.Binance,
221
+ [ChainId.BitcoinCash]: Chain.BitcoinCash,
222
+ [ChainId.Bitcoin]: Chain.Bitcoin,
223
+ [ChainId.Cosmos]: Chain.Cosmos,
224
+ [ChainId.Dogecoin]: Chain.Dogecoin,
225
+ [ChainId.EthereumHex]: Chain.Ethereum,
226
+ [ChainId.Ethereum]: Chain.Ethereum,
227
+ [ChainId.Litecoin]: Chain.Litecoin,
228
+ [ChainId.MayaStagenet]: Chain.Maya,
229
+ [ChainId.Maya]: Chain.Maya,
230
+ [ChainId.OptimismHex]: Chain.Optimism,
231
+ [ChainId.Optimism]: Chain.Optimism,
232
+ [ChainId.PolygonHex]: Chain.Polygon,
233
+ [ChainId.Polygon]: Chain.Polygon,
234
+ [ChainId.THORChainStagenet]: Chain.THORChain,
235
+ [ChainId.THORChain]: Chain.THORChain,
236
+ };
237
+
238
+ export const ChainToExplorerUrl: Record<Chain, string> = {
239
+ [Chain.Arbitrum]: 'https://arbiscan.io',
240
+ [Chain.Avalanche]: 'https://snowtrace.io',
241
+ [Chain.BinanceSmartChain]: 'https://bscscan.com',
242
+ [Chain.Binance]: 'https://explorer.binance.org',
243
+ [Chain.BitcoinCash]: 'https://www.blockchain.com/bch',
244
+ [Chain.Bitcoin]: 'https://blockstream.info',
245
+ [Chain.Cosmos]: 'https://cosmos.bigdipper.live',
246
+ [Chain.Dogecoin]: 'https://blockchair.com/dogecoin',
247
+ [Chain.Ethereum]: 'https://etherscan.io',
248
+ [Chain.Litecoin]: 'https://ltc.bitaps.com',
249
+ [Chain.Maya]: 'https://www.mayascan.org',
250
+ [Chain.Optimism]: 'https://optimistic.etherscan.io',
251
+ [Chain.Polygon]: 'https://polygonscan.com',
252
+ [Chain.THORChain]: 'https://viewblock.io/thorchain',
253
+ };