Skip to content

Commit

Permalink
Rename vault (#104)
Browse files Browse the repository at this point in the history
* More vault to loan rename

* bump version
  • Loading branch information
xlc authored Feb 9, 2020
1 parent 26d3fd1 commit d46f977
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
12 changes: 6 additions & 6 deletions modules/honzon/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ decl_module! {
<cdp_engine::Module<T>>::settle_cdp_has_debit(who, currency_id)?;
}

pub fn update_vault(
pub fn update_loan(
origin,
currency_id: CurrencyIdOf<T>,
collateral: AmountOf<T>,
Expand All @@ -87,7 +87,7 @@ decl_module! {
<cdp_engine::Module<T>>::update_position(&who, currency_id, collateral, T::DebitAmount::zero())?;
}

pub fn transfer_vault_from(
pub fn transfer_loan_from(
origin,
currency_id: CurrencyIdOf<T>,
from: T::AccountId,
Expand All @@ -101,7 +101,7 @@ decl_module! {
<loans::Module<T>>::transfer(from.clone(), to.clone(), currency_id)?;
}

/// `origin` allow `to` to manipulate the `currency_id` vault
/// `origin` allow `to` to manipulate the `currency_id` loan
pub fn authorize(
origin,
currency_id: CurrencyIdOf<T>,
Expand All @@ -115,7 +115,7 @@ decl_module! {
Self::deposit_event(RawEvent::Authorization(from, to, currency_id));
}

/// `origin` refuse `to` to manipulate the vault of `currency_id`
/// `origin` refuse `to` to manipulate the loan of `currency_id`
pub fn unauthorize(
origin,
currency_id: CurrencyIdOf<T>,
Expand All @@ -129,7 +129,7 @@ decl_module! {
Self::deposit_event(RawEvent::UnAuthorization(from, to, currency_id));
}

/// `origin` refuse anyone to manipulate its vault
/// `origin` refuse anyone to manipulate its loan
pub fn unauthorize_all(origin) {
let from = ensure_signed(origin)?;

Expand All @@ -142,7 +142,7 @@ decl_module! {
}

impl<T: Trait> Module<T> {
/// check if `from` allow `to` to manipulate its vault
/// check if `from` allow `to` to manipulate its loan
pub fn check_authorization(from: &T::AccountId, to: &T::AccountId, currency_id: CurrencyIdOf<T>) -> DispatchResult {
ensure!(
from == to || Self::authorization(from, (currency_id, to)),
Expand Down
16 changes: 8 additions & 8 deletions modules/honzon/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn unauthorize_all_should_work() {
}

#[test]
fn transfer_vault_from_should_work() {
fn transfer_loan_from_should_work() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(CdpEngineModule::set_collateral_params(
Origin::ROOT,
Expand All @@ -116,9 +116,9 @@ fn transfer_vault_from_should_work() {
Some(Some(Ratio::from_rational(9, 5))),
Some(10000),
));
assert_ok!(HonzonModule::update_vault(Origin::signed(ALICE), BTC, 100, 50));
assert_ok!(HonzonModule::update_loan(Origin::signed(ALICE), BTC, 100, 50));
assert_ok!(HonzonModule::authorize(Origin::signed(ALICE), BTC, BOB));
assert_ok!(HonzonModule::transfer_vault_from(Origin::signed(BOB), BTC, ALICE));
assert_ok!(HonzonModule::transfer_loan_from(Origin::signed(BOB), BTC, ALICE));
assert_eq!(LoansModule::collaterals(BOB, BTC), 100);
assert_eq!(LoansModule::debits(BOB, BTC), 50);
});
Expand All @@ -128,14 +128,14 @@ fn transfer_vault_from_should_work() {
fn transfer_unauthorization_loans_should_not_work() {
ExtBuilder::default().build().execute_with(|| {
assert_noop!(
HonzonModule::transfer_vault_from(Origin::signed(ALICE), BTC, BOB),
HonzonModule::transfer_loan_from(Origin::signed(ALICE), BTC, BOB),
Error::<Runtime>::NoAuthorization,
);
});
}

#[test]
fn update_vault_should_work() {
fn update_loan_should_work() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(CdpEngineModule::set_collateral_params(
Origin::ROOT,
Expand All @@ -146,7 +146,7 @@ fn update_vault_should_work() {
Some(Some(Ratio::from_rational(9, 5))),
Some(10000),
));
assert_ok!(HonzonModule::update_vault(Origin::signed(ALICE), BTC, 100, 50));
assert_ok!(HonzonModule::update_loan(Origin::signed(ALICE), BTC, 100, 50));
assert_eq!(LoansModule::collaterals(ALICE, BTC), 100);
assert_eq!(LoansModule::debits(ALICE, BTC), 50);
});
Expand All @@ -163,11 +163,11 @@ fn emergency_shutdown_should_work() {
Error::<Runtime>::AlreadyShutdown,
);
assert_noop!(
HonzonModule::update_vault(Origin::signed(ALICE), BTC, 100, 50),
HonzonModule::update_loan(Origin::signed(ALICE), BTC, 100, 50),
Error::<Runtime>::AlreadyShutdown,
);
assert_noop!(
HonzonModule::transfer_vault_from(Origin::signed(ALICE), BTC, BOB),
HonzonModule::transfer_loan_from(Origin::signed(ALICE), BTC, BOB),
Error::<Runtime>::AlreadyShutdown,
);
});
Expand Down
21 changes: 10 additions & 11 deletions modules/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ decl_event!(
UpdatePosition(AccountId, CurrencyId, Amount, DebitAmount),
/// Update collaterals and debits success (account, currency_id, collaterals, debits)
UpdateCollateralsAndDebits(AccountId, CurrencyId, Amount, DebitAmount),
/// Transfer vault (from, to)
TransferVault(AccountId, AccountId, CurrencyId),
/// Transfer loan (from, to)
TransferLoan(AccountId, AccountId, CurrencyId),
}
);

Expand Down Expand Up @@ -104,7 +104,7 @@ impl<T: Trait> Module<T> {
) -> DispatchResult {
// ensure mutate safe
Self::check_add_and_sub(&who, currency_id, collaterals, debits)?;
Self::update_vault(&who, currency_id, collaterals, debits)?;
Self::update_loan(&who, currency_id, collaterals, debits)?;
Self::deposit_event(RawEvent::UpdateCollateralsAndDebits(
who,
currency_id,
Expand Down Expand Up @@ -161,15 +161,14 @@ impl<T: Trait> Module<T> {
}

// mutate collaterals and debits
Self::update_vault(who, currency_id, collaterals, debits)
.expect("Will never fail ensured by check_add_and_sub");
Self::update_loan(who, currency_id, collaterals, debits).expect("Will never fail ensured by check_add_and_sub");

Self::deposit_event(RawEvent::UpdatePosition(who.clone(), currency_id, collaterals, debits));

Ok(())
}

// transfer vault
// transfer loan
pub fn transfer(from: T::AccountId, to: T::AccountId, currency_id: CurrencyIdOf<T>) -> DispatchResult {
// get `from` position data
let collateral: BalanceOf<T> = Self::collaterals(&from, currency_id);
Expand All @@ -192,11 +191,11 @@ impl<T: Trait> Module<T> {
.map_err(|_| Error::<T>::RiskCheckFailed)?;

// execute transfer
Self::update_vault(&from, currency_id, -collateral, -debit)
Self::update_loan(&from, currency_id, -collateral, -debit)
.expect("Will never fail ensured by check_add_and_sub");
Self::update_vault(&to, currency_id, collateral, debit).expect("Will never fail ensured by check_add_and_sub");
Self::update_loan(&to, currency_id, collateral, debit).expect("Will never fail ensured by check_add_and_sub");

Self::deposit_event(RawEvent::TransferVault(from, to, currency_id));
Self::deposit_event(RawEvent::TransferLoan(from, to, currency_id));

Ok(())
}
Expand All @@ -221,7 +220,7 @@ impl<T: Trait> Module<T> {
Ok(())
}

/// ensure sum and sub will success when updating vault collaterals and debits
/// ensure sum and sub will success when updating loan collaterals and debits
fn check_add_and_sub(
who: &T::AccountId,
currency_id: CurrencyIdOf<T>,
Expand Down Expand Up @@ -267,7 +266,7 @@ impl<T: Trait> Module<T> {
Ok(())
}

fn update_vault(
fn update_loan(
who: &T::AccountId,
currency_id: CurrencyIdOf<T>,
collaterals: AmountOf<T>,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("acala"),
impl_name: create_runtime_str!("acala"),
authoring_version: 1,
spec_version: 25,
spec_version: 26,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
Expand Down

0 comments on commit d46f977

Please sign in to comment.