Skip to content

Conversation

@febo
Copy link
Collaborator

@febo febo commented Nov 18, 2025

Problem

Creating accounts funded by a payer account is a common operation. In most cases, the logic needs to be replicated in different programs.

Solution

Add a helper to create accounts. The helper supports creating both PDA and non-PDA accounts.

@febo febo force-pushed the febo/create-account-helper branch from 4c01fc7 to 4b87477 Compare November 18, 2025 13:52
@febo febo marked this pull request as draft November 18, 2025 13:55
@febo febo closed this Nov 18, 2025
@febo febo force-pushed the febo/create-account-helper branch from 4b87477 to 05f74a9 Compare November 18, 2025 13:58
@febo febo reopened this Nov 18, 2025
@febo febo marked this pull request as ready for review November 18, 2025 14:04
to: account,
lamports: required_lamports,
}
.invoke()?;
Copy link

Choose a reason for hiding this comment

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

Should we make this .invoke_signed(signers)?; to support the case a PDA acts as the funding account for the transfer?

Copy link
Collaborator Author

@febo febo Nov 19, 2025

Choose a reason for hiding this comment

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

Yeah, that is a good point. It would only work for PDAs used as signers (i.e., owned by the system program), but it is a good idea to support this scenario.

Made the change on 1466eda and updated the docs.

Rent::get()?.minimum_balance(space)
};

if account.lamports() == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you think about using hints from pinocchio::hint module?

i expect account is not exist, in the majority of cases

Suggested change
if account.lamports() == 0 {
if likely(account.lamports() == 0) {

Choose a reason for hiding this comment

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

nice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

what do you think about using hints from pinocchio::hint module?

i expect account is not exist, in the majority of cases

It made no difference in my tests. Also, I had a look at the asm and it seems the compiler is doing the right thing already. Did you notice a difference?

Copy link
Contributor

Choose a reason for hiding this comment

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

the same for the lib (i didn't test it in the real app).
As a part of library it compiles in the expected instructions.
Just wanted to make extra sure this logic won't be miscompiled in the large program.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wrote a small program and there was no difference. I think we can leave it as it is and revisit later if we see that there is a change in behaviour.

@febo febo requested a review from grod220 November 19, 2025 11:14
@febo febo force-pushed the febo/create-account-helper branch from 49fc5db to 1466eda Compare November 19, 2025 11:15
Copy link

@grod220 grod220 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

6 participants