-
Notifications
You must be signed in to change notification settings - Fork 0
Push proceeds to users in FinalizeSettle
#62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0047ca9
b8b3804
3e07aaa
f6ad585
49fbd56
dc509c3
c84fc3f
9337a58
606693d
d01ae1a
aad2a64
903fa88
9f67290
514e20b
e71d23e
75130af
eb98478
8fe14a4
a81feaa
8c82ddc
8799e9d
006ebb9
dc54836
da7f43c
7e2f5e0
841def6
c48a9f1
777ffec
5a5d282
af7e4c5
bd4072a
e29f7c8
c495133
c00acd1
572f55e
c14c364
17f3cb8
0b496e1
3933d96
3942889
1c2c02c
915dabc
43147d2
db268c7
6c8213c
68dfbe0
bf1b683
a3bd2e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,16 @@ | |
|
|
||
| use std::ops::Deref; | ||
|
|
||
| use pinocchio::{sysvars::instructions::Instructions, Address, ProgramResult}; | ||
| use pinocchio::{ | ||
| cpi::{Seed, Signer}, | ||
| error::ProgramError, | ||
| sysvars::instructions::Instructions, | ||
| AccountView, Address, ProgramResult, | ||
| }; | ||
| use settlement_interface::{ | ||
| instruction::settle::recover_counterpart, recover_discriminator, SettlementError, | ||
| SettlementInstruction, | ||
| instruction::{create_buffer::SPL_TOKEN_PROGRAM_ID, settle::recover_counterpart}, | ||
| pda::state::{state_pda_seeds, state_pda_signer_seeds}, | ||
| recover_discriminator, SettlementError, SettlementInstruction, | ||
| }; | ||
|
|
||
| mod begin; | ||
|
|
@@ -42,3 +48,35 @@ fn validate_counterpart<T: Deref<Target = [u8]>>( | |
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Validate that `token_program_account` is the legacy SPL Token program, which | ||
| /// every settlement transfer is issued against. | ||
| #[must_use = "ignoring the output may lead to an unintended on-chain state"] | ||
| fn validate_token_program_account(token_program_account: &AccountView) -> ProgramResult { | ||
| if token_program_account.address() != &SPL_TOKEN_PROGRAM_ID { | ||
| return Err(ProgramError::IncorrectProgramId); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Validate that `state_pda_account` is the canonical state PDA and run `f` with | ||
| /// a signer for it. Both settlement transfers move funds under the state PDA's | ||
| /// authority, so it must sign each of them. | ||
| /// | ||
| /// The signer only borrows its seed buffers, which are local to this frame; | ||
| /// running `f` here rather than returning the signer keeps them alive for as | ||
| /// long as `f` needs it. | ||
| fn with_state_pda_signer( | ||
| program_id: &Address, | ||
| state_pda_account: &AccountView, | ||
| f: impl FnOnce(&Signer) -> ProgramResult, | ||
| ) -> ProgramResult { | ||
| let (state_pda, state_bump) = Address::find_program_address(&state_pda_seeds(), program_id); | ||
| if state_pda_account.address() != &state_pda { | ||
| return Err(SettlementError::StateAccountMismatch.into()); | ||
| } | ||
|
Comment on lines
+74
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I liked this fn a lot. I believe after #49 it will use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, then there won't be any reason to run the search loop! |
||
|
|
||
| let state_bump = [state_bump]; | ||
| let signer_seeds = state_pda_signer_seeds(&state_bump).map(Seed::from); | ||
| f(&Signer::from(&signer_seeds)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing critical, but I this looks like a good spot to call
pinocchio_token::state::Account::from_account_view, which also validates the account data.I assume any invalid token account would still cause a revert during the transfer call anyway, so we'd just be catching the error earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed this function to stress that this validates only the token program address: bf1b683.
The
from_account_viewalready existed in the current code, so I implemented the suggestion by moving the check from the order processing to this function: 4192b1e.The price for this is that we go through all orders twice instead of only once, but maybe it isn't too bad.
I didn't include in the PR because I wasn't sure this is the change you intended. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I don't have a strong opinion about where the validation takes place.
Ideally we'd iterate only once, but I agree it's not a huge gain.