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

Commit 4349310

Browse files
token-2022: Add scaled amount extension (#7511)
* token-2022: Add scaled amount extension #### Problem The interest-bearing extension is useful for tokens that accrue in value constantly, but many "rebasing" tokens on other blockchains employ a different method of updating the number of tokens in accounts. Rather than setting a rate and allowing the number to change automatically over time, they set a scaling factor for the tokens by hand. #### Summary of changes Add a new `ScaledUiAmount` extension to token-2022 for doing just that. This is essentially a simplified version of the interest-bearing extension, where someone just sets a scaling value into the mint directly. The scale has no impact on the operation of the token, just on the output of `amount_to_ui_amount` and `ui_amount_to_amount`. * Add timestamp, rename to "multiplier" * Update token/program-2022/src/extension/scaled_ui_amount/mod.rs Co-authored-by: samkim-crypto <[email protected]> * Address feedback --------- Co-authored-by: samkim-crypto <[email protected]>
1 parent 74e2559 commit 4349310

File tree

10 files changed

+1097
-4
lines changed

10 files changed

+1097
-4
lines changed

token/client/src/token.rs

+42-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ use {
4343
ConfidentialTransferFeeConfig,
4444
},
4545
cpi_guard, default_account_state, group_member_pointer, group_pointer,
46-
interest_bearing_mint, memo_transfer, metadata_pointer, transfer_fee, transfer_hook,
47-
BaseStateWithExtensions, Extension, ExtensionType, StateWithExtensionsOwned,
46+
interest_bearing_mint, memo_transfer, metadata_pointer, scaled_ui_amount, transfer_fee,
47+
transfer_hook, BaseStateWithExtensions, Extension, ExtensionType,
48+
StateWithExtensionsOwned,
4849
},
4950
instruction, offchain,
5051
solana_zk_sdk::{
@@ -188,6 +189,10 @@ pub enum ExtensionInitializationParams {
188189
authority: Option<Pubkey>,
189190
member_address: Option<Pubkey>,
190191
},
192+
ScaledUiAmountConfig {
193+
authority: Option<Pubkey>,
194+
multiplier: f64,
195+
},
191196
}
192197
impl ExtensionInitializationParams {
193198
/// Get the extension type associated with the init params
@@ -207,6 +212,7 @@ impl ExtensionInitializationParams {
207212
}
208213
Self::GroupPointer { .. } => ExtensionType::GroupPointer,
209214
Self::GroupMemberPointer { .. } => ExtensionType::GroupMemberPointer,
215+
Self::ScaledUiAmountConfig { .. } => ExtensionType::ScaledUiAmount,
210216
}
211217
}
212218
/// Generate an appropriate initialization instruction for the given mint
@@ -316,6 +322,15 @@ impl ExtensionInitializationParams {
316322
authority,
317323
member_address,
318324
),
325+
Self::ScaledUiAmountConfig {
326+
authority,
327+
multiplier,
328+
} => scaled_ui_amount::instruction::initialize(
329+
token_program_id,
330+
mint,
331+
authority,
332+
multiplier,
333+
),
319334
}
320335
}
321336
}
@@ -1805,6 +1820,31 @@ where
18051820
.await
18061821
}
18071822

1823+
/// Update multiplier
1824+
pub async fn update_multiplier<S: Signers>(
1825+
&self,
1826+
authority: &Pubkey,
1827+
new_multiplier: f64,
1828+
new_multiplier_effective_timestamp: i64,
1829+
signing_keypairs: &S,
1830+
) -> TokenResult<T::Output> {
1831+
let signing_pubkeys = signing_keypairs.pubkeys();
1832+
let multisig_signers = self.get_multisig_signers(authority, &signing_pubkeys);
1833+
1834+
self.process_ixs(
1835+
&[scaled_ui_amount::instruction::update_multiplier(
1836+
&self.program_id,
1837+
self.get_address(),
1838+
authority,
1839+
&multisig_signers,
1840+
new_multiplier,
1841+
new_multiplier_effective_timestamp,
1842+
)?],
1843+
signing_keypairs,
1844+
)
1845+
.await
1846+
}
1847+
18081848
/// Update transfer hook program id
18091849
pub async fn update_transfer_hook_program_id<S: Signers>(
18101850
&self,

0 commit comments

Comments
 (0)