codama-idl / codama

Generate clients, CLIs, documentation and more from your Solana programs
MIT License
73 stars 16 forks source link

Render sol amount as lamports #161

Closed mcintyre94 closed 2 months ago

mcintyre94 commented 2 months ago

Note: #160 is a prerequisite (Graphite 💔)

This PR updates how SolAmountTypeNode is rendered in the new web3js renderer. Previously it just rendered its nested number type. It now renders with a Lamports type from web3js. The encoder + decoder use getLamportsEncoder and getLamportsDecoder, passing the nested number encoder/decoder as an argument.

This means that you can represent Lamports in the Kinobi IDL using any numeric type, and you'll get properly typed Lamports back. This can improve eg parsing of instructions like createAccount where some arguments represent Lamport values.

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: 50ba8117e767a87104cc370d64e2f2140f7fbfb7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ----------------------- | ----- | | @kinobi-so/renderers-js | Patch | | @kinobi-so/renderers | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

lorisleiva commented 2 months ago

Nice thanks for this! Would you mind adding a changeset and a test for this?

For the changeset, you can just run changeset locally and for the test you can get inspired by this test and name it something like solAmount.test.ts.