Newbie questions about the BNS smart contract

I’m a total newb to Clarity, so could somebody explain to me what the NAMESPACE_PRICE_TIERS are?

My guess is that the tiers are priced based on the length of the TLD (namespace):

;; Price tables
(define-constant NAMESPACE_PRICE_TIERS (list
  u640000000000
  u64000000000 u64000000000 
  u6400000000 u6400000000 u6400000000 u6400000000 
  u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000 u640000000))

Also, when somebody pre-registers a .btc domain, the STX used in that goes where? Is it just burned?

Yup, that’s correct.

Yup, it gets burned. It happens at this line: stacks-blockchain/bns.clar at master · stacks-network/stacks-blockchain · GitHub

1 Like

I still can’t figure it out.

So the cost of a namespace is dervied from get-namespace-price

(define-read-only (get-namespace-price (namespace (buff 20)))
  (let ((namespace-len (len namespace)))
    (asserts!
      (> namespace-len u0)
      (err ERR_NAMESPACE_BLANK))
    (ok (unwrap-panic
      (element-at NAMESPACE_PRICE_TIERS (min u7 (- namespace-len u1)))))))

My read is if you want to register .foobar as a namespace, it’s length = 6, so… I can’t even find “min” in the clarity language reference, is it “the smaller of” or “minus” ?

What is in u7?

And then once you come away from that, and you have an index into NAMESPACE_PRICE_TIERS then I imagine those are all unsigned ints … with what values?

I guess these are all very basic questions and I apologize for it. I’m totally inexperienced in Clarity (or any other smart contract language)

min is a function in BNS: stacks-blockchain/bns.clar at master · stacks-network/stacks-blockchain · GitHub

(min u7 (- namespace-len u1)) takes the namespace length (i.e. for foobar, this is 6), subtracts 1 to get 5, and then takes the minimum of 5 and 7 to get 5 (note that u7 means “unsigned 7” – i.e. it has type uint, not int). So, this whole expression evaluates to u5 in Clarity.

(element-at NAMESPACE_PRICE_TIERS u5) evaluates to (some u6400000000). This is the 6th element of the list NAMESPACE_PRICE_TIERS (note that list elements are 0-indexed – you start counting at 0).

(unwrap-panic (some u6400000000)) finally evaluates to u6400000000. This is necessary because (element-at ...) handles the case where the index (i.e. u5) is outside the length of the list by returning none. This should never happen, so we use (unwrap-panic) to get the inner u6400000000 out of the (some ...) expression (note that (unwrap-panic none) will cause the transaction to abort).

Hope this helps! Also, have you seen the Clarity book? https://book.clarity-lang.org/

I came across that book, so I will dig into it.

Ok, I sort of get what you are telling me, however, u6400000000 is just an unsigned int, right? Where does the actual value get assigned to it?

In other words, I still can’t figure out where you calculate what it costs to register a namespace of varying lengths.

(This is more of a curiosity to me, just wait until I start trying to figure out how to register actual .btc names :slight_smile:

u6400000000 is the cost. It’s in microSTX, so divide by 1,000,000 to get the cost in STX (6,400 STX). The system reasons about STX in microSTX, much like how the Bitcoin code reasons about BTC in satoshis.

Ok, thanks for that.

So would price tier


u64000000000 u64000000000

be 6,400 STX multiplied by 6,400 STX? Or Plus?