fix pump amm quoteAmountIn

This commit is contained in:
thloyi
2026-04-27 14:36:03 +08:00
parent 6414e6a25f
commit 43659ea4e4
3 changed files with 50 additions and 6 deletions

View File

@@ -2006,16 +2006,12 @@ func resolveDlmmSwapAccounts(result *RawTx, accounts []int) (dlmmSwapAccounts, e
if eventAuthorityPos < len(accounts) && accountList[accounts[eventAuthorityPos]].Equals(solana.MemoProgramID) {
eventAuthorityPos++
}
programPos := eventAuthorityPos + 1
if programPos >= len(accounts) {
if eventAuthorityPos >= len(accounts) {
continue
}
if !accountList[accounts[eventAuthorityPos]].Equals(meteoraDlmmEventAuthority) {
continue
}
if !accountList[accounts[programPos]].Equals(meteoraDlmmProgram) {
continue
}
if hostFeePresent && oraclePos+1 < len(accounts) && dlmmIsSigner(result, accounts[oraclePos+1]) {
continue

View File

@@ -222,6 +222,50 @@ func TestDlmmDecodeLbPairCreateEvent(t *testing.T) {
}
}
func TestResolveDlmmSwapAccountsAllowsRemainingAccountsAfterEventAuthority(t *testing.T) {
t.Parallel()
accountList := make([]solana.PublicKey, 40)
for i := range accountList {
accountList[i] = testPublicKey(byte(i + 1))
}
accountList[0] = testPublicKey(200)
accountList[26] = meteoraDlmmProgram
accountList[27] = solana.MemoProgramID
accountList[29] = solana.TokenProgramID
accountList[33] = meteoraDlmmEventAuthority
rawTx := &RawTx{
accountList: accountList,
Transaction: Transaction{
Message: Message{
AccountKeys: accountList[:11],
Header: Header{
NumRequiredSignatures: 1,
},
},
},
}
accounts := []int{13, 26, 16, 14, 11, 4, 35, 28, 15, 26, 0, 29, 29, 27, 33, 29, 3, 7, 2}
resolved, err := resolveDlmmSwapAccounts(rawTx, accounts)
if err != nil {
t.Fatalf("resolveDlmmSwapAccounts() error = %v", err)
}
if resolved.poolIdx != 13 {
t.Fatalf("poolIdx = %d, want 13", resolved.poolIdx)
}
if resolved.reserveXIdx != 16 || resolved.reserveYIdx != 14 {
t.Fatalf("reserve indexes = %d/%d, want 16/14", resolved.reserveXIdx, resolved.reserveYIdx)
}
if resolved.userIdx != 0 {
t.Fatalf("userIdx = %d, want 0", resolved.userIdx)
}
if resolved.tokenXProgramIdx != 29 || resolved.tokenYProgramIdx != 29 {
t.Fatalf("token program indexes = %d/%d, want 29/29", resolved.tokenXProgramIdx, resolved.tokenYProgramIdx)
}
}
func TestMeteoraDlmmInitializeParserUsesLbPairCreateEvent(t *testing.T) {
t.Parallel()

View File

@@ -616,6 +616,10 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
}
isCashbackCoin := event.CashbackFeeBasisPoints > 0 || event.Cashback > 0
quoteAmount := decimal.NewFromUint64(event.UserQuoteAmountIn)
if event.IxName == "buy" {
quoteAmount = decimal.NewFromUint64(event.QuoteAmountIn)
}
swap := Swap{
Program: SolProgramPumpAMM,
Event: "buy",
@@ -629,7 +633,7 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
QuoteMintDecimals: quoteMintDecimals,
User: eventUser,
BaseAmount: decimal.NewFromUint64(event.BaseAmountOut),
QuoteAmount: decimal.NewFromUint64(event.UserQuoteAmountIn),
QuoteAmount: quoteAmount,
BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserve - event.BaseAmountOut),
QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserve + event.QuoteAmountIn),
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),