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
|
||||
[]
|
||||
(-> (:gas-price env 2000000000)
|
||||
(-> (:gas-price env 20000000000) ;; 20 gwei default
|
||||
str
|
||||
BigInteger.))
|
||||
|
||||
|
|
|
@ -164,4 +164,4 @@
|
|||
(into {}
|
||||
(map (fn [addr] (let [tla (first (token-data/token-info-by-addr addr))]
|
||||
(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.bounties :as db-bounties]
|
||||
[commiteth.bounties :as bounties]
|
||||
[commiteth.util.crypto-fiat-value :as fiat-util]
|
||||
[commiteth.util.util :refer [decimal->str]]
|
||||
[clojure.tools.logging :as log]
|
||||
[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]
|
||||
(do
|
||||
(log/debug "run-periodic-tasks" time)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns commiteth.util.crypto-fiat-value
|
||||
(:require [clj-http.client :as http]
|
||||
[clojure.string :as str]
|
||||
[clojure.data.json :as json]))
|
||||
|
||||
|
||||
|
@ -17,9 +18,10 @@
|
|||
|
||||
|
||||
(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]
|
||||
(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)))
|
||||
bounty)))
|
||||
|
|
Loading…
Reference in New Issue