Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an example, a test, and docs for decodeInstruction() #172

Open
3 tasks done
gotjoshua opened this issue Sep 23, 2021 · 1 comment · May be fixed by #174
Open
3 tasks done

Provide an example, a test, and docs for decodeInstruction() #172

gotjoshua opened this issue Sep 23, 2021 · 1 comment · May be fixed by #174

Comments

@gotjoshua
Copy link

gotjoshua commented Sep 23, 2021

I am trying to decode serum order info directly from the blockchain history (rpc results) this issue will document the process of figuring out how, and offer a PR to improve the internal documentation.

  • create a codesandbox
  • add a test for the decodeInstruction() fx 20a776e
  • add internal jsdocs for the decodeInstruction() fx a628aad
@gotjoshua
Copy link
Author

gotjoshua commented Sep 29, 2021

Earlier process (moved out of main issue description)

I think I should be able to pass a solana Instruction from the rpc directly to the exported serum function decodeInstruction()

I tried with raw TransactionInstruction from getConfirmedTransaction...
and with:
PartiallyDecodedInstruction from getParsedConfirmedTransactions

both give an error with this stack:

 Layout.js:570 Uncaught (in promise) TypeError: b.readUIntLE is not a function
    at UInt.decode (Layout.js:570)
    at OffsetLayout.decode (Layout.js:529)
    at UnionLayoutDiscriminator.decode (Layout.js:1414)
    at Union.decode (Layout.js:1682)
    at VersionedLayout.decode (layout.js:97)
    at decodeInstruction (instructions.js:108)

it seems that instructions.decode is passing along the whole (untyped) message and later decode is expecting it to have a
readUIntLE function.

further details of the issue:

@armaniferrante said
That decodeInstruction takes in raw bytes, i.e. the "instruction data"

So rather than passing the whole instruction one needs to pass the instruction.data in as a Uint8Array of raw bytes.

In this codesandbox i'm using basex-encoder.decodeToBuffer() to convert the PartiallyDecodedInstruction.data (which is base58 encoded) and then passing that to the serum decodeInstruction() fx, which returns this:

newOrderV3: Object
  side: "buy"
  limitPrice: BN
  maxBaseQuantity: BN
  maxQuoteQuantity: BN
  selfTradeBehavior: "decrementTake"
  orderType: "limit"
  clientId: BN
  limit: 65535

gotjoshua added a commit to gotjoshua/serum-ts that referenced this issue Sep 30, 2021
gotjoshua added a commit to gotjoshua/serum-ts that referenced this issue Sep 30, 2021
gotjoshua added a commit to gotjoshua/serum-ts that referenced this issue Sep 30, 2021
@gotjoshua gotjoshua changed the title Provide better typings, an example and or test for decodeInstruction() Provide an example, a test, and docs for decodeInstruction() Sep 30, 2021
gotjoshua added a commit to gotjoshua/serum-ts that referenced this issue Sep 30, 2021
@gotjoshua gotjoshua linked a pull request Sep 30, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant