package cust0dy_core // Deterministic basis-point fee math. One basis point is 1/100 of a percent. // // The marketplace charges two fees, both taken out of the buyer's locked // payment at settlement time: // // seller fee 500 bps (5.0%), deducted from the agreed price // buyer fee 250 bps (2.5%), added on top of the agreed price // // For offers, the maker locks an all-in amount and the buyer fee is waived; // see the realm's AcceptOffer for the exact rule. const ( SellerFeeBps int64 = 500 BuyerFeeBps int64 = 250 bpsDenominator int64 = 10000 ) // FeeFor returns amount * bps / 10000, rounded down. It never returns more // than amount. func FeeFor(amount, bps int64) int64 { if amount <= 0 || bps <= 0 { return 0 } // Multiply first; a price that overflows int64 when multiplied by 500 // is far outside any sane trade, and the realm rejects it at listing. fee := amount * bps / bpsDenominator if fee > amount { return amount } return fee } // BuyerTotal is what a buyer must lock to buy at the listed price: // price + buyer fee. func BuyerTotal(price int64) int64 { return price + FeeFor(price, BuyerFeeBps) } // SellerPayout is what the seller receives at settlement: price - seller fee. func SellerPayout(price int64) int64 { return price - FeeFor(price, SellerFeeBps) } // PlatformCut is what the marketplace keeps from a full-price buy: // the buyer fee plus the seller fee. func PlatformCut(price int64) int64 { return FeeFor(price, BuyerFeeBps) + FeeFor(price, SellerFeeBps) } // MaxPrice is the largest accepted price. It keeps amount*bps comfortably // inside int64 and bounds nonsense listings. const MaxPrice int64 = 1 << 50