-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
267 lines (216 loc) · 8.78 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# Exporting bin folder to the path for makefile
PWD := $(shell pwd)
export PATH := $(PWD)/bin:$(PATH)
# Default Shell
export SHELL := bash
# Type of OS: Linux or Darwin.
export OSTYPE := $(shell uname -s)
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
GO_VERSION := $(shell cat go.mod | grep -E 'go [0-9].[0-9]+' | cut -d ' ' -f 2)
PACKAGES_UNIT=$(shell go list ./...)
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
RUNNER := ubuntu
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(OSMOSIS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# --- Tooling & Variables ----------------------------------------------------------------
include ./misc/make/tools.Makefile
# Install local dependencies
install-deps: mockery
deps: $(MOCKERY) ## Checks for Global Development Dependencies.
deps:
@echo "Required Tools Are Available"
generate-mocks: mockery
bin/mockery --config mockery.yaml
swagger-gen:
$(HOME)/go/bin/swag init -g app/main.go --pd --overridesFile ./.swaggo
run:
go run -ldflags="-X github.com/osmosis-labs/sqs/version=${VERSION}" app/*.go --config config.json
run-docker:
$(DOCKER) rm -f sqs
$(DOCKER) run -d --name sqs -p 9092:9092 -p 26657:26657 -v $(PWD)/config.json:/osmosis/config.json:ro --net host osmolabs/sqs:local --config /osmosis/config.json
$(DOCKER) logs -f sqs
osmosis-start:
$(DOCKER) run -d --name osmosis -p 26657:26657 -p 9090:9090 -p 1317:1317 -p 9091:9091 -p 6060:6060 -p 50051:50051 -v $(HOME)/.osmosisd/:/osmosis/.osmosisd/ --net host osmolabs/osmosis-dev:v25.x-5b3e7918-1724274941 "start"
osmosis-stop:
$(DOCKER) container rm -f osmosis
all-stop: osmosis-stop
all-start: osmosis-start run
lint:
@echo "--> Running linter"
golangci-lint run --timeout=10m
test-unit:
@VERSION=$(VERSION) go test -mod=readonly $(PACKAGES_UNIT)
build:
BUILD_TAGS=muslc LINK_STATICALLY=true GOWORK=off go build -mod=readonly \
-tags "netgo,ledger,muslc" \
-ldflags "-w -s -linkmode=external -extldflags '-Wl,-z,muldefs -static'" \
-v -o /osmosis/build/sqsd app/*.go
###############################################################################
### Docker ###
###############################################################################
docker-build:
@DOCKER_BUILDKIT=1 $(DOCKER) build \
-t osmolabs/sqs:$(VERSION) \
-t osmolabs/sqs:local \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
-f Dockerfile .
# This builds a debug image with the same version as the main image
# The binary is built with the debug symbols and has started via Delve debugger.
# Developer can then attach their IDE to the running container.
# See README.md#Debugging for more details.
docker-build-debug:
@DOCKER_BUILDKIT=1 $(DOCKER) build \
-t osmolabs/sqs:$(VERSION)-debug \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
-f Dockerfile.debug .
# Cross-building for arm64 from amd64 (or vice-versa) takes
# a lot of time due to QEMU virtualization but it's the only way (afaik)
# to get a statically linked binary with CosmWasm
build-reproducible: build-reproducible-amd64 build-reproducible-arm64
build-reproducible-amd64: go.sum
mkdir -p $(BUILDDIR)
$(DOCKER) buildx create --name osmobuilder || true
$(DOCKER) buildx use osmobuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg RUNNER_IMAGE=${RUNNER} \
--platform linux/amd64 \
-t sqs:local-amd64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f sqsbinary || true
$(DOCKER) create -ti --name sqsbinary sqs:local-amd64
$(DOCKER) cp sqsbinary:/bin/sqsd $(BUILDDIR)/sqsd-linux-amd64
$(DOCKER) rm -f sqsbinary
build-reproducible-arm64: go.sum
mkdir -p $(BUILDDIR)
$(DOCKER) buildx create --name osmobuilder || true
$(DOCKER) buildx use osmobuilder
$(DOCKER) buildx build \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(COMMIT) \
--build-arg RUNNER_IMAGE=${RUNNER} \
--platform linux/arm64 \
-t sqs:local-arm64 \
--load \
-f Dockerfile .
$(DOCKER) rm -f sqsbinary || true
$(DOCKER) create -ti --name sqsbinary sqs:local-arm64
$(DOCKER) cp sqsbinary:/bin/sqsd $(BUILDDIR)/sqsd-linux-arm64
$(DOCKER) rm -f sqsbinary
###############################################################################
### Utils ###
###############################################################################
load-test-ui:
$(DOCKER) compose -f locust/docker-compose.yml up --scale worker=4
debug:
dlv --build-flags="-ldflags='-X github.com/osmosis-labs/sqs/version=${VERSION}'" debug app/*.go
profile:
go tool pprof -http=:8080 http://localhost:9092/debug/pprof/profile?seconds=60
# Validates that SQS concentrated liquidity pool state is
# consistent with the state of the chain.
validate-cl-state:
scripts/validate-cl-state.sh "http://localhost:9092"
# Compares the quotes between SQS and chain over pool 1136
# which is concentrated.
quote-compare:
scripts/quote.sh "http://localhost:9092"
sqs-quote-compare-stage:
ingest/sqs/scripts/quote.sh "http://165.227.168.61"
# Updates go tests with the latest mainnet state
# Make sure that the node is running locally
sqs-update-mainnet-state:
curl -X POST "http:/localhost:9092/router/store-state"
mv pools.json router/usecase/routertesting/parsing/pools.json
mv taker_fees.json router/usecase/routertesting/parsing/taker_fees.json
mv candidate_route_search_data.json router/usecase/routertesting/parsing/candidate_route_search_data.json
curl -X POST "http:/localhost:9092/tokens/store-state"
mv tokens.json router/usecase/routertesting/parsing/tokens.json
mv pool_denom_metadata.json router/usecase/routertesting/parsing/pool_denom_metadata.json
# Bench tests pricing
bench-pricing:
go test -bench BenchmarkGetPrices -run BenchmarkGetPrices github.com/osmosis-labs/sqs/tokens/usecase -count=6
proto-gen:
protoc --go_out=./ --go-grpc_out=./ --proto_path=./sqsdomain/proto ./sqsdomain/proto/ingest.proto
test-prices-mainnet:
CI_SQS_PRICING_WORKER_TEST=true go test \
-timeout 300s \
-run TestPricingWorkerTestSuite/TestGetPrices_Chain_FindUnsupportedTokens \
github.com/osmosis-labs/sqs/tokens/usecase/pricing/worker -v -count=1
### E2E Test
# Run E2E tests in verbose mode (-s) -n 4 concurrent workers
e2e-run-stage:
SQS_ENVIRONMENTS=stage pytest -s -n 4 --ignore=tests/test_synthetic_geo.py
e2e-run-local:
SQS_ENVIRONMENTS=local pytest -s -n 4 --ignore=tests/test_synthetic_geo.py
#### E2E Python Setup
# Setup virtual environment for e2e tests
e2e-setup-venv:
python3 -m venv tests/venv
# Activate virtual environment for e2e tests
e2e-source-venv:
source tests/venv/bin/activate
#
e2e-install-requirements:
pip install -r tests/requirements.txt
# Persist any new dependencies to requirements.txt
e2e-update-requirements:
pip freeze > tests/requirements.txt
# Set DATADOG_API_KEY in the environment
datadog-agent-start:
export DATADOG_API_KEY=@@REDACTED@@; \
docker run --cgroupns host \
--pid host \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /proc/:/host/proc/:ro \
-v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro \
-p 127.0.0.1:8126:8126/tcp \
-p 127.0.0.1:4317:4317/tcp \
-e DD_API_KEY=$$DATADOG_API_KEY \
-e DD_APM_ENABLED=true \
-e DD_SITE=us5.datadoghq.com \
-e DD_OTLP_CONFIG_RECEIVER_PROTOCOLS_GRPC_ENDPOINT=0.0.0.0:4317 \
gcr.io/datadoghq/agent:latest
#### Orderbook plugins ####
####
#### Orderbook Fill Bot Plugin
# Starts the full-scale order fill bot.
# - Creates a copy of the config.json file with the updated
# order fill bot configuration.
# Starts node and SQS in the background.
# - Starts DataDog service
# Use ./ingest/usecase/plugins/orderbook/fillbot/.env to configure the keyring.
orderbook-fillbot-start:
./ingest/usecase/plugins/orderbook/fillbot/create_copy_config.sh
cd ./ingest/usecase/plugins/orderbook/fillbot && docker compose up -d
cd ../../../../
echo "Orderbook Fill Bot Started"
sleep 10 && osmosisd status
sleep 10 && docker logs -f osmosis-sqs
orderbook-fillbot-stop:
cd ./ingest/usecase/plugins/orderbook/fillbot && docker compose down
cd ../../../../
echo "Orderbook Fill Bot Stopped"
orderbook-claimbot-start:
./ingest/usecase/plugins/orderbook/fillbot/create_copy_config.sh
cd ./ingest/usecase/plugins/orderbook/claimbot && docker compose up -d
cd ../../../../
echo "Orderbook Claim Bot Started"
sleep 10 && osmosisd status
sleep 10 && docker logs -f osmosis-sqs
orderbook-claimbot-stop:
cd ./ingest/usecase/plugins/orderbook/claimbot && docker compose down
cd ../../../../
echo "Orderbook Claim Bot Stopped"