mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 19:55:54 +00:00
Merge pull request #281 from mDuo13/doc1088
"Money in the XRP Ledger" intro and related
This commit is contained in:
121
content/concept-demurrage.md
Normal file
121
content/concept-demurrage.md
Normal file
@@ -0,0 +1,121 @@
|
||||
# Demurrage
|
||||
|
||||
**Warning:** Demurrage is a deprecated feature with no ongoing support. This page describes historical behavior of older versions of Ripple software.
|
||||
|
||||
[Demurrage](http://en.wikipedia.org/wiki/Demurrage_%28currency%29) is a negative interest rate on assets held that represents the cost of holding those assets. To represent the demurrage on an issued currency in the XRP Ledger, you can track it using a custom [currency code](reference-currency.html#currency-codes) that indicates the demurrage rate. This effectively creates separate versions of the currency for each varying amount of demurrage. Client applications can support this by representing the demurraging currency code with an annual percentage rate alongside the currency code. For example: "XAU (-0.5%pa)".
|
||||
|
||||
## Representing Demurraging Currency Amounts
|
||||
|
||||
Rather than continuously update all amounts in the XRP Ledger, this approach divides amounts of interest-bearing or demurraging currency into two types of amount: "ledger values" recorded in the XRP Ledger, and "display values" shown to people. The "ledger values" represent the value of the currency at a fixed point, namely the "Ripple Epoch" of midnight January 1, 2000. The "display values" represent the amount at a later point in time (usually the current time) after calculating continuous interest or demurrage from the Ripple Epoch until that time.
|
||||
|
||||
**Tip:** You can think of demurrage as similar to inflation, where the value of all assets affected by it decreases over time, but the ledger always holds amounts in year-2000 values. This does not reflect actual real-world inflation; demurrage is more like hypothetical inflation at a constant rate.
|
||||
|
||||
Thus, client software must apply two conversions:
|
||||
|
||||
- Taking display values at a given time and converting them to ledger values to be recorded.
|
||||
- Taking ledger values and converting them to a display value at a given point in time.
|
||||
|
||||
### Calculating Demurrage
|
||||
|
||||
The full formula for calculating demurrage on a currency is as follows:
|
||||
|
||||
```
|
||||
D = A × ( e ^ (t ÷ τ) )
|
||||
```
|
||||
|
||||
- **D** is the amount after demurrage
|
||||
- **A** is the pre-demurrage amount as recorded in the global ledger
|
||||
- **e** is Euler's number
|
||||
- **t** is the number of seconds since the Ripple Epoch (0:00 on January 1, 2000 UTC)
|
||||
- **τ** is the e-folding time in seconds. This value is [calculated from the desired interest rate](#calculating-e-folding-time).
|
||||
|
||||
To convert between display amounts and ledger amounts, you can use the following steps:
|
||||
|
||||
1. Calculate the value of `( e ^ (t ÷ τ) )`. We call this number the "demurrage coefficient". The demurrage coefficient is always relative to a specific time, such as the current time.
|
||||
2. Apply it to the amount to convert:
|
||||
- To convert ledger values to display values, multiply by the demurrage coefficient.
|
||||
- To convert display values to ledger values, divide by the demurrage coefficient.
|
||||
3. If necessary, adjust the resulting value so that it can be represented to the desired accuracy. Ledger values are limited to 15 decimal digits of precision, according to the XRP Ledger's [issued currency format](reference-currency.html#issued-currency-precision).
|
||||
|
||||
|
||||
## Interest-Bearing Currency Code Format
|
||||
|
||||
Rather than using the [standard currency code format](reference-currency.html#currency-codes), currencies that have positive interest or negative interest (demurrage) use a 160-bit currency code in the following format:
|
||||
|
||||

|
||||
|
||||
1. The first 8 bits must be `0x01`.
|
||||
2. The next 24 bits represent 3 characters of ASCII.
|
||||
This is expected to be an ISO 4217 code. It supports the same characters as the standard format's ASCII characters.
|
||||
3. The next 24 bits MUST be all `0`s.
|
||||
4. The next 64 bits are the interest rate of the currency, represented as "[e-folding time](http://en.wikipedia.org/wiki/E-folding)" in an IEEE 754 double format.
|
||||
5. The next 24 bits are reserved and should be all `0`s.
|
||||
|
||||
### Calculating e-folding Time
|
||||
|
||||
To convert between ledger amounts and display amounts, or to calculate a currency code for an interest-bearing/demurraging currency, you need the interest rate as an "e-folding time". The e-folding time is the amount of time it takes a quantity to increase by a factor of _e_ (Euler's number). By convention, e-folding time is written as the letter **τ** in formulas.
|
||||
|
||||
To calculate an e-folding time for a given rate of annual percent interest:
|
||||
|
||||
1. Add the interest rate to 100% to get the percentage of the initial amount present after applying annual interest. For demurrage, use a negative interest rate. For example, 0.5% demurrage would be an interest rate of -0.5%, resulting in **99.5%** remaining.
|
||||
2. Represent the percentage as a decimal. For example, 99.5% becomes **0.995**.
|
||||
3. Take the natural log of that number. For example, **ln(0.995) = -0.005012541823544286**. (This number is positive if the initial interest rate was positive, and negative if the interest rate was negative.)
|
||||
4. Take the number of seconds in one year (31536000) and divide by the natural log result from the previous step. For example, **31536000 ÷ -0.005012541823544286 = -6291418827.045599**. This result is the e-folding time in seconds.
|
||||
|
||||
**Note:** By convention, Ripple's interest/demurrage rules use a fixed number of seconds per year (31536000), which is not adjusted for leap days or leap seconds.
|
||||
|
||||
## Client Support
|
||||
|
||||
To support interest-bearing and demurraging currencies, client applications must implement several features:
|
||||
|
||||
- When displaying the amount of a demurraging currency retrieved from ledger or transaction data, the client must convert from the ledger value to the display value. (With demurrage, the display values are smaller than the ledger values.)
|
||||
|
||||
- When accepting input for a demurraging currency, the client must convert amounts from a display format to the ledger format. (With demurrage, the ledger values are are larger than the user input value.) The client must use the ledger value when creating payments, offers, and other types of transaction.
|
||||
|
||||
- Clients must distinguish between currencies that do and do not have interest or demurrage, and among currencies that have different rates of interest or demurrage. Clients should be able to parse the [Interest-Bearing Currency Code Format](#interest-bearing-currency-code-format) into a display such as "XAU (-0.5% pa)".
|
||||
|
||||
### ripple-lib Support
|
||||
|
||||
Demurrage was supported in ripple-lib versions **0.7.37** through **0.12.9**. Demurrage is ***not supported*** in [RippleAPI](reference-rippleapi.html).
|
||||
|
||||
The following code samples demonstrate how to use compatible versions of ripple-lib to convert between ledger values and display values. Also see the [Ripple Demurrage Calculator](https://ripple.github.io/ripple-demurrage-tool/).
|
||||
|
||||
To convert from a display value to a ledger value, use `Amount.from_human()`:
|
||||
|
||||
```js
|
||||
// create an Amount object for the display amount of the demurring currency
|
||||
// and pass in a reference_date that represents the current date
|
||||
// (in this case, ledger value 10 XAU with 0.5% annual demurrage,
|
||||
// at 2017-11-04T00:07:50Z.)
|
||||
var demAmount = ripple.Amount.from_human('10 0158415500000000C1F76FF6ECB0BAC600000000',
|
||||
{reference_date:563069270});
|
||||
|
||||
// set the issuer
|
||||
demAmount.set_issuer("rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh");
|
||||
|
||||
// get the JSON format for the ledger amount
|
||||
console.log(demAmount.to_json());
|
||||
|
||||
// { "value": "10.93625123082769",
|
||||
// "currency": "0158415500000000C1F76FF6ECB0BAC600000000",
|
||||
// "issuer": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" }
|
||||
```
|
||||
|
||||
To convert from a ledger value to a display value:
|
||||
|
||||
```js
|
||||
// create an Amount object with the ledger value,
|
||||
ledgerAmount = ripple.Amount.from_json({
|
||||
"currency": "015841551A748AD2C1F76FF6ECB0CCCD00000000",
|
||||
"issuer": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
|
||||
"value": "10.93625123082769"})
|
||||
|
||||
// apply interest up to the current time to get the display amount
|
||||
var displayAmount = demAmount.applyInterest(new Date());
|
||||
|
||||
console.log(displayAmount.to_json());
|
||||
|
||||
// { "value": "9.999998874657716",
|
||||
// "currency": "0158415500000000C1F76FF6ECB0BAC600000000",
|
||||
// "issuer": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" }
|
||||
```
|
||||
47
content/concept-money.md
Normal file
47
content/concept-money.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Money in the XRP Ledger
|
||||
|
||||
The XRP Ledger is an advanced blockchain-like system that was designed to let people transact in multiple currencies. Users of the XRP Ledger can seamlessly track, trade, and settle multiple currencies in an exchange that's as decentralized as the network itself. Users can issue their own currency-like digital assets, which may or may not represent obligations owed outside the XRP Ledger. Tying it all together is XRP, the XRP Ledger's native cryptocurrency, which acts as a medium of exchange and serves anti-spam purposes.
|
||||
|
||||
## XRP
|
||||
|
||||
**XRP** is the native cryptocurrency of the XRP Ledger. All [accounts](concept-accounts.html) in the XRP Ledger can send XRP among one another and must hold a minimum amount of XRP as a [reserve](concept-reserves.html). XRP can be sent directly from any XRP Ledger address to any other, without needing a gateway or liquidity provider. This helps make XRP a convenient bridge currency.
|
||||
|
||||
Some advanced features of the XRP Ledger, such as [Escrow](concept-escrow.html) and [Payment Channels](tutorial-paychan.html), only work with XRP. Order book [autobridging](https://ripple.com/dev-blog/introducing-offer-autobridging/) uses XRP to deepen liquidity in the decentralized exchange by merging order books of two issued currencies with XRP order books to create synthetic combined order books. (For example, autobridging matches USD:XRP and XRP:EUR orders to augment USD:EUR order books.)
|
||||
|
||||
XRP also serves as a protective measure against spamming the network. All XRP Ledger addresses need a small amount of XRP to pay the costs of maintaining the XRP Ledger. The [transaction cost](concept-transaction-cost.html) and [reserve](concept-reserves.html) are neutral fees denominated in XRP and not paid to any party. In the ledger's data format, XRP is stored in [AccountRoot objects](reference-ledger-format.html#accountroot).
|
||||
|
||||
For more information on XRP's use cases, benefits, and news, see the [XRP Portal](https://ripple.com/xrp-portal/).
|
||||
|
||||
### XRP Properties
|
||||
|
||||
The very first ledger contained 100 billion XRP, and no new XRP can be created. XRP can be destroyed by [transaction costs](concept-transaction-cost.html) or lost by sending it to addresses for which no one holds a key, so XRP is slightly [deflationary](https://en.wikipedia.org/wiki/Deflation) by nature. No need to worry about running out, though: at the current rate of destruction, it would take at least 70,000 years to destroy all XRP, and XRP [prices and fees can be adjusted](concept-fee-voting.html) as the total supply of XRP changes.
|
||||
|
||||
In technical contexts, XRP is measured precisely to the nearest 0.000001 XRP, called a "drop" of XRP. The [`rippled` APIs](reference-rippled.html) require all XRP amounts to be specified in drops of XRP. For example, 1 XRP is represented as `1000000` drops. For more detailed information, see the [currency format reference](reference-currency.html).
|
||||
|
||||
## Issued Currencies
|
||||
|
||||
All currencies other than XRP are represented as **issued currencies**. These digital assets (sometimes called "issuances" or "IOUs") are tracked in accounting relationships, called "trust lines," between addresses. Issued currencies are typically considered as liabilities from one perspective and assets from the other, so the balance of a trust line is negative or positive depending on which side you view it from. Any address may freely issue (non-XRP) currencies, limited only by how much other addresses are willing to hold.
|
||||
|
||||
Issued currencies can "ripple" through multiple issuers and holders if they use the same currency code. This is useful in some cases, but can cause unexpected and undesirable behavior in others. You can use the [NoRipple flag](concept-noripple.html) on trust lines to prevent those trust lines from rippling.
|
||||
|
||||
Issued currencies can be traded with XRP or each other in the XRP Ledger's decentralized exchange.
|
||||
|
||||
In the typical model, an issued currency is tied to holdings of currency or other assets outside the XRP Ledger. The issuer of the currency, called a _gateway_, handles deposits and withdrawals to exchange currency outside the XRP Ledger for equivalent balances of issued currency in the XRP Ledger. For more information on how to run a gateway, see the [Gateway Guide](tutorial-gateway-guide.html).
|
||||
|
||||
There are other use cases for issued currencies in the XRP Ledger. For example, you can create an "Initial Coin Offering" (ICO) by issuing a fixed amount of currency to a secondary address, then "throwing away the key" to the issuer.
|
||||
|
||||
**Warning:** ICOs may be [regulated as securities](https://www.sec.gov/oiea/investor-alerts-and-bulletins/ib_coinofferings) in the USA.
|
||||
|
||||
Ripple strongly recommends researching the relevant regulations before engaging in any financial service business.
|
||||
|
||||
### Issued Currency Properties
|
||||
|
||||
All issued currencies in the XRP Ledger exist in trust lines, represented in the ledger's data as [RippleState objects](reference-ledger-format.html#ripplestate). To create an issued currency, the issuing address sends a [Payment transaction][] to an address which has a trust line to the issuer with a nonzero limit for that currency. (You can also create issued currency by rippling "through" such a trust line.) You can erase issued currency by sending it back to the issuer.
|
||||
|
||||
The issuer of a currency can define a percentage [transfer fee](concept-transfer-fees.html) to deduct when two parties transact in its issued currencies.
|
||||
|
||||
Addresses can also [freeze](concept-freeze.html) issued currencies, which may be useful for businesses to comply with financial regulations in their jurisdiction. If you do not need this feature and do not want to freeze currencies, you can give up your address's ability to freeze individual trust lines and to undo a global freeze. XRP cannot be frozen.
|
||||
|
||||
Issued currencies are designed to be able to represent any kind of currency or asset, including those with very small or very large nominal values. For detailed technical information on the types of currency codes and the numeric limits of issued currency representation, see the [currency format reference](reference-currency.html).
|
||||
|
||||
{% include 'snippets/tx-type-links.md' %}
|
||||
139
content/img-sources/currency_code_format.uxf
Normal file
139
content/img-sources/currency_code_format.uxf
Normal file
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="14.2">
|
||||
<zoom_level>10</zoom_level>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>40</x>
|
||||
<y>70</y>
|
||||
<w>20</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>00</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>40</x>
|
||||
<y>90</y>
|
||||
<w>60</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;40.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>80</x>
|
||||
<y>120</y>
|
||||
<w>300</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Type code (8 bits)
|
||||
0x00 for ISO 4217/pseudo-ISO currency</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>70</x>
|
||||
<y>70</y>
|
||||
<w>220</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Reserved (96 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>460</x>
|
||||
<y>70</y>
|
||||
<w>20</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes/>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>460</x>
|
||||
<y>90</y>
|
||||
<w>40</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;20.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>480</x>
|
||||
<y>120</y>
|
||||
<w>250</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Version (8 bits)
|
||||
Increment if currency is reissued
|
||||
with the same code</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>490</x>
|
||||
<y>70</y>
|
||||
<w>150</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Reserved (24 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>300</x>
|
||||
<y>70</y>
|
||||
<w>150</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>ISO code (24 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLPackage</id>
|
||||
<coordinates>
|
||||
<x>30</x>
|
||||
<y>40</y>
|
||||
<w>620</w>
|
||||
<h>70</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Issued Currency Code Format</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>310</x>
|
||||
<y>90</y>
|
||||
<w>40</w>
|
||||
<h>50</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;30.0;20.0;30.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>330</x>
|
||||
<y>110</y>
|
||||
<w>130</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>3 chars of ASCII</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
</diagram>
|
||||
105
content/img-sources/currency_format.uxf
Normal file
105
content/img-sources/currency_format.uxf
Normal file
@@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="14.2">
|
||||
<zoom_level>10</zoom_level>
|
||||
<element>
|
||||
<id>UMLPackage</id>
|
||||
<coordinates>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<w>650</w>
|
||||
<h>70</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Issued Currency Number Format</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>30</x>
|
||||
<y>50</y>
|
||||
<w>20</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes/>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>60</x>
|
||||
<y>50</y>
|
||||
<w>20</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes/>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>90</x>
|
||||
<y>50</y>
|
||||
<w>150</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>exponent (8 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>250</x>
|
||||
<y>50</y>
|
||||
<w>410</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>mantissa (54 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>60</x>
|
||||
<y>70</y>
|
||||
<w>50</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;30.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>90</x>
|
||||
<y>100</y>
|
||||
<w>260</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Sign bit (0=negative, 1=positive)
|
||||
style=wordwrap</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>70</x>
|
||||
<y>130</y>
|
||||
<w>270</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>"Not XRP" bit (0=XRP, 1=not XRP)
|
||||
style=wordwrap</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>30</x>
|
||||
<y>70</y>
|
||||
<w>60</w>
|
||||
<h>90</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;70.0;40.0;70.0</additional_attributes>
|
||||
</element>
|
||||
</diagram>
|
||||
174
content/img-sources/demurrage-currency-code-format.uxf
Normal file
174
content/img-sources/demurrage-currency-code-format.uxf
Normal file
@@ -0,0 +1,174 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<diagram program="umlet" version="14.2">
|
||||
<zoom_level>10</zoom_level>
|
||||
<element>
|
||||
<id>UMLPackage</id>
|
||||
<coordinates>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<w>620</w>
|
||||
<h>70</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Demurraging Currency Code Format</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>30</x>
|
||||
<y>50</y>
|
||||
<w>20</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>01</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>60</x>
|
||||
<y>50</y>
|
||||
<w>80</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes/>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>150</x>
|
||||
<y>50</y>
|
||||
<w>120</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Unused (24 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>280</x>
|
||||
<y>50</y>
|
||||
<w>200</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>e-folding time (64 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLClass</id>
|
||||
<coordinates>
|
||||
<x>490</x>
|
||||
<y>50</y>
|
||||
<w>140</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Reserved (40 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>UMLNote</id>
|
||||
<coordinates>
|
||||
<x>660</x>
|
||||
<y>30</y>
|
||||
<w>120</w>
|
||||
<h>70</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Legacy only. Not currently supported.
|
||||
bg=red
|
||||
style=wordwrap</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>340</x>
|
||||
<y>70</y>
|
||||
<w>40</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;20.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>360</x>
|
||||
<y>100</y>
|
||||
<w>130</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>IEEE 754 Double</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>220</x>
|
||||
<y>100</y>
|
||||
<w>130</w>
|
||||
<h>30</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Must be all 0's</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>200</x>
|
||||
<y>70</y>
|
||||
<w>40</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;20.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>80</x>
|
||||
<y>90</y>
|
||||
<w>130</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>ISO 4217 code
|
||||
in ASCII
|
||||
(24 bits)</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>60</x>
|
||||
<y>70</y>
|
||||
<w>40</w>
|
||||
<h>60</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;40.0;20.0;40.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Relation</id>
|
||||
<coordinates>
|
||||
<x>30</x>
|
||||
<y>70</y>
|
||||
<w>70</w>
|
||||
<h>110</h>
|
||||
</coordinates>
|
||||
<panel_attributes>lt=<<-</panel_attributes>
|
||||
<additional_attributes>10.0;10.0;10.0;90.0;50.0;90.0</additional_attributes>
|
||||
</element>
|
||||
<element>
|
||||
<id>Text</id>
|
||||
<coordinates>
|
||||
<x>80</x>
|
||||
<y>150</y>
|
||||
<w>210</w>
|
||||
<h>40</h>
|
||||
</coordinates>
|
||||
<panel_attributes>Type code (8 bits)
|
||||
0x01 for demurraging currency</panel_attributes>
|
||||
<additional_attributes/>
|
||||
</element>
|
||||
</diagram>
|
||||
60
content/reference-currency.md
Normal file
60
content/reference-currency.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Currency Formats
|
||||
|
||||
The XRP Ledger has [two kinds of money](concept-money.html): XRP, and issued currencies. In the XRP Ledger, both types have high precision, although their formats are different.
|
||||
|
||||
## String Formatting
|
||||
|
||||
{% include 'snippets/string-number-formatting.md' %}
|
||||
|
||||
## XRP Precision
|
||||
|
||||
XRP has the same precision as a 64-bit unsigned integer where each unit is equivalent to 0.000001 XRP. Its properties are:
|
||||
|
||||
* Minimum value: `0`
|
||||
* Maximum value: `100000000000` (10<sup>11</sup>) XRP
|
||||
- `"100000000000000000"` (10<sup>17</sup>) drops of XRP
|
||||
* Precise to the nearest `0.000001` (10<sup>-6</sup>) XRP
|
||||
- `"1"` drop of XRP
|
||||
|
||||
## Issued Currency Precision
|
||||
|
||||
Issued currencies in the XRP Ledger are represented with a custom format with the following precision:
|
||||
|
||||
* Minimum nonzero absolute value: `1000000000000000e-96`
|
||||
* Maximum value: `9999999999999999e80`
|
||||
* Minimum value: `-9999999999999999e80`
|
||||
* 15 decimal digits of precision
|
||||
|
||||
## Issued Currency Math
|
||||
[[Source]<br>](https://github.com/ripple/rippled/blob/35fa20a110e3d43ffc1e9e664fc9017b6f2747ae/src/ripple/protocol/impl/STAmount.cpp "Source")
|
||||
|
||||

|
||||
|
||||
Internally, `rippled` represents numbers for issued currencies in a custom number format. This format can store a wide variety of assets, including those typically measured in very small or very large denominations. Unlike typical floating-point representations of non-whole numbers, this format uses integer math for all calculations, so it always maintains 15 decimal digits of precision. Unlike "arbitrary precision" number formats, the custom format can always be stored in a fixed size of 64 bits.
|
||||
|
||||
The internal format consists of three parts: a sign bit, significant digits, and an exponent. (It uses them in the same way as scientific notation.) The sign bit indicates whether the amount is positive or negative. The significant digits are represented using an integer in the range `1000000000000000` to `9999999999999999` (inclusive), except for the special case of the value 0, whose significant digits use the value `0`. The exponent indicates the scale (what power of 10 the significant digits should be multiplied by) in the range -96 to +80 (inclusive). Before recording any amount, `rippled` "canonicalizes" the value so that the significant digits and exponent are within the expected range. For example, the canonical representation of 1 unit of currency is `1000000000000000e-15`. The internal calculations generally use integer math so that numbers are always precise within 15 digits. Multiplication and division have adjustments to compensate for over-rounding in the least significant digits.
|
||||
|
||||
When transmitting non-XRP amounts across the network or recording them in ledgers, the amounts are joined into a 64-bit format. The most significant bit indicates whether the amount is XRP or issued currency. (The value `1` indicates a non-XRP amount.) The next bit is the sign bit, 1 for positive or 0 for negative. (Caution: This is the opposite of how sign bits work in most other numeric representations!) The next 8 bits are the exponent, and the significant digits occupy the remaining 54 bits.
|
||||
|
||||
## Currency Codes
|
||||
|
||||
All non-XRP currencies in the XRP Ledger have a 160-bit currency code. The [`rippled` APIs](reference-rippled.html) map 3-character ASCII strings (case-sensitive) to 160-bit currency codes using a standard mapping. The currency code `XRP` is disallowed for issued currencies. Currencies with the same code can [ripple](concept-noripple.html) across connected trustlines. Currency codes have no other behavior built into the XRP Ledger.
|
||||
|
||||
### Standard Currency Codes
|
||||
|
||||
The standard currency mapping allocates the bits as follows:
|
||||
|
||||

|
||||
|
||||
1. The first 8 bits must be `0x00`.
|
||||
2. The next 96 bits are reserved, and should be all `0`s.
|
||||
3. The next 24 bits represent 3 characters of ASCII.
|
||||
Ripple recommends using [ISO 4217](http://www.xe.com/iso4217.php) codes, or popular pseudo-ISO 4217 codes such as "BTC". However, any combination of the following characters is permitted: all uppercase and lowercase letters, digits, as well as the symbols `?`, `!`, `@`, `#`, `$`, `%`, `^`, `&`, `*`, `<`, `>`, `(`, `)`, `{`, `}`, `[`, `]`, and <code>|</code>. The currency code `XRP` (all-uppercase) is reserved for XRP and cannot be used by issued currencies.
|
||||
4. The next 8 bits indicate the currency version. If the same currency is reissued with a different value, you can increment this value to keep the currencies separate.
|
||||
5. The next 24 bits are reserved and should be all `0`s.
|
||||
|
||||
### Nonstandard Currency Codes
|
||||
|
||||
You can also issue currency of other types by using a 160-bit (40-character) hexadecimal string such as `015841551A748AD2C1F76FF6ECB0CCCD00000000` as the currency code. To prevent this from being treated as a different currency code type, the first 8 bits MUST NOT be `0x00`.
|
||||
|
||||
**Deprecated:** Some previous versions of [ripple-lib](https://github.com/ripple/ripple-lib) supported an "interest-bearing" or "demurraging" currency code type. These currencies have the first 8 bits `0x01`. Demurraging / interest-bearing currencies are no longer supported, but you may encounter them in ledger data. For more information, see [Demurrage](concept-demurrage.html).
|
||||
@@ -4980,15 +4980,7 @@ As a REST API, the Data API v2 uses [JSON](http://json.org/)'s native datatypes
|
||||
### Numbers and Precision ###
|
||||
[String - Number]: #numbers-and-precision
|
||||
|
||||
Currency amounts in the XRP Ledger require more precision than most native number types, so the Data API v2 uses the String type to represent some values.
|
||||
|
||||
Within the String value, the numbers are serialized in the same way as native JSON numbers:
|
||||
|
||||
* Base-10.
|
||||
* Non-zero-prefaced.
|
||||
* May contain `.` as a decimal point. For example, ½ is represented as `0.5`. (American style, not European)
|
||||
* May contain `E` or `e` to indicate being raised to a power of 10. For example, `1.2E5` is equivalent to `120000`.
|
||||
* No comma (`,`) characters are used.
|
||||
{% include 'snippets/string-number-formatting.md' %}
|
||||
|
||||
The precision for amounts of **non-XRP currency** in the XRP Ledger is as follows:
|
||||
|
||||
|
||||
7
content/snippets/string-number-formatting.md
Normal file
7
content/snippets/string-number-formatting.md
Normal file
@@ -0,0 +1,7 @@
|
||||
XRP Ledger APIs generally use strings, rather than native JSON numbers, to represent numeric amounts of currency for both XRP and issued currencies. This protects against a loss of precision when using JSON parsers, which may automatically try to represent all JSON numbers in a floating-point format. Within the String value, the numbers are serialized in the same way as native JSON numbers:
|
||||
|
||||
* Base-10.
|
||||
* Non-zero-prefaced.
|
||||
* May contain `.` as a decimal point. For example, ½ is represented as `0.5`. (American style, not European)
|
||||
* May contain `E` or `e` to indicate being raised to a power of 10 (scientific notation). For example, `1.2E5` is equivalent to 1.2×10<sup>5</sup>, or `120000`.
|
||||
* No comma (`,`) characters are used.
|
||||
@@ -158,6 +158,13 @@ pages:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
- md: reference-currency.md
|
||||
category: References
|
||||
html: reference-currency.html
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
# Tutorials are step-by-step guides to a specific goal
|
||||
- name: How to Multi-Sign
|
||||
category: Tutorials
|
||||
@@ -295,6 +302,20 @@ pages:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
- md: concept-money.md
|
||||
category: Features
|
||||
html: concept-money.html
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
- md: concept-demurrage.md
|
||||
category: Features
|
||||
html: concept-demurrage.html
|
||||
targets:
|
||||
- local
|
||||
- ripple.com
|
||||
|
||||
- md: concept-partial-payments.md
|
||||
category: Features
|
||||
html: concept-partial-payments.html
|
||||
|
||||
BIN
img/currency-code-format.png
Normal file
BIN
img/currency-code-format.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
img/currency-number-format.png
Normal file
BIN
img/currency-number-format.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
BIN
img/demurrage-currency-code-format.png
Normal file
BIN
img/demurrage-currency-code-format.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user