1

I am trying to create a Java (not Javascript!) Solana client that is able to understand/filter/process Meteora transactions. I started using the officially recommended library https://github.com/skynetcap/solanaj (recommended here: https://solana.com/docs/intro/dev#client-side-development) in a Spring Boot Server.

With just a few lines of code, I can already grab finalized transactions from the RPC that interacted with the Meteora DLMM program. It is as easy as this:

String meteoraProgramId = "LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo";
List<SignatureInformation> meteoraSignatures = client.getApi().getSignaturesForAddress(new PublicKey(meteoraProgramId), 1, Commitment.FINALIZED);
ConfirmedTransaction transaction = client.getApi().getTransaction(meteoraSignatures.get(0).getSignature());

When I debug into the resulting ConfirmedTransaction object, I am able to find all instructions and inner instructions. And as far as I understood, the real value (which instruction it is exactly and what input parameters were given) can only be understood when I decode it with the Meteora IDL. This one would be available in a JSON format in Meteoras SDK here https://github.com/MeteoraAg/dlmm-sdk/blob/main/ts-client/src/dlmm/idl.ts#L5163.

Sooo, can anyone guide me on the right path how I can decode the instructions? In JS/TS I would need to use a Borsh thingy that can be initialized with the IDL, but I haven't found anything similar in Java.

1
  • You would need to do the same kind of thing as in JS / TS, meaning use a deserialization library like borsh to deserialize the instructions according to the IDL. I don't think there exists a Java library to do that though, unfortunately
    – Jon C
    Commented Sep 6 at 17:01

2 Answers 2

0

I added an example to my README to demonstrate how you can do this with my Solana Java libraries, specifically if you jump down to the DriftProgram.PlaceOrdersIxData part. This library includes generated source for several popular programs from their mainnet IDL's including the Meteora DLMM program.

var placeOrdersIxData = Arrays.stream(instructions)
    .filter(DriftProgram.PLACE_ORDERS_DISCRIMINATOR)
    .map(DriftProgram.PlaceOrdersIxData::read)
    .findFirst().orElseThrow();

OrderParams[] orderParamsArray = placeOrdersIxData.params();
OrderParams orderParams = orderParamsArray[0];
2
  • This looks very promising! Thanks a lot for the links. If I understand correctly other people that want to build Java Classes for other IDLs could use your Generator for that purpose. But should first check if you already generated the sources in the repo of your link.
    – imaykay
    Commented Oct 3 at 12:49
  • Yes, either way. If there is a larger project and they have an anchor IDL deployed on chain I can add it. Keep in mind this is still a WIP and their is a high probability there will be some things the generator doesn't handle yet. Sometimes its easy to fix, other times not so much. The other reason to use the library, for some programs I have started program clients, e.g. Drift, which makes it much easier to serialize program instructions.
    – jpe7s
    Commented Oct 3 at 13:36
0

You can use sol4k to deserialize Solana transactions in Java.

var transaction = VersionedTransaction.from("AQAA....");

Here is an example from the unit tests (in Kotlin). Here is a repository with ready-to-run Java examples.

3
  • Okay, but I don't understand yet how I would get human readable instruction data from the framework? I only see ByteArray data properties in the Instruction classes. Any further tip?
    – imaykay
    Commented Oct 3 at 12:44
  • What do you mean by "human readable instruction data"? Instruction Data is byte array that can be anything depending on the transaction type. What you can read is Program IDs and accounts involved in the instruction. Commented Oct 3 at 19:53
  • Yes, exactly. And if you know the IDL of the program of the transaction type, you can deserialize this byte array into well known objects whose properties and their values become "human readable". In JS that is an easy task, but it wasn't clear to me how I can achieve this in Java. The Sava stack from the other answer provides very useful utility, but I was hoping that you knew another option to compare a little bit.
    – imaykay
    Commented Oct 4 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.