Skip to content

Commit

Permalink
Reinstate Mint supply (solana-labs#342)
Browse files Browse the repository at this point in the history
* Reinstate Mint supply, and adjust with Minto & Burn

* C headers

* Patch token-cli

* Patch token-swap
  • Loading branch information
CriesofCarrots authored Aug 27, 2020
1 parent fec5717 commit 49e6e4a
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 67 deletions.
12 changes: 10 additions & 2 deletions token-swap/program/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,20 @@ impl State {
token_program_id: &Pubkey,
swap: &Pubkey,
burn_account: &Pubkey,
mint: &Pubkey,
authority: &Pubkey,
amount: u64,
) -> Result<(), ProgramError> {
let swap_bytes = swap.to_bytes();
let signers = &[&[&swap_bytes[..32]][..]];
let ix =
spl_token::instruction::burn(token_program_id, burn_account, authority, &[], amount)?;
let ix = spl_token::instruction::burn(
token_program_id,
burn_account,
mint,
authority,
&[],
amount,
)?;
invoke_signed(&ix, accounts, signers)
}

Expand Down Expand Up @@ -414,6 +421,7 @@ impl State {
token_program_info.key,
swap_info.key,
source_info.key,
&token_swap.pool_mint,
authority_info.key,
amount,
)?;
Expand Down
10 changes: 9 additions & 1 deletion token/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use spl_token::{
self,
instruction::*,
native_mint,
state::{Account, Mint},
state::{self, Account, Mint},
};
use std::{mem::size_of, process::exit};

Expand Down Expand Up @@ -213,12 +213,20 @@ fn command_burn(config: &Config, source: Pubkey, ui_amount: f64) -> CommmandResu
.rpc_client
.get_token_account_balance_with_commitment(&source, config.commitment_config)?
.value;
let source_account = config
.rpc_client
.get_account_with_commitment(&source, config.commitment_config)?
.value
.unwrap_or_default();
let mut data = source_account.data.to_vec();
let mint_pubkey = state::unpack::<Account>(&mut data)?.mint;

let amount = spl_token::ui_amount_to_amount(ui_amount, source_token_balance.decimals);
let mut transaction = Transaction::new_with_payer(
&[burn(
&spl_token::id(),
&source,
&mint_pubkey,
&config.owner.pubkey(),
&[],
amount,
Expand Down
18 changes: 12 additions & 6 deletions token/program/inc/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ typedef enum Token_TokenInstruction_Tag {
* Accounts expected by this instruction:
*
* 0. `[writable]` The multisignature account to initialize.
* 2. `[]` Rent sysvar
* 3. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
* 1. `[]` Rent sysvar
* 2. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
*/
Token_TokenInstruction_InitializeMultisig,
/**
Expand Down Expand Up @@ -219,7 +219,7 @@ typedef enum Token_TokenInstruction_Tag {
* * Multisignature authority
* 0. `[writable]` The mint or account to change the authority of.
* 1. `[]` The mint's or account's multisignature authority.
* 3. ..3+M '[signer]' M signer accounts
* 2. ..2+M '[signer]' M signer accounts
*/
Token_TokenInstruction_SetAuthority,
/**
Expand Down Expand Up @@ -247,12 +247,14 @@ typedef enum Token_TokenInstruction_Tag {
*
* * Single owner/delegate
* 0. `[writable]` The account to burn from.
* 1. `[signer]` The account's owner/delegate.
* 1. '[writable]' The token mint.
* 2. `[signer]` The account's owner/delegate.
*
* * Multisignature owner/delegate
* 0. `[writable]` The account to burn from.
* 1. `[]` The account's multisignature owner/delegate.
* 2. ..2+M '[signer]' M signer accounts.
* 1. '[writable]' The token mint.
* 2. `[]` The account's multisignature owner/delegate.
* 3. ..3+M '[signer]' M signer accounts.
*/
Token_TokenInstruction_Burn,
/**
Expand Down Expand Up @@ -393,6 +395,10 @@ typedef struct Token_Mint {
* further tokens may be minted.
*/
Token_COption_Pubkey mint_authority;
/**
* Total supply of tokens.
*/
uint64_t supply;
/**
* Number of base 10 digits to the right of the decimal place.
*/
Expand Down
18 changes: 11 additions & 7 deletions token/program/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pub enum TokenInstruction {
/// Accounts expected by this instruction:
///
/// 0. `[writable]` The multisignature account to initialize.
/// 2. `[]` Rent sysvar
/// 3. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
/// 1. `[]` Rent sysvar
/// 2. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
InitializeMultisig {
/// The number of signers (M) required to validate this multisignature account.
m: u8,
Expand Down Expand Up @@ -133,7 +133,7 @@ pub enum TokenInstruction {
/// * Multisignature authority
/// 0. `[writable]` The mint or account to change the authority of.
/// 1. `[]` The mint's or account's multisignature authority.
/// 3. ..3+M '[signer]' M signer accounts
/// 2. ..2+M '[signer]' M signer accounts
SetAuthority {
/// The type of authority to update.
authority_type: AuthorityType,
Expand Down Expand Up @@ -165,12 +165,14 @@ pub enum TokenInstruction {
///
/// * Single owner/delegate
/// 0. `[writable]` The account to burn from.
/// 1. `[signer]` The account's owner/delegate.
/// 1. '[writable]' The token mint.
/// 2. `[signer]` The account's owner/delegate.
///
/// * Multisignature owner/delegate
/// 0. `[writable]` The account to burn from.
/// 1. `[]` The account's multisignature owner/delegate.
/// 2. ..2+M '[signer]' M signer accounts.
/// 1. '[writable]' The token mint.
/// 2. `[]` The account's multisignature owner/delegate.
/// 3. ..3+M '[signer]' M signer accounts.
Burn {
/// The amount of tokens to burn.
amount: u64,
Expand Down Expand Up @@ -696,14 +698,16 @@ pub fn mint_to(
pub fn burn(
token_program_id: &Pubkey,
account_pubkey: &Pubkey,
mint_pubkey: &Pubkey,
authority_pubkey: &Pubkey,
signer_pubkeys: &[&Pubkey],
amount: u64,
) -> Result<Instruction, ProgramError> {
let data = TokenInstruction::Burn { amount }.pack()?;

let mut accounts = Vec::with_capacity(2 + signer_pubkeys.len());
let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
accounts.push(AccountMeta::new(*account_pubkey, false));
accounts.push(AccountMeta::new(*mint_pubkey, false));
accounts.push(AccountMeta::new_readonly(
*authority_pubkey,
signer_pubkeys.is_empty(),
Expand Down
Loading

0 comments on commit 49e6e4a

Please sign in to comment.