Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 80b62da

Browse files
author
Joe C
authored
token 2022 & transfer hook: drop deprecated helpers (#6122)
* token 2022 & transfer hook: drop deprecated helpers * token js: drop deprecated helper
1 parent 14db758 commit 80b62da

File tree

4 files changed

+0
-212
lines changed

4 files changed

+0
-212
lines changed

token/js/src/extensions/transferHook/instructions.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -136,62 +136,6 @@ function deEscalateAccountMeta(accountMeta: AccountMeta, accountMetas: AccountMe
136136
return accountMeta;
137137
}
138138

139-
/**
140-
* @deprecated Deprecated since v0.3.12. Please use {@link addExtraAccountMetasForExecute} instead.
141-
*
142-
* Add extra accounts needed for transfer hook to an instruction
143-
*
144-
* @param connection Connection to use
145-
* @param instruction The transferChecked instruction to add accounts to
146-
* @param commitment Commitment to use
147-
* @param programId SPL Token program account
148-
*
149-
* @return Instruction to add to a transaction
150-
*/
151-
export async function addExtraAccountsToInstruction(
152-
connection: Connection,
153-
instruction: TransactionInstruction,
154-
mint: PublicKey,
155-
commitment?: Commitment,
156-
programId = TOKEN_PROGRAM_ID
157-
): Promise<TransactionInstruction> {
158-
if (!programSupportsExtensions(programId)) {
159-
throw new TokenUnsupportedInstructionError();
160-
}
161-
162-
const mintInfo = await getMint(connection, mint, commitment, programId);
163-
const transferHook = getTransferHook(mintInfo);
164-
if (transferHook == null) {
165-
return instruction;
166-
}
167-
168-
const extraAccountsAccount = getExtraAccountMetaAddress(mint, transferHook.programId);
169-
const extraAccountsInfo = await connection.getAccountInfo(extraAccountsAccount, commitment);
170-
if (extraAccountsInfo == null) {
171-
return instruction;
172-
}
173-
174-
const extraAccountMetas = getExtraAccountMetas(extraAccountsInfo);
175-
176-
const accountMetas = instruction.keys;
177-
178-
for (const extraAccountMeta of extraAccountMetas) {
179-
const accountMetaUnchecked = await resolveExtraAccountMeta(
180-
connection,
181-
extraAccountMeta,
182-
accountMetas,
183-
instruction.data,
184-
transferHook.programId
185-
);
186-
const accountMeta = deEscalateAccountMeta(accountMetaUnchecked, accountMetas);
187-
accountMetas.push(accountMeta);
188-
}
189-
accountMetas.push({ pubkey: transferHook.programId, isSigner: false, isWritable: false });
190-
accountMetas.push({ pubkey: extraAccountsAccount, isSigner: false, isWritable: false });
191-
192-
return new TransactionInstruction({ keys: accountMetas, programId, data: instruction.data });
193-
}
194-
195139
/**
196140
* Construct an `ExecuteInstruction` for a transfer hook program, without the
197141
* additional accounts

token/program-2022/src/offchain.rs

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,6 @@ use {
1111
std::future::Future,
1212
};
1313

14-
/// Offchain helper to get all additional required account metas for a checked
15-
/// transfer
16-
///
17-
/// To be client-agnostic and to avoid pulling in the full solana-sdk, this
18-
/// simply takes a function that will return its data as `Future<Vec<u8>>` for
19-
/// the given address. Can be called in the following way:
20-
///
21-
/// ```rust,ignore
22-
/// use futures_util::TryFutureExt;
23-
/// use solana_client::nonblocking::rpc_client::RpcClient;
24-
/// use solana_program::pubkey::Pubkey;
25-
///
26-
/// let mint = Pubkey::new_unique();
27-
/// let client = RpcClient::new_mock("succeeds".to_string());
28-
/// let mut account_metas = vec![];
29-
///
30-
/// get_extra_transfer_account_metas(
31-
/// &mut account_metas,
32-
/// |address| self.client.get_account(&address).map_ok(|opt| opt.map(|acc| acc.data)),
33-
/// &mint,
34-
/// ).await?;
35-
/// ```
36-
#[deprecated(
37-
since = "1.1.0",
38-
note = "Please use `create_transfer_checked_instruction_with_extra_metas` instead"
39-
)]
40-
pub async fn resolve_extra_transfer_account_metas<F, Fut>(
41-
instruction: &mut Instruction,
42-
fetch_account_data_fn: F,
43-
mint_address: &Pubkey,
44-
) -> Result<(), AccountFetchError>
45-
where
46-
F: Fn(Pubkey) -> Fut,
47-
Fut: Future<Output = AccountDataResult>,
48-
{
49-
let mint_data = fetch_account_data_fn(*mint_address)
50-
.await?
51-
.ok_or(ProgramError::InvalidAccountData)?;
52-
let mint = StateWithExtensions::<Mint>::unpack(&mint_data)?;
53-
if let Some(program_id) = transfer_hook::get_program_id(&mint) {
54-
#[allow(deprecated)]
55-
spl_transfer_hook_interface::offchain::resolve_extra_account_metas(
56-
instruction,
57-
fetch_account_data_fn,
58-
mint_address,
59-
&program_id,
60-
)
61-
.await?;
62-
}
63-
Ok(())
64-
}
65-
6614
/// Offchain helper to create a `TransferChecked` instruction with all
6715
/// additional required account metas for a transfer, including the ones
6816
/// required by the transfer hook.

token/transfer-hook/interface/src/offchain.rs

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,6 @@ use {
1616
std::future::Future,
1717
};
1818

19-
/// Offchain helper to get all additional required account metas for a mint
20-
///
21-
/// To be client-agnostic and to avoid pulling in the full solana-sdk, this
22-
/// simply takes a function that will return its data as `Future<Vec<u8>>` for
23-
/// the given address. Can be called in the following way:
24-
///
25-
/// ```rust,ignore
26-
/// use futures_util::TryFutureExt;
27-
/// use solana_client::nonblocking::rpc_client::RpcClient;
28-
/// use solana_program::pubkey::Pubkey;
29-
///
30-
/// let program_id = Pubkey::new_unique();
31-
/// let mint = Pubkey::new_unique();
32-
/// let client = RpcClient::new_mock("succeeds".to_string());
33-
/// let mut account_metas = vec![];
34-
///
35-
/// get_extra_account_metas(
36-
/// &mut account_metas,
37-
/// |address| self.client.get_account(&address).map_ok(|opt| opt.map(|acc| acc.data)),
38-
/// &mint,
39-
/// &program_id,
40-
/// ).await?;
41-
/// ```
42-
#[deprecated(
43-
since = "0.5.0",
44-
note = "Please use `add_extra_account_metas_for_execute` instead"
45-
)]
46-
pub async fn resolve_extra_account_metas<F, Fut>(
47-
instruction: &mut Instruction,
48-
fetch_account_data_fn: F,
49-
mint: &Pubkey,
50-
permissioned_transfer_program_id: &Pubkey,
51-
) -> Result<(), AccountFetchError>
52-
where
53-
F: Fn(Pubkey) -> Fut,
54-
Fut: Future<Output = AccountDataResult>,
55-
{
56-
let validation_address =
57-
get_extra_account_metas_address(mint, permissioned_transfer_program_id);
58-
let validation_account_data = fetch_account_data_fn(validation_address)
59-
.await?
60-
.ok_or(ProgramError::InvalidAccountData)?;
61-
ExtraAccountMetaList::add_to_instruction::<ExecuteInstruction, _, _>(
62-
instruction,
63-
fetch_account_data_fn,
64-
&validation_account_data,
65-
)
66-
.await?;
67-
// The onchain helpers pull out the required accounts from an opaque
68-
// slice by pubkey, so the order doesn't matter here!
69-
instruction.accounts.push(AccountMeta::new_readonly(
70-
*permissioned_transfer_program_id,
71-
false,
72-
));
73-
instruction
74-
.accounts
75-
.push(AccountMeta::new_readonly(validation_address, false));
76-
77-
Ok(())
78-
}
79-
8019
/// Offchain helper to get all additional required account metas for an execute
8120
/// instruction, based on a validation state account.
8221
///

token/transfer-hook/interface/src/onchain.rs

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,49 +54,6 @@ pub fn invoke_execute<'a>(
5454
invoke(&cpi_instruction, &cpi_account_infos)
5555
}
5656

57-
/// Helper to add accounts required for the transfer-hook program on-chain,
58-
/// looking through the additional account infos to add the proper accounts
59-
#[deprecated(
60-
since = "0.5.0",
61-
note = "Please use `add_extra_accounts_for_execute_cpi` instead"
62-
)]
63-
pub fn add_cpi_accounts_for_execute<'a>(
64-
cpi_instruction: &mut Instruction,
65-
cpi_account_infos: &mut Vec<AccountInfo<'a>>,
66-
mint_pubkey: &Pubkey,
67-
program_id: &Pubkey,
68-
additional_accounts: &[AccountInfo<'a>],
69-
) -> ProgramResult {
70-
let validation_pubkey = get_extra_account_metas_address(mint_pubkey, program_id);
71-
let validation_info = additional_accounts
72-
.iter()
73-
.find(|&x| *x.key == validation_pubkey)
74-
.ok_or(TransferHookError::IncorrectAccount)?;
75-
76-
let program_info = additional_accounts
77-
.iter()
78-
.find(|&x| x.key == program_id)
79-
.ok_or(TransferHookError::IncorrectAccount)?;
80-
81-
ExtraAccountMetaList::add_to_cpi_instruction::<instruction::ExecuteInstruction>(
82-
cpi_instruction,
83-
cpi_account_infos,
84-
&validation_info.try_borrow_data()?,
85-
additional_accounts,
86-
)?;
87-
// The onchain helpers pull out the required accounts from an opaque
88-
// slice by pubkey, so the order doesn't matter here!
89-
cpi_account_infos.push(validation_info.clone());
90-
cpi_account_infos.push(program_info.clone());
91-
cpi_instruction
92-
.accounts
93-
.push(AccountMeta::new_readonly(validation_pubkey, false));
94-
cpi_instruction
95-
.accounts
96-
.push(AccountMeta::new_readonly(*program_id, false));
97-
Ok(())
98-
}
99-
10057
/// Helper to add accounts required for an `ExecuteInstruction` on-chain,
10158
/// looking through the additional account infos to add the proper accounts.
10259
///

0 commit comments

Comments
 (0)