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

Add CW-2981 #414

Closed
wants to merge 4 commits into from
Closed
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
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ workflows:
- contract_cw20_merkle_airdrop
- contract_cw721_base
- contract_cw1155_base
- contract_cw2981_base
- package_controllers
- package_cw0
- package_cw1
Expand All @@ -27,6 +28,7 @@ workflows:
- package_cw20
- package_cw721
- package_cw1155
- package_cw2981
- package_multi_test
- package_storage_plus
- lint
Expand Down Expand Up @@ -584,6 +586,42 @@ jobs:
- target
key: cargocache-cw1155-base-rust:1.53.0-{{ checksum "~/project/Cargo.lock" }}

contract_cw2981_base:
docker:
- image: rust:1.53.0
working_directory: ~/project/contracts/cw2981-base
steps:
- checkout:
path: ~/project
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- cargocache-cw2981-base-rust:1.53.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Unit Tests
environment:
RUST_BACKTRACE: 1
command: cargo unit-test --locked
- run:
name: Build and run schema generator
command: cargo schema --locked
- run:
name: Ensure checked-in schemas are up-to-date
command: |
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
- save_cache:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-cw2981-base-rust:1.53.0-{{ checksum "~/project/Cargo.lock" }}

package_controllers:
docker:
- image: rust:1.53.0
Expand Down Expand Up @@ -883,6 +921,44 @@ jobs:
- target
key: cargocache-v2-cw1155:1.53.0-{{ checksum "~/project/Cargo.lock" }}


package_cw2981:
docker:
- image: rust:1.53.0
working_directory: ~/project/packages/cw2981
steps:
- checkout:
path: ~/project
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version; rustup target list --installed
- restore_cache:
keys:
- cargocache-v2-cw2981:1.53.0-{{ checksum "~/project/Cargo.lock" }}
- run:
name: Build library for native target
command: cargo build --locked
- run:
name: Run unit tests
command: cargo test --locked
- run:
name: Build and run schema generator
command: cargo schema --locked
- run:
name: Ensure schemas are up-to-date
command: |
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
- save_cache:
paths:
- /usr/local/cargo/registry
- target
key: cargocache-v2-cw2981:1.53.0-{{ checksum "~/project/Cargo.lock" }}

lint:
docker:
- image: rust:1.53.0
Expand Down
105 changes: 105 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions contracts/cw2981-base/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example schema"
38 changes: 38 additions & 0 deletions contracts/cw2981-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "cw2981-base"
version = "0.8.1"
authors = ["Alex Lynham <[email protected]>"]
edition = "2018"
description = "Basic implementation of royalties for cw721 NFTs with token level royalties"
license = "Apache-2.0"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"artifacts/*",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[dependencies]
cw0 = { path = "../../packages/cw0", version = "0.8.1" }
cw2 = { path = "../../packages/cw2", version = "0.8.1" }
cw721 = { path = "../../packages/cw721", version = "0.8.1" }
cw721-base = { path = "../../contracts/cw721-base", version = "0.8.1", features = ["library"] }
cw2981 = { path = "../../packages/cw2981", version = "0.8.1" }
cw-storage-plus = { path = "../../packages/storage-plus", version = "0.8.1" }
cosmwasm-std = { version = "0.16.0" }
schemars = "0.8.1"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.23" }
percentage = { version = "0.1.0"}

[dev-dependencies]
cosmwasm-schema = { version = "0.16.0" }
21 changes: 21 additions & 0 deletions contracts/cw2981-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# CW-2981 Token-level Royalties

An example of porting EIP-2981 to implement royalties at a token mint level.

All of the CW-721 logic and behaviour you would expect for an NFT is implemented as normal, but additionally at mint time, royalty information can be attached to a token.

Exposes two new query message types:

```rust
// Should be called on sale to see if royalties are owed
// by the marketplace selling the NFT.
// See https://eips.ethereum.org/EIPS/eip-2981
RoyaltyInfo {
token_id: String,
// the denom of this sale must also be the denom returned by RoyaltiesInfoResponse
sale_price: u128,
},

// Called against the contract to signal that CW-2981 is implemented
CheckRoyalties {},
```
29 changes: 29 additions & 0 deletions contracts/cw2981-base/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};

use cw721::{
AllNftInfoResponse, ApprovedForAllResponse, ContractInfoResponse, NftInfoResponse,
NumTokensResponse, OwnerOfResponse, TokensResponse,
};
use cw721_base::msg::{ExecuteMsg, InstantiateMsg, MinterResponse, QueryMsg};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(AllNftInfoResponse), &out_dir);
export_schema(&schema_for!(ApprovedForAllResponse), &out_dir);
export_schema(&schema_for!(ContractInfoResponse), &out_dir);
export_schema(&schema_for!(MinterResponse), &out_dir);
export_schema(&schema_for!(NftInfoResponse), &out_dir);
export_schema(&schema_for!(NumTokensResponse), &out_dir);
export_schema(&schema_for!(OwnerOfResponse), &out_dir);
export_schema(&schema_for!(TokensResponse), &out_dir);
}
Loading