Get combined balances + total USD value for a bounty

* add function for getting balance of tokens and ETH in a bounty
  contract and total USD value. This data will be kept in sync with
  the DB
* change default gas price 2 -> 20 gwei (still configurable)
This commit is contained in:
Teemu Patja 2017-08-22 14:49:37 +03:00
parent f1cf4c7375
commit de07f873ab
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
4 changed files with 18 additions and 4 deletions

View File

@ -14,7 +14,7 @@
(defn gas-price (defn gas-price
[] []
(-> (:gas-price env 2000000000) (-> (:gas-price env 20000000000) ;; 20 gwei default
str str
BigInteger.)) BigInteger.))

View File

@ -164,4 +164,4 @@
(into {} (into {}
(map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))] (map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))]
(assert tla) (assert tla)
[tla {:balance (token-balance bounty-addr tla)}])) token-addresses)))) [tla (token-balance bounty-addr tla)])) token-addresses))))

View File

@ -6,6 +6,7 @@
[commiteth.db.issues :as issues] [commiteth.db.issues :as issues]
[commiteth.db.bounties :as db-bounties] [commiteth.db.bounties :as db-bounties]
[commiteth.bounties :as bounties] [commiteth.bounties :as bounties]
[commiteth.util.crypto-fiat-value :as fiat-util]
[commiteth.util.util :refer [decimal->str]] [commiteth.util.util :refer [decimal->str]]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[mount.core :as mount] [mount.core :as mount]
@ -197,6 +198,17 @@
(defn get-bounty-funds
"Get funds in given bounty contract.
Returns map of asset -> balance
+ key total-usd -> current total USD value for all funds"
[bounty-addr]
(let [token-balances (multisig/token-balances bounty-addr)
eth-balance (read-string (eth/get-balance-eth bounty-addr 4))]
(merge token-balances {:ETH eth-balance})))
(defn run-periodic-tasks [time] (defn run-periodic-tasks [time]
(do (do
(log/debug "run-periodic-tasks" time) (log/debug "run-periodic-tasks" time)

View File

@ -1,5 +1,6 @@
(ns commiteth.util.crypto-fiat-value (ns commiteth.util.crypto-fiat-value
(:require [clj-http.client :as http] (:require [clj-http.client :as http]
[clojure.string :as str]
[clojure.data.json :as json])) [clojure.data.json :as json]))
@ -17,9 +18,10 @@
(defn bounty-usd-value (defn bounty-usd-value
"Get current USD value of a bounty. bounty is a map of token-name to value" "Get current USD value of a bounty. bounty is a map of token-tla (keyword) to value"
[bounty] [bounty]
(reduce + (map (fn [[token value]] (reduce + (map (fn [[token value]]
(let [usd-price (get-token-usd-price token)] (let [tla (subs (str token) 1)
usd-price (get-token-usd-price tla)]
(* usd-price value))) (* usd-price value)))
bounty))) bounty)))