Skip to content

Commit a2975ac

Browse files
committed
docs: mi/654/amounts-assets
1 parent 4bc7c58 commit a2975ac

File tree

1 file changed

+22
-103
lines changed

1 file changed

+22
-103
lines changed

docs/src/content/docs/concepts/amounts.mdx

Lines changed: 22 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -11,125 +11,30 @@ import {
1111
import { Steps } from '@astrojs/starlight/components'
1212

1313
:::tip[Summary]
14-
Amounts in Open Payments define monetary values using asset codes, asset scales, and specific amount types. They provide a standardized way to represent money across different currencies and payment scenarios.
14+
Amounts in Open Payments define monetary values using asset codes and asset scales. They provide a standardized way to represent money across different currencies and payment scenarios.
1515
:::
1616

17-
Amounts represent monetary values and are fundamental to all payment operations. Every amount consists of three key components: a numerical `value`, an `assetCode`, and an `assetScale`. Understanding these components is crucial for building Open Payments applications.
17+
Amounts represent monetary values and are fundamental to every Open Payments operation. Whether you're creating an incoming payment, requesting a quote, or tracking payment progress, every amount consists of three key components: a numerical `value`, an `assetCode`, and an `assetScale`. Understanding these components is crucial for building Open Payments applications.
1818

19-
Amounts are central to every Open Payments operation. Whether you're creating an incoming payment, requesting a quote, or tracking payment progress, all amounts follow the same three-part structure:
19+
## Values
2020

21-
```json
22-
{
23-
"value": "1000",
24-
"assetCode": "USD",
25-
"assetScale": 2
26-
}
27-
```
21+
To maximize precision and avoid rounding errors in financial calculations, Open Payments uses numerical data types without decimals to represent values. In the context of programming languages, this means that Open Payments uses unsigned 64-bit integers for monetary amounts instead of floating-point numbers.
2822

29-
This consistent structure enables multi-currency payments, precise calculations, and seamless integration between different <Tooltip content="Account servicing entity">ASEs</Tooltip>.
30-
31-
:::note[Wallet address asset constraint]
32-
[Wallet addresses](/concepts/wallet-addresses) support only one specific asset. Therefore, the amounts that can be sent or received by a particular wallet address will only be in the asset supported by that wallet. For example, a USD wallet address can only accept amounts with `assetCode: "USD"`.
33-
:::
23+
An example of a value is the number 10000.
3424

3525
## Asset codes
3626

3727
Asset codes identify the type of currency or asset being used in a payment and should follow the <LinkOut href='https://en.wikipedia.org/wiki/ISO_4217'>ISO 4217</LinkOut> standard for currency representation.
3828

39-
### Common currency examples
40-
41-
<table style='width: auto; margin: 1;'>
42-
<thead>
43-
<tr>
44-
<th>Asset Code</th>
45-
<th>Currency</th>
46-
<th>Symbol</th>
47-
</tr>
48-
</thead>
49-
<tbody>
50-
<tr>
51-
<td>
52-
<code>USD</code>
53-
</td>
54-
<td>US Dollar</td>
55-
<td>$</td>
56-
</tr>
57-
<tr>
58-
<td>
59-
<code>EUR</code>
60-
</td>
61-
<td>Euro</td>
62-
<td>€</td>
63-
</tr>
64-
<tr>
65-
<td>
66-
<code>GBP</code>
67-
</td>
68-
<td>British Pound</td>
69-
<td>£</td>
70-
</tr>
71-
<tr>
72-
<td>
73-
<code>JPY</code>
74-
</td>
75-
<td>Japanese Yen</td>
76-
<td>¥</td>
77-
</tr>
78-
<tr>
79-
<td>
80-
<code>MXN</code>
81-
</td>
82-
<td>Mexican Peso</td>
83-
<td>$</td>
84-
</tr>
85-
<tr>
86-
<td>
87-
<code>ZAR</code>
88-
</td>
89-
<td>South African Rand</td>
90-
<td>R</td>
91-
</tr>
92-
<tr>
93-
<td>
94-
<code>JOD</code>
95-
</td>
96-
<td>Jordanian Dinar</td>
97-
<td>د.ا</td>
98-
</tr>
99-
</tbody>
100-
</table>
101-
102-
When building payment applications, you'll specify the asset code to indicate which currency you're working with:
103-
104-
```json
105-
{
106-
"assetCode": "USD",
107-
"assetScale": 2,
108-
"value": "1000"
109-
}
110-
```
29+
An example of an ISO 4217 `assetCode` is `USD`, which represents the US Dollar.
11130

11231
## Asset scales
11332

114-
<<<<<<< HEAD
11533
An asset scale tells you how many decimal places a currency uses. It's like specifying whether you're counting in dollars, cents, or smaller units.
11634

11735
Asset scales are numbers between 0 and 255 that indicate decimal precision.
11836

11937
In the case of `USD` with an `assetScale` of 2, the display amount of $100.00 is stored and represented as 10000 cents.
120-
=======
121-
An asset scale defines the decimal precision for monetary amounts by specifying the power of 10 to divide the integer value by to get the display amount.
122-
123-
### Integer representation
124-
125-
Open Payments uses unsigned 64-bit integers for monetary amounts instead of floating-point numbers to maximize precision and avoid rounding errors in financial calculations. The smallest useful unit of each currency maps to 1, with all amounts expressed as multiples of that unit.
126-
127-
### How scales work
128-
129-
Asset scales are integers between 0 and 255 that represent the exponent in the conversion formula:
130-
131-
**Monetary Value = Integer Amount ÷ 10<sup> `assetScale`</sup>**
132-
>>>>>>> parent of 70b2464 (docs: 654/amounts-assets)
13338

13439
Thus, the conversion formula is:
13540

@@ -158,8 +63,8 @@ $$\frac{10000}{10^2} = \frac{10000}{100} = \$100.00$$
15863
<code>USD</code>
15964
</td>
16065
<td>2</td>
161-
<td>100</td>
162-
<td>$1.00</td>
66+
<td>10000</td>
67+
<td>$100.00</td>
16368
</tr>
16469
<tr>
16570
<td>Euro</td>
@@ -217,3 +122,17 @@ $$\frac{10000}{10^2} = \frac{10000}{100} = \$100.00$$
217122
</tr>
218123
</tbody>
219124
</table>
125+
126+
## Amounts in Open Payments
127+
128+
Using the three necessary components of `value`, `assetCode`, and `assetScale`, $100 USD would be represented in Open Payments using the following structure:
129+
130+
```json
131+
{
132+
"value": "10000",
133+
"assetCode": "USD",
134+
"assetScale": 2
135+
}
136+
```
137+
138+
This consistent structure enables multi-currency payments, precise calculations, and seamless integration between different <Tooltip content="Account servicing entity">ASEs</Tooltip>.

0 commit comments

Comments
 (0)