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 | secondary burn #97

Merged
merged 5 commits 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
23 changes: 20 additions & 3 deletions contracts/micro_mint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [UpdateConfig](#UpdateConfig)
* [UpdateMintLimit](#UpdateMintLimit)
* [RegisterAsset](#RegisterAsset)
* [RemoveAsset](#RemoveAsset)
* Queries
* [GetNativeAsset](#GetNativeAsset)
* [GetConfig](#GetConfig)
Expand All @@ -31,6 +32,7 @@ Contract responsible to mint a paired snip20 asset
|peg | String | Symbol to peg to when querying oracle (defaults to native_asset symbol) | yes |
|treasury | Contract | Treasury contract | yes |
|oracle | Contract | Oracle contract | no |
|start_epoch | String | The starting epoch | yes |
|epoch_frequency | String | The frequency in which the mint limit resets, if 0 then no limit is enforced | yes |
|epoch_mint_limit | String | The limit of uTokens to mint per epoch | yes |
## Admin
Expand All @@ -56,8 +58,9 @@ Updates the given values
#### UpdateMintLimit
Updates the given values
##### Request
|Name |Type |Description | optional |
|----------|----------|---------------------------------------------------------------------------------------|----------|
|Name |Type |Description | optional |
|-----------------|----------|---------------------------------------------------------------------------------------|----------|
|start_epoch | String | The starting epoch | yes |
|epoch_frequency | String | The frequency in which the mint limit resets, if 0 then no limit is enforced | yes |
|epoch_mint_limit | String | The limit of uTokens to mint per epoch | yes |
##### Response
Expand All @@ -72,7 +75,6 @@ Updates the given values
#### RegisterAsset
Registers a supported asset. The asset must be SNIP-20 compliant since [RegisterReceive](https://github.com/SecretFoundation/SNIPs/blob/master/SNIP-20.md#RegisterReceive) is called.

Note: Will return an error if there's an asset with that address already registered.
##### Request
|Name |Type |Description | optional |
|------------|--------|-----------------------------------------------------------------------------------------------------------------------|----------|
Expand All @@ -86,6 +88,21 @@ Note: Will return an error if there's an asset with that address already registe
}
```

#### RemoveAsset
Remove a registered asset.
##### Request
|Name |Type |Description | optional |
|------------|--------|-----------------------------------------------------------------------------------------------------------------------|----------|
|address | String | The asset to remove's address | no |
##### Response
```json
{
"remove_asset": {
"status": "success"
}
}
```

### Queries

#### GetNativeAsset
Expand Down
17 changes: 14 additions & 3 deletions contracts/micro_mint/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
},
oracle: msg.oracle,
treasury: msg.treasury,
secondary_burn: msg.secondary_burn,
activated: true,
};

// 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 +57,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 @@ -101,15 +107,20 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
owner,
oracle,
treasury,
} => handle::try_update_config(deps, env, owner, oracle, treasury),
secondary_burn,
} => handle::try_update_config(deps, env, owner, oracle, treasury, secondary_burn),
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,
} => handle::try_register_asset(deps, &env, &contract, commission),
HandleMsg::RemoveAsset {
address
} => handle::try_remove_asset(deps, &env, address),
HandleMsg::Receive {
sender,
from,
Expand Down
72 changes: 60 additions & 12 deletions contracts/micro_mint/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,30 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
}
}

//TODO: if token_config is None, or cant burn, need to trash

// Try to burn
match burn_asset.asset.token_config {
Some(ref conf) => {
if conf.burn_enabled {
messages.push(burn_msg(burn_amount,
None,
256,
if let Some(token_config) = burn_asset.asset.token_config.clone() {
if token_config.burn_enabled {
messages.push(burn_msg(burn_amount,
None,
256,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone())?);
}
else {
// If no config then dont burn
if let Some(recipient) = config.secondary_burn {
messages.push(send_msg(recipient, burn_amount, None, None, 1,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone())?);
burn_asset.asset.contract.address.clone())?)
}
}
None => {
}
else {
// If no config then dont burn
if let Some(recipient) = config.secondary_burn {
messages.push(send_msg(recipient, burn_amount, None, None, 1,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone())?)
}
}

Expand Down Expand Up @@ -172,6 +182,7 @@ pub fn try_update_config<S: Storage, A: Api, Q: Querier>(
owner: Option<HumanAddr>,
oracle: Option<Contract>,
treasury: Option<Contract>,
secondary_burn: Option<HumanAddr>,
) -> StdResult<HandleResponse> {

let config = config_r(&deps.storage).load()?;
Expand All @@ -196,6 +207,9 @@ pub fn try_update_config<S: Storage, A: Api, Q: Querier>(
if let Some(treasury) = treasury {
state.treasury = Some(treasury);
}
if let Some(secondary_burn) = secondary_burn {
state.secondary_burn = Some(secondary_burn)
}
Ok(state)
})?;

Expand All @@ -210,6 +224,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 +253,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 Expand Up @@ -319,6 +338,35 @@ pub fn try_register_asset<S: Storage, A: Api, Q: Querier>(
})
}

pub fn try_remove_asset<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
env: &Env,
address: HumanAddr
) -> StdResult<HandleResponse> {

let address_str = address.to_string();

// Remove asset from the array
asset_list_w(&mut deps.storage).update(|mut state| {
state.retain(|value| *value != address_str);
Ok(state)
})?;

// Remove supported asset
assets_w(&mut deps.storage).remove(&address_str.as_bytes());

// We wont remove the total burned since we want to keep track of all the burned assets

Ok(HandleResponse {
messages: vec![],
log: vec![],
data: Some( to_binary(
&HandleAnswer::RemoveAsset {
status: ResponseStatus::Success }
)?
)
})
}

pub fn register_receive (
env: &Env,
Expand Down Expand Up @@ -416,4 +464,4 @@ fn oracle<S: Storage, A: Api, Q: Querier>(
config.oracle.code_hash,
config.oracle.address)?;
Ok(answer.rate)
}
}
2 changes: 2 additions & 0 deletions contracts/micro_mint/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub mod tests {
oracle,
peg,
treasury,
secondary_burn: None,
start_epoch: None,
epoch_frequency: None,
epoch_mint_limit: None
};
Expand Down
10 changes: 10 additions & 0 deletions packages/shade_protocol/src/micro_mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Config {
pub oracle: Contract,
// Both treasury & Commission must be set to function
pub treasury: Option<Contract>,
pub secondary_burn: Option<HumanAddr>,
pub activated: bool,
}

Expand Down Expand Up @@ -45,7 +46,10 @@ pub struct InitMsg {
pub peg: Option<String>,
// Both treasury & commission must be set to function
pub treasury: Option<Contract>,
// This is where the non-burnable assets will go, if not defined they will stay in this contract
pub secondary_burn: Option<HumanAddr>,
// 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 @@ -63,8 +67,10 @@ pub enum HandleMsg {
owner: Option<HumanAddr>,
oracle: Option<Contract>,
treasury: Option<Contract>,
secondary_burn: Option<HumanAddr>,
},
UpdateMintLimit {
start_epoch: Option<Uint128>,
epoch_frequency: Option<Uint128>,
epoch_limit: Option<Uint128>,
},
Expand All @@ -73,6 +79,9 @@ pub enum HandleMsg {
// Commission * 100 e.g. 5 == .05 == 5%
commission: Option<Uint128>,
},
RemoveAsset {
address: HumanAddr,
},
Receive {
sender: HumanAddr,
from: HumanAddr,
Expand All @@ -95,6 +104,7 @@ pub enum HandleAnswer {
UpdateConfig { status: ResponseStatus },
UpdateMintLimit { status: ResponseStatus },
RegisterAsset { status: ResponseStatus },
RemoveAsset { status: ResponseStatus },
Burn { status: ResponseStatus, mint_amount: Uint128 }
}

Expand Down