juptierv6

This commit is contained in:
thloyi
2026-01-07 11:18:02 +08:00
parent c732bb2b46
commit 2d3f46ebbf
3 changed files with 123 additions and 32 deletions

View File

@@ -819,26 +819,43 @@ func decodeJupiterV6SharedAccountsRouteV2Arg(data []byte) (*JupiterV6SharedAccou
return &JupiterV6SharedAccountsRouteV2Arg{ID: id, In: inAmt, QuotedOut: quotedOut, Slippage: slippage, PlatFee: pf, PosSlip: pos, RoutePlan: plan}, nil
}
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) uint64 {
var ret uint64
func pumpSwapSellAtIdx0(amount uint64, plan []RoutePlanStep) (uint64, int) {
var (
ret uint64
i int
)
for _, step := range plan {
if step.InputIdx == 0 &&
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
i++
if ret > 0 {
// multiple pumpSwapSell at inputIdx=0? should not happen
return 0, i
}
ret += amount * uint64(step.Percent) / 100
}
}
return ret
return ret, i
}
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) uint64 {
var ret uint64
func pumpSwapSellAtIdx0V2(amount uint64, plan []RoutePlanStepV2) (uint64, int) {
var (
ret uint64
i int
)
for _, step := range plan {
if step.InputIdx == 0 &&
(step.Swap.Kind == PumpSwapSell || step.Swap.Kind == PumpSwapSellV2 || step.Swap.Kind == PumpSwapSellV3) {
i++
if ret > 0 {
// multiple pumpSwapSell at inputIdx=0? should not happen
return 0, i
}
ret += amount * uint64(step.Bps) / 10000
}
}
return ret
return ret, i
}
// only decodes inputIdx = 0 container pumpSwap instructions for now
@@ -861,6 +878,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
var (
sourceMint solana.PublicKey
inputAmount uint64
planCount int
err error
)
@@ -872,34 +890,34 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
if err != nil {
return nil, err
}
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.Plan)
case bytes.Equal(disc, jupiterSharedAccountsRouteV2):
args, err := decodeJupiterV6SharedAccountsRouteV2Arg(instruction.Data[8:])
if err != nil {
return nil, err
}
inputAmount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
inputAmount, planCount = pumpSwapSellAtIdx0V2(args.In, args.RoutePlan)
case bytes.Equal(disc, jupiterRoute):
args, err := decodeJupiterV6RouteArg(instruction.Data[8:])
if err != nil {
return nil, err
}
_ = args
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
case bytes.Equal(disc, jupiterSharedAccountsRoute):
args, err := decodeJupiterV6SharedAccountsRouteArg(instruction.Data[8:])
if err != nil {
return nil, err
}
_ = args
inputAmount = pumpSwapSellAtIdx0(args.In, args.Plan)
inputAmount, planCount = pumpSwapSellAtIdx0(args.In, args.Plan)
default:
return nil, nil
}
if planCount > 1 {
// multiple pumpSwapSell at inputIdx=0? should not happen
logger.Warn("pumpSwapSell at inputIdx=0: multiple instances found", "tx", tx.Signatures[0].String(), "planCount", planCount)
}
if inputAmount == 0 {
return nil, nil
}
@@ -913,6 +931,40 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
if err != nil {
return nil, err
}
var (
srcIdx uint8
)
for i, acctIdx := range instruction.Accounts {
if i < 9 {
continue
}
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
if err != nil {
return nil, err
}
if key.Equals(pumpAmmProgramID) {
srcIdx = uint8(i + 4)
break
}
}
if srcIdx == 0 {
return nil, nil
}
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
if err != nil {
return nil, err
}
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
if err != nil {
return nil, err
}
if !quoteMint.Equals(solana.WrappedSol) {
return nil, nil
}
} else if bytes.Equal(disc, jupiterSharedAccountsRoute) {
if len(instruction.Accounts) < 12 {
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterSharedAccountsRoute instruction")
@@ -921,6 +973,38 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
if err != nil {
return nil, err
}
var (
srcIdx uint8
)
for i, acctIdx := range instruction.Accounts {
if i < 12 {
continue
}
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
if err != nil {
return nil, err
}
if key.Equals(pumpAmmProgramID) {
srcIdx = uint8(i + 4)
break
}
}
if srcIdx == 0 {
return nil, nil
}
sourceMint, err = getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx]))
if err != nil {
return nil, err
}
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
if err != nil {
return nil, err
}
if !quoteMint.Equals(solana.WrappedSol) {
return nil, nil
}
} else {
if len(instruction.Accounts) < 10 {
return nil, fmt.Errorf("not enough accounts for jupiter v6 jupiterRoute instruction")
@@ -930,7 +1014,7 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
)
for i, acctIdx := range instruction.Accounts {
if i <= 9 {
if i < 9 {
continue
}
key, err := getStaticKey(tx.Message.StaticAccountKeys, int(acctIdx))
@@ -949,11 +1033,12 @@ func parseJupiterV6Instruction(tx *versionedTransaction, instructionIndex int) (
if err != nil {
return nil, err
}
distMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
quoteMint, err := getStaticKey(tx.Message.StaticAccountKeys, int(instruction.Accounts[srcIdx+1]))
if err != nil {
return nil, err
}
if !distMint.Equals(solana.WrappedSol) {
if !quoteMint.Equals(solana.WrappedSol) {
return nil, nil
}
}