Skip to content

Commit

Permalink
create cumulative_deposits genesis function
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 7, 2023
1 parent adab47d commit 9fa45c1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ module ol_framework::cumulative_deposits {
/// private function for the genesis fork migration
/// adjust for the coin split factor.
// NOTE: doing split factor on rust side
fun genesis_migrate_cumulative_deposits(vm: &signer, sender: &signer, value: u64, index: u64) {
fun genesis_migrate_cumulative_deposits(vm: &signer, sender: &signer, value:
u64, index: u64, depositors: vector<address>) {
system_addresses::assert_ol(vm);
if (!exists<CumulativeDeposits>(signer::address_of(sender))) {
move_to<CumulativeDeposits>(sender, CumulativeDeposits {
value,
index,
depositors: vector::empty<address>(),
depositors,
})
};
}
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
33 changes: 31 additions & 2 deletions tools/genesis/src/genesis_functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! ol functions to run at genesis e.g. migration.
use crate::supply::{Supply, SupplySettings};
use crate::{
process_comm_wallet,
supply::{Supply, SupplySettings},
};
use anyhow::Context;
use diem_types::account_config::CORE_CODE_ADDRESS;
use diem_vm::move_vm_ext::SessionExt;
Expand Down Expand Up @@ -419,8 +422,34 @@ pub fn genesis_migrate_community_wallet(
Ok(())
}

/// TODO: migrate the Match Index weights.
/// migrate the Cumulative Deposits Structs (for the Match Index weights).
pub fn genesis_migrate_cumu_deposits(
session: &mut SessionExt,
user_recovery: &[LegacyRecovery],
split_factor: f64,
) -> anyhow::Result<()> {
let (_dr, cw) = process_comm_wallet::prepare_cw_and_receipts(user_recovery, split_factor)?;

cw.list.iter().for_each(|(addr, wallet)| {
let serialized_values = serialize_values(&vec![
MoveValue::Signer(CORE_CODE_ADDRESS),
MoveValue::Signer(addr.to_owned()),
MoveValue::U64(wallet.cumulative_value),
MoveValue::U64(wallet.cumulative_index),
MoveValue::vector_address(wallet.depositors.clone()),
]);

exec_function(
session,
"cuulative_deposits",
"genesis_migrate_cumulative_deposits",
vec![],
serialized_values,
);
});

Ok(())
}
/// Since we are minting for each account to convert account balances there may be a rounding difference from target. Add those micro cents into the transaction fee account.
/// Note: we could have minted one giant coin and then split it, however there's no place to store in on chain without repurposing accounts (ie. system accounts by design do no hold any funds, only the transaction_fee contract can temporarily hold an aggregatable coin which by design can only be fully withdrawn (not split)). So the rounding mint is less elegant, but practical.
pub fn rounding_mint(session: &mut SessionExt, supply_settings: &SupplySettings) {
Expand Down
2 changes: 1 addition & 1 deletion types/src/legacy_types/legacy_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,6 @@ mod tests {
let old_str = address.to_hex_literal();
let parsed = AccountAddress::from_hex_literal(&old_str).unwrap();
let p: AccountAddress = address.try_into().unwrap();
assert!(&parsed == &p, "not equal");
assert!(parsed == p, "not equal");
}
}

0 comments on commit 9fa45c1

Please sign in to comment.