1

So I'm having trouble finding the offset for some account keys of programs that have an IDL and would like to get some help on this. For example in this program

https://solscan.io/account/dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH#anchorProgramIDL

I would like for this account:

Account struct

To know the offset where the key "unrealizedPnlMaxImbalance" begins.

Thank you in advance, for any help given

2 Answers 2

1

It's a bit annoying, but if you want the offset, the easiest option is to just count up all the bytes to get to the field that you care about. In your case, we can count all the way unrealizedPnlMaxImbalance:

  • pubkey: 32 bytes
  • amm: this one's complicated since it's a big type called "AMM" and has many subtypes in it. You could go through by hand and count the number of bytes in all the fields, but I'm being lazy, sorry!
  • pnlPool: PoolBalance which is 16 bytes for scaledBalance, 2 for marketIndex, and 6 for padding
  • name: 32 bytes
  • insuranceClaim: 5 ints, 8 bytes each
  • unrealizedPnlMaxImbalance: made it!

I hope this will be a good first step, and apologies for my laziness for counting up the bytes in the AMM type. Best of luck!

0

I provide these byte offsets in my Java library. I think it is pretty unique and lacking in other languages.

This is all possible because of Anchor IDL's, which I leverage with this anchor source generator.

tldr: the byte offset at this time is 1072. hope you go down the rabbit hole.

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.