setup reclaim order#53
Merged
Merged
Conversation
fedgiac
reviewed
Jul 1, 2026
prevents potential unexpected behavior anywhere else
…cowprotocol/solana-programs into kaze/sc-150-close-order-account
fedgiac
reviewed
Jul 7, 2026
fedgiac
reviewed
Jul 7, 2026
fedgiac
left a comment
Contributor
There was a problem hiding this comment.
Mostly minor comments.
The only notable points are:
- I think there's a security issue because we don't validate the PDA before clearing it. Should be reasonably easy to address.
- I still don't like the complexity introduced to handle time in unit tests. I think it's fine to just do the one relevant test as an integration test. (Same if there were more.)
- I added a suggestion on how to (imho) improve the unsafe block.
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
…checks from pda this requires adding bumps to the input data of the reclaimorder function
fedgiac
reviewed
Jul 16, 2026
tilacog
reviewed
Jul 16, 2026
Comment on lines
+58
to
+81
| impl OrderAccount { | ||
| /// Load and decode the order at the given PDA, and confirm its canonical | ||
| pub fn load_from_pda( | ||
| order_pda: &AccountView, | ||
| program_id: &Address, | ||
| bump: u8, | ||
| ) -> Result<Self, ProgramError> { | ||
| let data = order_pda.try_borrow()?; | ||
| let bytes: &[u8; EncodedOrderAccount::SIZE] = (&*data) | ||
| .try_into() | ||
| .map_err(|_| ProgramError::InvalidAccountData)?; | ||
| let (account, uid) = EncodedOrderAccount::decode_and_hash(bytes)?; | ||
| drop(data); | ||
|
|
||
| let expected = | ||
| Address::create_program_address(&order_pda_signer_seeds(&uid, &[bump]), program_id) | ||
| .map_err(|_| SettlementError::OrderNotCanonical)?; | ||
| if &expected != order_pda.address() { | ||
| return Err(SettlementError::OrderNotCanonical.into()); | ||
| } | ||
|
|
||
| Ok(account) | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Would it make sense to have traits for account deserialization just like we do for Instruction parsing?
(ref)
Contributor
Author
There was a problem hiding this comment.
it would but as of right now this is the only load_from_pda function we have so I didn't want to go too crazy for this PR.
I didn't see any great stdlib traits that would have made sense here either so if we do make a trait it would literally just be defining this function and thats it; and as you mention there are the bump consideration issues.
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: tilacog <tilacog@gmail.com>
…ay its non canonical
fedgiac
approved these changes
Jul 17, 2026
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the
ReclaimOrderinstruction. Also add some more capabilities to the test helpers.Changes
The ReclaimOrder instruction is fairly simple: anyone can call this instruction once an order has expired to close the account and return the rent to the original order creator.
Besides the addition of the instruction itself, I found it would be very helpful if the unit tests could do more to validate the behavior of the function. So I added a new account initialization fixture,
fake_account_with_data, which allows for creating an account that contains data that can subsequently be used to validate more conditions with particular input order PDAs. Unfortunately, due to the unusual dynamic memory layout of theRuntimeAccounttype which puts the account data contiguously after the actual data is set, .Additionally,
Clock::get()always returns an error outside of a solana target_os context, so I replaced calls to this with a helper functionget_timestampthat is stubbed to a static value (arbitrarily chosen to be 2026/01/01) for unit tests.Finally, while writing the unit tests, I noticed its not ergonomic to create new order data because
Defaulttrait was not in use. So I added it using#[derive]macro. In the future we may want to refactor more of the tests to remove helpers likesample_intentwhich basically just give you a plain intent. The default pattern is just a lot more ergonomic and standardized.With these optimizations, testing a function which has an input order PDA turned out to be relatively ergonomic in unit tests:
How to test
Check CI. Observe the changes and consider if the general direction. Evaluate if the usage of additional unsafe code is warranted for what it accomplishes.