forked from miraclesu/uniswap-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
currency.go
52 lines (44 loc) · 1.26 KB
/
currency.go
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
package entities
import (
"fmt"
"math/big"
"github.com/miraclesu/uniswap-sdk-go/constants"
"github.com/miraclesu/uniswap-sdk-go/utils"
)
/**
* The only instance of the base class `Currency`.
*/
var (
ETHER, _ = newCurrency(constants.Decimals18, "ETH", "Ether")
)
var (
// ErrInvalidCurrency diff currency error
ErrInvalidCurrency = fmt.Errorf("diff currency")
)
// Currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens.
type Currency struct {
Decimals int
Symbol string
Name string
}
/**
* newCurrency an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`.
* @param decimals decimals of the currency
* @param symbol symbol of the currency
* @param name of the currency
*/
func newCurrency(decimals int, symbol, name string) (*Currency, error) {
if err := utils.ValidateSolidityTypeInstance(big.NewInt(int64(decimals)), constants.Uint8); err != nil {
return nil, err
}
return &Currency{
Decimals: decimals,
Symbol: symbol,
Name: name,
}, nil
}
// Equals identifies whether A and B are equal
func (c *Currency) Equals(other *Currency) bool {
return c == other ||
(c.Decimals == other.Decimals && c.Symbol == other.Symbol && c.Name == other.Name)
}