Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4
with:
go-version: 1.19

Expand All @@ -21,5 +21,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.48.0
version: v1.52.2
args: --timeout=3m
153 changes: 153 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
run:
tests: true
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m
skip-dirs:
- osmosis-types/*

linters:
disable-all: true
enable:
# Check for pass []any as any in variadic func(...any).
# Rare case but saved me from debugging a few times.
- asasalint
# I prefer plane ASCII identifiers.
# Symbol `∆` instead of `delta` looks cool but no thanks.
- asciicheck
# Checks for dangerous unicode character sequences.
# Super rare but why not to be a bit paranoid?
- bidichk
- bodyclose
# Check whether the function uses a non-inherited context.
- contextcheck
# Check for two durations multiplied together.
- durationcheck
- depguard
- dogsled
- errcheck
# Checks `Err-` prefix for var and `-Error` suffix for error type.
- errname
# Suggests to use `%w` for error-wrapping.
- errorlint
# Checks for pointers to enclosing loop variables.
- exportloopref
- goconst
- gocritic
# Forces to put `.` at the end of the comment. Code is poetry.
- godot
# Might not be that important, but I prefer to keep all of them.
# `gofumpt` is amazing, kudos to Daniel Marti https://github.com/mvdan/gofumpt
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
# Finds sending HTTP request without context.Context.
- noctx
# Finds slices that could potentially be pre-allocated.
# Small performance win + cleaner code.
- prealloc
# Finds shadowing of Go's predeclared identifiers.
# I hear a lot of complaints from junior developers.
# But after some time they find it very useful.
- predeclared
# Lint your Prometheus metrics name.
- promlinter
# Checks that package variables are not reassigned.
# Super rare case but can catch bad things (like `io.EOF = nil`)
- reassign
- revive
- staticcheck
- stylecheck
# Checks that package variables are not reassigned.
# Super rare case but can catch bad things (like `io.EOF = nil`)
- reassign
- typecheck
# Test-related checks. All of them are good.
- tenv
- testableexamples
- thelper
- tparallel
- unconvert
- unused
- unparam
# Detect the possibility to use variables/constants from stdlib.
- usestdlibvars
# Finds wasted assignment statements.
- wastedassign

exclude-rules:
- linters:
- nolintlint
text:
- "should be written without leading space"

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec

linters-settings:
# I'm biased and I'm enabling more than 100 checks
# Might be too much for you. See https://go-critic.com/overview.html
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- hugeParam
- rangeExprCopy
- rangeValCopy
- timeCmpSimplify
- unlabelStmt
- unnamedResult
- tooManyResultsChecker
- whyNoLint
- commentedOutCode

gosec:
excludes:
- G306
- G107

errcheck:
# Report `a := b.(MyStruct)` when `a, ok := ...` should be.
check-type-assertions: true # Default: false


# Function to skip.
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)

govet:
disable:
- fieldalignment # I'm ok to waste some bytes


nakedret:
# No naked returns, ever.
max-func-lines: 1 # Default: 30

tagliatelle:
case:
rules:
json: snake # why it's not a `snake` by default?!
yaml: snake # why it's not a `snake` by default?!
xml: camel
bson: camel
avro: snake
mapstructure: kebab
37 changes: 35 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,49 @@ COMMIT_HASH := $(shell git rev-parse --short=7 HEAD)
DOCKER_TAG := $(COMMIT_HASH)

linker_flags = "-s -X main.GitCommit=${COMMIT_HASH}"
export GO111MODULE = on

build:


build: go.sum
go build -ldflags=${linker_flags} -o bin/evinced -a
build-docker:
build-docker: go.sum
DOCKER_BUILDKIT=1 $(DOCKER) build . -f Dockerfile -t quicksilverzone/evince:$(DOCKER_TAG)

go.sum: go.mod
echo "Ensure dependencies have not been modified ..." >&2
go mod verify
go mod tidy

run:
go run -a
install:
go build -ldflags=${linker_flags} -o /go/bin/evinced -a

all: build

###############################################################################
### Linting ###
###############################################################################

lint:
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run --out-format=tab

lint-fix:
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run --fix --out-format=tab --issues-exit-code=0

.PHONY: lint lint-fix

format:
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run mvdan.cc/gofumpt -w .
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run github.com/client9/misspell/cmd/misspell -w
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' -not -name '*.gw.go' | xargs go run golang.org/x/tools/cmd/goimports -w -local github.com/ingenuity-build/evince

.PHONY: format

mdlint:
@echo "--> Running markdown linter"
@$(DOCKER) run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md"

mdlint-fix:
@$(DOCKER) run -v $(PWD):/workdir ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --fix
20 changes: 13 additions & 7 deletions apr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"math"
"net/http"
Expand All @@ -24,9 +25,15 @@ type ChainAPR struct {
APR float64 `json:"apr"`
}

func getAPRquery(baseurl string, chainname string) (ChainAPR, error) {
url := baseurl + chainname
resp, err := http.Get(url)
func getAPRquery(ctx context.Context, baseurl, chainName string) (ChainAPR, error) {
url := baseurl + chainName

client := &http.Client{}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
if err != nil {
return ChainAPR{}, err
}
resp, err := client.Do(req)
if err != nil {
return ChainAPR{}, err
}
Expand All @@ -45,11 +52,10 @@ func getAPRquery(baseurl string, chainname string) (ChainAPR, error) {
return ChainAPR{}, err
}

if chainname != "quicksilver" {
feeadjustedAPR := (chain.Params.EstimatedApr) * (0.965)
compoundedAPR := math.Pow(1+feeadjustedAPR/121.66, 121.66) - 1
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

}
Loading