Repository navigation
Add WithdrawNativeSol instruction #198
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e7b0234
Add WithdrawNativeSol instruction
kaze-cow 82ce021
Merge remote-tracking branch 'origin/main' into kaze/sc-403-withdraw-…
kaze-cow d2d98b0
Destructure in tests
fedgiac 63d4152
Explicit amount
fedgiac 7bebf9e
Remove expected array
fedgiac b22dfd0
More generic comment
fedgiac e331010
Identifiably useless number
fedgiac e9de108
funded -> native_token_balance
fedgiac 1e6b0f7
Test arbitrary non-authority, not all invalid authorities
fedgiac 773c557
Test withdrawing more than expected
fedgiac 250b83a
Cap `WithdrawNativeSol` to full balance minus rent (#199)
fedgiac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| //! Builder for the `WithdrawNativeSol` instruction. | ||
|
|
||
| use cow_settlement_interface::{ | ||
| pda::{buffer::find_native_sol_buffer_pda, state::find_state_pda}, | ||
| Instruction, Pubkey, | ||
| }; | ||
|
|
||
| /// Moves `amount` lamports out of the native SOL buffer to `recipient`. | ||
| /// Authorized by `authority`, the settlement-owned-order authority, which picks | ||
| /// `recipient` freely and may set it to itself. | ||
| pub struct WithdrawNativeSol { | ||
| pub program_id: Pubkey, | ||
| pub authority: Pubkey, | ||
| pub recipient: Pubkey, | ||
| pub amount: u64, | ||
| } | ||
|
|
||
| impl From<WithdrawNativeSol> for Instruction { | ||
| fn from(builder: WithdrawNativeSol) -> Self { | ||
| cow_settlement_interface::instruction::withdraw_native_sol::WithdrawNativeSol { | ||
| program_id: builder.program_id, | ||
| state_pda: find_state_pda(&builder.program_id).0, | ||
| authority: builder.authority, | ||
| native_sol_buffer: find_native_sol_buffer_pda(&builder.program_id).0, | ||
| recipient: builder.recipient, | ||
| amount: builder.amount, | ||
| } | ||
| .into() | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,12 +147,19 @@ pub enum SettlementError { | |
| /// buffer the push draws from, so settling it would move no funds yet still | ||
| /// record the declared amount as received. | ||
| PushSourceIsDestination = 44, | ||
| /// `FinalizeSettle`: the native SOL payouts would empty the native SOL | ||
| /// buffer, which the runtime would then delete. | ||
| /// Moving lamports out of the native SOL buffer would empty it, which the | ||
| /// runtime would then delete. | ||
| NativeSolBufferEmptied = 45, | ||
| /// A buffer to be reclaimed holds more tokens than the burn limit supplied | ||
| /// for it, so its balance can't be cleared for closing. | ||
| ReclaimBufferBurnLimitExceeded = 46, | ||
| /// `WithdrawNativeSol`'s authority account isn't a signer, or doesn't | ||
| /// match the `settlement_owned_order_authority` recorded in the settlement | ||
| /// state PDA. | ||
| UnauthorizedNativeSolWithdrawal = 47, | ||
| /// `WithdrawNativeSol`'s native SOL buffer account isn't the canonical | ||
| /// native SOL buffer PDA. | ||
| NativeSolBufferMismatch = 48, | ||
|
Comment on lines
+156
to
+162
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. Not in this PR, and not before the audit, but we should really clean up all our errors. |
||
| } | ||
|
|
||
| impl From<SettlementError> for u32 { | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.