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

feat: transaction builder #1356

Merged
merged 79 commits into from
Mar 15, 2024
Merged

feat: transaction builder #1356

merged 79 commits into from
Mar 15, 2024

Conversation

guibescos
Copy link
Contributor

@guibescos guibescos commented Mar 13, 2024

This PR addresses a comment in #1330. It tries to make the sdk more ergonomic by providing a transaction builder.
You can see how to use the transaction builder in the README.

Copy link

vercel bot commented Mar 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
example-oracle-amm ⬜️ Ignored (Inspect) Visit Preview Mar 15, 2024 0:02am
xc-admin-frontend ⬜️ Ignored (Inspect) Visit Preview Mar 15, 2024 0:02am

@guibescos guibescos changed the title Solana/js sdk feat: transaction builder Mar 13, 2024
@guibescos guibescos marked this pull request as ready for review March 13, 2024 16:07
*
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
*/
async withPostPriceUpdates(priceUpdateDataArray: string[]) {
Copy link
Contributor Author

@guibescos guibescos Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we enforce that
withPostPriceUpdates, withPriceConsumerInstructions and withCloseInstructions need to be called sequentially and each one only once?

Copy link
Collaborator

@ali-bahjati ali-bahjati Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to expose them. If you enforce it via different types (or markers from below) the auto complete will also guide people to use it correctly. If you have an intermediate step you can have Builder & pricesMap: Record<String, String> exposed and people can just call addInstruction or addInstructions without lambda function.

Look at here or here to see how you can impose order using some type markers. Feel free to ignore it if you think it gets complex.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of constraints here aren't strictly necessary right? Like in theory I could call withPriceConsumerInstructions multiple times adding different sets of instructions and the code will work (?)

My inclination would be to avoid adding constraints on usage that aren't necessary for correctness -- you're just making the builder less flexible. see also the comment below about withCloseInstructions which I think helps resolve the one correctness constraint that exists.

* ...
* ```
*/
async withPostPartiallyVerifiedPriceUpdates(priceUpdateDataArray: string[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nit: normally withX implied that you return it and i chain them together.
B.withX().withY().build(). Maybe addX be a name that doesn't imply it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i agree with this. generally with builders there's always a question of "does this method mutate the internal state, or does it return a new builder". The with naming suggests that it returns a new builder

Copy link
Contributor

@jayantk jayantk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM. I left a couple suggestions on the approach here, but feel free to address whenever and merge this without another review from me.

* ...
* ```
*/
async withPostPartiallyVerifiedPriceUpdates(priceUpdateDataArray: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i agree with this. generally with builders there's always a question of "does this method mutate the internal state, or does it return a new builder". The with naming suggests that it returns a new builder

*
* @param priceUpdateDataArray the output of the `@pythnetwork/price-service-client`'s `PriceServiceConnection.getLatestVaas`. This is an array of verifiable price updates.
*/
async withPostPriceUpdates(priceUpdateDataArray: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of constraints here aren't strictly necessary right? Like in theory I could call withPriceConsumerInstructions multiple times adding different sets of instructions and the code will work (?)

My inclination would be to avoid adding constraints on usage that aren't necessary for correctness -- you're just making the builder less flexible. see also the comment below about withCloseInstructions which I think helps resolve the one correctness constraint that exists.

this.priceFeedIdToPriceUpdateAccount[priceFeedId];
if (!priceUpdateAccount) {
throw new Error(
`A price update account for the price feed ID ${priceFeedId} is being consumed before it was posted. Make sure to call addPostPriceUpdates or addPriceConsumerInstructions before calling addPriceConsumerInstructions.`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is ambiguous

@guibescos guibescos merged commit 8b1c29e into main Mar 15, 2024
6 checks passed
@guibescos guibescos deleted the solana/js-sdk branch March 15, 2024 12:11
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 this pull request may close these issues.

3 participants