Skip to content
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

I fixed my own dumbass issue sending 1.5sols to fanout instead hodlin… #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions programs/hydra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ pub mod hydra {
add_member_wallet(ctx, args)
}

pub fn process_transfer_to_hodling(
ctx: Context<TransferToHodling>,
args: TransferToArgs,
) -> Result<()> {
transfer_to_hodling(ctx, args)
}

pub fn process_add_member_nft(
ctx: Context<AddMemberWithNFT>,
args: AddMemberArgs,
Expand Down
2 changes: 2 additions & 0 deletions programs/hydra/src/processors/init/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod init_for_mint;
pub mod init_parent;
pub mod transfer_to_hodling;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strongly dislike this name for a instruction in publicly available smart contract 😬

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gm haha :) my PRs are always suggestions, some are lulzy && for the culture - this trend continues :) in a newer one I've used 'inverse_bruh' as a variable, much to @ChewingGlass dismay - and in one a long time ago @austbot had to rewrite most of my output to the CLI in favor of 'consider supporting free & open source developers'

I trust the maintainers to make calls about what's culture and what's better without the lulz


42 changes: 42 additions & 0 deletions programs/hydra/src/processors/init/transfer_to_hodling.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use crate::error::{OrArithError};
use crate::state::{Fanout};
use anchor_lang::prelude::*;

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
pub struct TransferToArgs {
pub bump_seed: u8,
pub native_account_bump_seed: u8,
}

#[derive(Accounts)]
#[instruction(args: TransferToArgs)]
pub struct TransferToHodling<'info> {
#[account(
mut,
seeds = [b"fanout-config", fanout.name.as_bytes()],
bump = fanout.bump_seed,
)]
pub fanout: Box<Account<'info, Fanout>>,
#[account(mut)]
/// CHECK: Could be native or Token Account
pub holding_account: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
pub rent: Sysvar<'info, Rent>,
}
pub fn transfer_to_hodling(
ctx: Context<TransferToHodling>,
_args: TransferToArgs
) -> Result<()> {
let fanout = &mut ctx.accounts.fanout.to_account_info();
let hodling = ctx.accounts.holding_account.to_account_info();
let snapshot: u64 = fanout.lamports();

**fanout.lamports.borrow_mut() = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to drop the fanout to below rent-exempt minimum?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaik from my previous work with candy machine refunds it will empty the thing and solana conveniently kicks it out (can't afford rent).

It's ? a weird process?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh - good point - we don't want to destroy the fanout in this particular case.

There's a function somewhere for RENT_EXEMPT_MINIMUM or w/e?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/cardinal-labs/cardinal-token-manager/blob/3825e0eb70007a2b1e263dedeaf02b693c9614b7/programs/cardinal-token-manager/src/instructions/invalidate.rs#L199-L205

            let required_lamports = ctx.accounts.rent.minimum_balance(token_manager.to_account_info().data_len());
            let token_manager_lamports = token_manager.to_account_info().lamports();
            if token_manager_lamports > required_lamports {
                let diff = token_manager_lamports.checked_sub(required_lamports).expect("Sub error");
                **token_manager.to_account_info().try_borrow_mut_lamports()? = required_lamports;
                **ctx.accounts.collector.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.collector.to_account_info().lamports().checked_add(diff).expect("Add error");
            };

this example gets rent minimum and removes any extra lamports above that


**hodling.lamports.borrow_mut() = hodling
.lamports()
.checked_add(snapshot)
.or_arith_error()?;

Ok(())
}
1 change: 1 addition & 0 deletions programs/hydra/src/processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub use self::distribute::token_member::*;
pub use self::distribute::wallet_member::*;
pub use self::init::init_for_mint::*;
pub use self::init::init_parent::*;
pub use self::init::transfer_to_hodling::*;
pub use self::remove_member::remove_member::*;
pub use self::signing::sign_metadata::*;
pub use self::stake::set::*;
Expand Down