mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-05-19 07:29:32 +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`.
72 lines
2.3 KiB
Rust
72 lines
2.3 KiB
Rust
use nssa_core::{
|
|
account::{Account, AccountWithMetadata, Data},
|
|
program::{AccountPostState, Claim},
|
|
};
|
|
use token_core::{TokenDefinition, TokenHolding};
|
|
|
|
pub fn mint(
|
|
definition_account: AccountWithMetadata,
|
|
user_holding_account: AccountWithMetadata,
|
|
amount_to_mint: u128,
|
|
) -> Vec<AccountPostState> {
|
|
assert!(
|
|
definition_account.is_authorized,
|
|
"Definition authorization is missing"
|
|
);
|
|
|
|
let mut definition = TokenDefinition::try_from(&definition_account.account.data)
|
|
.expect("Token Definition account must be valid");
|
|
let mut holding = if user_holding_account.account == Account::default() {
|
|
TokenHolding::zeroized_from_definition(definition_account.account_id, &definition)
|
|
} else {
|
|
TokenHolding::try_from(&user_holding_account.account.data)
|
|
.expect("Token Holding account must be valid")
|
|
};
|
|
|
|
assert_eq!(
|
|
definition_account.account_id,
|
|
holding.definition_id(),
|
|
"Mismatch Token Definition and Token Holding"
|
|
);
|
|
|
|
match (&mut definition, &mut holding) {
|
|
(
|
|
TokenDefinition::Fungible {
|
|
name: _,
|
|
metadata_id: _,
|
|
total_supply,
|
|
},
|
|
TokenHolding::Fungible {
|
|
definition_id: _,
|
|
balance,
|
|
},
|
|
) => {
|
|
*balance = balance
|
|
.checked_add(amount_to_mint)
|
|
.expect("Balance overflow on minting");
|
|
|
|
*total_supply = total_supply
|
|
.checked_add(amount_to_mint)
|
|
.expect("Total supply overflow");
|
|
}
|
|
(
|
|
TokenDefinition::NonFungible { .. },
|
|
TokenHolding::NftMaster { .. } | TokenHolding::NftPrintedCopy { .. },
|
|
) => {
|
|
panic!("Cannot mint additional supply for Non-Fungible Tokens");
|
|
}
|
|
_ => panic!("Mismatched Token Definition and Token Holding types"),
|
|
}
|
|
|
|
let mut definition_post = definition_account.account;
|
|
definition_post.data = Data::from(&definition);
|
|
|
|
let mut holding_post = user_holding_account.account;
|
|
holding_post.data = Data::from(&holding);
|
|
|
|
vec![
|
|
AccountPostState::new(definition_post),
|
|
AccountPostState::new_claimed_if_default(holding_post, Claim::Authorized),
|
|
]
|
|
}
|