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

Mint | start epoch #95

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions contracts/micro_mint/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
};

// Set the minting limit
let limit = MintLimit {
let mut limit = MintLimit {
frequency: match msg.epoch_frequency {
None => 0,
Some(frequency) => frequency.u128() as u64,
Expand All @@ -56,6 +56,11 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
Some(frequency) => env.block.time + frequency.u128() as u64,
},
};
// Override the next epoch
if let Some(next_epoch) = msg.start_epoch {
limit.next_epoch = next_epoch.u128() as u64;
}

limit_w(&mut deps.storage).save(&limit)?;

config_w(&mut deps.storage).save(&state)?;
Expand Down Expand Up @@ -103,9 +108,10 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
treasury,
} => handle::try_update_config(deps, env, owner, oracle, treasury),
HandleMsg::UpdateMintLimit {
start_epoch,
epoch_frequency,
epoch_limit,
} => handle::try_update_limit(deps, env, epoch_frequency, epoch_limit),
} => handle::try_update_limit(deps, env, start_epoch, epoch_frequency, epoch_limit),
HandleMsg::RegisterAsset {
contract,
commission,
Expand Down
7 changes: 6 additions & 1 deletion contracts/micro_mint/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ pub fn try_update_config<S: Storage, A: Api, Q: Querier>(
pub fn try_update_limit<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: Env,
start_epoch: Option<Uint128>,
epoch_frequency: Option<Uint128>,
epoch_limit: Option<Uint128>,
) -> StdResult<HandleResponse> {
Expand Down Expand Up @@ -238,7 +239,11 @@ pub fn try_update_limit<S: Storage, A: Api, Q: Querier>(
// Reset next epoch
if state.frequency == 0 {
state.next_epoch = 0;
} else {
}
else if let Some(next_epoch) = start_epoch {
state.next_epoch = next_epoch.u128() as u64;
}
else {
state.next_epoch = env.block.time + state.frequency;
}
Ok(state)
Expand Down
1 change: 1 addition & 0 deletions contracts/micro_mint/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub mod tests {
oracle,
peg,
treasury,
start_epoch: None,
epoch_frequency: None,
epoch_mint_limit: None
};
Expand Down
2 changes: 2 additions & 0 deletions packages/shade_protocol/src/micro_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub struct InitMsg {
// Both treasury & commission must be set to function
pub treasury: Option<Contract>,
// If left blank no limit will be enforced
pub start_epoch: Option<Uint128>,
pub epoch_frequency: Option<Uint128>,
pub epoch_mint_limit: Option<Uint128>,
}
Expand All @@ -65,6 +66,7 @@ pub enum HandleMsg {
treasury: Option<Contract>,
},
UpdateMintLimit {
start_epoch: Option<Uint128>,
epoch_frequency: Option<Uint128>,
epoch_limit: Option<Uint128>,
},
Expand Down