Skip to content

Commit

Permalink
Make expedited governance params optional (some chains don't have them)
Browse files Browse the repository at this point in the history
  • Loading branch information
zolting committed Nov 13, 2024
1 parent bc4c7b8 commit 1b866f4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 50 deletions.
62 changes: 34 additions & 28 deletions cosmos-proposals/src/governance_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,46 @@ fn add_governance_parameter_derive_from(row: &mut Row, block_id: &str, id: &str)
}

fn create_deposit_params(tables: &mut Tables, block_number: &str, gov_params: &GovernanceParamsStore) {
add_governance_parameter_derive_from(
tables
.create_row("DepositParam", &gov_params.block_id_last_updated)
.set("min_deposit", &gov_params.min_deposit)
.set("expedited_min_deposit", &gov_params.expedited_min_deposit)
.set_bigint("max_deposit_period", &gov_params.max_deposit_period),
&block_number,
&gov_params.block_id_last_updated,
);
let mut row = tables
.create_row("DepositParam", &gov_params.block_id_last_updated)
.set("min_deposit", &gov_params.min_deposit)
.set_bigint("max_deposit_period", &gov_params.max_deposit_period);

if let Some(expedited_min_deposit) = &gov_params.expedited_min_deposit {
row.set("expedited_min_deposit", expedited_min_deposit);
}

add_governance_parameter_derive_from(row, &block_number, &gov_params.block_id_last_updated);
}

fn create_voting_params(tables: &mut Tables, block_number: &str, gov_params: &GovernanceParamsStore) {
add_governance_parameter_derive_from(
tables
.create_row("VotingParam", &gov_params.block_id_last_updated)
.set_bigint("voting_period", &gov_params.voting_period)
.set_bigint("expedited_voting_period", &gov_params.expedited_voting_period),
&block_number,
&gov_params.block_id_last_updated,
);
let mut row = tables
.create_row("VotingParam", &gov_params.block_id_last_updated)
.set_bigint("voting_period", &gov_params.voting_period);

if let Some(expedited_voting_period) = &gov_params.expedited_voting_period {
row.set_bigint("expedited_voting_period", expedited_voting_period);
}

add_governance_parameter_derive_from(&mut row, block_number, &gov_params.block_id_last_updated);
}

fn create_tally_params(tables: &mut Tables, block_number: &str, gov_params: &GovernanceParamsStore) {
add_governance_parameter_derive_from(
tables
.create_row("TallyParam", &gov_params.block_id_last_updated)
.set_bigdecimal("quorum", &gov_params.quorum)
.set_bigdecimal("expedited_quorum", &gov_params.expedited_quorum)
.set_bigdecimal("threshold", &gov_params.threshold)
.set_bigdecimal("expedited_threshold", &gov_params.expedited_threshold)
.set_bigdecimal("veto_threshold", &gov_params.veto_threshold),
&block_number,
&gov_params.block_id_last_updated,
);
let mut row = tables
.create_row("TallyParam", &gov_params.block_id_last_updated)
.set_bigdecimal("quorum", &gov_params.quorum)
.set_bigdecimal("threshold", &gov_params.threshold)
.set_bigdecimal("veto_threshold", &gov_params.veto_threshold);

if let Some(expedited_quorum) = &gov_params.expedited_quorum {
row.set_bigdecimal("expedited_quorum", expedited_quorum);
}

if let Some(expedited_threshold) = &gov_params.expedited_threshold {
row.set_bigdecimal("expedited_threshold", expedited_threshold);
}

add_governance_parameter_derive_from(&mut row, block_number, &gov_params.block_id_last_updated);
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down
31 changes: 13 additions & 18 deletions cosmos-proposals/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ pub fn determine_voting_end_time(
proposal_type: &str,
) -> Timestamp {
let voting_period = if proposal_type == "Expedited" {
&gov_params.expedited_voting_period
&gov_params
.expedited_voting_period
.as_ref()
.expect("missing expedited_voting_period")
} else {
&gov_params.voting_period
};
Expand All @@ -107,25 +110,17 @@ pub fn extract_gov_params(gov_params: StoreGetString) -> GovernanceParamsStore {
let min_deposit_arr = build_min_deposit_array(&min_deposit);
let expedited_min_deposit = gov_params
.get_at(0, "expedited_min_deposit")
.expect("missing expedited_min_deposit");
let expedited_min_deposit_arr = build_min_deposit_array(&expedited_min_deposit);
.map(|deposit| build_min_deposit_array(&deposit));

let max_deposit_period = gov_params
.get_at(0, "max_deposit_period")
.expect("missing max_deposit_period");
let voting_period = gov_params.get_at(0, "voting_period").expect("missing voting_period");
let expedited_voting_period = gov_params
.get_at(0, "expedited_voting_period")
.expect("missing expedited_voting_period");
let expedited_voting_period = gov_params.get_at(0, "expedited_voting_period");
let quorum = gov_params.get_at(0, "quorum").expect("missing quorum");

// Osmosis doesn't have "expedited_quorum", so we set it to empty string
let expedited_quorum = gov_params.get_at(0, "expedited_quorum").unwrap_or("".to_string());

let expedited_quorum = gov_params.get_at(0, "expedited_quorum");
let threshold = gov_params.get_at(0, "threshold").expect("missing threshold");
let expedited_threshold = gov_params
.get_at(0, "expedited_threshold")
.expect("missing expedited_threshold");
let expedited_threshold = gov_params.get_at(0, "expedited_threshold");
let veto_threshold = gov_params.get_at(0, "veto_threshold").expect("missing veto_threshold");
let block_id_last_updated = gov_params
.get_at(0, "block_id_last_updated")
Expand All @@ -134,7 +129,7 @@ pub fn extract_gov_params(gov_params: StoreGetString) -> GovernanceParamsStore {
GovernanceParamsStore {
block_id_last_updated,
min_deposit: min_deposit_arr,
expedited_min_deposit: expedited_min_deposit_arr,
expedited_min_deposit,
max_deposit_period,
voting_period,
expedited_voting_period,
Expand Down Expand Up @@ -171,14 +166,14 @@ fn build_min_deposit_array(min_deposit: &str) -> Vec<String> {
pub struct GovernanceParamsStore {
pub block_id_last_updated: String,
pub min_deposit: Vec<String>,
pub expedited_min_deposit: Vec<String>,
pub expedited_min_deposit: Option<Vec<String>>,
pub max_deposit_period: String,
pub voting_period: String,
pub expedited_voting_period: String,
pub expedited_voting_period: Option<String>,
pub quorum: String,
pub expedited_quorum: String,
pub expedited_quorum: Option<String>,
pub threshold: String,
pub expedited_threshold: String,
pub expedited_threshold: Option<String>,
pub veto_threshold: String,
// StoreGetString is used to get proposal types (e.g Standard, MultipleChoice, Optimistic, Expedited)
// Example : store.get_string(0, "proposal_id_type:234")
Expand Down
8 changes: 4 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type DepositParam @entity {

# deposit parameters
min_deposit: [String!]! # 512000000 uatom
expedited_min_deposit: [String!]!
expedited_min_deposit: [String!]
max_deposit_period: BigInt!

# deriveFrom
Expand All @@ -144,7 +144,7 @@ type VotingParam @entity {

# voting parameters
voting_period: BigInt!
expedited_voting_period: BigInt!
expedited_voting_period: BigInt
# deriveFrom
block: Block!
governance_parameter: GovernanceParameter!
Expand All @@ -155,9 +155,9 @@ type TallyParam @entity {

# tally parameters
quorum: BigDecimal!
expedited_quorum: BigDecimal!
expedited_quorum: BigDecimal
threshold: BigDecimal!
expedited_threshold: BigDecimal!
expedited_threshold: BigDecimal
veto_threshold: BigDecimal!

# deriveFrom
Expand Down

0 comments on commit 1b866f4

Please sign in to comment.