Skip to content

Commit

Permalink
RFQ Relayer: configure chain confirmations (#2967)
Browse files Browse the repository at this point in the history
* Feat: configure Confirmations

* [goreleaser]

* Fix: build

* [goreleaser]

* [goreleaser]
  • Loading branch information
dwasse authored Jul 31, 2024
1 parent 4be7c10 commit 85de949
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
26 changes: 17 additions & 9 deletions services/rfq/relayer/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/synapsecns/sanguine/ethergo/listener"
"github.com/synapsecns/sanguine/ethergo/submitter"
"github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/reldb"
)

Expand All @@ -30,21 +31,28 @@ type Chain struct {
}

// NewChain creates a new chain.
func NewChain(ctx context.Context, chainClient client.EVM, addr common.Address, chainListener listener.ContractListener, ts submitter.TransactionSubmitter) (*Chain, error) {
bridge, err := fastbridge.NewFastBridgeRef(addr, chainClient)
func NewChain(ctx context.Context, cfg relconfig.Config, chainClient client.EVM, chainListener listener.ContractListener, ts submitter.TransactionSubmitter) (*Chain, error) {
chainID, err := chainClient.ChainID(ctx)
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
}
addr, err := cfg.GetRFQAddress(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get rfq address: %w", err)
}
bridge, err := fastbridge.NewFastBridgeRef(common.HexToAddress(addr), chainClient)
if err != nil {
return nil, fmt.Errorf("could not create bridge contract: %w", err)
}
chainID, err := chainClient.ChainID(ctx)
confirmations, err := cfg.GetConfirmations(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
return nil, fmt.Errorf("could not get confirmations: %w", err)
}
return &Chain{
ChainID: uint32(chainID.Int64()),
Bridge: bridge,
Client: chainClient,
// TODO: configure
Confirmations: 1,
ChainID: uint32(chainID.Int64()),
Bridge: bridge,
Client: chainClient,
Confirmations: confirmations,
listener: chainListener,
submitter: ts,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions services/rfq/relayer/relapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewRelayerAPI(
}

chains := make(map[uint32]*chain.Chain)
for chainID, chainCfg := range cfg.Chains {
for chainID := range cfg.Chains {
chainClient, err := omniRPCClient.GetChainClient(ctx, chainID)
if err != nil {
return nil, fmt.Errorf("could not create omnirpc client: %w", err)
Expand All @@ -80,7 +80,7 @@ func NewRelayerAPI(
if err != nil {
return nil, fmt.Errorf("could not get chain listener: %w", err)
}
chains[uint32(chainID)], err = chain.NewChain(ctx, chainClient, common.HexToAddress(chainCfg.RFQAddress), chainListener, submitter)
chains[uint32(chainID)], err = chain.NewChain(ctx, cfg, chainClient, chainListener, submitter)
if err != nil {
return nil, fmt.Errorf("could not create chain: %w", err)
}
Expand Down
7 changes: 1 addition & 6 deletions services/rfq/relayer/service/statushandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,7 @@ func (r *Relayer) chainIDToChain(ctx context.Context, chainID uint32) (*chain.Ch
return nil, fmt.Errorf("could not get origin client: %w", err)
}

//nolint: wrapcheck
rfqAddr, err := r.cfg.GetRFQAddress(id)
if err != nil {
return nil, fmt.Errorf("could not get rfq address: %w", err)
}
chain, err := chain.NewChain(ctx, chainClient, common.HexToAddress(rfqAddr), r.chainListeners[id], r.submitter)
chain, err := chain.NewChain(ctx, r.cfg, chainClient, r.chainListeners[id], r.submitter)
if err != nil {
return nil, fmt.Errorf("could not create chain: %w", err)
}
Expand Down

0 comments on commit 85de949

Please sign in to comment.