Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.
Open
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
60 changes: 46 additions & 14 deletions contracts/tokenfactory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use cosmwasm_std::{
};
use cw2::set_contract_version;

use token_bindings::{Metadata, TokenFactoryMsg, TokenFactoryQuery, TokenMsg, TokenQuerier};

use crate::error::TokenFactoryError;
use crate::msg::{ExecuteMsg, GetDenomResponse, InstantiateMsg, QueryMsg};
use crate::state::{State, STATE};
use token_bindings::{TokenFactoryMsg, TokenFactoryQuery, TokenMsg, TokenQuerier};

// version info for migration info
const CONTRACT_NAME: &str = "crates.io:tokenfactory-demo";
Expand Down Expand Up @@ -40,7 +41,7 @@ pub fn execute(
msg: ExecuteMsg,
) -> Result<Response<TokenFactoryMsg>, TokenFactoryError> {
match msg {
ExecuteMsg::CreateDenom { subdenom } => create_denom(subdenom),
ExecuteMsg::CreateDenom { subdenom, metadata } => create_denom(subdenom, metadata),
ExecuteMsg::ChangeAdmin {
denom,
new_admin_address,
Expand All @@ -58,15 +59,15 @@ pub fn execute(
}
}

pub fn create_denom(subdenom: String) -> Result<Response<TokenFactoryMsg>, TokenFactoryError> {
if subdenom.eq("") {
pub fn create_denom(
subdenom: String,
metadata: Option<Metadata>,
) -> Result<Response<TokenFactoryMsg>, TokenFactoryError> {
if subdenom.is_empty() {
return Err(TokenFactoryError::InvalidSubdenom { subdenom });
}

let create_denom_msg = TokenMsg::CreateDenom {
subdenom,
metadata: None,
};
let create_denom_msg = TokenMsg::CreateDenom { subdenom, metadata };

let res = Response::new()
.add_attribute("method", "create_denom")
Expand Down Expand Up @@ -212,18 +213,21 @@ fn validate_denom(

#[cfg(test)]
mod tests {
use super::*;
use std::marker::PhantomData;

use cosmwasm_std::testing::{
mock_env, mock_info, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR,
};
use cosmwasm_std::{
coins, from_binary, Attribute, ContractResult, CosmosMsg, OwnedDeps, Querier, StdError,
SystemError, SystemResult,
};
use std::marker::PhantomData;
use token_bindings::TokenQuery;

use token_bindings::{DenomUnit, TokenQuery};
use token_bindings_test::TokenFactoryApp;

use super::*;

const DENOM_NAME: &str = "mydenom";
const DENOM_PREFIX: &str = "factory";

Expand Down Expand Up @@ -305,15 +309,40 @@ mod tests {

let subdenom: String = String::from(DENOM_NAME);

let msg = ExecuteMsg::CreateDenom { subdenom };
let msg = ExecuteMsg::CreateDenom {
subdenom,
metadata: Some(Metadata {
description: Some("description".to_string()),
denom_units: vec![DenomUnit {
denom: DENOM_NAME.to_string(),
exponent: 6,
aliases: vec![],
}],
base: Some(format!("{}{}", "u", DENOM_NAME)),
display: Some(DENOM_NAME.to_string()),
name: Some(format!("{} {}", DENOM_NAME, "Token")),
symbol: Some(DENOM_NAME.to_string()),
}),
};
let info = mock_info("creator", &coins(2, "token"));
let res = execute(deps.as_mut(), mock_env(), info, msg).unwrap();

assert_eq!(1, res.messages.len());

let expected_message = CosmosMsg::from(TokenMsg::CreateDenom {
subdenom: String::from(DENOM_NAME),
metadata: None,
metadata: Some(Metadata {
description: Some("description".to_string()),
denom_units: vec![DenomUnit {
denom: DENOM_NAME.to_string(),
exponent: 6,
aliases: vec![],
}],
base: Some(format!("{}{}", "u", DENOM_NAME)),
display: Some(DENOM_NAME.to_string()),
name: Some(format!("{} {}", DENOM_NAME, "Token")),
symbol: Some(DENOM_NAME.to_string()),
}),
});
let actual_message = res.messages.get(0).unwrap();
assert_eq!(expected_message, actual_message.msg);
Expand All @@ -333,7 +362,10 @@ mod tests {

let subdenom: String = String::from("");

let msg = ExecuteMsg::CreateDenom { subdenom };
let msg = ExecuteMsg::CreateDenom {
subdenom,
metadata: None,
};
let info = mock_info("creator", &coins(2, "token"));
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
assert_eq!(
Expand Down
2 changes: 2 additions & 0 deletions contracts/tokenfactory/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::Uint128;
use token_bindings::Metadata;

#[cw_serde]
pub struct InstantiateMsg {}
Expand All @@ -8,6 +9,7 @@ pub struct InstantiateMsg {}
pub enum ExecuteMsg {
CreateDenom {
subdenom: String,
metadata: Option<Metadata>,
},
ChangeAdmin {
denom: String,
Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use query::{
AdminResponse, DenomsByCreatorResponse, FullDenomResponse, MetadataResponse, ParamsResponse,
TokenFactoryQuery, TokenQuery,
};
pub use types::{Metadata, Params};
pub use types::{DenomUnit, Metadata, Params};

// This is a signal, such that any contract that imports these helpers will only run on
// blockchains that support token_factory feature
Expand Down
4 changes: 2 additions & 2 deletions packages/bindings/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub struct DenomUnit {
/// 1 denom = 1^exponent base_denom
/// (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with
/// exponent = 6, thus: 1 atom = 10^6 uatom).
exponent: u32,
pub exponent: u32,
/// aliases is a list of string aliases for the given denom
aliases: Vec<String>,
pub aliases: Vec<String>,
}

/// This maps to osmosis.tokenfactory.v1beta1.Params protobuf struct
Expand Down