mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-05-18 23:19:30 +00:00
- Updated `nssa_core` and `spel-framework` dependencies to their respective release candidates in `Cargo.toml` and `Cargo.lock` files for `amm`, `ata`, and `token` modules. - Enhanced the `new_definition` function in `amm/src/new_definition.rs` to include new claim logic and updated PDA seed calculations. - Modified tests in `integration_tests/tests/amm.rs`, `integration_tests/tests/ata.rs`, and `integration_tests/tests/token.rs` to accommodate changes in transaction handling and account initialization. - Refactored account initialization logic in `ata/src/create.rs` and `token/src/initialize.rs` to include authorization claims. - Updated various functions in `token/src/mint.rs`, `token/src/new_definition.rs`, and `token/src/transfer.rs` to utilize the new claim system for account states. - Adjusted the IDL generation tool to use the latest version of `spel-framework-core`.
51 lines
1.9 KiB
Rust
51 lines
1.9 KiB
Rust
use nssa_core::{
|
|
account::{Account, AccountWithMetadata},
|
|
program::{AccountPostState, ChainedCall, Claim, ProgramId},
|
|
};
|
|
|
|
pub fn create_associated_token_account(
|
|
owner: AccountWithMetadata,
|
|
token_definition: AccountWithMetadata,
|
|
ata_account: AccountWithMetadata,
|
|
ata_program_id: ProgramId,
|
|
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
|
|
// No explicit owner authorization check is needed here: ATA creation is idempotent, so the
|
|
// call itself may proceed without `owner.is_authorized`. If the owner account is still
|
|
// default, the returned post-state will still carry `Claim::Authorized` so the runtime can
|
|
// claim that owner account when needed.
|
|
let token_program_id = token_definition.account.program_owner;
|
|
let seed = ata_core::verify_ata_and_get_seed(
|
|
&ata_account,
|
|
&owner,
|
|
token_definition.account_id,
|
|
ata_program_id,
|
|
);
|
|
|
|
// Idempotent: already initialized → no-op
|
|
if ata_account.account != Account::default() {
|
|
return (
|
|
vec![
|
|
AccountPostState::new_claimed_if_default(owner.account.clone(), Claim::Authorized),
|
|
AccountPostState::new(token_definition.account.clone()),
|
|
AccountPostState::new(ata_account.account.clone()),
|
|
],
|
|
vec![],
|
|
);
|
|
}
|
|
|
|
let post_states = vec![
|
|
AccountPostState::new_claimed_if_default(owner.account.clone(), Claim::Authorized),
|
|
AccountPostState::new(token_definition.account.clone()),
|
|
AccountPostState::new(ata_account.account.clone()),
|
|
];
|
|
let mut ata_account_auth = ata_account.clone();
|
|
ata_account_auth.is_authorized = true;
|
|
let chained_call = ChainedCall::new(
|
|
token_program_id,
|
|
vec![token_definition.clone(), ata_account_auth],
|
|
&token_core::Instruction::InitializeAccount,
|
|
)
|
|
.with_pda_seeds(vec![seed]);
|
|
(post_states, vec![chained_call])
|
|
}
|