Skip to content

Commit

Permalink
update migration logics
Browse files Browse the repository at this point in the history
  • Loading branch information
larry0x committed Nov 8, 2022
1 parent e806a2f commit dc485bd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ The Hub contract implements two methods, `purge_keys` and `purge_owners`, which

| Contract | Address |
| --------- | ------------------------------------------------------------------ |
| Badge Hub | `stars1yqzlqv4hpumnnswannzgtkrd73lmal5lglx29j0mjed0vqudw04qc8j5ga` |
| Badge NFT | `stars1sz5xunz3zanlpl2ldq8w74tfa37cx06hfv6tq47y9a36zzz053ss7wwhzk` |
| Badge Hub | `stars1dacun0xn7z73qzdcmq27q3xn6xuprg8e2ugj364784al2v27tklqynhuqa` |
| Badge NFT | `stars1vlw4y54dyzt3zg7phj8yey9fg4zj49czknssngwmgrnwymyktztstalg7t` |

## License

Expand Down
14 changes: 8 additions & 6 deletions contracts/hub/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use cosmwasm_std::{entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, StdResult};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Empty, Env, MessageInfo, StdResult,
};
use sg_std::Response;

use badges::hub::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg};
use badges::hub::{ExecuteMsg, InstantiateMsg, QueryMsg, SudoMsg};
use badges::Badge;

use crate::error::ContractError;
Expand Down Expand Up @@ -127,7 +129,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
}

#[entry_point]
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
let cw2::ContractVersion {
contract,
version,
Expand All @@ -137,9 +139,9 @@ pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, Co
return Err(ContractError::incorrect_contract_name(CONTRACT_NAME, contract));
}

if version != "v1.0.0" {
return Err(ContractError::incorrect_contract_version("v1.0.0", version));
if version != "1.0.0" {
return Err(ContractError::incorrect_contract_version("1.0.0", version));
}

upgrades::v1_1::migrate(deps, msg.fee_rate).map_err(ContractError::from)
upgrades::v1_1::migrate(deps).map_err(ContractError::from)
}
22 changes: 16 additions & 6 deletions contracts/hub/src/upgrades/v1_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ use crate::state::{BADGES, FEE_RATE};

const LEGACY_FEE_PER_BYTE: Item<Decimal> = Item::new("fee_per_byte");

/// Date and time (GMT): Wednesday, November 30, 2022 11:59:59 PM
const NEW_BADGE_3_EXPIRY: u64 = 1669852799;
/// Date and time (GMT): Wednesday, December 31, 2022 11:59:59 PM
const NEW_BADGE_3_EXPIRY: u64 = 1672531199;

/// This is the new fee rate that will be updated to
fn new_fee_rate() -> FeeRate {
FeeRate {
metadata: Decimal::from_ratio(200000u128, 1u128),
key: Decimal::from_ratio(10000u128, 1u128),
}
}

pub fn migrate(deps: DepsMut) -> StdResult<Response> {
let new_fee_rate = new_fee_rate();

pub fn migrate(deps: DepsMut, fee_rate: FeeRate) -> StdResult<Response> {
// set separate fee rates for metadata and keys
update_fee_rate(deps.storage, &fee_rate)?;
update_fee_rate(deps.storage, &new_fee_rate)?;

// extend the minting deadline for badge 3
update_badge_3_expiry(deps.storage)?;
Expand All @@ -22,8 +32,8 @@ pub fn migrate(deps: DepsMut, fee_rate: FeeRate) -> StdResult<Response> {
.add_attribute("action", "badges/hub/migrate")
.add_attribute("from_version", "1.0.0")
.add_attribute("to_version", "1.1.0")
.add_attribute("metadata_fee_rate", fee_rate.metadata.to_string())
.add_attribute("key_fee_rate", fee_rate.key.to_string()))
.add_attribute("metadata_fee_rate", new_fee_rate.metadata.to_string())
.add_attribute("key_fee_rate", new_fee_rate.key.to_string()))
}

fn update_fee_rate(store: &mut dyn Storage, fee_rate: &FeeRate) -> StdResult<()> {
Expand Down
6 changes: 0 additions & 6 deletions packages/badges/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ pub enum SudoMsg {
}
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MigrateMsg {
/// The fee rate charged for when creating or editing badges, quoted in ustars per byte
pub fee_rate: FeeRate,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::large_enum_variant)]
Expand Down

0 comments on commit dc485bd

Please sign in to comment.