From 3c720f55c5b07e2bf555ef49bec56f2d9bac3512 Mon Sep 17 00:00:00 2001 From: Jeffro <0xjeffro@gmail.com> Date: Tue, 10 Dec 2024 00:34:41 -0800 Subject: [PATCH] add parsers for OKX DEX AggregationRouterV2 - add parser for Swap instruction - add parser for CommissionSplProxySwap instruction - merge program U6m2CDdhRg - fixes #8 --- .../data/OKXDEX_commissionSplProxySwap.json | 768 ++++++++++++++++++ ...2CDdhRg_swap_0.json => OKXDEX_swap_0.json} | 0 ...2CDdhRg_swap_1.json => OKXDEX_swap_1.json} | 0 solana/parser_test.go | 118 +-- .../OKXDEXAggregationRouterV2/meta.go | 7 + .../parsers/commissionSplProxySwap.go | 124 +++ .../parsers/index.go | 31 + .../OKXDEXAggregationRouterV2/parsers/swap.go | 70 ++ .../OKXDEXAggregationRouterV2/types.go | 36 + solana/programs/U6m2CDdhRg/meta.go | 2 +- solana/programs/computeBudget/meta.go | 2 +- solana/router.go | 14 +- 12 files changed, 1116 insertions(+), 56 deletions(-) create mode 100644 solana/data/OKXDEX_commissionSplProxySwap.json rename solana/data/{U6m2CDdhRg_swap_0.json => OKXDEX_swap_0.json} (100%) rename solana/data/{U6m2CDdhRg_swap_1.json => OKXDEX_swap_1.json} (100%) create mode 100644 solana/programs/OKXDEXAggregationRouterV2/meta.go create mode 100644 solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSplProxySwap.go create mode 100644 solana/programs/OKXDEXAggregationRouterV2/parsers/index.go create mode 100644 solana/programs/OKXDEXAggregationRouterV2/parsers/swap.go create mode 100644 solana/programs/OKXDEXAggregationRouterV2/types.go diff --git a/solana/data/OKXDEX_commissionSplProxySwap.json b/solana/data/OKXDEX_commissionSplProxySwap.json new file mode 100644 index 0000000..3628d36 --- /dev/null +++ b/solana/data/OKXDEX_commissionSplProxySwap.json @@ -0,0 +1,768 @@ +[ + { + "blockTime": 1731789673, + "meta": { + "computeUnitsConsumed": 188764, + "err": null, + "fee": 1726067, + "innerInstructions": [ + { + "index": 2, + "instructions": [ + { + "accounts": [ + 4 + ], + "data": "84eT", + "programIdIndex": 31, + "stackHeight": 2 + }, + { + "accounts": [ + 0, + 1 + ], + "data": "11119os1e9qSs2u7TsThXqkBSRVFxhmYaFKFZ1waB2X7armDmvK3p5GmLdUxYdg3h7QSrL", + "programIdIndex": 29, + "stackHeight": 2 + }, + { + "accounts": [ + 1 + ], + "data": "P", + "programIdIndex": 31, + "stackHeight": 2 + }, + { + "accounts": [ + 1, + 4 + ], + "data": "6cTRjzZ247g5P9SUzEtZ7bAoBDNzzKfuxHZ9KNqPbK4xw", + "programIdIndex": 31, + "stackHeight": 2 + } + ] + }, + { + "index": 3, + "instructions": [ + { + "accounts": [ + 2, + 27, + 21, + 0 + ], + "data": "ikhE1RSQ3PAxV", + "programIdIndex": 31, + "stackHeight": 2 + }, + { + "accounts": [ + 30, + 22, + 25, + 19, + 20, + 21, + 24, + 23, + 31 + ], + "data": "1AMTAauCh9UPEJKNo5aBR7itMe4Trg6uxFoRKY273MEbgNhJnfLX4Pv7nJG1z1EwdeDyUHWtib", + "programIdIndex": 30, + "stackHeight": 2 + }, + { + "accounts": [ + 24, + 20, + 24 + ], + "data": "3JqfNX6mueyV", + "programIdIndex": 31, + "stackHeight": 3 + }, + { + "accounts": [ + 21, + 23, + 19 + ], + "data": "3t7zBmRSihZh", + "programIdIndex": 31, + "stackHeight": 3 + }, + { + "accounts": [ + 22 + ], + "data": "9bruytF42iaUmngumD7DDZgkVmb89cNb643FCyvL3Qtwvgy8zj2fAHSQbzMut9K7KZZRvnwCoDehKh4Xu2wYLXDK426hx3hucspPoHssbBX5yk1hkaZCRhrMNNBES2uNmBizGz4m8BpPpJkYtkH6wVEUkv9jrAUCUPUxT2vCJcMiU2NaorqdwYj6cKYsoo1AEjCQuTLamoncVmKtfBWFrTpi9mWwJwbGpdgDPSNPwK5euAyn2TZJbxpJFNqJQmSfcGAGteN2BLc6Svxt2dpjH", + "programIdIndex": 30, + "stackHeight": 3 + }, + { + "accounts": [ + 31, + 16, + 26, + 17, + 14, + 11, + 18, + 32, + 13, + 10, + 9, + 15, + 8, + 12, + 26, + 20, + 1, + 19 + ], + "data": "5yUrwJ96HTr8P9FNpZtB9Dh", + "programIdIndex": 28, + "stackHeight": 2 + }, + { + "accounts": [ + 20, + 11, + 19 + ], + "data": "3JqfNX6mueyV", + "programIdIndex": 31, + "stackHeight": 3 + }, + { + "accounts": [ + 18, + 1, + 26 + ], + "data": "3kxME6EaN8fq", + "programIdIndex": 31, + "stackHeight": 3 + }, + { + "accounts": [ + 2, + 27, + 3, + 0 + ], + "data": "iMD4piBovzE6R", + "programIdIndex": 31, + "stackHeight": 2 + } + ] + } + ], + "loadedAddresses": { + "readonly": [ + "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8", + "11111111111111111111111111111111", + "PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY", + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX" + ], + "writable": [ + "CUvTqEoGtxiSd3WSKru1y7gv95Z1fpdVUegawrjcJb3m", + "HVVvGrq73862Y3ej2DVgZJ9Ez1YhDbC8R1n2cS531XvU", + "41jZVsVxAQtkj1i81vTeiPS7Q1ATMk4gkKxyGJSJhpSY", + "8hQ2jUwszWf8p99Sb9DF3VLXuYg8xfCtJCBigMP9wQDh", + "FVtAJPPSD6QUQDCKoNpkXAk4QE27jqzescumK2JKHZYR", + "Gy1q9M4PHr5F74c5c9QyqZ8rYVXqpvkWUf6DsmqXjFjE", + "AXsb5SGVm1tM3QV5fDRjWZRRS2QpPURpLUzZuqEgzJPg", + "A8cjvyj6FVzJHYYvfgjrscmQknc1z9rKAwwXKnxGZe3m", + "GjvW8JQSpKG5ogjyD3zozfaeJSShTajS5ZFrexT8L12k", + "G8oCidm4Amc2Rf96LDu6rcmdgC7KhjG8W93kq3XFSx1k", + "HiYi67PFatEPhM42sz5mewhNYjFNu5FTpiMKnaNVXDmF", + "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K", + "2rikd7tzPbmowhUJzPNVtX7fuUGcnBa8jqJnx6HbtHeE", + "HjkGLCPnsMr4yP2Tmi1Uj7gV7Y2xDj2Npn9kYfVBYr2s", + "7aDTsspkQNGKmrexAN7FLx9oxU3iPczSSvHNggyuqYkR", + "ED7PzXEtJo7epZm9rzmg2MDiaDDoJmDpoPigbJ3CRSdo", + "C6hTSYmF9Q8wEgQdNT7bitt5sP5AAAVtaswPJqVgmoWX", + "B8a4RCvFaG9AFsatCZLpGLkbCPytyr9K6jSZWLQZDjg1" + ] + }, + "logMessages": [ + "Program ComputeBudget111111111111111111111111111111 invoke [1]", + "Program ComputeBudget111111111111111111111111111111 success", + "Program ComputeBudget111111111111111111111111111111 invoke [1]", + "Program ComputeBudget111111111111111111111111111111 success", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL invoke [1]", + "Program log: CreateIdempotent", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: GetAccountDataSize", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 1569 of 284795 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 278208 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: InitializeAccount3", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4188 of 274326 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL consumed 21845 of 291700 compute units", + "Program ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL success", + "Program 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma invoke [1]", + "Program log: Instruction: CommissionSplProxySwap", + "Program log: before_source_balance: 1603500000, before_destination_balance: 0, amount_in: 249250000, expect_amount_out: 6372650011, min_return: 6245197011", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: TransferChecked", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6200 of 241207 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program log: order_id: 100303", + "Program log: EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "Program log: DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "Program log: Dex::Phoenix amount_in: 249250000, offset: 0", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY invoke [2]", + "Program log: Discriminant for phoenix::program::accounts::MarketHeader is 8167313896524341111", + "Program log: PhoenixInstruction::Swap", + "Program consumption: 212847 units remaining", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 196144 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 188736 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program log: Sending batch 1 with header and 2 market events, total events sent: 2", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY invoke [3]", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY consumed 582 of 181608 compute units", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY success", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY consumed 37338 of 217826 compute units", + "Program PhoeNiXZ8ByJGLkxNfZRnkUfjvmuYqLR89jjFHGqdXY success", + "Program data: QMbN6CYIceIR0EDbDgAAAAAgK8pEAAAAAA==", + "Program log: SwapEvent { dex: Phoenix, amount_in: 249250000, amount_out: 1154100000 }", + "Program log: HjkGLCPnsMr4yP2Tmi1Uj7gV7Y2xDj2Npn9kYfVBYr2s", + "Program log: 2rikd7tzPbmowhUJzPNVtX7fuUGcnBa8jqJnx6HbtHeE", + "Program log: Dex::RaydiumSwap amount_in: 1154100000, offset: 9", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 invoke [2]", + "Program log: ray_log: AyArykQAAAAAAQAAAAAAAAACAAAAAAAAAC6AUnoBAAAAOoIsJR0CAAAa1l5UtQsAALxN4HsBAAAA", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4736 of 139776 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [3]", + "Program log: Instruction: Transfer", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 4645 of 132059 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 consumed 31382 of 157739 compute units", + "Program 675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8 success", + "Program data: QMbN6CYIceIEICvKRAAAAAC8TeB7AQAAAA==", + "Program log: SwapEvent { dex: RaydiumSwap, amount_in: 1154100000, amount_out: 6373264828 }", + "Program log: 2rikd7tzPbmowhUJzPNVtX7fuUGcnBa8jqJnx6HbtHeE", + "Program log: 76NMkoHrp4iko7YShpbKuwH4cnmwUJJYReNxK2ECcD2Y", + "Program log: Swap amount_out: 6373264828", + "Program log: after_source_balance: 1354250000, after_destination_balance: 6373264828, source_token_change: 249250000, destination_token_change: 6373264828", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA invoke [2]", + "Program log: Instruction: TransferChecked", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA consumed 6200 of 111314 compute units", + "Program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA success", + "Program log: commission_direction: true, commission_amount: 750000", + "Program 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma consumed 166619 of 269855 compute units", + "Program return: 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma vE3gewEAAAA=", + "Program 6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma success" + ], + "postBalances": [ + 1365899443, + 2039280, + 2039280, + 2039280, + 4589655600, + 1141440, + 731913600, + 1, + 2039280, + 457104960, + 457104960, + 2325357120330, + 2039280, + 3591360, + 16258560, + 1825496640, + 6124800, + 23357760, + 2039280, + 0, + 5195133694, + 2039280, + 0, + 2039280, + 2157885239280, + 1619397520, + 11935591132, + 320607390200, + 1141440, + 1, + 1141440, + 934087680, + 1141440 + ], + "postTokenBalances": [ + { + "accountIndex": 1, + "mint": "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "owner": "GKj54MVFppoYsxPU9jMn7CMniVRAuveFadyTtFhn1vXy", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "6373264828", + "decimals": 6, + "uiAmount": 6373.264828, + "uiAmountString": "6373.264828" + } + }, + { + "accountIndex": 2, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "GKj54MVFppoYsxPU9jMn7CMniVRAuveFadyTtFhn1vXy", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "1353500000", + "decimals": 6, + "uiAmount": 1353.5, + "uiAmountString": "1353.5" + } + }, + { + "accountIndex": 3, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "e24SXSTq1AkusXQEKgZW389taxTTzSuGF8JQqjhbTfc", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "4650329377", + "decimals": 6, + "uiAmount": 4650.329377, + "uiAmountString": "4650.329377" + } + }, + { + "accountIndex": 8, + "mint": "So11111111111111111111111111111111111111112", + "owner": "F8Jvc77vbdebLLKrtSFzkTGEELwkasb3uARtmzGB3UnT", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "0", + "decimals": 9, + "uiAmount": null, + "uiAmountString": "0" + } + }, + { + "accountIndex": 11, + "mint": "So11111111111111111111111111111111111111112", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2325355081050", + "decimals": 9, + "uiAmount": 2325.35508105, + "uiAmountString": "2325.35508105" + } + }, + { + "accountIndex": 12, + "mint": "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "owner": "F8Jvc77vbdebLLKrtSFzkTGEELwkasb3uARtmzGB3UnT", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "0", + "decimals": 6, + "uiAmount": null, + "uiAmountString": "0" + } + }, + { + "accountIndex": 18, + "mint": "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "12867059222622", + "decimals": 6, + "uiAmount": 12867059.222622, + "uiAmountString": "12867059.222622" + } + }, + { + "accountIndex": 20, + "mint": "So11111111111111111111111111111111111111112", + "owner": "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "5193094414", + "decimals": 9, + "uiAmount": 5.193094414, + "uiAmountString": "5.193094414" + } + }, + { + "accountIndex": 21, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "9804995895", + "decimals": 6, + "uiAmount": 9804.995895, + "uiAmountString": "9804.995895" + } + }, + { + "accountIndex": 23, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "ED7PzXEtJo7epZm9rzmg2MDiaDDoJmDpoPigbJ3CRSdo", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "798591267034", + "decimals": 6, + "uiAmount": 798591.267034, + "uiAmountString": "798591.267034" + } + }, + { + "accountIndex": 24, + "mint": "So11111111111111111111111111111111111111112", + "owner": "C6hTSYmF9Q8wEgQdNT7bitt5sP5AAAVtaswPJqVgmoWX", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2157883200000", + "decimals": 9, + "uiAmount": 2157.8832, + "uiAmountString": "2157.8832" + } + } + ], + "preBalances": [ + 1369664790, + 0, + 2039280, + 2039280, + 4589655600, + 1141440, + 731913600, + 1, + 2039280, + 457104960, + 457104960, + 2324203020330, + 2039280, + 3591360, + 16258560, + 1825496640, + 6124800, + 23357760, + 2039280, + 0, + 5195133694, + 2039280, + 0, + 2039280, + 2159039339280, + 1619397520, + 11935591132, + 320607390200, + 1141440, + 1, + 1141440, + 934087680, + 1141440 + ], + "preTokenBalances": [ + { + "accountIndex": 2, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "GKj54MVFppoYsxPU9jMn7CMniVRAuveFadyTtFhn1vXy", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "1603500000", + "decimals": 6, + "uiAmount": 1603.5, + "uiAmountString": "1603.5" + } + }, + { + "accountIndex": 3, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "e24SXSTq1AkusXQEKgZW389taxTTzSuGF8JQqjhbTfc", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "4649579377", + "decimals": 6, + "uiAmount": 4649.579377, + "uiAmountString": "4649.579377" + } + }, + { + "accountIndex": 8, + "mint": "So11111111111111111111111111111111111111112", + "owner": "F8Jvc77vbdebLLKrtSFzkTGEELwkasb3uARtmzGB3UnT", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "0", + "decimals": 9, + "uiAmount": null, + "uiAmountString": "0" + } + }, + { + "accountIndex": 11, + "mint": "So11111111111111111111111111111111111111112", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2324200981050", + "decimals": 9, + "uiAmount": 2324.20098105, + "uiAmountString": "2324.20098105" + } + }, + { + "accountIndex": 12, + "mint": "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "owner": "F8Jvc77vbdebLLKrtSFzkTGEELwkasb3uARtmzGB3UnT", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "0", + "decimals": 6, + "uiAmount": null, + "uiAmountString": "0" + } + }, + { + "accountIndex": 18, + "mint": "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "owner": "5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "12873432487450", + "decimals": 6, + "uiAmount": 12873432.48745, + "uiAmountString": "12873432.48745" + } + }, + { + "accountIndex": 20, + "mint": "So11111111111111111111111111111111111111112", + "owner": "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "5193094414", + "decimals": 9, + "uiAmount": 5.193094414, + "uiAmountString": "5.193094414" + } + }, + { + "accountIndex": 21, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "HV1KXxWFaSeriyFvXyx48FqG9BoFbfinB8njCJonqP7K", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "9804989006", + "decimals": 6, + "uiAmount": 9804.989006, + "uiAmountString": "9804.989006" + } + }, + { + "accountIndex": 23, + "mint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", + "owner": "ED7PzXEtJo7epZm9rzmg2MDiaDDoJmDpoPigbJ3CRSdo", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "798342023923", + "decimals": 6, + "uiAmount": 798342.023923, + "uiAmountString": "798342.023923" + } + }, + { + "accountIndex": 24, + "mint": "So11111111111111111111111111111111111111112", + "owner": "C6hTSYmF9Q8wEgQdNT7bitt5sP5AAAVtaswPJqVgmoWX", + "programId": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + "uiTokenAmount": { + "amount": "2159037300000", + "decimals": 9, + "uiAmount": 2159.0373, + "uiAmountString": "2159.0373" + } + } + ], + "returnData": { + "data": [ + "vE3gewEAAAA=", + "base64" + ], + "programId": "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma" + }, + "rewards": [], + "status": { + "Ok": null + } + }, + "slot": 301807437, + "transaction": { + "message": { + "accountKeys": [ + "GKj54MVFppoYsxPU9jMn7CMniVRAuveFadyTtFhn1vXy", + "76NMkoHrp4iko7YShpbKuwH4cnmwUJJYReNxK2ECcD2Y", + "HEdQot5BusCbwL75zFrPnJuPMzMgGkbk6jrDV9PprjE8", + "5HeHTk8hd1u2JL4vVdLwUuLQHWC22oegfHeFeYwziKa9", + "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump", + "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma", + "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + "ComputeBudget111111111111111111111111111111" + ], + "addressTableLookups": [ + { + "accountKey": "MTfWPFfTHBhoZGRr9sq6MQNchuP1K4wD2WGCamCAtfY", + "readonlyIndexes": [], + "writableIndexes": [ + 144, + 145, + 146, + 147, + 137, + 138, + 139, + 140, + 141, + 142, + 143 + ] + }, + { + "accountKey": "3ggaLcA6Vu63Q9zZqiHudcHEbF7fecAGAEM3z7X42ZrK", + "readonlyIndexes": [ + 32, + 53, + 21, + 7, + 40, + 9, + 25 + ], + "writableIndexes": [ + 1, + 2, + 3, + 42 + ] + }, + { + "accountKey": "5bKfc428yoqJkQMabBc6WW17QepFpWQh6oKBV6WmtkKt", + "readonlyIndexes": [], + "writableIndexes": [ + 128, + 126, + 127 + ] + } + ], + "header": { + "numReadonlySignedAccounts": 0, + "numReadonlyUnsignedAccounts": 4, + "numRequiredSignatures": 1 + }, + "instructions": [ + { + "accounts": [], + "data": "JBweYP", + "programIdIndex": 7, + "stackHeight": null + }, + { + "accounts": [], + "data": "3jDkjKMwTRUK", + "programIdIndex": 7, + "stackHeight": null + }, + { + "accounts": [ + 0, + 1, + 0, + 4, + 29, + 31 + ], + "data": "2", + "programIdIndex": 6, + "stackHeight": null + }, + { + "accounts": [ + 0, + 2, + 1, + 27, + 4, + 3, + 19, + 21, + 5, + 31, + 31, + 6, + 29, + 30, + 19, + 21, + 20, + 22, + 25, + 24, + 23, + 31, + 28, + 19, + 20, + 1, + 31, + 16, + 26, + 17, + 14, + 11, + 18, + 32, + 13, + 10, + 9, + 15, + 8, + 12, + 26 + ], + "data": "2ZCUgn4LwmxDSxBkrqTF9JLgahfiiioP5x9r6gmktbraryBdoB3PFrKn5M12emPTu3iqmLH6Jc4ejpttkkyW43JqR34szmY9Y5xuRHGc28YDixxyXm", + "programIdIndex": 5, + "stackHeight": null + } + ], + "recentBlockhash": "5zDMifYibSPNRXbpF7MFDHV6J2C8Y8oCyUaKyhhUdeL7" + }, + "signatures": [ + "3p36wGRa191szhME5kRbg41cv9sXPPYvozkkKvPMErwoakXGZNDbjgCtV3e7uzU9dSDABtAgpm7heoepNhDmxJwN" + ] + }, + "version": 0 + } +] \ No newline at end of file diff --git a/solana/data/U6m2CDdhRg_swap_0.json b/solana/data/OKXDEX_swap_0.json similarity index 100% rename from solana/data/U6m2CDdhRg_swap_0.json rename to solana/data/OKXDEX_swap_0.json diff --git a/solana/data/U6m2CDdhRg_swap_1.json b/solana/data/OKXDEX_swap_1.json similarity index 100% rename from solana/data/U6m2CDdhRg_swap_1.json rename to solana/data/OKXDEX_swap_1.json diff --git a/solana/parser_test.go b/solana/parser_test.go index b013da3..a282374 100644 --- a/solana/parser_test.go +++ b/solana/parser_test.go @@ -2,13 +2,13 @@ package solana import ( "fmt" + "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2" "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6" "io/ioutil" "os" "testing" "github.com/0xjeffro/tx-parser/solana/globals" - "github.com/0xjeffro/tx-parser/solana/programs/U6m2CDdhRg" "github.com/0xjeffro/tx-parser/solana/programs/computeBudget" "github.com/0xjeffro/tx-parser/solana/programs/jupiterDCA" "github.com/0xjeffro/tx-parser/solana/programs/pumpfun" @@ -329,52 +329,6 @@ func TestTokenProgramInitializeAccount(t *testing.T) { } } -func TestU6m2CDdhRgSwap(t *testing.T) { - byteValue, err := readJsonFile("data/U6m2CDdhRg_swap_0.json") - if err != nil { - t.Errorf("Error reading JSON file: %v", err) - } - results, _ := Parser(byteValue) - action := results[0].Actions[3] - - if transferAction, ok := action.(*types.U6m2CDdhRgSwapAction); ok { - assert.Equal(t, transferAction.ProgramID, U6m2CDdhRg.Program) - assert.Equal(t, transferAction.ProgramName, U6m2CDdhRg.ProgramName) - assert.Equal(t, transferAction.InstructionName, "Unknown") - assert.Equal(t, transferAction.FromToken, "7atgF8KQo4wJrD5ATGX7t1V2zVvykPJbFfNeVf1icFv1") - assert.Equal(t, transferAction.FromTokenAmount, uint64(358800)) - assert.Equal(t, transferAction.FromTokenDecimals, uint64(2)) - assert.Equal(t, transferAction.ToToken, "ED5nyyWEzpPPiWimP8vYm7sD7TD3LAt3Q3gRTWHzPJBY") - assert.Equal(t, transferAction.ToTokenAmount, uint64(74619)) - assert.Equal(t, transferAction.ToTokenDecimals, uint64(6)) - } else { - t.Errorf("Error type assertion") - } -} - -func TestU6m2CDdhRgSwap1(t *testing.T) { - byteValue, err := readJsonFile("data/U6m2CDdhRg_swap_1.json") - if err != nil { - t.Errorf("Error reading JSON file: %v", err) - } - results, _ := Parser(byteValue) - action := results[0].Actions[7] - - if transferAction, ok := action.(*types.U6m2CDdhRgSwapAction); ok { - assert.Equal(t, transferAction.ProgramID, U6m2CDdhRg.Program) - assert.Equal(t, transferAction.ProgramName, U6m2CDdhRg.ProgramName) - assert.Equal(t, transferAction.InstructionName, "Unknown") - assert.Equal(t, transferAction.FromToken, "So11111111111111111111111111111111111111112") - assert.Equal(t, transferAction.FromTokenAmount, uint64(10000000000)) - assert.Equal(t, transferAction.FromTokenDecimals, uint64(9)) - assert.Equal(t, transferAction.ToToken, "KMnDBXcPXoz6oMJW5XG4tXdwSWpmWEP2RQM1Uujpump") - assert.Equal(t, transferAction.ToTokenAmount, uint64(998528432013)) - assert.Equal(t, transferAction.ToTokenDecimals, uint64(6)) - } else { - t.Errorf("Error type assertion") - } -} - func TestJupiterDcaOpenDcaV2_0(t *testing.T) { byteValue, err := readJsonFile("data/jupiterDca_openDcaV2_0.json") if err != nil { @@ -671,3 +625,73 @@ func TestJupiterAggregatorV6Route_2(t *testing.T) { assert.Equal(t, swapAction.ToTokenDecimals, uint64(9)) } } + +func TestOKXDEXCommissionSplProxySwap_1(t *testing.T) { + byteValue, err := readJsonFile("data/OKXDEX_commissionSplProxySwap.json") + if err != nil { + t.Errorf("Error reading JSON file: %v", err) + } + results, _ := Parser(byteValue) + action := results[0].Actions[3] + + if swapAction, ok := action.(*OKXDEXAggregationRouterV2.CommissionSplProxySwapAction); ok { + assert.Equal(t, swapAction.ProgramID, OKXDEXAggregationRouterV2.Program) + assert.Equal(t, swapAction.ProgramName, OKXDEXAggregationRouterV2.ProgramName) + assert.Equal(t, swapAction.InstructionName, "CommissionSplProxySwap") + assert.Equal(t, swapAction.Who, "GKj54MVFppoYsxPU9jMn7CMniVRAuveFadyTtFhn1vXy") + assert.Equal(t, swapAction.FromToken, "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v") + assert.Equal(t, swapAction.FromTokenAmount, uint64(250000000)) + assert.Equal(t, swapAction.FromTokenDecimals, uint64(6)) + assert.Equal(t, swapAction.ToToken, "DKu9kykSfbN5LBfFXtNNDPaX35o4Fv6vJ9FKk7pZpump") + assert.Equal(t, swapAction.ToTokenAmount, uint64(6373264828)) + assert.Equal(t, swapAction.ToTokenDecimals, uint64(6)) + } else { + t.Errorf("Error type assertion") + } +} + +func TestOKXDEXSwap(t *testing.T) { + byteValue, err := readJsonFile("data/OKXDEX_swap_0.json") + if err != nil { + t.Errorf("Error reading JSON file: %v", err) + } + results, _ := Parser(byteValue) + action := results[0].Actions[3] + + if transferAction, ok := action.(*OKXDEXAggregationRouterV2.SwapAction); ok { + assert.Equal(t, transferAction.ProgramID, OKXDEXAggregationRouterV2.Program) + assert.Equal(t, transferAction.ProgramName, OKXDEXAggregationRouterV2.ProgramName) + assert.Equal(t, transferAction.InstructionName, "Swap") + assert.Equal(t, transferAction.FromToken, "7atgF8KQo4wJrD5ATGX7t1V2zVvykPJbFfNeVf1icFv1") + assert.Equal(t, transferAction.FromTokenAmount, uint64(358800)) + assert.Equal(t, transferAction.FromTokenDecimals, uint64(2)) + assert.Equal(t, transferAction.ToToken, "ED5nyyWEzpPPiWimP8vYm7sD7TD3LAt3Q3gRTWHzPJBY") + assert.Equal(t, transferAction.ToTokenAmount, uint64(74619)) + assert.Equal(t, transferAction.ToTokenDecimals, uint64(6)) + } else { + t.Errorf("Error type assertion") + } +} + +func TestOKXDEXSwap_1(t *testing.T) { + byteValue, err := readJsonFile("data/OKXDEX_swap_1.json") + if err != nil { + t.Errorf("Error reading JSON file: %v", err) + } + results, _ := Parser(byteValue) + action := results[0].Actions[7] + + if transferAction, ok := action.(*OKXDEXAggregationRouterV2.SwapAction); ok { + assert.Equal(t, transferAction.ProgramID, OKXDEXAggregationRouterV2.Program) + assert.Equal(t, transferAction.ProgramName, OKXDEXAggregationRouterV2.ProgramName) + assert.Equal(t, transferAction.InstructionName, "Swap") + assert.Equal(t, transferAction.FromToken, "So11111111111111111111111111111111111111112") + assert.Equal(t, transferAction.FromTokenAmount, uint64(10000000000)) + assert.Equal(t, transferAction.FromTokenDecimals, uint64(9)) + assert.Equal(t, transferAction.ToToken, "KMnDBXcPXoz6oMJW5XG4tXdwSWpmWEP2RQM1Uujpump") + assert.Equal(t, transferAction.ToTokenAmount, uint64(998528432013)) + assert.Equal(t, transferAction.ToTokenDecimals, uint64(6)) + } else { + t.Errorf("Error type assertion") + } +} diff --git a/solana/programs/OKXDEXAggregationRouterV2/meta.go b/solana/programs/OKXDEXAggregationRouterV2/meta.go new file mode 100644 index 0000000..eeb2bfa --- /dev/null +++ b/solana/programs/OKXDEXAggregationRouterV2/meta.go @@ -0,0 +1,7 @@ +package OKXDEXAggregationRouterV2 + +const Program = "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma" +const ProgramName = "OKX DEX: Aggregation Router V2" + +var CommissionSplProxySwapDiscriminator = [8]uint8{96, 67, 12, 151, 129, 164, 18, 71} +var SwapDiscriminator = [8]uint8{65, 75, 63, 76, 235, 91, 91, 136} diff --git a/solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSplProxySwap.go b/solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSplProxySwap.go new file mode 100644 index 0000000..2f60fca --- /dev/null +++ b/solana/programs/OKXDEXAggregationRouterV2/parsers/commissionSplProxySwap.go @@ -0,0 +1,124 @@ +package parsers + +import ( + "fmt" + "github.com/0xjeffro/tx-parser/solana/globals" + "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2" + "github.com/0xjeffro/tx-parser/solana/programs/systemProgram" + SystemProgramParsers "github.com/0xjeffro/tx-parser/solana/programs/systemProgram/parsers" + "github.com/0xjeffro/tx-parser/solana/programs/tokenProgram" + TokenProgramParsers "github.com/0xjeffro/tx-parser/solana/programs/tokenProgram/parsers" + "github.com/0xjeffro/tx-parser/solana/types" +) + +func CommissionSplProxySwapParser(result *types.ParsedResult, instruction types.Instruction) (*OKXDEXAggregationRouterV2.CommissionSplProxySwapAction, error) { + + var who string + var fromToken, toToken string = globals.WSOL, globals.WSOL + var fromTokenDecimals, toTokenDecimals uint64 = globals.SOLDecimals, globals.SOLDecimals + var fromTokenAmount, toTokenAmount uint64 + + who = result.AccountList[instruction.Accounts[0]] + fromToken = result.AccountList[instruction.Accounts[3]] + toToken = result.AccountList[instruction.Accounts[4]] + + var fromTokenAccount, toTokenAccount string + fromTokenAccount = result.AccountList[instruction.Accounts[1]] + toTokenAccount = result.AccountList[instruction.Accounts[2]] + + // get index of this instruction + var instructionIndex int + for idx, instr := range result.RawTx.Transaction.Message.Instructions { + if result.AccountList[instr.ProgramIDIndex] == OKXDEXAggregationRouterV2.Program && instr.Data == instruction.Data { + instructionIndex = idx + break + } + } + + // get all innerInstructions for this instruction + var innerInstructions []types.Instruction + for _, innerInstruction := range result.RawTx.Meta.InnerInstructions { + if innerInstruction.Index == instructionIndex { + innerInstructions = innerInstruction.Instructions + break + } + } + + for _, instr := range innerInstructions { + programId := result.AccountList[instr.ProgramIDIndex] + switch programId { + case systemProgram.Program: + parsedData, err := SystemProgramParsers.InstructionRouter(result, instr) + if err != nil { + continue + } + switch p := parsedData.(type) { + case *types.SystemProgramTransferAction: + if p.From == fromTokenAccount { + fromTokenAmount += p.Lamports + } + if p.To == toTokenAccount { + toTokenAmount += p.Lamports + } + } + case tokenProgram.Program: + parsedData, err := TokenProgramParsers.InstructionRouter(result, instr) + if err != nil { + continue + } + switch p := parsedData.(type) { + case *types.TokenProgramTransferAction: + if p.From == fromTokenAccount { + fromTokenAmount += p.Amount + } + if p.To == toTokenAccount { + toTokenAmount += p.Amount + } + case *types.TokenProgramTransferCheckedAction: + if p.From == fromTokenAccount { + fromTokenAmount += p.Amount + } + if p.To == toTokenAccount { + toTokenAmount += p.Amount + } + } + default: + continue + } + } + + var tokenBalances []types.TokenBalance + tokenBalances = append(tokenBalances, result.RawTx.Meta.PreTokenBalances...) + tokenBalances = append(tokenBalances, result.RawTx.Meta.PostTokenBalances...) + + for _, tokenBalance := range tokenBalances { + account := result.AccountList[tokenBalance.AccountIndex] + if account == fromTokenAccount { + fromToken = tokenBalance.Mint + fromTokenDecimals = tokenBalance.UITokenAmount.Decimals + } else if account == toTokenAccount { + toToken = tokenBalance.Mint + toTokenDecimals = tokenBalance.UITokenAmount.Decimals + } + } + + fmt.Println("fromTokenAmount: ", fromTokenAmount) + fmt.Println("toTokenAmount: ", toTokenAmount) + + action := OKXDEXAggregationRouterV2.CommissionSplProxySwapAction{ + BaseAction: types.BaseAction{ + ProgramID: OKXDEXAggregationRouterV2.Program, + ProgramName: OKXDEXAggregationRouterV2.ProgramName, + InstructionName: "CommissionSplProxySwap", + }, + Who: who, + ToToken: toToken, + FromToken: fromToken, + ToTokenAmount: toTokenAmount, + FromTokenAmount: fromTokenAmount, + FromTokenDecimals: fromTokenDecimals, + ToTokenDecimals: toTokenDecimals, + } + + return &action, nil +} diff --git a/solana/programs/OKXDEXAggregationRouterV2/parsers/index.go b/solana/programs/OKXDEXAggregationRouterV2/parsers/index.go new file mode 100644 index 0000000..e82b394 --- /dev/null +++ b/solana/programs/OKXDEXAggregationRouterV2/parsers/index.go @@ -0,0 +1,31 @@ +package parsers + +import ( + "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2" + "github.com/0xjeffro/tx-parser/solana/types" + "github.com/mr-tron/base58" +) + +func InstructionRouter(result *types.ParsedResult, instruction types.Instruction) (types.Action, error) { + data := instruction.Data + decode, err := base58.Decode(data) + if err != nil { + return nil, err + } + discriminator := *(*[8]byte)(decode[:8]) + + switch discriminator { + case OKXDEXAggregationRouterV2.CommissionSplProxySwapDiscriminator: + return CommissionSplProxySwapParser(result, instruction) + case OKXDEXAggregationRouterV2.SwapDiscriminator: + return SwapParser(result, instruction, decode) + default: + return types.UnknownAction{ + BaseAction: types.BaseAction{ + ProgramID: result.AccountList[instruction.ProgramIDIndex], + ProgramName: OKXDEXAggregationRouterV2.ProgramName, + InstructionName: "Unknown", + }, + }, nil + } +} diff --git a/solana/programs/OKXDEXAggregationRouterV2/parsers/swap.go b/solana/programs/OKXDEXAggregationRouterV2/parsers/swap.go new file mode 100644 index 0000000..bc127c9 --- /dev/null +++ b/solana/programs/OKXDEXAggregationRouterV2/parsers/swap.go @@ -0,0 +1,70 @@ +package parsers + +import ( + "encoding/binary" + "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2" + "github.com/0xjeffro/tx-parser/solana/types" + "strconv" +) + +func SwapParser(result *types.ParsedResult, instruction types.Instruction, decodedData []byte) (*OKXDEXAggregationRouterV2.SwapAction, error) { + who := result.AccountList[instruction.Accounts[0]] + fromToken := result.AccountList[instruction.Accounts[3]] + toToken := result.AccountList[instruction.Accounts[4]] + fromTokenAmount := binary.LittleEndian.Uint64(decodedData[8:16]) + toTokenAmount := uint64(0) + + preTokenBalances := result.RawTx.Meta.PreTokenBalances + postTokenBalances := result.RawTx.Meta.PostTokenBalances + + var preToTokenAmount, postToTokenAmount uint64 + var fromTokenDecimals, toTokenDecimals uint64 + for _, b := range preTokenBalances { + if b.Mint == toToken && b.Owner == who { + var err error + preToTokenAmount, err = strconv.ParseUint(b.UITokenAmount.Amount, 10, 64) + if err != nil { + return nil, err + } + } + if b.Mint == fromToken { + fromTokenDecimals = b.UITokenAmount.Decimals + } + if b.Mint == toToken { + toTokenDecimals = b.UITokenAmount.Decimals + } + } + for _, b := range postTokenBalances { + if b.Mint == toToken && b.Owner == who { + var err error + postToTokenAmount, err = strconv.ParseUint(b.UITokenAmount.Amount, 10, 64) + if err != nil { + return nil, err + } + break + } + if b.Mint == fromToken { + fromTokenDecimals = b.UITokenAmount.Decimals + } + if b.Mint == toToken { + toTokenDecimals = b.UITokenAmount.Decimals + } + } + toTokenAmount = postToTokenAmount - preToTokenAmount + + action := OKXDEXAggregationRouterV2.SwapAction{ + BaseAction: types.BaseAction{ + ProgramID: OKXDEXAggregationRouterV2.Program, + ProgramName: OKXDEXAggregationRouterV2.ProgramName, + InstructionName: "Swap", + }, + Who: who, + FromToken: fromToken, + ToToken: toToken, + FromTokenAmount: fromTokenAmount, + ToTokenAmount: toTokenAmount, + FromTokenDecimals: fromTokenDecimals, + ToTokenDecimals: toTokenDecimals, + } + return &action, nil +} diff --git a/solana/programs/OKXDEXAggregationRouterV2/types.go b/solana/programs/OKXDEXAggregationRouterV2/types.go new file mode 100644 index 0000000..de096ac --- /dev/null +++ b/solana/programs/OKXDEXAggregationRouterV2/types.go @@ -0,0 +1,36 @@ +package OKXDEXAggregationRouterV2 + +import "github.com/0xjeffro/tx-parser/solana/types" + +type CommissionSplProxySwapAction struct { + types.BaseAction + Who string `json:"who"` + FromToken string `json:"fromToken"` + FromTokenAmount uint64 `json:"fromTokenAmount"` + FromTokenDecimals uint64 `json:"fromTokenDecimals"` + ToToken string `json:"toToken"` + ToTokenAmount uint64 `json:"toTokenAmount"` + ToTokenDecimals uint64 `json:"toTokenDecimals"` +} + +type CommissionSplProxySwap2Action struct { + types.BaseAction + Who string `json:"who"` + FromToken string `json:"fromToken"` + FromTokenAmount uint64 `json:"fromTokenAmount"` + FromTokenDecimals uint64 `json:"fromTokenDecimals"` + ToToken string `json:"toToken"` + ToTokenAmount uint64 `json:"toTokenAmount"` + ToTokenDecimals uint64 `json:"toTokenDecimals"` +} + +type SwapAction struct { + types.BaseAction + Who string `json:"who"` + FromToken string `json:"fromToken"` + FromTokenAmount uint64 `json:"fromTokenAmount"` + FromTokenDecimals uint64 `json:"fromTokenDecimals"` + ToToken string `json:"toToken"` + ToTokenAmount uint64 `json:"toTokenAmount"` + ToTokenDecimals uint64 `json:"toTokenDecimals"` +} diff --git a/solana/programs/U6m2CDdhRg/meta.go b/solana/programs/U6m2CDdhRg/meta.go index 7b01fb0..35dab66 100644 --- a/solana/programs/U6m2CDdhRg/meta.go +++ b/solana/programs/U6m2CDdhRg/meta.go @@ -3,4 +3,4 @@ package U6m2CDdhRg const Program = "6m2CDdhRgxpH4WjvdzxAYbGxwdGUz5MziiL5jek2kBma" const ProgramName = "Unknown" -var SwapDiscriminator = [8]uint8{65, 75, 63, 76, 235, 91, 91, 136} +var SwapDiscriminator = [8]uint8{65, 75, 63, 76, 235, 91, 91, 136} \ No newline at end of file diff --git a/solana/programs/computeBudget/meta.go b/solana/programs/computeBudget/meta.go index 59c9ff5..6b3dfed 100644 --- a/solana/programs/computeBudget/meta.go +++ b/solana/programs/computeBudget/meta.go @@ -4,4 +4,4 @@ const Program = "ComputeBudget111111111111111111111111111111" const ProgramName = "ComputeBudget" var SetComputeUnitLimitDiscriminator = uint8(2) -var SetComputeUnitPriceDiscriminator = uint8(3) +var SetComputeUnitPriceDiscriminator = uint8(3) \ No newline at end of file diff --git a/solana/router.go b/solana/router.go index 3eaf00a..d461d58 100644 --- a/solana/router.go +++ b/solana/router.go @@ -1,13 +1,12 @@ package solana import ( - "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6" - JupiterAggregatorV6 "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6/parsers" - - "github.com/0xjeffro/tx-parser/solana/programs/U6m2CDdhRg" - U6m2CDdhRgParsers "github.com/0xjeffro/tx-parser/solana/programs/U6m2CDdhRg/parsers" + "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2" + OKXDEXAggregationRouterV2Parsers "github.com/0xjeffro/tx-parser/solana/programs/OKXDEXAggregationRouterV2/parsers" "github.com/0xjeffro/tx-parser/solana/programs/computeBudget" ComputeBudgetParsers "github.com/0xjeffro/tx-parser/solana/programs/computeBudget/parsers" + "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6" + JupiterAggregatorV6 "github.com/0xjeffro/tx-parser/solana/programs/jupiterAggregatorV6/parsers" "github.com/0xjeffro/tx-parser/solana/programs/jupiterDCA" JupiterDCA "github.com/0xjeffro/tx-parser/solana/programs/jupiterDCA/parsers" "github.com/0xjeffro/tx-parser/solana/programs/pumpfun" @@ -39,14 +38,15 @@ func router(result *types.ParsedResult, instructionIdx int) (action types.Action return ComputeBudgetParsers.InstructionRouter(result, instruction) case pumpfun.Program: return PumpfunParsers.InstructionRouter(result, instruction) - case U6m2CDdhRg.Program: - return U6m2CDdhRgParsers.InstructionRouter(result, instruction) case jupiterDCA.Program: return JupiterDCA.InstructionRouter(result, instruction) case raydiumLiquidityPoolV4.Program: return RaydiumLiquidityPoolV4.InstructionRouter(result, instruction, instructionIdx) case jupiterAggregatorV6.Program: return JupiterAggregatorV6.InstructionRouter(result, instruction) + case OKXDEXAggregationRouterV2.Program: + return OKXDEXAggregationRouterV2Parsers.InstructionRouter(result, instruction) + default: return types.UnknownAction{ BaseAction: types.BaseAction{