Search Apps Documentation Source Content File Folder Download Copy Actions Download

split.gno

0.93 Kb · 32 lines
 1package memba_market_core
 2
 3// SplitProceeds computes the three-way split of a sale price into platform fee,
 4// creator royalty, and seller proceeds. `royaltyAmount` is the actual amount from
 5// the collection's RoyaltyInfo (NOT bps); it is floored at 0 and clamped to
 6// MaxRoyaltyBPS of price (defense-in-depth). Identical to memba_nft_market_v3's
 7// splitProceeds — the conformance reference for every engine.
 8func SplitProceeds(price, royaltyAmount int64) (fee, royalty, seller int64) {
 9	if price < MinPrice {
10		panic("price below minimum")
11	}
12	if price > MaxPrice {
13		panic("price above maximum")
14	}
15	fee = price * FeeBPS / 10000
16	royalty = royaltyAmount
17	if royalty < 0 {
18		royalty = 0
19	}
20	maxRoy := price * MaxRoyaltyBPS / 10000
21	if royalty > maxRoy {
22		royalty = maxRoy
23	}
24	if fee+royalty >= price {
25		panic("fee plus royalty exceeds price")
26	}
27	seller = price - fee - royalty
28	if seller <= 0 {
29		panic("seller amount not positive")
30	}
31	return
32}