Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make extra Mint fields a separate account #6

Open
wants to merge 2 commits into
base: mantis
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions token/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ pub enum TokenError {
/// Instruction does not support non-native tokens
#[error("Instruction does not support non-native tokens")]
NonNativeNotSupported,
/// The token mint is not a rebasing token
#[error("The token mint is not a rebasing token")]
NotRebasingMint,
/// Invalid token mint extra
#[error("Invalid token mint extra")]
InvalidMintExtra,
/// The share price of the token can only increase
#[error("Share Price Can Only Increase")]
SharePriceCanOnlyIncrease,
/// Token supply is zero
#[error("Token supply is zero")]
ZeroSupply,
/// Token share is zero
#[error("Token share is zero")]
ZeroShare,
}
impl From<TokenError> for ProgramError {
fn from(e: TokenError) -> Self {
Expand Down Expand Up @@ -140,12 +146,16 @@ impl PrintProgramError for TokenError {
TokenError::NonNativeNotSupported => {
msg!("Error: Instruction does not support non-native tokens")
}
TokenError::NotRebasingMint => {
TokenError::InvalidMintExtra => {
msg!("Error: The token mint is not a rebasing token")
}
TokenError::SharePriceCanOnlyIncrease => {
msg!("Error: The share price of the token can only increase")
}
TokenError::ZeroSupply =>
msg!("Error: Token supply is zero"),
TokenError::ZeroShare =>
msg!("Error: Token share is zero"),
}
}
}
53 changes: 51 additions & 2 deletions token/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ pub fn initialize_mint2(
pub fn initialize_mint2_with_rebasing(
token_program_id: &Pubkey,
mint_pubkey: &Pubkey,
mint_extra_pubkey: &Pubkey,
mint_authority_pubkey: &Pubkey,
freeze_authority_pubkey: Option<&Pubkey>,
decimals: u8,
Expand All @@ -896,7 +897,10 @@ pub fn initialize_mint2_with_rebasing(
}
.pack();

let accounts = vec![AccountMeta::new(*mint_pubkey, false)];
let accounts = vec![
AccountMeta::new(*mint_pubkey, false),
AccountMeta::new(*mint_extra_pubkey, false),
];

Ok(Instruction {
program_id: *token_program_id,
Expand Down Expand Up @@ -1508,19 +1512,64 @@ pub fn ui_amount_to_amount(
})
}

/// Creates an `AmountToUiAmount` instruction for rebased tokens
pub fn amount_to_ui_amount_rebasing(
token_program_id: &Pubkey,
mint_pubkey: &Pubkey,
mint_extra_pubkey: &Pubkey,
amount: u64,
) -> Result<Instruction, ProgramError> {
check_program_account(token_program_id)?;

Ok(Instruction {
program_id: *token_program_id,
accounts: vec![
AccountMeta::new_readonly(*mint_pubkey, false),
AccountMeta::new_readonly(*mint_extra_pubkey, false),
],
data: TokenInstruction::AmountToUiAmount { amount }.pack(),
})
}

/// Creates a `UiAmountToAmount` instruction for rebased tokens
pub fn ui_amount_to_amount_rebasing(
token_program_id: &Pubkey,
mint_pubkey: &Pubkey,
mint_extra_pubkey: &Pubkey,
ui_amount: &str,
) -> Result<Instruction, ProgramError> {
check_program_account(token_program_id)?;

Ok(Instruction {
program_id: *token_program_id,
accounts: vec![
AccountMeta::new_readonly(*mint_pubkey, false),
AccountMeta::new_readonly(*mint_extra_pubkey, false),
],
data: TokenInstruction::UiAmountToAmount { ui_amount }.pack(),
})
}

/// Creates a `UiAmountToAmount` instruction
pub fn update_l1_token_supply(
token_program_id: &Pubkey,
mint_pubkey: &Pubkey,
mint_extra_pubkey: &Pubkey,
signer_pubkeys: &[&Pubkey],
new_l1_token_supply: u64,
) -> Result<Instruction, ProgramError> {
check_program_account(token_program_id)?;

let mut accounts = vec![AccountMeta::new(*mint_pubkey, false)];
let mut accounts = vec![
AccountMeta::new(*mint_pubkey, false),
];
for signer_pubkey in signer_pubkeys.iter() {
accounts.push(AccountMeta::new_readonly(**signer_pubkey, true));
}
accounts.push(
AccountMeta::new(*mint_extra_pubkey, false),

);

Ok(Instruction {
program_id: *token_program_id,
Expand Down
Loading
Loading