Skip to content

Add instruction to add a solver - #119

Merged
fedgiac merged 22 commits into
mainfrom
federico/sc-299-add-functions-to-add-solver
Aug 28, 2026
Merged

Add instruction to add a solver#119
fedgiac merged 22 commits into
mainfrom
federico/sc-299-add-functions-to-add-solver

Conversation

@fedgiac

@fedgiac fedgiac commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Add the first of the manager's solver-management instructions: AddSolver inserts a solver into the allowlist stored in the state PDA.
Moreover, it encodes this list into the state PDA and includes the minimum accessors needed to it.

Scope is deliberately add only: removing solvers and the solver gate on settling are separate follow-ups. Right now, solvers are unused, can only be appended to.

Solver storage

Solvers live packed and sorted by address immediately after the header, one 32-byte entry each. Sorted storage keeps the list binary-searchable, which is what the manager gate and the future settle gate rely on.

The instruction

The manager authorizes: it signs but doesn't pay. Someone needs to pay for the extra rent from the account's growth, and that's the dedicated payer.

Test-helper cleanup (incidental)

Single-instruction tests were calling assert_settlement_error(0, …), whose instruction-index argument is only meaningful for the multi-instruction settlement tests. I moved that helper out of the shared common scaffolding into settle_limit_prices.rs (the one file that has a reason to care about the index). No behaviour change.

How to test

New tests.

@fedgiac
fedgiac requested a review from a team as a code owner August 26, 2026 00:40
@linear-code

linear-code Bot commented Aug 26, 2026

Copy link
Copy Markdown

SC-299

@kaze-cow kaze-cow 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.

it may be worthwhile, similar to the pattern taken with ReclaimBuffers, to allow for multiple solvers to be added in a single instruction. It doesn't seem like it would be that hard, as it could be resize once by the number of new addresses being added and then call add_solver on StatePda in a loop (see comment)

HOWEVER, in the name of accelerating for the deadline, feel free to ignore this change if its going to take longer than maybe 30 minutes to an hour.

Single-instruction tests were calling assert_settlement_error(0, …), whose instruction-index argument is only meaningful for the multi-instruction settlement tests. I moved that helper out of the shared common scaffolding into settle_limit_prices.rs (the one file that has a reason to care about the index). No behaviour change.

I thought we introduced a new assert_settlement_error_at to remove the index for most cases? or was that in an unmerged PR...

I later saw that the function was not the one I thought I added. assert_setltement_error should have basically been a wrapper for assert_settlement_error_at with 0 index.

Comment thread client/src/parse.rs
Comment thread programs/settlement/src/add_solver.rs
Comment thread programs/settlement/src/add_solver.rs
Comment thread programs/settlement/src/add_solver.rs Outdated
Comment thread programs/settlement/src/add_solver.rs Outdated
Comment thread programs/settlement/tests/add_solvers.rs
Comment thread programs/settlement/tests/add_solvers.rs
Comment thread programs/settlement/tests/add_solvers.rs Outdated
Comment thread programs/settlement/tests/add_solvers.rs
Comment thread bench-report.json Outdated
Comment thread interface/src/data/state.rs Outdated
@fedgiac

fedgiac commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

About adding multiple solvers at once: I want to do it but I won't because it would take more than 1h to do it properly. I created an issue to remember about this. Even if we do this, I'd do that in another PR to prevent the scope from growing.

@kaze-cow kaze-cow 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.

couple of minor it appears unaddressed comments. overall would be ok with merging this otherwise.

Base automatically changed from refactor-state-account-decoder to main August 27, 2026 10:43
@fedgiac
fedgiac requested a review from kaze-cow August 27, 2026 16:52

@kaze-cow kaze-cow 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.

looks good!

@fedgiac
fedgiac merged commit b9598e9 into main Aug 28, 2026
14 checks passed
@fedgiac
fedgiac deleted the federico/sc-299-add-functions-to-add-solver branch August 28, 2026 08:38
kaze-cow added a commit that referenced this pull request Aug 28, 2026
Drives the new `AddSolver` instruction (#119) from the dev CLI:

```
cow solver add <address> [--manager <keypair-path>]
```

- New `test-cli/src/cmd/solver.rs`: a `solver` command group whose `add`
subcommand builds `cow_settlement_client::instructions::AddSolver`
against the derived state PDA, sends it, and prints a summary
(signature, solver, manager, statePda).
- `AddSolver` needs both the manager's and the payer's signature, so
`--manager` takes a *keypair path*, not an address. It defaults to by
the same as `--keypair`, which is the payer.

## Verification

I deployed a testing program for this base branch for the change at
`7hwEhpgqZy1qRNMdFvVh4YjerBrZnMR7qGZUbLJTFSxg`

To test adding a solver:

```
➜  solana-programs git:(kaze/sc-299-add-functions-to-addremove-solvers) ./target/debug/cow solver add B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5 --program-id 7hwEhpgqZy1qRNMdFvVh4YjerBrZnMR7qGZUbLJTFSxg
signature = 2dsTvWAGvxL2w9MVWTHiMn76oKM73XH29GWh5eaKAGfh739A3CrB4ZRhh1hF72HppJdJyRHSmCTUY1gKi6DzwcXE
   solver = B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5
  manager = B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5
 statePda = HkqW1CPzMddJzZm5eFfFBK3wH6uUasLLQ5TczrM2o5VQ
```

The specified solver account can now be used for a settlement as in #98 

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
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