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

feat: Rename oracle to slinky, refactor mm provider factory #272

Merged
merged 23 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d8d191
Convert all commands to cobra
Eric-Warehime Mar 22, 2024
0b0e899
Fix lint
Eric-Warehime Mar 25, 2024
adb39d8
Merge branch 'main' into eric/convert-everything-to-cobra
Eric-Warehime Mar 25, 2024
0fcc9dd
Rename oracle to slinky, refactor mm provider factory
Eric-Warehime Mar 25, 2024
c50a833
Merge remote-tracking branch 'origin' into eric/rename-slinky-refacto…
Eric-Warehime Mar 25, 2024
c1cd3ee
Update aggregation stuff
Eric-Warehime Mar 25, 2024
5960108
Merge remote-tracking branch 'origin' into eric/rename-slinky-refacto…
Eric-Warehime Mar 25, 2024
ebdb2aa
Fix metrics stuff I broke in merge
Eric-Warehime Mar 25, 2024
6d8b7fb
Remove chain arg from slinky
Eric-Warehime Mar 25, 2024
adeecd2
Change names, flags
Eric-Warehime Mar 25, 2024
279db59
Do validate
Eric-Warehime Mar 25, 2024
d5e7d3d
Fix path tests
Eric-Warehime Mar 25, 2024
7c2230f
Fix keeper tests
Eric-Warehime Mar 25, 2024
7a8f3b9
Fix integ tests
Eric-Warehime Mar 25, 2024
0da58f2
Generate paths for default configs
Eric-Warehime Mar 26, 2024
a752c03
Fix lint fumpt
Eric-Warehime Mar 26, 2024
77faa08
Fix integ tests
Eric-Warehime Mar 26, 2024
67614b2
Provide paths everywhere
Eric-Warehime Mar 26, 2024
a62d7d6
Fix slashing tests
Eric-Warehime Mar 26, 2024
f19b85e
update
Eric-Warehime Mar 26, 2024
ea8f03b
Update oracle/constants/chains.go
Eric-Warehime Mar 26, 2024
f4c871e
Merge remote-tracking branch 'origin' into eric/rename-slinky-refacto…
Eric-Warehime Mar 26, 2024
db63e31
Merge branch 'main' into eric/rename-slinky-refactor-mmfactory
Eric-Warehime Mar 26, 2024
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
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ release:
prerelease: true

builds:
- main: 'cmd/oracle/main.go'
- main: 'cmd/slinky/main.go'
goos:
- 'linux'
- 'darwin'
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ build: tidy
@go build -o ./build/ ./...

run-oracle-server: build
@./build/oracle --oracle-config-path ${ORACLE_CONFIG_FILE} --market-config-path ${MARKET_CONFIG_FILE}
@./build/slinky --oracle-config-path ${ORACLE_CONFIG_FILE} --market-config-path ${MARKET_CONFIG_FILE}

run-oracle-client: build
@./build/client --host localhost --port 8080
Expand All @@ -54,7 +54,7 @@ stop-oracle:
@$(DOCKER_COMPOSE) -f docker-compose.yml down

install: tidy
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/oracle
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/slinky

.PHONY: build run-oracle-server install

Expand Down
126 changes: 75 additions & 51 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import (
"context"
"flag"
"fmt"
"log"
"os"
Expand All @@ -11,72 +10,97 @@
"syscall"
"time"

"github.com/spf13/cobra"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/skip-mev/slinky/service/servers/oracle/types"
)

var (
host = flag.String("host", "localhost", "host for the grpc-service to listen on")
port = flag.String("port", "8080", "port for the grpc-service to listen on")
)
rootCmd = &cobra.Command{
Use: "client",
Short: "Continuously calls the Prices RPC on the sidecar.",
Args: cobra.NoArgs,
Run: func(_ *cobra.Command, _ []string) {

Check warning on line 25 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L25

Added line #L25 was not covered by tests
// Channel with width for termination signal.
sigs := make(chan os.Signal, 1)

Check warning on line 27 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L27

Added line #L27 was not covered by tests

func main() {
// Channel with width for termination signal.
sigs := make(chan os.Signal, 1)
// Gracefully trigger close on interrupt or terminate signals.
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

Check warning on line 30 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L30

Added line #L30 was not covered by tests

// Gracefully trigger close on interrupt or terminate signals.
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
// Set up a connection to the server.
url := fmt.Sprintf("%s:%s", host, port)
conn, err := grpc.Dial(url, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)

Check warning on line 36 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L33-L36

Added lines #L33 - L36 were not covered by tests
}
defer conn.Close()

Check warning on line 38 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L38

Added line #L38 was not covered by tests

// Parse flags.
flag.Parse()
// Create a new client
client := types.NewOracleClient(conn)

Check warning on line 41 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L41

Added line #L41 was not covered by tests

// Set up a connection to the server.
url := fmt.Sprintf("%s:%s", *host, *port)
conn, err := grpc.Dial(url, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
// Continuous loop
for {
select {
case <-sigs:
log.Printf("Received interrupt or terminate signal, exiting...\n")
return
default:

Check warning on line 49 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L44-L49

Added lines #L44 - L49 were not covered by tests
// Call Prices RPC
log.Printf("Calling Prices RPC...\n")
resp, err := client.Prices(context.Background(), &types.QueryPricesRequest{})
if err != nil {
log.Fatalf("could not get prices: %v", err)

Check warning on line 54 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L51-L54

Added lines #L51 - L54 were not covered by tests
}

// Create a new client
client := types.NewOracleClient(conn)
prices := resp.GetPrices()

Check warning on line 57 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L57

Added line #L57 was not covered by tests

// Continuous loop
for {
select {
case <-sigs:
log.Printf("Received interrupt or terminate signal, exiting...\n")
return
default:
// Call Prices RPC
log.Printf("Calling Prices RPC...\n")
resp, err := client.Prices(context.Background(), &types.QueryPricesRequest{})
if err != nil {
log.Fatalf("could not get prices: %v", err) //nolint
}
var keys []string
for k := range prices {
keys = append(keys, k)

Check warning on line 61 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L59-L61

Added lines #L59 - L61 were not covered by tests
}

prices := resp.GetPrices()
// Sort the prices by the currency pair
sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})

Check warning on line 67 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L65-L67

Added lines #L65 - L67 were not covered by tests

var keys []string
for k := range prices {
keys = append(keys, k)
}
// Log the response
for _, key := range keys {
log.Printf("Currency Pair, Price: (%s, %s)", key, prices[key])

Check warning on line 71 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L70-L71

Added lines #L70 - L71 were not covered by tests
}

// Sort the prices by the currency pair
sort.Slice(keys, func(i, j int) bool {
return keys[i] < keys[j]
})

// Log the response
for _, key := range keys {
log.Printf("Currency Pair, Price: (%s, %s)", key, prices[key])
// Wait for a bit before making the next request
log.Printf("Sleeping for 10 seconds...\n\n")
time.Sleep(time.Second * 10) // Adjust the interval as needed

Check warning on line 76 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}
}

// Wait for a bit before making the next request
log.Printf("Sleeping for 10 seconds...\n\n")
time.Sleep(time.Second * 10) // Adjust the interval as needed
}
},
}
// host stores the host portion of the sidecar RPC to query.
host string
// port stores the port of the sidecar RPC to query.
port string
)

func init() {
rootCmd.Flags().StringVarP(
&host,
"host",
"",
"localhost",
"host of the grpc-service, which the client will connect to",
)
rootCmd.Flags().StringVarP(
&port,
"port",
"",
"8080",
"port the grpc-service, which the client will connect to",
)

Check warning on line 101 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L87-L101

Added lines #L87 - L101 were not covered by tests
}

func main() {
rootCmd.Execute()

Check warning on line 105 in cmd/client/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/client/main.go#L104-L105

Added lines #L104 - L105 were not covered by tests
}
Loading
Loading