Skip to content

Commit

Permalink
pgf over ibc
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Dec 11, 2023
1 parent 9562c16 commit c3ec642
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 102 deletions.
4 changes: 2 additions & 2 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ pub async fn query_pgf(context: &impl Namada, _args: args::QueryPgf) {
context.io(),
"{:4}- {} for {}",
"",
funding.detail.target,
funding.detail.amount.to_string_native()
funding.detail.target(),
funding.detail.amount().to_string_native()
);
}
}
Expand Down
51 changes: 31 additions & 20 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Implementation of the `FinalizeBlock` ABCI++ method for the Shell

use data_encoding::HEXUPPER;
use namada::core::ledger::governance::storage::proposal::PGFTarget;
use namada::core::ledger::inflation;
use namada::core::ledger::masp_conversions::update_allowed_conversions;
use namada::core::ledger::pgf::ADDRESS as pgf_address;
Expand Down Expand Up @@ -750,26 +751,36 @@ where
pgf_fundings.sort_by(|a, b| a.id.cmp(&b.id));

for funding in pgf_fundings {
if storage_api::token::transfer(
&mut self.wl_storage,
&staking_token,
&pgf_address,
&funding.detail.target,
funding.detail.amount,
)
.is_ok()
{
tracing::info!(
"Paying {} tokens for {} project.",
funding.detail.amount.to_string_native(),
&funding.detail.target,
);
} else {
tracing::warn!(
"Failed to pay {} tokens for {} project.",
funding.detail.amount.to_string_native(),
&funding.detail.target,
);
let result = match &funding.detail {
PGFTarget::Internal(target) => storage_api::token::transfer(
&mut self.wl_storage,
&staking_token,
&pgf_address,
&target.target,
target.amount,
),
PGFTarget::Ibc(target) => ibc::transfer_over_ibc(
&mut self.wl_storage,
&staking_token,
&pgf_address,
target,
),
};
match result {
Ok(()) => {
tracing::info!(
"Paying {} tokens for {} project.",
funding.detail.amount().to_string_native(),
&funding.detail.target(),
);
}
Err(_) => {
tracing::warn!(
"Failed to pay {} tokens for {} project.",
funding.detail.amount().to_string_native(),
&funding.detail.target(),
);
}
}
}

Expand Down
49 changes: 28 additions & 21 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use namada::core::ledger::governance::storage::keys as gov_storage;
use namada::core::ledger::governance::storage::proposal::{
AddRemove, PGFAction, ProposalType, StoragePgfFunding,
AddRemove, PGFAction, PGFTarget, ProposalType, StoragePgfFunding,
};
use namada::core::ledger::governance::utils::{
compute_proposal_result, ProposalVotes, TallyResult, TallyType, TallyVote,
Expand Down Expand Up @@ -340,64 +340,71 @@ where
Ok(true)
}

fn execute_pgf_payment_proposal<S>(
storage: &mut S,
fn execute_pgf_payment_proposal<D, H>(
storage: &mut WlStorage<D, H>,
token: &Address,
payments: Vec<PGFAction>,
proposal_id: u64,
) -> Result<bool>
where
S: StorageRead + StorageWrite,
D: DB + for<'iter> DBIter<'iter> + Sync + 'static,
H: StorageHasher + Sync + 'static,
{
for payment in payments {
match payment {
PGFAction::Continuous(action) => match action {
AddRemove::Add(target) => {
pgf_storage::fundings_handle().insert(
storage,
target.target.clone(),
target.target().clone(),
StoragePgfFunding::new(target.clone(), proposal_id),
)?;
tracing::info!(
"Execute ContinousPgf from proposal id {}: set {} to \
{}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
);
}
AddRemove::Remove(target) => {
pgf_storage::fundings_handle()
.remove(storage, &target.target)?;
.remove(storage, &target.target())?;
tracing::info!(
"Execute ContinousPgf from proposal id {}: set {} to \
{}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
);
}
},
PGFAction::Retro(target) => {
match token::transfer(
storage,
token,
&ADDRESS,
&target.target,
target.amount,
) {
let result = match &target {
PGFTarget::Internal(target) => token::transfer(
storage,
token,
&ADDRESS,
&target.target,
target.amount,
),
PGFTarget::Ibc(target) => {
ibc::transfer_over_ibc(storage, token, &ADDRESS, target)
}
};
match result {
Ok(()) => tracing::info!(
"Execute RetroPgf from proposal id {}: sent {} to {}.",
proposal_id,
target.amount.to_string_native(),
target.target
target.amount().to_string_native(),
target.target()
),
Err(e) => tracing::warn!(
"Error in RetroPgf transfer from proposal id {}, \
amount {} to {}: {}",
proposal_id,
target.amount.to_string_native(),
target.target,
target.amount().to_string_native(),
target.target(),
e
),
}
Expand Down
1 change: 1 addition & 0 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
pub mod block_alloc;
mod finalize_block;
mod governance;
mod ibc;
mod init_chain;
pub mod prepare_proposal;
pub mod process_proposal;
Expand Down
20 changes: 5 additions & 15 deletions core/src/ledger/governance/cli/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::validation::{
ProposalValidation,
};
use crate::ledger::governance::parameters::GovernanceParameters;
use crate::ledger::governance::storage::proposal::PGFTarget;
use crate::ledger::storage_api::token;
use crate::types::address::Address;
use crate::types::storage::Epoch;
Expand Down Expand Up @@ -277,9 +278,9 @@ impl PgfAction {
)]
pub struct PgfFunding {
/// Pgf continous funding
pub continous: Vec<PgfFundingTarget>,
pub continous: Vec<PGFTarget>,
/// pgf retro fundings
pub retro: Vec<PgfFundingTarget>,
pub retro: Vec<PGFTarget>,
}

/// Pgf continous funding
Expand All @@ -288,7 +289,7 @@ pub struct PgfFunding {
)]
pub struct PgfContinous {
/// Pgf target
pub target: PgfFundingTarget,
pub target: PGFTarget,
/// Pgf action
pub action: PgfAction,
}
Expand All @@ -299,18 +300,7 @@ pub struct PgfContinous {
)]
pub struct PgfRetro {
/// Pgf retro target
pub target: PgfFundingTarget,
}

/// Pgf Target
#[derive(
Debug, Clone, BorshSerialize, BorshDeserialize, Serialize, Deserialize,
)]
pub struct PgfFundingTarget {
/// Target amount
pub amount: token::Amount,
/// Target address
pub address: Address,
pub target: PGFTarget,
}

/// Represent an proposal vote
Expand Down
Loading

0 comments on commit c3ec642

Please sign in to comment.