Skip to content

Commit

Permalink
BE-586 | Requested changes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
deividaspetraitis committed Oct 30, 2024
1 parent 131ba9e commit 172b2ad
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 320 deletions.
2 changes: 0 additions & 2 deletions app/sidecar_query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,6 @@ func NewSideCarQueryServer(appCodec codec.Codec, config domain.Config, logger lo
keyring,
orderBookUseCase,
poolsUseCase,
orderBookRepository,
orderBookAPIClient,
logger,
config.ChainGRPCGatewayEndpoint,
config.ChainID,
Expand Down
26 changes: 21 additions & 5 deletions domain/mocks/orderbook_usecase_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import (
"github.com/osmosis-labs/sqs/domain/mvc"
orderbookdomain "github.com/osmosis-labs/sqs/domain/orderbook"
"github.com/osmosis-labs/sqs/sqsdomain"

"github.com/osmosis-labs/osmosis/osmomath"
)

var _ mvc.OrderBookUsecase = &OrderbookUsecaseMock{}

// OrderbookUsecaseMock is a mock implementation of the RouterUsecase interface
type OrderbookUsecaseMock struct {
ProcessPoolFunc func(ctx context.Context, pool sqsdomain.PoolI) error
GetAllTicksFunc func(poolID uint64) (map[int64]orderbookdomain.OrderbookTick, bool)
GetActiveOrdersFunc func(ctx context.Context, address string) ([]orderbookdomain.LimitOrder, bool, error)
GetActiveOrdersStreamFunc func(ctx context.Context, address string) <-chan orderbookdomain.OrderbookResult
CreateFormattedLimitOrderFunc func(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)
ProcessPoolFunc func(ctx context.Context, pool sqsdomain.PoolI) error
GetAllTicksFunc func(poolID uint64) (map[int64]orderbookdomain.OrderbookTick, bool)
GetActiveOrdersFunc func(ctx context.Context, address string) ([]orderbookdomain.LimitOrder, bool, error)
GetActiveOrdersStreamFunc func(ctx context.Context, address string) <-chan orderbookdomain.OrderbookResult
CreateFormattedLimitOrderFunc func(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)
GetClaimableOrdersForOrderbookFunc func(ctx context.Context, fillThreshold osmomath.Dec, orderbook domain.CanonicalOrderBooksResult) (orderbookdomain.Orders, error)
}

func (m *OrderbookUsecaseMock) ProcessPool(ctx context.Context, pool sqsdomain.PoolI) error {
Expand Down Expand Up @@ -59,3 +62,16 @@ func (m *OrderbookUsecaseMock) CreateFormattedLimitOrder(orderbook domain.Canoni
}
panic("unimplemented")
}

func (m *OrderbookUsecaseMock) GetClaimableOrdersForOrderbook(ctx context.Context, fillThreshold osmomath.Dec, orderbook domain.CanonicalOrderBooksResult) (orderbookdomain.Orders, error) {
if m.GetClaimableOrdersForOrderbookFunc != nil {
return m.GetClaimableOrdersForOrderbookFunc(ctx, fillThreshold, orderbook)
}
panic("unimplemented")
}

func (m *OrderbookUsecaseMock) WithGetClaimableOrdersForOrderbook(orders orderbookdomain.Orders, err error) {
m.GetClaimableOrdersForOrderbookFunc = func(ctx context.Context, fillThreshold osmomath.Dec, orderbook domain.CanonicalOrderBooksResult) (orderbookdomain.Orders, error) {
return orders, err
}
}
6 changes: 6 additions & 0 deletions domain/mvc/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mvc
import (
"context"

"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/sqs/domain"
orderbookdomain "github.com/osmosis-labs/sqs/domain/orderbook"
"github.com/osmosis-labs/sqs/sqsdomain"
Expand All @@ -25,4 +26,9 @@ type OrderBookUsecase interface {

// CreateFormattedLimitOrder creates a formatted limit order from the given orderbook and order.
CreateFormattedLimitOrder(orderbook domain.CanonicalOrderBooksResult, order orderbookdomain.Order) (orderbookdomain.LimitOrder, error)

// GetClaimableOrdersForOrderbook retrieves all claimable orders for a given orderbook.
// It fetches all ticks for the orderbook, processes each tick to find claimable orders,
// and returns a combined list of all claimable orders across all ticks.
GetClaimableOrdersForOrderbook(ctx context.Context, fillThreshold osmomath.Dec, orderbook domain.CanonicalOrderBooksResult) (orderbookdomain.Orders, error)
}
16 changes: 16 additions & 0 deletions domain/orderbook/orderbook_tick.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,19 @@ type TickValues struct {
// sync.
LastTickSyncEtas string `json:"last_tick_sync_etas"`
}

// isTickFullyFilled checks if a tick is fully filled by comparing its cumulative total value
// to its effective total amount swapped.
func (tv *TickValues) IsTickFullyFilled() (bool, error) {
cumulativeTotalValue, err := osmomath.NewDecFromStr(tv.CumulativeTotalValue)
if err != nil {
return false, err
}

effectiveTotalAmountSwapped, err := osmomath.NewDecFromStr(tv.EffectiveTotalAmountSwapped)
if err != nil {
return false, err
}

return cumulativeTotalValue.Equal(effectiveTotalAmountSwapped), nil
}
44 changes: 18 additions & 26 deletions ingest/usecase/plugins/orderbook/claimbot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
sqstx "github.com/osmosis-labs/sqs/domain/cosmos/tx"
"github.com/osmosis-labs/sqs/domain/keyring"
"github.com/osmosis-labs/sqs/domain/mvc"
orderbookdomain "github.com/osmosis-labs/sqs/domain/orderbook"
orderbookgrpcclientdomain "github.com/osmosis-labs/sqs/domain/orderbook/grpcclient"
"github.com/osmosis-labs/sqs/log"

txfeestypes "github.com/osmosis-labs/osmosis/v26/x/txfees/types"
Expand All @@ -17,26 +15,22 @@ import (

// Config is the configuration for the claimbot plugin
type Config struct {
Keyring keyring.Keyring
PoolsUseCase mvc.PoolsUsecase
OrderbookUsecase mvc.OrderBookUsecase
OrderbookRepository orderbookdomain.OrderBookRepository
OrderBookClient orderbookgrpcclientdomain.OrderBookClient
AccountQueryClient authtypes.QueryClient
TxfeesClient txfeestypes.QueryClient
GasCalculator sqstx.GasCalculator
TxServiceClient txtypes.ServiceClient
ChainID string
Logger log.Logger
Keyring keyring.Keyring
PoolsUseCase mvc.PoolsUsecase
OrderbookUsecase mvc.OrderBookUsecase
AccountQueryClient authtypes.QueryClient
TxfeesClient txfeestypes.QueryClient
GasCalculator sqstx.GasCalculator
TxServiceClient txtypes.ServiceClient
ChainID string
Logger log.Logger
}

// NewConfig creates a new Config instance.
func NewConfig(
keyring keyring.Keyring,
orderbookusecase mvc.OrderBookUsecase,
poolsUseCase mvc.PoolsUsecase,
orderbookRepository orderbookdomain.OrderBookRepository,
orderBookClient orderbookgrpcclientdomain.OrderBookClient,
logger log.Logger,
chainGRPCGatewayEndpoint string,
chainID string,
Expand All @@ -47,16 +41,14 @@ func NewConfig(
}

return &Config{
Keyring: keyring,
PoolsUseCase: poolsUseCase,
OrderbookUsecase: orderbookusecase,
OrderbookRepository: orderbookRepository,
OrderBookClient: orderBookClient,
AccountQueryClient: authtypes.NewQueryClient(grpcClient),
TxfeesClient: txfeestypes.NewQueryClient(grpcClient),
GasCalculator: sqstx.NewGasCalculator(grpcClient),
TxServiceClient: txtypes.NewServiceClient(grpcClient),
Logger: logger.Named("claimbot"),
ChainID: chainID,
Keyring: keyring,
PoolsUseCase: poolsUseCase,
OrderbookUsecase: orderbookusecase,
AccountQueryClient: authtypes.NewQueryClient(grpcClient),
TxfeesClient: txfeestypes.NewQueryClient(grpcClient),
GasCalculator: sqstx.NewGasCalculator(grpcClient),
TxServiceClient: txtypes.NewServiceClient(grpcClient),
Logger: logger.Named("claimbot"),
ChainID: chainID,
}, nil
}
15 changes: 5 additions & 10 deletions ingest/usecase/plugins/orderbook/claimbot/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@ import (
"context"

"github.com/osmosis-labs/sqs/domain"
authtypes "github.com/osmosis-labs/sqs/domain/cosmos/auth/types"
sqstx "github.com/osmosis-labs/sqs/domain/cosmos/tx"
"github.com/osmosis-labs/sqs/domain/keyring"
"github.com/osmosis-labs/sqs/domain/mvc"
orderbookdomain "github.com/osmosis-labs/sqs/domain/orderbook"
orderbookgrpcclientdomain "github.com/osmosis-labs/sqs/domain/orderbook/grpcclient"
"github.com/osmosis-labs/sqs/log"

txfeestypes "github.com/osmosis-labs/osmosis/v26/x/txfees/types"

"github.com/osmosis-labs/osmosis/osmomath"

sdk "github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

// ProcessedOrderbook is order alias data structure for testing purposes.
Expand All @@ -27,30 +25,27 @@ type ProcessedOrderbook = processedOrderbook
// This function is exported for testing purposes.
func ProcessOrderbooksAndGetClaimableOrders(
ctx context.Context,
orderbookusecase mvc.OrderBookUsecase,
fillThreshold osmomath.Dec,
orderbooks []domain.CanonicalOrderBooksResult,
orderbookRepository orderbookdomain.OrderBookRepository,
orderBookClient orderbookgrpcclientdomain.OrderBookClient,
orderbookusecase mvc.OrderBookUsecase,
logger log.Logger,
) ([]ProcessedOrderbook, error) {
return processOrderbooksAndGetClaimableOrders(ctx, fillThreshold, orderbooks, orderbookRepository, orderBookClient, orderbookusecase, logger)
return processOrderbooksAndGetClaimableOrders(ctx, orderbookusecase, fillThreshold, orderbooks)
}

// SendBatchClaimTx a test wrapper for sendBatchClaimTx.
// This function is used only for testing purposes.
func SendBatchClaimTx(
ctx context.Context,
keyring keyring.Keyring,
accountQueryClient authtypes.QueryClient,
txfeesClient txfeestypes.QueryClient,
gasCalculator sqstx.GasCalculator,
txServiceClient txtypes.ServiceClient,
chainID string,
account *authtypes.BaseAccount,
contractAddress string,
claims orderbookdomain.Orders,
) (*sdk.TxResponse, error) {
return sendBatchClaimTx(ctx, keyring, accountQueryClient, txfeesClient, gasCalculator, txServiceClient, chainID, contractAddress, claims)
return sendBatchClaimTx(ctx, keyring, txfeesClient, gasCalculator, txServiceClient, chainID, account, contractAddress, claims)
}

// PrepareBatchClaimMsg is a test wrapper for prepareBatchClaimMsg.
Expand Down
Loading

0 comments on commit 172b2ad

Please sign in to comment.