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

Commit 612a301

Browse files
authored
token-2022: Add Pausable extension (#7562)
* token-2022: Add Pausable extension #### Problem Users want a more Ethereum-style token experience by being able to "pause" their token, similar to the "Pausable" interface. When a mint is paused, tokens cannot be minted, burned, or transferred. #### Summary of changes Add the extension and some tests. It covers the following interactions: * mint / mint-checked * burn / burn-checked * transfer / transfer-checked / transfer-with-fee * confidential transfer / confidential transfer with fee * confidential mint / confidential burn Unfortunately, the confidential mint / burn extension doesn't have testing, so I couldn't get a full end-to-end test for it. Also note that it's still possible to: * move withheld tokens * initialize token accounts * close token accounts * set authority * freeze / thaw * approve / revoke * almost every other bit of extension management * Fix comments and semicolon * Add tests for deposit and withdraw
1 parent f634a9b commit 612a301

File tree

14 files changed

+1128
-4
lines changed

14 files changed

+1128
-4
lines changed

token/client/src/token.rs

+51-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ use {
4343
ConfidentialTransferFeeConfig,
4444
},
4545
cpi_guard, default_account_state, group_member_pointer, group_pointer,
46-
interest_bearing_mint, memo_transfer, metadata_pointer, scaled_ui_amount, transfer_fee,
47-
transfer_hook, BaseStateWithExtensions, Extension, ExtensionType,
46+
interest_bearing_mint, memo_transfer, metadata_pointer, pausable, scaled_ui_amount,
47+
transfer_fee, transfer_hook, BaseStateWithExtensions, Extension, ExtensionType,
4848
StateWithExtensionsOwned,
4949
},
5050
instruction, offchain,
@@ -193,6 +193,9 @@ pub enum ExtensionInitializationParams {
193193
authority: Option<Pubkey>,
194194
multiplier: f64,
195195
},
196+
PausableConfig {
197+
authority: Pubkey,
198+
},
196199
}
197200
impl ExtensionInitializationParams {
198201
/// Get the extension type associated with the init params
@@ -213,6 +216,7 @@ impl ExtensionInitializationParams {
213216
Self::GroupPointer { .. } => ExtensionType::GroupPointer,
214217
Self::GroupMemberPointer { .. } => ExtensionType::GroupMemberPointer,
215218
Self::ScaledUiAmountConfig { .. } => ExtensionType::ScaledUiAmount,
219+
Self::PausableConfig { .. } => ExtensionType::Pausable,
216220
}
217221
}
218222
/// Generate an appropriate initialization instruction for the given mint
@@ -331,6 +335,9 @@ impl ExtensionInitializationParams {
331335
authority,
332336
multiplier,
333337
),
338+
Self::PausableConfig { authority } => {
339+
pausable::instruction::initialize(token_program_id, mint, &authority)
340+
}
334341
}
335342
}
336343
}
@@ -1753,6 +1760,48 @@ where
17531760
.await
17541761
}
17551762

1763+
/// Pause transferring, minting, and burning on the mint
1764+
pub async fn pause<S: Signers>(
1765+
&self,
1766+
authority: &Pubkey,
1767+
signing_keypairs: &S,
1768+
) -> TokenResult<T::Output> {
1769+
let signing_pubkeys = signing_keypairs.pubkeys();
1770+
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
1771+
1772+
self.process_ixs(
1773+
&[pausable::instruction::pause(
1774+
&self.program_id,
1775+
self.get_address(),
1776+
authority,
1777+
&multisig_signers,
1778+
)?],
1779+
signing_keypairs,
1780+
)
1781+
.await
1782+
}
1783+
1784+
/// Resume transferring, minting, and burning on the mint
1785+
pub async fn resume<S: Signers>(
1786+
&self,
1787+
authority: &Pubkey,
1788+
signing_keypairs: &S,
1789+
) -> TokenResult<T::Output> {
1790+
let signing_pubkeys = signing_keypairs.pubkeys();
1791+
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
1792+
1793+
self.process_ixs(
1794+
&[pausable::instruction::resume(
1795+
&self.program_id,
1796+
self.get_address(),
1797+
authority,
1798+
&multisig_signers,
1799+
)?],
1800+
signing_keypairs,
1801+
)
1802+
.await
1803+
}
1804+
17561805
/// Prevent unsafe usage of token account through CPI
17571806
pub async fn enable_cpi_guard<S: Signers>(
17581807
&self,

0 commit comments

Comments
 (0)