Skip to content

Commit

Permalink
Merge branch 'main' into zeke/cw20-base-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
ueco-jb authored Jul 19, 2022
2 parents d9cbf6d + 8fd2904 commit ca3c996
Show file tree
Hide file tree
Showing 26 changed files with 306 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

[Full Changelog](https://github.com/CosmWasm/cw-plus/compare/v0.13.4...HEAD)

**Merged pull requests:**

- Add ability to unset minter in UpdateMinter message. [\#748](https://github.com/CosmWasm/cw-plus/pull/748) ([ezekiiel](https://github.com/ezekiiel))

## [v0.13.4](https://github.com/CosmWasm/cw-plus/tree/v0.13.4) (2022-06-02)

[Full Changelog](https://github.com/CosmWasm/cw-plus/compare/v0.13.3...v0.13.4)
Expand Down
35 changes: 23 additions & 12 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ many custom contracts.
If you don't know what CosmWasm is, please check out
[our homepage](https://cosmwasm.com) and
[our documentation](https://docs.cosmwasm.com) to get more background.
We are running a [public testnet](https://github.com/CosmWasm/testnets/blob/master/sandynet-1/README.md)
We are running [public testnets](https://github.com/CosmWasm/testnets#running)
you can use to test out any contracts.

**Warning** None of these contracts have been audited and no liability is
Expand All @@ -62,7 +62,7 @@ cleaner (before: `expires: {at_height: {height: 12345}}` after
The most reusable components are the various cwXYZ specifications under
`packages`. Each one defines a standard interface for different domains,
e.g. [cw20](./packages/cw20/README.md) for fungible tokens,
[cw721](./packages/cw721/README.md) for non-fungible tokens,
[cw721](https://github.com/CosmWasm/cw-nfts/blob/main/packages/cw721/README.md) for non-fungible tokens,
[cw1](./packages/cw1/README.md) for "proxy contracts", etc.
The interface comes with a human description in the READMEs, as well
as Rust types that can be imported.
Expand Down Expand Up @@ -160,7 +160,7 @@ and depth of discussion can give an idea how much review was present.

After that, fuzzing it (ideally with an intelligent fuzzer that understands the domain)
can be valuable. And beyond that formal verification can provide even more assurance
(but is very time consuming and expensive).
(but is very time-consuming and expensive).

### Code Coverage

Expand Down Expand Up @@ -213,7 +213,7 @@ relevant `Cargo.toml` file for clarity.

All *specifications* will always be Apache-2.0. All contracts that are
meant to be *building blocks* will also be Apache-2.0. This is along
the lines of Open Zepellin or other public references.
the lines of Open Zeppelin or other public references.

Contracts that are "ready to deploy" may be licensed under AGPL 3.0 to
encourage anyone using them to contribute back any improvements they
Expand Down
66 changes: 56 additions & 10 deletions contracts/cw20-base/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ pub fn execute_update_minter(
deps: DepsMut,
_env: Env,
info: MessageInfo,
new_minter: String,
new_minter: Option<String>,
) -> Result<Response, ContractError> {
let mut config = TOKEN_INFO
.may_load(deps.storage)?
Expand All @@ -404,18 +404,27 @@ pub fn execute_update_minter(
return Err(ContractError::Unauthorized {});
}

let minter = deps.api.addr_validate(&new_minter)?;
let minter_data = MinterData {
minter,
cap: mint.cap,
};
config.mint = Some(minter_data);
let minter_data = new_minter
.map(|new_minter| deps.api.addr_validate(&new_minter))
.transpose()?
.map(|minter| MinterData {
minter,
cap: mint.cap,
});

config.mint = minter_data;

TOKEN_INFO.save(deps.storage, &config)?;

Ok(Response::default()
.add_attribute("action", "update_minter")
.add_attribute("new_minter", new_minter))
.add_attribute(
"new_minter",
config
.mint
.map(|m| m.minter.into_string())
.unwrap_or_else(|| "None".to_string()),
))
}

pub fn execute_update_marketing(
Expand Down Expand Up @@ -932,7 +941,7 @@ mod tests {

let new_minter = "new_minter";
let msg = ExecuteMsg::UpdateMinter {
new_minter: new_minter.to_string(),
new_minter: Some(new_minter.to_string()),
};

let info = mock_info(&minter, &[]);
Expand Down Expand Up @@ -961,7 +970,7 @@ mod tests {
);

let msg = ExecuteMsg::UpdateMinter {
new_minter: String::from("new_minter"),
new_minter: Some("new_minter".to_string()),
};

let info = mock_info("not the minter", &[]);
Expand All @@ -970,6 +979,43 @@ mod tests {
assert_eq!(err, ContractError::Unauthorized {});
}

#[test]
fn unset_minter() {
let mut deps = mock_dependencies();
let minter = String::from("minter");
let cap = None;
do_instantiate_with_minter(
deps.as_mut(),
&String::from("genesis"),
Uint128::new(1234),
&minter,
cap,
);

let msg = ExecuteMsg::UpdateMinter { new_minter: None };

let info = mock_info(&minter, &[]);
let env = mock_env();
let res = execute(deps.as_mut(), env.clone(), info, msg);
assert!(res.is_ok());
let query_minter_msg = QueryMsg::Minter {};
let res = query(deps.as_ref(), env, query_minter_msg);
let mint: Option<MinterResponse> = from_binary(&res.unwrap()).unwrap();

// Check that mint information was removed.
assert_eq!(mint, None);

// Check that old minter can no longer mint.
let msg = ExecuteMsg::Mint {
recipient: String::from("lucky"),
amount: Uint128::new(222),
};
let info = mock_info("minter", &[]);
let env = mock_env();
let err = execute(deps.as_mut(), env, info, msg).unwrap_err();
assert_eq!(err, ContractError::Unauthorized {});
}

#[test]
fn no_one_mints_if_minter_unset() {
let mut deps = mock_dependencies();
Expand Down
1 change: 0 additions & 1 deletion packages/controllers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Common controllers we can reuse in many contracts"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion packages/controllers/src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'a> Claims<'a> {
let mut to_send = Uint128::zero();
self.0.update(storage, addr, |claim| -> StdResult<_> {
let (_send, waiting): (Vec<_>, _) =
claim.unwrap_or_default().iter().cloned().partition(|c| {
claim.unwrap_or_default().into_iter().partition(|c| {
// if mature and we can pay fully, then include in _send
if c.release_at.is_expired(block) {
if let Some(limit) = cap {
Expand Down
1 change: 0 additions & 1 deletion packages/cw1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-1 interface"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cosmwasm-std = { version = "1.0.0" }
Expand Down
1 change: 0 additions & 1 deletion packages/cw1155/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-1155 interface"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cw-utils = { path = "../../packages/utils", version = "0.13.4" }
Expand Down
1 change: 0 additions & 1 deletion packages/cw2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-2 interface"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cosmwasm-std = { version = "1.0.0", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion packages/cw20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Definition and types for the CosmWasm-20 interface"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cw-utils = { path = "../../packages/utils", version = "0.13.4" }
Expand Down
21 changes: 13 additions & 8 deletions packages/cw20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ minter address and handle updating the ACL there.
this will create `amount` new tokens (updating total supply) and
add them to the balance of `recipient`, as long as it does not exceed the cap.

`UpdateMinter { new_minter: Option<String> }` - Callable only by the
current minter. If `new_minter` is `Some(address)` the minter is set
to the specified address, otherwise the minter is removed and no
future minters may be set.

### Queries

`Minter{}` - Returns who and how much can be minted. Return type is
Expand All @@ -144,6 +149,14 @@ the minter is a smart contract.
This should be enabled with all blockchains that have iterator support.
It allows us to get lists of results with pagination.

### Queries

`AllAllowances{owner, start_after, limit}` - Returns the list of all non-expired allowances
by the given owner. `start_after` and `limit` provide pagination.

`AllAccounts{start_after, limit}` - Returns the list of all accounts that have been created on
the contract (just the addresses). `start_after` and `limit` provide pagination.

## Marketing

This allows us to attach more metadata on the token to help with displaying the token in
Expand Down Expand Up @@ -173,11 +186,3 @@ account, this will update some marketing-related metadata on the contract.
`DownloadLogo{}` - If the token's logo was previously uploaded to the blockchain
(see `UploadLogo` message), then it returns the raw data to be displayed in a browser.
Return type is `DownloadLogoResponse{ mime_type, data }`.

### Queries

`AllAllowances{owner, start_after, limit}` - Returns the list of all non-expired allowances
by the given owner. `start_after` and `limit` provide pagination.

`AllAccounts{start_after, limit}` - Returns the list of all accounts that have been created on
the contract (just the addresses). `start_after` and `limit` provide pagination.
6 changes: 4 additions & 2 deletions packages/cw20/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ pub enum Cw20ExecuteMsg {
/// Only with the "mintable" extension. If authorized, creates amount new tokens
/// and adds to the recipient balance.
Mint { recipient: String, amount: Uint128 },
/// Only with the "mintable" extension. The current minter may set a new minter.
UpdateMinter { new_minter: String },
/// Only with the "mintable" extension. The current minter may set
/// a new minter. Setting the minter to None will remove the
/// token's minter forever.
UpdateMinter { new_minter: Option<String> },
/// Only with the "marketing" extension. If authorized, updates marketing metadata.
/// Setting None/null for any of these will leave it unchanged.
/// Setting Some("") will clear this field on the contract storage
Expand Down
1 change: 0 additions & 1 deletion packages/cw3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "CosmWasm-3 Interface: On-Chain MultiSig/Voting contracts"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cw-utils = { path = "../../packages/utils", version = "0.13.4" }
Expand Down
1 change: 0 additions & 1 deletion packages/cw4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "CosmWasm-4 Interface: Groups Members"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[dependencies]
cw-storage-plus = { path = "../storage-plus", version = "0.13.4" }
Expand Down
1 change: 0 additions & 1 deletion packages/multi-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ description = "Test helpers for multi-contract interactions"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
Expand Down
21 changes: 21 additions & 0 deletions packages/storage-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "cw-storage-macro"
version = "0.13.4"
authors = ["yoisha <[email protected]>"]
edition = "2018"
description = "Macro helpers for storage-plus"
license = "Apache-2.0"
repository = "https://github.com/CosmWasm/cw-plus"
homepage = "https://cosmwasm.com"
documentation = "https://docs.cosmwasm.com"

[lib]
proc-macro = true

[dependencies]
syn = { version = "1.0.96", features = ["full"] }

[dev-dependencies]
cw-storage-plus = { version = "0.13.4", path = "../storage-plus" }
cosmwasm-std = { version = "1.0.0", default-features = false }
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
14 changes: 14 additions & 0 deletions packages/storage-macro/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CW-Storage-Macro: Macro helpers for storage-plus
Copyright (C) 2022 Confio GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Loading

0 comments on commit ca3c996

Please sign in to comment.