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

[API-3392] Profitability Checks #3

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
58 changes: 30 additions & 28 deletions cmd/solver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import (
"context"
"flag"
"fmt"
"github.com/skip-mev/go-fast-solver/txverifier"
"os/signal"
"syscall"
"time"

_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/mattn/go-sqlite3"
"github.com/skip-mev/go-fast-solver/db/connect"
"github.com/skip-mev/go-fast-solver/db/gen/db"
"github.com/skip-mev/go-fast-solver/txverifier"

"github.com/skip-mev/go-fast-solver/fundrebalancer"
"github.com/skip-mev/go-fast-solver/hyperlane"
"github.com/skip-mev/go-fast-solver/orderfulfiller"
"github.com/skip-mev/go-fast-solver/orderfulfiller/order_fulfillment_handler"
"github.com/skip-mev/go-fast-solver/ordersettler"
"github.com/skip-mev/go-fast-solver/shared/clientmanager"
"github.com/skip-mev/go-fast-solver/shared/clients/coingecko"
"github.com/skip-mev/go-fast-solver/shared/clients/skipgo"
"github.com/skip-mev/go-fast-solver/shared/clients/utils"

_ "github.com/golang-migrate/migrate/v4/source/file"
_ "github.com/mattn/go-sqlite3"
"github.com/skip-mev/go-fast-solver/shared/config"
"github.com/skip-mev/go-fast-solver/shared/evmrpc"
"github.com/skip-mev/go-fast-solver/shared/keys"
Expand Down Expand Up @@ -75,6 +80,18 @@ func main() {
}

evmManager := evmrpc.NewEVMRPCClientManager()
rateLimitedClient := utils.DefaultRateLimitedHTTPClient(3)
coingeckoClient := coingecko.NewCoingeckoClient(rateLimitedClient, "https://api.coingecko.com/api/v3/", "")
cachedCoinGeckoClient := coingecko.NewCachedPriceClient(coingeckoClient, 15*time.Minute)
evmTxPriceOracle := evmrpc.NewOracle(cachedCoinGeckoClient)

hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore, evmTxPriceOracle)
if err != nil {
lmt.Logger(ctx).Fatal("creating hyperlane multi client from config", zap.Error(err))
}

relayer := hyperlane.NewRelayer(hype, make(map[string]string))
relayerRunner := hyperlane.NewRelayerRunner(db.New(dbConn), hype, relayer)

eg, ctx := errgroup.WithContext(ctx)

Expand All @@ -88,16 +105,7 @@ func main() {
//})

eg.Go(func() error {
transferMonitor := transfermonitor.NewTransferMonitor(db.New(dbConn), *quickStart)
err := transferMonitor.Start(ctx)
if err != nil {
return fmt.Errorf("creating transfer monitor: %w", err)
}
return nil
})

eg.Go(func() error {
orderFillHandler, err := order_fulfillment_handler.NewOrderFulfillmentHandler(ctx, db.New(dbConn), clientManager)
orderFillHandler, err := order_fulfillment_handler.NewOrderFulfillmentHandler(ctx, db.New(dbConn), clientManager, relayerRunner)
if err != nil {
return err
}
Expand All @@ -117,44 +125,38 @@ func main() {
})

eg.Go(func() error {
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager)
r, err := ordersettler.NewOrderSettler(ctx, db.New(dbConn), clientManager, relayerRunner)
if err != nil {
return err
return fmt.Errorf("creating order settler: %w", err)
}
r.Run(ctx)
return nil
})

eg.Go(func() error {
r, err := ordersettler.NewOrderSettler(ctx, db.New(dbConn), clientManager)
r, err := fundrebalancer.NewFundRebalancer(ctx, *keysPath, skipgo, evmManager, db.New(dbConn))
if err != nil {
return fmt.Errorf("creating order settler: %w", err)
return fmt.Errorf("creating fund rebalancer: %w", err)
}
r.Run(ctx)
return nil
})

eg.Go(func() error {
r, err := fundrebalancer.NewFundRebalancer(ctx, *keysPath, skipgo, evmManager, db.New(dbConn))
r, err := txverifier.NewTxVerifier(ctx, db.New(dbConn), clientManager)
if err != nil {
return fmt.Errorf("creating fund rebalancer: %w", err)
return err
}
r.Run(ctx)
return nil
})

eg.Go(func() error {
hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmManager, keyStore)
if err != nil {
return fmt.Errorf("creating hyperlane multi client from config: %w", err)
}

relayer := hyperlane.NewRelayer(hype, make(map[string]string))
err = hyperlane.NewRelayerRunner(db.New(dbConn), hype, relayer).Run(ctx)
transferMonitor := transfermonitor.NewTransferMonitor(db.New(dbConn), *quickStart)
err := transferMonitor.Start(ctx)
if err != nil {
return fmt.Errorf("relaying message: %v", err)
return fmt.Errorf("creating transfer monitor: %w", err)
}

return nil
})

Expand Down
12 changes: 10 additions & 2 deletions cmd/solvercli/cmd/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ package cmd

import (
"encoding/json"
"time"

"os/signal"
"syscall"

"github.com/skip-mev/go-fast-solver/hyperlane"
"github.com/skip-mev/go-fast-solver/shared/clients/coingecko"
"github.com/skip-mev/go-fast-solver/shared/clients/utils"
"github.com/skip-mev/go-fast-solver/shared/config"
"github.com/skip-mev/go-fast-solver/shared/evmrpc"
"github.com/skip-mev/go-fast-solver/shared/keys"
Expand Down Expand Up @@ -89,12 +92,17 @@ var relayCmd = &cobra.Command{
return
}

hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore)
rateLimitedClient := utils.DefaultRateLimitedHTTPClient(3)
coingeckoClient := coingecko.NewCoingeckoClient(rateLimitedClient, "https://api.coingecko.com/api/v3/", "")
cachedCoinGeckoClient := coingecko.NewCachedPriceClient(coingeckoClient, 15*time.Minute)
evmTxPriceOracle := evmrpc.NewOracle(cachedCoinGeckoClient)

hype, err := hyperlane.NewMultiClientFromConfig(ctx, evmrpc.NewEVMRPCClientManager(), keyStore, evmTxPriceOracle)
if err != nil {
lmt.Logger(ctx).Error("Error creating hyperlane multi client from config", zap.Error(err))
}

destinationTxHash, destinationChainID, err := hyperlane.NewRelayer(hype, storageOverrideMap).Relay(ctx, originChainID, originTxHash)
destinationTxHash, destinationChainID, err := hyperlane.NewRelayer(hype, storageOverrideMap).Relay(ctx, originChainID, originTxHash, hyperlane.RelayOpts{})
if err != nil {
lmt.Logger(ctx).Error("Error relaying message", zap.Error(err))
return
Expand Down
20 changes: 16 additions & 4 deletions db/gen/db/hyperlane_transfers.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions db/gen/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions db/migrations/000006_hyperlane_transfers.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ CREATE TABLE IF NOT EXISTS hyperlane_transfers (
transfer_status TEXT NOT NULL,
transfer_status_message TEXT,

transfer_value TEXT,
max_gas_price_pct INTEGER,
Comment on lines +15 to +16
Copy link
Author

Choose a reason for hiding this comment

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

relay profitability options are now stored in the db along with the transfers info


UNIQUE(source_chain_id, destination_chain_id, message_id)
);
8 changes: 5 additions & 3 deletions db/queries/hyperlane_transfers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ INSERT INTO hyperlane_transfers (
destination_chain_id,
message_id,
message_sent_tx,
transfer_status
) VALUES (?, ?, ?, ?, ?) ON CONFLICT DO NOTHING RETURNING *;
transfer_status,
transfer_value,
max_gas_price_pct
) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT DO NOTHING RETURNING *;

-- name: GetAllHyperlaneTransfersWithTransferStatus :many
SELECT * FROM hyperlane_transfers WHERE transfer_status = ?;
Expand All @@ -14,4 +16,4 @@ SELECT * FROM hyperlane_transfers WHERE transfer_status = ?;
UPDATE hyperlane_transfers
SET updated_at=CURRENT_TIMESTAMP, transfer_status = ?, transfer_status_message = ?
WHERE source_chain_id = ? AND destination_chain_id = ? AND message_id = ?
RETURNING *;
RETURNING *;
14 changes: 12 additions & 2 deletions hyperlane/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hyperlane
import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/skip-mev/go-fast-solver/hyperlane/cosmos"
Expand All @@ -22,6 +23,7 @@ type Client interface {
Process(ctx context.Context, domain string, message []byte, metadata []byte) ([]byte, error)
IsContract(ctx context.Context, domain, address string) (bool, error)
GetHyperlaneDispatch(ctx context.Context, domain, originChainID, initiateTxHash string) (*types.MailboxDispatchEvent, *types.MailboxMerkleHookPostDispatchEvent, error)
QuoteProcessUUSDC(ctx context.Context, domain string, message []byte, metadata []byte) (*big.Int, error)
}

type MultiClient struct {
Expand All @@ -30,7 +32,7 @@ type MultiClient struct {

// NewMultiClientFromConfig creates a MultiClient that is configured for every
// chain specific in the config that has a HyperlaneDomain set
func NewMultiClientFromConfig(ctx context.Context, manager evmrpc.EVMRPCClientManager, keystore keys.KeyStore) (*MultiClient, error) {
func NewMultiClientFromConfig(ctx context.Context, manager evmrpc.EVMRPCClientManager, keystore keys.KeyStore, evmTxPriceOracle ethereum.TxPriceOracle) (*MultiClient, error) {
clients := make(map[string]Client)
for _, cfg := range config.GetConfigReader(ctx).Config().Chains {
if cfg.HyperlaneDomain == "" {
Expand All @@ -45,7 +47,7 @@ func NewMultiClientFromConfig(ctx context.Context, manager evmrpc.EVMRPCClientMa
}
clients[cfg.HyperlaneDomain] = client
case config.ChainType_EVM:
client, err := ethereum.NewHyperlaneClient(ctx, cfg.HyperlaneDomain, manager, keystore)
client, err := ethereum.NewHyperlaneClient(ctx, cfg.HyperlaneDomain, manager, keystore, evmTxPriceOracle)
if err != nil {
return nil, fmt.Errorf("creating cosmos hyperlane client for domain %s: %w", cfg.HyperlaneDomain, err)
}
Expand Down Expand Up @@ -121,6 +123,14 @@ func (c *MultiClient) Process(ctx context.Context, domain string, message []byte
return client.Process(ctx, domain, message, metadata)
}

func (c *MultiClient) QuoteProcessUUSDC(ctx context.Context, domain string, message []byte, metadata []byte) (*big.Int, error) {
client, ok := c.clients[domain]
if !ok {
return nil, fmt.Errorf("no configured client for domain %s", domain)
}
return client.QuoteProcessUUSDC(ctx, domain, message, metadata)
}

func (c *MultiClient) IsContract(ctx context.Context, domain, address string) (bool, error) {
client, ok := c.clients[domain]
if !ok {
Expand Down
5 changes: 5 additions & 0 deletions hyperlane/cosmos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cosmos
import (
"context"
"fmt"
"math/big"

"strconv"

Expand Down Expand Up @@ -223,6 +224,10 @@ func (c *HyperlaneClient) Process(ctx context.Context, domain string, message []
panic("not implemented")
}

func (c *HyperlaneClient) QuoteProcessUUSDC(ctx context.Context, domain string, message []byte, metadata []byte) (*big.Int, error) {
panic("not implemented")
}

func (c *HyperlaneClient) IsContract(ctx context.Context, domain, address string) (bool, error) {
panic("not implemented")
}
Loading
Loading