Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
golangisfun123 committed Nov 4, 2024
1 parent a2d6461 commit d537d66
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions contrib/opbot/botmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d537d66

Please sign in to comment.