Skip to content

Commit

Permalink
[libra framework] Update comments in LBR module, use create_from_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Zakian authored and bors-libra committed Sep 18, 2020
1 parent fd0c740 commit f14a2ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Binary file modified language/stdlib/compiled/stdlib/024_LBR.mv
Binary file not shown.
19 changes: 10 additions & 9 deletions language/stdlib/modules/LBR.move
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ module LBR {
use 0x1::CoreAddresses;
use 0x1::Errors;
use 0x1::FixedPoint32::{Self, FixedPoint32};
use 0x1::Libra::{Self, Libra,
// RegisterNewCurrency
};
use 0x1::Libra::{Self, Libra};
use 0x1::LibraTimestamp;

/// The type tag representing the `LBR` currency on-chain.
resource struct LBR { }

/// A `ReserveComponent` holds one part of the on-chain reserve that backs
/// `LBR` coins. Each `ReserveComponent` holds both the backing currency
/// itself, along with the ratio of the backing currency to the `LBR` coin.
/// For example, if `Coin1` makes up 1/2 of an `LBR`, then the `ratio` field would be 0.5.
/// itself, along with the ratio between this coin and the `LBR`.
/// For example, if every `LBR` coin is made up of 100 `Coin1`'s and
/// `1/100`'th of a `Coin2`, then the `ratio` fields of
/// `ReserveComponent<Coin1>` and `ReserveComponent<Coin2>` would be `100`
/// and `0.01` respectively.
resource struct ReserveComponent<CoinType> {
/// Specifies the relative ratio between the `CoinType` and `LBR` (i.e., how
/// many `CoinType`s make up one `LBR`).
Expand All @@ -46,8 +47,8 @@ module LBR {
/// coins, and also each reserve component that holds the backing for these coins on-chain.
/// A crucial invariant of this on-chain reserve is that for each component
/// `c_i`, `c_i.value/c_i.ratio >= LBR.market_cap`.
/// e.g., if `coin1.ratio = 1/2` and `coin2.ratio = 1/2` and `LBR.market_cap ==
/// 100`, then `coin1.value >= 50`, and `coin2.value >= 50`.
/// e.g., if `coin1.ratio = 100` and `coin2.ratio = 1/100` and `LBR.market_cap ==
/// 100`, then `coin1.value >= 10_000`, and `coin2.value >= 1`.
resource struct Reserve {
/// The mint capability allowing minting of `LBR` coins.
mint_cap: Libra::MintCapability<LBR>,
Expand Down Expand Up @@ -113,11 +114,11 @@ module LBR {
AccountLimits::publish_unrestricted_limits<LBR>(lr_account);
let preburn_cap = Libra::create_preburn<LBR>(tc_account);
let coin1 = ReserveComponent<Coin1> {
ratio: FixedPoint32::create_from_rational(1, 2),
ratio: FixedPoint32::create_from_raw_value(2147483648), // 2^31 = 1/2
backing: Libra::zero<Coin1>(),
};
let coin2 = ReserveComponent<Coin2> {
ratio: FixedPoint32::create_from_rational(1, 2),
ratio: FixedPoint32::create_from_raw_value(2147483648), // 2^31 = 1/2
backing: Libra::zero<Coin2>(),
};
move_to(lr_account, Reserve { mint_cap, burn_cap, preburn_cap, coin1, coin2 });
Expand Down
15 changes: 9 additions & 6 deletions language/stdlib/modules/doc/LBR.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ The type tag representing the <code><a href="#0x1_LBR">LBR</a></code> currency o

A <code><a href="#0x1_LBR_ReserveComponent">ReserveComponent</a></code> holds one part of the on-chain reserve that backs
<code><a href="#0x1_LBR">LBR</a></code> coins. Each <code><a href="#0x1_LBR_ReserveComponent">ReserveComponent</a></code> holds both the backing currency
itself, along with the ratio of the backing currency to the <code><a href="#0x1_LBR">LBR</a></code> coin.
For example, if <code><a href="Coin1.md#0x1_Coin1">Coin1</a></code> makes up 1/2 of an <code><a href="#0x1_LBR">LBR</a></code>, then the <code>ratio</code> field would be 0.5.
itself, along with the ratio between this coin and the <code><a href="#0x1_LBR">LBR</a></code>.
For example, if every <code><a href="#0x1_LBR">LBR</a></code> coin is made up of 100 <code><a href="Coin1.md#0x1_Coin1">Coin1</a></code>'s and
<code>1/100</code>'th of a <code><a href="Coin2.md#0x1_Coin2">Coin2</a></code>, then the <code>ratio</code> fields of
<code><a href="#0x1_LBR_ReserveComponent">ReserveComponent</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt;</code> and <code><a href="#0x1_LBR_ReserveComponent">ReserveComponent</a>&lt;<a href="Coin2.md#0x1_Coin2">Coin2</a>&gt;</code> would be <code>100</code>
and <code>0.01</code> respectively.


<pre><code><b>resource</b> <b>struct</b> <a href="#0x1_LBR_ReserveComponent">ReserveComponent</a>&lt;CoinType&gt;
Expand Down Expand Up @@ -113,8 +116,8 @@ The on-chain reserve for the <code><a href="#0x1_LBR">LBR</a></code> holds both
coins, and also each reserve component that holds the backing for these coins on-chain.
A crucial invariant of this on-chain reserve is that for each component
<code>c_i</code>, <code>c_i.value/c_i.ratio &gt;= <a href="#0x1_LBR">LBR</a>.market_cap</code>.
e.g., if <code>coin1.ratio = 1/2</code> and <code>coin2.ratio = 1/2</code> and <code><a href="#0x1_LBR">LBR</a>.market_cap ==
100</code>, then <code>coin1.value &gt;= 50</code>, and <code>coin2.value &gt;= 50</code>.
e.g., if <code>coin1.ratio = 100</code> and <code>coin2.ratio = 1/100</code> and <code><a href="#0x1_LBR">LBR</a>.market_cap ==
100</code>, then <code>coin1.value &gt;= 10_000</code>, and <code>coin2.value &gt;= 1</code>.


<pre><code><b>resource</b> <b>struct</b> <a href="#0x1_LBR_Reserve">Reserve</a>
Expand Down Expand Up @@ -268,11 +271,11 @@ restrictions are enforced in the <code><a href="Libra.md#0x1_Libra_register_curr
<a href="AccountLimits.md#0x1_AccountLimits_publish_unrestricted_limits">AccountLimits::publish_unrestricted_limits</a>&lt;<a href="#0x1_LBR">LBR</a>&gt;(lr_account);
<b>let</b> preburn_cap = <a href="Libra.md#0x1_Libra_create_preburn">Libra::create_preburn</a>&lt;<a href="#0x1_LBR">LBR</a>&gt;(tc_account);
<b>let</b> coin1 = <a href="#0x1_LBR_ReserveComponent">ReserveComponent</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt; {
ratio: <a href="FixedPoint32.md#0x1_FixedPoint32_create_from_rational">FixedPoint32::create_from_rational</a>(1, 2),
ratio: <a href="FixedPoint32.md#0x1_FixedPoint32_create_from_raw_value">FixedPoint32::create_from_raw_value</a>(2147483648), // 2^31 = 1/2
backing: <a href="Libra.md#0x1_Libra_zero">Libra::zero</a>&lt;<a href="Coin1.md#0x1_Coin1">Coin1</a>&gt;(),
};
<b>let</b> coin2 = <a href="#0x1_LBR_ReserveComponent">ReserveComponent</a>&lt;<a href="Coin2.md#0x1_Coin2">Coin2</a>&gt; {
ratio: <a href="FixedPoint32.md#0x1_FixedPoint32_create_from_rational">FixedPoint32::create_from_rational</a>(1, 2),
ratio: <a href="FixedPoint32.md#0x1_FixedPoint32_create_from_raw_value">FixedPoint32::create_from_raw_value</a>(2147483648), // 2^31 = 1/2
backing: <a href="Libra.md#0x1_Libra_zero">Libra::zero</a>&lt;<a href="Coin2.md#0x1_Coin2">Coin2</a>&gt;(),
};
move_to(lr_account, <a href="#0x1_LBR_Reserve">Reserve</a> { mint_cap, burn_cap, preburn_cap, coin1, coin2 });
Expand Down

0 comments on commit f14a2ad

Please sign in to comment.