Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auction bot module #70

Merged
merged 14 commits into from
Aug 28, 2024
Merged
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
15 changes: 15 additions & 0 deletions .github/scripts/wait-for-node-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
get_block_number() {
local BLOCK_NUMBER=$(curl -sS -X POST \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
-H "Content-Type: application/json" \
http://localhost:8545 | jq .result)
echo $BLOCK_NUMBER
}

BLOCK_NUMBER=$(get_block_number)

while [ "$BLOCK_NUMBER" == "" ]
do
BLOCK_NUMBER=$(get_block_number)
sleep 0.5
done
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'

- name: Cache Go Modules
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build
run: make build-all

- name: Vet
run: make vet

- name: Test
run: make test

lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.21'

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=10m

integration-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout go-tools-kava
uses: actions/checkout@v4
with:
path: go-tools

# TODO(yevhenii): consider reusing already built kava docker image instead of rebuilding it
- name: Checkout kava
uses: actions/checkout@v4
with:
repository: Kava-Labs/kava
ref: ${{ github.event.client_payload.ref }}
path: kava
submodules: 'true'

- name: Print kava version
run: |
git branch
git rev-parse HEAD
working-directory: ./kava

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go-tools/go.mod

- name: Cache Go Modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('./rosetta-kava/**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build kava docker image
run: make docker-build
working-directory: ./kava

- name: Install kvtool
run: make install
working-directory: ./kava/tests/e2e/kvtool

- name: Run kava docker container
run: KAVA_TAG=local kvtool t bootstrap

- name: Wait until kava node is ready to serve traffic
run: bash ${GITHUB_WORKSPACE}/go-tools/.github/scripts/wait-for-node-init.sh

- name: Run integration tests
run: make test-integration
working-directory: ./go-tools
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Define the base directory (default is current directory)
BASEDIR := $(shell pwd)

# Find all directories containing a main.go file
MODULES := $(shell find . -type f -name 'main.go' -not -path "*/vendor/*" -exec dirname {} \;)

# output the list of modules
.PHONY: modules
modules:
@echo $(MODULES)

# Default target: build all modules
.PHONY: build-all
build-all:
@for dir in $(MODULES); do \
echo "Building module in $$dir..."; \
if ! (cd $$dir && go build -o $(BASEDIR)/$$(basename $$dir)/$$(basename $$dir)); then \
echo "Failed to build $$dir"; \
exit 1; \
fi; \
echo "Built module $$dir successfully."; \
done

.PHONY: golangci-lint
golangci-lint:
golangci-lint run

.PHONY: vet
vet:
go vet ./...

.PHONY: test
test:
go test -v ./...

.PHONY: test-integration
test-integration:
cd signing/testing && go test -v -tags=integration -count=1
Comment on lines +37 to +38
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be moved to the signing specific Makefile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it make sense. If we will extend integration test to other modules it's easier to run one integration test for all of them with just make test-integration, than running it directory b directory, so would prefer to keep one common make command in the root

8 changes: 4 additions & 4 deletions auction-bot/calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func handleReverseDebtAuction(
}

func calculateUSDValue(coin sdk.Coin, assetInfo AssetInfo) sdk.Dec {
return coin.Amount.ToDec().Quo(assetInfo.ConversionFactor.ToDec()).Mul(assetInfo.Price)
return coin.Amount.ToLegacyDec().Quo(assetInfo.ConversionFactor.ToLegacyDec()).Mul(assetInfo.Price)
}

func calculateProposedBid(
Expand All @@ -269,13 +269,13 @@ func calculateProposedBid(
if lotUSDValue.IsZero() {
return sdk.Coin{}, false
}
minBid := currentBid.Amount.ToDec().Mul(d("1.0105")).RoundInt()
minBid := currentBid.Amount.ToLegacyDec().Mul(d("1.0105")).RoundInt()
if minBid.GT(maxbid.Amount) {
minBid = maxbid.Amount
}

for _, bidIncrement := range bidsToTry {
bidAmountInt := maxbid.Amount.ToDec().Mul(bidIncrement).TruncateInt()
bidAmountInt := maxbid.Amount.ToLegacyDec().Mul(bidIncrement).TruncateInt()
if bidAmountInt.LT(minBid) {
bidAmountInt = minBid
}
Expand Down Expand Up @@ -326,7 +326,7 @@ func calculateProposedLot(
}

for _, lotIncrement := range incrementsToTry {
proposedLotInt := lot.Amount.ToDec().Mul(sdk.OneDec().Sub(lotIncrement)).TruncateInt()
proposedLotInt := lot.Amount.ToLegacyDec().Mul(sdk.OneDec().Sub(lotIncrement)).TruncateInt()
proposedLotCoin := sdk.NewCoin(lot.Denom, proposedLotInt)
proposedLotUSDValue := calculateUSDValue(proposedLotCoin, assetInfoLot)
if proposedLotUSDValue.IsZero() {
Expand Down
Loading
Loading