Skip to content

Commit

Permalink
add error index
Browse files Browse the repository at this point in the history
  • Loading branch information
bonedaddy committed Apr 27, 2021
1 parent 90b9183 commit 4b4ac86
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 5 deletions.
5 changes: 5 additions & 0 deletions bclient/bclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (c *Client) NFTP() (IndexPool, error) {
return poolbindings.NewPoolbindings(NFTPTokenAddress, c.ec)
}

// ERROR returns an ERROR contract binding
func (c *Client) ERROR() (IndexPool, error) {
return poolbindings.NewPoolbindings(ERRORTokenAddress, c.ec)
}

// MCAPControllerAt returns the marketcap square root controller bindings for an IndexPool
func (c *Client) MCAPControllerAt(ip IndexPool) (*mcapscontroller.Mcapscontroller, error) {
cntrl, err := ip.GetController(nil)
Expand Down
3 changes: 3 additions & 0 deletions bclient/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
orcl5Addr = "0xD6cb2aDF47655B1bABdDc214d79257348CBC39A7"
degen10Addr = "0x126c121f99e1E211dF2e5f8De2d96Fa36647c855"
nftpAddr = "0x68bB81B3F67f7AAb5fd1390ECB0B8e1a806F2465"
errorAddr = "0xd3dEFf001ef67E39212F4973B617C2E684fa436C"
// DEFI5TokenAddress is the address of the DEFI5 token/pool contract
DEFI5TokenAddress = common.HexToAddress(defi5Addr)
// DEFI5StakingAddress is the address of the DEFI5 staking contract
Expand All @@ -37,6 +38,8 @@ var (
DEGEN10TokenAddress = common.HexToAddress(degen10Addr)
// NFTPTokenAddress is the address of the nftp token contract
NFTPTokenAddress = common.HexToAddress(nftpAddr)
// ERRORTokenAddress is the address of the error token contract
ERRORTokenAddress = common.HexToAddress(errorAddr)
// WETHTokenAddress is the address of the WETH token contract
WETHTokenAddress = common.HexToAddress("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
// DAITokenAddress is the address of the MCD (Multi Collateral DAI) contract
Expand Down
30 changes: 30 additions & 0 deletions bclient/uniswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ func (c *Client) NftpDaiPrice() (float64, error) {
return edF * oeF, nil
}

func (c *Client) ErrorDaiPrice() (float64, error) {
errorEthPrice, err := c.ExchangeAmount(utils.ToWei("1.0", 18), "error-eth")
if err != nil {
return 0, err
}
errorEthPriceDec := utils.ToDecimal(errorEthPrice, 18)
ethDaiPrice, err := c.EthDaiPrice()
if err != nil {
return 0, err
}
ethDaiPriceDec := utils.ToDecimal(utils.ToWei(ethDaiPrice.Int64(), 18), 18)
// derive the price of ERROR by getting the amount of ETH you would get from
// 1 ERROR token, and converting that into DAI
edF, _ := ethDaiPriceDec.Float64()
oeF, _ := errorEthPriceDec.Float64()
return edF * oeF, nil
}

// EthDaiPrice returns the price of ETH in terms of DAI
func (c *Client) EthDaiPrice() (*big.Int, error) {
reserves, err := c.Reserves("eth-dai")
Expand Down Expand Up @@ -172,6 +190,10 @@ func (c *Client) Reserves(pair string) (*uniswap.Reserve, error) {
return c.uc.GetReserves(NFTPTokenAddress, WETHTokenAddress)
case "eth-nftp":
return c.uc.GetReserves(WETHTokenAddress, NFTPTokenAddress)
case "error-eth":
return c.uc.GetReserves(ERRORTokenAddress, WETHTokenAddress)
case "eth-error":
return c.uc.GetReserves(WETHTokenAddress, ERRORTokenAddress)
default:
return nil, errors.New("unsupported pair")
}
Expand Down Expand Up @@ -204,6 +226,10 @@ func (c *Client) ExchangeAmount(amount *big.Int, pair string) (*big.Int, error)
return c.uc.GetExchangeAmount(amount, NFTPTokenAddress, WETHTokenAddress)
case "eth-nftp":
return c.uc.GetExchangeAmount(amount, WETHTokenAddress, NFTPTokenAddress)
case "error-eth":
return c.uc.GetExchangeAmount(amount, ERRORTokenAddress, WETHTokenAddress)
case "eth-error":
return c.uc.GetExchangeAmount(amount, WETHTokenAddress, ERRORTokenAddress)
default:
return nil, errors.New("unsupported pair")
}
Expand Down Expand Up @@ -236,6 +262,10 @@ func (c *Client) PairDecimals(pair string) int {
return 18
case "eth-nftp":
return 18
case "error-eth":
return 18
case "eth-error":
return 18
default:
return 0
}
Expand Down
4 changes: 4 additions & 0 deletions bclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func (bc *Client) GetIndexPool(name string) (IndexPool, error) {
return bc.DEGEN10()
case "nftp":
return bc.NFTP()
case "error":
return bc.ERROR()
default:
return nil, errors.New("invalid pool name")
}
Expand All @@ -38,6 +40,8 @@ func (bc *Client) GetPoolAddress(name string) (common.Address, error) {
return DEGEN10TokenAddress, nil
case "nftp":
return NFTPTokenAddress, nil
case "error":
return ERRORTokenAddress, nil
default:
return common.Address{}, errors.New("invalid pool name")
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/gondx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ func getValues(bc *bclient.Client, ip bclient.IndexPool, mc *multicall.Multicall
price, err = bc.Cc10DaiPrice()
case "orcl5":
price, err = bc.Orcl5DaiPrice()
case "degen10":
case "degen10", "degen":
price, err = bc.Degen10DaiPrice()
case "nftp":
price, err = bc.NftpDaiPrice()
case "error":
price, err = bc.ErrorDaiPrice()
}
return
}
Expand Down Expand Up @@ -488,6 +490,8 @@ func getPoolAddress(indice string) (poolAddress common.Address) {
poolAddress = bclient.DEGEN10TokenAddress
case "nftp":
poolAddress = bclient.NFTPTokenAddress
case "error":
poolAddress = bclient.ERRORTokenAddress
}
return
}
3 changes: 2 additions & 1 deletion db/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
Asset("ORCL5"),
Asset("DEGEN10"),
Asset("NFTP"),
Asset("ERROR"),
}
// ErrInvalidAsset is an error returned when the given asset specified is invalid
ErrInvalidAsset = errors.New("invalid asset")
Expand All @@ -31,7 +32,7 @@ var (
// IsValidAsset determines whether or not the given asset is one we are tracking
func IsValidAsset(asset string) bool {
switch strings.ToLower(asset) {
case "ndx", "defi5", "cc10", "orcl5", "eth", "degen10", "nftp":
case "ndx", "defi5", "cc10", "orcl5", "eth", "degen10", "nftp", "error":
return true
default:
return false
Expand Down
6 changes: 6 additions & 0 deletions discord/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ func (c *Client) priceWindowChart(ctx *dgc.Ctx) {
c.logger.Error("failed to fetch dai price", zap.Error(err), zap.String("asset", "nftp"))
return
}
case "error-dai":
prices, err = c.db.PricesInRange("error", window)
if err != nil {
ctx.RespondText("failed to get price")
c.logger.Error("failed to fetch dai price", zap.Error(err), zap.String("asset", "error"))
}
case "ndx-dai":
prices, err = c.db.PricesInRange("ndx", window)
if err != nil {
Expand Down
25 changes: 24 additions & 1 deletion discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ func ndxPriceWatchRoutine(ctx context.Context, bot *discordgo.Session, wg *sync.
logger.Error("failed to get tvl", zap.Error(err), zap.String("asset", "degen10"))
continue
}
nftpTVL, err := db.LastValueLocked("nftp")
if err != nil {
logger.Error("failed to get tvl", zap.Error(err), zap.String("asset", "nftp"))
continue
}
/* todo(bonedaddy): uncomment when error fund is live
errorTVL , err := db.LastValueLocked("error")
if err != nil {
logger.Error("fialed to get tvl", zap.Error(err), zap.String("asset", "error"))
}
*/
price, err := db.LastPrice("ndx")
if err != nil {
logger.Error("failed to get price", zap.Error(err), zap.String("asset", "ndx"))
Expand All @@ -311,7 +322,8 @@ func ndxPriceWatchRoutine(ctx context.Context, bot *discordgo.Session, wg *sync.
continue
}
update := fmt.Sprintf("NDXBot: $%0.2f", price)
parsed := ParseValue(defi5TVL + cc10TVL + orcl5TVL + degen10TVL)
// todo(bonedaddy): uncomment when error fund is live
parsed := ParseValue(defi5TVL + cc10TVL + orcl5TVL + degen10TVL + nftpTVL /* + errorTVL */)
for _, guild := range guilds {
bot.GuildMemberNickname(guild.ID, "@me", update)
bot.UpdateStatus(0, parsed+" TVL")
Expand Down Expand Up @@ -501,6 +513,17 @@ func launchSingleWatcherBot(ctx context.Context, bot *discordgo.Session, bc *bcl
logger.Error("failed to get tvl price", zap.Error(err), zap.String("asset", "nftp"))
continue
}
case "error":
price, err = database.LastPrice("error")
if err != nil {
logger.Error("failed to get dai price", zap.Error(err), zap.String("asset", "error"))
continue
}
tvl, err = database.LastValueLocked("error")
if err != nil {
logger.Error("failed to get tvl price", zap.Error(err), zap.String("asset", "error"))
continue
}
case "ndx":
price, err = database.LastPrice("ndx")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion discord/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (c *Client) poolTotalValueLocked(ctx *dgc.Ctx) {
// get tvl across all pools
var (
totalLocked float64
pools = []string{"defi5", "cc10", "orcl5", "degen10", "nftp"}
pools = []string{"defi5", "cc10", "orcl5", "degen10", "nftp", "error"}
)
for _, pool := range pools {
tvl, err := c.db.LastValueLocked(strings.ToLower(pool))
Expand Down
24 changes: 23 additions & 1 deletion discord/uniswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ func (c *Client) uniswapExchangeRateHandler(ctx *dgc.Ctx) {
return
}
ctx.RespondText(fmt.Sprintf("NFTP-DAI exchange rate: %0.2f", price))
case "error-dai":
price, err := c.db.LastPrice("error")
if err != nil {
ctx.RespondText("failed to get price")
c.logger.Error("failed to fetch dai price", zap.Error(err), zap.String("asset", "error"))
return
}
ctx.RespondText(fmt.Sprintf("ERROR-DAI exchange rate: %0.2f", price))
default:
ctx.RespondText("invalid currency requested must be one of: defi5-dai, cc10-dai, eth-dai, ndx-dai, orcl5-dai, degen10-dai, degen-dai")
return
Expand Down Expand Up @@ -209,7 +217,7 @@ func (c *Client) uniswapPercentChangeHandler(ctx *dgc.Ctx) {
changed = "increased"
}
ctx.RespondText(fmt.Sprintf("DEGEN10-DAI price has %s %0.2f%% over the last %v days", changed, math.Abs(price*100), window))
case "nftp":
case "nftp", "nftp-dai":
price, err := c.db.PriceChangeInRange("nftp", window)
if err != nil {
ctx.RespondText("failed to get price")
Expand All @@ -223,6 +231,20 @@ func (c *Client) uniswapPercentChangeHandler(ctx *dgc.Ctx) {
changed = "increased"
}
ctx.RespondText(fmt.Sprintf("NFTP-DAI price has %s %0.2f%% over the last %v days", changed, math.Abs(price*100), window))
case "error", "error-dai":
price, err := c.db.PriceChangeInRange("error", window)
if err != nil {
ctx.RespondText("failed to get price")
c.logger.Error("failed to calculate price change", zap.Error(err), zap.String("asset", "error"))
return
}
var changed string
if (price * 100) < 0 {
changed = "decreased"
} else {
changed = "increased"
}
ctx.RespondText(fmt.Sprintf("ERROR-DAI price has %s %0.2f%% over the last %v days", changed, math.Abs(price*100), window))
default:
ctx.RespondText("invalid currency requested must be one of: defi5-dai, cc10-dai, eth-dai, ndx-dai, orcl5-dai")
return
Expand Down

0 comments on commit 4b4ac86

Please sign in to comment.