swap amount input
This commit is contained in:
36
pump.go
36
pump.go
@@ -218,6 +218,31 @@ type PumpTradeArgs struct {
|
||||
Amount2 uint64
|
||||
}
|
||||
|
||||
func pumpTradeAmountInfoFromArgs(args PumpTradeArgs) (swapMode SwapMode, fixedAmount decimal.Decimal, limitAmount decimal.Decimal, ok bool) {
|
||||
switch {
|
||||
case bytes.Equal(args.Discriminator[:], pumpBuyV2Discriminator[:]):
|
||||
return SwapModeExactIn, decimal.NewFromUint64(args.Amount1), decimal.NewFromUint64(args.Amount2), true
|
||||
case bytes.Equal(args.Discriminator[:], pumpBuyDiscriminator[:]):
|
||||
return SwapModeExactOut, decimal.NewFromUint64(args.Amount1), decimal.NewFromUint64(args.Amount2), true
|
||||
case bytes.Equal(args.Discriminator[:], pumpSellDiscriminator[:]):
|
||||
return SwapModeExactIn, decimal.NewFromUint64(args.Amount1), decimal.NewFromUint64(args.Amount2), true
|
||||
default:
|
||||
return SwapModeUnknown, decimal.Zero, decimal.Zero, false
|
||||
}
|
||||
}
|
||||
|
||||
func normalizePumpQuoteSideMint(s *Swap) {
|
||||
if s.FixedAmountSide == SwapAmountSideQuote && s.FixedMint.IsZero() {
|
||||
s.FixedMint = wSolMint
|
||||
}
|
||||
if s.LimitAmountSide == SwapAmountSideQuote && s.LimitMint.IsZero() {
|
||||
s.LimitMint = wSolMint
|
||||
}
|
||||
if s.ActualLimitAmountSide == SwapAmountSideQuote && s.LimitMint.IsZero() {
|
||||
s.LimitMint = wSolMint
|
||||
}
|
||||
}
|
||||
|
||||
func failedTxBuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerInstructions, offset [2]uint) ([]Swap, [2]uint, error) {
|
||||
if tx.Err == nil || tx.Err.UnKnown != "" {
|
||||
return nil, increaseOffset(offset), fmt.Errorf("tx pump failed but error is nil, offset, %d, %d", offset[0], offset[1])
|
||||
@@ -315,6 +340,10 @@ func failedTxBuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions
|
||||
EntryContract: entryContract,
|
||||
},
|
||||
}
|
||||
if swapMode, fixedAmount, limitAmount, ok := pumpTradeAmountInfoFromArgs(args); ok {
|
||||
swaps[0].SetSwapAmountInfo(swapMode, fixedAmount, limitAmount)
|
||||
normalizePumpQuoteSideMint(&swaps[0])
|
||||
}
|
||||
return swaps, offset, nil
|
||||
}
|
||||
|
||||
@@ -466,6 +495,13 @@ func BuyOrSellParser(tx *Tx, instruction Instruction, innerInstructions InnerIns
|
||||
Cashback: isCashbackCoin,
|
||||
},
|
||||
}
|
||||
var args PumpTradeArgs
|
||||
if err := agbinary.NewBorshDecoder(instruction.Data[:]).Decode(&args); err == nil {
|
||||
if swapMode, fixedAmount, limitAmount, ok := pumpTradeAmountInfoFromArgs(args); ok {
|
||||
swaps[0].SetSwapAmountInfo(swapMode, fixedAmount, limitAmount)
|
||||
normalizePumpQuoteSideMint(&swaps[0])
|
||||
}
|
||||
}
|
||||
if completed {
|
||||
swaps = append(swaps, Swap{
|
||||
Program: SolProgramPump,
|
||||
|
||||
Reference in New Issue
Block a user