-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7108baa
commit 0dea9c2
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"math" | ||
"net/http" | ||
) | ||
|
||
type Chain struct { | ||
ChainID string `json:"chain_id"` | ||
Params Params `json:"params"` | ||
} | ||
|
||
type Params struct { | ||
EstimatedApr float64 `json:"estimated_apr"` | ||
} | ||
|
||
type APRResponse struct { | ||
Chains []ChainAPR `json:"chains"` | ||
} | ||
|
||
type ChainAPR struct { | ||
ChainID string `json:"chain_id"` | ||
APR float64 `json:"apr"` | ||
} | ||
|
||
func getAPRquery(baseurl string, chainname string) (ChainAPR, error) { | ||
url := baseurl + chainname | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return ChainAPR{}, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
var result map[string]json.RawMessage | ||
err = json.NewDecoder(resp.Body).Decode(&result) | ||
if err != nil { | ||
return ChainAPR{}, err | ||
} | ||
|
||
var chain Chain | ||
err = json.Unmarshal(result["chain"], &chain) | ||
if err != nil { | ||
return ChainAPR{}, err | ||
} | ||
|
||
if chainname != "quicksilver" { | ||
feeadjustedAPR := (chain.Params.EstimatedApr) * (0.965) | ||
compoundedAPR := math.Pow(1+feeadjustedAPR/121.66, 121.66) - 1 | ||
return ChainAPR{ChainID: chain.ChainID, APR: compoundedAPR}, nil | ||
} | ||
return ChainAPR{ChainID: chain.ChainID, APR: chain.Params.EstimatedApr}, nil | ||
|
||
} |