Skip to content

Commit

Permalink
Use Token-2022 (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
zpetersen-paxos authored Oct 30, 2024
1 parent 917a149 commit 7fafbe6
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 67 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
# Solana Programs
Solana programs developed at Paxos

## Minter Controller
`minter_controller` is used to add transaction controls to Solana mint authorities for the token and token-2022 program.
The transaction controls include rate limitings and whitelisting. The program requires the token mint authority
to be a [spl token multisig](https://spl.solana.com/token#example-mint-with-multisig-authority).

### Usage

#### Add Minter
The program is first used by calling the `add_minter` instruction which creates a PDA that can be used to mint tokens.
The PDA is derived from the `minter_authority` and `mint_account`.
The minter PDA should be added as a signer on the spl token multisig.
An `admin` Pubkey is also specified to update the transaction controls.

#### Whitelisting
Whitelisted addresses which can be minted to can be added via `add_whitelisted_address`. Whitelisted addresses can be
removed via `remove_whitelisted_address`. These instructions can only be called by the `admin`.

#### Rate limiting
The initial rate limit is specified when calling `add_minter`. It can also be updated via `update_rate_limit`.
These instructions can only be called by the `admin`.

#### Update admin
Updating the admin is a two step process. Step 1 is to call `start_admin_transfer` with the current `admin`.
Step 2 is for the new admin to call `accept_admin_transfer`.

#### Minting tokens
Minting tokens is done by calling `mint_tokens`. This instruction must be signed with the `minter_authority`.


## Development

### Required installs
- rust 1.79.0 (Installed via asdf)
- rust 1.79.0
- [solana](https://docs.solanalabs.com/cli/install) 1.18.18
- [anchor](https://book.anchor-lang.com/getting_started/installation.html) 0.30.1

Expand All @@ -13,6 +42,7 @@ Solana programs developed at Paxos

### Test
`npm install`

`anchor test`

### Deploy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -21,7 +19,7 @@ pub struct AcceptAdminTransfer<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
mut,
Expand Down
6 changes: 2 additions & 4 deletions programs/minter-controller/src/instructions/add_minter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -16,7 +14,7 @@ pub struct AddMinter<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
init,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -20,7 +18,7 @@ pub struct AddWhitelistedAddress<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
has_one = admin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -17,7 +15,7 @@ pub struct GetRemainingAmount<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
mut,
Expand Down
16 changes: 8 additions & 8 deletions programs/minter-controller/src/instructions/mint_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use {
anchor_lang::prelude::*,
anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, Token, TokenAccount},
token_interface::{Mint, TokenInterface, TokenAccount}
},
};
pub use anchor_spl::token::spl_token;
pub use anchor_spl::token::spl_token::ID as splId;
pub use anchor_spl::token_2022::spl_token_2022;
use crate::*;

#[derive(Accounts)]
Expand All @@ -23,7 +22,7 @@ pub struct MintToken<'info> {

// Mint account address is a PDA
#[account(mut)]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
mut,
Expand All @@ -48,10 +47,11 @@ pub struct MintToken<'info> {
payer = payer,
associated_token::mint = mint_account,
associated_token::authority = to_address,
associated_token::token_program = token_program
)]
pub associated_token_account: Account<'info, TokenAccount>,
pub associated_token_account: InterfaceAccount<'info, TokenAccount>,

pub token_program: Program<'info, Token>,
pub token_program: Interface<'info, TokenInterface>,
pub associated_token_program: Program<'info, AssociatedToken>,
pub system_program: Program<'info, System>,
}
Expand All @@ -68,8 +68,8 @@ pub fn mint_token(ctx: Context<MintToken>, amount: u64) -> Result<()> {

// Invoke the mint_to instruction on the token program
// Anchor does not implement the token multisig so we have to do it here manually.
let ix = spl_token::instruction::mint_to(
&splId,
let ix = spl_token_2022::instruction::mint_to(
ctx.accounts.token_program.to_account_info().key,
ctx.accounts.mint_account.to_account_info().key,
ctx.accounts.associated_token_account.to_account_info().key,
ctx.accounts.mint_multisig.to_account_info().key,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -20,7 +18,7 @@ pub struct RemoveWhitelistedAddress<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
has_one = admin,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -21,7 +19,7 @@ pub struct StartAdminTransfer<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
mut,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

use {
anchor_lang::prelude::*,
anchor_spl::{
token::{ Mint },
},
anchor_spl::token_interface::{Mint},
};
use crate::*;

Expand All @@ -21,7 +19,7 @@ pub struct UpdateRateLimit<'info> {

// Mint account address is a PDA
#[account()]
pub mint_account: Account<'info, Mint>,
pub mint_account: InterfaceAccount<'info, Mint>,

#[account(
mut,
Expand Down
2 changes: 1 addition & 1 deletion programs/minter-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use state::*;
pub mod instructions;
pub mod state;

declare_id!("wKv26ghpb9Dtxd4ba8RtAndZKuGh1HjrEU2FRSFSPN6");
declare_id!("DWGSMEEzjofw9Xd1rSUHr71HNgtmotoUbWuqRyfLcMWk");


#[program]
Expand Down
Loading

0 comments on commit 7fafbe6

Please sign in to comment.