Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

fee.gno

0.49 Kb · 21 lines
 1package fee
 2
 3const Denom int64 = 10000
 4
 5// ProtocolFee is (price * bps) / Denom without overflowing int64 on price*bps.
 6func ProtocolFee(price, bps int64) int64 {
 7	if price < 0 {
 8		panic("fee: negative price")
 9	}
10	if bps < 0 || bps > Denom {
11		panic("fee: bps")
12	}
13	q := price / Denom
14	r := price % Denom
15	return q*bps + r*bps/Denom
16}
17
18// SellerProceeds is the ugnot the seller receives after the protocol fee.
19func SellerProceeds(price, bps int64) int64 {
20	return price - ProtocolFee(price, bps)
21}