Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

fees.gno

1.63 Kb · 54 lines
 1package cust0dy_core
 2
 3// Deterministic basis-point fee math. One basis point is 1/100 of a percent.
 4//
 5// The marketplace charges two fees, both taken out of the buyer's locked
 6// payment at settlement time:
 7//
 8//	seller fee 500 bps (5.0%), deducted from the agreed price
 9//	buyer fee  250 bps (2.5%), added on top of the agreed price
10//
11// For offers, the maker locks an all-in amount and the buyer fee is waived;
12// see the realm's AcceptOffer for the exact rule.
13
14const (
15	SellerFeeBps int64 = 500
16	BuyerFeeBps  int64 = 250
17	bpsDenominator int64 = 10000
18)
19
20// FeeFor returns amount * bps / 10000, rounded down. It never returns more
21// than amount.
22func FeeFor(amount, bps int64) int64 {
23	if amount <= 0 || bps <= 0 {
24		return 0
25	}
26	// Multiply first; a price that overflows int64 when multiplied by 500
27	// is far outside any sane trade, and the realm rejects it at listing.
28	fee := amount * bps / bpsDenominator
29	if fee > amount {
30		return amount
31	}
32	return fee
33}
34
35// BuyerTotal is what a buyer must lock to buy at the listed price:
36// price + buyer fee.
37func BuyerTotal(price int64) int64 {
38	return price + FeeFor(price, BuyerFeeBps)
39}
40
41// SellerPayout is what the seller receives at settlement: price - seller fee.
42func SellerPayout(price int64) int64 {
43	return price - FeeFor(price, SellerFeeBps)
44}
45
46// PlatformCut is what the marketplace keeps from a full-price buy:
47// the buyer fee plus the seller fee.
48func PlatformCut(price int64) int64 {
49	return FeeFor(price, BuyerFeeBps) + FeeFor(price, SellerFeeBps)
50}
51
52// MaxPrice is the largest accepted price. It keeps amount*bps comfortably
53// inside int64 and bounds nonsense listings.
54const MaxPrice int64 = 1 << 50