Skip to content Search Apps Documentation Source Content 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.

fee.gno

0.88 Kb · 33 lines
 1package otc
 2
 3const bpsDenominator = 10000
 4
 5// feeOf is bps of amount, rounded down (F1). Split so that a large amount
 6// cannot overflow on the multiplication: bps is at most feeCapBps, so both
 7// terms stay far below int64 max.
 8func feeOf(amount, bps int64) int64 {
 9	if amount <= 0 || bps <= 0 {
10		return 0
11	}
12	return amount/bpsDenominator*bps + amount%bpsDenominator*bps/bpsDenominator
13}
14
15// feeFor picks the fee a new offer on tokenKey is created with (F4, F6).
16func feeFor(tokenKey string) int64 {
17	if gnomicFeeOn && tokenKey == gnomicKey {
18		return gnomicFee
19	}
20	return feeBps
21}
22
23// addSat adds two non-negative totals without wrapping (S5). The totals are
24// statistics, not money: one that stops at the ceiling is better than one
25// that turns negative.
26func addSat(a, b int64) int64 {
27	if b > 0 && a > maxInt64-b {
28		return maxInt64
29	}
30	return a + b
31}
32
33const maxInt64 = int64(9223372036854775807)