setup reclaim order#53
Open
kaze-cow wants to merge 6 commits into
Open
Conversation
fedgiac
reviewed
Jul 1, 2026
Comment on lines
+68
to
+85
| /// Current on-chain unix timestamp. | ||
| /// | ||
| /// Off the Solana target (e.g. host-run unit tests), the `Clock` sysvar isn't | ||
| /// available, so this returns a fixed 2026-01-01T00:00:00Z timestamp instead. | ||
| #[cfg(target_os = "solana")] | ||
| #[inline(always)] | ||
| pub fn get_timestamp() -> Result<i64, ProgramError> { | ||
| use pinocchio::sysvars::{clock::Clock, Sysvar}; | ||
|
|
||
| Ok(Clock::get()?.unix_timestamp) | ||
| } | ||
|
|
||
| #[cfg(not(target_os = "solana"))] | ||
| #[inline(always)] | ||
| pub fn get_timestamp() -> Result<i64, ProgramError> { | ||
| Ok(1_767_225_600) | ||
| } | ||
|
|
Contributor
There was a problem hiding this comment.
I don't like this approach: it's a landmine for anyone who wants to use the settlement program outside the solana environment. The implicit assumption here is that this is only used for tests, and even then, we'd be testing with code that does something different from what we want to test for. What if unix_timestamp is in a different format, or if this has some meaningful side effect that we wouldn't know (like, increasing the number of CPIs and changing the logs)?
I see that the syscall invocation when os ≠ solana returns UnsupportedSysvar.
Maybe this unfortunately a good reason to actually end up using integration tests only. 😢
prevents potential unexpected behavior anywhere else
…cowprotocol/solana-programs into kaze/sc-150-close-order-account
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.