-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
246 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use cfg_primitives::{AccountId, Balance, CollectionId, ItemId, PoolId, CFG}; | ||
use frame_support::traits::Get; | ||
use orml_traits::GetByKey; | ||
|
||
use crate::{ | ||
generic::{ | ||
environment::{Blocks, Env}, | ||
envs::runtime_env::RuntimeEnv, | ||
runtime::Runtime, | ||
utils::{ | ||
self, | ||
genesis::{self, Genesis, MUSD_CURRENCY_ID}, | ||
}, | ||
}, | ||
utils::accounts::Keyring, | ||
}; | ||
|
||
const POOL_ADMIN: Keyring = Keyring::Admin; | ||
const INVESTOR: Keyring = Keyring::Alice; | ||
const BORROWER: Keyring = Keyring::Bob; | ||
|
||
const FOR_FEES: Balance = 1 * CFG; | ||
|
||
const POOL_A: PoolId = 23; | ||
const NFT_A: (CollectionId, ItemId) = (1, ItemId(10)); | ||
|
||
fn borrow<T: Runtime>() { | ||
let mut env = RuntimeEnv::<T>::from_storage( | ||
Genesis::<T>::default() | ||
.add(genesis::balances(T::ExistentialDeposit::get() + FOR_FEES)) | ||
.add(genesis::tokens(vec![( | ||
MUSD_CURRENCY_ID, | ||
T::ExistentialDeposits::get(&MUSD_CURRENCY_ID), | ||
)])) | ||
.add(genesis::assets(vec![MUSD_CURRENCY_ID])) | ||
.storage(), | ||
); | ||
|
||
env.state_mut(|| { | ||
utils::give_balance_to::<T>(POOL_ADMIN.id(), T::PoolDeposit::get()); | ||
utils::give_nft_to::<T>(BORROWER.id(), NFT_A); | ||
}); | ||
|
||
env.state(|| { | ||
//pallet_uniques::Pallet::<T>:: | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Divide this utilties into files when they grow | ||
|
||
use cfg_primitives::{Balance, CollectionId, ItemId, Moment, PoolId, TrancheId}; | ||
use cfg_types::{ | ||
permissions::{PermissionScope, PoolRole, Role}, | ||
tokens::CurrencyId, | ||
}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::{traits::StaticLookup, AccountId32}; | ||
pub mod genesis; | ||
|
||
use crate::generic::runtime::Runtime; | ||
|
||
pub fn give_nft_to<T: Runtime>( | ||
dest: AccountId32, | ||
(collection_id, item_id): (CollectionId, ItemId), | ||
) { | ||
pallet_uniques::Pallet::<T>::force_create( | ||
RawOrigin::Root.into(), | ||
collection_id, | ||
T::Lookup::unlookup(dest.clone()), | ||
true, | ||
) | ||
.unwrap(); | ||
|
||
pallet_uniques::Pallet::<T>::mint( | ||
RawOrigin::Signed(dest.clone()).into(), | ||
collection_id, | ||
item_id, | ||
T::Lookup::unlookup(dest), | ||
) | ||
.unwrap() | ||
} | ||
|
||
pub fn give_balance_to<T: Runtime>(dest: AccountId32, amount: Balance) { | ||
let data = pallet_balances::Account::<T>::get(dest.clone()); | ||
pallet_balances::Pallet::<T>::set_balance( | ||
RawOrigin::Root.into(), | ||
T::Lookup::unlookup(dest), | ||
data.free + amount, | ||
data.reserved, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn give_token_to<T: Runtime>(dest: AccountId32, currency_id: CurrencyId, amount: Balance) { | ||
let data = orml_tokens::Accounts::<T>::get(dest.clone(), currency_id); | ||
orml_tokens::Pallet::<T>::set_balance( | ||
RawOrigin::Root.into(), | ||
T::Lookup::unlookup(dest), | ||
currency_id, | ||
data.free + amount, | ||
data.reserved, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn give_investor_role<T: Runtime>( | ||
investor: AccountId32, | ||
pool_id: PoolId, | ||
tranche_id: TrancheId, | ||
) { | ||
let role = Role::PoolRole(PoolRole::TrancheInvestor(tranche_id, Moment::MAX)); | ||
pallet_permissions::Pallet::<T>::add( | ||
RawOrigin::Root.into(), | ||
role, | ||
investor, | ||
PermissionScope::Pool(pool_id), | ||
role, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn give_borrower_role<T: Runtime>(borrower: AccountId32, pool_id: PoolId) { | ||
let role = Role::PoolRole(PoolRole::Borrower); | ||
pallet_permissions::Pallet::<T>::add( | ||
RawOrigin::Root.into(), | ||
role, | ||
borrower, | ||
PermissionScope::Pool(pool_id), | ||
role, | ||
) | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters