From 324751d811e658ebd7570517fbc7e31c82ba73c8 Mon Sep 17 00:00:00 2001 From: Mirko Zichichi Date: Wed, 14 Aug 2024 21:33:00 +0200 Subject: [PATCH] feat(iota-genesis-builder): Allow Shimmer test outputs generation (#1699) * feat(iota-genesis-builder): allow shimmer test outputs generation * fix(iota-genesis-builder): adapt the other example * fix(iota-genesis-builder): differentiate between shimmer and iota coin type * fix(iota-genesis-builder): use u32 instead of CoinType * fix(iota-genesis-builder): fix example about * fix(iota-genesis-builder): storage deposit amounts (#1811) --------- Co-authored-by: Thibault Martinez --- .../examples/snapshot_add_test_outputs.rs | 65 ++++++++++++++---- .../examples/snapshot_only_test_outputs.rs | 67 ++++++++++++++++--- .../stardust/test_outputs/alias_ownership.rs | 8 ++- .../test_outputs/delegator_outputs.rs | 7 +- .../src/stardust/test_outputs/mod.rs | 59 +++++++++++++--- .../src/stardust/test_outputs/stardust_mix.rs | 25 +++---- .../test_outputs/vesting_schedule_entity.rs | 5 +- .../vesting_schedule_iota_airdrop.rs | 5 +- .../vesting_schedule_portfolio_mix.rs | 4 +- 9 files changed, 181 insertions(+), 64 deletions(-) diff --git a/crates/iota-genesis-builder/examples/snapshot_add_test_outputs.rs b/crates/iota-genesis-builder/examples/snapshot_add_test_outputs.rs index 1605861feec..4888dd2ef0c 100644 --- a/crates/iota-genesis-builder/examples/snapshot_add_test_outputs.rs +++ b/crates/iota-genesis-builder/examples/snapshot_add_test_outputs.rs @@ -5,13 +5,38 @@ use std::{fs::File, path::Path}; +use clap::{Parser, Subcommand}; use iota_genesis_builder::stardust::{ parse::HornetSnapshotParser, - test_outputs::{add_snapshot_test_outputs, to_micros}, + test_outputs::{add_snapshot_test_outputs, to_micros, STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO}, }; -use iota_types::gas_coin::STARDUST_TOTAL_SUPPLY_IOTA; +use iota_types::{gas_coin::STARDUST_TOTAL_SUPPLY_IOTA, stardust::coin_type::CoinType}; -fn parse_snapshot(path: impl AsRef) -> anyhow::Result<()> { +#[derive(Parser, Debug)] +#[clap(about = "Tool for adding test data to Iota and Shimmer Hornet full-snapshots")] +struct Cli { + #[clap(subcommand)] + snapshot: Snapshot, +} + +#[derive(Subcommand, Debug)] +enum Snapshot { + #[clap(about = "Parse an Iota Hornet full-snapshot file")] + Iota { + #[clap(long, help = "Path to the Iota Hornet full-snapshot file")] + snapshot_path: String, + }, + #[clap(about = "Parse a Shimmer Hornet full-snapshot file")] + Shimmer { + #[clap(long, help = "Path to the Shimmer Hornet full-snapshot file")] + snapshot_path: String, + }, +} + +fn parse_snapshot( + path: impl AsRef, + coin_type: CoinType, +) -> anyhow::Result<()> { let file = File::open(path)?; let mut parser = HornetSnapshotParser::new::(file)?; @@ -21,8 +46,12 @@ fn parse_snapshot(path: impl AsRef) -> anyhow::Result< Ok::<_, anyhow::Error>(acc + output?.1.amount()) })?; - // Total supply is in IOTA, snapshot supply is Micros - assert_eq!(total_supply, to_micros(STARDUST_TOTAL_SUPPLY_IOTA)); + let expected_total_supply = match coin_type { + CoinType::Iota => to_micros(STARDUST_TOTAL_SUPPLY_IOTA), + CoinType::Shimmer => STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO, + }; + + assert_eq!(total_supply, expected_total_supply); println!("Total supply: {total_supply}"); @@ -31,8 +60,10 @@ fn parse_snapshot(path: impl AsRef) -> anyhow::Result< #[tokio::main] async fn main() -> anyhow::Result<()> { - let Some(current_path) = std::env::args().nth(1) else { - anyhow::bail!("please provide path to the full-snapshot file"); + let cli = Cli::parse(); + let (current_path, coin_type) = match cli.snapshot { + Snapshot::Iota { snapshot_path } => (snapshot_path, CoinType::Iota), + Snapshot::Shimmer { snapshot_path } => (snapshot_path, CoinType::Shimmer), }; let mut new_path = String::from("test-"); // prepend "test-" before the file name @@ -44,13 +75,23 @@ async fn main() -> anyhow::Result<()> { new_path.push_str(¤t_path); } - parse_snapshot::(¤t_path)?; + parse_snapshot::(¤t_path, coin_type)?; - let randomness_seed = 0; - add_snapshot_test_outputs::(¤t_path, &new_path, randomness_seed, None, false) - .await?; + let randomness_seed = match coin_type { + CoinType::Iota => 0, + CoinType::Shimmer => 1, + }; + add_snapshot_test_outputs::( + ¤t_path, + &new_path, + coin_type, + randomness_seed, + None, + false, + ) + .await?; - parse_snapshot::(&new_path)?; + parse_snapshot::(¤t_path, coin_type)?; Ok(()) } diff --git a/crates/iota-genesis-builder/examples/snapshot_only_test_outputs.rs b/crates/iota-genesis-builder/examples/snapshot_only_test_outputs.rs index 91ec43b55bf..e29c07b9db8 100644 --- a/crates/iota-genesis-builder/examples/snapshot_only_test_outputs.rs +++ b/crates/iota-genesis-builder/examples/snapshot_only_test_outputs.rs @@ -6,19 +6,47 @@ use std::{fs::File, path::Path}; +use clap::{Parser, Subcommand}; use iota_genesis_builder::{ stardust::{ parse::HornetSnapshotParser, - test_outputs::{add_snapshot_test_outputs, to_micros}, + test_outputs::{add_snapshot_test_outputs, to_micros, STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO}, }, IF_STARDUST_ADDRESS, }; use iota_sdk::types::block::address::Address; -use iota_types::gas_coin::STARDUST_TOTAL_SUPPLY_IOTA; +use iota_types::{gas_coin::STARDUST_TOTAL_SUPPLY_IOTA, stardust::coin_type::CoinType}; + +pub const IF_SHIMMER_STARDUST_ADDRESS: &str = + "smr1qqzhsp9x3m22l55wlclawlw25536e3rgghep77awcfrgh60uxhxuq6vlak7"; const WITH_SAMPLING: bool = false; -fn parse_snapshot(path: impl AsRef) -> anyhow::Result<()> { +#[derive(Parser, Debug)] +#[clap(about = "Tool for generating Iota and Shimmer Hornet full-snapshot files with test data")] +struct Cli { + #[clap(subcommand)] + snapshot: Snapshot, +} + +#[derive(Subcommand, Debug)] +enum Snapshot { + #[clap(about = "Parse an Iota Hornet full-snapshot file")] + Iota { + #[clap(long, help = "Path to the Iota Hornet full-snapshot file")] + snapshot_path: String, + }, + #[clap(about = "Parse a Shimmer Hornet full-snapshot file")] + Shimmer { + #[clap(long, help = "Path to the Shimmer Hornet full-snapshot file")] + snapshot_path: String, + }, +} + +fn parse_snapshot( + path: impl AsRef, + coin_type: CoinType, +) -> anyhow::Result<()> { let file = File::open(path)?; let mut parser = HornetSnapshotParser::new::(file)?; @@ -28,8 +56,12 @@ fn parse_snapshot(path: impl AsRef) -> anyhow::Result< Ok::<_, anyhow::Error>(acc + output?.1.amount()) })?; - // Total supply is in IOTA, snapshot supply is Micros - assert_eq!(total_supply, to_micros(STARDUST_TOTAL_SUPPLY_IOTA)); + let expected_total_supply = match coin_type { + CoinType::Iota => to_micros(STARDUST_TOTAL_SUPPLY_IOTA), + CoinType::Shimmer => STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO, + }; + + assert_eq!(total_supply, expected_total_supply); println!("Total supply: {total_supply}"); @@ -38,8 +70,10 @@ fn parse_snapshot(path: impl AsRef) -> anyhow::Result< #[tokio::main] async fn main() -> anyhow::Result<()> { - let Some(current_path) = std::env::args().nth(1) else { - anyhow::bail!("please provide path to the full-snapshot file"); + let cli = Cli::parse(); + let (current_path, coin_type) = match cli.snapshot { + Snapshot::Iota { snapshot_path } => (snapshot_path, CoinType::Iota), + Snapshot::Shimmer { snapshot_path } => (snapshot_path, CoinType::Shimmer), }; let mut new_path = String::from("test-"); // prepend "test-" before the file name @@ -51,19 +85,30 @@ async fn main() -> anyhow::Result<()> { new_path.push_str(¤t_path); } - parse_snapshot::(¤t_path)?; + parse_snapshot::(¤t_path, coin_type)?; + + let (randomness_seed, delegator_address) = match coin_type { + CoinType::Iota => { + // IOTA coin type values + (0, IF_STARDUST_ADDRESS) + } + CoinType::Shimmer => { + // Shimmer coin type values + (1, IF_SHIMMER_STARDUST_ADDRESS) + } + }; - let randomness_seed = 0; add_snapshot_test_outputs::( ¤t_path, &new_path, + coin_type, randomness_seed, - *Address::try_from_bech32(IF_STARDUST_ADDRESS)?.as_ed25519(), + *Address::try_from_bech32(delegator_address)?.as_ed25519(), WITH_SAMPLING, ) .await?; - parse_snapshot::(&new_path)?; + parse_snapshot::(&new_path, coin_type)?; Ok(()) } diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs index e317d319d98..3bf77d8f484 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/alias_ownership.rs @@ -27,15 +27,17 @@ use crate::stardust::{ }; const MNEMONIC: &str = "few hood high omit camp keep burger give happy iron evolve draft few dawn pulp jazz box dash load snake gown bag draft car"; -const COIN_TYPE: u32 = 4218; const OWNING_ALIAS_COUNT: u32 = 10; -pub(crate) async fn outputs(rng: &mut StdRng) -> anyhow::Result> { +pub(crate) async fn outputs( + rng: &mut StdRng, + coin_type: u32, +) -> anyhow::Result> { let mut outputs = Vec::new(); let secret_manager = MnemonicSecretManager::try_from_mnemonic(MNEMONIC)?; let alias_owners = secret_manager - .generate_ed25519_addresses(COIN_TYPE, 0, 0..OWNING_ALIAS_COUNT, None) + .generate_ed25519_addresses(coin_type, 0, 0..OWNING_ALIAS_COUNT, None) .await?; // create 10 different alias outputs with each owning various other assets diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/delegator_outputs.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/delegator_outputs.rs index bd51c80a8e3..fbc044976b2 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/delegator_outputs.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/delegator_outputs.rs @@ -12,12 +12,11 @@ use iota_types::timelock::timelock::VESTED_REWARD_ID_PREFIX; use rand::{rngs::StdRng, Rng}; use super::to_micros; -use crate::stardust::types::{ - output_header::OutputHeader, output_index::random_output_index_with_rng, +use crate::stardust::{ + test_outputs::{MERGE_MILESTONE_INDEX, MERGE_TIMESTAMP_SECS}, + types::{output_header::OutputHeader, output_index::random_output_index_with_rng}, }; -const MERGE_MILESTONE_INDEX: u32 = 7669900; -const MERGE_TIMESTAMP_SECS: u32 = 1696406475; const A_WEEK_IN_SECONDS: u32 = 604_800; const TIMELOCK_MAX_ENDING_TIME: u32 = A_WEEK_IN_SECONDS * 208; diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs index e2807cb8729..69b3ef4800c 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/mod.rs @@ -23,6 +23,7 @@ use iota_sdk::types::block::{ }; use iota_types::{ gas_coin::STARDUST_TOTAL_SUPPLY_IOTA, + stardust::coin_type::CoinType, timelock::timelock::{self}, }; use packable::{ @@ -33,10 +34,17 @@ use rand::{rngs::StdRng, Rng, SeedableRng}; use crate::stardust::{parse::HornetSnapshotParser, types::output_header::OutputHeader}; -const OUTPUT_TO_DECREASE_AMOUNT_FROM: &str = +pub const IOTA_COIN_TYPE: u32 = 4218; +const IOTA_OUTPUT_TO_DECREASE_AMOUNT_FROM: &str = "0xb462c8b2595d40d3ff19924e3731f501aab13e215613ce3e248d0ed9f212db160000"; -const MERGE_MILESTONE_INDEX: u32 = 7669900; -const MERGE_TIMESTAMP_SECS: u32 = 1696406475; + +pub const SHIMMER_COIN_TYPE: u32 = 4219; +pub const STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO: u64 = 1_813_620_509_061_365; +const SHIMMER_OUTPUT_TO_DECREASE_AMOUNT_FROM: &str = + "0x4c337ea67697cb8dd0267cced8d9b51c479eb61dea04842138dcef31218d63810000"; + +pub const MERGE_MILESTONE_INDEX: u32 = 7669900; +pub const MERGE_TIMESTAMP_SECS: u32 = 1696406475; pub const fn to_micros(n: u64) -> u64 { match n.checked_mul(1_000_000) { @@ -60,6 +68,7 @@ const PROBABILITY_OF_PICKING_A_BASIC_OUTPUT: f64 = 0.1; pub async fn add_snapshot_test_outputs( current_path: impl AsRef + core::fmt::Debug, new_path: impl AsRef + core::fmt::Debug, + coin_type: CoinType, randomness_seed: u64, delegator: impl Into>, with_sampling: bool, @@ -72,13 +81,29 @@ pub async fn add_snapshot_test_outputs( let mut new_header = parser.header.clone(); let mut vested_index = u32::MAX; + let address_derivation_coin_type = match coin_type { + CoinType::Iota => IOTA_COIN_TYPE, + CoinType::Shimmer => SHIMMER_COIN_TYPE, + }; + let mut rng = StdRng::seed_from_u64(randomness_seed); let mut new_outputs = [ - alias_ownership::outputs(&mut rng).await?, - stardust_mix::outputs(&mut rng, &mut vested_index).await?, - vesting_schedule_entity::outputs(&mut rng, &mut vested_index).await?, - vesting_schedule_iota_airdrop::outputs(&mut rng, &mut vested_index).await?, - vesting_schedule_portfolio_mix::outputs(&mut rng, &mut vested_index).await?, + alias_ownership::outputs(&mut rng, address_derivation_coin_type).await?, + stardust_mix::outputs(&mut rng, &mut vested_index, address_derivation_coin_type).await?, + vesting_schedule_entity::outputs(&mut rng, &mut vested_index, address_derivation_coin_type) + .await?, + vesting_schedule_iota_airdrop::outputs( + &mut rng, + &mut vested_index, + address_derivation_coin_type, + ) + .await?, + vesting_schedule_portfolio_mix::outputs( + &mut rng, + &mut vested_index, + address_derivation_coin_type, + ) + .await?, ] .concat(); @@ -91,9 +116,10 @@ pub async fn add_snapshot_test_outputs( delegator, with_sampling.then_some(&mut parser), new_temp_amount, + coin_type, )? } else { - add_all_previous_outputs_and_test_outputs(&mut parser, new_temp_amount)? + add_all_previous_outputs_and_test_outputs(&mut parser, new_temp_amount, coin_type)? }); // Adjust the output count according to newly generated outputs. @@ -117,12 +143,18 @@ pub async fn add_snapshot_test_outputs( fn add_all_previous_outputs_and_test_outputs( parser: &mut HornetSnapshotParser, new_amount: u64, + coin_type: CoinType, ) -> anyhow::Result> { let mut new_outputs = Vec::new(); + let target_output = match coin_type { + CoinType::Iota => IOTA_OUTPUT_TO_DECREASE_AMOUNT_FROM, + CoinType::Shimmer => SHIMMER_OUTPUT_TO_DECREASE_AMOUNT_FROM, + }; + // Writes previous outputs. for (output_header, output) in parser.outputs().filter_map(|o| o.ok()) { - if output_header.output_id() == OutputId::from_str(OUTPUT_TO_DECREASE_AMOUNT_FROM)? { + if output_header.output_id() == OutputId::from_str(target_output)? { let basic = output.as_basic(); let amount = basic .amount() @@ -154,6 +186,7 @@ fn add_only_test_outputs( delegator: Ed25519Address, parser: Option<&mut HornetSnapshotParser>, new_temp_amount: u64, + coin_type: CoinType, ) -> anyhow::Result> { // Needed outputs for delegator let mut new_outputs = delegator_outputs::outputs(rng, vested_index, delegator)?; @@ -165,7 +198,11 @@ fn add_only_test_outputs( // Add all the remainder tokens to the zero address let zero_address = Ed25519Address::new([0; 32]); - let remainder = to_micros(STARDUST_TOTAL_SUPPLY_IOTA) + let network_total_supply = match coin_type { + CoinType::Iota => to_micros(STARDUST_TOTAL_SUPPLY_IOTA), + CoinType::Shimmer => STARDUST_TOTAL_SUPPLY_SHIMMER_MICRO, + }; + let remainder = network_total_supply .checked_sub(new_temp_amount + new_outputs.iter().map(|o| o.1.amount()).sum::()) .ok_or_else(|| anyhow!("new amount should not be higher than total supply"))?; let remainder_per_output = remainder / 4; diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/stardust_mix.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/stardust_mix.rs index 26f5dccce7e..bc3fea1efde 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/stardust_mix.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/stardust_mix.rs @@ -27,19 +27,15 @@ use iota_sdk::{ use rand::{rngs::StdRng, Rng}; use crate::stardust::{ - test_outputs::new_vested_output, + test_outputs::{new_vested_output, MERGE_MILESTONE_INDEX, MERGE_TIMESTAMP_SECS}, types::{output_header::OutputHeader, output_index::random_output_index_with_rng}, }; -const MERGE_MILESTONE_INDEX: u32 = 7669900; -const MERGE_TIMESTAMP_SECS: u32 = 1696406475; - -const IOTA_COIN_TYPE: u32 = 4218; const OUTPUT_IOTA_AMOUNT: u64 = 1_000_000; +const STORAGE_DEPOSIT_AMOUNT: u64 = 500_000; struct StardustWallet { mnemonic: &'static str, - coin_type: u32, // bip path values for account, internal, address addresses: &'static [[u32; 3]], } @@ -48,25 +44,21 @@ const STARDUST_MIX: &[StardustWallet] = &[ // First public address only StardustWallet { mnemonic: "chest inquiry stick anger scheme tail void cup toe game copy jump law bone risk pull crowd dry raw baby want tip oak dice", - coin_type: IOTA_COIN_TYPE, addresses: &[[0, 0, 0]], }, // Multiple public addresses StardustWallet { mnemonic: "okay pottery arch air egg very cave cash poem gown sorry mind poem crack dawn wet car pink extra crane hen bar boring salt", - coin_type: IOTA_COIN_TYPE, addresses: &[[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 0, 5]], }, // Multiple internal addresses StardustWallet { mnemonic: "face tag all fade win east asset taxi holiday need slow fold play pull away earn bus room run one kidney mail design space", - coin_type: IOTA_COIN_TYPE, addresses: &[[0, 1, 1], [0, 1, 2], [0, 1, 5]], }, // Multiple public and internal addresses StardustWallet { mnemonic: "rain flip mad lamp owner siren tower buddy wolf shy tray exit glad come dry tent they pond wrist web cliff mixed seek drum", - coin_type: IOTA_COIN_TYPE, addresses: &[ // public [0, 0, 0], @@ -82,7 +74,6 @@ const STARDUST_MIX: &[StardustWallet] = &[ // Multiple accounts multiple public and internal addresses StardustWallet { mnemonic: "oak eye use bus high enact city desk gaze sure radio text ice food give foil raw dove attitude van clap tenant human other", - coin_type: IOTA_COIN_TYPE, addresses: &[ // account 2 // public @@ -119,7 +110,6 @@ const STARDUST_MIX: &[StardustWallet] = &[ // Everything crazy StardustWallet { mnemonic: "crazy drum raw dirt tooth where fee base warm beach trim rule sign silk fee fee dad large creek venue coin steel hub scale", - coin_type: IOTA_COIN_TYPE, addresses: &[ // account 0 // public @@ -168,6 +158,7 @@ const STARDUST_MIX: &[StardustWallet] = &[ pub(crate) async fn outputs( rng: &mut StdRng, vested_index: &mut u32, + coin_type: u32, ) -> anyhow::Result> { let mut outputs = Vec::new(); @@ -176,7 +167,7 @@ pub(crate) async fn outputs( for [account_index, internal, address_index] in wallet.addresses { let address = secret_manager .generate_ed25519_addresses( - wallet.coin_type, + coin_type, *account_index, *address_index..address_index + 1, if *internal == 1 { @@ -247,20 +238,20 @@ fn new_basic_or_nft_outputs( ExpirationUnlockCondition::new(address, rng.gen())?.into(), ]); add_output_with_unlock_conditions(vec![ - StorageDepositReturnUnlockCondition::new(address, 500_0000, u64::MAX)?.into(), + StorageDepositReturnUnlockCondition::new(address, STORAGE_DEPOSIT_AMOUNT, u64::MAX)?.into(), ]); add_output_with_unlock_conditions(vec![ StorageDepositReturnUnlockCondition::new( Ed25519Address::new([0u8; 32]), - 500_0000, + STORAGE_DEPOSIT_AMOUNT, u64::MAX, )? .into(), ]); add_output_with_unlock_conditions(vec![ AddressUnlockCondition::new(Ed25519Address::new([0u8; 32])).into(), - StorageDepositReturnUnlockCondition::new(address, 500_0000, u64::MAX)?.into(), + StorageDepositReturnUnlockCondition::new(address, STORAGE_DEPOSIT_AMOUNT, u64::MAX)?.into(), ]); add_output_with_unlock_conditions(vec![ TimelockUnlockCondition::new(rng.gen())?.into(), @@ -269,7 +260,7 @@ fn new_basic_or_nft_outputs( add_output_with_unlock_conditions(vec![ TimelockUnlockCondition::new(rng.gen())?.into(), ExpirationUnlockCondition::new(address, rng.gen())?.into(), - StorageDepositReturnUnlockCondition::new(address, 500_0000, u64::MAX)?.into(), + StorageDepositReturnUnlockCondition::new(address, STORAGE_DEPOSIT_AMOUNT, u64::MAX)?.into(), ]); outputs.push(finish_with_header( diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_entity.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_entity.rs index 0e7ee2ced80..1a704fb40d7 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_entity.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_entity.rs @@ -17,19 +17,20 @@ use crate::stardust::{ }; const MNEMONIC: &str = "chunk beach oval twist manage spread street width view pig hen oak size fix lab tent say home team cube loop van they suit"; -const COIN_TYPE: u32 = 4218; + const VESTING_WEEKS: usize = 208; const VESTING_WEEKS_FREQUENCY: usize = 2; pub(crate) async fn outputs( rng: &mut StdRng, vested_index: &mut u32, + coin_type: u32, ) -> anyhow::Result> { let mut outputs = Vec::new(); let secret_manager = MnemonicSecretManager::try_from_mnemonic(MNEMONIC)?; let address = secret_manager - .generate_ed25519_addresses(COIN_TYPE, 0, 0..1, None) + .generate_ed25519_addresses(coin_type, 0, 0..1, None) .await?[0]; // VESTING_WEEKS / VESTING_WEEKS_FREQUENCY * 10 so that `vested_amount` doesn't // lose precision. diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_iota_airdrop.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_iota_airdrop.rs index 0f4f543925b..f8a2e3a9916 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_iota_airdrop.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_iota_airdrop.rs @@ -24,13 +24,14 @@ use crate::stardust::{ const MNEMONIC: &str = "mesh dose off wage gas tent key light help girl faint catch sock trouble guard moon talk pill enemy hawk gain mix sad mimic"; const ACCOUNTS: u32 = 10; const ADDRESSES_PER_ACCOUNT: u32 = 20; -const COIN_TYPE: u32 = 4218; + const VESTING_WEEKS: usize = 104; const VESTING_WEEKS_FREQUENCY: usize = 2; pub(crate) async fn outputs( rng: &mut StdRng, vested_index: &mut u32, + coin_type: u32, ) -> anyhow::Result> { let now = SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH)? @@ -42,7 +43,7 @@ pub(crate) async fn outputs( for address_index in 0..ADDRESSES_PER_ACCOUNT { let address = secret_manager .generate_ed25519_addresses( - COIN_TYPE, + coin_type, account_index, address_index..address_index + 1, None, diff --git a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_portfolio_mix.rs b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_portfolio_mix.rs index 29b8b705538..c7d7efd8b35 100644 --- a/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_portfolio_mix.rs +++ b/crates/iota-genesis-builder/src/stardust/test_outputs/vesting_schedule_portfolio_mix.rs @@ -22,7 +22,6 @@ use crate::stardust::{ types::{output_header::OutputHeader, output_index::OutputIndex}, }; -const IOTA_COIN_TYPE: u32 = 4218; const VESTING_WEEKS: usize = 208; const VESTING_WEEKS_FREQUENCY: usize = 2; const MNEMONIC: &str = "axis art silk merit assist hour bright always day legal misery arm laundry mule ship upon oil ski cup hat skin wet old sea"; @@ -41,6 +40,7 @@ const ADDRESSES: &[[u32; 3]] = &[ pub(crate) async fn outputs( rng: &mut StdRng, vested_index: &mut u32, + coin_type: u32, ) -> anyhow::Result> { let mut outputs = Vec::new(); let secret_manager = MnemonicSecretManager::try_from_mnemonic(MNEMONIC)?; @@ -48,7 +48,7 @@ pub(crate) async fn outputs( for [account_index, internal, address_index] in ADDRESSES { let address = secret_manager .generate_ed25519_addresses( - IOTA_COIN_TYPE, + coin_type, *account_index, *address_index..address_index + 1, (*internal == 1).then_some(GenerateAddressOptions::internal()),