From 5392a6b2d2fd59e3f688ddac2d9daa364b8dc672 Mon Sep 17 00:00:00 2001 From: Jeffro <0xjeffro@gmail.com> Date: Mon, 9 Dec 2024 04:15:44 -0800 Subject: [PATCH] fixes #9 --- .../data/raydiumLiquidityPoolV4_swap_2.json | 342 ++++++++++++++++++ solana/parser_test.go | 28 ++ .../raydiumLiquidityPoolV4/parsers/swap.go | 10 +- 3 files changed, 377 insertions(+), 3 deletions(-) create mode 100644 solana/data/raydiumLiquidityPoolV4_swap_2.json diff --git a/solana/data/raydiumLiquidityPoolV4_swap_2.json b/solana/data/raydiumLiquidityPoolV4_swap_2.json new file mode 100644 index 0000000..eb7e248 --- /dev/null +++ b/solana/data/raydiumLiquidityPoolV4_swap_2.json @@ -0,0 +1,342 @@ +[ + { + "blockTime": 1733393650, + "meta": { + "computeUnitsConsumed": 53274, + "err": null, + "fee": 205002, + "innerInstructions": [ + { + "index": 2, + "instructions": [ + { + "accounts": [ + 9 + ], + "data": "84eT", + "programIdIndex": 11, + "stackHeight": 2 + }, + { + "accounts": [ + 0, + 1 + ], + "data": "11119os1e9qSs2u7TsThXqkBSRVFxhmYaFKFZ1waB2X7armDmvK3p5GmLdUxYdg3h7QSrL", + "programIdIndex": 10, + "stackHeight": 2 + }, + { + "accounts": [ + 1 + ], + "data": "P", + "programIdIndex": 11, + "stackHeight": 2 + }, + { + "accounts": [ + 1, + 9 + ], + "data": "6MwZH6Px6qJXZj8tYueKo9WrrKfRVDHxJCdK88k4LkM36", + "programIdIndex": 11, + "stackHeight": 2 + } + ] + }, + { + "index": 3, + "instructions": [ + { + "accounts": [ + 5, + 4, + 0 + ], + "data": "3uyyT2PjqNNj", + "programIdIndex": 11, + "stackHeight": 2 + }, + { + "accounts": [ + 3, + 1, + 13 + ], + "data": "3TfEAHDG6wy1", + "programIdIndex": 11, + "stackHeight": 2 + } + ] + } + ], + "loadedAddresses": { + "readonly": [], + "writable": [] + }, + "logMessages": [ + "Program ComputeBudget111111111111111111111111111111 invoke [1]", + "Program ComputeBudget111111111111111111111111111111 success", + "Program ComputeBudget111111111111111111111111111111 invoke [1]", + "Program ComputeBudget111111111111111111111111111111 success", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", + "Program log: Create", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: GetAccountDataSize", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 94333 compute units", + "Program return: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA pQAAAAAAAAA=", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program 11111111111111111111111111111111 invoke [2]", + "Program 11111111111111111111111111111111 success", + "Program log: Initialize the associated token account", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: InitializeImmutableOwner", + "Program log: Please upgrade to SPL Token 2022 for immutable owner support", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1405 of 87746 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: InitializeAccount3", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 3158 of 83864 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 19277 of 99700 compute units", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [1]", + "Program log: ray_log: A/JHdi4FAAAAAQAAAAAAAAABAAAAAAAAAAJJOCYGAgAAnswgeQoAAABbD7gYQVsBAFTnJwAAAAAA", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 63028 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4736 of 55402 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 30632 of 80423 compute units", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [1]", + "Program log: Instruction: CloseAccount", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 2915 of 49791 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program 11111111111111111111111111111111 invoke [1]", + "Program 11111111111111111111111111111111 success" + ], + "postBalances": [ + 184387854020, + 0, + 6124800, + 44981289786, + 2039280, + 2039280, + 2100675, + 1, + 731913600, + 742524947309, + 1, + 934087680, + 1141440, + 13532449905, + 3591360 + ], + "postTokenBalances": [ + { + "accountIndex": 3, + "mint": "So11111111111111111111111111111111111111112", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "44979250506", + "decimals": 9, + "uiAmount": 44.979250506, + "uiAmountString": "44.979250506" + } + }, + { + "accountIndex": 4, + "mint": "AaJ6gmTzaQw9zxfK6BD9N89wzZLuSuwTRbi8YrTCpump", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "381832376768333", + "decimals": 6, + "uiAmount": 381832376.768333, + "uiAmountString": "381832376.768333" + } + }, + { + "accountIndex": 5, + "mint": "AaJ6gmTzaQw9zxfK6BD9N89wzZLuSuwTRbi8YrTCpump", + "owner": "orcACRJYTFjTeo2pV8TfYRTpmqfoYgbVi9GeANXTCc8", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2203179942160", + "decimals": 6, + "uiAmount": 2203179.94216, + "uiAmountString": "2203179.94216" + } + } + ], + "preBalances": [ + 184386443918, + 0, + 6124800, + 44983904910, + 2039280, + 2039280, + 1100655, + 1, + 731913600, + 742524947309, + 1, + 934087680, + 1141440, + 13532449905, + 3591360 + ], + "preTokenBalances": [ + { + "accountIndex": 3, + "mint": "So11111111111111111111111111111111111111112", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "44981865630", + "decimals": 9, + "uiAmount": 44.98186563, + "uiAmountString": "44.98186563" + } + }, + { + "accountIndex": 4, + "mint": "AaJ6gmTzaQw9zxfK6BD9N89wzZLuSuwTRbi8YrTCpump", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "381810122428251", + "decimals": 6, + "uiAmount": 381810122.428251, + "uiAmountString": "381810122.428251" + } + }, + { + "accountIndex": 5, + "mint": "AaJ6gmTzaQw9zxfK6BD9N89wzZLuSuwTRbi8YrTCpump", + "owner": "orcACRJYTFjTeo2pV8TfYRTpmqfoYgbVi9GeANXTCc8", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2225434282242", + "decimals": 6, + "uiAmount": 2225434.282242, + "uiAmountString": "2225434.282242" + } + } + ], + "rewards": [], + "status": { + "Ok": null + } + }, + "slot": 305539244, + "transaction": { + "message": { + "accountKeys": [ + "orcACRJYTFjTeo2pV8TfYRTpmqfoYgbVi9GeANXTCc8", + "H2AuE7NVmJ1TtqsWWfSaNh5S7TLk7j5vwzkpXu7VnDbA", + "FrSpBqMa6MbEt4EY9CvPdM6Ycuc5wRYCdNcDMxgSznLz", + "DfXYzvmP9JgF7JxMbipDcx9rSoB5fzodAaYEr1ScJ3bG", + "DB7bz74FypSXqwsAh8q2pEp4LjCbi9NpKdViCCof4aim", + "AarSAVG8DLJ27HYAy5GNmz2RAKzNWx5qk85AVUG3Vas3", + "DfXygSm4jCyNCybVYYK6DwvWqjKee8pbDmJGcLWNDXjh", + "ComputeBudget111111111111111111111111111111", + "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "So11111111111111111111111111111111111111112", + "11111111111111111111111111111111", + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8", + "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "5m2GnfN5ma2R64xMf1R8ciHNzVv8HbCBZNCDyHBXChxr" + ], + "addressTableLookups": [], + "header": { + "numReadonlySignedAccounts": 0, + "numReadonlyUnsignedAccounts": 8, + "numRequiredSignatures": 1 + }, + "instructions": [ + { + "accounts": [], + "data": "3eJMY7mcBi9m", + "programIdIndex": 7, + "stackHeight": null + }, + { + "accounts": [], + "data": "JC3gyu", + "programIdIndex": 7, + "stackHeight": null + }, + { + "accounts": [ + 0, + 1, + 0, + 9, + 10, + 11 + ], + "data": "", + "programIdIndex": 8, + "stackHeight": null + }, + { + "accounts": [ + 11, + 2, + 13, + 14, + 3, + 4, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 14, + 5, + 1, + 0 + ], + "data": "6RRg4WiFngE5NtxBuqnEfbV", + "programIdIndex": 12, + "stackHeight": null + }, + { + "accounts": [ + 1, + 0, + 0 + ], + "data": "A", + "programIdIndex": 11, + "stackHeight": null + }, + { + "accounts": [ + 0, + 6 + ], + "data": "3Bxs4Ex4wq3eMLMV", + "programIdIndex": 10, + "stackHeight": null + } + ], + "recentBlockhash": "9gS6fP4QuxbFdCzL1gfc1n776v37agKK1wsyer5yzzKq" + }, + "signatures": [ + "2XgzfkWeDeua4oemWXrj3JzhxVsV4mGsqVZfETSbhn6hGFuLvi2fjdK2TGcmuQQnZSEjUmMmPjUnCFWDebGJcgWQ" + ] + }, + "version": 0 + } +] \ No newline at end of file diff --git a/solana/parser_test.go b/solana/parser_test.go index d42ca8d..b013da3 100644 --- a/solana/parser_test.go +++ b/solana/parser_test.go @@ -1,6 +1,7 @@ package solana import ( + "fmt" "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6" "io/ioutil" "os" @@ -556,6 +557,33 @@ func TestRaydiumLiquidityPoolV4Swap_1(t *testing.T) { } } +func TestRaydiumLiquidityPoolV4Swap_2(t *testing.T) { + byteValue, err := readJsonFile("data/raydiumLiquidityPoolV4_swap_2.json") + if err != nil { + t.Errorf("Error reading JSON file: %v", err) + } + results, _ := Parser(byteValue) + action := results[0].Actions[3] + + fmt.Println(action) + + if swapAction, ok := action.(*types.RaydiumLiquidityPoolV4SwapAction); ok { + assert.Equal(t, swapAction.ProgramID, raydiumLiquidityPoolV4.Program) + assert.Equal(t, swapAction.ProgramName, raydiumLiquidityPoolV4.ProgramName) + assert.Equal(t, swapAction.InstructionName, "Swap") + assert.Equal(t, swapAction.Who, "orcACRJYTFjTeo2pV8TfYRTpmqfoYgbVi9GeANXTCc8") + assert.Equal(t, swapAction.FromToken, "AaJ6gmTzaQw9zxfK6BD9N89wzZLuSuwTRbi8YrTCpump") + assert.Equal(t, swapAction.FromTokenAmount, uint64(22254340082)) + assert.Equal(t, swapAction.FromTokenDecimals, uint64(6)) + assert.Equal(t, swapAction.ToToken, globals.WSOL) + assert.Equal(t, swapAction.ToTokenAmount, uint64(2615124)) + assert.Equal(t, swapAction.ToTokenDecimals, uint64(globals.SOLDecimals)) + assert.Equal(t, swapAction.MinimumAmountOut, uint64(1)) + } else { + t.Errorf("Error type assertion") + } +} + func TestJupiterAggregatorV6SharedAccountRoute_1(t *testing.T) { byteValue, err := readJsonFile("data/jupiterAggregatorV6_sharedAccountsRoute_1.json") if err != nil { diff --git a/solana/programs/raydiumLiquidityPoolV4/parsers/swap.go b/solana/programs/raydiumLiquidityPoolV4/parsers/swap.go index a55b797..1fa8f68 100644 --- a/solana/programs/raydiumLiquidityPoolV4/parsers/swap.go +++ b/solana/programs/raydiumLiquidityPoolV4/parsers/swap.go @@ -1,6 +1,7 @@ package parsers import ( + "fmt" "github.com/0xjeffro/tx-parser/solana/globals" "github.com/0xjeffro/tx-parser/solana/programs/raydiumLiquidityPoolV4" "github.com/0xjeffro/tx-parser/solana/programs/tokenProgram" @@ -21,12 +22,15 @@ func SwapParser(result *types.ParsedResult, instruction types.Instruction, instr if err != nil { return nil, err } + fmt.Println(swapData) var fromToken, toToken string = globals.WSOL, globals.WSOL var fromTokenDecimals, toTokenDecimals uint64 = globals.SOLDecimals, globals.SOLDecimals - userSourceTokenAccount := result.AccountList[instruction.Accounts[15]] - userDestinationTokenAccount := result.AccountList[instruction.Accounts[16]] + accountsLen := len(instruction.Accounts) + who := result.AccountList[instruction.Accounts[accountsLen-1]] + userSourceTokenAccount := result.AccountList[instruction.Accounts[accountsLen-3]] + userDestinationTokenAccount := result.AccountList[instruction.Accounts[accountsLen-2]] tokenBalances := append([]types.TokenBalance{}, result.RawTx.Meta.PreTokenBalances[:]...) tokenBalances = append(tokenBalances, result.RawTx.Meta.PostTokenBalances[:]...) @@ -72,7 +76,7 @@ func SwapParser(result *types.ParsedResult, instruction types.Instruction, instr ProgramName: raydiumLiquidityPoolV4.ProgramName, InstructionName: "Swap", }, - Who: result.AccountList[instruction.Accounts[17]], + Who: who, FromToken: fromToken, FromTokenAmount: swapData.AmountIn, FromTokenDecimals: fromTokenDecimals,