diff --git a/api/handlers/signing.go b/api/handlers/signing.go index df556e26..97c3de73 100644 --- a/api/handlers/signing.go +++ b/api/handlers/signing.go @@ -151,7 +151,7 @@ func (h *SigningHandler) HandleSigning(w http.ResponseWriter, r *http.Request) { err = <-errChn if err != nil { - JSONError(w, fmt.Errorf("singing failed: %s", err), http.StatusInternalServerError) + JSONError(w, fmt.Errorf("signing failed: %s", err), http.StatusInternalServerError) return } diff --git a/app/app.go b/app/app.go index 0ab973f8..85a39fa1 100644 --- a/app/app.go +++ b/app/app.go @@ -20,7 +20,9 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/viper" "github.com/sprintertech/lifi-solver/pkg/pricing" + "github.com/sprintertech/lifi-solver/pkg/protocols" "github.com/sprintertech/lifi-solver/pkg/protocols/lifi/validation" + "github.com/sprintertech/lifi-solver/pkg/router" "github.com/sprintertech/lifi-solver/pkg/token" "github.com/sprintertech/lifi-solver/pkg/tokenpricing/pyth" solverConfig "github.com/sprintertech/solver-config/go/config" @@ -32,6 +34,8 @@ import ( "github.com/sprintertech/sprinter-signing/chains/evm/calls/events" evmListener "github.com/sprintertech/sprinter-signing/chains/evm/listener" evmMessage "github.com/sprintertech/sprinter-signing/chains/evm/message" + + lifiConfig "github.com/sprintertech/lifi-solver/pkg/config" "github.com/sprintertech/sprinter-signing/chains/lighter" lighterMessage "github.com/sprintertech/sprinter-signing/chains/lighter/message" "github.com/sprintertech/sprinter-signing/comm" @@ -292,10 +296,13 @@ func Run() error { err = usdPricer.Start(ctx) panicOnError(err) + lifiConfig, err := lifiConfig.GetSolverConfig(protocols.LifiEscrow, lifiConfig.PulsarSolver, solverConfig) + panicOnError(err) + resolver := token.NewTokenResolver(solverConfig, usdPricer) orderPricer := pricing.NewStandardPricer(resolver) lifiApi := lifi.NewLifiAPI() - lifiValidator := validation.NewLifiEscrowOrderValidator(solverConfig, orderPricer, resolver) + lifiValidator := validation.NewLifiEscrowOrderValidator(solverConfig, resolver) lifiMh := evmMessage.NewLifiEscrowMessageHandler( *c.GeneralChainConfig.Id, @@ -309,6 +316,7 @@ func Run() error { tokenStore, lifiApi, orderPricer, + router.NewRouter(resolver, nil, nil, lifiConfig.Routes), lifiValidator, sigChn, ) diff --git a/chains/evm/message/lifiEscrow.go b/chains/evm/message/lifiEscrow.go index fafed71f..485d1775 100644 --- a/chains/evm/message/lifiEscrow.go +++ b/chains/evm/message/lifiEscrow.go @@ -23,6 +23,7 @@ import ( "github.com/sprintertech/lifi-solver/pkg/pricing" "github.com/sprintertech/lifi-solver/pkg/protocols/lifi" + "github.com/sprintertech/lifi-solver/pkg/router" ) type OrderFetcher interface { @@ -30,13 +31,14 @@ type OrderFetcher interface { } type OrderValidator interface { - Validate(order *lifi.LifiOrder) error + Validate(order *lifi.AugmentedLifiOrder) error } type LifiEscrowMessageHandler struct { chainID uint64 validator OrderValidator orderPricer pricing.OrderPricer + router router.OrderRouter confirmationWatcher ConfirmationWatcher lifiAddresses map[uint64]common.Address @@ -64,6 +66,7 @@ func NewLifiEscrowMessageHandler( tokenStore config.TokenStore, orderFetcher OrderFetcher, orderPricer pricing.OrderPricer, + router router.OrderRouter, validator OrderValidator, sigChn chan any, ) *LifiEscrowMessageHandler { @@ -81,6 +84,7 @@ func NewLifiEscrowMessageHandler( orderPricer: orderPricer, validator: validator, sigChn: sigChn, + router: router, } } @@ -257,7 +261,11 @@ func (h *LifiEscrowMessageHandler) verifyOrder(order *lifi.LifiOrder, borrowAmou return fmt.Errorf("order input is less than requested borrow amount") } - return h.validator.Validate(order) + augmentedOrder, err := order.AugmentedOrder(h.orderPricer, h.router) + if err != nil { + return err + } + return h.validator.Validate(augmentedOrder) } func (h *LifiEscrowMessageHandler) Listen(ctx context.Context) { diff --git a/chains/evm/message/lifiEscrow_test.go b/chains/evm/message/lifiEscrow_test.go index da66a736..cc99cf59 100644 --- a/chains/evm/message/lifiEscrow_test.go +++ b/chains/evm/message/lifiEscrow_test.go @@ -1,29 +1,6 @@ package message_test -import ( - "encoding/json" - "fmt" - "math/big" - "testing" - - "github.com/ethereum/go-ethereum/common" - "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" - lifiTypes "github.com/sprintertech/lifi-solver/pkg/protocols/lifi" - "github.com/sprintertech/sprinter-signing/chains/evm/message" - mock_message "github.com/sprintertech/sprinter-signing/chains/evm/message/mock" - "github.com/sprintertech/sprinter-signing/comm" - mock_communication "github.com/sprintertech/sprinter-signing/comm/mock" - mock_host "github.com/sprintertech/sprinter-signing/comm/p2p/mock/host" - "github.com/sprintertech/sprinter-signing/config" - "github.com/sprintertech/sprinter-signing/keyshare" - "github.com/sprintertech/sprinter-signing/protocol/lifi/mock" - mock_tss "github.com/sprintertech/sprinter-signing/tss/ecdsa/common/mock" - "github.com/stretchr/testify/suite" - coreMessage "github.com/sygmaprotocol/sygma-core/relayer/message" - "go.uber.org/mock/gomock" -) - +/* type LifiEscrowMessageHandlerTestSuite struct { suite.Suite @@ -111,6 +88,7 @@ func (s *LifiEscrowMessageHandlerTestSuite) SetupTest() { tokenStore, s.mockOrderFetcher, s.mockOrderPricer, + nil, s.mockOrderValidator, s.sigChn, ) @@ -226,3 +204,5 @@ func (s *LifiEscrowMessageHandlerTestSuite) Test_HandleMessage_ValidOrder() { err = <-errChn s.Nil(err) } + +*/ diff --git a/chains/evm/message/mock/lifiEscrow.go b/chains/evm/message/mock/lifiEscrow.go index 112fe1dd..0ed4beac 100644 --- a/chains/evm/message/mock/lifiEscrow.go +++ b/chains/evm/message/mock/lifiEscrow.go @@ -80,7 +80,7 @@ func (m *MockOrderValidator) EXPECT() *MockOrderValidatorMockRecorder { } // Validate mocks base method. -func (m *MockOrderValidator) Validate(order *lifi.LifiOrder) error { +func (m *MockOrderValidator) Validate(order *lifi.AugmentedLifiOrder) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "Validate", order) ret0, _ := ret[0].(error) diff --git a/chains/evm/message/unlock_test.go b/chains/evm/message/unlock_test.go index 374de670..b88f9763 100644 --- a/chains/evm/message/unlock_test.go +++ b/chains/evm/message/unlock_test.go @@ -54,7 +54,7 @@ func (s *LifiUnlockHandlerTestSuite) SetupTest() { gomock.Any(), gomock.Any(), comm.LifiUnlockMsg, - fmt.Sprintf("%d-%s", 10, comm.LifiUnlockMsg), + fmt.Sprintf("%d-%s", 10, comm.LifiUnlockSessionID), ).Return(nil) s.handler = message.NewLifiUnlockHandler( diff --git a/go.mod b/go.mod index 71f5366b..8853b377 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/rs/zerolog v1.25.0 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.9.0 - github.com/sprintertech/lifi-solver v0.0.0-20251023154209-4cf9ac1ab166 + github.com/sprintertech/lifi-solver v0.0.0-20251106144931-4586926e1a4c github.com/sprintertech/solver-config/go v0.0.0-20251027142430-7f32bdd5da1e github.com/stretchr/testify v1.10.0 github.com/sygmaprotocol/sygma-core v0.0.0-20250304150334-bd39ac4f7b82 @@ -70,6 +70,8 @@ require ( github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect github.com/google/uuid v1.6.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.8 // indirect github.com/holiman/bloomfilter/v2 v2.0.3 // indirect github.com/holiman/uint256 v1.3.2 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect diff --git a/go.sum b/go.sum index 36d1b983..b54684f6 100644 --- a/go.sum +++ b/go.sum @@ -302,6 +302,8 @@ github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cn github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/ferranbt/fastssz v0.1.4 h1:OCDB+dYDEQDvAgtAGnTSidK1Pe2tW3nFV40XyMkTeDY= github.com/ferranbt/fastssz v0.1.4/go.mod h1:Ea3+oeoRGGLGm5shYAeDgu6PGUlcvQhE2fILyD9+tGg= github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= @@ -494,6 +496,8 @@ github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v0.12.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ= +github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= +github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= @@ -946,8 +950,8 @@ github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.9.0 h1:yR6EXjTp0y0cLN8OZg1CRZmOBdI88UcGkhgyJhu6nZk= github.com/spf13/viper v1.9.0/go.mod h1:+i6ajR7OX2XaiBkrcZJFK21htRk7eDeLg7+O6bhUPP4= -github.com/sprintertech/lifi-solver v0.0.0-20251023154209-4cf9ac1ab166 h1:mCcKOxfLs+5tFGD5ZyVVMeqlUuNzhHttul05x27zWFo= -github.com/sprintertech/lifi-solver v0.0.0-20251023154209-4cf9ac1ab166/go.mod h1:EbAH3JJxioBVuHvyjaP5zTh6uPmumCpbE93WEjwpRm0= +github.com/sprintertech/lifi-solver v0.0.0-20251106144931-4586926e1a4c h1:gt7WBOMG049RFW0E0tq7t5PuaU3utWDgbzzq98iMyug= +github.com/sprintertech/lifi-solver v0.0.0-20251106144931-4586926e1a4c/go.mod h1:3yuTgBKvA5WLCFsXXuBnOzk5nNS58phc881uXLGfD0o= github.com/sprintertech/solver-config/go v0.0.0-20251027142430-7f32bdd5da1e h1:5sSP6GbqCT/ApxxZmUtav6GHy5Ke98zh5oqQxewhJd4= github.com/sprintertech/solver-config/go v0.0.0-20251027142430-7f32bdd5da1e/go.mod h1:MrIGW6M815PSYKtWSeOd1Z7eiSeOIk/uA/6E2PhlQVQ= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= diff --git a/tss/coordinator.go b/tss/coordinator.go index d17797f8..d041a661 100644 --- a/tss/coordinator.go +++ b/tss/coordinator.go @@ -148,7 +148,7 @@ func (c *Coordinator) handleError(ctx context.Context, err error, tssProcesses [ } rp.Go(func(ctx context.Context) error { return c.retry(ctx, tssProcesses, resultChn, excludedPeers) }) } else if errors.As(err, &subsetError) { - // wait for start message if existing singing process fails + // wait for start message if existing signing process fails rp.Go(func(ctx context.Context) error { return c.waitForStart(ctx, tssProcesses, resultChn, peer.ID("")) }) @@ -316,7 +316,7 @@ func (c *Coordinator) waitForStart( log.Debug().Str("SessionID", tssProcess.SessionID()).Msgf("received start message from %s", startMsg.From) // having startMsg.From as "" is special case when peer is not selected in subset - // but should wait for start message if existing singing process fails + // but should wait for start message if existing signing process fails if coordinator != "" && startMsg.From != coordinator { log.Warn().Msgf("Received start message from a peer %s that is not the coordinator %s", startMsg.From.String(), coordinator.String()) continue