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

ForceTransfer Msg + Burn from any addr #1

Merged
merged 2 commits into from
Mar 22, 2023
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
364 changes: 220 additions & 144 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/reflect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "token-reflect"
version = "0.8.0"
version = "0.9.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Reflect messages to use for test cases - based on cw-mask"
Expand All @@ -20,7 +20,7 @@ backtraces = ["cosmwasm-std/backtraces"]
cosmwasm-schema = "1.1"
cosmwasm-std = { version = "1.1", features = ["staking", "stargate"] }
cosmwasm-storage = "1.1"
token-bindings = { version = "0.8.0", path = "../../packages/bindings" }
token-bindings = { version = "0.9.0", path = "../../packages/bindings" }
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
thiserror = "1.0"
Expand Down
16 changes: 8 additions & 8 deletions contracts/tokenfactory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tokenfactory"
version = "0.8.0"
version = "0.9.0"
authors = ["Roman <[email protected]>"]
edition = "2018"

Expand Down Expand Up @@ -41,15 +41,15 @@ optimize = """docker run --rm -v "$(pwd)":/code \

[dependencies]
cosmwasm-schema = "1.1"
cosmwasm-std = "1.1"
cosmwasm-std = "1.2.3"
cosmwasm-storage = "1.1"
cw-storage-plus = "0.15"
token-bindings = { version = "0.8.0", path = "../../packages/bindings" }
cw2 = "0.15"
cw-storage-plus = "1.0.1"
token-bindings = { version = "0.9.0", path = "../../packages/bindings" }
cw2 = "1.0.1"
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
thiserror = "1.0"
thiserror = { version = "1.0" }

[dev-dependencies]
cw-multi-test = "0.15"
token-bindings-test = { version = "0.8.0", path = "../../packages/bindings-test" }
cw-multi-test = "0.16.2"
token-bindings-test = { path = "../../packages/bindings-test" }
61 changes: 51 additions & 10 deletions contracts/tokenfactory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ pub fn execute(
amount,
burn_from_address,
} => burn_tokens(deps, denom, amount, burn_from_address),
ExecuteMsg::ForceTransfer {
denom,
amount,
from_address,
to_address,
} => force_transfer(deps, denom, amount, from_address, to_address),
}
}

Expand Down Expand Up @@ -125,12 +131,6 @@ pub fn burn_tokens(
amount: Uint128,
burn_from_address: String,
) -> Result<Response<TokenFactoryMsg>, TokenFactoryError> {
if !burn_from_address.is_empty() {
return Result::Err(TokenFactoryError::BurnFromAddressNotSupported {
address: burn_from_address,
});
}

if amount.eq(&Uint128::new(0_u128)) {
return Result::Err(TokenFactoryError::ZeroAmount {});
}
Expand All @@ -146,6 +146,28 @@ pub fn burn_tokens(
Ok(res)
}

pub fn force_transfer(
deps: DepsMut<TokenFactoryQuery>,
denom: String,
amount: Uint128,
from_address: String,
to_address: String,
) -> Result<Response<TokenFactoryMsg>, TokenFactoryError> {
if amount.eq(&Uint128::new(0_u128)) {
return Result::Err(TokenFactoryError::ZeroAmount {});
}

validate_denom(deps, denom.clone())?;

let force_msg = TokenMsg::force_transfer_tokens(denom, amount, from_address, to_address);

let res = Response::new()
.add_attribute("method", "force_transfer_tokens")
.add_message(force_msg);

Ok(res)
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<TokenFactoryQuery>, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
Expand Down Expand Up @@ -554,13 +576,32 @@ mod tests {
burn_from_address: String::from(BURN_FROM_ADDR),
amount: burn_amount,
};
let err = execute(deps.as_mut(), mock_env(), info, msg).unwrap_err();
let err = execute(deps.as_mut(), mock_env(), info, msg).is_err();
assert_eq!(err, false)
}

#[test]
fn msg_force_transfer_tokens_address() {
let mut deps = mock_dependencies();

const TRANSFER_FROM_ADDR: &str = "transferme";
const TRANSFER_TO_ADDR: &str = "tome";

let transfer_amount = Uint128::new(100_u128);
let full_denom_name: &str =
&format!("{}/{}/{}", DENOM_PREFIX, MOCK_CONTRACT_ADDR, DENOM_NAME)[..];

let info = mock_info("creator", &coins(2, "token"));

let expected_error = TokenFactoryError::BurnFromAddressNotSupported {
address: String::from(BURN_FROM_ADDR),
let msg = ExecuteMsg::ForceTransfer {
denom: String::from(full_denom_name),
amount: transfer_amount,
from_address: TRANSFER_FROM_ADDR.to_string(),
to_address: TRANSFER_TO_ADDR.to_string(),
};

assert_eq!(expected_error, err)
let err = execute(deps.as_mut(), mock_env(), info, msg).is_err();
assert_eq!(err, false)
}

#[test]
Expand Down
3 changes: 0 additions & 3 deletions contracts/tokenfactory/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub enum TokenFactoryError {
#[error("denom does not exist: {denom:?}")]
DenomDoesNotExist { denom: String },

#[error("address is not supported yet, was: {address:?}")]
BurnFromAddressNotSupported { address: String },

#[error("amount was zero, must be positive")]
ZeroAmount {},
}
6 changes: 6 additions & 0 deletions contracts/tokenfactory/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub enum ExecuteMsg {
amount: Uint128,
burn_from_address: String,
},
ForceTransfer {
denom: String,
amount: Uint128,
from_address: String,
to_address: String,
},
}

#[cw_serde]
Expand Down
2 changes: 1 addition & 1 deletion packages/bindings-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "Apache-2.0"

[dependencies]
itertools = "0.10"
token-bindings = { version = "0.8.0", path = "../bindings" }
token-bindings = { version = "0.9.0", path = "../bindings" }
cosmwasm-std = "1.1"
schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
6 changes: 6 additions & 0 deletions packages/bindings-test/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ impl Module for TokenFactoryModule {
amount: _,
burn_from_address: _,
} => todo!(),
TokenMsg::ForceTransfer {
denom: _,
amount: _,
from_address: _,
to_address: _,
} => todo!(),
TokenMsg::ChangeAdmin {
denom,
new_admin_address,
Expand Down
2 changes: 1 addition & 1 deletion packages/bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "token-bindings"
version = "0.8.0"
version = "0.9.0"
authors = ["Ethan Frey <[email protected]>"]
edition = "2018"
description = "Bindings for CustomMsg and CustomQuery for the Osmosis blockchain"
Expand Down
27 changes: 24 additions & 3 deletions packages/bindings/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,19 @@ pub enum TokenMsg {
},
/// Contracts can burn native tokens for an existing factory denom
/// that they are the admin of.
/// Currently, the burn from address must be the admin contract.
BurnTokens {
denom: String,
amount: Uint128,
burn_from_address: String,
},
/// Contracts can force transfer tokens for an existing factory denom
/// that they are the admin of.
ForceTransfer {
denom: String,
amount: Uint128,
from_address: String,
to_address: String,
},
SetMetadata {
denom: String,
metadata: Metadata,
Expand All @@ -67,12 +74,26 @@ impl TokenMsg {
pub fn burn_contract_tokens(
denom: String,
amount: Uint128,
_burn_from_address: String,
burn_from_address: String,
) -> Self {
TokenMsg::BurnTokens {
denom,
amount,
burn_from_address: "".to_string(), // burn_from_address is currently disabled.
burn_from_address,
}
}

pub fn force_transfer_tokens(
denom: String,
amount: Uint128,
from_address: String,
to_address: String,
) -> Self {
TokenMsg::ForceTransfer {
denom,
amount,
from_address,
to_address,
}
}
}
Expand Down