diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d700280b9b..162495a7e5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -4,8 +4,8 @@ name: Go Workflows on: pull_request: branches-ignore: - - 'gh-pages' - - 'fe-release' + - 'gh-pages' + - 'fe-release' push: branches-ignore: - 'gh-pages' @@ -77,8 +77,8 @@ jobs: test: name: Go Coverage - runs-on: ${{ (matrix.package == 'agents' || matrix.package == 'core' || matrix.package == 'tools' || contains(matrix.package, 'explorer') || contains(matrix.package, 'contrib')) && 'ubuntu-latest' || 'namespace-profile-default-coverage-runner' }} - if: ${{ !contains(matrix.package, 'agents') && needs.changes.outputs.package_count_deps > 0 && (github.event_name != 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) }} + runs-on: ${{ (matrix.package == 'core' || matrix.package == 'tools' || contains(matrix.package, 'explorer') || contains(matrix.package, 'contrib')) && 'ubuntu-latest' || 'namespace-profile-default-coverage-runner' }} + if: ${{ needs.changes.outputs.package_count_deps > 0 && (github.event_name != 'push' || github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) }} needs: changes strategy: fail-fast: false @@ -109,7 +109,7 @@ jobs: - name: Go modules cache uses: actions/cache@v4 - if: ${{ !contains(runner.name, 'nsc') }} + if: ${{ !contains(runner.name, 'nsc') }} with: # see https://github.com/mvdan/github-actions-golang # also: https://glebbahmutov.com/blog/do-not-let-npm-cache-snowball/ w/ go build (workaround now is having a cache that just gets expired at night) @@ -143,7 +143,6 @@ jobs: sleep 1 done - - name: Install gotestsum uses: jaxxstorm/action-install-gh-release@v1.10.0 with: # Grab the latest version @@ -156,7 +155,6 @@ jobs: run: | echo "::set-output name=flag::$(echo "${{ matrix.package }}" | rev | cut -d/ -f1 | rev)" - - name: Precompile Tests working-directory: ${{ matrix.package }} run: go test -run=nope ./... @@ -232,9 +230,8 @@ jobs: run: echo "::set-output name=package_name::$(echo ${{ matrix.package }} | sed 's/\//-/g')" shell: bash - - name: Upload logs to GitHub -# if: failure() + # if: failure() uses: actions/upload-artifact@v4 with: name: ${{ steps.replace.outputs.package_name }} diff --git a/services/rfq/e2e/rfq_test.go b/services/rfq/e2e/rfq_test.go index f75f3a9586..790ef9fc11 100644 --- a/services/rfq/e2e/rfq_test.go +++ b/services/rfq/e2e/rfq_test.go @@ -22,10 +22,10 @@ import ( "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge" "github.com/synapsecns/sanguine/services/rfq/guard/guarddb" guardService "github.com/synapsecns/sanguine/services/rfq/guard/service" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" "github.com/synapsecns/sanguine/services/rfq/relayer/service" "github.com/synapsecns/sanguine/services/rfq/testutil" + "github.com/synapsecns/sanguine/services/rfq/util" ) type IntegrationSuite struct { @@ -288,7 +288,7 @@ func (i *IntegrationSuite) TestETHtoETH() { // let's figure out the amount of ETH we need for _, quote := range allQuotes { - if common.HexToAddress(quote.DestTokenAddr) == chain.EthAddress { + if common.HexToAddress(quote.DestTokenAddr) == util.EthAddress { destAmountBigInt, _ := new(big.Int).SetString(quote.DestAmount, 10) if destAmountBigInt.Cmp(realWantAmount) > 0 { // we found our quote! @@ -308,9 +308,9 @@ func (i *IntegrationSuite) TestETHtoETH() { tx, err := originFastBridge.Bridge(auth.TransactOpts, fastbridge.IFastBridgeBridgeParams{ DstChainId: uint32(i.destBackend.GetChainID()), To: i.userWallet.Address(), - OriginToken: chain.EthAddress, + OriginToken: util.EthAddress, SendChainGas: true, - DestToken: chain.EthAddress, + DestToken: util.EthAddress, OriginAmount: realWantAmount, DestAmount: new(big.Int).Sub(realWantAmount, big.NewInt(1e17)), Deadline: new(big.Int).SetInt64(time.Now().Add(time.Hour * 24).Unix()), @@ -353,7 +353,7 @@ func (i *IntegrationSuite) TestETHtoETH() { // let's figure out the amount of ETH we need for _, quote := range allQuotes { - if common.HexToAddress(quote.DestTokenAddr) == chain.EthAddress && quote.DestChainID == originBackendChainID { + if common.HexToAddress(quote.DestTokenAddr) == util.EthAddress && quote.DestChainID == originBackendChainID { // we should now have some ETH on the origin chain since we claimed // this should be offered up as inventory destAmountBigInt, _ := new(big.Int).SetString(quote.DestAmount, 10) diff --git a/services/rfq/e2e/setup_test.go b/services/rfq/e2e/setup_test.go index 55792ccd00..1ead9bf14a 100644 --- a/services/rfq/e2e/setup_test.go +++ b/services/rfq/e2e/setup_test.go @@ -1,12 +1,14 @@ package e2e_test import ( + "context" "fmt" "math/big" "net/http" "slices" "strconv" "sync" + "time" "github.com/ethereum/go-ethereum/common" @@ -17,6 +19,7 @@ import ( "github.com/phayes/freeport" "github.com/synapsecns/sanguine/core" "github.com/synapsecns/sanguine/core/dbcommon" + "github.com/synapsecns/sanguine/core/retry" "github.com/synapsecns/sanguine/core/testsuite" "github.com/synapsecns/sanguine/ethergo/backends" "github.com/synapsecns/sanguine/ethergo/backends/anvil" @@ -34,11 +37,11 @@ import ( "github.com/synapsecns/sanguine/services/rfq/guard/guardconfig" guardConnect "github.com/synapsecns/sanguine/services/rfq/guard/guarddb/connect" guardService "github.com/synapsecns/sanguine/services/rfq/guard/service" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb/connect" "github.com/synapsecns/sanguine/services/rfq/relayer/service" "github.com/synapsecns/sanguine/services/rfq/testutil" + "github.com/synapsecns/sanguine/services/rfq/util" ) func (i *IntegrationSuite) setupQuoterAPI() { @@ -208,21 +211,32 @@ func addressToBytes32(addr common.Address) [32]byte { // Approve checks if the token is approved and approves it if not. func (i *IntegrationSuite) Approve(backend backends.SimulatedTestBackend, token contracts.DeployedContract, user wallet.Wallet) { - erc20, err := ierc20.NewIERC20(token.Address(), backend) - i.NoError(err) + err := retry.WithBackoff(i.GetTestContext(), func(_ context.Context) (err error) { + erc20, err := ierc20.NewIERC20(token.Address(), backend) + if err != nil { + return fmt.Errorf("could not get token at %s: %w", token.Address().String(), err) + } - _, fastBridge := i.manager.GetFastBridge(i.GetTestContext(), backend) + _, fastBridge := i.manager.GetFastBridge(i.GetTestContext(), backend) - allowance, err := erc20.Allowance(&bind.CallOpts{Context: i.GetTestContext()}, user.Address(), fastBridge.Address()) - i.NoError(err) + allowance, err := erc20.Allowance(&bind.CallOpts{Context: i.GetTestContext()}, user.Address(), fastBridge.Address()) + if err != nil { + return fmt.Errorf("could not get allowance: %w", err) + } - // TODO: can also use in mem cache - if allowance.Cmp(big.NewInt(0)) == 0 { - txOpts := backend.GetTxContext(i.GetTestContext(), user.AddressPtr()) - tx, err := erc20.Approve(txOpts.TransactOpts, fastBridge.Address(), core.CopyBigInt(abi.MaxUint256)) - i.NoError(err) - backend.WaitForConfirmation(i.GetTestContext(), tx) - } + // TODO: can also use in mem cache + if allowance.Cmp(big.NewInt(0)) == 0 { + txOpts := backend.GetTxContext(i.GetTestContext(), user.AddressPtr()) + tx, err := erc20.Approve(txOpts.TransactOpts, fastBridge.Address(), core.CopyBigInt(abi.MaxUint256)) + if err != nil { + return fmt.Errorf("could not approve: %w", err) + } + backend.WaitForConfirmation(i.GetTestContext(), tx) + } + + return nil + }, retry.WithMaxTotalTime(15*time.Second)) + i.NoError(err) } func (i *IntegrationSuite) getRelayerConfig() relconfig.Config { @@ -241,7 +255,7 @@ func (i *IntegrationSuite) getRelayerConfig() relconfig.Config { Confirmations: 0, Tokens: map[string]relconfig.TokenConfig{ "ETH": { - Address: chain.EthAddress.String(), + Address: util.EthAddress.String(), PriceUSD: 2000, Decimals: 18, }, @@ -254,7 +268,7 @@ func (i *IntegrationSuite) getRelayerConfig() relconfig.Config { Confirmations: 0, Tokens: map[string]relconfig.TokenConfig{ "ETH": { - Address: chain.EthAddress.String(), + Address: util.EthAddress.String(), PriceUSD: 2000, Decimals: 18, }, @@ -379,11 +393,11 @@ func (i *IntegrationSuite) setupRelayer() { } // Add ETH as quotable token from origin to destination - cfg.QuotableTokens[fmt.Sprintf("%d-%s", originBackendChainID, chain.EthAddress)] = []string{ - fmt.Sprintf("%d-%s", destBackendChainID, chain.EthAddress), + cfg.QuotableTokens[fmt.Sprintf("%d-%s", originBackendChainID, util.EthAddress)] = []string{ + fmt.Sprintf("%d-%s", destBackendChainID, util.EthAddress), } - cfg.QuotableTokens[fmt.Sprintf("%d-%s", destBackendChainID, chain.EthAddress)] = []string{ - fmt.Sprintf("%d-%s", originBackendChainID, chain.EthAddress), + cfg.QuotableTokens[fmt.Sprintf("%d-%s", destBackendChainID, util.EthAddress)] = []string{ + fmt.Sprintf("%d-%s", originBackendChainID, util.EthAddress), } var err error diff --git a/services/rfq/relayer/chain/chain.go b/services/rfq/relayer/chain/chain.go index 10b19d28ae..a2a39475e2 100644 --- a/services/rfq/relayer/chain/chain.go +++ b/services/rfq/relayer/chain/chain.go @@ -16,6 +16,7 @@ import ( "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" ) // Chain is a chain helper for relayer. @@ -75,7 +76,7 @@ func (c Chain) SubmitRelay(ctx context.Context, request reldb.QuoteRequest) (uin var err error // Check to see if ETH should be sent to destination - if IsGasToken(request.Transaction.DestToken) { + if util.IsGasToken(request.Transaction.DestToken) { gasAmount = request.Transaction.DestAmount } else if request.Transaction.SendChainGas { gasAmount, err = c.Bridge.ChainGasAmount(&bind.CallOpts{Context: ctx}) diff --git a/services/rfq/relayer/inventory/manager.go b/services/rfq/relayer/inventory/manager.go index e88f4d8932..5af39afa13 100644 --- a/services/rfq/relayer/inventory/manager.go +++ b/services/rfq/relayer/inventory/manager.go @@ -22,9 +22,9 @@ import ( "github.com/synapsecns/sanguine/ethergo/client" "github.com/synapsecns/sanguine/ethergo/submitter" "github.com/synapsecns/sanguine/services/rfq/contracts/ierc20" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" @@ -95,7 +95,7 @@ func (i *inventoryManagerImpl) GetCommittableBalance(ctx context.Context, chainI balance := committableBalances[chainID][token] // the gas token may not be registered in the inventory tokens map, // but it is always tracked in gasBalances. - if balance == nil && token == chain.EthAddress { + if balance == nil && token == util.EthAddress { gasBalance, ok := i.gasBalances[chainID] if !ok || gasBalance == nil { return nil, ErrUnsupportedChain @@ -311,7 +311,7 @@ func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) error { // approve RFQ contract. // Note: in the case where submitter hasn't finished from last boot, // this will double submit approvals unfortunately. - if address != chain.EthAddress && token.Allowances[contractRFQ].Cmp(big.NewInt(0)) == 0 { + if address != util.EthAddress && token.Allowances[contractRFQ].Cmp(big.NewInt(0)) == 0 { tokenAddr := address // capture func literal contractAddr, err := i.cfg.GetRFQAddress(chainID) if err != nil { @@ -324,7 +324,7 @@ func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) error { } // approve SynapseCCTP contract - if address != chain.EthAddress && token.Allowances[contractSynapseCCTP].Cmp(big.NewInt(0)) == 0 { + if address != util.EthAddress && token.Allowances[contractSynapseCCTP].Cmp(big.NewInt(0)) == 0 { tokenAddr := address // capture func literal contractAddr, err := i.cfg.GetSynapseCCTPAddress(chainID) if err != nil { @@ -337,7 +337,7 @@ func (i *inventoryManagerImpl) ApproveAllTokens(ctx context.Context) error { } // approve TokenMessenger contract - if address != chain.EthAddress && token.Allowances[contractTokenMessenger].Cmp(big.NewInt(0)) == 0 { + if address != util.EthAddress && token.Allowances[contractTokenMessenger].Cmp(big.NewInt(0)) == 0 { tokenAddr := address // capture func literal contractAddr, err := i.cfg.GetTokenMessengerAddress(chainID) if err != nil { @@ -409,7 +409,7 @@ func (i *inventoryManagerImpl) HasSufficientGas(parentCtx context.Context, chain span.SetAttributes(attribute.String("gas_value", gasValue.String())) } - gasBalance, err := i.GetCommittableBalance(ctx, chainID, chain.EthAddress) + gasBalance, err := i.GetCommittableBalance(ctx, chainID, util.EthAddress) if err != nil { return false, fmt.Errorf("error getting committable gas on origin: %w", err) } @@ -541,7 +541,7 @@ func (i *inventoryManagerImpl) initializeTokens(parentCtx context.Context, cfg r var token common.Address if rtoken.IsGasToken { - token = chain.EthAddress + token = util.EthAddress } else { token = common.HexToAddress(tokenCfg.Address) } diff --git a/services/rfq/relayer/quoter/quoter.go b/services/rfq/relayer/quoter/quoter.go index 15b722076e..522c33ec98 100644 --- a/services/rfq/relayer/quoter/quoter.go +++ b/services/rfq/relayer/quoter/quoter.go @@ -20,10 +20,10 @@ import ( "github.com/ipfs/go-log" "github.com/synapsecns/sanguine/core/metrics" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/pricer" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" "golang.org/x/exp/slices" "golang.org/x/sync/errgroup" @@ -539,7 +539,7 @@ func (m *Manager) getOriginAmount(parentCtx context.Context, origin, dest int, a // deductGasCost deducts the gas cost from the quote amount, if necessary. func (m *Manager) deductGasCost(parentCtx context.Context, quoteAmount *big.Int, address common.Address, dest int) (quoteAmountAdj *big.Int, err error) { - if !chain.IsGasToken(address) { + if !util.IsGasToken(address) { return quoteAmount, nil } diff --git a/services/rfq/relayer/quoter/quoter_test.go b/services/rfq/relayer/quoter/quoter_test.go index 44510fabe8..d4e2a9a127 100644 --- a/services/rfq/relayer/quoter/quoter_test.go +++ b/services/rfq/relayer/quoter/quoter_test.go @@ -11,12 +11,12 @@ import ( fetcherMocks "github.com/synapsecns/sanguine/ethergo/submitter/mocks" "github.com/synapsecns/sanguine/services/rfq/api/model" "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" inventoryMocks "github.com/synapsecns/sanguine/services/rfq/relayer/inventory/mocks" "github.com/synapsecns/sanguine/services/rfq/relayer/pricer" priceMocks "github.com/synapsecns/sanguine/services/rfq/relayer/pricer/mocks" "github.com/synapsecns/sanguine/services/rfq/relayer/quoter" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" ) func (s *QuoterSuite) TestGenerateQuotes() { @@ -43,7 +43,7 @@ func (s *QuoterSuite) TestGenerateQuotes() { func (s *QuoterSuite) TestGenerateQuotesForNativeToken() { // Generate quotes for ETH on the destination chain. balance, _ := new(big.Int).SetString("1000000000000000000", 10) // 1 ETH - quotes, err := s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), chain.EthAddress, balance) + quotes, err := s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), util.EthAddress, balance) s.Require().NoError(err) minGasToken, err := s.config.GetMinGasToken(int(s.destination)) @@ -54,9 +54,9 @@ func (s *QuoterSuite) TestGenerateQuotesForNativeToken() { expectedQuotes := []model.PutQuoteRequest{ { OriginChainID: int(s.origin), - OriginTokenAddr: chain.EthAddress.String(), + OriginTokenAddr: util.EthAddress.String(), DestChainID: int(s.destinationEth), - DestTokenAddr: chain.EthAddress.String(), + DestTokenAddr: util.EthAddress.String(), DestAmount: expectedQuoteAmount.String(), MaxOriginAmount: expectedQuoteAmount.String(), FixedFee: "150000000000000000", // (500k gas + 1m gas) * 100 gwei @@ -68,7 +68,7 @@ func (s *QuoterSuite) TestGenerateQuotesForNativeToken() { s.config.BaseChainConfig.MinGasToken = "100000000000000000" // 0.1 ETH s.manager.SetConfig(s.config) - quotes, err = s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), chain.EthAddress, balance) + quotes, err = s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), util.EthAddress, balance) s.Require().NoError(err) minGasToken, err = s.config.GetMinGasToken(int(s.destination)) @@ -79,9 +79,9 @@ func (s *QuoterSuite) TestGenerateQuotesForNativeToken() { expectedQuotes = []model.PutQuoteRequest{ { OriginChainID: int(s.origin), - OriginTokenAddr: chain.EthAddress.String(), + OriginTokenAddr: util.EthAddress.String(), DestChainID: int(s.destinationEth), - DestTokenAddr: chain.EthAddress.String(), + DestTokenAddr: util.EthAddress.String(), DestAmount: expectedQuoteAmount.String(), MaxOriginAmount: expectedQuoteAmount.String(), FixedFee: "150000000000000000", // (500k gas + 1m gas) * 100 gwei @@ -93,7 +93,7 @@ func (s *QuoterSuite) TestGenerateQuotesForNativeToken() { s.config.BaseChainConfig.MinGasToken = "1000000000000000001" // 0.1 ETH s.manager.SetConfig(s.config) - quotes, err = s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), chain.EthAddress, balance) + quotes, err = s.manager.GenerateQuotes(s.GetTestContext(), int(s.destinationEth), util.EthAddress, balance) s.NoError(err) s.Equal(quotes[0].DestAmount, "0") s.Equal(quotes[0].MaxOriginAmount, "0") diff --git a/services/rfq/relayer/quoter/suite_test.go b/services/rfq/relayer/quoter/suite_test.go index f58808dedc..83950f06b1 100644 --- a/services/rfq/relayer/quoter/suite_test.go +++ b/services/rfq/relayer/quoter/suite_test.go @@ -11,12 +11,12 @@ import ( "github.com/synapsecns/sanguine/core/testsuite" clientMocks "github.com/synapsecns/sanguine/ethergo/client/mocks" fetcherMocks "github.com/synapsecns/sanguine/ethergo/submitter/mocks" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" inventoryMocks "github.com/synapsecns/sanguine/services/rfq/relayer/inventory/mocks" "github.com/synapsecns/sanguine/services/rfq/relayer/pricer" priceMocks "github.com/synapsecns/sanguine/services/rfq/relayer/pricer/mocks" "github.com/synapsecns/sanguine/services/rfq/relayer/quoter" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" + "github.com/synapsecns/sanguine/services/rfq/util" ) // Server suite is the main API server test suite. @@ -53,7 +53,7 @@ func (s *QuoterSuite) SetupTest() { Decimals: 6, }, "ETH": { - Address: chain.EthAddress.String(), + Address: util.EthAddress.String(), PriceUSD: 2000, Decimals: 18, }, @@ -78,7 +78,7 @@ func (s *QuoterSuite) SetupTest() { int(s.destinationEth): { Tokens: map[string]relconfig.TokenConfig{ "ETH": { - Address: chain.EthAddress.String(), + Address: util.EthAddress.String(), PriceUSD: 2000, Decimals: 18, }, diff --git a/services/rfq/relayer/relapi/client_test.go b/services/rfq/relayer/relapi/client_test.go index 81baea2940..c7bffee702 100644 --- a/services/rfq/relayer/relapi/client_test.go +++ b/services/rfq/relayer/relapi/client_test.go @@ -10,9 +10,9 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/synapsecns/sanguine/core/retry" submitterdb "github.com/synapsecns/sanguine/ethergo/submitter/db" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/relapi" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" ) func (c *RelayerClientSuite) TestHealth() { @@ -72,7 +72,7 @@ func (c *RelayerClientSuite) TestEthWithdraw() { ChainID: uint32(backend.GetChainID()), To: testWithdrawalAddress, Amount: withdrawalAmount.String(), - TokenAddress: chain.EthAddress, + TokenAddress: util.EthAddress, }) c.Require().NoError(err) @@ -171,7 +171,7 @@ func (c *RelayerClientSuite) TestEthWithdrawCLI() { ChainID: c.underlying.originChainID, To: common.HexToAddress(testWithdrawalAddress.String()), Amount: "1000000000000000000", - TokenAddress: chain.EthAddress, + TokenAddress: util.EthAddress, }) c.Require().NoError(err) diff --git a/services/rfq/relayer/relapi/handler.go b/services/rfq/relayer/relapi/handler.go index 685b932b09..2c644aee70 100644 --- a/services/rfq/relayer/relapi/handler.go +++ b/services/rfq/relayer/relapi/handler.go @@ -3,17 +3,19 @@ package relapi import ( "encoding/json" "fmt" - "github.com/synapsecns/sanguine/core/metrics" - "go.opentelemetry.io/otel/attribute" "math/big" "net/http" + "github.com/synapsecns/sanguine/core/metrics" + "go.opentelemetry.io/otel/attribute" + "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/core/types" "github.com/synapsecns/sanguine/ethergo/submitter" "github.com/synapsecns/sanguine/services/rfq/contracts/ierc20" "github.com/synapsecns/sanguine/services/rfq/relayer/relconfig" + "github.com/synapsecns/sanguine/services/rfq/util" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -215,7 +217,7 @@ func (h *Handler) Withdraw(c *gin.Context) { } //nolint: nestif - if chain.IsGasToken(req.TokenAddress) { + if util.IsGasToken(req.TokenAddress) { nonce, err = h.submitter.SubmitTransaction(ctx, big.NewInt(int64(req.ChainID)), func(transactor *bind.TransactOpts) (tx *types.Transaction, err error) { bc := bind.NewBoundContract(req.To, abi.ABI{}, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client, h.chains[req.ChainID].Client) if transactor.GasPrice != nil { diff --git a/services/rfq/relayer/relapi/suite_test.go b/services/rfq/relayer/relapi/suite_test.go index 321a85a578..1d7bdc7641 100644 --- a/services/rfq/relayer/relapi/suite_test.go +++ b/services/rfq/relayer/relapi/suite_test.go @@ -8,8 +8,8 @@ import ( "testing" "github.com/ethereum/go-ethereum/params" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/testutil" + "github.com/synapsecns/sanguine/services/rfq/util" "github.com/Flaque/filet" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -104,10 +104,10 @@ func (c *RelayerServerSuite) SetupTest() { }, QuotableTokens: map[string][]string{ // gas tokens. - fmt.Sprintf("%d-%s", c.originChainID, chain.EthAddress): { + fmt.Sprintf("%d-%s", c.originChainID, util.EthAddress): { // not used for this test }, - fmt.Sprintf("%d-%s", c.destChainID, chain.EthAddress): { + fmt.Sprintf("%d-%s", c.destChainID, util.EthAddress): { // not used for this test }, c.getMockTokenID(c.testBackends[uint64(c.originChainID)]): { diff --git a/services/rfq/relayer/relconfig/config.go b/services/rfq/relayer/relconfig/config.go index 7ed139cfec..f89644d5b4 100644 --- a/services/rfq/relayer/relconfig/config.go +++ b/services/rfq/relayer/relconfig/config.go @@ -18,7 +18,7 @@ import ( submitterConfig "github.com/synapsecns/sanguine/ethergo/submitter/config" cctpConfig "github.com/synapsecns/sanguine/services/cctp-relayer/config" "github.com/synapsecns/sanguine/services/rfq/contracts/ierc20" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" + "github.com/synapsecns/sanguine/services/rfq/util" "gopkg.in/yaml.v2" "path/filepath" @@ -259,7 +259,7 @@ func (c Config) validateTokenDecimals(ctx context.Context, omniClient omniClient } // Check if the token is the gas token. SHOULD BE 18. - if tokenCFG.Address == chain.EthAddress.String() { + if tokenCFG.Address == util.EthAddress.String() { if tokenCFG.Decimals != 18 { return fmt.Errorf("decimals mismatch for token %s on chain %d: expected 18, got %d", tokenName, chainID, tokenCFG.Decimals) } diff --git a/services/rfq/relayer/service/chainindexer.go b/services/rfq/relayer/service/chainindexer.go index ef5c47c31c..60ab86ee90 100644 --- a/services/rfq/relayer/service/chainindexer.go +++ b/services/rfq/relayer/service/chainindexer.go @@ -13,8 +13,8 @@ import ( "github.com/synapsecns/sanguine/core/metrics" "github.com/synapsecns/sanguine/services/rfq/contracts/fastbridge" "github.com/synapsecns/sanguine/services/rfq/contracts/ierc20" - "github.com/synapsecns/sanguine/services/rfq/relayer/chain" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" @@ -180,7 +180,7 @@ func (r *Relayer) getDecimals(ctx context.Context, addr common.Address, chainID return decimals, nil } - if addr == chain.EthAddress { + if addr == util.EthAddress { return ðDecimals, nil } diff --git a/services/rfq/relayer/service/statushandler.go b/services/rfq/relayer/service/statushandler.go index 8d89c89b54..6aedc1c331 100644 --- a/services/rfq/relayer/service/statushandler.go +++ b/services/rfq/relayer/service/statushandler.go @@ -16,6 +16,7 @@ import ( "github.com/synapsecns/sanguine/services/rfq/relayer/inventory" "github.com/synapsecns/sanguine/services/rfq/relayer/quoter" "github.com/synapsecns/sanguine/services/rfq/relayer/reldb" + "github.com/synapsecns/sanguine/services/rfq/util" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -175,7 +176,7 @@ func (r *Relayer) gasMiddleware(next func(ctx context.Context, span trace.Span, // Therefore, we only need to check the gas value for requests with all the other statuses. isInFlight := req.Status == reldb.CommittedPending || req.Status == reldb.CommittedConfirmed || req.Status == reldb.RelayStarted var destGasValue *big.Int - if req.Transaction.DestToken == chain.EthAddress && !isInFlight { + if req.Transaction.DestToken == util.EthAddress && !isInFlight { destGasValue = req.Transaction.DestAmount span.SetAttributes(attribute.String("dest_gas_value", destGasValue.String())) } diff --git a/services/rfq/util/doc.go b/services/rfq/util/doc.go new file mode 100644 index 0000000000..c2e748f104 --- /dev/null +++ b/services/rfq/util/doc.go @@ -0,0 +1,2 @@ +// Package util contains utility functions for the RFQ service. +package util diff --git a/services/rfq/relayer/chain/util.go b/services/rfq/util/util.go similarity index 95% rename from services/rfq/relayer/chain/util.go rename to services/rfq/util/util.go index 2948ddcde3..2a2e12fadc 100644 --- a/services/rfq/relayer/chain/util.go +++ b/services/rfq/util/util.go @@ -1,4 +1,4 @@ -package chain +package util import "github.com/ethereum/go-ethereum/common"