Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ genmocks:
mockgen -source=./chains/evm/message/confirmations.go -destination=./chains/evm/message/mock/confirmations.go
mockgen -source=./api/handlers/signing.go -destination=./api/handlers/mock/signing.go
mockgen -package mock_message -destination=./chains/evm/message/mock/pricing.go github.com/sprintertech/lifi-solver/pkg/pricing OrderPricer
mockgen -source=./chains/lighter/message/lighter.go -destination=./chains/lighter/message/mock/lighter.go



Expand Down
19 changes: 17 additions & 2 deletions api/handlers/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
evmMessage "github.com/sprintertech/sprinter-signing/chains/evm/message"
lighterMessage "github.com/sprintertech/sprinter-signing/chains/lighter/message"
"github.com/sygmaprotocol/sygma-core/relayer/message"
)

Expand All @@ -20,8 +21,9 @@ const (
AcrossProtocol ProtocolType = "across"
MayanProtocol ProtocolType = "mayan"
RhinestoneProtocol ProtocolType = "rhinestone"
LifiEscrow ProtocolType = "lifi-escrow"
LifiEscrowProtocol ProtocolType = "lifi-escrow"
LifiProtocol ProtocolType = "lifi"
LighterProtocol ProtocolType = "lighter"
)

type SigningBody struct {
Expand Down Expand Up @@ -113,7 +115,7 @@ func (h *SigningHandler) HandleSigning(w http.ResponseWriter, r *http.Request) {
BorrowAmount: b.BorrowAmount.Int,
})
}
case LifiEscrow:
case LifiEscrowProtocol:
{
m = evmMessage.NewLifiEscrowData(0, b.ChainId, &evmMessage.LifiEscrowData{
OrderID: b.DepositId,
Expand All @@ -126,6 +128,19 @@ func (h *SigningHandler) HandleSigning(w http.ResponseWriter, r *http.Request) {
BorrowAmount: b.BorrowAmount.Int,
})
}
case LighterProtocol:
{
m = lighterMessage.NewLighterMessage(0, b.ChainId, &lighterMessage.LighterData{
OrderHash: b.DepositId,
Nonce: b.Nonce.Int,
LiquidityPool: common.HexToAddress(b.LiquidityPool),
Caller: common.HexToAddress(b.Caller),
BorrowAmount: b.BorrowAmount.Int,
ErrChn: errChn,
Source: 0,
Destination: b.ChainId,
})
}
default:
JSONError(w, fmt.Errorf("invalid protocol %s", b.Protocol), http.StatusBadRequest)
return
Expand Down
35 changes: 35 additions & 0 deletions api/handlers/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/sprintertech/sprinter-signing/api/handlers"
mock_handlers "github.com/sprintertech/sprinter-signing/api/handlers/mock"
across "github.com/sprintertech/sprinter-signing/chains/evm/message"
lighter "github.com/sprintertech/sprinter-signing/chains/lighter/message"
"github.com/stretchr/testify/suite"
"github.com/sygmaprotocol/sygma-core/relayer/message"
"go.uber.org/mock/gomock"
Expand Down Expand Up @@ -394,6 +395,40 @@ func (s *SigningHandlerTestSuite) Test_HandleSigning_LifiSuccess() {
s.Equal(http.StatusAccepted, recorder.Code)
}

func (s *SigningHandlerTestSuite) Test_HandleSigning_LighterSuccess() {
msgChn := make(chan []*message.Message)
handler := handlers.NewSigningHandler(msgChn, s.chains)

input := handlers.SigningBody{
DepositId: "depositID",
Protocol: "lighter",
LiquidityPool: "0xbe526bA5d1ad94cC59D7A79d99A59F607d31A657",
Caller: "0xbe526bA5d1ad94cC59D7A79d99A59F607d31A657",
Calldata: "0xbe5",
Nonce: &handlers.BigInt{big.NewInt(1001)},
BorrowAmount: &handlers.BigInt{big.NewInt(1000)},
}
body, _ := json.Marshal(input)

req := httptest.NewRequest(http.MethodPost, "/v1/chains/1/signatures", bytes.NewReader(body))
req = mux.SetURLVars(req, map[string]string{
"chainId": "1",
})
req.Header.Set("Content-Type", "application/json")

recorder := httptest.NewRecorder()

go func() {
msg := <-msgChn
ad := msg[0].Data.(*lighter.LighterData)
ad.ErrChn <- nil
}()

handler.HandleSigning(recorder, req)

s.Equal(http.StatusAccepted, recorder.Code)
}

type StatusHandlerTestSuite struct {
suite.Suite

Expand Down
32 changes: 27 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ 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"
"github.com/sprintertech/sprinter-signing/chains/lighter"
lighterMessage "github.com/sprintertech/sprinter-signing/chains/lighter/message"
"github.com/sprintertech/sprinter-signing/comm"
"github.com/sprintertech/sprinter-signing/comm/elector"
"github.com/sprintertech/sprinter-signing/comm/p2p"
"github.com/sprintertech/sprinter-signing/config"
Expand All @@ -42,6 +45,7 @@ import (
"github.com/sprintertech/sprinter-signing/price"
"github.com/sprintertech/sprinter-signing/protocol/across"
"github.com/sprintertech/sprinter-signing/protocol/lifi"
lighterAPI "github.com/sprintertech/sprinter-signing/protocol/lighter"
"github.com/sprintertech/sprinter-signing/protocol/mayan"
"github.com/sprintertech/sprinter-signing/topology"
"github.com/sprintertech/sprinter-signing/tss"
Expand Down Expand Up @@ -254,7 +258,7 @@ func Run() error {
sigChn)
go acrossMh.Listen(ctx)

mh.RegisterMessageHandler(evmMessage.AcrossMessage, acrossMh)
mh.RegisterMessageHandler(message.MessageType(comm.AcrossMsg.String()), acrossMh)
supportedChains[*c.GeneralChainConfig.Id] = struct{}{}
confirmationsPerChain[*c.GeneralChainConfig.Id] = c.ConfirmationsByValue
}
Expand All @@ -278,7 +282,7 @@ func Run() error {
sigChn)
go mayanMh.Listen(ctx)

mh.RegisterMessageHandler(evmMessage.MayanMessage, mayanMh)
mh.RegisterMessageHandler(message.MessageType(comm.MayanMsg.String()), mayanMh)
supportedChains[*c.GeneralChainConfig.Id] = struct{}{}
confirmationsPerChain[*c.GeneralChainConfig.Id] = c.ConfirmationsByValue
}
Expand All @@ -291,7 +295,7 @@ func Run() error {
resolver := token.NewTokenResolver(solverConfig, usdPricer)
orderPricer := pricing.NewStandardPricer(resolver)
lifiApi := lifi.NewLifiAPI()
lifiValidator := validation.NewLifiEscrowOrderValidator(solverConfig, orderPricer)
lifiValidator := validation.NewLifiEscrowOrderValidator(solverConfig, orderPricer, resolver)

lifiMh := evmMessage.NewLifiEscrowMessageHandler(
*c.GeneralChainConfig.Id,
Expand All @@ -309,7 +313,7 @@ func Run() error {
sigChn,
)
go lifiMh.Listen(ctx)
mh.RegisterMessageHandler(evmMessage.LifiEscrowMessage, lifiMh)
mh.RegisterMessageHandler(message.MessageType(comm.LifiEscrowMsg.String()), lifiMh)
supportedChains[*c.GeneralChainConfig.Id] = struct{}{}
confirmationsPerChain[*c.GeneralChainConfig.Id] = c.ConfirmationsByValue
}
Expand All @@ -323,7 +327,7 @@ func Run() error {
keyshareStore,
)
go lifiUnlockMh.Listen(ctx)
mh.RegisterMessageHandler(evmMessage.LifiUnlockMessage, lifiUnlockMh)
mh.RegisterMessageHandler(message.MessageType(comm.LifiUnlockMsg.String()), lifiUnlockMh)

var startBlock *big.Int
var listener *coreListener.EVMListener
Expand All @@ -349,6 +353,24 @@ func Run() error {
}
}

lighterConfig, err := lighter.NewLighterConfig(*solverConfig)
panicOnError(err)
lighterAPI := lighterAPI.NewLighterAPI()
lighterMessageHandler := lighterMessage.NewLighterMessageHandler(
lighterConfig.WithdrawalAddress,
lighterConfig.UsdcAddress,
lighterConfig.RepaymentAddress,
lighterAPI,
coordinator,
host,
communication,
keyshareStore,
sigChn,
)
go lighterMessageHandler.Listen(ctx)
lighterChain := lighter.NewLighterChain(lighterMessageHandler)
domains[lighter.LIGHTER_DOMAIN_ID] = lighterChain

go jobs.StartCommunicationHealthCheckJob(host, configuration.RelayerConfig.MpcConfig.CommHealthCheckInterval, sygmaMetrics)

r := relayer.NewRelayer(domains, sygmaMetrics)
Expand Down
19 changes: 19 additions & 0 deletions chains/evm/calls/consts/lighter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package consts

import (
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
)

var LighterABI, _ = abi.JSON(strings.NewReader(`[{
"name": "withdraw",
"type": "function",
"stateMutability": "nonpayable",
"inputs": [
{"name": "txHash", "type": "bytes32"},
{"name": "toAddress", "type": "address"},
{"name": "amount", "type": "uint256"}
],
"outputs": []
}]`))
3 changes: 2 additions & 1 deletion chains/evm/message/across.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/rs/zerolog/log"
"github.com/sprintertech/sprinter-signing/chains/evm/calls/events"
"github.com/sprintertech/sprinter-signing/chains/evm/signature"
"github.com/sprintertech/sprinter-signing/comm"
"github.com/sprintertech/sprinter-signing/tss"
"github.com/sprintertech/sprinter-signing/tss/ecdsa/signing"
Expand Down Expand Up @@ -141,7 +142,7 @@ func (h *AcrossMessageHandler) HandleMessage(m *message.Message) (*proposal.Prop
return nil, err
}

unlockHash, err := borrowUnlockHash(
unlockHash, err := signature.BorrowUnlockHash(
calldata,
d.OutputAmount,
common.BytesToAddress(d.OutputToken[12:]),
Expand Down
3 changes: 2 additions & 1 deletion chains/evm/message/lifiEscrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/rs/zerolog/log"
"github.com/sprintertech/sprinter-signing/chains/evm/calls/consts"
"github.com/sprintertech/sprinter-signing/chains/evm/signature"
"github.com/sprintertech/sprinter-signing/comm"
"github.com/sprintertech/sprinter-signing/config"
"github.com/sprintertech/sprinter-signing/tss"
Expand Down Expand Up @@ -150,7 +151,7 @@ func (h *LifiEscrowMessageHandler) HandleMessage(m *message.Message) (*proposal.
big.NewInt(order.Order.FillDeadline.Unix()).Uint64(),
)

unlockHash, err := borrowUnlockHash(
unlockHash, err := signature.BorrowUnlockHash(
calldata,
data.BorrowAmount,
borrowToken,
Expand Down
3 changes: 2 additions & 1 deletion chains/evm/message/mayan.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"
"github.com/rs/zerolog/log"
"github.com/sprintertech/sprinter-signing/chains/evm/calls/contracts"
"github.com/sprintertech/sprinter-signing/chains/evm/signature"
"github.com/sprintertech/sprinter-signing/comm"
"github.com/sprintertech/sprinter-signing/config"
"github.com/sprintertech/sprinter-signing/protocol/mayan"
Expand Down Expand Up @@ -160,7 +161,7 @@ func (h *MayanMessageHandler) HandleMessage(m *message.Message) (*proposal.Propo

data.ErrChn <- nil

unlockHash, err := borrowUnlockHash(
unlockHash, err := signature.BorrowUnlockHash(
calldataBytes,
data.BorrowAmount,
destinationBorrowToken.Address,
Expand Down
Loading
Loading