Skip to content

Commit

Permalink
removed create denom funtionality from voting contract and token factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-1857 committed Feb 13, 2024
1 parent f08e96e commit 8d7a2c6
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 287 deletions.
85 changes: 31 additions & 54 deletions contracts/external/cw-tokenfactory-issuer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
use std::convert::TryInto;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, SubMsg,
};
use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult};
use secret_cw2::{get_contract_version, set_contract_version, ContractVersion};
use cw_tokenfactory_types::msg::msg_create_denom;
use cw_tokenfactory_types::cosmwasm::MsgCreateDenomResponse;

use crate::error::ContractError;
use crate::execute;
use crate::hooks;
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg,InstantiateResponse};
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg};
use crate::queries;
use crate::state::{BeforeSendHookInfo, BEFORE_SEND_HOOK_INFO, DENOM, IS_FROZEN};

// Version info for migration
const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME");
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");

const CREATE_DENOM_REPLY_ID: u64 = 1;

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn instantiate(
deps: DepsMut,
env: Env,
_env: Env,
info: MessageInfo,
msg: InstantiateMsg,
) -> Result<Response, ContractError> {
Expand All @@ -44,34 +36,34 @@ pub fn instantiate(
)?;
IS_FROZEN.save(deps.storage, &false)?;

match msg {
InstantiateMsg::NewToken { subdenom } => {
Ok(Response::new()
.add_attribute("action", "instantiate")
.add_attribute("owner", info.sender)
.add_attribute("subdenom", subdenom.clone())
.set_data(to_binary(&InstantiateResponse{
contact_address: env.contract.address.clone(),
code_hash:env.contract.code_hash,
})?)
.add_submessage(
// Create new denom, denom info is saved in the reply
SubMsg::reply_on_success(
msg_create_denom(env.contract.address.to_string(), subdenom),
CREATE_DENOM_REPLY_ID,
),
))
}
InstantiateMsg::ExistingToken { denom } => {
DENOM.save(deps.storage, &denom)?;

Ok(Response::new()
.add_attribute("action", "instantiate")
.add_attribute("owner", info.sender)
.add_attribute("denom", denom))
}
}
// match msg {
// InstantiateMsg::NewToken { subdenom } => {
// Ok(Response::new()
// .add_attribute("action", "instantiate")
// .add_attribute("owner", info.sender)
// .add_attribute("subdenom", subdenom.clone())
// .set_data(to_binary(&InstantiateResponse{
// contact_address: env.contract.address.clone(),
// code_hash:env.contract.code_hash,
// })?)
// .add_submessage(
// // Create new denom, denom info is saved in the reply
// SubMsg::reply_on_success(
// msg_create_denom(env.contract.address.to_string(), subdenom),
// CREATE_DENOM_REPLY_ID,
// ),
// ))
// }
// InstantiateMsg::ExistingToken { denom } => {
DENOM.save(deps.storage, &msg.denom)?;

Ok(Response::new()
.add_attribute("action", "instantiate")
.add_attribute("owner", info.sender)
.add_attribute("denom", msg.denom))
}
// }
// }

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
Expand Down Expand Up @@ -151,9 +143,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::Denylist { start_after, limit } => {
to_binary(&queries::query_denylist(deps, start_after, limit)?)
}
QueryMsg::IsAllowed { address } => {
to_binary(&queries::query_is_allowed(deps, address)?)
}
QueryMsg::IsAllowed { address } => to_binary(&queries::query_is_allowed(deps, address)?),
QueryMsg::IsDenied { address } => to_binary(&queries::query_is_denied(deps, address)?),
QueryMsg::IsFrozen {} => to_binary(&queries::query_is_frozen(deps)?),
QueryMsg::Ownership {} => to_binary(&queries::query_owner(deps)?),
Expand All @@ -178,16 +168,3 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, C

Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractError> {
match msg.id {
CREATE_DENOM_REPLY_ID => {
let MsgCreateDenomResponse { new_token_denom } = msg.result.try_into()?;
DENOM.save(deps.storage, &new_token_denom)?;

Ok(Response::new().add_attribute("denom", new_token_denom))
}
_ => Err(ContractError::UnknownReplyId { id: msg.id }),
}
}
22 changes: 13 additions & 9 deletions contracts/external/cw-tokenfactory-issuer/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ use secret_toolkit::utils::InitCallback;

/// The message used to create a new instance of this smart contract.
#[cw_serde]
pub enum InstantiateMsg {
pub struct InstantiateMsg {
/// `NewToken` will create a new token when instantiate the contract.
/// Newly created token will have full denom as `factory/<contract_address>/<subdenom>`.
/// It will be attached to the contract setup the beforesend listener automatically.
NewToken {
/// component of fulldenom (`factory/<contract_address>/<subdenom>`).
subdenom: String,
},

/// NOTE* ============ The new token functionality is not suported right now in Secret Network

// NewToken {
// /// component of fulldenom (`factory/<contract_address>/<subdenom>`).
// subdenom: String,
// },

/// `ExistingToken` will use already created token. So to set this up,
/// Token Factory admin for the existing token needs trasfer admin over
/// to this contract, and optionally set the `BeforeSendHook` manually.
ExistingToken { denom: String },
pub denom: String,
}

impl InitCallback for InstantiateMsg{
const BLOCK_SIZE: usize=264;
impl InitCallback for InstantiateMsg {
const BLOCK_SIZE: usize = 264;
}

#[cw_serde]
pub struct InstantiateResponse{
pub struct InstantiateResponse {
pub contact_address: Addr,
pub code_hash: String,
}
Expand Down
Loading

0 comments on commit 8d7a2c6

Please sign in to comment.