From c5659ed63b80d72ae1dadb9f42e8af900b05434b Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Fri, 18 Oct 2024 11:51:21 -0500 Subject: [PATCH 1/9] add additional check --- contrib/opbot/botmd/commands.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index b72f4ff7c2..242ef45428 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -336,6 +336,22 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } + isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) + if err != nil { + _, err := ctx.Response().Reply("error fetching bridge relays") + if err != nil { + log.Println(err) + } + return + } + if isRelayed { + _, err := ctx.Response().Reply("transaction has already been relayed") + if err != nil { + log.Println(err) + } + return + } + 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 { From a2d6461f6fbe088ace46e0428b58e3e125391dad Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Mon, 4 Nov 2024 11:18:37 -0600 Subject: [PATCH 2/9] return origin and destination contracts [goreleaser] --- contrib/opbot/botmd/commands.go | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 242ef45428..0ca9c13a68 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -4,7 +4,6 @@ package botmd import ( "context" - "errors" "fmt" "log" "math/big" @@ -311,7 +310,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } - fastBridgeContract, err := b.makeFastBridge(ctx.Context(), rawRequest) + fastBridgeContractOrigin, fastBridgeContractDest, err := b.makeFastBridge(ctx.Context(), rawRequest) if err != nil { _, err := ctx.Response().Reply(err.Error()) if err != nil { @@ -336,7 +335,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } - isRelayed, err := fastBridgeContract.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) + isRelayed, err := fastBridgeContractDest.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) if err != nil { _, err := ctx.Response().Reply("error fetching bridge relays") if err != nil { @@ -353,7 +352,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } 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)) + tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.QuoteRequestRaw)) if err != nil { return nil, fmt.Errorf("error submitting refund: %w", err) } @@ -393,32 +392,41 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } } -func (b *Bot) makeFastBridge(ctx context.Context, req *relapi.GetQuoteRequestResponse) (*fastbridge.FastBridge, error) { +// returns origin and dest fast bridge contracts +func (b *Bot) makeFastBridge(ctx context.Context, req *relapi.GetQuoteRequestResponse) (*fastbridge.FastBridge, *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) + return nil, nil, fmt.Errorf("error creating rfq client: %w", err) } contracts, err := client.GetRFQContracts(ctx) if err != nil { - return nil, fmt.Errorf("error fetching rfq contracts: %w", err) + return nil, nil, fmt.Errorf("error fetching rfq contracts: %w", err) } - chainClient, err := b.rpcClient.GetChainClient(ctx, int(req.OriginChainID)) - if err != nil { - return nil, fmt.Errorf("error getting chain client: %w", err) - } + var fastBridges [2]*fastbridge.FastBridge + chainIDs := []uint32{req.OriginChainID, req.DestChainID} - contractAddress, ok := contracts.Contracts[req.OriginChainID] - if !ok { - return nil, errors.New("contract address not found") - } + for i, chainID := range chainIDs { + chainClient, err := b.rpcClient.GetChainClient(ctx, int(chainID)) + if err != nil { + return nil, nil, fmt.Errorf("error getting chain client for chain ID %d: %w", chainID, err) + } - fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient) - if err != nil { - return nil, fmt.Errorf("error creating fast bridge: %w", err) + contractAddress, ok := contracts.Contracts[chainID] + if !ok { + return nil, nil, fmt.Errorf("contract address not found for chain ID %d", chainID) + } + + fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient) + if err != nil { + return nil, nil, fmt.Errorf("error creating fast bridge for chain ID %d: %w", chainID, err) + } + + fastBridges[i] = fastBridgeHandle } - return fastBridgeHandle, nil + + return fastBridges[0], fastBridges[1], nil } func getTxAge(ctx context.Context, client client.EVM, res *relapi.GetQuoteRequestResponse) string { From d537d663fda4ef1d0057cf1f38bd69a6e30c80a1 Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Mon, 4 Nov 2024 14:51:04 -0600 Subject: [PATCH 3/9] fixed --- contrib/opbot/botmd/commands.go | 50 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 0ca9c13a68..623431565a 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -310,7 +310,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } - fastBridgeContractOrigin, fastBridgeContractDest, err := b.makeFastBridge(ctx.Context(), rawRequest) + fastBridgeContractOrigin, err := b.makeFastBridge(ctx.Context(), rawRequest.OriginChainID) if err != nil { _, err := ctx.Response().Reply(err.Error()) if err != nil { @@ -335,6 +335,15 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } + fastBridgeContractDest, err := b.makeFastBridge(ctx.Context(), rawRequest.DestChainID) + if err != nil { + _, err := ctx.Response().Reply(err.Error()) + if err != nil { + log.Println(err) + } + return + } + isRelayed, err := fastBridgeContractDest.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) if err != nil { _, err := ctx.Response().Reply("error fetching bridge relays") @@ -392,41 +401,34 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } } -// returns origin and dest fast bridge contracts -func (b *Bot) makeFastBridge(ctx context.Context, req *relapi.GetQuoteRequestResponse) (*fastbridge.FastBridge, *fastbridge.FastBridge, error) { +func (b *Bot) makeFastBridge(ctx context.Context, chainID uint32) (*fastbridge.FastBridge, error) { client, err := rfqClient.NewUnauthenticatedClient(b.handler, b.cfg.RFQApiURL) if err != nil { - return nil, nil, fmt.Errorf("error creating rfq client: %w", err) + return nil, fmt.Errorf("error creating rfq client: %w", err) } contracts, err := client.GetRFQContracts(ctx) if err != nil { - return nil, nil, fmt.Errorf("error fetching rfq contracts: %w", err) + return nil, fmt.Errorf("error fetching rfq contracts: %w", err) } - var fastBridges [2]*fastbridge.FastBridge - chainIDs := []uint32{req.OriginChainID, req.DestChainID} - - for i, chainID := range chainIDs { - chainClient, err := b.rpcClient.GetChainClient(ctx, int(chainID)) - if err != nil { - return nil, nil, fmt.Errorf("error getting chain client for chain ID %d: %w", chainID, err) - } - - contractAddress, ok := contracts.Contracts[chainID] - if !ok { - return nil, nil, fmt.Errorf("contract address not found for chain ID %d", chainID) - } + chainClient, err := b.rpcClient.GetChainClient(ctx, int(chainID)) + if err != nil { + return nil, fmt.Errorf("error getting chain client for chain ID %d: %w", chainID, err) + } - fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient) - if err != nil { - return nil, nil, fmt.Errorf("error creating fast bridge for chain ID %d: %w", chainID, err) - } + contractAddress, ok := contracts.Contracts[chainID] + if !ok { + return nil, fmt.Errorf("contract address not found for chain ID %d", chainID) + } - fastBridges[i] = fastBridgeHandle + fastBridgeHandle, err := fastbridge.NewFastBridge(common.HexToAddress(contractAddress), chainClient) + if err != nil { + return nil, fmt.Errorf("error creating fast bridge for chain ID %d: %w", chainID, err) } - return fastBridges[0], fastBridges[1], nil + return fastBridgeHandle, nil + } func getTxAge(ctx context.Context, client client.EVM, res *relapi.GetQuoteRequestResponse) string { From 077bc5186f641ee87fd619eaa6986e84f6fac8a5 Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Mon, 4 Nov 2024 14:51:22 -0600 Subject: [PATCH 4/9] [goreleaser] From 134cbf55fe886a5de7b6c6755b6eb70e1c48b112 Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Mon, 4 Nov 2024 15:53:00 -0600 Subject: [PATCH 5/9] [goreleaser] --- contrib/opbot/botmd/commands.go | 12 ++++++++++-- core/bytes.go | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 623431565a..c5466cfe69 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -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" "github.com/synapsecns/sanguine/core/retry" "github.com/synapsecns/sanguine/ethergo/chaindata" "github.com/synapsecns/sanguine/ethergo/client" @@ -343,8 +344,15 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } return } - - isRelayed, err := fastBridgeContractDest.BridgeRelays(nil, [32]byte(common.Hex2Bytes(rawRequest.TxID))) + txBz, err := core.BytesToArray(common.Hex2Bytes(rawRequest.TxID)) + if err != nil { + _, err := ctx.Response().Reply("error converting tx id") + if err != nil { + log.Println(err) + } + return + } + isRelayed, err := fastBridgeContractDest.BridgeRelays(nil, txBz) if err != nil { _, err := ctx.Response().Reply("error fetching bridge relays") if err != nil { diff --git a/core/bytes.go b/core/bytes.go index ee25375e62..adca7464b3 100644 --- a/core/bytes.go +++ b/core/bytes.go @@ -25,3 +25,11 @@ func BytesToJSONString(bz []byte) (string, error) { return string(formattedJSON), nil } +func BytesToArray(bz []byte) ([32]byte, error) { + var bytes [32]byte + if len(bz) != 32 { + return bytes, fmt.Errorf("invalid length of bytes: %d", len(bz)) + } + copy(bytes[:], bz) + return bytes, nil +} From ffe317909aa2f7e28a455f5e5ab488c25a3ce18b Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Mon, 4 Nov 2024 19:49:40 -0600 Subject: [PATCH 6/9] fix lint [goreleaser] --- core/bytes.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/bytes.go b/core/bytes.go index adca7464b3..5b766116ce 100644 --- a/core/bytes.go +++ b/core/bytes.go @@ -25,6 +25,8 @@ func BytesToJSONString(bz []byte) (string, error) { return string(formattedJSON), nil } + +// BytesToArray converts a slice to a 32 length byte array. func BytesToArray(bz []byte) ([32]byte, error) { var bytes [32]byte if len(bz) != 32 { From 15a282a028f2d3264a4488615552199f9e8b8c2f Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Thu, 7 Nov 2024 10:07:20 -0600 Subject: [PATCH 7/9] format [goreleaser] --- contrib/opbot/botmd/commands.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 2b5db81937..1af798d3ca 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -306,8 +306,9 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } - nonce, err := b.submitter.SubmitTransaction(ctx.Context(), big.NewInt(int64(rawRequest.Bridge.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request)) + nonce, err := b.submitter.SubmitTransaction( + ctx.Context(), big.NewInt(int64(rawRequest.Bridge.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { + tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request[2:])) if err != nil { return nil, fmt.Errorf("error submitting refund: %w", err) } From 692228ff97d45fe7eb7f46454f68a1a6cffae024 Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Thu, 7 Nov 2024 10:10:36 -0600 Subject: [PATCH 8/9] remove 0x [goreleaser] --- contrib/opbot/botmd/commands.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 1af798d3ca..9508ff81fc 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -282,7 +282,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } return } - txBz, err := core.BytesToArray(common.Hex2Bytes(rawRequest.Bridge.TransactionID)) + txBz, err := core.BytesToArray(common.Hex2Bytes(rawRequest.Bridge.TransactionID[2:])) if err != nil { _, err := ctx.Response().Reply("error converting tx id") if err != nil { @@ -307,13 +307,15 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { } nonce, err := b.submitter.SubmitTransaction( - ctx.Context(), big.NewInt(int64(rawRequest.Bridge.OriginChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { - tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request[2:])) - if err != nil { - return nil, fmt.Errorf("error submitting refund: %w", err) - } - return tx, nil - }) + ctx.Context(), + big.NewInt(int64(rawRequest.Bridge.OriginChainID)), + func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { + tx, err = fastBridgeContractOrigin.Refund(transactor, common.Hex2Bytes(rawRequest.Bridge.Request[2:])) + if err != nil { + return nil, fmt.Errorf("error submitting refund: %w", err) + } + return tx, nil + }) if err != nil { log.Printf("error submitting refund: %v\n", err) return From 3bc396671b1b2a34d377a0b807b5877e9f870373 Mon Sep 17 00:00:00 2001 From: golangisfun123 Date: Thu, 7 Nov 2024 10:25:29 -0600 Subject: [PATCH 9/9] fix lint --- contrib/opbot/botmd/commands.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/opbot/botmd/commands.go b/contrib/opbot/botmd/commands.go index 9508ff81fc..bf49c6a98f 100644 --- a/contrib/opbot/botmd/commands.go +++ b/contrib/opbot/botmd/commands.go @@ -249,6 +249,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } + //nolint: gosec fastBridgeContractOrigin, err := b.makeFastBridge(ctx.Context(), uint32(rawRequest.Bridge.OriginChainID)) if err != nil { _, err := ctx.Response().Reply(err.Error()) @@ -274,6 +275,7 @@ func (b *Bot) rfqRefund() *slacker.CommandDefinition { return } + //nolint:gosec fastBridgeContractDest, err := b.makeFastBridge(ctx.Context(), uint32(rawRequest.Bridge.DestChainID)) if err != nil { _, err := ctx.Response().Reply(err.Error())