@yaswap/cryptoassets 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,10 @@
1
+ import { ChainId } from '../types'
2
+ import dapps from './dapps.json'
3
+
4
+ interface OriginChains {
5
+ [index: string]: ChainId[]
6
+ }
7
+
8
+ const dappChains = dapps as OriginChains
9
+
10
+ export { dappChains }
package/src/index.ts ADDED
@@ -0,0 +1,29 @@
1
+ import BigNumber from 'bignumber.js'
2
+ import { assets, testnetAssets, chainToTokenAddressMap, chainToTestnetTokenAddressMap } from './assets'
3
+ import { chains, isEthereumChain } from './chains'
4
+ import { dappChains } from './dapps'
5
+ import { Asset, ChainId } from './types'
6
+
7
+ function unitToCurrency(asset: Asset, value: number | BigNumber): BigNumber {
8
+ const multiplier = new BigNumber(10).pow(asset.decimals)
9
+ return new BigNumber(value).dividedBy(multiplier)
10
+ }
11
+
12
+ function currencyToUnit(asset: Asset, value: number | BigNumber): BigNumber {
13
+ const multiplier = new BigNumber(10).pow(asset.decimals)
14
+ return new BigNumber(value).times(multiplier)
15
+ }
16
+
17
+ export {
18
+ assets,
19
+ chainToTokenAddressMap,
20
+ testnetAssets,
21
+ chainToTestnetTokenAddressMap,
22
+ chains,
23
+ dappChains,
24
+ isEthereumChain,
25
+ unitToCurrency,
26
+ currencyToUnit,
27
+ Asset,
28
+ ChainId
29
+ }
package/src/types.ts ADDED
@@ -0,0 +1,47 @@
1
+ export interface Chain {
2
+ name: string
3
+ code: string
4
+ nativeAsset: string
5
+ fees: {
6
+ unit: string
7
+ }
8
+ safeConfirmations: number
9
+ txFailureTimeout: number
10
+ isValidAddress: (address: string, network?: string) => boolean
11
+ formatAddress: (address: string, network?: string) => string
12
+ isValidTransactionHash: (hash: string) => boolean
13
+ formatTransactionHash: (hash: string) => string
14
+ }
15
+
16
+ export type AssetType = 'native' | 'erc20'
17
+
18
+ export enum ChainId {
19
+ Bitcoin = 'bitcoin',
20
+ BitcoinCash = 'bitcoin_cash',
21
+ Ethereum = 'ethereum',
22
+ Rootstock = 'rsk',
23
+ BinanceSmartChain = 'bsc',
24
+ Near = 'near',
25
+ Polygon = 'polygon',
26
+ Arbitrum = 'arbitrum',
27
+ Solana = 'solana',
28
+ Fuse = 'fuse',
29
+ Terra = 'terra',
30
+ Avalanche = 'avalanche',
31
+ Yacoin = 'yacoin'
32
+ }
33
+
34
+ export interface Asset {
35
+ name: string
36
+ chain: ChainId
37
+ type: AssetType
38
+ code: string
39
+ decimals: number
40
+ coinGeckoId?: string
41
+ color?: string
42
+ contractAddress?: string // ERC20 only
43
+ matchingAsset?: string
44
+ feeAsset?: string
45
+ }
46
+
47
+ export type AssetMap = Record<string, Asset>
@@ -0,0 +1,4 @@
1
+ declare module 'bitcoin-address-validation' {
2
+ export function validate(address: string, network?: string): boolean
3
+ export = validate
4
+ }
@@ -0,0 +1 @@
1
+ declare module 'cashaddrjs'