diff --git a/app/app.go b/app/app.go index 9d67d63f..07beff95 100644 --- a/app/app.go +++ b/app/app.go @@ -182,12 +182,14 @@ func Run() error { priceAPI := price.NewPricerProxy(multiPricer) evmSignHandler := evmMessage.NewSignHandler(coordinator, host, communication, keyshareStore) + chainConfigs := config.MergeChainConfigs(configuration.ChainConfigs, *solverConfig) + var hubPoolContract across.TokenMatcher acrossPools := make(map[uint64]common.Address) lifiOutputSettlers := make(map[uint64]string) repayerAddresses := make(map[uint64]common.Address) tokens := make(map[uint64]map[string]config.TokenConfig) - for _, chainConfig := range configuration.ChainConfigs { + for _, chainConfig := range chainConfigs { switch chainConfig["type"] { case "evm": { @@ -230,7 +232,7 @@ func Run() error { Tokens: tokens, } - for _, chainConfig := range configuration.ChainConfigs { + for _, chainConfig := range chainConfigs { switch chainConfig["type"] { case "evm": { diff --git a/config/config.go b/config/config.go index a448ebae..b5bd6e65 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,8 @@ import ( "github.com/creasty/defaults" "github.com/imdario/mergo" + solverConfig "github.com/sprintertech/solver-config/go/config" + "github.com/sprintertech/solver-sdk/pkg/chains/caip" "github.com/sprintertech/sprinter-signing/config/relayer" "github.com/spf13/cobra" @@ -135,6 +137,44 @@ func compareDomainID(a, b interface{}) bool { return false } +// MergeChainConfigs fills in chains that are present in the shared solver +// config but were not manually configured, deriving their endpoint from the +// solver config's transport so a chain can be supported without a manual +// chain config entry. Manually configured fields always take precedence. +func MergeChainConfigs(chainConfigs []map[string]interface{}, solverConfig solverConfig.SolverConfig) []map[string]interface{} { + for caipID, c := range solverConfig.Chains { + id, err := caip.CAIPToChainID(caipID) + if err != nil { + continue + } + + if chainExists(chainConfigs, id) { + continue + } + + cc := map[string]interface{}{ + "id": id, + "type": "evm", + "name": fmt.Sprintf("chain-%d", id), + "endpoint": c.Transport.HTTP[0], + } + chainConfigs = append(chainConfigs, cc) + } + + return chainConfigs +} + +func chainExists(chainConfigs []map[string]interface{}, chainID uint64) bool { + for _, cc := range chainConfigs { + ccID := cc["id"].(uint64) + if ccID == chainID { + return true + } + } + + return false +} + var ( // Flags for running the app StagingFlagName = "staging" diff --git a/config/config_test.go b/config/config_test.go index 928b4931..03ee181c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + solverConfig "github.com/sprintertech/solver-config/go/config" "github.com/sprintertech/sprinter-signing/config" "github.com/sprintertech/sprinter-signing/config/relayer" "github.com/stretchr/testify/suite" @@ -579,3 +580,68 @@ func (s *GetConfigTestSuite) Test_GetConfigFromFile() { }) } } + +type MergeChainConfigsTestSuite struct { + suite.Suite +} + +func TestRunMergeChainConfigsTestSuite(t *testing.T) { + suite.Run(t, new(MergeChainConfigsTestSuite)) +} + +func (s *MergeChainConfigsTestSuite) Test_MergeChainConfigs_AddsChainFromSolverConfig() { + solverChains := map[string]solverConfig.Chain{ + "eip155:10": { + Transport: solverConfig.Transport{ + HTTP: []string{"https://chain10.example"}, + }, + }, + } + + merged := config.MergeChainConfigs(nil, solverConfig.SolverConfig{Chains: solverChains}) + + s.Len(merged, 1) + s.Equal(map[string]interface{}{ + "id": uint64(10), + "type": "evm", + "name": "chain-10", + "endpoint": "https://chain10.example", + }, merged[0]) +} + +func (s *MergeChainConfigsTestSuite) Test_MergeChainConfigs_ManuallyConfiguredChainNotOverwritten() { + solverChains := map[string]solverConfig.Chain{ + "eip155:10": { + Transport: solverConfig.Transport{ + HTTP: []string{"https://chain10.example"}, + }, + }, + } + + manual := []map[string]interface{}{ + { + "id": uint64(10), + "endpoint": "https://custom.example", + "admin": "adminAddress", + }, + } + + merged := config.MergeChainConfigs(manual, solverConfig.SolverConfig{Chains: solverChains}) + + s.Equal(manual, merged) +} + +func (s *MergeChainConfigsTestSuite) Test_MergeChainConfigs_KeepsManualOnlyChains() { + manual := []map[string]interface{}{ + { + "id": uint64(99), + "type": "evm", + "endpoint": "https://manual-only.example", + "name": "manual99", + }, + } + + merged := config.MergeChainConfigs(manual, solverConfig.SolverConfig{}) + + s.Equal(manual, merged) +} diff --git a/go.mod b/go.mod index a9897183..40bf46b4 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.9.0 github.com/sprintertech/solver-config/go v0.0.0-20260819115035-7b1b83250ca4 - github.com/sprintertech/solver-sdk v1.1.1-0.20260825101026-32c00a9704e6 + github.com/sprintertech/solver-sdk v1.1.1-0.20260827154133-1e8cff30b44b github.com/stretchr/testify v1.11.1 github.com/sygmaprotocol/sygma-core v0.0.0-20250304150334-bd39ac4f7b82 go.opentelemetry.io/otel v1.39.0 diff --git a/go.sum b/go.sum index fd65a776..767f82a9 100644 --- a/go.sum +++ b/go.sum @@ -1721,6 +1721,8 @@ github.com/sprintertech/solver-sdk v1.1.1-0.20260821104752-6a3c113a5958 h1:++m9Z github.com/sprintertech/solver-sdk v1.1.1-0.20260821104752-6a3c113a5958/go.mod h1:6euNIW0DgGI/RfIvpZJgnvoVcd1PmzE1T20C0dXnyrc= github.com/sprintertech/solver-sdk v1.1.1-0.20260825101026-32c00a9704e6 h1:0bfmInjG3+ak7E65LVBVOQxArztBSZw49iNY9dpfS8I= github.com/sprintertech/solver-sdk v1.1.1-0.20260825101026-32c00a9704e6/go.mod h1:A9fQAvneC86+z0ib2cb+yTOV84olOqcBZxomj1pe3bc= +github.com/sprintertech/solver-sdk v1.1.1-0.20260827154133-1e8cff30b44b h1:Xfr0QWclvoL0OGtjMrFTxoDU66JQHwBR8u1LdRYLba8= +github.com/sprintertech/solver-sdk v1.1.1-0.20260827154133-1e8cff30b44b/go.mod h1:A9fQAvneC86+z0ib2cb+yTOV84olOqcBZxomj1pe3bc= github.com/status-im/keycard-go v0.2.0/go.mod h1:wlp8ZLbsmrF6g6WjugPAx+IzoLrkdf9+mHxBEeo3Hbg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=