-
Notifications
You must be signed in to change notification settings - Fork 26
Feat: native SPL support #738
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
Open
GabrielePicco
wants to merge
8
commits into
master
Choose a base branch
from
feat/clone-eata
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bea8bfe
feat: clone eata into ata
GabrielePicco 595df48
fix: set delegated on ata manifacturing
GabrielePicco fe55cac
feat: map on commit/undelegation
GabrielePicco 00d6f19
Merge branch 'master' into feat/clone-eata
GabrielePicco ea3ab55
chore: refactor
GabrielePicco 29f678b
chore: refactor
GabrielePicco 235b4a6
chore: refactor
GabrielePicco 7ee8a1f
chore: refactor
GabrielePicco 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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,58 @@ | ||
| pub use magicblock_core::token_programs::{ | ||
| derive_ata, derive_eata, EphemeralAta, EATA_PROGRAM_ID, | ||
| SPL_TOKEN_PROGRAM_ID, | ||
| }; | ||
| use solana_account::Account; | ||
| use solana_program::{program_option::COption, program_pack::Pack}; | ||
| use solana_pubkey::Pubkey; | ||
| use solana_sdk::rent::Rent; | ||
| use spl_token::state::{Account as SplAccount, AccountState}; | ||
|
|
||
| pub fn create_ata_account(owner: &Pubkey, mint: &Pubkey) -> Account { | ||
| let token_account = SplAccount { | ||
| mint: *mint, | ||
| owner: *owner, | ||
| amount: 0, | ||
| delegate: COption::None, | ||
| state: AccountState::Initialized, | ||
| is_native: COption::None, | ||
| delegated_amount: 0, | ||
| close_authority: COption::None, | ||
| }; | ||
|
|
||
| let mut data = vec![0u8; SplAccount::LEN]; | ||
| SplAccount::pack(token_account, &mut data).expect("pack spl token account"); | ||
| let lamports = Rent::default().minimum_balance(data.len()); | ||
|
|
||
| Account { | ||
| owner: SPL_TOKEN_PROGRAM_ID, | ||
| data, | ||
| lamports, | ||
| executable: false, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| pub fn create_eata_account( | ||
| owner: &Pubkey, | ||
| mint: &Pubkey, | ||
| amount: u64, | ||
| delegate: bool, | ||
| ) -> Account { | ||
| let mut data = Vec::with_capacity(64 + 8); | ||
| data.extend_from_slice(owner.as_ref()); | ||
| data.extend_from_slice(mint.as_ref()); | ||
| data.extend_from_slice(&amount.to_le_bytes()); | ||
| let lamports = Rent::default().minimum_balance(data.len()); | ||
|
|
||
| let owner = if delegate { dlp::ID } else { EATA_PROGRAM_ID }; | ||
|
|
||
| Account { | ||
| owner, | ||
| data, | ||
| lamports, | ||
| ..Default::default() | ||
| } | ||
| } | ||
|
|
||
| // Reuse EphemeralAta definition from magicblock_core::token_programs | ||
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 |
|---|---|---|
|
|
@@ -15,4 +15,5 @@ macro_rules! debug_panic { | |
|
|
||
| pub mod link; | ||
| pub mod tls; | ||
| pub mod token_programs; | ||
| pub mod traits; | ||
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.
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.
🧹 Nitpick | 🔵 Trivial
Variable shadowing reduces readability.
The
ownerparameter (line 37) is shadowed by the localownerbinding (line 48), which can confuse readers about whichowneris used in theAccountconstruction.📝 Committable suggestion
🤖 Prompt for AI Agents