Skip to content

Commit

Permalink
feat: make furnace permissionless
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x authored Jun 21, 2024
2 parents da1b8b1 + 4e3c38f commit a3b2cef
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 178 deletions.
106 changes: 65 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions smart-contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "furnace"
version = "0.2.0"
version = "0.2.1"
authors = ["Paul Stelzig <paul@irulast.com>", "Nahem <nahemseguias@gmail.com>"]
edition = "2021"

Expand All @@ -18,22 +18,22 @@ crate-type = ["cdylib", "rlib"]
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-schema = "2.0.0"
cosmwasm-std = { version = "1.1.3", features = ["stargate"] }
cosmwasm-storage = "1.1.3"
cw-storage-plus = "1.0.1"
cw2 = "1.0.1"
schemars = "0.8.10"
cosmwasm-schema = { version = "1.5.5" }
cosmwasm-std = { version = "1.5.5", features = ["stargate"] }
cw-storage-plus = { version = "1.2.0" }
cw2 = { version = "1.1.2" }
schemars = { version = "0.8.21" }
serde = { version = "1.0.145", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.31" }
osmosis-std-derive = "0.15.3"
osmosis-std-derive = { version = "0.15.3" }
prost = { version = "0.11.0", default-features = false, features = [
"prost-derive",
] }
prost-types = { version = "0.11.1", default-features = false }
semver = "1.0.12"
cw20 = "1.0.1"
cw-utils = "1.0.1"
semver = { version = "1.0.12" }
cw20 = { version = "1.1.2" }
cw-utils = { version = "1.0.3" }
white-whale-std = { version = "1.1.5" }

[dev-dependencies]
cw-multi-test = "0.20.0"
cw-multi-test = { version = "0.20.1" }
75 changes: 54 additions & 21 deletions smart-contracts/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ use crate::error::ContractError;
use crate::execute::{
execute_add_fuel, execute_burn, execute_update_config, execute_update_fuel_config,
};
use crate::helpers::validate_fee_rate;
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::query::{query_config, query_fuels, query_leaderboard};
use crate::state::{Config, CONFIG};
use cosmwasm_schema::cw_serde;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response};
use cw2::set_contract_version;
use cosmwasm_std::{
to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, Uint128,
};
use cw2::{get_contract_version, set_contract_version};
use cw_storage_plus::Item;
use semver::Version;
use white_whale_std::migrate_guards::check_contract_name;

// version info for migration info
const CONTRACT_NAME: &str = "furnace";
Expand All @@ -30,6 +37,10 @@ pub fn instantiate(
owner: deps.api.addr_validate(&msg.owner)?,
mint_cost: msg.mint_cost,
native_denom: msg.native_denom.to_string(),
default_fuel_fee_recipient: deps.api.addr_validate(&msg.default_fuel_fee_recipient)?,
default_fuel_fee_rate: validate_fee_rate(msg.default_fuel_fee_rate)?,
default_ash_fee_recipient: deps.api.addr_validate(&msg.default_ash_fee_recipient)?,
default_ash_fee_rate: validate_fee_rate(msg.default_ash_fee_rate)?,
};
CONFIG.save(deps.storage, &config)?;

Expand All @@ -48,24 +59,9 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response, ContractError> {
match msg {
ExecuteMsg::AddFuel {
subdenom,
denom,
fuel_fee_recipient,
fuel_fee_rate,
ash_fee_recipient,
ash_fee_rate,
} => execute_add_fuel(
deps,
env,
info,
subdenom,
denom,
fuel_fee_recipient,
fuel_fee_rate,
ash_fee_recipient,
ash_fee_rate,
),
ExecuteMsg::AddFuel { subdenom, denom } => {
execute_add_fuel(deps, env, info, subdenom, denom)
}
ExecuteMsg::UpdateConfig { owner, mint_cost } => {
execute_update_config(deps, info, owner, mint_cost)
}
Expand Down Expand Up @@ -117,6 +113,43 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr

// This will be used in the future for migrating the contract
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
pub fn migrate(deps: DepsMut, _env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
check_contract_name(deps.storage, CONTRACT_NAME.to_string())?;
let version: Version = CONTRACT_VERSION.parse()?;
let storage_version: Version = get_contract_version(deps.storage)?.version.parse()?;

if storage_version >= version {
return Err(ContractError::MigrateInvalidVersion {
current_version: storage_version,
new_version: version,
});
}

if storage_version < Version::parse("0.2.1")? {
#[cw_serde]
struct OldConfig {
pub owner: Addr,
pub mint_cost: Uint128,
pub native_denom: String,
}

const OLD_CONFIG: Item<OldConfig> = Item::new("config");
let old_config: OldConfig = OLD_CONFIG.load(deps.storage)?;

let config = Config {
owner: old_config.owner,
mint_cost: old_config.mint_cost,
native_denom: old_config.native_denom,
default_fuel_fee_recipient: deps.api.addr_validate(&msg.default_fuel_fee_recipient)?,
default_fuel_fee_rate: validate_fee_rate(msg.default_fuel_fee_rate)?,
default_ash_fee_recipient: deps.api.addr_validate(&msg.default_ash_fee_recipient)?,
default_ash_fee_rate: validate_fee_rate(msg.default_ash_fee_rate)?,
};

CONFIG.save(deps.storage, &config)?;
}

set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;

Ok(Response::default())
}
19 changes: 19 additions & 0 deletions smart-contracts/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_std::{OverflowError, StdError, Uint128};
use cw_utils::PaymentError;
use semver::Version;
use thiserror::Error;

use crate::contract::MIN_AMOUNT_TO_BURN;
Expand Down Expand Up @@ -39,4 +40,22 @@ pub enum ContractError {

#[error("Insufficient funds")]
InsufficientFunds {},

#[error("Attempt to migrate to version {new_version}, but contract is on a higher version {current_version}")]
MigrateInvalidVersion {
new_version: Version,
current_version: Version,
},

#[error("Semver parsing error: {0}")]
SemVer(String),

#[error("Can't burn IBC tokens. Please add the fuel token on the native chain")]
InvalidIBCFuel {},
}

impl From<semver::Error> for ContractError {
fn from(err: semver::Error) -> Self {
Self::SemVer(err.to_string())
}
}
Loading

0 comments on commit a3b2cef

Please sign in to comment.