-
Notifications
You must be signed in to change notification settings - Fork 69
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
1 parent
5480a44
commit 0ae9428
Showing
5 changed files
with
99 additions
and
50 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,51 @@ | ||
use pallet_ice::traits::{OmnipoolAssetInfo, OmnipoolInfo}; | ||
use pallet_ice::types::{Intent, Swap, SwapType}; | ||
use primitives::{AccountId, AssetId, Moment}; | ||
use rand::Rng; | ||
use sp_core::crypto::AccountId32; | ||
use sp_runtime::{FixedPointNumber, FixedU128}; | ||
|
||
pub(crate) fn generate_random_intents( | ||
c: u32, | ||
data: Vec<OmnipoolAssetInfo<AssetId>>, | ||
deadline: Moment, | ||
) -> Vec<Intent<AccountId, AssetId>> { | ||
let random_pair = || { | ||
let mut rng = rand::thread_rng(); | ||
loop { | ||
let idx_in = rng.gen_range(0..data.len()); | ||
let idx_out = rng.gen_range(0..data.len()); | ||
let reserve_in = data[idx_in].reserve; | ||
let reserve_out = data[idx_out].reserve; | ||
let amount_in = rng.gen_range(1..reserve_in / 4); | ||
let lrna_in = FixedU128::from_rational(amount_in, reserve_in) | ||
.checked_mul_int(data[idx_in].hub_reserve) | ||
.unwrap(); | ||
let amount_out = FixedU128::from_rational(reserve_out, data[idx_out].hub_reserve) | ||
.checked_mul_int(lrna_in) | ||
.unwrap(); | ||
return (data[idx_in].asset_id, data[idx_out].asset_id, amount_in, amount_out); | ||
} | ||
}; | ||
|
||
let mut intents = Vec::new(); | ||
for i in 0..c { | ||
let who: [u8; 32] = [i as u8; 32]; | ||
let (asset_in, asset_out, amount_in, amount_out) = random_pair(); | ||
intents.push(Intent { | ||
who: who.into(), | ||
swap: Swap { | ||
asset_in, | ||
asset_out, | ||
amount_in, | ||
amount_out, | ||
swap_type: SwapType::ExactIn, | ||
}, | ||
deadline, | ||
partial: true, | ||
on_success: None, | ||
on_failure: None, | ||
}); | ||
} | ||
intents | ||
} |
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