swap amount input
This commit is contained in:
@@ -367,6 +367,11 @@ type RaydiumLaunchLabSwapEvent struct {
|
||||
|
||||
}
|
||||
|
||||
type raydiumLaunchLabSwapArgs struct {
|
||||
Amount uint64
|
||||
OtherAmountThreshold uint64
|
||||
}
|
||||
|
||||
func raydiumLaunchLabSwapParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
platformConfig := tx.rawTx.accountList[instruction.Accounts[3]]
|
||||
var programName string
|
||||
@@ -375,6 +380,26 @@ func raydiumLaunchLabSwapParser(tx *Tx, instruction Instruction, innerInstructio
|
||||
} else {
|
||||
programName = SolProgramRaydiumLaunchLab
|
||||
}
|
||||
discriminator := *(*[8]byte)(instruction.Data[:8])
|
||||
var swapMode SwapMode
|
||||
var fixedAmount decimal.Decimal
|
||||
var limitAmount decimal.Decimal
|
||||
var swapArgs raydiumLaunchLabSwapArgs
|
||||
if err := agbinary.NewBorshDecoder(instruction.Data[8:]).Decode(&swapArgs); err != nil {
|
||||
return nil, increaseOffset(offset), fmt.Errorf("failed to decode raydium launchlab swap args: %w", err)
|
||||
}
|
||||
switch discriminator {
|
||||
case raydiumLaunchLabSellExactInDiscriminator, raydiumLaunchLabBuyExactInDiscriminator:
|
||||
swapMode = SwapModeExactIn
|
||||
fixedAmount = decimal.NewFromUint64(swapArgs.Amount)
|
||||
limitAmount = decimal.NewFromUint64(swapArgs.OtherAmountThreshold)
|
||||
case raydiumLaunchLabSellExactOutDiscriminator, raydiumLaunchLabBuyExactOutDiscriminator:
|
||||
swapMode = SwapModeExactOut
|
||||
fixedAmount = decimal.NewFromUint64(swapArgs.Amount)
|
||||
limitAmount = decimal.NewFromUint64(swapArgs.OtherAmountThreshold)
|
||||
default:
|
||||
return nil, increaseOffset(offset), InstructionIgnoredError
|
||||
}
|
||||
var entryContract solana.PublicKey = tx.rawTx.accountList[tx.rawTx.Transaction.Message.Instructions[offset[0]].ProgramIDIndex]
|
||||
user := tx.rawTx.accountList[instruction.Accounts[0]]
|
||||
pool := tx.rawTx.accountList[instruction.Accounts[4]]
|
||||
@@ -447,7 +472,7 @@ func raydiumLaunchLabSwapParser(tx *Tx, instruction Instruction, innerInstructio
|
||||
userBase := getAccountBalanceAfterTx(tx.rawTx, userBaseIdx)
|
||||
userQuote := getAccountBalanceAfterTx(tx.rawTx, userQuoteIdx)
|
||||
|
||||
return []Swap{{
|
||||
swap := Swap{
|
||||
Program: programName,
|
||||
Event: event,
|
||||
Pool: pool,
|
||||
@@ -466,5 +491,8 @@ func raydiumLaunchLabSwapParser(tx *Tx, instruction Instruction, innerInstructio
|
||||
UserBaseBalance: userBase,
|
||||
UserQuoteBalance: userQuote,
|
||||
EntryContract: entryContract,
|
||||
}}, offset, nil
|
||||
}
|
||||
swap.SetSwapAmountInfo(swapMode, fixedAmount, limitAmount)
|
||||
|
||||
return []Swap{swap}, offset, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user