/
baseCurrency.ts
65 lines (59 loc) · 2.05 KB
/
baseCurrency.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import invariant from 'tiny-invariant'
import { Currency } from './currency'
import { Token } from './token'
import { ChainId } from './chain'
/**
* A currency is any fungible financial instrument, including Ether, all ERC20 tokens, and other chain-native currencies
*/
export abstract class BaseCurrency {
/**
* Returns whether the currency is native to the chain and must be wrapped (e.g. Ether)
*/
public abstract readonly isNative: boolean
/**
* Returns whether the currency is a token that is usable in Uniswap without wrapping
*/
public abstract readonly isToken: boolean
/**
* The chain ID on which this currency resides
*/
public readonly chainId: ChainId
/**
* The decimals used in representing currency amounts
*/
public readonly decimals: number
/**
* The symbol of the currency, i.e. a short textual non-unique identifier
*/
public readonly symbol?: string
/**
* The name of the currency, i.e. a descriptive textual non-unique identifier
*/
public readonly name?: string
/**
* Constructs an instance of the base class `BaseCurrency`.
* @param chainId the chain ID on which this currency resides
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
protected constructor(chainId: number, decimals: number, symbol?: string, name?: string) {
invariant(Number.isSafeInteger(chainId), 'CHAIN_ID')
invariant(chainId in ChainId, 'CHAIN_ID_NOT_SUPPORTED')
invariant(decimals >= 0 && decimals < 255 && Number.isInteger(decimals), 'DECIMALS')
this.chainId = chainId
this.decimals = decimals
this.symbol = symbol
this.name = name
}
/**
* Returns whether this currency is functionally equivalent to the other currency
* @param other the other currency
*/
public abstract equals(other: Currency): boolean
/**
* Return the wrapped version of this currency that can be used with the Uniswap contracts. Currencies must
* implement this to be used in Uniswap
*/
public abstract get wrapped(): Token
}