Auto-calculate fees in scala
(cherry picked from commit 24c2821)