-
Notifications
You must be signed in to change notification settings - Fork 74
Add return_funds instruction to Launchpad v6
#387
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| use anchor_lang::prelude::*; | ||
| use anchor_spl::token::{self, Token, TokenAccount, Transfer}; | ||
|
|
||
| use crate::events::{CommonFields, LaunchFundsReturnedEvent}; | ||
| use crate::state::Launch; | ||
|
|
||
| pub mod admin { | ||
| use anchor_lang::prelude::declare_id; | ||
|
|
||
| // MetaDAO multisig vault | ||
| declare_id!("6awyHMshBGVjJ3ozdSJdyyDE1CTAXUwrpNMaRGMsb4sf"); | ||
| } | ||
|
|
||
| #[derive(AnchorSerialize, AnchorDeserialize, Clone)] | ||
| pub struct ReturnFundsArgs { | ||
| pub amount: u64, | ||
| } | ||
|
|
||
| #[event_cpi] | ||
| #[derive(Accounts)] | ||
| pub struct ReturnFunds<'info> { | ||
| pub admin: Signer<'info>, | ||
|
|
||
| #[account( | ||
| mut, | ||
| has_one = launch_quote_vault, | ||
| has_one = launch_signer, | ||
| )] | ||
| pub launch: Account<'info, Launch>, | ||
|
|
||
| #[account(mut)] | ||
| pub launch_quote_vault: Account<'info, TokenAccount>, | ||
|
|
||
| /// CHECK: This is the launch signer | ||
| #[account( | ||
| seeds = [b"launch_signer", launch.key().as_ref()], | ||
| bump | ||
| )] | ||
| pub launch_signer: UncheckedAccount<'info>, | ||
|
|
||
| /// CHECK: not used, just for constraints | ||
| pub recipient: UncheckedAccount<'info>, | ||
|
|
||
| #[account(mut, associated_token::mint = launch.quote_mint, associated_token::authority = recipient)] | ||
| pub recipient_quote_account: Account<'info, TokenAccount>, | ||
|
|
||
| pub token_program: Program<'info, Token>, | ||
| pub system_program: Program<'info, System>, | ||
| } | ||
|
|
||
| impl ReturnFunds<'_> { | ||
| pub fn validate(&self) -> Result<()> { | ||
| #[cfg(feature = "production")] | ||
| require_keys_eq!(self.admin.key(), admin::ID, LaunchpadError::InvalidAdmin); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn handle(ctx: Context<Self>, args: ReturnFundsArgs) -> Result<()> { | ||
| let launch = &mut ctx.accounts.launch; | ||
| let launch_key = launch.key(); | ||
|
|
||
| let seeds = &[ | ||
| b"launch_signer", | ||
| launch_key.as_ref(), | ||
| &[launch.launch_signer_pda_bump], | ||
| ]; | ||
| let signer = &[&seeds[..]]; | ||
|
|
||
| // Transfer USDC back to the recipient | ||
| token::transfer( | ||
| CpiContext::new_with_signer( | ||
| ctx.accounts.token_program.to_account_info(), | ||
| Transfer { | ||
| from: ctx.accounts.launch_quote_vault.to_account_info(), | ||
| to: ctx.accounts.recipient_quote_account.to_account_info(), | ||
| authority: ctx.accounts.launch_signer.to_account_info(), | ||
| }, | ||
| signer, | ||
| ), | ||
| args.amount, | ||
| )?; | ||
|
|
||
| launch.seq_num += 1; | ||
|
|
||
| let clock = Clock::get()?; | ||
| emit_cpi!(LaunchFundsReturnedEvent { | ||
| common: CommonFields::new(&clock, launch.seq_num), | ||
| launch: ctx.accounts.launch.key(), | ||
| recipient: ctx.accounts.recipient.key(), | ||
| usdc_returned: args.amount, | ||
| }); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
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.