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:
parent
f1cf4c7375
commit
de07f873ab
|
@ -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.))
|
||||||
|
|
||||||
|
|
|
@ -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))))
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)))
|
||||||
|
|
Loading…
Reference in New Issue