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

CW-1155 (and royalties extension) #162

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2b1ba1b
feat: add cw1155-base
ALPAC-4 Aug 17, 2022
26122c8
feat: add cw1155-metadata-onchain
ALPAC-4 Aug 18, 2022
78746b0
feat: add jobs for cw1155
ALPAC-4 Aug 18, 2022
8fe5edb
fix: fix spaceing
ALPAC-4 Aug 18, 2022
b70c8dc
fix: add jobs to test and add package_cw1155
ALPAC-4 Aug 18, 2022
5e3fd48
add schema
ALPAC-4 Aug 18, 2022
753cb6b
fix: add package schema, fix typo
ALPAC-4 Aug 18, 2022
adeb7cf
trivial
dirtyshab Apr 30, 2024
d822a4f
fix: split up transfer event into relevant action events.
dirtyshab May 1, 2024
42a4499
fix: bring back ApprovedForAll and IsApprovedForAll queries (part of …
dirtyshab May 2, 2024
159c79e
Cw1155 Approve/Revoke single (#3)
dirtyshab May 3, 2024
ad05092
refactor: moves cw1155 messages to package, renames messages to close…
dirtyshab May 3, 2024
823639f
fix: mint logic
dirtyshab May 3, 2024
71a1f2a
fix: rename events to be in format *_single and *_batch
dirtyshab May 3, 2024
5875ad0
fix: schema files
dirtyshab May 3, 2024
e107869
feat: implement mint_batch
dirtyshab May 3, 2024
ed56d0a
feat: implements contract_info, minter, and ownership queries.
dirtyshab May 3, 2024
d8e7f76
feat: query all_token_infos
dirtyshab May 4, 2024
0f49674
feat: store and query total supply (sum of all token balances)
dirtyshab May 4, 2024
e42a811
fix: use library feature in cw721-base import
dirtyshab May 6, 2024
b2c060c
fix: store total supply in base instantiate.
dirtyshab May 6, 2024
56e4bc3
fix: cw1155-metadata tests
dirtyshab May 6, 2024
6635fa3
feat: cw1155 on-chain royalties extension
dirtyshab May 6, 2024
00c7b19
fix: existing tests/imports
dirtyshab May 6, 2024
8f9afd2
fix: generic usage
dirtyshab May 6, 2024
c048017
chore: lint
dirtyshab May 6, 2024
be21d01
chore: clippy
dirtyshab May 6, 2024
65ab7d4
fix: lint 2, add circle ci config for cw1155-royalties
dirtyshab May 6, 2024
09f471d
fix: circle ci
dirtyshab May 6, 2024
68960bb
fix: circle ci lint
dirtyshab May 7, 2024
85e5d47
fix: move cosmwasm-schema to deps in metadata extension
dirtyshab May 7, 2024
6f5e9f5
fix: clippy
dirtyshab May 7, 2024
4c7600e
adds custom execute extension and response generics to Cw1155Contract…
dirtyshab May 22, 2024
c00a913
impl cw_ownable_execute on cw1155.
dirtyshab May 23, 2024
1d3b795
fix: cargo schema
dirtyshab May 23, 2024
32c6e41
fix: cargo schema package
dirtyshab May 23, 2024
cfa0c08
chore: merge queries num_tokens/supply
dirtyshab May 23, 2024
3751bf6
fix query BalanceOfBatch
dirtyshab Jun 5, 2024
3609e4a
make state mod public
dirtyshab Jul 1, 2024
5acfcbf
rename AllBalancesResponse to BalancesResponse and return as response…
dirtyshab Jul 3, 2024
d1e6c9d
remove query AllTokenInfo
dirtyshab Jul 3, 2024
07105d8
transfer funds along with send/batch_send
dirtyshab Jul 3, 2024
46136ba
Merge upstream (#4)
dirtyshab Jul 8, 2024
1e1108d
Merge branch 'main' of github.com:CosmWasm/cw-nfts into cw1155
dirtyshab Jul 9, 2024
f142b3b
add more tests
dirtyshab Jul 9, 2024
9dbbc6e
add sender/owner to transfer/mint/burn events
dirtyshab Jul 23, 2024
49d70aa
implement update_metadata() for updating exension/token_uri. not on b…
dirtyshab Jul 23, 2024
e076bd1
clippy
dirtyshab Jul 23, 2024
de3e709
change events to be attributes under wasm like cw721 has
dirtyshab Jul 24, 2024
f0e2812
use same collection key as cw721
dirtyshab Jul 24, 2024
45fc627
zero amount check
dirtyshab Jul 24, 2024
5b88809
use rust version 1.75
dirtyshab Jul 25, 2024
3ba9341
add Cw2981QueryExtensionMsg for convenience (possibly also to add bac…
dirtyshab Aug 9, 2024
1ac8336
fixes cw2981 extension query msg
dirtyshab Aug 9, 2024
2d0420f
fix cw2981 entry mod
dirtyshab Aug 9, 2024
501bfcf
adds query OwnersOf - gets balances of owners of a token id, and also…
dirtyshab Aug 16, 2024
76a30e0
error instead of take min when transferring tokens with amount > than…
dirtyshab Aug 16, 2024
76700c1
Merge branch 'main' of github.com:CosmWasm/cw-nfts into cw1155
dirtyshab Aug 23, 2024
58e692b
bump rust version in ci
dirtyshab Aug 23, 2024
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
Prev Previous commit
Next Next commit
fix: circle ci lint
  • Loading branch information
dirtyshab committed May 7, 2024
commit 68960bb4640132885c29b7520b73b5f10e887288
30 changes: 15 additions & 15 deletions contracts/cw1155-base/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ where
info,
} = env;

let from = &if let Some(from) = from {
let from = if let Some(from) = from {
deps.api.addr_validate(&from)?
} else {
info.sender.clone()
};
let to = deps.api.addr_validate(&to)?;

let balance_update =
self.verify_approval(deps.storage, &env, &info, from, &token_id, amount)?;
self.verify_approval(deps.storage, &env, &info, &from, &token_id, amount)?;

let mut rsp = Response::default();

Expand Down Expand Up @@ -267,14 +267,14 @@ where
info,
} = env;

let from = &if let Some(from) = from {
let from = if let Some(from) = from {
deps.api.addr_validate(&from)?
} else {
info.sender.clone()
};
let to = deps.api.addr_validate(&to)?;

let batch = self.verify_approvals(deps.storage, &env, &info, from, batch)?;
let batch = self.verify_approvals(deps.storage, &env, &info, &from, batch)?;

let mut rsp = Response::default();
let event = self.update_balances(
Expand Down Expand Up @@ -314,25 +314,25 @@ where
env,
} = env;

let from = &if let Some(from) = from {
let from = if let Some(from) = from {
deps.api.addr_validate(&from)?
} else {
info.sender.clone()
};

// whoever can transfer these tokens can burn
let balance_update =
self.verify_approval(deps.storage, &env, &info, from, &token_id, amount)?;
self.verify_approval(deps.storage, &env, &info, &from, &token_id, amount)?;

let mut rsp = Response::default();

let event = self.update_balances(
&mut deps,
&env,
Some(from.clone()),
Some(from),
None,
vec![TokenAmount {
token_id: token_id.to_string(),
token_id,
amount: balance_update.amount,
}],
)?;
Expand All @@ -353,16 +353,16 @@ where
env,
} = env;

let from = &if let Some(from) = from {
let from = if let Some(from) = from {
deps.api.addr_validate(&from)?
} else {
info.sender.clone()
};

let batch = self.verify_approvals(deps.storage, &env, &info, from, batch)?;
let batch = self.verify_approvals(deps.storage, &env, &info, &from, batch)?;

let mut rsp = Response::default();
let event = self.update_balances(&mut deps, &env, Some(from.clone()), None, batch)?;
let event = self.update_balances(&mut deps, &env, Some(from), None, batch)?;
rsp = rsp.add_event(event);

Ok(rsp)
Expand Down Expand Up @@ -549,17 +549,17 @@ where
// remove token approvals
for (operator, approval) in self
.token_approves
.prefix((&token_id, from))
.prefix((token_id, from))
.range(deps.storage, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()?
{
if approval.is_expired(env) || approval.amount <= *amount {
self.token_approves
.remove(deps.storage, (&token_id, &from, &operator));
.remove(deps.storage, (token_id, from, &operator));
} else {
self.token_approves.update(
deps.storage,
(&token_id, &from, &operator),
(token_id, from, &operator),
|prev| -> StdResult<_> {
let mut new_approval = prev.unwrap();
new_approval.amount = new_approval.amount.checked_sub(*amount)?;
Expand Down Expand Up @@ -671,7 +671,7 @@ where
) -> Option<TokenApproval> {
match self
.token_approves
.load(storage, (&token_id, owner, operator))
.load(storage, (token_id, owner, operator))
{
Ok(approval) => {
if !approval.is_expired(env) {
Expand Down
6 changes: 3 additions & 3 deletions contracts/cw1155-base/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use schemars::JsonSchema;
use cosmwasm_schema::cw_serde;
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde::Serialize;
use std::marker::PhantomData;

use cosmwasm_std::{Addr, CustomMsg, StdError, StdResult, Storage, Uint128};
Expand Down Expand Up @@ -128,7 +128,7 @@ where
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[cw_serde]
pub struct TokenInfo<T> {
/// Metadata JSON Schema
pub token_uri: Option<String>,
Expand Down
9 changes: 3 additions & 6 deletions packages/cw1155/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use cosmwasm_schema::cw_serde;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};

use cosmwasm_std::{Binary, Env, Uint128};
use cw_utils::Expiration;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[cw_serde]
pub struct Cw1155InstantiateMsg {
/// Name of the token contract
pub name: String,
Expand All @@ -23,8 +21,7 @@ pub struct Cw1155InstantiateMsg {
/// This is like Cw1155ExecuteMsg but we add a Mint command for a minter
/// to make this stand-alone. You will likely want to remove mint and
/// use other control logic in any contract that inherits this.
#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
pub enum Cw1155ExecuteMsg<T> {
// cw1155
/// BatchSendFrom is a base message to move multiple types of tokens in batch,
Expand Down Expand Up @@ -101,7 +98,7 @@ pub enum Cw1155ExecuteMsg<T> {
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[cw_serde]
pub struct Cw1155MintMsg<T> {
pub token_id: String,
/// The amount of the newly minted tokens
Expand Down
21 changes: 10 additions & 11 deletions packages/cw1155/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use cosmwasm_std::{Addr, Uint128};
use cw_ownable::cw_ownable_query;
Expand Down Expand Up @@ -93,47 +92,47 @@ pub enum Cw1155QueryMsg<Q: JsonSchema> {
Extension { msg: Q },
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct BalanceResponse {
pub balance: Uint128,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct AllBalancesResponse {
pub balances: Vec<Balance>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[cw_serde]
pub struct Balance {
pub token_id: String,
pub owner: Addr,
pub amount: Uint128,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct BatchBalanceResponse {
pub balances: Vec<Uint128>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct NumTokensResponse {
pub count: Uint128,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct Approval {
/// Account that can transfer/send the token
pub spender: String,
/// When the Approval expires (maybe Expiration::never)
pub expires: Expiration,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct ApprovedForAllResponse {
pub operators: Vec<Approval>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct IsApprovedForAllResponse {
pub approved: bool,
}
Expand All @@ -144,15 +143,15 @@ pub struct AllTokenInfoResponse<T> {
pub info: TokenInfoResponse<T>,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct TokenInfoResponse<T> {
/// Should be a url point to a json file
pub token_uri: Option<String>,
/// You can add any custom metadata here when you extend cw1155-base
pub extension: T,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
#[cw_serde]
pub struct TokensResponse {
/// Contains all token_ids in lexicographical ordering
/// If there are more than `limit`, use `start_from` in future queries
Expand Down
13 changes: 4 additions & 9 deletions packages/cw1155/src/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::TokenAmount;
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_json_binary, Binary, CosmosMsg, StdResult, Uint128, WasmMsg};

/// Cw1155ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
pub struct Cw1155ReceiveMsg {
/// The account that executed the send message
pub operator: String,
Expand Down Expand Up @@ -37,8 +34,7 @@ impl Cw1155ReceiveMsg {
}

/// Cw1155BatchReceiveMsg should be de/serialized under `BatchReceive()` variant in a ExecuteMsg
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
pub struct Cw1155BatchReceiveMsg {
pub operator: String,
pub from: Option<String>,
Expand Down Expand Up @@ -66,8 +62,7 @@ impl Cw1155BatchReceiveMsg {
}

// This is just a helper to properly serialize the above message
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, JsonSchema, Debug)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
enum ReceiverExecuteMsg {
Receive(Cw1155ReceiveMsg),
BatchReceive(Cw1155BatchReceiveMsg),
Expand Down