Skip to content

feat: Save CU by removing parsing/validation of the token program account args - #144

Merged
kaze-cow merged 2 commits into
kaze/sc-153-token-2022-settlefrom
kaze/sc-153-token-2022-optimize
Sep 11, 2026
Merged

kaze-cow merged 2 commits into
kaze/sc-153-token-2022-settlefrom
kaze/sc-153-token-2022-optimize

Conversation

@kaze-cow

@kaze-cow kaze-cow commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

kaze-cow and others added 2 commits September 8, 2026 18:00
Every token-moving instruction still names its token program — a CPI can
only dispatch to a program its own instruction names — but nothing reads
those accounts any more. The program a transfer targets is the one owning
the account it moves, which the account itself says, so the slots are
skipped positionally and dropped from the parsed inputs.

`BeginSettle` pulls against the sell account's owner and `FinalizeSettle`
pushes against the destination's owner; `CreateBuffer` creates each buffer
under its mint's owner and `ReclaimBuffer` closes each one through the
program that owns it. That takes ~110-170 CU off every settlement, and
costs ~35 CU per buffer in the two batch instructions, which resolve once
per buffer rather than once per instruction.

`TokenProgramNotProvided` went with the slot validation: a settlement that
leaves out a program its accounts live under is now refused by the runtime
as a missing account. `PushDestinationInvalid` takes its code, both being
new on this stack.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@linear-code

linear-code Bot commented Sep 8, 2026

Copy link
Copy Markdown

SC-153

@kaze-cow kaze-cow changed the title Kaze/sc 153 token 2022 optimize feat: Save CU by removing parsing/validation of the token program account args Sep 8, 2026

@fedgiac fedgiac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very good idea, let's merge this into #128. Some comments, also I think comments are generally too heavy, but this was fine for a draft. Feel free to merge without approval since what matters is how it works with #128.

Comment thread client/src/instructions.rs
Comment thread interface/src/instruction/settle/begin.rs
Comment thread interface/src/lib.rs
Comment thread programs/settlement/src/token.rs
Comment thread programs/settlement/src/token.rs
Comment thread programs/settlement/src/token.rs
Comment thread programs/settlement/tests/common/token.rs
Comment thread programs/settlement/tests/begin_settle_orders.rs
Comment thread programs/settlement/tests/create_buffer.rs
Comment thread programs/settlement/tests/settle_solver_auth.rs
@kaze-cow

Copy link
Copy Markdown
Contributor Author

will address comments in #128 to speed things along

@kaze-cow
kaze-cow marked this pull request as ready for review September 11, 2026 08:08
@kaze-cow
kaze-cow requested a review from a team as a code owner September 11, 2026 08:08
@kaze-cow
kaze-cow merged commit 6ecb26c into kaze/sc-153-token-2022-settle Sep 11, 2026
16 of 18 checks passed
@kaze-cow
kaze-cow deleted the kaze/sc-153-token-2022-optimize branch September 11, 2026 08:09
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.

2 participants