Merge branch 'master' of https://github.com/samlior/libsam
This commit is contained in:
@@ -1253,6 +1253,38 @@ func findPumpFunMint(tx VersionedTransaction, accounts []uint8) (solana.PublicKe
|
|||||||
return solana.PublicKey{}, false, nil
|
return solana.PublicKey{}, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findPreferredToken1Mint(tx VersionedTransaction, accounts []uint8) (solana.PublicKey, bool, error) {
|
||||||
|
var stableMint solana.PublicKey
|
||||||
|
sawSystemProgram := false
|
||||||
|
|
||||||
|
for _, acctIdx := range accounts {
|
||||||
|
key, err := tx.GetAccount(int(acctIdx))
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch {
|
||||||
|
case key.Equals(solana.WrappedSol):
|
||||||
|
return solana.WrappedSol, true, nil
|
||||||
|
case isStableMint(key):
|
||||||
|
if stableMint.IsZero() {
|
||||||
|
stableMint = key
|
||||||
|
} else if !stableMint.Equals(key) {
|
||||||
|
return solana.PublicKey{}, false, nil
|
||||||
|
}
|
||||||
|
case key.Equals(solana.SystemProgramID):
|
||||||
|
sawSystemProgram = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !stableMint.IsZero() {
|
||||||
|
return stableMint, true, nil
|
||||||
|
}
|
||||||
|
if sawSystemProgram {
|
||||||
|
return solana.WrappedSol, true, nil
|
||||||
|
}
|
||||||
|
return solana.PublicKey{}, false, nil
|
||||||
|
}
|
||||||
|
|
||||||
func jupiterV6SourceDestMints(msg VersionedTransaction, instruction Instructions, disc []byte) (solana.PublicKey, solana.PublicKey, bool, error) {
|
func jupiterV6SourceDestMints(msg VersionedTransaction, instruction Instructions, disc []byte) (solana.PublicKey, solana.PublicKey, bool, error) {
|
||||||
switch {
|
switch {
|
||||||
case bytes.Equal(disc, jupiterRouteV2),
|
case bytes.Equal(disc, jupiterRouteV2),
|
||||||
@@ -1406,6 +1438,10 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
|||||||
if len(instruction.Accounts) < 13 {
|
if len(instruction.Accounts) < 13 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
token1Mint, token1MintOK, err := findPreferredToken1Mint(tx, instruction.Accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
destMint, err := tx.GetAccount(int(instruction.Accounts[5]))
|
destMint, err := tx.GetAccount(int(instruction.Accounts[5]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1422,13 +1458,26 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
|||||||
if routeIn > 0 {
|
if routeIn > 0 {
|
||||||
token0Amount = formatTokenAmount(routeIn)
|
token0Amount = formatTokenAmount(routeIn)
|
||||||
}
|
}
|
||||||
|
token1Amount := decimal.Zero
|
||||||
|
token1Address := wsolMint
|
||||||
|
if destMint.Equals(solana.WrappedSol) || destMint.Equals(solana.SystemProgramID) {
|
||||||
|
token1Address = wsolMint
|
||||||
|
if routeOut > 0 {
|
||||||
|
token1Amount = formatSolAmount(routeOut)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
token1Address = destMint.String()
|
||||||
|
if routeOut > 0 {
|
||||||
|
token1Amount = formatTokenAmount(routeOut)
|
||||||
|
}
|
||||||
|
}
|
||||||
return TxSignalBatch{&TxSignal{
|
return TxSignalBatch{&TxSignal{
|
||||||
TxHash: tx.Signatures[0].String(),
|
TxHash: tx.Signatures[0].String(),
|
||||||
Maker: tx.StaticAccountKeys[0].String(),
|
Maker: tx.StaticAccountKeys[0].String(),
|
||||||
Token0Address: pumpMint.String(),
|
Token0Address: pumpMint.String(),
|
||||||
Token1Address: destMint.String(),
|
Token1Address: token1Address,
|
||||||
Token0Amount: token0Amount,
|
Token0Amount: token0Amount,
|
||||||
Token1Amount: decimal.Zero,
|
Token1Amount: token1Amount,
|
||||||
Program: "Pump",
|
Program: "Pump",
|
||||||
Event: "sell",
|
Event: "sell",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
@@ -1436,28 +1485,38 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
|||||||
ExactSOL: false,
|
ExactSOL: false,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: routeIn,
|
Token0AmountUint64: routeIn,
|
||||||
Token1AmountUint64: 0,
|
Token1AmountUint64: routeOut,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
token0Amount := decimal.Zero
|
token0Amount := decimal.Zero
|
||||||
if routeOut > 0 {
|
if routeOut > 0 {
|
||||||
token0Amount = formatTokenAmount(routeOut)
|
token0Amount = formatTokenAmount(routeOut)
|
||||||
}
|
}
|
||||||
|
token1Amount := decimal.Zero
|
||||||
|
token1Address := wsolMint
|
||||||
|
if token1MintOK && isStableMint(token1Mint) {
|
||||||
|
token1Address = token1Mint.String()
|
||||||
|
if routeIn > 0 {
|
||||||
|
token1Amount = formatTokenAmount(routeIn)
|
||||||
|
}
|
||||||
|
} else if routeIn > 0 {
|
||||||
|
token1Amount = formatSolAmount(routeIn)
|
||||||
|
}
|
||||||
return TxSignalBatch{&TxSignal{
|
return TxSignalBatch{&TxSignal{
|
||||||
TxHash: tx.Signatures[0].String(),
|
TxHash: tx.Signatures[0].String(),
|
||||||
Maker: tx.StaticAccountKeys[0].String(),
|
Maker: tx.StaticAccountKeys[0].String(),
|
||||||
Token0Address: destMint.String(),
|
Token0Address: destMint.String(),
|
||||||
Token1Address: wsolMint,
|
Token1Address: token1Address,
|
||||||
Token0Amount: token0Amount,
|
Token0Amount: token0Amount,
|
||||||
Token1Amount: decimal.Zero,
|
Token1Amount: token1Amount,
|
||||||
Program: "Pump",
|
Program: "Pump",
|
||||||
Event: "buy",
|
Event: "buy",
|
||||||
IsToken2022: false,
|
IsToken2022: false,
|
||||||
IsMayhemMode: false,
|
IsMayhemMode: false,
|
||||||
ExactSOL: false,
|
ExactSOL: true,
|
||||||
Block: tx.Block,
|
Block: tx.Block,
|
||||||
Token0AmountUint64: routeOut,
|
Token0AmountUint64: routeOut,
|
||||||
Token1AmountUint64: 0,
|
Token1AmountUint64: routeIn,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
if wrappedCnt > 1 {
|
if wrappedCnt > 1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user