swap amount input
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
package pump_parser
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func decodeRaydiumClmmSwapArgs(data []byte) (amountSpecified uint64, otherAmountThreshold uint64, swapMode SwapMode, err error) {
|
||||
if len(data) < 41 {
|
||||
return 0, 0, SwapModeUnknown, fmt.Errorf("raydium clmm swap instruction data too short")
|
||||
}
|
||||
amountSpecified = binary.LittleEndian.Uint64(data[8:16])
|
||||
otherAmountThreshold = binary.LittleEndian.Uint64(data[16:24])
|
||||
isBaseInput := data[40] != 0
|
||||
swapMode = SwapModeExactOut
|
||||
if isBaseInput {
|
||||
swapMode = SwapModeExactIn
|
||||
}
|
||||
return amountSpecified, otherAmountThreshold, swapMode, nil
|
||||
}
|
||||
|
||||
func raydiumClmmParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
if !tx.rawTx.accountList[instruction.ProgramIDIndex].Equals(raydiumClmmProgramID) {
|
||||
return nil, increaseOffset(offset), fmt.Errorf("raydiumClmm instruction not found, offset, %d, %d", offset[0], offset[1])
|
||||
@@ -278,6 +293,10 @@ func raydiumClmmSwapParser(tx *Tx, instruction Instruction, innerInstructions In
|
||||
userTokenOutAccount int
|
||||
)
|
||||
var entryContract = tx.rawTx.accountList[tx.rawTx.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
|
||||
amountSpecified, otherAmountThreshold, swapMode, err := decodeRaydiumClmmSwapArgs(instruction.Data)
|
||||
if err != nil {
|
||||
return nil, increaseOffset(offset), err
|
||||
}
|
||||
if discriminator == raydiumClmmSwapDiscriminator {
|
||||
accountMin = 9
|
||||
pool = tx.rawTx.accountList[instruction.Accounts[2]]
|
||||
@@ -350,26 +369,26 @@ func raydiumClmmSwapParser(tx *Tx, instruction Instruction, innerInstructions In
|
||||
|
||||
offset[1] += 2
|
||||
|
||||
return []Swap{
|
||||
{
|
||||
Program: SolProgramRaydiumCLMM,
|
||||
Event: "sell",
|
||||
Pool: pool,
|
||||
BaseMint: baseMint,
|
||||
QuoteMint: quoteMint,
|
||||
BaseTokenProgram: baseTokenProgram,
|
||||
QuoteTokenProgram: quoteTokenProgram,
|
||||
BaseMintDecimals: baseMintDecimals,
|
||||
QuoteMintDecimals: quoteMintDecimals,
|
||||
User: tx.rawTx.accountList[instruction.Accounts[0]],
|
||||
BaseAmount: baseAmount,
|
||||
QuoteAmount: quoteAmount,
|
||||
BaseReserve: baseReserve,
|
||||
QuoteReserve: quoteReserve,
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
},
|
||||
}, offset, nil
|
||||
swap := Swap{
|
||||
Program: SolProgramRaydiumCLMM,
|
||||
Event: "sell",
|
||||
Pool: pool,
|
||||
BaseMint: baseMint,
|
||||
QuoteMint: quoteMint,
|
||||
BaseTokenProgram: baseTokenProgram,
|
||||
QuoteTokenProgram: quoteTokenProgram,
|
||||
BaseMintDecimals: baseMintDecimals,
|
||||
QuoteMintDecimals: quoteMintDecimals,
|
||||
User: tx.rawTx.accountList[instruction.Accounts[0]],
|
||||
BaseAmount: baseAmount,
|
||||
QuoteAmount: quoteAmount,
|
||||
BaseReserve: baseReserve,
|
||||
QuoteReserve: quoteReserve,
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
}
|
||||
swap.SetSwapAmountInfo(swapMode, decimal.NewFromUint64(amountSpecified), decimal.NewFromUint64(otherAmountThreshold))
|
||||
return []Swap{swap}, offset, nil
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user