Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currencies #469

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System

#### The Setter - SERP Basket Stablecoin
```
SETT("Setter", 12) = 2,
SETR("Setter", 12) = 2,
```

#### The SettCurrencies - SERP Stablecoins
Expand All @@ -53,17 +53,17 @@ DRAM("Setheum Dirham", 12) = 1, // Staking Reward and Governance Token - System
SARJ("Setheum Saudi Riyal", 12) = 12,
```

1. The Setter - The Setter is a basket currency pegged to the Top 10 Strongest and most valuable currencies. It serves as the medium of Exchange and the Defacto stablecoin of the Setheum Ecosystem. All other Setheum system stablecoins orbit around the Setter (SETT) and the SettMint for minting Setheum Currencies (system stablecoins) accepts only the Setter as the Minting Reserve Asset. Only with the Setter (SETT) can a user participate in the DNAR Auctions to stabilize the price of the Setter, while the Setter is Auctioned to stabilize the price of all the other SettCurrencies (system stablecoins). It's the star that brightens many planets - 10 to be exact
1. The Setter - The Setter is a basket currency pegged to the Top 10 Strongest and most valuable currencies. It serves as the medium of Exchange and the Defacto stablecoin of the Setheum Ecosystem. All other Setheum system stablecoins orbit around the Setter (SETR) and the SettMint for minting Setheum Currencies (system stablecoins) accepts only the Setter as the Minting Reserve Asset. Only with the Setter (SETR) can a user participate in the DNAR Auctions to stabilize the price of the Setter, while the Setter is Auctioned to stabilize the price of all the other SettCurrencies (system stablecoins). It's the star that brightens many planets - 10 to be exact

2. [The SERP](./lib-serp) - The SERP (Setheum Elastic Reserve Protocol) is algorithmically responsible for stabilizing the prices of the Setheum Stable Currencies. No human interferrance is needed for this, it's all algorithmically handled by the SERP. The SERP is the backbone of Setheum, it is based on my TES (Token Elasticity of Supply) algorithm based on PES (Price Elasticity of Supply) such that the demand curve or price of a currency determines the supply serping point, meaning the supply curve of a SettCurrency will be adjusted according to the demand curve of that specific SettCurrency. The result will be burning or minting an amount equivalent to the serping point produced by the SERP-TES, the burning amount will be bought back by the SERP automatically through the built-in-DEX and the bought amount will be burnt to meet the satisfaction of the demand curve to prop the price back up to its peg, the opposite is done to lower the price of an under-supplied currency that is on demand and above its peg on the demand curve, for this the mint amount is divided into receipients including the SettPayTreasury where CashDrops are deposited for users to claim, the System Treasury under Governance, the Charity Fund stewarded by the Setheum Foundation, and the WelfareTreasury, more on the Welfare Treasury below.
2. [The SERP](./lib-serp) - The SERP (Setheum Elastic Reserve Protocol) is algorithmically responsible for stabilizing the prices of the Setheum Stable Currencies. No human interferrance is needed for this, it's all algorithmically handled by the SERP. The SERP is the backbone of Setheum, it is based on my TES (Token Elasticity of Supply) algorithm based on PES (Price Elasticity of Supply) such that the demand curve or price of a currency determines the supply serping point, meaning the supply curve of a SetCurrency will be adjusted according to the demand curve of that specific SetCurrency. The result will be burning or minting an amount equivalent to the serping point produced by the SERP-TES, the burning amount will be bought back by the SERP automatically through the built-in-DEX and the bought amount will be burnt to meet the satisfaction of the demand curve to prop the price back up to its peg, the opposite is done to lower the price of an under-supplied currency that is on demand and above its peg on the demand curve, for this the mint amount is divided into receipients including the SettPayTreasury where CashDrops are deposited for users to claim, the System Treasury under Governance, the Charity Fund stewarded by the Setheum Foundation, and the WelfareTreasury, more on the Welfare Treasury below.

In The SERP and Setheum lingua, I coined these terms:
* serp: to increase or decrease the supply of a Setheum stable Currency at its serping point in the curve, on either the x or y axis, the negative or the positive.
* serpup: to increase the supply of a Setheum stablecurrency at its serping point.
* serpdown: to decrease the supply of a Setheum stablecurrency at its serping point.

3. [The SettMint](./lib-serml/settmint) - The Settmint is partly inspired by the Maker Protocol (MakerDAO), except that SettMint is on a very different principle of Setheum that ought not to be violated.
SettMint is not a CDP but quite similar, as users can hold, authorize & transfer positions, users can reserve the Setter (SETT) to mint any SettCurrency of their choice without the need for over-collateralization, debt, interest rates, liquidation, or even stability fees. The stability of the Currencies is handles by the SERP, and the the Setter used as the reserve currency is also a SettCurrency (Setheum System Stablecoin) therefore eliminating position volatility and the risk of liquidation as all risk parameters have been eliminated with the Setter and Setheum's strong principle on the matters of the SettMint and Setheum's Monetary Policy.
SettMint is not a CDP but quite similar, as users can hold, authorize & transfer positions, users can reserve the Setter (SETR) to mint any SetCurrency of their choice without the need for over-collateralization, debt, interest rates, liquidation, or even stability fees. The stability of the Currencies is handles by the SERP, and the the Setter used as the reserve currency is also a SetCurrency (Setheum System Stablecoin) therefore eliminating position volatility and the risk of liquidation as all risk parameters have been eliminated with the Setter and Setheum's strong principle on the matters of the SettMint and Setheum's Monetary Policy.
This is one of the reasons I see Setheum as one of the most Sophisticated Advanced Economic Systems yet so simple, easy to use and understand, and even easier to get started.

4. The SettPay - The SettPay is responsible for the CashDrops that are dispatched by the SERP to the claimants (transactors that claim cashdrops). It is under the governance of the "Financial Council". They decide how much percent claimants get based on how much they spent, these params are custom and governable for every Setheum System currency including the DNAR. For example, DNAR spenders get 2.58% cashdrop per claimed transaction if their spent amount is >= 10000 dollars, else if their spent amount is < 10000 dollars && >= 100 then they get 4% cashdrop, else if their spent amount is < 100 then they get 5% cashdrop. The Welfare Council can update these parameters by governance proposals and voting without the need for forking or even a runtime upgrade.
Expand Down
2 changes: 1 addition & 1 deletion lib-serml/evm/evm-manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn name_works() {
);

assert_eq!(
EvmCurrencyIdMapping::<Runtime>::name(CurrencyId::DexShare(DexShare::Token(TokenSymbol::DNAR), DexShare::Token(TokenSymbol::SETT))),
EvmCurrencyIdMapping::<Runtime>::name(CurrencyId::DexShare(DexShare::Token(TokenSymbol::DNAR), DexShare::Token(TokenSymbol::SETR))),
Some(b"LP Setheum Dinar - Setter".to_vec())
);

Expand Down
20 changes: 10 additions & 10 deletions lib-serml/serp/serp-prices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! The data from Oracle cannot be used in production, prices module will
//! do some process and feed prices for setheum, this includes constructing
//! the Setter (SETT) currency basket price.
//! the Setter (SETR) currency basket price.
//! Process include:
//! - specify a fixed price for stable currencies
//! - specify the Setter basket currency price
Expand Down Expand Up @@ -68,7 +68,7 @@ pub mod module {
type Source: DataProvider<CurrencyId, Price> + DataFeeder<CurrencyId, Price, Self::AccountId>;

#[pallet::constant]
/// The Setter currency id, it should be SETT in Setheum.
/// The Setter currency id, it should be SETR in Setheum.
type SetterCurrencyId: Get<CurrencyId>;

#[pallet::constant]
Expand Down Expand Up @@ -252,9 +252,9 @@ impl<T: Config> PriceProvider<CurrencyId> for Pallet<T> {
}
}

/// get the exchange rate of a specific SettCurrency to USD
/// get the exchange rate of a specific SetCurrency to USD
/// Note: this returns the price for 1 basic unit
/// For the SERP TO USE WHEN STABILISING SettCurrency prices.
/// For the SERP TO USE WHEN STABILISING SetCurrency prices.
fn get_market_price(currency_id: CurrencyId) -> Option<Price>{
let maybe_feed_price = if let CurrencyId::DexShare(symbol_0, symbol_1) = currency_id {
let token_0 = match symbol_0 {
Expand Down Expand Up @@ -287,10 +287,10 @@ impl<T: Config> PriceProvider<CurrencyId> for Pallet<T> {
}
}

/// get the exchange rate of a specific SettCurrency peg to USD
/// get the exchange rate of a specific SetCurrency peg to USD
/// Note: this returns the price for 1 basic unit
/// For the SERP TO USE WHEN STABILISING SettCurrency peg prices.
/// The settcurrency_id matching to its peg,
/// For the SERP TO USE WHEN STABILISING SetCurrency peg prices.
/// The setcurrency_id matching to its peg,
fn get_peg_price(currency_id: CurrencyId) -> Option<Price> {
let maybe_feed_price = if currency_id == T::SetterCurrencyId::get() {
Self::get_setter_price()
Expand Down Expand Up @@ -337,9 +337,9 @@ impl<T: Config> PriceProvider<CurrencyId> for Pallet<T> {
}
}

/// get the exchange rate of a specific SettCurrency peg to USD
/// get the exchange rate of a specific SetCurrency peg to USD
/// Note: this returns the price for 1 basic unit
/// For the SERP TO USE WHEN STABILISING SettCurrency peg prices.
/// For the SERP TO USE WHEN STABILISING SetCurrency peg prices.
fn get_setter_price() -> Option<Price> {
if let (Some(price_a),
Some(price_b),
Expand Down Expand Up @@ -470,7 +470,7 @@ fn lp_token_fair_price(
.map(Price::from_inner)
}

/// Get the price of a Setter (SETT basket coin - basket of currencies) -
/// Get the price of a Setter (SETR basket coin - basket of currencies) -
/// aggregate the setter price.
/// the final price = total_price_of_basket(all currencies prices combined) -
/// divided by the amount of currencies in the basket.
Expand Down
26 changes: 13 additions & 13 deletions lib-serml/serp/serp-prices/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod serp_prices {
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
pub const DRAM: CurrencyId = CurrencyId::Token(TokenSymbol::DRAM);
pub const SETT: CurrencyId = CurrencyId::Token(TokenSymbol::SETT);
pub const SETR: CurrencyId = CurrencyId::Token(TokenSymbol::SETR);
pub const AUDJ: CurrencyId = CurrencyId::Token(TokenSymbol::AUDJ);
pub const CADJ: CurrencyId = CurrencyId::Token(TokenSymbol::CADJ);
pub const EURJ: CurrencyId = CurrencyId::Token(TokenSymbol::EURJ);
Expand Down Expand Up @@ -223,7 +223,7 @@ ord_parameter_types! {
}

parameter_types! {
pub const SetterCurrencyId: CurrencyId = SETT; // Setter currency ticker is SETT.
pub const SetterCurrencyId: CurrencyId = SETR; // Setter currency ticker is SETR.
pub const GetSettUSDCurrencyId: CurrencyId = USDJ; // SettUSD currency ticker is USDJ.
pub const GetFiatAUDCurrencyId: CurrencyId = AUD; // The AUD Fiat currency denomination.
pub const GetFiatCADCurrencyId: CurrencyId = CAD; // The CAD Fiat currency denomination.
Expand All @@ -237,20 +237,20 @@ parameter_types! {
pub const GetFiatUSDCurrencyId: CurrencyId = USD; // The USD Fiat currency denomination.
pub FiatUsdFixedPrice: Price = Price::one(); // Fixed 1 USD Fiat denomination for pricing.

pub const GetSetterPegOneCurrencyId: CurrencyId = GBP; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegTwoCurrencyId: CurrencyId = EUR; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegThreeCurrencyId: CurrencyId = KWD; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegFourCurrencyId: CurrencyId = JOD; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegFiveCurrencyId: CurrencyId = BHD; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegSixCurrencyId: CurrencyId = KYD; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegSevenCurrencyId: CurrencyId = OMR; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegEightCurrencyId: CurrencyId = CHF; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegNineCurrencyId: CurrencyId = GIP; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegTenCurrencyId: CurrencyId = USD; // Fiat pegs of the Setter (SETT).
pub const GetSetterPegOneCurrencyId: CurrencyId = GBP; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegTwoCurrencyId: CurrencyId = EUR; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegThreeCurrencyId: CurrencyId = KWD; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegFourCurrencyId: CurrencyId = JOD; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegFiveCurrencyId: CurrencyId = BHD; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegSixCurrencyId: CurrencyId = KYD; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegSevenCurrencyId: CurrencyId = OMR; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegEightCurrencyId: CurrencyId = CHF; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegNineCurrencyId: CurrencyId = GIP; // Fiat pegs of the Setter (SETR).
pub const GetSetterPegTenCurrencyId: CurrencyId = USD; // Fiat pegs of the Setter (SETR).


pub StableCurrencyIds: Vec<CurrencyId> = vec![
SETT, AUDJ, CADJ, BTC, EURJ, GBPJ,
SETR, AUDJ, CADJ, BTC, EURJ, GBPJ,
JPYJ, SARJ, SEKJ, SGDJ, USDJ,
];
pub FiatCurrencyIds: Vec<CurrencyId> = vec![
Expand Down
2 changes: 1 addition & 1 deletion lib-serml/serp/serp-staking/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Staking Module

Serp Staking supports multicurrency rewards, such that in Setheum, staking the
Dinar (DNAR) will reward the Dirham (DRAM) and the Setter (SETT).
Dinar (DNAR) will reward the Dirham (DRAM) and the Setter (SETR).

The Staking module is used to manage funds at stake by network maintainers.

Expand Down
4 changes: 2 additions & 2 deletions lib-serml/serp/serp-staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ pub mod pallet {
/// The Currency for managing assets related to the SERP (Setheum Elastic Reserve Protocol).
type MultiCurrency: MultiCurrencyExtended<Self::AccountId, CurrencyId = CurrencyId, Balance = Balance>;

/// The Incentive reward type (SETT)
/// SETT in Setheum.
/// The Incentive reward type (SETR)
/// SETR in Setheum.
#[pallet::constant]
type SetterCurrencyId: Get<CurrencyId>;

Expand Down
4 changes: 2 additions & 2 deletions lib-serml/serp/serp-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub const BLOCK_TIME: u64 = 1000;
// Currencies constants - CurrencyId/TokenSymbol
pub const DNAR: CurrencyId = CurrencyId::Token(TokenSymbol::DNAR);
pub const DRAM: CurrencyId = CurrencyId::Token(TokenSymbol::DRAM);
pub const SETT: CurrencyId = CurrencyId::Token(TokenSymbol::SETT);
pub const SETR: CurrencyId = CurrencyId::Token(TokenSymbol::SETR);

/// The AccountId alias in this test module.
pub(crate) type AccountId = u64;
Expand Down Expand Up @@ -195,7 +195,7 @@ pub type AdaptedBasicCurrency = orml_currencies::BasicCurrencyAdapter<Runtime, P

parameter_types! {
pub const GetNativeCurrencyId: CurrencyId = DNAR;
pub const SetterCurrencyId: CurrencyId = SETT;
pub const SetterCurrencyId: CurrencyId = SETR;
pub const DirhamCurrencyId: CurrencyId = DRAM;
}
impl orml_currencies::Config for Runtime {
Expand Down
24 changes: 12 additions & 12 deletions lib-serml/serp/serp-staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ fn reward_validator_slashing_validator_does_not_overflow() {
ErasValidatorReward::<Test>::insert(0, stake);
assert_ok!(Staking::payout_stakers(Origin::signed(1337), 11, 0));
assert_eq!(Tokens::total_balance(DRAM, &11), halved_stake * 2);
assert_eq!(Tokens::total_balance(SETT, &11), halved_stake * 2);
assert_eq!(Tokens::total_balance(SETR, &11), halved_stake * 2);

// Set staker
let _ = Balances::make_free_balance_be(&11, stake);
Expand Down Expand Up @@ -2949,8 +2949,8 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() {

let init_balance_5 = Tokens::total_balance(DRAM, &5);
let init_balance_50 = Tokens::total_balance(DRAM, &50);
let init_balance_5 = Tokens::total_balance(SETT, &5);
let init_balance_50 = Tokens::total_balance(SETT, &50);
let init_balance_5 = Tokens::total_balance(SETR, &5);
let init_balance_50 = Tokens::total_balance(SETR, &50);

let part_for_10 = Perbill::from_rational::<u32>(1000, 1125);
let part_for_100 = Perbill::from_rational::<u32>(125, 1125);
Expand All @@ -2963,8 +2963,8 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() {

MockPriceSource::set_relative_price(Some(Price::one()));
assert_eq!(
SerpPrices::get_relative_price(DRAM, SETT),
Some(Price::saturating_from_rational(1, 1)) // 1DRAM = 1SETT
SerpPrices::get_relative_price(DRAM, SETR),
Some(Price::saturating_from_rational(1, 1)) // 1DRAM = 1SETR
);

// Check state
Expand Down Expand Up @@ -3037,11 +3037,11 @@ fn claim_reward_at_the_last_era_and_no_double_claim_and_invalid_claim() {
init_balance_50 + part_for_50 * (halved_total_payout_1 + halved_total_payout_2),
);
assert_eq!(
Tokens::total_balance(SETT, &5),
Tokens::total_balance(SETR, &5),
init_balance_5 + part_for_5 * (halved_total_payout_1 + halved_total_payout_2),
);
assert_eq!(
Tokens::total_balance(SETT, &50),
Tokens::total_balance(SETR, &50),
init_balance_50 + part_for_50 * (halved_total_payout_1 + halved_total_payout_2),
);
});
Expand Down Expand Up @@ -3214,8 +3214,8 @@ fn test_payout_stakers() {

MockPriceSource::set_relative_price(Some(Price::one()));
assert_eq!(
PriceSource::get_relative_price(DRAM, SETT),
Some(Price::saturating_from_rational(1, 2)) // 1DRAM = 2SETT
PriceSource::get_relative_price(DRAM, SETR),
Some(Price::saturating_from_rational(1, 2)) // 1DRAM = 2SETR
);

// Create a validator:
Expand All @@ -3238,15 +3238,15 @@ fn test_payout_stakers() {
// Top 64 nominators of validator 11 automatically paid out, including the validator
// Validator payout goes to controller.
assert!(Tokens::free_balance(DRAM, &10) > balance);
assert!(Tokens::free_balance(SETT, &10) > balance);
assert!(Tokens::free_balance(SETR, &10) > balance);
for i in 36..100 {
assert!(Tokens::free_balance(DRAM, &(100 + i)) > balance + i as Balance);
assert!(Tokens::free_balance(SETT, &(100 + i)) > balance + i as Balance);
assert!(Tokens::free_balance(SETR, &(100 + i)) > balance + i as Balance);
}
// The bottom 36 do not
for i in 0..36 {
assert_eq!(Tokens::free_balance(DRAM, &(100 + i)), balance + i as Balance);
assert_eq!(Tokens::free_balance(SETT, &(100 + i)), balance + i as Balance);
assert_eq!(Tokens::free_balance(SETR, &(100 + i)), balance + i as Balance);
}

// We track rewards in `claimed_rewards` vec
Expand Down
Loading