Skip to content

Commit

Permalink
community-open: add registration cost
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Mar 21, 2024
1 parent c6dd046 commit 64ddcda
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion contracts/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/community-open/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "community-open"
version = "5.0.0"
version = "1.0.0"
authors = ["Robert Zaremba 'https://zaremba.ch/'"]
edition = { workspace = true }
repository = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/community-open/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Only class admin can add or revoke minting authority.

Anyone can become an issuer by acquiring permissionlessly a class. Class is just an ID associated to the account that acquired it. Any account can acquire many classes.

Once you acquire a class, you can add more admins and add or remove minters, update class metadata. A minter will have a permission to mint on your behalves, but won't be able to add nor remove other minters.
Once you acquire a class, you can add more admins and add or remove minters, update [class metadata](https://github.com/near/NEPs/blob/master/neps/nep-0393.md#smart-contract-interface). A minter will have a permission to mint on your behalves, but won't be able to add nor remove other minters.

To prevent spam, a payment is required, that is defined by the `const REGISTRATION_COST`.

Expand Down
34 changes: 24 additions & 10 deletions contracts/community-open/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
use near_sdk::collections::{LazyOption, LookupMap};
use near_sdk::{env, near_bindgen, require, AccountId, PanicOnDefault, Promise};
use near_sdk::{env, near_bindgen, require, AccountId, PanicOnDefault, Promise, ONE_NEAR};

use cost::{calculate_iah_mint_gas, calculate_mint_gas, mint_deposit};
use sbt::*;
Expand All @@ -15,7 +15,7 @@ pub mod migrate;
mod storage;

const MIN_TTL: u64 = 86_400_000; // 24 hours in miliseconds
const REGISTRATION_COST: u128 = 1;
const MILI_NEAR: u128 = ONE_NEAR / 1000;

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)]
Expand All @@ -28,6 +28,7 @@ pub struct Contract {
/// contract metadata
pub metadata: LazyOption<ContractMetadata>,
pub class_metadata: LookupMap<ClassId, ClassMetadata>,
pub registration_cost: u64, // cost in milinear
}

// Implement the contract structure
Expand All @@ -42,6 +43,7 @@ impl Contract {
registry,
metadata: LazyOption::new(StorageKey::ContractMetadata, Some(&metadata)),
class_metadata: LookupMap::new(StorageKey::ClassMetadata),
registration_cost: 100, // 0.1 Near
}
}

Expand Down Expand Up @@ -309,7 +311,10 @@ impl Contract {
);
require!(
MIN_TTL <= max_ttl,
format!("deposit must be at least {}yNEAR", REGISTRATION_COST)
format!(
"deposit must be at least {}yNEAR",
self.registration_cost as u128 * MILI_NEAR
)
);
let cls = self.next_class;
self.next_class += 1;
Expand Down Expand Up @@ -352,15 +357,21 @@ impl Contract {
/// admin: revokes `class` minting for `minter`.
/// Must be called by a class admin, panics otherwise.
#[handle_result]
pub fn remove_minter(
pub fn remove_minters(
&mut self,
class: ClassId,
minter: AccountId,
minters: Vec<AccountId>,
#[allow(unused_variables)] memo: Option<String>,
) -> Result<(), Error> {
let mut c = self.class_info_admin(class)?;
if let Some(idx) = c.minters.iter().position(|x| x == &minter) {
c.minters.swap_remove(idx);
let mut ok = false;
for m in minters {
if let Some(idx) = c.minters.iter().position(|x| x == &m) {
c.minters.swap_remove(idx);
ok = true;
}
}
if ok {
self.classes.insert(&class, &c);
}
Ok(())
Expand Down Expand Up @@ -629,7 +640,7 @@ mod tests {
let (mut ctx, mut ctr) = setup(&admin(), None);

matches!(
ctr.remove_minter(2, auth(1), None),
ctr.remove_minters(2, vec! {auth(1)}, None),
Err(Error::ClassNotFound)
);

Expand All @@ -638,7 +649,7 @@ mod tests {
ctr.add_minters(1, vec![auth(2), auth(3), auth(4)], None)?;
ctr.add_minters(2, vec![auth(2)], None)?;

ctr.remove_minter(1, auth(2), None)?;
ctr.remove_minters(1, vec![auth(2)], None)?;

assert_eq!(
ctr.class_minter(1),
Expand All @@ -651,7 +662,10 @@ mod tests {

ctx.predecessor_account_id = alice();
testing_env!(ctx.clone());
matches!(ctr.remove_minter(1, auth(1), None), Err(Error::NotAdmin));
matches!(
ctr.remove_minters(1, vec![auth(1)], None),
Err(Error::NotAdmin)
);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/community-open/src/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct OldContract {
pub registry: AccountId,
pub metadata: LazyOption<ContractMetadata>,
pub class_metadata: LookupMap<ClassId, ClassMetadata>,
pub registration_cost: u64,
}

// migration to community-open/v...
Expand All @@ -28,6 +29,7 @@ impl Contract {
registry: old_state.registry,
metadata: old_state.metadata,
class_metadata: old_state.class_metadata,
registration_cost: old_state.registration_cost,
}
}
}

0 comments on commit 64ddcda

Please sign in to comment.