💰 currencies
This crate provides a generic Currency
and corresponding Amount
type that can handle basic
arithmetic operations and formatting of arbitrary currencies and cryptocurrencies. Main
features include:
Features
- Built-in support for all ISO-4217 currencies with proper precision and formatting
- Support for a variety of cryptocurrencies, also with proper underlying data types and
formatting. Accurate implementations for
ETH
,BTC
,DOT
,KSM
andAAVE
are included. - The ability to specify whether an
Amount
is forced to only make use of unchecked math, or not, at compile-time. Normally this is impossible to control since thecore:ops
operators are set up such that the checked operators require their unchecked counterparts to be implemented on the host type, however I have gone out of my way to make it possible to implement unchecked math only, and control it easily with aAmount<ETH, Checked>
-style switch. This is extremely desirable for scenarios where panicking could cause a catastrophic issue, and the way it is set up, programmers are forced to consume theOption
returned by the checked ops. - An easy-to-use macro,
define_currency!
that can define new currencies on-the-fly. - A painstakingly wrapped version of
primitive_types::U256
that implements many more usefulnum-traits
andnum-integer
traits than what Parity includes with thenum-traits
feature, and are often required when working with amounts of a currency. - All provided currencies implement most useful
num-traits
andnum-integer
traits. - Thorough testing of all of the above.
Examples
Future Work
- Additional macros for defining an
Amount
via a decimal literal - Currency conversion facilities, possibly including an online data source
- Add
Signedness
support toAmount
- Additional testing
- Support for negative amounts via an additional const generic defaulting to
Positive