@swapkit/types 1.0.0-rc.37 → 1.0.0-rc.38

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/src/chainflip.ts CHANGED
@@ -19,12 +19,12 @@ export enum ErrorCode {
19
19
  }
20
20
 
21
21
  export enum MemoType {
22
- BOND = 'BOND',
23
- DEPOSIT = '+',
24
- LEAVE = 'LEAVE',
25
- THORNAME_REGISTER = '~',
26
- UNBOND = 'UNBOND',
27
- WITHDRAW = '-',
28
- OPEN_LOAN = '$+',
29
- CLOSE_LOAN = '$-',
22
+ BOND = "BOND",
23
+ DEPOSIT = "+",
24
+ LEAVE = "LEAVE",
25
+ THORNAME_REGISTER = "~",
26
+ UNBOND = "UNBOND",
27
+ WITHDRAW = "-",
28
+ OPEN_LOAN = "$+",
29
+ CLOSE_LOAN = "$-",
30
30
  }
@@ -1,22 +1,16 @@
1
- import type { Chain, CosmosChain, EVMChain, UTXOChain } from './network.ts';
2
- import type { WalletOption } from './wallet.ts';
1
+ import type { Chain, CosmosChain, EVMChain, UTXOChain } from "./network.ts";
2
+ import type { WalletOption } from "./wallet.ts";
3
3
 
4
4
  type ConnectMethodNames =
5
- | 'connectEVMWallet'
6
- | 'connectKeplr'
7
- | 'connectKeystore'
8
- | 'connectKeepkey'
9
- | 'connectLedger'
10
- | 'connectOkx'
11
- | 'connectTrezor'
12
- | 'connectWalletconnect'
13
- | 'connectXDEFI';
14
-
15
- type ChainWallet = {
16
- address: string;
17
- balance: any[];
18
- walletType: WalletOption;
19
- };
5
+ | "connectEVMWallet"
6
+ | "connectKeplr"
7
+ | "connectKeystore"
8
+ | "connectKeepkey"
9
+ | "connectLedger"
10
+ | "connectOkx"
11
+ | "connectTrezor"
12
+ | "connectWalletconnect"
13
+ | "connectXDEFI";
20
14
 
21
15
  export type ConnectConfig = {
22
16
  stagenet?: boolean;
@@ -65,15 +59,12 @@ export type ConnectConfig = {
65
59
  };
66
60
  };
67
61
 
68
- export type AddChainWalletParams = {
69
- chain: Chain;
70
- wallet: ChainWallet;
71
- walletMethods: any;
72
- };
73
-
74
- export type Witness = {
75
- value: number;
76
- script: Buffer;
62
+ export type AddChainWalletParams<T extends Chain> = {
63
+ address: string;
64
+ balance: any[];
65
+ walletType: WalletOption;
66
+ chain: T;
67
+ [key: string]: any;
77
68
  };
78
69
 
79
70
  type ApisType = { [key in UTXOChain]?: string | any } & {
@@ -83,13 +74,18 @@ type ApisType = { [key in UTXOChain]?: string | any } & {
83
74
  };
84
75
 
85
76
  export type ConnectWalletParams = {
86
- addChain: (params: AddChainWalletParams) => void;
77
+ addChain: <T extends Chain>(params: AddChainWalletParams<T>) => void;
87
78
  config: ConnectConfig;
88
79
  rpcUrls: { [chain in Chain]?: string };
89
80
  apis: ApisType;
90
81
  };
91
82
 
92
- export type ExtendParams<WalletConnectMethodNames = ''> = {
83
+ export type Witness = {
84
+ value: number;
85
+ script: Buffer;
86
+ };
87
+
88
+ export type ExtendParams<WalletConnectMethodNames = ""> = {
93
89
  excludedChains?: Chain[];
94
90
  config?: ConnectConfig;
95
91
  rpcUrls?: { [chain in Chain]?: string };
@@ -101,22 +97,22 @@ export type ExtendParams<WalletConnectMethodNames = ''> = {
101
97
  };
102
98
 
103
99
  export enum QuoteMode {
104
- TC_SUPPORTED_TO_TC_SUPPORTED = 'TC-TC',
105
- TC_SUPPORTED_TO_ETH = 'TC-ERC20',
106
- TC_SUPPORTED_TO_AVAX = 'TC-ARC20',
107
- TC_SUPPORTED_TO_BSC = 'TC-BEP20',
108
- ETH_TO_TC_SUPPORTED = 'ERC20-TC',
109
- ETH_TO_ETH = 'ERC20-ERC20',
110
- ETH_TO_AVAX = 'ERC20-ARC20',
111
- ETH_TO_BSC = 'ERC20-BEP20',
112
- AVAX_TO_TC_SUPPORTED = 'ARC20-TC',
113
- AVAX_TO_ETH = 'ARC20-ERC20',
114
- AVAX_TO_AVAX = 'ARC20-ARC20',
115
- AVAX_TO_BSC = 'ARC20-BEP20',
116
- BSC_TO_TC_SUPPORTED = 'BEP20-TC',
117
- BSC_TO_ETH = 'BEP20-ERC20',
118
- BSC_TO_AVAX = 'BEP20-ARC20',
119
- BSC_TO_BSC = 'BEP20-BEP20',
100
+ TC_SUPPORTED_TO_TC_SUPPORTED = "TC-TC",
101
+ TC_SUPPORTED_TO_ETH = "TC-ERC20",
102
+ TC_SUPPORTED_TO_AVAX = "TC-ARC20",
103
+ TC_SUPPORTED_TO_BSC = "TC-BEP20",
104
+ ETH_TO_TC_SUPPORTED = "ERC20-TC",
105
+ ETH_TO_ETH = "ERC20-ERC20",
106
+ ETH_TO_AVAX = "ERC20-ARC20",
107
+ ETH_TO_BSC = "ERC20-BEP20",
108
+ AVAX_TO_TC_SUPPORTED = "ARC20-TC",
109
+ AVAX_TO_ETH = "ARC20-ERC20",
110
+ AVAX_TO_AVAX = "ARC20-ARC20",
111
+ AVAX_TO_BSC = "ARC20-BEP20",
112
+ BSC_TO_TC_SUPPORTED = "BEP20-TC",
113
+ BSC_TO_ETH = "BEP20-ERC20",
114
+ BSC_TO_AVAX = "BEP20-ARC20",
115
+ BSC_TO_BSC = "BEP20-BEP20",
120
116
  }
121
117
 
122
118
  export type Asset = {
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
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';
1
+ export { erc20ABI } from "./abis/erc20.ts";
2
+ export { TCAvalancheDepositABI, TCBscDepositABI, TCEthereumVaultAbi } from "./abis/tcEthVault.ts";
3
+ export * from "./commonTypes.ts";
4
+ export * from "./network.ts";
5
+ export * from "./thorchain.ts";
6
+ export * from "./transactions.ts";
7
+ export * from "./wallet.ts";
package/src/network.ts CHANGED
@@ -1,32 +1,32 @@
1
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
- Dash = 'DASH',
10
- Dogecoin = 'DOGE',
11
- Ethereum = 'ETH',
12
- Kujira = 'KUJI',
13
- Litecoin = 'LTC',
14
- Maya = 'MAYA',
15
- Optimism = 'OP',
16
- Polkadot = 'DOT',
17
- Chainflip = 'FLIP',
18
- Polygon = 'MATIC',
19
- THORChain = 'THOR',
2
+ Arbitrum = "ARB",
3
+ Avalanche = "AVAX",
4
+ Binance = "BNB",
5
+ BinanceSmartChain = "BSC",
6
+ Bitcoin = "BTC",
7
+ BitcoinCash = "BCH",
8
+ Cosmos = "GAIA",
9
+ Dash = "DASH",
10
+ Dogecoin = "DOGE",
11
+ Ethereum = "ETH",
12
+ Kujira = "KUJI",
13
+ Litecoin = "LTC",
14
+ Maya = "MAYA",
15
+ Optimism = "OP",
16
+ Polkadot = "DOT",
17
+ Chainflip = "FLIP",
18
+ Polygon = "MATIC",
19
+ THORChain = "THOR",
20
20
  }
21
21
  type ChainNameType = keyof typeof Chain;
22
22
 
23
23
  export enum ContractAddress {
24
- ARB = '0x0000000000000000000000000000000000000000',
25
- AVAX = '0x0000000000000000000000000000000000000000',
26
- ETH = '0x0000000000000000000000000000000000000000',
27
- BSC = '0x0000000000000000000000000000000000000000',
28
- MATIC = '0x0000000000000000000000000000000000001010',
29
- OP = '0x4200000000000000000000000000000000000042',
24
+ ARB = "0x0000000000000000000000000000000000000000",
25
+ AVAX = "0x0000000000000000000000000000000000000000",
26
+ ETH = "0x0000000000000000000000000000000000000000",
27
+ BSC = "0x0000000000000000000000000000000000000000",
28
+ MATIC = "0x0000000000000000000000000000000000001010",
29
+ OP = "0x4200000000000000000000000000000000000042",
30
30
  }
31
31
 
32
32
  export enum DerivationPath {
@@ -38,9 +38,9 @@ export enum DerivationPath {
38
38
  BTC = "m/84'/0'/0'/0",
39
39
  DASH = "m/44'/5'/0'/0",
40
40
  DOGE = "m/44'/3'/0'/0",
41
- DOT = '////',
41
+ DOT = "////",
42
42
  ETH = "m/44'/60'/0'/0",
43
- FLIP = '////',
43
+ FLIP = "////",
44
44
  GAIA = "m/44'/118'/0'/0",
45
45
  KUJI = "m/44'/118'/0'/0",
46
46
  LTC = "m/84'/2'/0'/0",
@@ -177,66 +177,66 @@ export const TCSupportedChains = [
177
177
  export const TCSupportedChainList = TCSupportedChains;
178
178
 
179
179
  export enum ChainId {
180
- Arbitrum = '42161',
181
- ArbitrumHex = '0xa4b1',
182
- Avalanche = '43114',
183
- AvalancheHex = '0xa86a',
184
- Binance = 'Binance-Chain-Tigris',
185
- BinanceSmartChain = '56',
186
- BinanceSmartChainHex = '0x38',
187
- Bitcoin = 'bitcoin',
188
- BitcoinCash = 'bitcoincash',
189
- Chainflip = 'chainflip',
190
- Cosmos = 'cosmoshub-4',
191
- Dash = 'dash',
192
- Dogecoin = 'dogecoin',
193
- Kujira = 'kaiyo-1',
194
- Ethereum = '1',
195
- EthereumHex = '0x1',
196
- Litecoin = 'litecoin',
197
- Maya = 'mayachain-mainnet-v1',
198
- MayaStagenet = 'mayachain-stagenet-v1',
199
- Optimism = '10',
200
- OptimismHex = '0xa',
201
- Polkadot = 'polkadot',
202
- Polygon = '137',
203
- PolygonHex = '0x89',
204
- THORChain = 'thorchain-mainnet-v1',
205
- THORChainStagenet = 'thorchain-stagenet-v2',
180
+ Arbitrum = "42161",
181
+ ArbitrumHex = "0xa4b1",
182
+ Avalanche = "43114",
183
+ AvalancheHex = "0xa86a",
184
+ Binance = "Binance-Chain-Tigris",
185
+ BinanceSmartChain = "56",
186
+ BinanceSmartChainHex = "0x38",
187
+ Bitcoin = "bitcoin",
188
+ BitcoinCash = "bitcoincash",
189
+ Chainflip = "chainflip",
190
+ Cosmos = "cosmoshub-4",
191
+ Dash = "dash",
192
+ Dogecoin = "dogecoin",
193
+ Kujira = "kaiyo-1",
194
+ Ethereum = "1",
195
+ EthereumHex = "0x1",
196
+ Litecoin = "litecoin",
197
+ Maya = "mayachain-mainnet-v1",
198
+ MayaStagenet = "mayachain-stagenet-v1",
199
+ Optimism = "10",
200
+ OptimismHex = "0xa",
201
+ Polkadot = "polkadot",
202
+ Polygon = "137",
203
+ PolygonHex = "0x89",
204
+ THORChain = "thorchain-mainnet-v1",
205
+ THORChainStagenet = "thorchain-stagenet-v2",
206
206
  }
207
207
 
208
208
  export enum RPCUrl {
209
- Arbitrum = 'https://arb1.arbitrum.io/rpc',
210
- Avalanche = 'https://node-router.thorswap.net/avalanche-c',
211
- Binance = '',
212
- BinanceSmartChain = 'https://bsc-dataseed.binance.org',
213
- Bitcoin = 'https://node-router.thorswap.net/bitcoin',
214
- BitcoinCash = 'https://node-router.thorswap.net/bitcoin-cash',
215
- Chainflip = 'wss://mainnet-archive.chainflip.io',
216
- Cosmos = 'https://node-router.thorswap.net/cosmos/rpc',
217
- Dash = 'https://node-router.thorswap.net/dash',
218
- Dogecoin = 'https://node-router.thorswap.net/dogecoin',
219
- Ethereum = 'https://node-router.thorswap.net/ethereum',
220
- Kujira = 'https://rpc-kujira.synergynodes.com/',
221
- Litecoin = 'https://node-router.thorswap.net/litecoin',
222
- Maya = 'https://tendermint.mayachain.info',
223
- MayaStagenet = 'https://stagenet.tendermint.mayachain.info',
224
- Optimism = 'https://mainnet.optimism.io',
225
- Polkadot = 'wss://rpc.polkadot.io',
226
- Polygon = 'https://polygon-rpc.com',
227
- THORChain = 'https://rpc.thorswap.net',
228
- THORChainStagenet = 'https://stagenet-rpc.ninerealms.com',
209
+ Arbitrum = "https://arb1.arbitrum.io/rpc",
210
+ Avalanche = "https://node-router.thorswap.net/avalanche-c",
211
+ Binance = "",
212
+ BinanceSmartChain = "https://bsc-dataseed.binance.org",
213
+ Bitcoin = "https://node-router.thorswap.net/bitcoin",
214
+ BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash",
215
+ Chainflip = "wss://mainnet-archive.chainflip.io",
216
+ Cosmos = "https://node-router.thorswap.net/cosmos/rpc",
217
+ Dash = "https://node-router.thorswap.net/dash",
218
+ Dogecoin = "https://node-router.thorswap.net/dogecoin",
219
+ Ethereum = "https://node-router.thorswap.net/ethereum",
220
+ Kujira = "https://rpc-kujira.synergynodes.com/",
221
+ Litecoin = "https://node-router.thorswap.net/litecoin",
222
+ Maya = "https://tendermint.mayachain.info",
223
+ MayaStagenet = "https://stagenet.tendermint.mayachain.info",
224
+ Optimism = "https://mainnet.optimism.io",
225
+ Polkadot = "wss://rpc.polkadot.io",
226
+ Polygon = "https://polygon-rpc.com",
227
+ THORChain = "https://rpc.thorswap.net",
228
+ THORChainStagenet = "https://stagenet-rpc.ninerealms.com",
229
229
  }
230
230
 
231
231
  export enum ApiUrl {
232
- Cosmos = 'https://node-router.thorswap.net/cosmos/rest',
233
- Kujira = 'https://lcd-kujira.synergynodes.com/',
234
- MayanodeMainnet = 'https://mayanode.mayachain.info',
235
- MayanodeStagenet = 'https://stagenet.mayanode.mayachain.info',
236
- ThornodeMainnet = 'https://thornode.thorswap.net',
237
- ThornodeStagenet = 'https://stagenet-thornode.ninerealms.com',
238
- ThorswapApi = 'https://api.thorswap.net',
239
- ThorswapStatic = 'https://static.thorswap.net',
232
+ Cosmos = "https://node-router.thorswap.net/cosmos/rest",
233
+ Kujira = "https://lcd-kujira.synergynodes.com/",
234
+ MayanodeMainnet = "https://mayanode.mayachain.info",
235
+ MayanodeStagenet = "https://stagenet.mayanode.mayachain.info",
236
+ ThornodeMainnet = "https://thornode.thorswap.net",
237
+ ThornodeStagenet = "https://stagenet-thornode.ninerealms.com",
238
+ ThorswapApi = "https://api.thorswap.net",
239
+ ThorswapStatic = "https://static.thorswap.net",
240
240
  }
241
241
 
242
242
  const chains = Object.values(Chain) as Chain[];
@@ -309,22 +309,22 @@ export const ChainIdToChain: Record<ChainId, Chain> = {
309
309
  };
310
310
 
311
311
  export const ChainToExplorerUrl: Record<Chain, string> = {
312
- [Chain.Arbitrum]: 'https://arbiscan.io',
313
- [Chain.Avalanche]: 'https://snowtrace.io',
314
- [Chain.BinanceSmartChain]: 'https://bscscan.com',
315
- [Chain.Binance]: 'https://explorer.binance.org',
316
- [Chain.BitcoinCash]: 'https://www.blockchair.com/bitcoin-cash',
317
- [Chain.Bitcoin]: 'https://blockchair.com/bitcoin',
318
- [Chain.Chainflip]: 'https://explorer.polkascan.io/polkadot',
319
- [Chain.Cosmos]: 'https://cosmos.bigdipper.live',
320
- [Chain.Dash]: 'https://blockchair.com/dash',
321
- [Chain.Dogecoin]: 'https://blockchair.com/dogecoin',
322
- [Chain.Kujira]: 'https://finder.kujira.network/kaiyo-1',
323
- [Chain.Ethereum]: 'https://etherscan.io',
324
- [Chain.Litecoin]: 'https://blockchair.com/litecoin',
325
- [Chain.Maya]: 'https://www.mayascan.org',
326
- [Chain.Optimism]: 'https://optimistic.etherscan.io',
327
- [Chain.Polkadot]: 'https://explorer.polkascan.io/polkadot',
328
- [Chain.Polygon]: 'https://polygonscan.com',
329
- [Chain.THORChain]: 'https://runescan.io',
312
+ [Chain.Arbitrum]: "https://arbiscan.io",
313
+ [Chain.Avalanche]: "https://snowtrace.io",
314
+ [Chain.BinanceSmartChain]: "https://bscscan.com",
315
+ [Chain.Binance]: "https://explorer.binance.org",
316
+ [Chain.BitcoinCash]: "https://www.blockchair.com/bitcoin-cash",
317
+ [Chain.Bitcoin]: "https://blockchair.com/bitcoin",
318
+ [Chain.Chainflip]: "https://explorer.polkascan.io/polkadot",
319
+ [Chain.Cosmos]: "https://cosmos.bigdipper.live",
320
+ [Chain.Dash]: "https://blockchair.com/dash",
321
+ [Chain.Dogecoin]: "https://blockchair.com/dogecoin",
322
+ [Chain.Kujira]: "https://finder.kujira.network/kaiyo-1",
323
+ [Chain.Ethereum]: "https://etherscan.io",
324
+ [Chain.Litecoin]: "https://blockchair.com/litecoin",
325
+ [Chain.Maya]: "https://www.mayascan.org",
326
+ [Chain.Optimism]: "https://optimistic.etherscan.io",
327
+ [Chain.Polkadot]: "https://explorer.polkascan.io/polkadot",
328
+ [Chain.Polygon]: "https://polygonscan.com",
329
+ [Chain.THORChain]: "https://runescan.io",
330
330
  };
package/src/thorchain.ts CHANGED
@@ -15,12 +15,12 @@ export type Signature = {
15
15
  };
16
16
 
17
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 = '$-',
18
+ BOND = "BOND",
19
+ DEPOSIT = "+",
20
+ LEAVE = "LEAVE",
21
+ THORNAME_REGISTER = "~",
22
+ UNBOND = "UNBOND",
23
+ WITHDRAW = "-",
24
+ OPEN_LOAN = "$+",
25
+ CLOSE_LOAN = "$-",
26
26
  }
@@ -1,7 +1,7 @@
1
1
  export enum FeeOption {
2
- Average = 'average',
3
- Fast = 'fast',
4
- Fastest = 'fastest',
2
+ Average = "average",
3
+ Fast = "fast",
4
+ Fastest = "fastest",
5
5
  }
6
6
 
7
7
  export type WalletTxParams = {
package/src/wallet.ts CHANGED
@@ -1,17 +1,17 @@
1
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',
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
15
  }
16
16
 
17
17
  export type EVMWalletOptions =
@@ -1,75 +0,0 @@
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
- }
@@ -1,72 +0,0 @@
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: 4 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.SWAP_AMOUNT_TOO_LOW]: 'Swap amount too low for this pair.',
30
- [ERROR_CODE.DESTINATION_ADDRESS_SMART_CONTRACT]: 'Destination address is a smart contract.',
31
- [ERROR_CODE.BUY_AMOUNT_MUST_BE_POSITIVE_INTEGER]: 'Buy amount must be a positive integer.',
32
- [ERROR_CODE.INVALID_PROVIDER]: 'Invalid provider {0}.',
33
- [ERROR_CODE.MISSING_CROSS_CHAIN_PROVIDER]: 'Missing cross-chain provider.',
34
- [ERROR_CODE.MISSING_AVAX_PROVIDER]: 'Missing AVAX provider.',
35
- [ERROR_CODE.MISSING_BSC_PROVIDER]: 'Missing BSC provider.',
36
- [ERROR_CODE.MISSING_ETH_PROVIDER]: 'Missing ETH provider.',
37
- [ERROR_CODE.MISSING_ARB_PROVIDER]: 'Missing ARB provider.',
38
- [ERROR_CODE.INVALID_PROVIDER_FOR_SWAP_OUT]: 'Invalid provider for swap out.',
39
- [ERROR_CODE.INVALID_CHAIN]: 'Invalid chain {0}.',
40
- [ERROR_CODE.INVALID_ASSET]: 'Invalid asset {0}.',
41
- [ERROR_CODE.UNSUPPORTED_CHAIN]: 'Unsupported chain {0}.',
42
- [ERROR_CODE.UNSUPPORTED_ASSET]: 'Unsupported asset {0}.',
43
- [ERROR_CODE.UNSUPPORTED_ASSET_FOR_SWAPOUT]: 'Unsupported asset {0} for swap out.',
44
- [ERROR_CODE.THORNODE_QUOTE_GENERIC_ERROR]: 'ThorNode quote generic error.',
45
- [ERROR_CODE.INVALID_SOURCE_ADDRESS]: 'Invalid source address {0}',
46
- [ERROR_CODE.INVALID_DESTINATION_ADDRESS]: 'Invalid destination address {0}',
47
- [ERROR_CODE.NOT_ENOUGH_SYNTH_BALANCE]:
48
- "Source address doesn't have enough synth balance for this quote.",
49
- [ERROR_CODE.SYNTH_MINTING_CAP_REACHED]: 'Synth minting cap reached.',
50
- [ERROR_CODE.INVALID_QUOTE_MODE]: 'Invalid quote mode.',
51
- [ERROR_CODE.NO_QUOTES]: 'No quotes to service this request.',
52
- [ERROR_CODE.SERVICE_UNAVAILABLE_GENERIC]: 'Service unavailable.',
53
- [ERROR_CODE.MISSING_GAS_DATA_GENERIC]: 'Missing gas data.',
54
- [ERROR_CODE.MISSING_TOKEN_INFO_GENERIC]: 'Missing token info.',
55
- [ERROR_CODE.CANT_FIND_TOKEN_LIST]: "Can't find tokenlist {0}.",
56
- [ERROR_CODE.NO_PRICE]: 'No price for asset {0}.',
57
- [ERROR_CODE.PRICE_IS_STALE]: 'Price is stale for asset {0}.',
58
- [ERROR_CODE.ADDRESS_NOT_WHITELISTED]: 'Address {0} not whitelisted for airdrop.',
59
- [ERROR_CODE.ADDRESS_ALREADY_CLAIMED]: 'Address {0} already claimed the airdrop.',
60
- };
61
-
62
- export const getDisplayMessage = (code: ERROR_CODE, displayMessageParams: string[]) => {
63
- let displayMessage = ERROR_DISPLAY_MESSAGES[code];
64
-
65
- if (!displayMessage) return '';
66
-
67
- for (let i = 0; i < displayMessageParams.length; i++) {
68
- displayMessage = displayMessage?.replace(`{${i}}`, displayMessageParams[i]) ?? '';
69
- }
70
-
71
- return displayMessage;
72
- };
@@ -1,2 +0,0 @@
1
- export * from './apiError.ts';
2
- export * from './types.ts';