Skip to content
This repository has been archived by the owner on Feb 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #34 from Setheum-Labs/standard-0.5.2
Browse files Browse the repository at this point in the history
Standard 0.5.2
  • Loading branch information
balqaasem authored Mar 27, 2021
2 parents 5e43ee4 + cd4360e commit f5845d1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ homepage = 'https://setheum.xyz'
license = 'Apache-2.0 License'
name = 'stp258-currencies'
repository = 'https://github.com/Setheum-Labs/Setheum/'
version = '0.5.1-dev'
version = '0.5.2'

[dependencies]
serde = { version = "1.0.111", optional = true }
Expand All @@ -18,15 +18,15 @@ sp-std = { version = "3.0.0", default-features = false }
frame-support = { version = "3.0.0", default-features = false }
frame-system = { version = "3.0.0", default-features = false }

stp258-traits = { version = '0.5.0-dev', git = "https://github.com/Setheum-Labs/stp258-traits", branch = "pretty-messy" }
stp258-traits = { version = '0.5.2', git = "https://github.com/Setheum-Labs/stp258-traits", branch = "tes-markr" }
orml-utilities = { version = "0.4.0", default-features = false }

funty = { version = "1.1.0", default-features = false } # https://github.com/bitvecto-rs/bitvec/issues/105

[dev-dependencies]
sp-core = "3.0.0"
pallet-balances = "3.0.0"
stp258-tokens = { version = "0.5.1-dev", git = "https://github.com/Setheum-Labs/stp258-tokens"}
stp258-tokens = { version = "0.5.2", git = "https://github.com/Setheum-Labs/stp258-tokens"}

[features]
default = ["std"]
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# STP-258 Currencies
## Setheum Tokenization Protocol 258 Standard
Multi-Currency Stablecoin SERP Module built on top of `Stp258Tokens` and `Stp258Traits`.

Multi-Currency Stablecoin SERP Module based on `Stp258Standard` built on top of `Stp258Tokens` and `Stp258Traits`.

## Overview

Expand Down
16 changes: 13 additions & 3 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use sp_runtime::{
AccountId32, ModuleId, Perbill,
};

use crate as stp258_standard;
use crate as stp258_currencies;

parameter_types! {
pub const BlockHashCount: u64 = 250;
Expand All @@ -23,7 +23,7 @@ impl frame_system::Config for Runtime {
type Origin = Origin;
type Call = Call;
type Index = u64;
type BlockNumber = u64;
type BlockNumber = Blocknumber;
type Hash = H256;
type Hashing = ::sp_runtime::traits::BlakeTwo256;
type AccountId = AccountId;
Expand All @@ -46,6 +46,7 @@ impl frame_system::Config for Runtime {

type CurrencyId = u32;
type Balance = u64;
type Blocknumber = u64;

parameter_types! {
pub const ExistentialDeposit: u64 = 1;
Expand Down Expand Up @@ -77,6 +78,7 @@ parameter_type_with_key! {
};
}

const PERCENT: Balance = 100;
const SERP_QUOTE_MULTIPLE: Balance = 2;
const SINGLE_UNIT: Balance = 1;
const SERPER_RATIO: Perbill = Perbill::from_percent(25);
Expand All @@ -93,6 +95,9 @@ parameter_types! {
pub const GetSingleUnit: Balance = SINGLE_UNIT;
pub const GetSerperRatio: Perbill = SERPER_RATIO;
pub const GetSettPayRatio: Perbill = SETT_PAY_RATIO;
pub const GetSerpNativeId: CurrencyId = DNAR;
pub const GetPercent: Balance = PERCENT;
pub const AdjustmentFrequency: Blocknumber = ADJUSTMENT_FREQUENCY;
}

impl stp258_tokens::Config for Runtime {
Expand All @@ -103,6 +108,9 @@ impl stp258_tokens::Config for Runtime {
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type GetBaseUnit = GetBaseUnit;
type AdjustmentFrequency = AdjustmentFrequency;
type GetPercent = GetPercent;
type GetSerpNativeId = GetSerpNativeId;
type GetSerpQuoteMultiple = GetSerpQuoteMultiple;
type GetSerperAcc = GetSerperAcc;
type GetSettPayAcc = GetSettPayAcc;
Expand All @@ -116,6 +124,8 @@ pub const DNAR: CurrencyId = 1;
pub const SETT: CurrencyId = 2;
pub const JUSD: CurrencyId = 3;

pub const ADJUSTMENT_FREQUENCY: Blocknumber = 10;

parameter_types! {
pub const GetStp258NativeId: CurrencyId = DNAR;
}
Expand All @@ -140,7 +150,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic,
{
System: frame_system::{Module, Call, Storage, Config, Event<T>},
Stp258Standard: stp258_standard::{Module, Call, Event<T>},
Stp258Currencies: stp258_currencies::{Module, Call, Event<T>},
Stp258Tokens: stp258_tokens::{Module, Storage, Event<T>, Config<T>},
PalletBalances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
}
Expand Down
74 changes: 37 additions & 37 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Unit tests for the Stp258Standard module.
//! Unit tests for the Stp258Currencies module.
#![cfg(test)]

Expand All @@ -13,9 +13,9 @@ fn stp258_currency_lockable_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_ok!(Stp258Standard::set_lock(ID_1, SETT, &ALICE, 50 * 10_000));
assert_ok!(Stp258Currencies::set_lock(ID_1, SETT, &ALICE, 50 * 10_000));
assert_eq!(Stp258Tokens::locks(&ALICE, SETT).len(), 1);
assert_ok!(Stp258Standard::set_lock(ID_1, DNAR, &ALICE, 50));
assert_ok!(Stp258Currencies::set_lock(ID_1, DNAR, &ALICE, 50));
assert_eq!(PalletBalances::locks(&ALICE).len(), 1);
});
}
Expand All @@ -26,15 +26,15 @@ fn stp258_currency_reservable_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_eq!(Stp258Standard::total_issuance(DNAR), 400);
assert_eq!(Stp258Standard::total_issuance(SETT), 400 * 10_000);
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 100 * 10_000);
assert_eq!(Stp258Currencies::total_issuance(DNAR), 400);
assert_eq!(Stp258Currencies::total_issuance(SETT), 400 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 100 * 10_000);
assert_eq!(Stp258Native::free_balance(&ALICE), 100);

assert_ok!(Stp258Standard::reserve(SETT, &ALICE, 30 * 10_000));
assert_ok!(Stp258Standard::reserve(DNAR, &ALICE, 40));
assert_eq!(Stp258Standard::reserved_balance(SETT, &ALICE), 30 * 10_000);
assert_eq!(Stp258Standard::reserved_balance(DNAR, &ALICE), 40);
assert_ok!(Stp258Currencies::reserve(SETT, &ALICE, 30 * 10_000));
assert_ok!(Stp258Currencies::reserve(DNAR, &ALICE, 40));
assert_eq!(Stp258Currencies::reserved_balance(SETT, &ALICE), 30 * 10_000);
assert_eq!(Stp258Currencies::reserved_balance(DNAR, &ALICE), 40);
});
}

Expand Down Expand Up @@ -92,9 +92,9 @@ fn stp258_currency_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_ok!(Stp258Standard::transfer(Some(ALICE).into(), BOB, SETT, 50 * 10_000));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 50 * 10_000);
assert_eq!(Stp258Standard::free_balance(SETT, &BOB), 150 * 10_000);
assert_ok!(Stp258Currencies::transfer(Some(ALICE).into(), BOB, SETT, 50 * 10_000));
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 50 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &BOB), 150 * 10_000);
});
}

Expand All @@ -104,10 +104,10 @@ fn stp258_currency_extended_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_ok!(<Stp258Standard as Stp258CurrencyExtended<AccountId>>::update_balance(
assert_ok!(<Stp258Currencies as Stp258CurrencyExtended<AccountId>>::update_balance(
SETT, &ALICE, 50 * 10_000
));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 150 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 150 * 10_000);
});
}

Expand All @@ -117,15 +117,15 @@ fn stp258_native_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_ok!(Stp258Standard::transfer_native_currency(Some(ALICE).into(), BOB, 50));
assert_ok!(Stp258Currencies::transfer_native_currency(Some(ALICE).into(), BOB, 50));
assert_eq!(Stp258Native::free_balance(&ALICE), 50);
assert_eq!(Stp258Native::free_balance(&BOB), 150);

assert_ok!(Stp258Native::transfer(&ALICE, &BOB, 10));
assert_eq!(Stp258Native::free_balance(&ALICE), 40);
assert_eq!(Stp258Native::free_balance(&BOB), 160);

assert_eq!(Stp258Standard::slash(DNAR, &ALICE, 10), 0);
assert_eq!(Stp258Currencies::slash(DNAR, &ALICE, 10), 0);
assert_eq!(Stp258Native::free_balance(&ALICE), 30);
assert_eq!(Stp258Native::total_issuance(), 390);
});
Expand All @@ -140,7 +140,7 @@ fn stp258_native_extended_should_work() {
assert_ok!(Stp258Native::update_balance(&ALICE, 10));
assert_eq!(Stp258Native::free_balance(&ALICE), 110);

assert_ok!(<Stp258Standard as Stp258CurrencyExtended<AccountId>>::update_balance(
assert_ok!(<Stp258Currencies as Stp258CurrencyExtended<AccountId>>::update_balance(
DNAR,
&ALICE,
10
Expand Down Expand Up @@ -218,24 +218,24 @@ fn update_balance_call_should_work() {
.one_hundred_for_alice_n_bob_n_serper_n_settpay()
.build()
.execute_with(|| {
assert_ok!(Stp258Standard::update_balance(
assert_ok!(Stp258Currencies::update_balance(
Origin::root(),
ALICE,
DNAR,
-10
));
assert_eq!(Stp258Native::free_balance(&ALICE), 90);
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 100 * 10_000);
assert_ok!(Stp258Standard::update_balance(Origin::root(), ALICE, SETT, 10 * 10_000));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 110 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 100 * 10_000);
assert_ok!(Stp258Currencies::update_balance(Origin::root(), ALICE, SETT, 10 * 10_000));
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 110 * 10_000);
});
}

#[test]
fn update_balance_call_fails_if_not_root_origin() {
ExtBuilder::default().build().execute_with(|| {
assert_noop!(
Stp258Standard::update_balance(Some(ALICE).into(), ALICE, SETT, 100 * 10_000),
Stp258Currencies::update_balance(Some(ALICE).into(), ALICE, SETT, 100 * 10_000),
BadOrigin
);
});
Expand All @@ -249,36 +249,36 @@ fn call_event_should_work() {
.execute_with(|| {
System::set_block_number(1);

assert_ok!(Stp258Standard::transfer(Some(ALICE).into(), BOB, SETT, 50 * 10_000));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 50 * 10_000);
assert_eq!(Stp258Standard::free_balance(SETT, &BOB), 150 * 10_000);
assert_ok!(Stp258Currencies::transfer(Some(ALICE).into(), BOB, SETT, 50 * 10_000));
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 50 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &BOB), 150 * 10_000);

let transferred_event = Event::stp258_standard(crate::Event::Transferred(SETT, ALICE, BOB, 50 * 10_000));
let transferred_event = Event::stp258_currencies(crate::Event::Transferred(SETT, ALICE, BOB, 50 * 10_000));
assert!(System::events().iter().any(|record| record.event == transferred_event));

assert_ok!(<Stp258Standard as Stp258Currency<AccountId>>::transfer(
assert_ok!(<Stp258Currencies as Stp258Currency<AccountId>>::transfer(
SETT, &ALICE, &BOB, 10 * 10_000
));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 40 * 10_000);
assert_eq!(Stp258Standard::free_balance(SETT, &BOB), 160 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 40 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &BOB), 160 * 10_000);

let transferred_event = Event::stp258_standard(crate::Event::Transferred(SETT, ALICE, BOB, 10 * 10_000));
let transferred_event = Event::stp258_currencies(crate::Event::Transferred(SETT, ALICE, BOB, 10 * 10_000));
assert!(System::events().iter().any(|record| record.event == transferred_event));

assert_ok!(<Stp258Standard as Stp258Currency<AccountId>>::deposit(
assert_ok!(<Stp258Currencies as Stp258Currency<AccountId>>::deposit(
SETT, &ALICE, 100 * 10_000
));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 140 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 140 * 10_000);

let transferred_event = Event::stp258_standard(crate::Event::Deposited(SETT, ALICE, 100 * 10_000));
let transferred_event = Event::stp258_currencies(crate::Event::Deposited(SETT, ALICE, 100 * 10_000));
assert!(System::events().iter().any(|record| record.event == transferred_event));

assert_ok!(<Stp258Standard as Stp258Currency<AccountId>>::withdraw(
assert_ok!(<Stp258Currencies as Stp258Currency<AccountId>>::withdraw(
SETT, &ALICE, 20 * 10_000
));
assert_eq!(Stp258Standard::free_balance(SETT, &ALICE), 120 * 10_000);
assert_eq!(Stp258Currencies::free_balance(SETT, &ALICE), 120 * 10_000);

let transferred_event = Event::stp258_standard(crate::Event::Withdrawn(SETT, ALICE, 20 * 10_000));
let transferred_event = Event::stp258_currencies(crate::Event::Withdrawn(SETT, ALICE, 20 * 10_000));
assert!(System::events().iter().any(|record| record.event == transferred_event));
});
}

0 comments on commit f5845d1

Please sign in to comment.