Skip to content

Commit

Permalink
[goreleaser]
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Jul 5, 2024
1 parent 2eba05a commit 07afb2a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 61 deletions.
97 changes: 36 additions & 61 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package botmd

import (
"context"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -19,7 +20,6 @@ import (
"log"
"math/big"
"regexp"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -246,28 +246,13 @@ func (b *Bot) rfqLookupCommand() *slacker.CommandDefinition {
}}
}

// nolint: gocognit, cyclop.
func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return &slacker.CommandDefinition{
Command: "refund <tx> <origin_chainid>",
Description: "refund a quote request",
Examples: []string{"refund 0x1234"},
Handler: func(ctx *slacker.CommandContext) {
client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
if err != nil {
log.Printf("error creating rfq client: %v\n", err)
return
}

contracts, err := client.GetRFQContracts(ctx.Context())
if err != nil {
log.Printf("error fetching rfq contracts: %v\n", err)
_, err = ctx.Response().Reply("error fetching rfq contracts")
if err != nil {
return
}
return
}

tx := stripLinks(ctx.Request().Param("tx"))

if len(tx) == 0 {
Expand All @@ -287,36 +272,6 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return

Check warning on line 272 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L266-L272

Added lines #L266 - L272 were not covered by tests
}

originChainID, err := strconv.Atoi(convertChainName(originChainIDStr))
if err != nil {
_, err := ctx.Response().Reply("origin_chainid must be a number")
if err != nil {
log.Println(err)
}
return
}

chainClient, err := b.rpcClient.GetChainClient(ctx.Context(), originChainID)
if err != nil {
log.Printf("error getting chain client: %v\n", err)
return
}

contractAddress, ok := contracts.Contracts[uint32(originChainID)]
if !ok {
_, err := ctx.Response().Reply("contract address not found")
if err != nil {
log.Println(err)
}
return
}

fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
if err != nil {
log.Printf("error creating fast bridge: %v\n", err)
return
}

for _, relayer := range b.cfg.RelayerURLS {
relClient := relapi.NewRelayerClient(b.handler, relayer)

Expand All @@ -329,16 +284,18 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
return

Check warning on line 284 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L275-L284

Added lines #L275 - L284 were not covered by tests
}

if rawRequest.OriginChainID != uint32(originChainID) {
_, err := ctx.Response().Reply("origin chain id does not match")
fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest)
if err != nil {
_, err := ctx.Response().Reply(err.Error())
if err != nil {
log.Println(err)
}
return

Check warning on line 293 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L287-L293

Added lines #L287 - L293 were not covered by tests
}

nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(originChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
return fastBridgeHandle.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))
nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
//nolint: wrapcheck.
return fastBridgeContract.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw))

Check failure on line 298 in contrib/opbot/botmd/commands.go

View workflow job for this annotation

GitHub Actions / Lint (contrib/opbot)

error returned from external package is unwrapped: sig: func (*github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge.FastBridgeTransactor).Refund(opts *github.com/ethereum/go-ethereum/accounts/abi/bind.TransactOpts, request []byte) (*github.com/ethereum/go-ethereum/core/types.Transaction, error) (wrapcheck)
})
if err != nil {
log.Printf("error submitting refund: %v\n", err)
Expand All @@ -356,6 +313,34 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition {
}
}

func (b *Bot) makeFastBridge(ctx context.Context, req *relapi.GetQuoteRequestResponse) (*fastbridge.FastBridge, error) {
client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL)
if err != nil {
return nil, fmt.Errorf("error creating rfq client: %w", err)
}

Check warning on line 320 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L316-L320

Added lines #L316 - L320 were not covered by tests

contracts, err := client.GetRFQContracts(ctx)
if err != nil {
return nil, fmt.Errorf("error fetching rfq contracts: %w", err)
}

Check warning on line 325 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L322-L325

Added lines #L322 - L325 were not covered by tests

chainClient, err := b.rpcClient.GetChainClient(ctx, int(req.OriginChainID))
if err != nil {
return nil, fmt.Errorf("error getting chain client: %w", err)
}

Check warning on line 330 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L327-L330

Added lines #L327 - L330 were not covered by tests

contractAddress, ok := contracts.Contracts[req.OriginChainID]
if !ok {
return nil, errors.New("contract address not found")
}

Check warning on line 335 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L332-L335

Added lines #L332 - L335 were not covered by tests

fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient)
if err != nil {
return nil, fmt.Errorf("error creating fast bridge: %w", err)
}
return fastBridgeHandle, nil

Check warning on line 341 in contrib/opbot/botmd/commands.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/botmd/commands.go#L337-L341

Added lines #L337 - L341 were not covered by tests
}

func toExplorerSlackLink(ogHash string) string {
rfqHash := strings.ToUpper(ogHash)
// cut off 0x
Expand All @@ -382,16 +367,6 @@ func stripLinks(input string) string {
return linkRegex.ReplaceAllString(input, "$1")
}

// convertChainName detects if the string contains letters and if it does, tries to convert it to a chain id.
// otherwise return the original string
func convertChainName(input string) string {
res := chaindata.ChainNameToChainID(input)
if res != 0 {
return strconv.Itoa(int(res))
}
return input
}

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.GetQuoteRequestStatusByTxHash(ctx, tx)
Expand Down
1 change: 1 addition & 0 deletions contrib/opbot/sql/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewSqliteStore(parentCtx context.Context, dbPath string, handler metrics.Ha
}()

Check warning on line 31 in contrib/opbot/sql/sqlite/sqlite.go

View check run for this annotation

Codecov / codecov/patch

contrib/opbot/sql/sqlite/sqlite.go#L25-L31

Added lines #L25 - L31 were not covered by tests

// create the directory to the store if it doesn't exist
//nolint: gosec.
err = os.MkdirAll(dbPath, os.ModePerm)
if err != nil {
return nil, fmt.Errorf("could not create sqlite store")
Expand Down

0 comments on commit 07afb2a

Please sign in to comment.