fix pump amm quoteAmountIn
This commit is contained in:
@@ -2006,16 +2006,12 @@ func resolveDlmmSwapAccounts(result *RawTx, accounts []int) (dlmmSwapAccounts, e
|
|||||||
if eventAuthorityPos < len(accounts) && accountList[accounts[eventAuthorityPos]].Equals(solana.MemoProgramID) {
|
if eventAuthorityPos < len(accounts) && accountList[accounts[eventAuthorityPos]].Equals(solana.MemoProgramID) {
|
||||||
eventAuthorityPos++
|
eventAuthorityPos++
|
||||||
}
|
}
|
||||||
programPos := eventAuthorityPos + 1
|
if eventAuthorityPos >= len(accounts) {
|
||||||
if programPos >= len(accounts) {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !accountList[accounts[eventAuthorityPos]].Equals(meteoraDlmmEventAuthority) {
|
if !accountList[accounts[eventAuthorityPos]].Equals(meteoraDlmmEventAuthority) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !accountList[accounts[programPos]].Equals(meteoraDlmmProgram) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if hostFeePresent && oraclePos+1 < len(accounts) && dlmmIsSigner(result, accounts[oraclePos+1]) {
|
if hostFeePresent && oraclePos+1 < len(accounts) && dlmmIsSigner(result, accounts[oraclePos+1]) {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -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) {
|
func TestMeteoraDlmmInitializeParserUsesLbPairCreateEvent(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -616,6 +616,10 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
|
|||||||
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
|
userQuote = userQuote.Add(decimal.NewFromUint64(userBalance))
|
||||||
}
|
}
|
||||||
isCashbackCoin := event.CashbackFeeBasisPoints > 0 || event.Cashback > 0
|
isCashbackCoin := event.CashbackFeeBasisPoints > 0 || event.Cashback > 0
|
||||||
|
quoteAmount := decimal.NewFromUint64(event.UserQuoteAmountIn)
|
||||||
|
if event.IxName == "buy" {
|
||||||
|
quoteAmount = decimal.NewFromUint64(event.QuoteAmountIn)
|
||||||
|
}
|
||||||
swap := Swap{
|
swap := Swap{
|
||||||
Program: SolProgramPumpAMM,
|
Program: SolProgramPumpAMM,
|
||||||
Event: "buy",
|
Event: "buy",
|
||||||
@@ -629,7 +633,7 @@ func ammBuyParser(tx *Tx, instruction Instruction, innerInstructions InnerInstru
|
|||||||
QuoteMintDecimals: quoteMintDecimals,
|
QuoteMintDecimals: quoteMintDecimals,
|
||||||
User: eventUser,
|
User: eventUser,
|
||||||
BaseAmount: decimal.NewFromUint64(event.BaseAmountOut),
|
BaseAmount: decimal.NewFromUint64(event.BaseAmountOut),
|
||||||
QuoteAmount: decimal.NewFromUint64(event.UserQuoteAmountIn),
|
QuoteAmount: quoteAmount,
|
||||||
BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserve - event.BaseAmountOut),
|
BaseReserve: decimal.NewFromUint64(event.PoolBaseTokenReserve - event.BaseAmountOut),
|
||||||
QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserve + event.QuoteAmountIn),
|
QuoteReserve: decimal.NewFromUint64(event.PoolQuoteTokenReserve + event.QuoteAmountIn),
|
||||||
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
|
Mayhem: isMayhemPump(result.accountList[instruction.Accounts[9]]),
|
||||||
|
|||||||
Reference in New Issue
Block a user