rules.go32 lines, 1.5 KB
| 1 | package risk |
| 2 | |
| 3 | import "time" |
| 4 | |
| 5 | // Limits are the rules' thresholds, with amounts in US cents. They come from |
| 6 | // the configuration: tuning them is the risk team's job, not a release. |
| 7 | type Limits struct { |
| 8 | MaxCount int // transfers per CountWindow: one more is denied |
| 9 | CountWindow time.Duration // like ten minutes |
| 10 | MaxAmount int64 // sent per AmountWindow: more needs a review |
| 11 | AmountWindow time.Duration // like a day: at least CountWindow |
| 12 | ReviewAbove int64 // one transfer this big needs a review |
| 13 | FirstTimeAbove int64 // the most a new wallet, or a new recipient, gets without one |
| 14 | NewWalletAge time.Duration // a wallet younger than this is new |
| 15 | } |
| 16 | |
| 17 | // Rules returns our rules, in the order they run, with thresholds from l. |
| 18 | func Rules(l Limits) []Rule { |
| 19 | return []Rule{ |
| 20 | Check{"receiver_frozen", Deny, func(s Signals) bool { return s.ReceiverFrozen }}, |
| 21 | Check{"velocity_count", Deny, func(s Signals) bool { return s.Recent.Count > l.MaxCount }}, |
| 22 | Check{"velocity_amount", Review, func(s Signals) bool { return s.Recent.Amount > l.MaxAmount }}, |
| 23 | Check{"velocity_unknown", Review, func(s Signals) bool { return s.RecentUnknown }}, |
| 24 | Check{"large_amount", Review, func(s Signals) bool { return s.Amount >= l.ReviewAbove }}, |
| 25 | Check{"new_wallet", Review, func(s Signals) bool { |
| 26 | return s.ReceiverAge < l.NewWalletAge && s.Amount > l.FirstTimeAbove |
| 27 | }}, |
| 28 | Check{"new_recipient", Review, func(s Signals) bool { |
| 29 | return !s.PaidBefore && s.Amount > l.FirstTimeAbove |
| 30 | }}, |
| 31 | } |
| 32 | } |