Fix jupiter error
This commit is contained in:
@@ -1253,6 +1253,38 @@ func findPumpFunMint(tx VersionedTransaction, accounts []uint8) (solana.PublicKe
|
||||
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) {
|
||||
switch {
|
||||
case bytes.Equal(disc, jupiterRouteV2),
|
||||
@@ -1406,6 +1438,10 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
||||
if len(instruction.Accounts) < 13 {
|
||||
return nil, nil
|
||||
}
|
||||
token1Mint, token1MintOK, err := findPreferredToken1Mint(tx, instruction.Accounts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
destMint, err := tx.GetAccount(int(instruction.Accounts[5]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1422,13 +1458,26 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
||||
if routeIn > 0 {
|
||||
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{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: pumpMint.String(),
|
||||
Token1Address: destMint.String(),
|
||||
Token1Address: token1Address,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: decimal.Zero,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "Pump",
|
||||
Event: "sell",
|
||||
IsToken2022: false,
|
||||
@@ -1436,28 +1485,38 @@ func parseJupiterV6Instruction(tx VersionedTransaction, instructionIndex int) (T
|
||||
ExactSOL: false,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: routeIn,
|
||||
Token1AmountUint64: 0,
|
||||
Token1AmountUint64: routeOut,
|
||||
}}, nil
|
||||
}
|
||||
token0Amount := decimal.Zero
|
||||
if routeOut > 0 {
|
||||
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{
|
||||
TxHash: tx.Signatures[0].String(),
|
||||
Maker: tx.StaticAccountKeys[0].String(),
|
||||
Token0Address: destMint.String(),
|
||||
Token1Address: wsolMint,
|
||||
Token1Address: token1Address,
|
||||
Token0Amount: token0Amount,
|
||||
Token1Amount: decimal.Zero,
|
||||
Token1Amount: token1Amount,
|
||||
Program: "Pump",
|
||||
Event: "buy",
|
||||
IsToken2022: false,
|
||||
IsMayhemMode: false,
|
||||
ExactSOL: false,
|
||||
ExactSOL: true,
|
||||
Block: tx.Block,
|
||||
Token0AmountUint64: routeOut,
|
||||
Token1AmountUint64: 0,
|
||||
Token1AmountUint64: routeIn,
|
||||
}}, nil
|
||||
}
|
||||
if wrappedCnt > 1 {
|
||||
|
||||
Reference in New Issue
Block a user