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

Fix series hashing and royalties #70

Merged
merged 6 commits into from
Mar 3, 2025
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
7 changes: 1 addition & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ jobs:
RUST_BACKTRACE: 1
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
uses: actions/checkout@v4
- name: Run integration test
run: cd integration-tests && cargo run --example integration-tests
- name: Market tests
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ publish = false
edition = "2021"

[dev-dependencies]
near-sdk = { version = "5.1.0", features = ["unit-testing"] }
near-workspaces = { version = "0.10.0", features = ["unstable"] }
near-sdk = { version = "5.4.0", features = ["unit-testing"] }
near-workspaces = { version = "0.14.1", features = ["unstable"] }
tokio = { version = "1.12.0", features = ["full"] }
serde_json = "1"

Expand Down
296 changes: 254 additions & 42 deletions integration-tests/src/tests.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions market-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }

[dev-dependencies]
near-sdk = { version = "5.1.0", features = ["unit-testing"] }
near-workspaces = { version = "0.10.0", features = ["unstable"] }
near-sdk = { version = "5.4.0", features = ["unit-testing"] }
near-workspaces = { version = "0.14.1", features = ["unstable"] }
tokio = { version = "1.12.0", features = ["full"] }
serde_json = "1"

Expand Down
2 changes: 1 addition & 1 deletion nft-contract-approval/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }
serde_json = "1.0.113"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion nft-contract-basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion nft-contract-events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }
serde_json = "1.0.113"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion nft-contract-royalty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }
serde_json = "1.0.113"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion nft-contract-skeleton/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }

[profile.release]
codegen-units = 1
Expand Down
6 changes: 3 additions & 3 deletions nft-series/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = { version = "5.1.0", features = ["legacy"] }
near-sdk = { version = "5.4.0", features = ["legacy"] }
serde_json = "1.0.113"

[dev-dependencies]
near-sdk = { version = "5.1.0", features = ["unit-testing"] }
near-workspaces = { version = "0.10.0", features = ["unstable"] }
near-sdk = { version = "5.4.0", features = ["unit-testing"] }
near-workspaces = { version = "0.14.1", features = ["unstable"] }
tokio = { version = "1.12.0", features = ["full"] }
serde_json = "1"

Expand Down
32 changes: 23 additions & 9 deletions nft-series/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Contract {
id: U64,
metadata: TokenMetadata,
royalty: Option<HashMap<AccountId, u32>>,
price: Option<NearToken>
price: Option<NearToken>,
) {
// Measure the initial storage being used on the contract
let initial_storage_usage = env::storage_usage();
Expand All @@ -25,6 +25,16 @@ impl Contract {
"only approved creators can add a type"
);

// Check that the total royalty amount does not exceed 100%
if !royalty.is_none() {
let mut total_royalty = 0;

for (_, v) in royalty.clone().unwrap().iter() {
total_royalty += *v;
}
require!(total_royalty <= 100, "total royalty can't exceed 100%");
}

// Insert the series and ensure it doesn't already exist
require!(
self.series_by_id
Expand All @@ -35,10 +45,7 @@ impl Contract {
royalty,
tokens: UnorderedSet::new(StorageKey::SeriesByIdInner {
// We get a new unique prefix for the collection
account_id_hash: hash_account_id(&format!(
"{}{}",
id.0, caller
)),
account_id_hash: hash_account_id(&format!("{}.{}", id.0, caller)),
}),
owner_id: caller,
price: price.map(|p| p),
Expand All @@ -64,12 +71,15 @@ impl Contract {

// Get the series and how many tokens currently exist (edition number = cur_len + 1)
let mut series = self.series_by_id.get(&id.0).expect("Not a series");

// Check if the series has a price per token. If it does, ensure the caller has attached at least that amount
let mut price_per_token = NearToken::from_yoctonear(0);
let mut price_per_token = NearToken::from_yoctonear(0);
if let Some(price) = series.price {
price_per_token = price;
require!(env::attached_deposit().ge(&price_per_token), "Need to attach at least enough to cover price");
require!(
env::attached_deposit().ge(&price_per_token),
"Need to attach at least enough to cover price"
);
// If the series doesn't have a price, ensure the caller is an approved minter.
} else {
// Ensure the caller is an approved minter
Expand Down Expand Up @@ -140,7 +150,11 @@ impl Contract {

// If there's some price for the token, we'll payout the series owner. Otherwise, refund the excess deposit for storage to the caller
if price_per_token.gt(&NearToken::from_yoctonear(0)) {
payout_series_owner(required_storage_in_bytes.into(), price_per_token, series.owner_id);
payout_series_owner(
required_storage_in_bytes.into(),
price_per_token,
series.owner_id,
);
} else {
refund_deposit(required_storage_in_bytes.into());
}
Expand Down
Loading