Skip to content

Commit

Permalink
Merge branch 'master' into fix/rfq-ci-flake
Browse files Browse the repository at this point in the history
  • Loading branch information
dwasse committed Sep 3, 2024
2 parents 7758212 + 4a17c15 commit 5541966
Show file tree
Hide file tree
Showing 44 changed files with 1,903 additions and 787 deletions.
28 changes: 19 additions & 9 deletions contrib/git-changes-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

moduledetector "github.com/synapsecns/sanguine/contrib/git-changes-action/detector/module"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/package"
packagedetector "github.com/synapsecns/sanguine/contrib/git-changes-action/detector/package"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/tree"

"github.com/sethvargo/go-githubactions"
Expand Down Expand Up @@ -45,12 +45,12 @@ func main() {
panic(err)
}

noDepChanged, noDepUnchanged, err := outputModuleChanges(workingDirectory, ct, false, dependencyLevelResolution)
noDepChanged, noDepUnchanged, _, err := outputModuleChanges(workingDirectory, ct, false, dependencyLevelResolution)
if err != nil {
panic(err)
}

depChanged, depUnchanged, err := outputModuleChanges(workingDirectory, ct, true, dependencyLevelResolution)
depChanged, depUnchanged, allModules, err := outputModuleChanges(workingDirectory, ct, true, dependencyLevelResolution)
if err != nil {
panic(err)
}
Expand All @@ -60,12 +60,15 @@ func main() {

githubactions.SetOutput("changed_modules_deps", depChanged)
githubactions.SetOutput("unchanged_modules_deps", depUnchanged)

githubactions.SetOutput("all_modules", allModules)

}

// outputModuleChanges outputs the changed modules.
// this wraps detector.DetectChangedModules and handles the output formatting to be parsable by github actions.
// the final output is a json array of strings.
func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool, dependencyLevelResolution string) (changedJSON string, unchangedJSON string, err error) {
func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool, dependencyLevelResolution string) (changedJSON string, unchangedJSON string, allModulesJSON string, err error) {
var modules map[string]bool

if dependencyLevelResolution == "packages" {
Expand All @@ -75,12 +78,13 @@ func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool
}

if err != nil {
return changedJSON, unchangedJSON, fmt.Errorf("failed to detect changed modules w/ include deps set to %v: %w", includeDeps, err)
return changedJSON, unchangedJSON, allModulesJSON, fmt.Errorf("failed to detect changed modules w/ include deps set to %v: %w", includeDeps, err)
}

var changedModules, unchangedModules []string
var changedModules, unchangedModules, allModules []string
for module, changed := range modules {
modName := strings.TrimPrefix(module, "./")
allModules = append(allModules, modName)

if changed {
changedModules = append(changedModules, modName)
Expand All @@ -91,18 +95,24 @@ func outputModuleChanges(workingDirectory string, ct tree.Tree, includeDeps bool

sort.Strings(changedModules)
sort.Strings(unchangedModules)
sort.Strings(allModules)

marshalledChanged, err := json.Marshal(changedModules)
if err != nil {
return changedJSON, unchangedJSON, fmt.Errorf("failed to marshall changed module json w/ include deps set to %v: %w", includeDeps, err)
return changedJSON, unchangedJSON, allModulesJSON, fmt.Errorf("failed to marshall changed module json w/ include deps set to %v: %w", includeDeps, err)
}

marshalledUnchanged, err := json.Marshal(unchangedModules)
if err != nil {
return changedJSON, unchangedJSON, fmt.Errorf("failed to marshall unchanged module json w/ include deps set to %v: %w", includeDeps, err)
return changedJSON, unchangedJSON, allModulesJSON, fmt.Errorf("failed to marshall unchanged module json w/ include deps set to %v: %w", includeDeps, err)
}

marshalledAll, err := json.Marshal(allModules)
if err != nil {
return changedJSON, unchangedJSON, allModulesJSON, fmt.Errorf("failed to marshall all modules json w/ include deps set to %v: %w", includeDeps, err)
}

return string(marshalledChanged), string(marshalledUnchanged), nil
return string(marshalledChanged), string(marshalledUnchanged), string(marshalledAll), nil
}

// getTimeout gets the timeout setting. If it is not set, it defaults to 1 minute.
Expand Down
9 changes: 9 additions & 0 deletions contrib/opbot/botmd/botmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package botmd
import (
"context"
"fmt"

"github.com/slack-io/slacker"
"github.com/synapsecns/sanguine/contrib/opbot/config"
"github.com/synapsecns/sanguine/contrib/opbot/signoz"
screenerClient "github.com/synapsecns/sanguine/contrib/screener-api/client"
"github.com/synapsecns/sanguine/core/dbcommon"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/metrics/instrumentation/slackertrace"
Expand All @@ -27,6 +29,7 @@ type Bot struct {
rpcClient omnirpcClient.RPCClient
signer signer.Signer
submitter submitter.TransactionSubmitter
screener screenerClient.ScreenerClient
}

// NewBot creates a new bot server.
Expand Down Expand Up @@ -88,6 +91,12 @@ func (b *Bot) Start(ctx context.Context) (err error) {

b.submitter = submitter.NewTransactionSubmitter(b.handler, b.signer, b.rpcClient, store.SubmitterDB(), &b.cfg.SubmitterConfig)

screenerClient, err := screenerClient.NewClient(b.handler, b.cfg.ScreenerURL)
if err != nil {
return fmt.Errorf("could not create screener client: %w", err)
}
b.screener = screenerClient

g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
return b.submitter.Start(ctx)
Expand Down
109 changes: 74 additions & 35 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/slack-go/slack"
"github.com/slack-io/slacker"
"github.com/synapsecns/sanguine/contrib/opbot/signoz"
"github.com/synapsecns/sanguine/core/retry"
"github.com/synapsecns/sanguine/ethergo/chaindata"
"github.com/synapsecns/sanguine/ethergo/client"
rfqClient "github.com/synapsecns/sanguine/services/rfq/api/client"
Expand Down Expand Up @@ -278,45 +279,87 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return
}

var rawRequest *relapi.GetQuoteRequestResponse
var err error
var relClient relapi.RelayerClient
for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)
relClient = relapi.NewRelayerClient(b.handler, relayer)
rawRequest, err = getQuoteRequest(ctx.Context(), relClient, tx)
if err == nil {
break
}
}
if err != nil {
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
}
return
}

rawRequest, err := getQuoteRequest(ctx.Context(), relClient, tx)
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
_, err := ctx.Response().Reply("error fetching quote request")
if err != nil {
log.Println(err)
}
return
log.Println(err)
}
return
}

fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
isScreened, err := b.screener.ScreenAddress(ctx.Context(), rawRequest.Sender)
if err != nil {
_, err := ctx.Response().Reply("error screening address")
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return
log.Println(err)
}
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
return
}
if isScreened {
_, err := ctx.Response().Reply("address cannot be refunded")
if err != nil {
log.Printf("error submitting refund: %v\n", err)
continue
log.Println(err)
}
return
}

// TODO: follow the lead of https://github.com/synapsecns/sanguine/pull/2845
_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted with nonce %d", nonce))
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
if err != nil {
log.Println(err)
return nil, fmt.Errorf("error submitting refund: %w", err)
}
return tx, nil
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
return
}

var txHash *relapi.TxHashByNonceResponse
err = retry.WithBackoff(
ctx.Context(),
func(ctx context.Context) error {
txHash, err = relClient.GetTxHashByNonce(ctx, &relapi.GetTxByNonceRequest{
ChainID: rawRequest.OriginChainID,
Nonce: nonce,
})
if err != nil {
return fmt.Errorf("error fetching quote request: %w", err)
}
return nil
},
retry.WithMaxAttempts(3),
retry.WithMaxAttemptTime(15*time.Second),
)
if err != nil {
_, 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
}

_, err = ctx.Response().Reply(fmt.Sprintf("refund submitted: %s", toExplorerSlackLink(txHash.Hash)))
if err != nil {
log.Println(err)
}
},
}
}
Expand Down Expand Up @@ -389,19 +432,15 @@ func stripLinks(input string) string {
return linkRegex.ReplaceAllString(input, "$1")
}

func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (*relapi.GetQuoteRequestResponse, error) {
// at this point tx can be a txid or a has, we try both
txRequest, err := client.GetQuoteRequestByTxHash(ctx, tx)
if err == nil {
// override tx with txid
tx = txRequest.TxID
func getQuoteRequest(ctx context.Context, client relapi.RelayerClient, tx string) (qr *relapi.GetQuoteRequestResponse, err error) {
if qr, err = client.GetQuoteRequestByTxHash(ctx, tx); err == nil {
return qr, nil
}

// look up quote request
qr, err := client.GetQuoteRequestByTXID(ctx, tx)
if err != nil {
return nil, fmt.Errorf("error fetching quote request: %w", err)
if qr, err = client.GetQuoteRequestByTXID(ctx, tx); err == nil {
return qr, nil
}

return qr, nil
return nil, fmt.Errorf("error fetching quote request: %w", err)
}
4 changes: 3 additions & 1 deletion contrib/opbot/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package cmd

import (
"fmt"
"os"

"github.com/synapsecns/sanguine/contrib/opbot/botmd"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/metrics"

// used for testing.

_ "github.com/joho/godotenv/autoload"
"github.com/synapsecns/sanguine/contrib/opbot/config"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
"os"
)

var fileFlag = &cli.StringFlag{
Expand Down
5 changes: 4 additions & 1 deletion contrib/opbot/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config

import (
"errors"
"strings"

"github.com/synapsecns/sanguine/ethergo/signer/config"
submitterConfig "github.com/synapsecns/sanguine/ethergo/submitter/config"
"strings"
)

// Config represents the configuration of the application.
Expand Down Expand Up @@ -33,6 +34,8 @@ type Config struct {
Signer config.SignerConfig `yaml:"signer"`
// SubmitterConfig is the submitter config.
SubmitterConfig submitterConfig.Config `yaml:"submitter_config"`
// ScreenerConfig is the screener config.
ScreenerURL string `yaml:"screener_url"`
// Database is the database config.
Database DatabaseConfig `yaml:"database"`
}
Expand Down
2 changes: 2 additions & 0 deletions contrib/opbot/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/prometheus/prometheus v0.53.0
github.com/slack-go/slack v0.13.0
github.com/slack-io/slacker v0.1.1
github.com/synapsecns/sanguine/contrib/screener-api v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/core v0.0.0-00010101000000-000000000000
github.com/synapsecns/sanguine/ethergo v0.1.0
github.com/synapsecns/sanguine/services/cctp-relayer v0.0.0-00010101000000-000000000000
Expand Down Expand Up @@ -294,6 +295,7 @@ replace (
// later versions give errors on uint64 being too high.
github.com/brianvoe/gofakeit/v6 => github.com/brianvoe/gofakeit/v6 v6.9.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/synapsecns/sanguine/contrib/screener-api => ./../../contrib/screener-api
github.com/synapsecns/sanguine/core => ./../../core
github.com/synapsecns/sanguine/ethergo => ./../../ethergo
github.com/synapsecns/sanguine/services/cctp-relayer => ./../../services/cctp-relayer
Expand Down
8 changes: 8 additions & 0 deletions packages/rest-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.0.71](https://github.com/synapsecns/sanguine/compare/@synapsecns/rest-api@1.0.70...@synapsecns/rest-api@1.0.71) (2024-08-29)

**Note:** Version bump only for package @synapsecns/rest-api





## [1.0.70](https://github.com/synapsecns/sanguine/compare/@synapsecns/rest-api@1.0.69...@synapsecns/rest-api@1.0.70) (2024-08-26)

**Note:** Version bump only for package @synapsecns/rest-api
Expand Down
19 changes: 9 additions & 10 deletions packages/rest-api/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{
"name": "@synapsecns/rest-api",
"version": "1.0.70",
"version": "1.0.71",
"private": "true",
"engines": {
"node": ">=18.17.0"
},
"scripts": {
"test": "tsdx test",
"start": "node ./dist/app.js",
"dev": "yarn add @synapsecns/sdk-router && concurrently \"npx tsc --watch\" \"nodemon -q dist/app.js\"",
"test:coverage": "echo 'No tests defined.'",
"lint:fix": "eslint src/**.ts --fix",
"build": "tsc",
"start": "node dist/app.js",
"lint:fix": "eslint src/**/*.ts --fix",
"lint:check": "eslint . --max-warnings=0",
"ci:lint": "npm run lint:check",
"build:go": " ",
"build:slither": " ",
"build": "echo 'please run build api'",
"build:api": "yarn add @synapsecns/sdk-router && tsc",
"test": "tsdx test",
"test:coverage": "echo 'No tests defined.'",
"postinstall": "npm run build"
},
"dependencies": {
Expand All @@ -27,11 +23,14 @@
"bignumber": "^1.1.0",
"ethers": "5.7.2",
"express": "^4.18.2",
"lodash": "^4.17.21",
"supertest": "^6.3.3"
},
"description": "A node.js project exposing a rest api for synapse sdk quotes",
"devDependencies": {
"@types/supertest": "^6.0.2",
"concurrently": "^8.2.0",
"lodash": "^4.17.21",
"nodemon": "^3.0.1",
"typescript": "^4.8.3"
}
Expand Down
Loading

0 comments on commit 5541966

Please sign in to comment.