Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/btc delegations #39

Merged
merged 7 commits into from
Aug 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better / consistent naming / uses
Mauro Lacy committed Aug 12, 2024
commit c1bf80ec7420740372bd6c55797b0bef3aa33241
6 changes: 3 additions & 3 deletions contracts/btc-staking/src/staking.rs
Original file line number Diff line number Diff line change
@@ -423,7 +423,7 @@ pub(crate) mod tests {
use crate::contract::{execute, instantiate};
use crate::msg::{ExecuteMsg, InstantiateMsg};
use crate::queries;
use crate::state::staking::UndelegationInfo;
use crate::state::staking::BtcUndelegationInfo;

// Compute staking tx hash of an active delegation
pub(crate) fn staking_tx_hash(del: &BtcDelegation) -> Txid {
@@ -616,7 +616,7 @@ pub(crate) mod tests {
let btc_undelegation = btc_del.undelegation_info;
assert_eq!(
btc_undelegation,
UndelegationInfo {
BtcUndelegationInfo {
unbonding_tx: active_delegation_undelegation.unbonding_tx.to_vec(),
slashing_tx: active_delegation_undelegation.slashing_tx.to_vec(),
delegator_unbonding_sig: vec![],
@@ -650,7 +650,7 @@ pub(crate) mod tests {
let btc_undelegation = btc_del.undelegation_info;
assert_eq!(
btc_undelegation,
UndelegationInfo {
BtcUndelegationInfo {
unbonding_tx: active_delegation_undelegation.unbonding_tx.into(),
slashing_tx: active_delegation_undelegation.slashing_tx.into(),
delegator_unbonding_sig: vec![0x01, 0x02, 0x03],
69 changes: 34 additions & 35 deletions contracts/btc-staking/src/state/staking.rs
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@ use cw_storage_plus::{IndexedSnapshotMap, Item, Map, MultiIndex, Strategy};
use crate::msg::FinalityProviderInfo;
use crate::state::fp_index::FinalityProviderIndexes;
use babylon_apis::btc_staking_api::{
ActiveBtcDelegation, BTCDelegationStatus, BtcUndelegationInfo, FinalityProvider, SignatureInfo,
HASH_SIZE,
BTCDelegationStatus, FinalityProvider, SignatureInfo, HASH_SIZE,
};
use babylon_apis::{btc_staking_api, Bytes};

@@ -45,7 +44,7 @@ pub struct BtcDelegation {
/// change outputs
pub unbonding_time: u32,
/// undelegation_info is the undelegation info of this delegation.
pub undelegation_info: UndelegationInfo,
pub undelegation_info: BtcUndelegationInfo,
/// params version used to validate the delegation
pub params_version: u32,
}
@@ -77,34 +76,34 @@ impl BtcDelegation {
}
}

impl From<ActiveBtcDelegation> for BtcDelegation {
fn from(delegation: ActiveBtcDelegation) -> Self {
impl From<btc_staking_api::ActiveBtcDelegation> for BtcDelegation {
fn from(active_delegation: btc_staking_api::ActiveBtcDelegation) -> Self {
BtcDelegation {
staker_addr: delegation.staker_addr,
btc_pk_hex: delegation.btc_pk_hex,
fp_btc_pk_list: delegation.fp_btc_pk_list,
start_height: delegation.start_height,
end_height: delegation.end_height,
total_sat: delegation.total_sat,
staking_tx: delegation.staking_tx.to_vec(),
slashing_tx: delegation.slashing_tx.to_vec(),
delegator_slashing_sig: delegation.delegator_slashing_sig.to_vec(),
covenant_sigs: delegation
staker_addr: active_delegation.staker_addr,
btc_pk_hex: active_delegation.btc_pk_hex,
fp_btc_pk_list: active_delegation.fp_btc_pk_list,
start_height: active_delegation.start_height,
end_height: active_delegation.end_height,
total_sat: active_delegation.total_sat,
staking_tx: active_delegation.staking_tx.to_vec(),
slashing_tx: active_delegation.slashing_tx.to_vec(),
delegator_slashing_sig: active_delegation.delegator_slashing_sig.to_vec(),
covenant_sigs: active_delegation
.covenant_sigs
.into_iter()
.map(|sig| sig.into())
.collect(),
staking_output_idx: delegation.staking_output_idx,
unbonding_time: delegation.unbonding_time,
undelegation_info: delegation.undelegation_info.into(),
params_version: delegation.params_version,
staking_output_idx: active_delegation.staking_output_idx,
unbonding_time: active_delegation.unbonding_time,
undelegation_info: active_delegation.undelegation_info.into(),
params_version: active_delegation.params_version,
}
}
}

impl From<&ActiveBtcDelegation> for BtcDelegation {
fn from(delegation: &ActiveBtcDelegation) -> Self {
BtcDelegation::from(delegation.clone())
impl From<&btc_staking_api::ActiveBtcDelegation> for BtcDelegation {
fn from(active_delegation: &btc_staking_api::ActiveBtcDelegation) -> Self {
BtcDelegation::from(active_delegation.clone())
}
}

@@ -117,10 +116,10 @@ pub struct CovenantAdaptorSignatures {
}

impl From<btc_staking_api::CovenantAdaptorSignatures> for CovenantAdaptorSignatures {
fn from(info: btc_staking_api::CovenantAdaptorSignatures) -> Self {
fn from(cov_adaptor_sigs: btc_staking_api::CovenantAdaptorSignatures) -> Self {
CovenantAdaptorSignatures {
cov_pk: info.cov_pk.to_vec(),
adaptor_sigs: info
cov_pk: cov_adaptor_sigs.cov_pk.to_vec(),
adaptor_sigs: cov_adaptor_sigs
.adaptor_sigs
.into_iter()
.map(|sig| sig.to_vec())
@@ -130,7 +129,7 @@ impl From<btc_staking_api::CovenantAdaptorSignatures> for CovenantAdaptorSignatu
}

#[cw_serde]
pub struct UndelegationInfo {
pub struct BtcUndelegationInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current impression is that contract side only needs to remember the unbonding tx hash and unbonding slashing tx hash and that's it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The delegator_unbonding_sig field is being used to mark the delegation as undelegated. The same can be done through a boolean though.

/// unbonding_tx is the transaction which will transfer the funds from staking
/// output to unbonding output. Unbonding output will usually have lower timelock
/// than staking output.
@@ -156,15 +155,15 @@ pub struct UndelegationInfo {
pub covenant_slashing_sigs: Vec<CovenantAdaptorSignatures>,
}

impl From<BtcUndelegationInfo> for UndelegationInfo {
fn from(info: BtcUndelegationInfo) -> Self {
UndelegationInfo {
unbonding_tx: info.unbonding_tx.to_vec(),
delegator_unbonding_sig: info.delegator_unbonding_sig.to_vec(),
covenant_unbonding_sig_list: info.covenant_unbonding_sig_list,
slashing_tx: info.slashing_tx.to_vec(),
delegator_slashing_sig: info.delegator_slashing_sig.to_vec(),
covenant_slashing_sigs: info
impl From<btc_staking_api::BtcUndelegationInfo> for BtcUndelegationInfo {
fn from(undelegation_info: btc_staking_api::BtcUndelegationInfo) -> Self {
BtcUndelegationInfo {
unbonding_tx: undelegation_info.unbonding_tx.to_vec(),
delegator_unbonding_sig: undelegation_info.delegator_unbonding_sig.to_vec(),
covenant_unbonding_sig_list: undelegation_info.covenant_unbonding_sig_list,
slashing_tx: undelegation_info.slashing_tx.to_vec(),
delegator_slashing_sig: undelegation_info.delegator_slashing_sig.to_vec(),
covenant_slashing_sigs: undelegation_info
.covenant_slashing_sigs
.into_iter()
.map(|sig| sig.into())