Skip to content

Commit 69d6179

Browse files
authored
Fixed dependency issues. Simplified attach. Cargo fmt (#400)
1 parent 911ecb7 commit 69d6179

File tree

21 files changed

+196
-351
lines changed

21 files changed

+196
-351
lines changed

tokens/token-2022/transfer-hook/allow-block-list-token/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ yarn-error.log*
4141
next-env.d.ts
4242

4343
# Anchor
44-
/anchor/target/
44+
/anchor/target/

tokens/token-2022/transfer-hook/allow-block-list-token/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The allow/block list is then consumed by a transfer-hook.
99

1010
The list is managed by a single authority and can be used by several token mints. This enables a separation of concerns between token management and allow/block list management, ideal for scenarios where an issuer wants a 3rd party managed allow/block list or wants to share the same list across a group of assets.
1111

12+
1213
Initializes new tokens with several configuration options:
1314
- Permanent delegate
1415
- Allow list
@@ -30,7 +31,7 @@ This repo includes a UI to manage the allow/block list based on the `legacy-next
3031
Install dependencies:
3132
`yarn install`
3233

33-
Compile the program:
34+
Compile the program (make sure to replace your program ID):
3435
`anchor build`
3536

3637
Compile the UI:
@@ -43,8 +44,8 @@ Serve the UI:
4344

4445
There are a couple scripts to manage the local validator and deployment.
4546

46-
To start the local validator and deploy the program:
47+
To start the local validator and deploy the program (uses the anchor CLI and default anchor keypair):
4748
`./scripts/start.sh`
4849

4950
To stop the local validator:
50-
`./scripts/stop.sh`
51+
`./scripts/stop.sh`

tokens/token-2022/transfer-hook/allow-block-list-token/anchor/Anchor.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ resolution = true
66
skip-lint = false
77

88
[programs.localnet]
9-
abl-token = "LtkoMwPSKxAE714EY3V1oAEQ5LciqJcRwQQuQnzEhQQ"
9+
abl-token = "EYBRvArz4kb5YLtzjD4TW6DbWhS8qjcMYqBU4wHLW3qj"
1010

1111
[registry]
1212
url = "https://api.apr.dev"
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
pub const META_LIST_ACCOUNT_SEED: &[u8] = b"extra-account-metas";
32
pub const CONFIG_SEED: &[u8] = b"config";
4-
pub const AB_WALLET_SEED: &[u8] = b"ab_wallet";
3+
pub const AB_WALLET_SEED: &[u8] = b"ab_wallet";

tokens/token-2022/transfer-hook/allow-block-list-token/anchor/programs/abl-token/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pub enum ABListError {
1313

1414
#[msg("Wallet blocked")]
1515
WalletBlocked,
16-
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
use anchor_lang::{prelude::*, solana_program::program::invoke, solana_program::system_instruction::transfer};
1+
use anchor_lang::prelude::*;
22
use anchor_spl::{
3-
token_2022::{spl_token_2022::{extension::{BaseStateWithExtensions, StateWithExtensions}, state::Mint as Mint2022}, Token2022},
4-
token_interface::{spl_token_metadata_interface::state::{Field, TokenMetadata}, token_metadata_initialize, token_metadata_update_field, Mint, TokenMetadataInitialize, TokenMetadataUpdateField},
3+
token_2022::Token2022,
4+
token_interface::{transfer_hook_update, Mint, TransferHookUpdate},
55
};
66

7-
use spl_tlv_account_resolution::{
8-
state::ExtraAccountMetaList,
9-
};
7+
use spl_tlv_account_resolution::state::ExtraAccountMetaList;
108
use spl_transfer_hook_interface::instruction::ExecuteInstruction;
119

12-
use crate::{Mode, META_LIST_ACCOUNT_SEED, get_extra_account_metas, get_meta_list_size};
13-
10+
use crate::{get_extra_account_metas, get_meta_list_size, META_LIST_ACCOUNT_SEED};
1411

1512
#[derive(Accounts)]
16-
#[instruction(args: AttachToMintArgs)]
1713
pub struct AttachToMint<'info> {
1814
#[account(mut)]
1915
pub payer: Signer<'info>,
2016

21-
pub mint_authority: Signer<'info>,
22-
23-
pub metadata_authority: Signer<'info>,
24-
2517
#[account(
2618
mut,
2719
mint::token_program = token_program,
@@ -44,78 +36,16 @@ pub struct AttachToMint<'info> {
4436
}
4537

4638
impl AttachToMint<'_> {
47-
pub fn attach_to_mint(&mut self, args: AttachToMintArgs) -> Result<()> {
48-
let mint_info = self.mint.to_account_info();
49-
let mint_data = mint_info.data.borrow();
50-
let mint = StateWithExtensions::<Mint2022>::unpack(&mint_data)?;
51-
52-
let metadata = mint.get_variable_len_extension::<TokenMetadata>();
53-
54-
if metadata.is_err() {
55-
// assume metadata is not initialized, so we need to initialize it
56-
57-
let cpi_accounts = TokenMetadataInitialize {
58-
program_id: self.token_program.to_account_info(),
59-
mint: self.mint.to_account_info(),
60-
metadata: self.mint.to_account_info(), // metadata account is the mint, since data is stored in mint
61-
mint_authority: self.mint_authority.to_account_info(),
62-
update_authority: self.metadata_authority.to_account_info(),
63-
};
64-
let cpi_ctx = CpiContext::new(
65-
self.token_program.to_account_info(),
66-
cpi_accounts,
67-
);
68-
token_metadata_initialize(cpi_ctx, args.name.unwrap(), args.symbol.unwrap(), args.uri.unwrap())?;
69-
}
70-
71-
let cpi_accounts = TokenMetadataUpdateField {
72-
metadata: self.mint.to_account_info(),
73-
update_authority: self.metadata_authority.to_account_info(),
74-
program_id: self.token_program.to_account_info(),
39+
pub fn attach_to_mint(&mut self) -> Result<()> {
40+
let tx_hook_accs = TransferHookUpdate {
41+
token_program_id: self.token_program.to_account_info(),
42+
mint: self.mint.to_account_info(),
43+
authority: self.payer.to_account_info(),
7544
};
7645

77-
let cpi_ctx = CpiContext::new(
78-
self.token_program.to_account_info(),
79-
cpi_accounts,
80-
);
46+
let ctx = CpiContext::new(self.token_program.to_account_info(), tx_hook_accs);
8147

82-
token_metadata_update_field(cpi_ctx, Field::Key("AB".to_string()), args.mode.to_string())?;
83-
84-
if args.mode == Mode::Mixed {
85-
let cpi_accounts = TokenMetadataUpdateField {
86-
metadata: self.mint.to_account_info(),
87-
update_authority: self.metadata_authority.to_account_info(),
88-
program_id: self.token_program.to_account_info(),
89-
};
90-
let cpi_ctx = CpiContext::new(
91-
self.token_program.to_account_info(),
92-
cpi_accounts,
93-
);
94-
95-
token_metadata_update_field(
96-
cpi_ctx,
97-
Field::Key("threshold".to_string()),
98-
args.threshold.to_string(),
99-
)?;
100-
}
101-
102-
103-
let data = self.mint.to_account_info().data_len();
104-
let min_balance = Rent::get()?.minimum_balance(data);
105-
if min_balance > self.mint.to_account_info().get_lamports() {
106-
invoke(
107-
&transfer(
108-
&self.payer.key(),
109-
&self.mint.to_account_info().key(),
110-
min_balance - self.mint.to_account_info().get_lamports(),
111-
),
112-
&[
113-
self.payer.to_account_info(),
114-
self.mint.to_account_info(),
115-
self.system_program.to_account_info(),
116-
],
117-
)?;
118-
}
48+
transfer_hook_update(ctx, Some(crate::ID_CONST))?;
11949

12050
// initialize the extra metas account
12151
let extra_metas_account = &self.extra_metas_account;
@@ -124,16 +54,5 @@ impl AttachToMint<'_> {
12454
ExtraAccountMetaList::init::<ExecuteInstruction>(&mut data, &metas)?;
12555

12656
Ok(())
127-
12857
}
12958
}
130-
131-
#[derive(AnchorSerialize, AnchorDeserialize)]
132-
pub struct AttachToMintArgs {
133-
pub name: Option<String>,
134-
pub symbol: Option<String>,
135-
pub uri: Option<String>,
136-
pub mode: Mode,
137-
pub threshold: u64,
138-
}
139-

tokens/token-2022/transfer-hook/allow-block-list-token/anchor/programs/abl-token/src/instructions/change_mode.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
use anchor_lang::{prelude::*, solana_program::system_instruction::transfer };
21
use anchor_lang::solana_program::program::invoke;
2+
use anchor_lang::{prelude::*, solana_program::system_instruction::transfer};
33
use anchor_spl::token_interface::spl_token_metadata_interface::state::TokenMetadata;
44
use anchor_spl::{
55
token_2022::{
66
spl_token_2022::extension::{BaseStateWithExtensions, StateWithExtensions},
77
spl_token_2022::state::Mint,
88
Token2022,
9-
109
},
1110
token_interface::{
12-
Mint as MintAccount,
1311
spl_token_metadata_interface::state::Field, token_metadata_update_field,
14-
TokenMetadataUpdateField,
12+
Mint as MintAccount, TokenMetadataUpdateField,
1513
},
1614
};
1715

@@ -21,7 +19,7 @@ use crate::Mode;
2119
pub struct ChangeMode<'info> {
2220
#[account(mut)]
2321
pub authority: Signer<'info>,
24-
22+
2523
#[account(
2624
mut,
2725
mint::token_program = token_program,
@@ -73,8 +71,6 @@ impl ChangeMode<'_> {
7371
)?;
7472
}
7573

76-
77-
7874
let data = self.mint.to_account_info().data_len();
7975
let min_balance = Rent::get()?.minimum_balance(data);
8076
if min_balance > self.mint.to_account_info().get_lamports() {

tokens/token-2022/transfer-hook/allow-block-list-token/anchor/programs/abl-token/src/instructions/init_config.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use anchor_lang::prelude::*;
21
use crate::{Config, CONFIG_SEED};
3-
2+
use anchor_lang::prelude::*;
43

54
#[derive(Accounts)]
65
pub struct InitConfig<'info> {
@@ -21,7 +20,6 @@ pub struct InitConfig<'info> {
2120

2221
impl InitConfig<'_> {
2322
pub fn init_config(&mut self, config_bump: u8) -> Result<()> {
24-
2523
self.config.set_inner(Config {
2624
authority: self.payer.key(),
2725
bump: config_bump,

tokens/token-2022/transfer-hook/allow-block-list-token/anchor/programs/abl-token/src/instructions/init_mint.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ use anchor_spl::{
99
},
1010
};
1111

12-
use spl_tlv_account_resolution::
13-
state::ExtraAccountMetaList
14-
;
12+
use spl_tlv_account_resolution::state::ExtraAccountMetaList;
1513
use spl_transfer_hook_interface::instruction::ExecuteInstruction;
1614

1715
use crate::{get_extra_account_metas, get_meta_list_size, Mode, META_LIST_ACCOUNT_SEED};
1816

19-
2017
#[derive(Accounts)]
2118
#[instruction(args: InitMintArgs)]
2219
pub struct InitMint<'info> {
@@ -62,10 +59,7 @@ impl InitMint<'_> {
6259
mint_authority: self.payer.to_account_info(),
6360
update_authority: self.payer.to_account_info(),
6461
};
65-
let cpi_ctx = CpiContext::new(
66-
self.token_program.to_account_info(),
67-
cpi_accounts,
68-
);
62+
let cpi_ctx = CpiContext::new(self.token_program.to_account_info(), cpi_accounts);
6963
token_metadata_initialize(cpi_ctx, args.name, args.symbol, args.uri)?;
7064

7165
let cpi_accounts = TokenMetadataUpdateField {
@@ -74,10 +68,7 @@ impl InitMint<'_> {
7468
program_id: self.token_program.to_account_info(),
7569
};
7670

77-
let cpi_ctx = CpiContext::new(
78-
self.token_program.to_account_info(),
79-
cpi_accounts,
80-
);
71+
let cpi_ctx = CpiContext::new(self.token_program.to_account_info(), cpi_accounts);
8172

8273
token_metadata_update_field(cpi_ctx, Field::Key("AB".to_string()), args.mode.to_string())?;
8374

@@ -87,10 +78,7 @@ impl InitMint<'_> {
8778
update_authority: self.payer.to_account_info(),
8879
program_id: self.token_program.to_account_info(),
8980
};
90-
let cpi_ctx = CpiContext::new(
91-
self.token_program.to_account_info(),
92-
cpi_accounts,
93-
);
81+
let cpi_ctx = CpiContext::new(self.token_program.to_account_info(), cpi_accounts);
9482

9583
token_metadata_update_field(
9684
cpi_ctx,
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1+
pub mod attach_to_mint;
2+
pub mod change_mode;
3+
pub mod init_config;
14
pub mod init_mint;
25
pub mod init_wallet;
3-
pub mod tx_hook;
46
pub mod remove_wallet;
5-
pub mod change_mode;
6-
pub mod init_config;
7-
pub mod attach_to_mint;
7+
pub mod tx_hook;
88

9+
pub use attach_to_mint::*;
10+
pub use change_mode::*;
11+
pub use init_config::*;
912
pub use init_mint::*;
1013
pub use init_wallet::*;
11-
pub use tx_hook::*;
1214
pub use remove_wallet::*;
13-
pub use change_mode::*;
14-
pub use init_config::*;
15-
pub use attach_to_mint::*;
16-
15+
pub use tx_hook::*;

0 commit comments

Comments
 (0)