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

function to fund other delegators #118

Merged
merged 19 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,18 @@ pub enum EntryFunctionCall {
pool_address: AccountAddress,
},

PboDelegationPoolFundDelegatorsWithLockedStake {
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
stakes: Vec<u64>,
},

PboDelegationPoolFundDelegatorsWithStake {
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
stakes: Vec<u64>,
},

/// Move `amount` of coins from pending_inactive to active.
PboDelegationPoolReactivateStake {
pool_address: AccountAddress,
Expand Down Expand Up @@ -1484,6 +1496,20 @@ impl EntryFunctionCall {
PboDelegationPoolEnablePartialGovernanceVoting { pool_address } => {
pbo_delegation_pool_enable_partial_governance_voting(pool_address)
},
PboDelegationPoolFundDelegatorsWithLockedStake {
pool_address,
delegators,
stakes,
} => pbo_delegation_pool_fund_delegators_with_locked_stake(
pool_address,
delegators,
stakes,
),
PboDelegationPoolFundDelegatorsWithStake {
pool_address,
delegators,
stakes,
} => pbo_delegation_pool_fund_delegators_with_stake(pool_address, delegators, stakes),
PboDelegationPoolReactivateStake {
pool_address,
amount,
Expand Down Expand Up @@ -3235,6 +3261,52 @@ pub fn pbo_delegation_pool_enable_partial_governance_voting(
))
}

pub fn pbo_delegation_pool_fund_delegators_with_locked_stake(
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
stakes: Vec<u64>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("pbo_delegation_pool").to_owned(),
),
ident_str!("fund_delegators_with_locked_stake").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&delegators).unwrap(),
bcs::to_bytes(&stakes).unwrap(),
],
))
}

pub fn pbo_delegation_pool_fund_delegators_with_stake(
pool_address: AccountAddress,
delegators: Vec<AccountAddress>,
stakes: Vec<u64>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("pbo_delegation_pool").to_owned(),
),
ident_str!("fund_delegators_with_stake").to_owned(),
vec![],
vec![
bcs::to_bytes(&pool_address).unwrap(),
bcs::to_bytes(&delegators).unwrap(),
bcs::to_bytes(&stakes).unwrap(),
],
))
}

/// Move `amount` of coins from pending_inactive to active.
pub fn pbo_delegation_pool_reactivate_stake(
pool_address: AccountAddress,
Expand Down Expand Up @@ -5870,6 +5942,38 @@ mod decoder {
}
}

pub fn pbo_delegation_pool_fund_delegators_with_locked_stake(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(
EntryFunctionCall::PboDelegationPoolFundDelegatorsWithLockedStake {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
delegators: bcs::from_bytes(script.args().get(1)?).ok()?,
stakes: bcs::from_bytes(script.args().get(2)?).ok()?,
},
)
} else {
None
}
}

pub fn pbo_delegation_pool_fund_delegators_with_stake(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(
EntryFunctionCall::PboDelegationPoolFundDelegatorsWithStake {
pool_address: bcs::from_bytes(script.args().get(0)?).ok()?,
delegators: bcs::from_bytes(script.args().get(1)?).ok()?,
stakes: bcs::from_bytes(script.args().get(2)?).ok()?,
},
)
} else {
None
}
}

pub fn pbo_delegation_pool_reactivate_stake(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -7218,6 +7322,14 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"pbo_delegation_pool_enable_partial_governance_voting".to_string(),
Box::new(decoder::pbo_delegation_pool_enable_partial_governance_voting),
);
map.insert(
"pbo_delegation_pool_fund_delegators_with_locked_stake".to_string(),
Box::new(decoder::pbo_delegation_pool_fund_delegators_with_locked_stake),
);
map.insert(
"pbo_delegation_pool_fund_delegators_with_stake".to_string(),
Box::new(decoder::pbo_delegation_pool_fund_delegators_with_stake),
);
map.insert(
"pbo_delegation_pool_reactivate_stake".to_string(),
Box::new(decoder::pbo_delegation_pool_reactivate_stake),
Expand Down
Loading