Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Anchor v0.26.0 upgrade (rebased) Special thanks @dovahcrow ! * anchor 0.26 solana 1.14.12 use mpl-token-metadata 1.7 because rust 1.60 does not compile 1.8 * initialize_pool: ignore passed bump and use one anchor derived - initialize_pool.test: update error codes, add a test case for ignoring bump * update expected error messages * add CHECK comments on UncheckedAccounts * use create_metadata_accounts_v3 (v2 have been deprecated) * update unit test cases (cargo test) ## Bundled Positions * import bundled positions * upgrade to Anchor v0.26.0 (position bundles related codes) - ProgramResult to Result<()> - add /// CHECK comments - remove space attribute on Mint account - change create_metadata_accounts_v2 to v3 - update testcases - Change in error code detected first - Change in account closing method coral-xyz/anchor#2169 * cargo fmt * update seed of BundledPosition * change temporary mint_authority to position_bundle * bump to v0.2.0 doc fields are added on IDL * fix: accidental failure test cases Fixed test cases that did not take into account rewards accruing up to just before the close. This test case is not related to bundled positions. The test case happened to fail, so I fixed them to make them all successful. --------- Co-authored-by: Weiyuan Wu <weiyuan@crows.land>
- Loading branch information
1 parent
d18229e
commit 44021b1
Showing
87 changed files
with
9,037 additions
and
570 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod nft; | ||
pub mod test_constants; | ||
|
||
pub use nft::*; | ||
pub use test_constants::*; |
This file contains 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,18 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
pub mod whirlpool_nft_update_auth { | ||
use super::*; | ||
declare_id!("3axbTs2z5GBy6usVbNVoqEgZMng3vZvMnAoX29BFfwhr"); | ||
} | ||
|
||
// METADATA_NAME : max 32 bytes | ||
// METADATA_SYMBOL : max 10 bytes | ||
// METADATA_URI : max 200 bytes | ||
pub const WP_METADATA_NAME: &str = "Orca Whirlpool Position"; | ||
pub const WP_METADATA_SYMBOL: &str = "OWP"; | ||
pub const WP_METADATA_URI: &str = "https://arweave.net/E19ZNY2sqMqddm1Wx7mrXPUZ0ZZ5ISizhebb0UsVEws"; | ||
|
||
pub const WPB_METADATA_NAME_PREFIX: &str = "Orca Position Bundle"; | ||
pub const WPB_METADATA_SYMBOL: &str = "OPB"; | ||
pub const WPB_METADATA_URI: &str = | ||
"https://arweave.net/A_Wo8dx2_3lSUwMIi7bdT_sqxi8soghRNAWXXiqXpgE"; |
This file contains 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
56 changes: 56 additions & 0 deletions
56
programs/whirlpool/src/instructions/close_bundled_position.rs
This file contains 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,56 @@ | ||
use anchor_lang::prelude::*; | ||
use anchor_spl::token::TokenAccount; | ||
|
||
use crate::errors::ErrorCode; | ||
use crate::{state::*, util::verify_position_bundle_authority}; | ||
|
||
#[derive(Accounts)] | ||
#[instruction(bundle_index: u16)] | ||
pub struct CloseBundledPosition<'info> { | ||
#[account(mut, | ||
close = receiver, | ||
seeds = [ | ||
b"bundled_position".as_ref(), | ||
position_bundle.position_bundle_mint.key().as_ref(), | ||
bundle_index.to_string().as_bytes() | ||
], | ||
bump, | ||
)] | ||
pub bundled_position: Account<'info, Position>, | ||
|
||
#[account(mut)] | ||
pub position_bundle: Box<Account<'info, PositionBundle>>, | ||
|
||
#[account( | ||
constraint = position_bundle_token_account.mint == bundled_position.position_mint, | ||
constraint = position_bundle_token_account.mint == position_bundle.position_bundle_mint, | ||
constraint = position_bundle_token_account.amount == 1 | ||
)] | ||
pub position_bundle_token_account: Box<Account<'info, TokenAccount>>, | ||
|
||
pub position_bundle_authority: Signer<'info>, | ||
|
||
/// CHECK: safe, for receiving rent only | ||
#[account(mut)] | ||
pub receiver: UncheckedAccount<'info>, | ||
} | ||
|
||
pub fn handler(ctx: Context<CloseBundledPosition>, bundle_index: u16) -> Result<()> { | ||
let position_bundle = &mut ctx.accounts.position_bundle; | ||
|
||
// Allow delegation | ||
verify_position_bundle_authority( | ||
&ctx.accounts.position_bundle_token_account, | ||
&ctx.accounts.position_bundle_authority, | ||
)?; | ||
|
||
if !Position::is_position_empty(&ctx.accounts.bundled_position) { | ||
return Err(ErrorCode::ClosePositionNotEmpty.into()); | ||
} | ||
|
||
position_bundle.close_bundled_position(bundle_index)?; | ||
|
||
// Anchor will close the Position account | ||
|
||
Ok(()) | ||
} |
This file contains 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 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 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 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 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
47 changes: 47 additions & 0 deletions
47
programs/whirlpool/src/instructions/delete_position_bundle.rs
This file contains 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,47 @@ | ||
use anchor_lang::prelude::*; | ||
use anchor_spl::token::{self, Mint, Token, TokenAccount}; | ||
|
||
use crate::errors::ErrorCode; | ||
use crate::state::*; | ||
use crate::util::burn_and_close_position_bundle_token; | ||
|
||
#[derive(Accounts)] | ||
pub struct DeletePositionBundle<'info> { | ||
#[account(mut, close = receiver)] | ||
pub position_bundle: Account<'info, PositionBundle>, | ||
|
||
#[account(mut, address = position_bundle.position_bundle_mint)] | ||
pub position_bundle_mint: Account<'info, Mint>, | ||
|
||
#[account(mut, | ||
constraint = position_bundle_token_account.mint == position_bundle.position_bundle_mint, | ||
constraint = position_bundle_token_account.owner == position_bundle_owner.key(), | ||
constraint = position_bundle_token_account.amount == 1, | ||
)] | ||
pub position_bundle_token_account: Box<Account<'info, TokenAccount>>, | ||
|
||
pub position_bundle_owner: Signer<'info>, | ||
|
||
/// CHECK: safe, for receiving rent only | ||
#[account(mut)] | ||
pub receiver: UncheckedAccount<'info>, | ||
|
||
#[account(address = token::ID)] | ||
pub token_program: Program<'info, Token>, | ||
} | ||
|
||
pub fn handler(ctx: Context<DeletePositionBundle>) -> Result<()> { | ||
let position_bundle = &ctx.accounts.position_bundle; | ||
|
||
if !position_bundle.is_deletable() { | ||
return Err(ErrorCode::PositionBundleNotDeletable.into()); | ||
} | ||
|
||
burn_and_close_position_bundle_token( | ||
&ctx.accounts.position_bundle_owner, | ||
&ctx.accounts.receiver, | ||
&ctx.accounts.position_bundle_mint, | ||
&ctx.accounts.position_bundle_token_account, | ||
&ctx.accounts.token_program, | ||
) | ||
} |
This file contains 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 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 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 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
63 changes: 63 additions & 0 deletions
63
programs/whirlpool/src/instructions/initialize_position_bundle.rs
This file contains 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,63 @@ | ||
use anchor_lang::prelude::*; | ||
use anchor_spl::associated_token::AssociatedToken; | ||
use anchor_spl::token::{self, Mint, Token, TokenAccount}; | ||
|
||
use crate::{state::*, util::mint_position_bundle_token_and_remove_authority}; | ||
|
||
#[derive(Accounts)] | ||
pub struct InitializePositionBundle<'info> { | ||
#[account(init, | ||
payer = funder, | ||
space = PositionBundle::LEN, | ||
seeds = [b"position_bundle".as_ref(), position_bundle_mint.key().as_ref()], | ||
bump, | ||
)] | ||
pub position_bundle: Box<Account<'info, PositionBundle>>, | ||
|
||
#[account(init, | ||
payer = funder, | ||
mint::authority = position_bundle, // will be removed in the transaction | ||
mint::decimals = 0, | ||
)] | ||
pub position_bundle_mint: Account<'info, Mint>, | ||
|
||
#[account(init, | ||
payer = funder, | ||
associated_token::mint = position_bundle_mint, | ||
associated_token::authority = position_bundle_owner, | ||
)] | ||
pub position_bundle_token_account: Box<Account<'info, TokenAccount>>, | ||
|
||
/// CHECK: safe, the account that will be the owner of the position bundle can be arbitrary | ||
pub position_bundle_owner: UncheckedAccount<'info>, | ||
|
||
#[account(mut)] | ||
pub funder: Signer<'info>, | ||
|
||
#[account(address = token::ID)] | ||
pub token_program: Program<'info, Token>, | ||
pub system_program: Program<'info, System>, | ||
pub rent: Sysvar<'info, Rent>, | ||
pub associated_token_program: Program<'info, AssociatedToken>, | ||
} | ||
|
||
pub fn handler(ctx: Context<InitializePositionBundle>) -> Result<()> { | ||
let position_bundle_mint = &ctx.accounts.position_bundle_mint; | ||
let position_bundle = &mut ctx.accounts.position_bundle; | ||
|
||
position_bundle.initialize(position_bundle_mint.key())?; | ||
|
||
let bump = *ctx.bumps.get("position_bundle").unwrap(); | ||
|
||
mint_position_bundle_token_and_remove_authority( | ||
&ctx.accounts.position_bundle, | ||
position_bundle_mint, | ||
&ctx.accounts.position_bundle_token_account, | ||
&ctx.accounts.token_program, | ||
&[ | ||
b"position_bundle".as_ref(), | ||
position_bundle_mint.key().as_ref(), | ||
&[bump], | ||
], | ||
) | ||
} |
Oops, something went wrong.