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

Commit 49e6e4a

Browse files
Reinstate Mint supply (#342)
* Reinstate Mint supply, and adjust with Minto & Burn * C headers * Patch token-cli * Patch token-swap
1 parent fec5717 commit 49e6e4a

File tree

6 files changed

+206
-67
lines changed

6 files changed

+206
-67
lines changed

token-swap/program/src/processor.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ impl State {
8989
token_program_id: &Pubkey,
9090
swap: &Pubkey,
9191
burn_account: &Pubkey,
92+
mint: &Pubkey,
9293
authority: &Pubkey,
9394
amount: u64,
9495
) -> Result<(), ProgramError> {
9596
let swap_bytes = swap.to_bytes();
9697
let signers = &[&[&swap_bytes[..32]][..]];
97-
let ix =
98-
spl_token::instruction::burn(token_program_id, burn_account, authority, &[], amount)?;
98+
let ix = spl_token::instruction::burn(
99+
token_program_id,
100+
burn_account,
101+
mint,
102+
authority,
103+
&[],
104+
amount,
105+
)?;
99106
invoke_signed(&ix, accounts, signers)
100107
}
101108

@@ -414,6 +421,7 @@ impl State {
414421
token_program_info.key,
415422
swap_info.key,
416423
source_info.key,
424+
&token_swap.pool_mint,
417425
authority_info.key,
418426
amount,
419427
)?;

token/cli/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use spl_token::{
2020
self,
2121
instruction::*,
2222
native_mint,
23-
state::{Account, Mint},
23+
state::{self, Account, Mint},
2424
};
2525
use std::{mem::size_of, process::exit};
2626

@@ -213,12 +213,20 @@ fn command_burn(config: &Config, source: Pubkey, ui_amount: f64) -> CommmandResu
213213
.rpc_client
214214
.get_token_account_balance_with_commitment(&source, config.commitment_config)?
215215
.value;
216+
let source_account = config
217+
.rpc_client
218+
.get_account_with_commitment(&source, config.commitment_config)?
219+
.value
220+
.unwrap_or_default();
221+
let mut data = source_account.data.to_vec();
222+
let mint_pubkey = state::unpack::<Account>(&mut data)?.mint;
216223

217224
let amount = spl_token::ui_amount_to_amount(ui_amount, source_token_balance.decimals);
218225
let mut transaction = Transaction::new_with_payer(
219226
&[burn(
220227
&spl_token::id(),
221228
&source,
229+
&mint_pubkey,
222230
&config.owner.pubkey(),
223231
&[],
224232
amount,

token/program/inc/token.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ typedef enum Token_TokenInstruction_Tag {
152152
* Accounts expected by this instruction:
153153
*
154154
* 0. `[writable]` The multisignature account to initialize.
155-
* 2. `[]` Rent sysvar
156-
* 3. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
155+
* 1. `[]` Rent sysvar
156+
* 2. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
157157
*/
158158
Token_TokenInstruction_InitializeMultisig,
159159
/**
@@ -219,7 +219,7 @@ typedef enum Token_TokenInstruction_Tag {
219219
* * Multisignature authority
220220
* 0. `[writable]` The mint or account to change the authority of.
221221
* 1. `[]` The mint's or account's multisignature authority.
222-
* 3. ..3+M '[signer]' M signer accounts
222+
* 2. ..2+M '[signer]' M signer accounts
223223
*/
224224
Token_TokenInstruction_SetAuthority,
225225
/**
@@ -247,12 +247,14 @@ typedef enum Token_TokenInstruction_Tag {
247247
*
248248
* * Single owner/delegate
249249
* 0. `[writable]` The account to burn from.
250-
* 1. `[signer]` The account's owner/delegate.
250+
* 1. '[writable]' The token mint.
251+
* 2. `[signer]` The account's owner/delegate.
251252
*
252253
* * Multisignature owner/delegate
253254
* 0. `[writable]` The account to burn from.
254-
* 1. `[]` The account's multisignature owner/delegate.
255-
* 2. ..2+M '[signer]' M signer accounts.
255+
* 1. '[writable]' The token mint.
256+
* 2. `[]` The account's multisignature owner/delegate.
257+
* 3. ..3+M '[signer]' M signer accounts.
256258
*/
257259
Token_TokenInstruction_Burn,
258260
/**
@@ -393,6 +395,10 @@ typedef struct Token_Mint {
393395
* further tokens may be minted.
394396
*/
395397
Token_COption_Pubkey mint_authority;
398+
/**
399+
* Total supply of tokens.
400+
*/
401+
uint64_t supply;
396402
/**
397403
* Number of base 10 digits to the right of the decimal place.
398404
*/

token/program/src/instruction.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub enum TokenInstruction {
6464
/// Accounts expected by this instruction:
6565
///
6666
/// 0. `[writable]` The multisignature account to initialize.
67-
/// 2. `[]` Rent sysvar
68-
/// 3. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
67+
/// 1. `[]` Rent sysvar
68+
/// 2. ..2+N. `[]` The signer accounts, must equal to N where 1 <= N <= 11.
6969
InitializeMultisig {
7070
/// The number of signers (M) required to validate this multisignature account.
7171
m: u8,
@@ -133,7 +133,7 @@ pub enum TokenInstruction {
133133
/// * Multisignature authority
134134
/// 0. `[writable]` The mint or account to change the authority of.
135135
/// 1. `[]` The mint's or account's multisignature authority.
136-
/// 3. ..3+M '[signer]' M signer accounts
136+
/// 2. ..2+M '[signer]' M signer accounts
137137
SetAuthority {
138138
/// The type of authority to update.
139139
authority_type: AuthorityType,
@@ -165,12 +165,14 @@ pub enum TokenInstruction {
165165
///
166166
/// * Single owner/delegate
167167
/// 0. `[writable]` The account to burn from.
168-
/// 1. `[signer]` The account's owner/delegate.
168+
/// 1. '[writable]' The token mint.
169+
/// 2. `[signer]` The account's owner/delegate.
169170
///
170171
/// * Multisignature owner/delegate
171172
/// 0. `[writable]` The account to burn from.
172-
/// 1. `[]` The account's multisignature owner/delegate.
173-
/// 2. ..2+M '[signer]' M signer accounts.
173+
/// 1. '[writable]' The token mint.
174+
/// 2. `[]` The account's multisignature owner/delegate.
175+
/// 3. ..3+M '[signer]' M signer accounts.
174176
Burn {
175177
/// The amount of tokens to burn.
176178
amount: u64,
@@ -696,14 +698,16 @@ pub fn mint_to(
696698
pub fn burn(
697699
token_program_id: &Pubkey,
698700
account_pubkey: &Pubkey,
701+
mint_pubkey: &Pubkey,
699702
authority_pubkey: &Pubkey,
700703
signer_pubkeys: &[&Pubkey],
701704
amount: u64,
702705
) -> Result<Instruction, ProgramError> {
703706
let data = TokenInstruction::Burn { amount }.pack()?;
704707

705-
let mut accounts = Vec::with_capacity(2 + signer_pubkeys.len());
708+
let mut accounts = Vec::with_capacity(3 + signer_pubkeys.len());
706709
accounts.push(AccountMeta::new(*account_pubkey, false));
710+
accounts.push(AccountMeta::new(*mint_pubkey, false));
707711
accounts.push(AccountMeta::new_readonly(
708712
*authority_pubkey,
709713
signer_pubkeys.is_empty(),

0 commit comments

Comments
 (0)