chore: add all
This commit is contained in:
6
pkg/consts/consts.go
Normal file
6
pkg/consts/consts.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package consts
|
||||
|
||||
const (
|
||||
SolDecimals = 9 // Decimals for SOL
|
||||
TokenDecimals = 6 // Default decimals for SPL tokens
|
||||
)
|
||||
18
pkg/logger/logger.go
Normal file
18
pkg/logger/logger.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package logger
|
||||
|
||||
type Logger interface {
|
||||
Info(a ...interface{})
|
||||
Infof(format string, a ...interface{})
|
||||
|
||||
Error(a ...interface{})
|
||||
Errorf(format string, a ...interface{})
|
||||
|
||||
Debug(a ...interface{})
|
||||
Debugf(format string, a ...interface{})
|
||||
|
||||
Warn(a ...interface{})
|
||||
Warnf(format string, a ...interface{})
|
||||
|
||||
Fatal(a ...interface{})
|
||||
Fatalf(format string, a ...interface{})
|
||||
}
|
||||
105
pkg/shreder/shreder_client.go
Normal file
105
pkg/shreder/shreder_client.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package shreder_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/samlior/libsam/pkg/logger"
|
||||
"github.com/samlior/libsam/pkg/txparser"
|
||||
"github.com/samlior/libsam/pkg/types"
|
||||
"github.com/samlior/libsam/third_party/shreder_protos"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type ShrederClient struct {
|
||||
log logger.Logger
|
||||
|
||||
conn *grpc.ClientConn
|
||||
client shreder_protos.ShrederServiceClient
|
||||
}
|
||||
|
||||
func NewShrederClient(logger logger.Logger, url string) (*ShrederClient, func(), error) {
|
||||
conn, err := grpc.NewClient(url, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return nil, func() {}, err
|
||||
}
|
||||
|
||||
s := &ShrederClient{
|
||||
log: logger,
|
||||
conn: conn,
|
||||
client: shreder_protos.NewShrederServiceClient(conn),
|
||||
}
|
||||
|
||||
return s, func() {
|
||||
s.Wait()
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *ShrederClient) Wait() {
|
||||
c.log.Debug("waiting for shreder client to stop")
|
||||
|
||||
err := c.conn.Close()
|
||||
if err != nil {
|
||||
c.log.Errorf("failed to close connection: %v", err)
|
||||
}
|
||||
|
||||
c.log.Debug("shreder client stopped")
|
||||
}
|
||||
|
||||
func (c *ShrederClient) ReadSync(ctx context.Context, txCh chan<- types.TxSignalBatch) error {
|
||||
stream, err := c.client.SubscribeTransactions(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = stream.Send(&shreder_protos.SubscribeTransactionsRequest{
|
||||
Transactions: map[string]*shreder_protos.SubscribeRequestFilterTransactions{
|
||||
"pumpfun": {
|
||||
AccountRequired: []string{
|
||||
"6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P",
|
||||
},
|
||||
},
|
||||
"axiom": {
|
||||
AccountRequired: []string{
|
||||
"F5tfvbLog9VdGUPqBDTT8rgXvTTcq7e5UiGnupL1zvBq",
|
||||
},
|
||||
},
|
||||
"photon": {
|
||||
AccountRequired: []string{
|
||||
"BSfD6SHZigAfDWSjzD5Q41jw8LmKwtmjskPH9XW1mrRW",
|
||||
},
|
||||
},
|
||||
"fjsz": {
|
||||
AccountRequired: []string{
|
||||
"FJsZbftBqRLfF7uqUKpm4s2goDr6xsQ5Q3mN7AFJB6hK",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
response, err := stream.Recv()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
txBatch := txparser.ParseTransaction(response.Transaction)
|
||||
if len(txBatch) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// set fixed source for tx signals
|
||||
for _, tx := range txBatch {
|
||||
tx.Source = "shreder"
|
||||
}
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case txCh <- txBatch:
|
||||
}
|
||||
}
|
||||
}
|
||||
1232
pkg/txparser/txparser.go
Normal file
1232
pkg/txparser/txparser.go
Normal file
File diff suppressed because it is too large
Load Diff
38
pkg/types/tx_signal.go
Normal file
38
pkg/types/tx_signal.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/samlior/libsam/pkg/consts"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type TxSignal struct {
|
||||
Source string
|
||||
TxHash string
|
||||
Maker string
|
||||
Token0Address string
|
||||
Token1Address string
|
||||
Token0Amount decimal.Decimal
|
||||
Token1Amount decimal.Decimal
|
||||
Block uint64
|
||||
BlockAt time.Time
|
||||
BlockIndex uint64
|
||||
Event string
|
||||
Program string
|
||||
IsProcessed bool
|
||||
IsToken2022 bool
|
||||
IsMayhemMode bool
|
||||
TxFee decimal.Decimal
|
||||
|
||||
Token0AmountUint64 uint64
|
||||
Token1AmountUint64 uint64
|
||||
}
|
||||
|
||||
func (t *TxSignal) Parse() *TxSignal {
|
||||
t.Token0AmountUint64 = t.Token0Amount.Mul(decimal.New(1, consts.TokenDecimals)).BigInt().Uint64()
|
||||
t.Token1AmountUint64 = t.Token1Amount.Mul(decimal.New(1, consts.SolDecimals)).BigInt().Uint64()
|
||||
return t
|
||||
}
|
||||
|
||||
type TxSignalBatch = []*TxSignal
|
||||
Reference in New Issue
Block a user