Skip to content

Commit

Permalink
update to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses committed Sep 17, 2024
2 parents f0a059b + 0357100 commit e37ee32
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 646 deletions.
7 changes: 7 additions & 0 deletions contrib/opbot/botmd/botmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/synapsecns/sanguine/core/dbcommon"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/metrics/instrumentation/slackertrace"
experimentalLogger "github.com/synapsecns/sanguine/core/metrics/logger"
signerConfig "github.com/synapsecns/sanguine/ethergo/signer/config"
"github.com/synapsecns/sanguine/ethergo/signer/signer"
"github.com/synapsecns/sanguine/ethergo/submitter"
cctpSql "github.com/synapsecns/sanguine/services/cctp-relayer/db/sql"
omnirpcClient "github.com/synapsecns/sanguine/services/omnirpc/client"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
"golang.org/x/sync/errgroup"
)

Expand All @@ -30,15 +32,20 @@ type Bot struct {
signer signer.Signer
submitter submitter.TransactionSubmitter
screener screenerClient.ScreenerClient
logger experimentalLogger.ExperimentalLogger
}

// NewBot creates a new bot server.
func NewBot(handler metrics.Handler, cfg config.Config) *Bot {
server := slacker.NewClient(cfg.SlackBotToken, cfg.SlackAppToken)

sugaredLogger := otelzap.New(experimentalLogger.MakeZapLogger()).Sugar()

bot := Bot{
handler: handler,
cfg: cfg,
server: server,
logger: experimentalLogger.MakeWrappedSugaredLogger(sugaredLogger),
}

// you should be able to run opbot even without signoz.
Expand Down
35 changes: 26 additions & 9 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"math/big"
"regexp"
"sort"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -50,14 +51,16 @@ func (b *Bot) requiresSignoz(definition *slacker.CommandDefinition) *slacker.Com
// TODO: add trace middleware.
func (b *Bot) traceCommand() *slacker.CommandDefinition {
return b.requiresSignoz(&slacker.CommandDefinition{
Command: "trace <tags>",
Command: "trace {tags} {order}",
Description: "find a transaction in signoz",
Examples: []string{
"trace transaction_id:0x1234 serviceName:rfq",
"trace transaction_id:0x1234@serviceName:rfq",
"trace transaction_id:0x1234@serviceName:rfq a",
"trace transaction_id:0x1234@serviceName:rfq asc",
},
Handler: func(ctx *slacker.CommandContext) {
tags := stripLinks(ctx.Request().Param("tags"))
splitTags := strings.Split(tags, " ")
splitTags := strings.Split(tags, "@")
if len(splitTags) == 0 {
_, err := ctx.Response().Reply("please provide tags in a key:value format")
if err != nil {
Expand All @@ -82,6 +85,7 @@ func (b *Bot) traceCommand() *slacker.CommandDefinition {
// search for the transaction
res, err := b.signozClient.SearchTraces(ctx.Context(), signoz.Last3Hr, searchMap)
if err != nil {
b.logger.Errorf(ctx.Context(), "error searching for the transaction: %v", err)
_, err := ctx.Response().Reply("error searching for the transaction")
if err != nil {
log.Println(err)
Expand All @@ -106,6 +110,14 @@ func (b *Bot) traceCommand() *slacker.CommandDefinition {
return
}

order := strings.ToLower(ctx.Request().Param("order"))
isAscending := order == "a" || order == "asc"
if isAscending {
sort.Slice(traceList, func(i, j int) bool {
return traceList[i].Timestamp.Before(traceList[j].Timestamp)
})
}

slackBlocks := []slack.Block{slack.NewHeaderBlock(slack.NewTextBlockObject(slack.PlainTextType, fmt.Sprintf("Traces for %s", tags), false, false))}

for _, results := range traceList {
Expand Down Expand Up @@ -290,6 +302,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
}
}
if err != nil {
b.logger.Errorf(ctx.Context(), "error fetching quote request: %v", err)
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
Expand Down Expand Up @@ -338,19 +351,23 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
err = retry.WithBackoff(
ctx.Context(),
func(ctx context.Context) error {
txHash, err = relClient.GetTxHashByNonce(ctx, &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
txHash, err = relClient.GetTxHashByNonce(
ctx,
&relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
b.logger.Errorf(ctx, "error fetching quote request: %v", err)
return fmt.Errorf("error fetching quote request: %w", err)
}
return nil
},
retry.WithMaxAttempts(3),
retry.WithMaxAttemptTime(15*time.Second),
retry.WithMaxAttempts(5),
retry.WithMaxAttemptTime(30*time.Second),
)
if err != nil {
b.logger.Errorf(ctx.Context(), "error fetching quote request: %v", err)
_, err := ctx.Response().Reply(fmt.Sprintf("error fetching explorer link to refund, but nonce is %d", nonce))
log.Printf("error fetching quote request: %v\n", err)
return
Expand Down
2 changes: 1 addition & 1 deletion contrib/opbot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/synapsecns/sanguine/services/cctp-relayer v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/omnirpc v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/services/rfq v0.0.0-00010101000000-000000000000
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1
github.com/urfave/cli/v2 v2.27.2
golang.org/x/sync v0.8.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -240,7 +241,6 @@ require (
github.com/uptrace/opentelemetry-go-extra/otelgorm v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelsql v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.3.1 // indirect
github.com/uptrace/opentelemetry-go-extra/otelzap v0.3.1 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
Expand Down
12 changes: 6 additions & 6 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"scripts": {
"build": "tsc",
"build:go": " ",
"build:slither": " ",
"dev": "nodemon --watch src --exec ts-node src/app.ts",
"start": "node dist/app.js",
"lint:fix": "eslint src/**/*.ts --fix",
"lint:check": "eslint . --max-warnings=0",
"ci:lint": "npm run lint:check",
"test": "jest",
"test:coverage": "jest --collect-coverage",
"postinstall": "npm run build"
"test:coverage": "jest --collect-coverage"
},
"dependencies": {
"@ethersproject/bignumber": "^5.7.0",
Expand All @@ -27,7 +27,9 @@
"express": "^4.18.2",
"express-validator": "^7.2.0",
"jest": "^29.7.0",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"supertest": "^6.3.3",
"typescript": "^4.8.3"
},
"description": "A node.js project exposing a rest api for synapse sdk quotes",
"devDependencies": {
Expand All @@ -40,9 +42,7 @@
"jest": "^29.7.0",
"lodash": "^4.17.21",
"nodemon": "^3.0.1",
"supertest": "^6.3.3",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^4.8.3"
"ts-node": "^10.9.2"
}
}
Loading

0 comments on commit e37ee32

Please sign in to comment.