punm parser
This commit is contained in:
@@ -54,7 +54,7 @@ func main() {
|
||||
instructorErrIndex, customerErrCode, _ = txErr.GetCustomErrorCode()
|
||||
fmt.Printf("now: %s, block: %d, tx: %s, errInstr Code: %d, errInstrIndex: %d, err: %v\n", time.Now().Format("2006-01-02 15:04:05"), ptx.Block, ptx.GetTxHash(), customerErrCode, instructorErrIndex, ptx.Err)
|
||||
} else {
|
||||
txs := example.FromTx(ptx, msg.RawTx)
|
||||
txs := example.FromTx(ptx)
|
||||
if len(txs) == 0 {
|
||||
fmt.Printf("tx is empty, block: %d, tx %s \n", ptx.Block, ptx.GetTxHash())
|
||||
continue
|
||||
|
||||
@@ -18,5 +18,4 @@ type SubscriptionMessage struct {
|
||||
|
||||
Block *BlockInfo
|
||||
Tx *pump_parser.Tx
|
||||
RawTx *pump_parser.RawTx
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ import (
|
||||
)
|
||||
|
||||
type PumpHandler struct {
|
||||
callback func(*types.Tx, *types.RawTx)
|
||||
callback func(*types.Tx)
|
||||
}
|
||||
|
||||
func NewPumpHandler(cb func(*types.Tx, *types.RawTx)) *PumpHandler {
|
||||
func NewPumpHandler(cb func(*types.Tx)) *PumpHandler {
|
||||
return &PumpHandler{
|
||||
callback: func(tx *types.Tx, tx2 *types.RawTx) {
|
||||
callback: func(tx *types.Tx) {
|
||||
//tx.Check(tx2)
|
||||
cb(tx, tx2)
|
||||
cb(tx)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -40,11 +40,13 @@ func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) {
|
||||
|
||||
BeforeSolBalance: beforeSolBalance,
|
||||
AfterSOLBalance: afterSolBalance,
|
||||
}, rawTx)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
parsedTx, err := types.Parser(rawTx)
|
||||
var parsedTx = &types.Tx{}
|
||||
parsedTx.SetRawTx(rawTx)
|
||||
err := parsedTx.Parser()
|
||||
if err != nil {
|
||||
fmt.Printf("parser error: %s, block: %d tx: %s\n", err, rawTx.Slot, rawTx.TxHash())
|
||||
return
|
||||
@@ -55,6 +57,6 @@ func (h *PumpHandler) HandleMessage(rawTx *types.RawTx) {
|
||||
}
|
||||
// fmt.Println(parsedTx.GetTxHash(), len(parsedTx.Swaps))
|
||||
if h.callback != nil {
|
||||
h.callback(parsedTx, rawTx)
|
||||
h.callback(parsedTx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ func NewClientWithPumpSwap(endpoint string, ch chan SubscriptionMessage) *Client
|
||||
subStatus: false,
|
||||
subscription: &subscription,
|
||||
}
|
||||
c.handler = NewPumpHandler(func(tx *types.Tx, tx2 *types.RawTx) {
|
||||
c.sendTx(tx, tx2)
|
||||
c.handler = NewPumpHandler(func(tx *types.Tx) {
|
||||
c.sendTx(tx)
|
||||
})
|
||||
return c
|
||||
}
|
||||
@@ -107,8 +107,8 @@ func NewClientWithLaunchLab(endpoint string, ch chan SubscriptionMessage) *Clien
|
||||
subStatus: false,
|
||||
subscription: &subscription,
|
||||
}
|
||||
c.handler = NewPumpHandler(func(tx *types.Tx, tx2 *types.RawTx) {
|
||||
c.sendTx(tx, tx2)
|
||||
c.handler = NewPumpHandler(func(tx *types.Tx) {
|
||||
c.sendTx(tx)
|
||||
})
|
||||
return c
|
||||
}
|
||||
@@ -262,13 +262,12 @@ func (c *Client) computeDelay(slot uint64) int64 {
|
||||
return delay
|
||||
}
|
||||
|
||||
func (c *Client) sendTx(t *types.Tx, tx *types.RawTx) {
|
||||
func (c *Client) sendTx(t *types.Tx) {
|
||||
c.ch <- SubscriptionMessage{
|
||||
Reconnect: c.firstMessage,
|
||||
EstimateDelaySecond: c.computeDelay(tx.Slot),
|
||||
EstimateDelaySecond: c.computeDelay(t.Block),
|
||||
Block: nil,
|
||||
Tx: t,
|
||||
RawTx: tx,
|
||||
}
|
||||
c.firstMessage = false
|
||||
}
|
||||
@@ -287,8 +286,7 @@ func (c *Client) sendBlock(blockMeta *pb.SubscribeUpdateBlockMeta) {
|
||||
BlockHash: c.leastBlock.BlockHash,
|
||||
Height: c.leastBlock.Height,
|
||||
},
|
||||
Tx: nil,
|
||||
RawTx: nil,
|
||||
Tx: nil,
|
||||
}
|
||||
c.firstMessage = false
|
||||
}
|
||||
|
||||
@@ -64,14 +64,15 @@ func (tx *Tx) GetTxHash() string {
|
||||
return tx.CachedTxHash
|
||||
}
|
||||
|
||||
func FromTx(tx *parser.Tx, raw *parser.RawTx) []*Tx {
|
||||
var txs []*Tx = make([]*Tx, 0, len(tx.Swaps))
|
||||
func FromTx(tx *parser.Tx) []*Tx {
|
||||
var txs = make([]*Tx, 0, len(tx.Swaps))
|
||||
mev, mevFee := tx.CheckMevAgent()
|
||||
for i, s := range tx.Swaps {
|
||||
var newTx *Tx
|
||||
platform, platformFee := tx.CheckPlatform(s, raw)
|
||||
platform, platformFee := tx.CheckPlatform(s)
|
||||
token0Program := s.BaseTokenProgram
|
||||
token0Address := s.BaseMint
|
||||
token0Decimals := s.BaseMintDecimals
|
||||
if s.Program == "Pump" {
|
||||
newTx = &Tx{
|
||||
Err: nil,
|
||||
@@ -126,6 +127,7 @@ func FromTx(tx *parser.Tx, raw *parser.RawTx) []*Tx {
|
||||
}
|
||||
token0Program = s.QuoteTokenProgram
|
||||
token0Address = s.QuoteMint
|
||||
token0Decimals = s.QuoteMintDecimals
|
||||
newTx = &Tx{
|
||||
Err: nil,
|
||||
//BondingCurve: s.Pool.String(),
|
||||
@@ -220,7 +222,7 @@ func FromTx(tx *parser.Tx, raw *parser.RawTx) []*Tx {
|
||||
}
|
||||
if newTx.Maker == "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K" && newTx.EntryContract == "oKXAggregatorV2" {
|
||||
newTx.Maker = tx.Signer.String()
|
||||
newTx.AfterSignerToken0Balance = parser.GetTokenBalanceAfterTx(raw, 0, token0Program, token0Address)
|
||||
newTx.AfterSignerToken0Balance = tx.GetSignerTokenBalanceAfterTx(token0Program, token0Address).Div(decimal.New(1, int32(token0Decimals)))
|
||||
}
|
||||
|
||||
txs = append(txs, newTx)
|
||||
|
||||
Reference in New Issue
Block a user