@swapkit/types 0.0.0-nightly-20240208140027

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,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,71 @@
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_MAX_500]:
23
+ 'affiliateBasisPoints must be an integer between 0 and 100.',
24
+ [ERROR_CODE.SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN]: 'Source address {0} invalid for sell chain.',
25
+ [ERROR_CODE.DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN]:
26
+ 'Destination address {0} invalid for buy chain.',
27
+ [ERROR_CODE.PREFERRED_PROVIDER_NOT_SUPPORTED]: 'Preferred provider not supported.',
28
+ [ERROR_CODE.SOURCE_ADDRESS_SMART_CONTRACT]: 'Source address is a smart contract.',
29
+ [ERROR_CODE.DESTINATION_ADDRESS_SMART_CONTRACT]: 'Destination address is a smart contract.',
30
+ [ERROR_CODE.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER]: 'Buy amount must be a positive integer.',
31
+ [ERROR_CODE.INVALID_PROVIDER]: 'Invalid provider {0}.',
32
+ [ERROR_CODE.MISSING_CROSS_CHAIN_PROVIDER]: 'Missing cross-chain provider.',
33
+ [ERROR_CODE.MISSING_AVAX_PROVIDER]: 'Missing AVAX provider.',
34
+ [ERROR_CODE.MISSING_BSC_PROVIDER]: 'Missing BSC provider.',
35
+ [ERROR_CODE.MISSING_ETH_PROVIDER]: 'Missing ETH provider.',
36
+ [ERROR_CODE.MISSING_ARB_PROVIDER]: 'Missing ARB provider.',
37
+ [ERROR_CODE.INVALID_PROVIDER_FOR_SWAP_OUT]: 'Invalid provider for swap out.',
38
+ [ERROR_CODE.INVALID_CHAIN]: 'Invalid chain {0}.',
39
+ [ERROR_CODE.INVALID_ASSET]: 'Invalid asset {0}.',
40
+ [ERROR_CODE.UNSUPPORTED_CHAIN]: 'Unsupported chain {0}.',
41
+ [ERROR_CODE.UNSUPPORTED_ASSET]: 'Unsupported asset {0}.',
42
+ [ERROR_CODE.UNSUPPORTED_ASSET_FOR_SWAPOUT]: 'Unsupported asset {0} for swap out.',
43
+ [ERROR_CODE.THORNODE_QUOTE_GENERIC_ERROR]: 'ThorNode quote generic error.',
44
+ [ERROR_CODE.INVALID_SOURCE_ADDRESS]: 'Invalid source address {0}',
45
+ [ERROR_CODE.INVALID_DESTINATION_ADDRESS]: 'Invalid destination address {0}',
46
+ [ERROR_CODE.NOT_ENOUGH_SYNTH_BALANCE]:
47
+ "Source address doesn't have enough synth balance for this quote.",
48
+ [ERROR_CODE.SYNTH_MINTING_CAP_REACHED]: 'Synth minting cap reached.',
49
+ [ERROR_CODE.INVALID_QUOTE_MODE]: 'Invalid quote mode.',
50
+ [ERROR_CODE.NO_QUOTES]: 'No quotes to service this request.',
51
+ [ERROR_CODE.SERVICE_UNAVAILABLE_GENERIC]: 'Service unavailable.',
52
+ [ERROR_CODE.MISSING_GAS_DATA_GENERIC]: 'Missing gas data.',
53
+ [ERROR_CODE.MISSING_TOKEN_INFO_GENERIC]: 'Missing token info.',
54
+ [ERROR_CODE.CANT_FIND_TOKEN_LIST]: "Can't find tokenlist {0}.",
55
+ [ERROR_CODE.NO_PRICE]: 'No price for asset {0}.',
56
+ [ERROR_CODE.PRICE_IS_STALE]: 'Price is stale for asset {0}.',
57
+ [ERROR_CODE.ADDRESS_NOT_WHITELISTED]: 'Address {0} not whitelisted for airdrop.',
58
+ [ERROR_CODE.ADDRESS_ALREADY_CLAIMED]: 'Address {0} already claimed the airdrop.',
59
+ };
60
+
61
+ export const getDisplayMessage = (code: ERROR_CODE, displayMessageParams: string[]) => {
62
+ let displayMessage = ERROR_DISPLAY_MESSAGES[code];
63
+
64
+ if (!displayMessage) return '';
65
+
66
+ for (let i = 0; i < displayMessageParams.length; i++) {
67
+ displayMessage = displayMessage?.replace(`{${i}}`, displayMessageParams[i]) ?? '';
68
+ }
69
+
70
+ return displayMessage;
71
+ };
@@ -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_MAX_500 = '2005',
80
+ SOURCE_ADDRESS_INVALID_FOR_SELL_CHAIN = '2006',
81
+ DESTINATION_ADDRESS_INVALID_FOR_BUY_CHAIN = '2007',
82
+ PREFERRED_PROVIDER_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,290 @@
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
+ Kujira = 'KUJI',
12
+ Litecoin = 'LTC',
13
+ Maya = 'MAYA',
14
+ Optimism = 'OP',
15
+ Polkadot = 'DOT',
16
+ Chainflip = 'FLIP',
17
+ Polygon = 'MATIC',
18
+ THORChain = 'THOR',
19
+ }
20
+ type ChainNameType = keyof typeof Chain;
21
+
22
+ export enum ContractAddress {
23
+ ARB = '0x0000000000000000000000000000000000000000',
24
+ AVAX = '0x0000000000000000000000000000000000000000',
25
+ ETH = '0x0000000000000000000000000000000000000000',
26
+ BSC = '0x0000000000000000000000000000000000000000',
27
+ MATIC = '0x0000000000000000000000000000000000001010',
28
+ OP = '0x4200000000000000000000000000000000000042',
29
+ }
30
+
31
+ export enum DerivationPath {
32
+ ARB = "m/44'/60'/0'/0",
33
+ AVAX = "m/44'/60'/0'/0",
34
+ BCH = "m/44'/145'/0'/0",
35
+ BNB = "m/44'/714'/0'/0",
36
+ BSC = "m/44'/60'/0'/0",
37
+ BTC = "m/84'/0'/0'/0",
38
+ DOGE = "m/44'/3'/0'/0",
39
+ DOT = '////',
40
+ ETH = "m/44'/60'/0'/0",
41
+ FLIP = '////',
42
+ GAIA = "m/44'/118'/0'/0",
43
+ KUJI = "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
+ KUJI: [44, 118, 0, 0, 0],
64
+ LTC: [84, 2, 0, 0, 0],
65
+ MATIC: [44, 60, 0, 0, 0],
66
+ MAYA: [44, 931, 0, 0, 0],
67
+ OP: [44, 60, 0, 0, 0],
68
+ THOR: [44, 931, 0, 0, 0],
69
+ // Polkadot and related network derivation path is not number based
70
+ DOT: [0, 0, 0, 0, 0],
71
+ FLIP: [0, 0, 0, 0, 0],
72
+ };
73
+
74
+ export enum BaseDecimal {
75
+ ARB = 18,
76
+ AVAX = 18,
77
+ BCH = 8,
78
+ BNB = 8,
79
+ BSC = 18,
80
+ BTC = 8,
81
+ DASH = 8,
82
+ DOGE = 8,
83
+ DOT = 10,
84
+ ETH = 18,
85
+ FLIP = 18,
86
+ GAIA = 6,
87
+ KUJI = 6,
88
+ LTC = 8,
89
+ MATIC = 18,
90
+ MAYA = 10,
91
+ OP = 18,
92
+ THOR = 8,
93
+ }
94
+
95
+ export type EVMChain =
96
+ | Chain.Ethereum
97
+ | Chain.Avalanche
98
+ | Chain.BinanceSmartChain
99
+ | Chain.Arbitrum
100
+ | Chain.Optimism
101
+ | Chain.Polygon;
102
+
103
+ export const EVMChainList: EVMChain[] = [
104
+ Chain.Ethereum,
105
+ Chain.Avalanche,
106
+ Chain.BinanceSmartChain,
107
+ Chain.Arbitrum,
108
+ Chain.Optimism,
109
+ Chain.Polygon,
110
+ ];
111
+
112
+ export type UTXOChain = Chain.Bitcoin | Chain.BitcoinCash | Chain.Dogecoin | Chain.Litecoin;
113
+
114
+ export const UTXOChainList: UTXOChain[] = [
115
+ Chain.Bitcoin,
116
+ Chain.BitcoinCash,
117
+ Chain.Dogecoin,
118
+ Chain.Litecoin,
119
+ ];
120
+
121
+ export type CosmosChain =
122
+ | Chain.Cosmos
123
+ | Chain.THORChain
124
+ | Chain.Binance
125
+ | Chain.Maya
126
+ | Chain.Kujira;
127
+
128
+ export const CosmosChainList: CosmosChain[] = [Chain.Cosmos, Chain.THORChain, Chain.Binance];
129
+
130
+ export const TCSupportedChainList = [
131
+ Chain.Avalanche,
132
+ Chain.Binance,
133
+ Chain.BinanceSmartChain,
134
+ Chain.Bitcoin,
135
+ Chain.BitcoinCash,
136
+ Chain.Cosmos,
137
+ Chain.Dogecoin,
138
+ Chain.Ethereum,
139
+ Chain.Litecoin,
140
+ Chain.THORChain,
141
+ ];
142
+
143
+ export enum ChainId {
144
+ Arbitrum = '42161',
145
+ ArbitrumHex = '0xa4b1',
146
+ Avalanche = '43114',
147
+ AvalancheHex = '0xa86a',
148
+ Binance = 'Binance-Chain-Tigris',
149
+ BinanceSmartChain = '56',
150
+ BinanceSmartChainHex = '0x38',
151
+ Bitcoin = 'bitcoin',
152
+ BitcoinCash = 'bitcoincash',
153
+ Chainflip = 'chainflip',
154
+ Cosmos = 'cosmoshub-4',
155
+ Dogecoin = 'dogecoin',
156
+ Kujira = 'kaiyo-1',
157
+ Ethereum = '1',
158
+ EthereumHex = '0x1',
159
+ Litecoin = 'litecoin',
160
+ Maya = 'mayachain-mainnet-v1',
161
+ MayaStagenet = 'mayachain-stagenet-v1',
162
+ Optimism = '10',
163
+ OptimismHex = '0xa',
164
+ Polkadot = 'polkadot',
165
+ Polygon = '137',
166
+ PolygonHex = '0x89',
167
+ THORChain = 'thorchain-mainnet-v1',
168
+ THORChainStagenet = 'thorchain-stagenet-v2',
169
+ }
170
+
171
+ export enum RPCUrl {
172
+ Arbitrum = 'https://arb1.arbitrum.io/rpc',
173
+ Avalanche = 'https://node-router.thorswap.net/avalanche-c',
174
+ Binance = '',
175
+ BinanceSmartChain = 'https://bsc-dataseed.binance.org',
176
+ Bitcoin = 'https://node-router.thorswap.net/bitcoin',
177
+ BitcoinCash = 'https://node-router.thorswap.net/bitcoin-cash',
178
+ Chainflip = 'wss://mainnet-archive.chainflip.io',
179
+ Cosmos = 'https://node-router.thorswap.net/cosmos/rpc',
180
+ Kujira = 'https://rpc-kujira.synergynodes.com/',
181
+ Dogecoin = 'https://node-router.thorswap.net/dogecoin',
182
+ Ethereum = 'https://node-router.thorswap.net/ethereum',
183
+ Litecoin = 'https://node-router.thorswap.net/litecoin',
184
+ Maya = 'https://tendermint.mayachain.info',
185
+ MayaStagenet = 'https://stagenet.tendermint.mayachain.info',
186
+ Optimism = 'https://mainnet.optimism.io',
187
+ Polkadot = 'wss://rpc.polkadot.io',
188
+ Polygon = 'https://polygon-rpc.com',
189
+ THORChain = 'https://rpc.thorswap.net',
190
+ THORChainStagenet = 'https://stagenet-rpc.ninerealms.com',
191
+ }
192
+
193
+ export enum ApiUrl {
194
+ Cosmos = 'https://node-router.thorswap.net/cosmos/rest',
195
+ Kujira = 'https://lcd-kujira.synergynodes.com/',
196
+ MayanodeMainnet = 'https://mayanode.mayachain.info',
197
+ MayanodeStagenet = 'https://stagenet.mayanode.mayachain.info',
198
+ ThornodeMainnet = 'https://thornode.thorswap.net',
199
+ ThornodeStagenet = 'https://stagenet-thornode.ninerealms.com',
200
+ ThorswapApi = 'https://api.thorswap.net',
201
+ ThorswapStatic = 'https://static.thorswap.net',
202
+ }
203
+
204
+ const chains = Object.values(Chain) as Chain[];
205
+ const chainNames = Object.keys(Chain) as ChainNameType[];
206
+
207
+ const ChainToChainName = chains.reduce(
208
+ (acc, chain) => {
209
+ const chainName = chainNames.find((key) => Chain[key as ChainNameType] === chain);
210
+
211
+ if (chainName) acc[chain] = chainName;
212
+
213
+ return acc;
214
+ },
215
+ {} as { [key in Chain]: ChainNameType },
216
+ );
217
+
218
+ export const ChainToChainId = chains.reduce(
219
+ (acc, chain) => {
220
+ acc[chain] = ChainId[ChainToChainName[chain]];
221
+ return acc;
222
+ },
223
+ {} as { [key in Chain]: ChainId },
224
+ );
225
+
226
+ export const ChainToRPC = chains.reduce(
227
+ (acc, chain) => {
228
+ acc[chain] = RPCUrl[ChainToChainName[chain]];
229
+ return acc;
230
+ },
231
+ {} as { [key in Chain]: RPCUrl },
232
+ );
233
+
234
+ export const ChainToHexChainId = chains.reduce(
235
+ (acc, chain) => {
236
+ const chainString = `${ChainToChainName[chain]}Hex` as keyof typeof ChainId;
237
+
238
+ acc[chain] = ChainId[chainString];
239
+ return acc;
240
+ },
241
+ {} as { [key in Chain]: ChainId },
242
+ );
243
+
244
+ export const ChainIdToChain: Record<ChainId, Chain> = {
245
+ [ChainId.ArbitrumHex]: Chain.Arbitrum,
246
+ [ChainId.Arbitrum]: Chain.Arbitrum,
247
+ [ChainId.AvalancheHex]: Chain.Avalanche,
248
+ [ChainId.Avalanche]: Chain.Avalanche,
249
+ [ChainId.BinanceSmartChainHex]: Chain.BinanceSmartChain,
250
+ [ChainId.BinanceSmartChain]: Chain.BinanceSmartChain,
251
+ [ChainId.Binance]: Chain.Binance,
252
+ [ChainId.BitcoinCash]: Chain.BitcoinCash,
253
+ [ChainId.Bitcoin]: Chain.Bitcoin,
254
+ [ChainId.Chainflip]: Chain.Chainflip,
255
+ [ChainId.Cosmos]: Chain.Cosmos,
256
+ [ChainId.Dogecoin]: Chain.Dogecoin,
257
+ [ChainId.EthereumHex]: Chain.Ethereum,
258
+ [ChainId.Kujira]: Chain.Kujira,
259
+ [ChainId.Ethereum]: Chain.Ethereum,
260
+ [ChainId.Litecoin]: Chain.Litecoin,
261
+ [ChainId.MayaStagenet]: Chain.Maya,
262
+ [ChainId.Maya]: Chain.Maya,
263
+ [ChainId.OptimismHex]: Chain.Optimism,
264
+ [ChainId.Optimism]: Chain.Optimism,
265
+ [ChainId.Polkadot]: Chain.Polkadot,
266
+ [ChainId.PolygonHex]: Chain.Polygon,
267
+ [ChainId.Polygon]: Chain.Polygon,
268
+ [ChainId.THORChainStagenet]: Chain.THORChain,
269
+ [ChainId.THORChain]: Chain.THORChain,
270
+ };
271
+
272
+ export const ChainToExplorerUrl: Record<Chain, string> = {
273
+ [Chain.Arbitrum]: 'https://arbiscan.io',
274
+ [Chain.Avalanche]: 'https://snowtrace.io',
275
+ [Chain.BinanceSmartChain]: 'https://bscscan.com',
276
+ [Chain.Binance]: 'https://explorer.binance.org',
277
+ [Chain.BitcoinCash]: 'https://www.blockchair.com/bitcoin-cash',
278
+ [Chain.Bitcoin]: 'https://blockchair.com/bitcoin',
279
+ [Chain.Chainflip]: 'https://explorer.polkascan.io/polkadot',
280
+ [Chain.Cosmos]: 'https://cosmos.bigdipper.live',
281
+ [Chain.Dogecoin]: 'https://blockchair.com/dogecoin',
282
+ [Chain.Kujira]: 'https://finder.kujira.network/kaiyo-1',
283
+ [Chain.Ethereum]: 'https://etherscan.io',
284
+ [Chain.Litecoin]: 'https://blockchair.com/litecoin',
285
+ [Chain.Maya]: 'https://www.mayascan.org',
286
+ [Chain.Optimism]: 'https://optimistic.etherscan.io',
287
+ [Chain.Polkadot]: 'https://explorer.polkascan.io/polkadot',
288
+ [Chain.Polygon]: 'https://polygonscan.com',
289
+ [Chain.THORChain]: 'https://runescan.io',
290
+ };
@@ -0,0 +1,26 @@
1
+ export type GetAddressAndPubKeyResponse = {
2
+ bech32_address: string;
3
+ compressed_pk: any;
4
+ error_message: string;
5
+ return_code: number;
6
+ };
7
+
8
+ export type Signature = {
9
+ pub_key: {
10
+ type: string;
11
+ value: string;
12
+ };
13
+ sequence: string;
14
+ signature: string;
15
+ };
16
+
17
+ export enum MemoType {
18
+ BOND = 'BOND',
19
+ DEPOSIT = '+',
20
+ LEAVE = 'LEAVE',
21
+ THORNAME_REGISTER = '~',
22
+ UNBOND = 'UNBOND',
23
+ WITHDRAW = '-',
24
+ OPEN_LOAN = '$+',
25
+ CLOSE_LOAN = '$-',
26
+ }
@@ -0,0 +1,22 @@
1
+ export enum FeeOption {
2
+ Average = 'average',
3
+ Fast = 'fast',
4
+ Fastest = 'fastest',
5
+ }
6
+
7
+ export type WalletTxParams = {
8
+ feeOptionKey?: FeeOption;
9
+ from?: string;
10
+ memo?: string; // optional memo to pass
11
+ recipient: string;
12
+ };
13
+
14
+ export type EVMTxBaseParams<T = bigint> = {
15
+ to?: string;
16
+ from?: string;
17
+ nonce?: number;
18
+ gasLimit?: T;
19
+ data?: string;
20
+ value?: T;
21
+ chainId?: T;
22
+ };
package/src/wallet.ts ADDED
@@ -0,0 +1,28 @@
1
+ export enum WalletOption {
2
+ 'KEYSTORE' = 'KEYSTORE',
3
+ 'KEEPKEY' = 'KEEPKEY',
4
+ 'XDEFI' = 'XDEFI',
5
+ 'METAMASK' = 'METAMASK',
6
+ 'COINBASE_WEB' = 'COINBASE_WEB',
7
+ 'TREZOR' = 'TREZOR',
8
+ 'TRUSTWALLET_WEB' = 'TRUSTWALLET_WEB',
9
+ 'LEDGER' = 'LEDGER',
10
+ 'KEPLR' = 'KEPLR',
11
+ 'OKX' = 'OKX',
12
+ 'OKX_MOBILE' = 'OKX_MOBILE',
13
+ 'BRAVE' = 'BRAVE',
14
+ 'WALLETCONNECT' = 'WALLETCONNECT',
15
+ }
16
+
17
+ export type EVMWalletOptions =
18
+ | WalletOption.BRAVE
19
+ | WalletOption.OKX_MOBILE
20
+ | WalletOption.METAMASK
21
+ | WalletOption.TRUSTWALLET_WEB
22
+ | WalletOption.COINBASE_WEB;
23
+
24
+ export enum LedgerErrorCode {
25
+ NoError = 0x9000,
26
+ LockedDevice = 0x5515,
27
+ TC_NotFound = 65535,
28
+ }