Open dharjeezy opened 1 year ago
Here is a table of test data:
Before the inverse issuance is calculated, the number of decimals should be added to the Total Issuance. This aligns each currency appropriately to the smallest currency unit according to the number of decimal places.
We cannot check that the total issuance is appropriately supplied by an extrinsic, but we can use the number of decimals as a crude sanity check: that the supplied value is within a certain expected range +/- the existing value.
Weighting per currency = Inverse Issuance / Total Inverse Issuance
Weight adjusted price = Weighting per currency * Price
Unit of Account per currency unit = Price / (100_000 * Unit of Account)
Symbol | Decimals | Total Issuance | Inverse Issuance | Weighting per currency | Price | Weight adjusted price (for Unit of Account calc only) | Unit of Account per currency unit |
---|---|---|---|---|---|---|---|
CNY | 2 | 20308000000000000 | 0.00000000000000004924 | 0.000693859246235965 | $0.14 | 0.0000978362008771359 | 0.00000261216547787 |
USD | 2 | 1564692617100000 | 0.00000000000000063910 | 0.009005534645313300 | $1.00 | 0.0090055346453133000 | 0.00001852560865275 |
EUR | 2 | 1214125230000000 | 0.00000000000000082364 | 0.011605799158427800 | $1.08 | 0.0125213275644432000 | 0.00001998700917578 |
JPY | 2 | 138166400000000000 | 0.00000000000000000724 | 0.000101984951280195 | $0.01 | 0.0000009335163936936 | 0.00000016957363967 |
GBP | 2 | 288957500000000 | 0.00000000000000346072 | 0.048764588469100100 | $1.23 | 0.0599569675118472000 | 0.00002277758002272 |
KRW | 2 | 414795400000000000 | 0.00000000000000000241 | 0.000033970708384326 | $0.00 | 0.0000000276252556365 | 0.00000001506517524 |
INR | 2 | 16370023000000000 | 0.00000000000000006109 | 0.000860774207376494 | $0.01 | 0.0000113059188514640 | 0.00000024332632914 |
HKD | 2 | 1481642700000000 | 0.00000000000000067493 | 0.009510318224872960 | $0.13 | 0.0012266664811812900 | 0.00000238948294268 |
CAD | 2 | 262358300000000 | 0.00000000000000381158 | 0.053708586968889400 | $0.71 | 0.0379834314115889000 | 0.00001310155834163 |
TWD | 2 | 4661099100000000 | 0.00000000000000021454 | 0.003023083884348220 | $0.03 | 0.0000999863125741122 | 0.00000061272110475 |
AUD | 2 | 216420000000000 | 0.00000000000000462065 | 0.065109017524073500 | $0.61 | 0.0394104957988599000 | 0.00001121355304909 |
BRL | 2 | 674888154000000 | 0.00000000000000148173 | 0.020878857465558600 | $0.19 | 0.0039026380942576900 | 0.00000346277310273 |
CHF | 2 | 107432400000000 | 0.00000000000000930818 | 0.131160558384249000 | $1.02 | 0.1340108806726950000 | 0.00001892819885136 |
RUB | 2 | 5062290000000000 | 0.00000000000000019754 | 0.002783501848483590 | $0.01 | 0.0000364605586142105 | 0.00000024266340635 |
THB | 2 | 2086203000000000 | 0.00000000000000047934 | 0.006754325237074240 | $0.03 | 0.0002054292610286960 | 0.00000056344667484 |
SAR | 2 | 194879800000000 | 0.00000000000000513137 | 0.072305562570158500 | $0.27 | 0.0192247009959278000 | 0.00000492561394251 |
AED | 2 | 169370000000000 | 0.00000000000000590423 | 0.083195923555293000 | $0.27 | 0.0226502222965908000 | 0.00000504362637294 |
SGD | 2 | 65602100000000 | 0.00000000000001524341 | 0.214793330892761000 | $0.70 | 0.1496416541090850000 | 0.00001290637242159 |
MYR | 2 | 196142970000000 | 0.00000000000000509832 | 0.071839911328761800 | $0.23 | 0.0164437464095326000 | 0.00000424040627464 |
MXN | 2 | 1075609856600000 | 0.00000000000000092971 | 0.013100376020261900 | $0.04 | 0.0005215518782401990 | 0.00000073754111893 |
TRY | 2 | 266853972700000 | 0.00000000000000374737 | 0.052803761660318700 | $0.15 | 0.0077898346674402500 | 0.00000273297628769 |
VND | 2 | 921184805000000000 | 0.00000000000000000109 | 0.000015296489364650 | $0.00 | 0.0000000006472876744 | 0.00000000078393139 |
SEK | 2 | 375795200000000 | 0.00000000000000266102 | 0.037496204242523500 | $0.10 | 0.0036834625288696500 | 0.00000181987448264 |
PLN | 2 | 155778160000000 | 0.00000000000000641939 | 0.090454872316889500 | $0.24 | 0.0213682357059139000 | 0.00000437632116599 |
Total Inverse Issuance | Unit of account (sum of all) | ||||||
0.00000000000007096782 | 0.5397933308126700000 |
The storage should contain:
In other storage store the Unit of Account
as a simple value that gets overwritten each time it changes.
Since we normally use Ledger Balance
which is u64
the floats should be converted for storage by multiplying by 1_000_000_000_000_000_000
. There are conversion utilities in the primitives directory.
The weighting per currency changes for all currencies, whenever at least one issuance changes. This also implies that Weight adjusted price
and Unit of Account per currency unit
changes for all currencies even if the price is not updated when an issuance change happens.
Additionally Weight adjusted price
and Unit of Account per currency unit
must also be updated when the price changes.
We need to implement a new pallet. This pallet draws inspiration from this totem doc
STORAGE
This pallet will introduce a storage called
CurrencyBasket
which can be aStorageMap
of a particular currency to it'sissuance
which is aLedgerBalance
and theweight(w)
that will be calculated.This pallet will also introduce another storage called
Neer
(Nominal Effective Exchange Rate) which is the actual Unit of Account and which will be aStorageValue
This pallet will also introduce another storage for whitelisted accounts that are allowed to send
extrinsics
to update the basket of currencies maintainedEXTRINSICS
This pallet will introduce an
extrinsic
for addingwhitelisted
accountThis pallet will introduce an
extrinsic
for removingwhitelisted
accountThis pallet will introduce an
extrinsic
for adding a new Currency to theCurrencyBasket
storage. When a new Currency is added to the basket/pool, we calculate theweight(w)
for that currency and also re-calculate and update theNeer
(Nominal Effective Exchange Rate) for the pallet, as this will change.This pallet will introduce an extrinsic for removing a Currency from the
CurrencyBasket
storage. When a Currency is removed from the basket/pool, we re-calculate and update theNeer
(Nominal Effective Exchange Rate) for the pallet, as this will change.TODOS