Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CCTP rebalancing to RFQ relayer #2073

Merged
merged 80 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
3a73d21
Feat: relconfig Bridge -> RFQAddress, add CCTPAddress
dwasse Feb 20, 2024
6664fd9
Feat: add RebalanceMethod enum
dwasse Feb 20, 2024
91017b7
Feat: add MaintenanceBalancePct and InitialBalancePct
dwasse Feb 20, 2024
f7d56f2
Feat: add RebalanceMethodNone
dwasse Feb 20, 2024
cbf01e7
Feat: add Rebalance() to inventory manager
dwasse Feb 20, 2024
512fb30
Cleanup: remove rebalance.go
dwasse Feb 20, 2024
536f227
Feat: add submitter to inventory manager
dwasse Feb 20, 2024
1e9e1d6
Cleanup: Adress -> Address
dwasse Feb 20, 2024
708eab0
WIP: add Rebalance() impl to inventory manager
dwasse Feb 20, 2024
eabdda0
Feat: add token address and chain id to tokenMetadata
dwasse Feb 20, 2024
1f7c3a3
Cleanup: utilize new tokenMetadata fields
dwasse Feb 20, 2024
44be2b3
Feat: add approval for CCTP bridge
dwasse Feb 20, 2024
d2acc79
Feat: impl rebalanceCCTP()
dwasse Feb 20, 2024
4ad03dc
Fix: regenerate
dwasse Feb 21, 2024
7c0cf7e
Cleanup: lint
dwasse Feb 21, 2024
fda6f90
WIP: export inventory structs for use in tests
dwasse Feb 21, 2024
4db711f
Feat: add TestGetRebalance
dwasse Feb 21, 2024
06e8e57
Feat: add rebalance case to TestGetRebalance
dwasse Feb 21, 2024
6b38ba5
Cleanup: remove duplicate data from RebalanceData
dwasse Feb 21, 2024
90a63e6
Feat: address rebalance case where origin chain cannot pass initial t…
dwasse Feb 21, 2024
6c70e96
Cleanup: regenerate inventory
dwasse Feb 21, 2024
3d561b0
Feat: remove handleClaimCompleted and move Rebalance() call to chaini…
dwasse Feb 21, 2024
e5868de
Feat: enforce rebalance methods to match from config
dwasse Feb 21, 2024
eca3b63
WIP: set rebalance params in e2e test
dwasse Feb 21, 2024
383ece0
WIP: add Rebalance interface and rebalanceManagerCCTP
dwasse Feb 21, 2024
0095c7c
Feat: add Start() to inventory manager
dwasse Feb 21, 2024
58c8a7f
Feat: add rebalance db models and functions
dwasse Feb 21, 2024
5aeb2c5
Feat: rebalance manager listens for cctp events and updates db
dwasse Feb 22, 2024
baab066
Feat: rebalance on interval instead of on DepositClaimed
dwasse Feb 22, 2024
752763b
Cleanup: DBSelectorIntervalSeconds -> DBSelectorInterval
dwasse Feb 22, 2024
ab90a63
Feat: check for pending rebalances
dwasse Feb 22, 2024
989c2d5
Feat: attempt rebalance on DepositClaimed
dwasse Feb 22, 2024
73e027d
Cleanup: lint
dwasse Feb 22, 2024
a4e308c
Fix: start inventory manager
dwasse Feb 23, 2024
03891fb
WIP: add cctp contract setup for integration test
dwasse Feb 23, 2024
c9ca663
WIP: use origin instead of origin tx hash for rebalance updating
dwasse Feb 26, 2024
81cfc79
WIP: enforce only one row affected in rebalance update
dwasse Feb 26, 2024
3a6ea21
WIP: don't track origin tx hash for now
dwasse Feb 26, 2024
42f24ce
WIP: logs
dwasse Feb 26, 2024
ed841c8
WIP: working test with MockMintBurnToken
dwasse Feb 27, 2024
628733d
WIP: adjust amounts
dwasse Feb 27, 2024
efaf3bd
WIP: fix approvals
dwasse Feb 27, 2024
1e7175f
Feat: remove fastbridge ref from chain listener
dwasse Feb 27, 2024
5c99c21
Feat: use iota+1 for rebalance status, regen model
dwasse Feb 27, 2024
8fcfbcb
WIP: don't return error in listener handler
dwasse Feb 27, 2024
88de62a
Feat: check for pending rebalances in integration test
dwasse Feb 27, 2024
ce32aa9
Cleanup: remove balance logs
dwasse Feb 27, 2024
819dd14
Cleanup: logs / comments
dwasse Feb 27, 2024
5f4486b
Cleanup: dedup code in inv manager
dwasse Feb 27, 2024
c8f2c67
Cleanup: lints
dwasse Feb 27, 2024
b7dd419
Feat: add CCTPStartBlock to relconfig
dwasse Feb 27, 2024
53e8129
[goreleaser]
dwasse Feb 27, 2024
2e33da3
Cleanup: lints
dwasse Feb 27, 2024
45c2ad9
Cleanup: lints
dwasse Feb 27, 2024
ba58876
add directive (#2122)
trajan0x Feb 28, 2024
4febe40
Feat: move listener to ethergo/chain/listener package
dwasse Feb 28, 2024
000549f
Merge branch 'feat/relayer-rebalance' of github.com:synapsecns/sangui…
dwasse Feb 28, 2024
ceb8479
[goreleaser]
dwasse Feb 28, 2024
19dc080
Cleanup: lints
dwasse Feb 28, 2024
085ac5e
update db
trajan0x Feb 28, 2024
782b869
Cleanup: remove unnecessary errgroup
dwasse Feb 28, 2024
6195502
Merge branch 'master' into feat/relayer-rebalance
dwasse Feb 28, 2024
07dbaeb
[goreleaser]
dwasse Feb 28, 2024
7a9a30b
fast
trajan0x Feb 29, 2024
f2d7ab8
cleanup
trajan0x Feb 29, 2024
cd760c2
more cleanup
trajan0x Feb 29, 2024
4055168
Merge pull request #2129 from synapsecns/feat/relayer-rebalance-gener…
trajan0x Feb 29, 2024
7ff3b2a
[goreleaser]
trajan0x Feb 29, 2024
d91525a
Feat: add tracing
dwasse Feb 29, 2024
ecbdc0e
Merge branch 'feat/relayer-rebalance' of github.com:synapsecns/sangui…
dwasse Feb 29, 2024
edeeb0e
[goreleaser]
dwasse Feb 29, 2024
5743f58
Feat: add more tracing around rebalance trigger
dwasse Mar 1, 2024
d8deade
[goreleaser]
dwasse Mar 1, 2024
e1296a4
Feat: add MaxRebalanceAmount and getter test
dwasse Mar 1, 2024
edae452
Feat: incorporate MaxRebalanceAmount and test
dwasse Mar 1, 2024
ab2a9ab
Feat: use big.Float for MaxRebalanceAmount parsing
dwasse Mar 1, 2024
996a82b
[goreleaser]
dwasse Mar 1, 2024
93a1e04
Feat: add check for address match in cctp event
dwasse Mar 1, 2024
b0f9d22
[goreleaser]
dwasse Mar 1, 2024
3285fe6
Cleanup: lint
dwasse Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions services/rfq/e2e/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (i *IntegrationSuite) setupRelayer() {
// generated ex-post facto
Chains: map[int]relconfig.ChainConfig{
originBackendChainID: {
Bridge: i.manager.Get(i.GetTestContext(), i.originBackend, testutil.FastBridgeType).Address().String(),
RFQAddress: i.manager.Get(i.GetTestContext(), i.originBackend, testutil.FastBridgeType).Address().String(),
Confirmations: 0,
Tokens: map[string]relconfig.TokenConfig{
"ETH": {
Expand All @@ -209,7 +209,7 @@ func (i *IntegrationSuite) setupRelayer() {
NativeToken: "ETH",
},
destBackendChainID: {
Bridge: i.manager.Get(i.GetTestContext(), i.destBackend, testutil.FastBridgeType).Address().String(),
RFQAddress: i.manager.Get(i.GetTestContext(), i.destBackend, testutil.FastBridgeType).Address().String(),
Confirmations: 0,
Tokens: map[string]relconfig.TokenConfig{
"ETH": {
Expand Down
212 changes: 199 additions & 13 deletions services/rfq/relayer/inventory/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/ethergo/submitter"
"github.com/synapsecns/sanguine/services/cctp-relayer/contracts/cctp"
"github.com/synapsecns/sanguine/services/rfq/contracts/ierc20"
"github.com/synapsecns/sanguine/services/rfq/relayer/chain"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
Expand All @@ -39,9 +40,12 @@
// GetCommittableBalances gets the total balances committable for all tracked tokens.
GetCommittableBalances(ctx context.Context, options ...BalanceFetchArgOption) (map[int]map[common.Address]*big.Int, error)
// ApproveAllTokens approves all tokens for the relayer address.
ApproveAllTokens(ctx context.Context, submitter submitter.TransactionSubmitter) error
ApproveAllTokens(ctx context.Context) error
// HasSufficientGas checks if there is sufficient gas for a given route.
HasSufficientGas(ctx context.Context, origin, dest int) (bool, error)
// Rebalance checks whether a given token should be rebalanced, and
// executes the rebalance if necessary.
Rebalance(ctx context.Context, chainID int, token common.Address) error
Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Rebalance method is a significant addition, implementing the core functionality of token rebalancing. It's crucial to ensure this method is thoroughly tested, especially given its impact on the inventory management system's reliability and accuracy.

Would you like assistance in creating unit tests for the Rebalance method?

}

type inventoryManagerImpl struct {
Expand All @@ -59,7 +63,12 @@
relayerAddress common.Address
// chainClient is an omnirpc client
chainClient submitter.ClientFetcher
db reldb.Service
// txSubmitter is the transaction submitter
txSubmitter submitter.TransactionSubmitter
// cctpContracts is the map of cctp contracts (used for rebalancing)
cctpContracts map[int]*cctp.SynapseCCTP
// db is the database
db reldb.Service
}

// GetCommittableBalance gets the committable balances.
Expand Down Expand Up @@ -122,6 +131,8 @@
decimals uint8
startAllowance *big.Int
isGasToken bool
chainID int
addr common.Address
}

var (
Expand All @@ -135,12 +146,15 @@
const defaultPollPeriod = 5

// NewInventoryManager creates a list of tokens we should use.
func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetcher, handler metrics.Handler, cfg relconfig.Config, relayer common.Address, db reldb.Service) (Manager, error) {
// TODO: too many args here

Check failure on line 149 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

Comment should end in a period (godot)
func NewInventoryManager(ctx context.Context, clientFetcher submitter.ClientFetcher, handler metrics.Handler, cfg relconfig.Config, relayer common.Address, txSubmitter submitter.TransactionSubmitter, db reldb.Service) (Manager, error) {
i := inventoryManagerImpl{
relayerAddress: relayer,
handler: handler,
cfg: cfg,
chainClient: clientFetcher,
txSubmitter: txSubmitter,
cctpContracts: make(map[int]*cctp.SynapseCCTP),
db: db,
}

Expand Down Expand Up @@ -173,7 +187,7 @@
const maxBatchSize = 10

// ApproveAllTokens approves all checks if allowance is set and if not approves.
func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context, submitter submitter.TransactionSubmitter) error {
func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) error {

Check failure on line 190 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

cognitive complexity 41 of func `(*inventoryManagerImpl).ApproveAllTokens` is high (> 30) (gocognit)
i.mux.RLock()
defer i.mux.RUnlock()

Expand All @@ -185,25 +199,46 @@

for address, token := range tokenMap {
// if startAllowance is 0
if address != chain.EthAddress && token.startAllowance.Cmp(big.NewInt(0)) == 0 {

Check failure on line 202 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

`if address != chain.EthAddress && token.startAllowance.Cmp(big.NewInt(0)) == 0` has complex nested blocks (complexity: 7) (nestif)
chainID := chainID // capture func literal
address := address // capture func literal
// init an approval in submitter. Note: in the case where submitter hasn't finished from last boot, this will double submit approvals unfortanutely
_, err = submitter.SubmitTransaction(ctx, big.NewInt(int64(chainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
erc20, err := ierc20.NewIERC20(address, backendClient)

erc20, err := ierc20.NewIERC20(address, backendClient)
if err != nil {
return fmt.Errorf("could not get erc20: %w", err)
}

// init an approval for RFQ bridge in submitter. Note: in the case where submitter hasn't finished from last boot, this will double submit approvals unfortanutely
_, err = i.txSubmitter.SubmitTransaction(ctx, big.NewInt(int64(chainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
rfqAddr, err := i.cfg.GetRFQAddress(chainID)
if err != nil {
return nil, fmt.Errorf("could not get erc20: %w", err)
return nil, fmt.Errorf("could not get rfq address: %w", err)
}
tx, err = erc20.Approve(transactor, common.HexToAddress(rfqAddr), abi.MaxInt256)
if err != nil {
return nil, fmt.Errorf("could not approve rfq: %w", err)
}
return tx, nil
})
if err != nil {
return fmt.Errorf("could not submit RFQ approval: %w", err)
}

approveAmount, err := erc20.Approve(transactor, common.HexToAddress(i.cfg.Chains[chainID].Bridge), abi.MaxInt256)
// approve CCTP bridge, if configured
_, err = i.txSubmitter.SubmitTransaction(ctx, big.NewInt(int64(chainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
cctpAddr, err := i.cfg.GetCCTPAddress(chainID)
if err != nil {
return nil, fmt.Errorf("could not approve: %w", err)
return nil, fmt.Errorf("could not get cctp address: %w", err)
}
tx, err = erc20.Approve(transactor, common.HexToAddress(cctpAddr), abi.MaxInt256)
if err != nil {
return nil, fmt.Errorf("could not approve cctp: %w", err)
}

return approveAmount, nil
return tx, nil
})
if err != nil {
return fmt.Errorf("could not submit approval: %w", err)
return fmt.Errorf("could not submit CCTP approval: %w", err)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [190-242]

The updated logic in ApproveAllTokens to handle approvals for both RFQ and CCTP bridges is crucial for the new functionality. Ensure that error handling is robust, especially in the context of transaction submissions. Consider adding more detailed logging for each step to aid in debugging and monitoring.

Consider enhancing error logging with more context, such as the chain ID and token address, to improve traceability in case of failures.

Expand All @@ -230,6 +265,151 @@
return sufficient, nil
}

// Rebalance checks whether a given token should be rebalanced, and executes the rebalance if necessary.
// Note that if there are multiple tokens whose balance is below the maintenance balance, only the lowest balance
// will be rebalanced.
func (i *inventoryManagerImpl) Rebalance(ctx context.Context, chainID int, token common.Address) error {
method, err := i.cfg.GetRebalanceMethod(chainID, token.Hex())
if err != nil {
return fmt.Errorf("could not get rebalance method: %w", err)
}
if method == relconfig.RebalanceMethodNone {
return nil
}

err = i.refreshBalances(ctx)
if err != nil {
return fmt.Errorf("could not refresh balances: %w", err)
}

rebalance, err := i.getRebalance(ctx, chainID, token)
if err != nil {
return fmt.Errorf("could not get rebalance: %w", err)
}
if rebalance == nil {
return nil
}

switch method {

Check failure on line 293 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

missing cases in switch of type relconfig.RebalanceMethod: relconfig.RebalanceMethodNone, relconfig.RebalanceMethodNative (exhaustive)
case relconfig.RebalanceMethodCCTP:
return i.rebalanceCCTP(ctx, rebalance)
default:
return fmt.Errorf("unknown rebalance method: %s", method)
}
}

// rebalanceData contains metadata for a rebalance action.
type rebalanceData struct {
origin int
dest int
originMetadata *tokenMetadata
destMetadata *tokenMetadata
amount *big.Int
}

func (i *inventoryManagerImpl) getRebalance(ctx context.Context, chainID int, token common.Address) (rebalance *rebalanceData, err error) {

Check warning on line 310 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
maintenancePct, err := i.cfg.GetMaintenanceBalancePct(chainID, token.Hex())
if err != nil {
return nil, fmt.Errorf("could not get maintenance pct: %w", err)
}

// get token metadata
var rebalanceTokenData *tokenMetadata
for address, tokenData := range i.tokens[chainID] {
if address == token {
rebalanceTokenData = tokenData
break
}
}

// get total balance for given token across all chains
totalBalance := big.NewInt(0)
for _, tokenMap := range i.tokens {
for _, tokenData := range tokenMap {
if tokenData.name == rebalanceTokenData.name {
totalBalance.Add(totalBalance, tokenData.balance)
}
}
}

// check if any balances are below maintenance threshold
var minTokenData, maxTokenData *tokenMetadata
for _, tokenMap := range i.tokens {
for _, tokenData := range tokenMap {
if tokenData.name == rebalanceTokenData.name {
if minTokenData == nil || minTokenData.balance.Cmp(minTokenData.balance) < 0 {

Check failure on line 340 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

dupArg: suspicious method call with the same argument and receiver (gocritic)
minTokenData = tokenData
}
if maxTokenData == nil || maxTokenData.balance.Cmp(maxTokenData.balance) > 0 {

Check failure on line 343 in services/rfq/relayer/inventory/manager.go

View workflow job for this annotation

GitHub Actions / Lint (services/rfq)

dupArg: suspicious method call with the same argument and receiver (gocritic)
maxTokenData = tokenData
}
}
}
}

// get the initialPct for the origin chain
initialPct, err := i.cfg.GetInitialBalancePct(maxTokenData.chainID, maxTokenData.addr.Hex())
if err != nil {
return nil, fmt.Errorf("could not get initial pct: %w", err)
}

// check if the minimum balance is below the threshold and trigger rebalance
maintenanceThresh, _ := new(big.Float).Mul(new(big.Float).SetInt(totalBalance), big.NewFloat(maintenancePct)).Int(nil)
if minTokenData.balance.Cmp(maintenanceThresh) < 0 {
initialThresh, _ := new(big.Float).Mul(new(big.Float).SetInt(totalBalance), big.NewFloat(initialPct)).Int(nil)
amount := new(big.Int).Sub(maxTokenData.balance, initialThresh)
rebalance = &rebalanceData{
origin: maxTokenData.chainID,
dest: minTokenData.chainID,
originMetadata: maxTokenData,
destMetadata: minTokenData,
amount: amount,
}
}
return rebalance, nil
}

func (i *inventoryManagerImpl) rebalanceCCTP(ctx context.Context, rebalance *rebalanceData) (err error) {
// fetch the corresponding CCTP contract
contract, ok := i.cctpContracts[rebalance.dest]
if !ok {
contractAddr, err := i.cfg.GetCCTPAddress(rebalance.origin)
if err != nil {
return fmt.Errorf("could not get cctp address: %w", err)
}
chainClient, err := i.chainClient.GetClient(ctx, big.NewInt(int64(rebalance.origin)))
if err != nil {
return fmt.Errorf("could not get chain client: %w", err)
}
contract, err = cctp.NewSynapseCCTP(common.HexToAddress(contractAddr), chainClient)
if err != nil {
return fmt.Errorf("could not get cctp: %w", err)
}
i.cctpContracts[rebalance.dest] = contract
}

// perform rebalance by calling sendCircleToken()
_, err = i.txSubmitter.SubmitTransaction(ctx, big.NewInt(int64(rebalance.originMetadata.chainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) {
tx, err = contract.SendCircleToken(
transactor,
i.relayerAddress,
big.NewInt(int64(rebalance.destMetadata.chainID)),
rebalance.originMetadata.addr,
rebalance.amount,
0, // TODO: inspect
[]byte{}, // TODO: inspect
)
if err != nil {
return nil, fmt.Errorf("could not send circle token: %w", err)
}
return tx, nil
})
if err != nil {
return fmt.Errorf("could not submit CCTP rebalance: %w", err)
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rebalanceCCTP method performs the actual rebalancing operation using the CCTP bridge. Ensure that the contract interaction logic is secure and correctly handles potential errors. The use of placeholders (0 and []byte{}) in the SendCircleToken call should be reviewed and replaced with actual values if necessary.

Consider replacing the placeholders in the SendCircleToken call with actual values or configurations, as these might impact the functionality of the rebalancing operation.

}

// initializes tokens converts the configuration into a data structure we can use to determine inventory
// it gets metadata like name, decimals, etc once and exports these to prometheus for ease of debugging.
func (i *inventoryManagerImpl) initializeTokens(parentCtx context.Context, cfg relconfig.Config) (err error) {
Expand Down Expand Up @@ -274,6 +454,7 @@
}
rtoken := &tokenMetadata{
isGasToken: tokenName == nativeToken,
chainID: chainID,
}

var token common.Address
Expand All @@ -283,6 +464,7 @@
token = common.HexToAddress(tokenCfg.Address)
}
i.tokens[chainID][token] = rtoken
rtoken.addr = token

// requires non-nil pointer
rtoken.balance = new(big.Int)
Expand All @@ -294,11 +476,15 @@
rtoken.balance = i.gasBalances[chainID]
// TODO: start allowance?
} else {
rfqAddr, err := cfg.GetRFQAddress(chainID)
if err != nil {
return fmt.Errorf("could not get rfq address: %w", err)
}
deferredCalls[chainID] = append(deferredCalls[chainID],
eth.CallFunc(funcBalanceOf, token, i.relayerAddress).Returns(rtoken.balance),
eth.CallFunc(funcDecimals, token).Returns(&rtoken.decimals),
eth.CallFunc(funcName, token).Returns(&rtoken.name),
eth.CallFunc(funcAllowance, token, i.relayerAddress, common.HexToAddress(i.cfg.Chains[chainID].Bridge)).Returns(rtoken.startAllowance),
eth.CallFunc(funcAllowance, token, i.relayerAddress, common.HexToAddress(rfqAddr)).Returns(rtoken.startAllowance),
)
}

Expand Down
17 changes: 8 additions & 9 deletions services/rfq/relayer/quoter/quoter.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,9 @@ func (m *Manager) prepareAndSubmitQuotes(ctx context.Context, inv map[int]map[co
// We can do this by looking at the quotableTokens map, and finding the key that matches the destination chain token.
// Generates quotes for a given chain ID, address, and balance.
func (m *Manager) generateQuotes(ctx context.Context, chainID int, address common.Address, balance *big.Int) ([]model.PutQuoteRequest, error) {

destChainCfg, ok := m.config.Chains[chainID]
if !ok {
return nil, fmt.Errorf("error getting chain config for destination chain ID %d", chainID)
destRFQAddr, err := m.config.GetRFQAddress(chainID)
if err != nil {
return nil, fmt.Errorf("error getting destination RFQ address: %w", err)
}

destTokenID := fmt.Sprintf("%d-%s", chainID, address.Hex())
Expand Down Expand Up @@ -277,9 +276,9 @@ func (m *Manager) generateQuotes(ctx context.Context, chainID int, address commo
if err != nil {
return nil, fmt.Errorf("error getting total fee: %w", err)
}
originChainCfg, ok := m.config.Chains[origin]
if !ok {
return nil, fmt.Errorf("error getting chain config for origin chain ID %d", origin)
originRFQAddr, err := m.config.GetRFQAddress(origin)
if err != nil {
return nil, fmt.Errorf("error getting RFQ address: %w", err)
}

// Build the quote
Expand All @@ -295,8 +294,8 @@ func (m *Manager) generateQuotes(ctx context.Context, chainID int, address commo
DestAmount: destAmount.String(),
MaxOriginAmount: quoteAmount.String(),
FixedFee: fee.String(),
OriginFastBridgeAddress: originChainCfg.Bridge,
DestFastBridgeAddress: destChainCfg.Bridge,
OriginFastBridgeAddress: originRFQAddr,
DestFastBridgeAddress: destRFQAddr,
}
quotes = append(quotes, quote)
}
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,11 +59,11 @@ func NewRelayerAPI(
if err != nil {
return nil, fmt.Errorf("could not create omnirpc client: %w", err)
}
chainListener, err := listener.NewChainListener(chainClient, store, common.HexToAddress(chainCfg.Bridge), handler)
chainListener, err := listener.NewChainListener(chainClient, store, common.HexToAddress(chainCfg.RFQAddress), handler)
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.Bridge), chainListener, submitter)
chains[uint32(chainID)], err = chain.NewChain(ctx, chainClient, common.HexToAddress(chainCfg.RFQAddress), chainListener, submitter)
if err != nil {
return nil, fmt.Errorf("could not create chain: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions services/rfq/relayer/relapi/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ func (c *RelayerServerSuite) SetupTest() {
testConfig := relconfig.Config{
Chains: map[int]relconfig.ChainConfig{
int(c.originChainID): {
Bridge: ethFastBridgeAddress.Hex(),
RFQAddress: ethFastBridgeAddress.Hex(),
},
int(c.destChainID): {
Bridge: arbFastBridgeAddress.Hex(),
RFQAddress: arbFastBridgeAddress.Hex(),
},
},
RelayerAPIPort: strconv.Itoa(port),
Expand Down
Loading
Loading