-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdemurrage.html
More file actions
349 lines (294 loc) · 20.3 KB
/
demurrage.html
File metadata and controls
349 lines (294 loc) · 20.3 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">
<title>Demurrage - XAG Ledger Dev Portal</title>
<!-- favicon -->
<link rel="apple-touch-icon" sizes="180x180" href="assets/favicons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/favicons/favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicons/favicon-32x32.png">
<link rel="manifest" href="assets/favicons/site.webmanifest">
<link rel="shortcut icon" href="favicon.ico">
<meta name="msapplication-TileColor" content="#25A768">
<meta name="msapplication-config" content="assets/favicons/browserconfig.xml">
<meta name="theme-color" content="#25A768">
<!-- jQuery -->
<script src="assets/vendor/jquery-1.11.1.min.js"></script>
<!-- Stylesheet -->
<link href="assets/css/devportal.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
<!-- syntax highlighting -->
<link rel="stylesheet" href="assets/vendor/docco.min.css" />
<script src="assets/vendor/highlight.min.js"></script>
<!-- expandable code samples -->
<script src="assets/js/expandcode.js"></script>
<!-- multi-code selection tabs -->
<script src="assets/js/multicodetab.js"></script>
<script>
$(document).ready(function() {
$(".multicode").minitabs();
hljs.initHighlighting();
make_code_expandable();
});
</script>
</head>
<body class="xrp-ledger-dev-portal sidebar-primary lang-en ">
<nav class="navbar fixed-top navbar-expand-lg navbar-light bg-white">
<a href="index.html" class="navbar-brand"><img src="assets/img/logo.png" class="logo" height="44" alt="XAG Ledger Dev Portal" /></a>
<button class="navbar-toggler" type="button" data-toggle="slide-collapse" data-target="#navbarHolder" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarHolder">
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="dev-tools.html">Dev Tools</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://xagfans.com/" target="blank">BBS</a>
</li>
</ul><!-- /.navbar-nav -->
<div class="github-edit-wrap">
<a href="https://github.com/xagfans/docs/concepts/issued-currencies/demurrage.md" target="_blank" class="github-edit">Edit</a>
</div><!-- /.github-edit -->
<div class="nav navbar-nav language-selector">
<div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="language_selector_header_btn" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
English
</button>
<div class="dropdown-menu" aria-labelledby="language_selector_header_btn">
<a class="dropdown-item" href="/demurrage.html">English</a>
<a class="dropdown-item" href="/cn/demurrage.html">中文</a>
</div><!--/.dropdown-menu-->
</div><!--/.dropdown-->
</div><!--/.language-selector-->
</div><!--/#navbarHolder-->
<div class="menu-overlay"></div>
</nav>
<div class="container-fluid" role="document" id="main_content_wrapper">
<div class="row">
<!-- Right sidebar first so it's at the beginning for mobile layouts -->
<!-- main column -->
<main class="main col-md-7 col-lg-6 order-md-3 " role="main" id="main_content_body">
<nav class="breadcrumbs-wrap p-0 p-md-3" aria-label="breadcrumb">
<ul class="breadcrumb bg-white">
<li class="breadcrumb-item"><a href="index.html">Home</a></li>
<li class="active breadcrumb-item"><a href="docs.html">Docs</a></li>
<li class="active breadcrumb-item"><a href="concepts.html">Concepts</a></li>
<li class="active breadcrumb-item"><a href="issued-currencies.html">Issued Currencies</a></li>
<li class="active breadcrumb-item">Demurrage</li>
</ul>
</nav><!--/.breadcrumbs-wrap--> <article class="pt-3 p-md-3">
<div class="content">
<h1 id="demurrage">Demurrage</h1>
<p class="devportal-callout warning"><strong>Warning:</strong> Demurrage is a deprecated feature with no ongoing support. This page describes historical behavior of older versions of Ripple software.</p>
<p><a class="external-link" href="http://en.wikipedia.org/wiki/Demurrage_%28currency%29" target="_blank">Demurrage <i aria-hidden="true" class="fa fa-external-link"></i></a> 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 XAG Ledger, you can track it using a custom <a href="currency-formats.html#currency-codes">currency code</a> 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)".</p>
<h2 id="representing-demurraging-currency-amounts">Representing Demurraging Currency Amounts</h2>
<p>Rather than continuously update all amounts in the XAG Ledger, this approach divides amounts of interest-bearing or demurraging currency into two types of amount: "ledger values" recorded in the XAG 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.</p>
<p class="devportal-callout tip"><strong>Tip:</strong> 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.</p>
<p>Thus, client software must apply two conversions:</p>
<ul>
<li>Taking display values at a given time and converting them to ledger values to be recorded.</li>
<li>Taking ledger values and converting them to a display value at a given point in time.</li>
</ul>
<h3 id="calculating-demurrage">Calculating Demurrage</h3>
<p>The full formula for calculating demurrage on a currency is as follows:</p>
<pre><code>D = A × ( e ^ (t ÷ τ) )
</code></pre>
<ul>
<li><strong>D</strong> is the amount after demurrage</li>
<li><strong>A</strong> is the pre-demurrage amount as recorded in the global ledger</li>
<li><strong>e</strong> is Euler's number</li>
<li><strong>t</strong> is the number of seconds since the Ripple Epoch (0:00 on January 1, 2000 UTC)</li>
<li><strong>τ</strong> is the e-folding time in seconds. This value is <a href="#calculating-e-folding-time">calculated from the desired interest rate</a>.</li>
</ul>
<p>To convert between display amounts and ledger amounts, you can use the following steps:</p>
<ol>
<li>Calculate the value of <code>( e ^ (t ÷ τ) )</code>. We call this number the "demurrage coefficient". The demurrage coefficient is always relative to a specific time, such as the current time.</li>
<li>Apply it to the amount to convert:<ul>
<li>To convert ledger values to display values, multiply by the demurrage coefficient.</li>
<li>To convert display values to ledger values, divide by the demurrage coefficient.</li>
</ul>
</li>
<li>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 XAG Ledger's <a href="currency-formats.html#issued-currency-precision">issued currency format</a>.</li>
</ol>
<h2 id="interest-bearing-currency-code-format">Interest-Bearing Currency Code Format</h2>
<p>Rather than using the <a href="currency-formats.html#currency-codes">standard currency code format</a>, currencies that have positive interest or negative interest (demurrage) use a 160-bit currency code in the following format:</p>
<p><img alt="Demurraging Currency Code Format" src="img/demurrage-currency-code-format.png"/></p>
<ol>
<li>The first 8 bits must be <code>0x01</code>.</li>
<li>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.</li>
<li>The next 24 bits MUST be all <code>0</code>s.</li>
<li>The next 64 bits are the interest rate of the currency, represented as "<a class="external-link" href="http://en.wikipedia.org/wiki/E-folding" target="_blank">e-folding time <i aria-hidden="true" class="fa fa-external-link"></i></a>" in an IEEE 754 double format.</li>
<li>The next 24 bits are reserved and should be all <code>0</code>s.</li>
</ol>
<h3 id="calculating-e-folding-time">Calculating e-folding Time</h3>
<p>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 <em>e</em> (Euler's number). By convention, e-folding time is written as the letter <strong>τ</strong> in formulas.</p>
<p>To calculate an e-folding time for a given rate of annual percent interest:</p>
<ol>
<li>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 <strong>99.5%</strong> remaining.</li>
<li>Represent the percentage as a decimal. For example, 99.5% becomes <strong>0.995</strong>.</li>
<li>Take the natural log of that number. For example, <strong>ln(0.995) = -0.005012541823544286</strong>. (This number is positive if the initial interest rate was positive, and negative if the interest rate was negative.)</li>
<li>Take the number of seconds in one year (31536000) and divide by the natural log result from the previous step. For example, <strong>31536000 ÷ -0.005012541823544286 = -6291418827.045599</strong>. This result is the e-folding time in seconds.</li>
</ol>
<p class="devportal-callout note"><strong>Note:</strong> By convention, the XAG Ledger's interest/demurrage rules use a fixed number of seconds per year (31536000), which is not adjusted for leap days or leap seconds.</p>
<h2 id="client-support">Client Support</h2>
<p>To support interest-bearing and demurraging currencies, client applications must implement several features:</p>
<ul>
<li>
<p>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.)</p>
</li>
<li>
<p>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.</p>
</li>
<li>
<p>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 <a href="#interest-bearing-currency-code-format">Interest-Bearing Currency Code Format</a> into a display such as "XAU (-0.5% pa)".</p>
</li>
</ul>
<h3 id="ripple-lib-support">ripple-lib Support</h3>
<p>Demurrage was supported in ripple-lib versions <strong>0.7.37*<em> through <strong>0.12.9</strong>. Demurrage is </em></strong>not supported*** in <a href="rippleapi-reference.html">RippleAPI</a>.</p>
<p>The following code samples demonstrate how to use compatible versions of ripple-lib to convert between ledger values and display values. Also see the <a class="external-link" href="https://ripple.github.io/ripple-demurrage-tool/" target="_blank">Ripple Demurrage Calculator <i aria-hidden="true" class="fa fa-external-link"></i></a>.</p>
<p>To convert from a display value to a ledger value, use <code>Amount.from_human()</code>:</p>
<pre><code class="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" }
</code></pre>
<p>To convert from a ledger value to a display value:</p>
<pre><code class="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" }
</code></pre>
</div>
</article>
</main>
<!-- Left sidebar last so it's at the end for mobile -->
<aside class="sidebar col-md-5 col-lg-3 p-0 order-md-1" role="complementary">
<div class="tree_nav">
<!---->
<div class="sidenav_parent">
<a href="concepts.html"> Concepts</a>
</div>
<!---->
<!---->
<div id="sidenav" role="tablist" aria-multiselectable="true">
<!---->
<div class="card">
<div class="card-header" role="tab" id="sidenav_cat_head_2">
<a class="collapsed sidenav_cat_toggler" role="button" data-toggle="collapse" href="#sidenav_collapse_2" aria-expanded="true" aria-controls="sidenav_collapse_2"></a>
<h5 class="card-title">
<a class="sidenav_cat_title" href="introduction.html">Introduction</a>
<!-- <a class="sidenav_cat_title" href="introduction.html">Introduction</a> -->
</h5>
</div><!-- /.card-header -->
<div id="sidenav_collapse_2" class="collapse" role="tabpanel" aria-labelledby="sidenav_cat_head_2">
<div class="card-body">
<ul class="sidebar_pagelist">
<li><a class="nosubcat-page" href="xag-ledger-overview.html">XAG Ledger Overview</a></li>
<li><a class="nosubcat-page" href="intro-to-consensus.html">Introduction to Consensus</a></li>
<li><a class="nosubcat-page" href="xag.html">XAG</a></li>
<li><a class="nosubcat-page" href="software-ecosystem.html">Software Ecosystem</a></li>
<li><a class="nosubcat-page" href="technical-faq.html">Technical FAQ</a></li>
</ul>
</div><!-- /.card-body -->
</div><!-- /#sidenav_collapse2 -->
</div><!-- /.card -->
<!---->
<div class="card">
<div class="card-header" role="tab" id="sidenav_cat_head_8">
<a class="collapsed sidenav_cat_toggler" role="button" data-toggle="collapse" href="#sidenav_collapse_8" aria-expanded="true" aria-controls="sidenav_collapse_8"></a>
<h5 class="card-title">
<a class="sidenav_cat_title" href="payment-system-basics.html">Payment System Basics</a>
<!-- <a class="sidenav_cat_title" href="payment-system-basics.html">Payment System Basics</a> -->
</h5>
</div><!-- /.card-header -->
<div id="sidenav_collapse_8" class="collapse" role="tabpanel" aria-labelledby="sidenav_cat_head_8">
<div class="card-body">
<ul class="sidebar_pagelist">
<li><a class="subcat-title" href="accounts.html">Accounts</a></li>
<li><a class="subpage" href="cryptographic-keys.html">Cryptographic Keys</a></li>
<li><a class="subpage" href="multi-signing.html">Multi-Signing</a></li>
<li><a class="nosubcat-page" href="ledgers.html">Ledgers</a></li>
<li><a class="subcat-title" href="transaction-basics.html">Transaction Basics</a></li>
<li><a class="subpage" href="transaction-cost.html">Transaction Cost</a></li>
<li><a class="subpage" href="finality-of-results.html">Finality of Results</a></li>
<li><a class="subpage" href="source-and-destination-tags.html">Source and Destination Tags</a></li>
</ul>
</div><!-- /.card-body -->
</div><!-- /#sidenav_collapse8 -->
</div><!-- /.card -->
<!---->
<!---->
<div class="card active">
<div class="card-header" role="tab" id="sidenav_cat_head_28">
<a class="sidenav_cat_toggler" role="button" data-toggle="collapse" href="#sidenav_collapse_28" aria-expanded="true" aria-controls="sidenav_collapse_28"></a>
<h5 class="card-title">
<a class="sidenav_cat_title active-parent" href="issued-currencies.html">Issued Currencies</a>
<!-- <a class="sidenav_cat_title" href="issued-currencies.html">Issued Currencies</a> -->
</h5>
</div><!-- /.card-header -->
<div id="sidenav_collapse_28" class="collapse show" role="tabpanel" aria-labelledby="sidenav_cat_head_28">
<div class="card-body">
<ul class="sidebar_pagelist">
<li><a class="nosubcat-page" href="issued-currencies-overview.html">Issued Currencies Overview</a></li>
<li><a class="nosubcat-page" href="trust-lines-and-issuing.html">Trust Lines and Issuing</a></li>
<li><a class="nosubcat-page" href="authorized-trust-lines.html">Authorized Trust Lines</a></li>
<li><a class="nosubcat-page" href="freezes.html">Freezing Issued Currencies</a></li>
<li><a class="nosubcat-page" href="rippling.html">Rippling</a></li>
<li><a class="nosubcat-page" href="transfer-fees.html">Transfer Fees</a></li>
<li><a class="nosubcat-page" href="issuing-and-operational-addresses.html">Issuing and Operational Addresses</a></li>
<li><a class="nosubcat-page" href="paths.html">Paths</a></li>
<li><a class="active nosubcat-page" href="demurrage.html">Demurrage</a></li>
</ul>
</div><!-- /.card-body -->
</div><!-- /#sidenav_collapse28 -->
</div><!-- /.card -->
<!---->
<!---->
<!---->
</div><!-- /#sidenav -->
</div><!-- /.tree_nav --> </aside>
</div><!--/.row (main layout)-->
</div>
<!-- Jump to top button -->
<a href="#main_content_wrapper" class="jump-to-top btn btn-primary btn-lg" role="button" title="Jump to top of page">Top</a>
<script type="text/javascript" src="assets/js/jump-to-top.js"></script>
<!-- Non-blocking resources -->
<!-- Bootstrap JS -->
<script src="assets/vendor/bootstrap.min.js"></script>
<!-- fontawesome icons -->
<link rel="stylesheet" href="assets/vendor/fontawesome/css/font-awesome.min.css" />
<!-- Algolia DocSearch -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
<script type="text/javascript"> docsearch({
apiKey: '70de5b9b8ef95460f3c6e04054b325b2',
indexName: 'xrpl',
inputSelector: '#topsearchbar',
algoliaOptions: { 'facetFilters': ["lang:en"] },
debug: false
});
</script>
<script type="application/javascript">
gtag('set', {'content_group1': 'Content Docs'});
</script>
</body>
</html>