Skip to content

Commit

Permalink
support kujira's /kujira.denom... tokenfactory fork (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso authored Apr 1, 2024
1 parent d59c282 commit caea80a
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 155 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ cw-hooks = { path = "./packages/cw-hooks", version = "2.4.1" }
cw-paginate-storage = { path = "./packages/cw-paginate-storage", version = "2.4.1" }
cw-payroll-factory = { path = "./contracts/external/cw-payroll-factory", version = "2.4.1" }
cw-stake-tracker = { path = "./packages/cw-stake-tracker", version = "2.4.1" }
cw-tokenfactory-issuer = { path = "./contracts/external/cw-tokenfactory-issuer", version = "2.4.1" }
cw-tokenfactory-issuer = { path = "./contracts/external/cw-tokenfactory-issuer", version = "2.4.1", default-features = false }
cw-tokenfactory-types = { path = "./packages/cw-tokenfactory-types", version = "2.4.1", default-features = false }
cw-vesting = { path = "./contracts/external/cw-vesting", version = "2.4.1" }
cw-wormhole = { path = "./packages/cw-wormhole", version = "2.4.1" }
Expand Down
1 change: 1 addition & 0 deletions contracts/external/cw-tokenfactory-issuer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test-tube = ["osmosis_tokenfactory"]
# standard in types library
osmosis_tokenfactory = ["cw-tokenfactory-types/osmosis_tokenfactory"]
cosmwasm_tokenfactory = ["cw-tokenfactory-types/cosmwasm_tokenfactory"]
kujira_tokenfactory = ["cw-tokenfactory-types/kujira_tokenfactory"]

[dependencies]
cosmwasm-schema = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions contracts/external/cw-tokenfactory-issuer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn execute(
ExecuteMsg::SetBeforeSendHook { cosmwasm_address } => {
execute::set_before_send_hook(deps, env, info, cosmwasm_address)
}
#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
ExecuteMsg::SetDenomMetadata { metadata } => {
execute::set_denom_metadata(deps, env, info, metadata)
}
Expand Down
7 changes: 4 additions & 3 deletions contracts/external/cw-tokenfactory-issuer/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cosmwasm_std::{coins, BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128};

use cw_tokenfactory_types::msg::{msg_burn, msg_change_admin, msg_mint, msg_set_denom_metadata};
use cw_tokenfactory_types::msg::{msg_burn, msg_change_admin, msg_mint};
#[cfg(feature = "osmosis_tokenfactory")]
use cw_tokenfactory_types::msg::{msg_force_transfer, msg_set_before_send_hook};

use dao_interface::token::Metadata;
#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
use {cw_tokenfactory_types::msg::msg_set_denom_metadata, dao_interface::token::Metadata};

use crate::error::ContractError;
use crate::helpers::{check_before_send_hook_features_enabled, check_is_not_frozen};
Expand Down Expand Up @@ -177,6 +177,7 @@ pub fn update_tokenfactory_admin(
/// Sets metadata related to the Token Factory denom.
///
/// Must be the contract owner to call this method.
#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
pub fn set_denom_metadata(
deps: DepsMut,
env: Env,
Expand Down
2 changes: 2 additions & 0 deletions contracts/external/cw-tokenfactory-issuer/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::state::BeforeSendHookInfo;
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Coin, Uint128};

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
pub use dao_interface::token::{DenomUnit, Metadata};

/// The message used to create a new instance of this smart contract.
Expand Down Expand Up @@ -78,6 +79,7 @@ pub enum ExecuteMsg {
SetBurnerAllowance { address: String, allowance: Uint128 },

/// Set denom metadata. see: https://docs.cosmos.network/main/modules/bank#denom-metadata.
#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
SetDenomMetadata { metadata: Metadata },

/// Grant/revoke mint allowance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use cw_tokenfactory_issuer::{msg::InstantiateMsg, ContractError};

use crate::test_env::{TestEnv, TokenfactoryIssuer};

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
#[test]
fn set_denom_metadata_by_contract_owner_should_work() {
let subdenom = "usthb".to_string();
Expand Down Expand Up @@ -35,6 +36,7 @@ fn set_denom_metadata_by_contract_owner_should_work() {
.unwrap();
}

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
#[test]
fn set_denom_metadata_by_contract_non_owner_should_fail() {
let subdenom = "usthb".to_string();
Expand Down Expand Up @@ -78,6 +80,7 @@ fn set_denom_metadata_by_contract_non_owner_should_fail() {
)
}

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
#[test]
fn set_denom_metadata_with_base_denom_unit_should_overides_default_base_denom_unit() {
let subdenom = "usthb".to_string();
Expand Down
6 changes: 5 additions & 1 deletion contracts/external/cw-tokenfactory-issuer/tests/test_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use cosmwasm_std::Uint128;
use cosmwasm_std::{Addr, Coin};

use cw_tokenfactory_issuer::msg::{AllowlistResponse, DenylistResponse, Metadata, MigrateMsg};
#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
use cw_tokenfactory_issuer::msg::Metadata;

use cw_tokenfactory_issuer::msg::{AllowlistResponse, DenylistResponse, MigrateMsg};
use cw_tokenfactory_issuer::{
msg::{
AllowanceResponse, AllowancesResponse, DenomResponse, ExecuteMsg, InstantiateMsg,
Expand Down Expand Up @@ -204,6 +207,7 @@ impl TokenfactoryIssuer {
)
}

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
pub fn set_denom_metadata(
&self,
metadata: Metadata,
Expand Down
5 changes: 4 additions & 1 deletion contracts/test/dao-test-custom-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ thiserror = { workspace = true }
dao-dao-macros = { workspace = true }
dao-interface = { workspace = true }
dao-voting = { workspace = true }
cw-tokenfactory-issuer = { workspace = true, features = ["library"] }
cw-tokenfactory-issuer = { workspace = true, features = [
"library",
"osmosis_tokenfactory",
] }

[dev-dependencies]
cw-multi-test = { workspace = true }
19 changes: 15 additions & 4 deletions contracts/voting/dao-voting-token-staked/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[package]
name = "dao-voting-token-staked"
authors = ["Callum Anderson <callumanderson745@gmail.com>", "Noah Saso <no-reply@no-reply.com>", "Jake Hartnell <no-reply@no-reply.com>"]
authors = [
"Callum Anderson <callumanderson745@gmail.com>",
"Noah Saso <no-reply@no-reply.com>",
"Jake Hartnell <no-reply@no-reply.com>",
]
description = "A DAO DAO voting module based on staked token factory or native tokens. Only works with chains that support Token Factory."
edition = { workspace = true }
license = { workspace = true }
Expand All @@ -11,6 +15,7 @@ version = { workspace = true }
crate-type = ["cdylib", "rlib"]

[features]
default = ["osmosis_tokenfactory"]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
Expand All @@ -20,9 +25,14 @@ library = []
test-tube = []
# when writing tests you may wish to enable test-tube as a default feature
# default = ["test-tube"]
# different tokenfactory cosmos sdk module standards. enable corresponding
# standard in types library
osmosis_tokenfactory = ["cw-tokenfactory-issuer/osmosis_tokenfactory"]
cosmwasm_tokenfactory = ["cw-tokenfactory-issuer/cosmwasm_tokenfactory"]
kujira_tokenfactory = ["cw-tokenfactory-issuer/kujira_tokenfactory"]

[dependencies]
cosmwasm-std = { workspace = true, features = ["cosmwasm_1_1"] }
cosmwasm-std = { workspace = true, features = ["cosmwasm_1_1"] }
cosmwasm-schema = { workspace = true }
cw-ownable = { workspace = true }
cw-storage-plus = { workspace = true }
Expand All @@ -35,12 +45,13 @@ dao-dao-macros = { workspace = true }
dao-hooks = { workspace = true }
dao-interface = { workspace = true }
dao-voting = { workspace = true }
cw-tokenfactory-issuer = { workspace = true, features = ["library"] }
cw-tokenfactory-issuer = { workspace = true, default-features = false, features = [
"library",
] }

[dev-dependencies]
anyhow = { workspace = true }
cw-multi-test = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
dao-proposal-single = { workspace = true }
dao-proposal-hook-counter = { workspace = true }
dao-test-custom-factory = { workspace = true }
Expand Down
10 changes: 9 additions & 1 deletion contracts/voting/dao-voting-token-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ use cw2::{get_contract_version, set_contract_version, ContractVersion};
use cw_controllers::ClaimsResponse;
use cw_storage_plus::Bound;
use cw_tokenfactory_issuer::msg::{
DenomUnit, ExecuteMsg as IssuerExecuteMsg, InstantiateMsg as IssuerInstantiateMsg, Metadata,
ExecuteMsg as IssuerExecuteMsg, InstantiateMsg as IssuerInstantiateMsg,
};

#[cfg(any(feature = "osmosis_tokenfactory", feature = "cosmwasm_tokenfactory"))]
use cw_tokenfactory_issuer::msg::{DenomUnit, Metadata};

use cw_utils::{
maybe_addr, must_pay, parse_reply_execute_data, parse_reply_instantiate_data, Duration,
};
Expand Down Expand Up @@ -627,6 +631,10 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result<Response, ContractEr
});

// If metadata, set it by calling the contract
#[cfg(any(
feature = "osmosis_tokenfactory",
feature = "cosmwasm_tokenfactory"
))]
if let Some(metadata) = token.metadata {
// The first denom_unit must be the same as the tf and base denom.
// It must have an exponent of 0. This the smallest unit of the token.
Expand Down
6 changes: 4 additions & 2 deletions packages/cw-tokenfactory-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ version = { workspace = true }

[features]
default = ["osmosis_tokenfactory"]
# use the /cosmwasm.tokenfactory... msg types
cosmwasm_tokenfactory = []
# use the /osmosis.tokenfactory... msg types
osmosis_tokenfactory = []
# use the /cosmwasm.tokenfactory... msg types
cosmwasm_tokenfactory = []
# use the /kujira.denom... msg types
kujira_tokenfactory = []

[dependencies]
cosmwasm-std = { workspace = true }
Expand Down
12 changes: 7 additions & 5 deletions packages/cw-tokenfactory-types/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
This package supports contracts that depend on varying tokenfactory standards,
which use very similar or identical Cosmos SDK msgs with different type URLs:

- `/cosmwasm.tokenfactory...`
- `/osmosis.tokenfactory...`
- `/cosmwasm.tokenfactory...`
- `/kujira.denom...`

Build features:

Enabling the `cosmwasm_tokenfactory` build feature will use the
`/cosmwasm.tokenfactory...` msg type URLs, whereas enabling the
`osmosis_tokenfactory` build feature will use the `/osmosis.tokenfactory...` msg
type URLs. `osmosis_tokenfactory` is enabled by default.
- `osmosis_tokenfactory` (default)
- `cosmwasm_tokenfactory`
- `kujira_tokenfactory`
97 changes: 97 additions & 0 deletions packages/cw-tokenfactory-types/src/cosmos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use std::convert::TryFrom;
use std::convert::TryInto;

use osmosis_std_derive::CosmwasmExt;

/// Coin defines a token with a denomination and an amount.
///
/// NOTE: The amount field is an Int which implements the custom method
/// signatures required by gogoproto.
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.base.v1beta1.Coin")]
pub struct Coin {
#[prost(string, tag = "1")]
pub denom: ::prost::alloc::string::String,
#[prost(string, tag = "2")]
pub amount: ::prost::alloc::string::String,
}

/// DenomUnit represents a struct that describes a given
/// denomination unit of the basic token.
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.bank.v1beta1.DenomUnit")]
pub struct DenomUnit {
/// denom represents the string name of the given denom unit (e.g uatom).
#[prost(string, tag = "1")]
pub denom: ::prost::alloc::string::String,
/// exponent represents power of 10 exponent that one must
/// raise the base_denom to in order to equal the given DenomUnit's denom
/// 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).
#[prost(uint32, tag = "2")]
#[serde(
serialize_with = "crate::shim::as_str::serialize",
deserialize_with = "crate::shim::as_str::deserialize"
)]
pub exponent: u32,
/// aliases is a list of string aliases for the given denom
#[prost(string, repeated, tag = "3")]
pub aliases: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
}
/// Metadata represents a struct that describes
/// a basic token.
#[derive(
Clone,
PartialEq,
Eq,
::prost::Message,
::serde::Serialize,
::serde::Deserialize,
::schemars::JsonSchema,
CosmwasmExt,
)]
#[proto_message(type_url = "/cosmos.bank.v1beta1.Metadata")]
pub struct Metadata {
#[prost(string, tag = "1")]
pub description: ::prost::alloc::string::String,
/// denom_units represents the list of DenomUnit's for a given coin
#[prost(message, repeated, tag = "2")]
pub denom_units: ::prost::alloc::vec::Vec<DenomUnit>,
/// base represents the base denom (should be the DenomUnit with exponent = 0).
#[prost(string, tag = "3")]
pub base: ::prost::alloc::string::String,
/// display indicates the suggested denom that should be
/// displayed in clients.
#[prost(string, tag = "4")]
pub display: ::prost::alloc::string::String,
/// name defines the name of the token (eg: Cosmos Atom)
///
/// Since: cosmos-sdk 0.43
#[prost(string, tag = "5")]
pub name: ::prost::alloc::string::String,
/// symbol is the token symbol usually shown on exchanges (eg: ATOM). This can
/// be the same as the display.
///
/// Since: cosmos-sdk 0.43
#[prost(string, tag = "6")]
pub symbol: ::prost::alloc::string::String,
}
Loading

0 comments on commit caea80a

Please sign in to comment.