Skip to content

Commit

Permalink
Require minimum storage stake
Browse files Browse the repository at this point in the history
  • Loading branch information
tifrel committed Apr 20, 2022
1 parent c2af047 commit b0fceab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mintbase-deps/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub const ROYALTY_UPPER_LIMIT: u32 = 5000;
/// Maximum payout (royalties + splits) participants to process
pub const MAX_LEN_PAYOUT: u32 = 50;

// pub const MINIMUM_CUSHION: near_sdk::Balance = 5 * 10u128.pow(23);
/// Minimum storage stake required to allow updates
pub const MINIMUM_FREE_STORAGE_STAKE: near_sdk::Balance = 50 * YOCTO_PER_BYTE;

//?

Expand Down
16 changes: 15 additions & 1 deletion store/src/minting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use mintbase_deps::common::{
SplitOwners,
TokenMetadata,
};
use mintbase_deps::constants::MAX_LEN_PAYOUT;
use mintbase_deps::constants::{
MAX_LEN_PAYOUT,
MINIMUM_FREE_STORAGE_STAKE,
};
use mintbase_deps::logging::{
log_grant_minter,
log_nft_batch_mint,
Expand Down Expand Up @@ -136,6 +139,17 @@ impl MintbaseStore {
self.tokens_per_owner.insert(&owner_id, &owned_set);

let minted = self.tokens_minted;

// check if sufficient storage stake (e.g. 0.5 NEAR) remains
let used_storage_stake: Balance = env::storage_usage() as u128 * env::storage_byte_cost();
let free_storage_stake: Balance = env::account_balance() - used_storage_stake;
near_assert!(
free_storage_stake > MINIMUM_FREE_STORAGE_STAKE,
"A minimum of {} yoctoNEAR is required as free contract balance to allow updates (currently: {})",
MINIMUM_FREE_STORAGE_STAKE,
free_storage_stake
);

log_nft_batch_mint(
minted - num_to_mint,
minted - 1,
Expand Down

0 comments on commit b0fceab

Please sign in to comment.