Skip to content

Commit

Permalink
Sync repo to audited commit hash (#2)
Browse files Browse the repository at this point in the history
* Sync repos

* Sync repos
  • Loading branch information
zpetersen-paxos authored Oct 18, 2024
1 parent 1bde284 commit 917a149
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 157 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

32 changes: 1 addition & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
# 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
- rust 1.79.0 (Installed via asdf)
- [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 @@ -42,7 +13,6 @@ Minting tokens is done by calling `mint_tokens`. This instruction must be signe

### Test
`npm install`

`anchor test`

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

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

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

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

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

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

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

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

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

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

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

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

// Mint account address is a PDA
#[account()]
pub mint_account: InterfaceAccount<'info, Mint>,
pub mint_account: Account<'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,10 +2,11 @@ use {
anchor_lang::prelude::*,
anchor_spl::{
associated_token::AssociatedToken,
token_interface::{Mint, TokenInterface, TokenAccount}
token::{Mint, Token, TokenAccount},
},
};
pub use anchor_spl::token_2022::spl_token_2022;
pub use anchor_spl::token::spl_token;
pub use anchor_spl::token::spl_token::ID as splId;
use crate::*;

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

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

#[account(
mut,
Expand All @@ -47,11 +48,10 @@ 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: InterfaceAccount<'info, TokenAccount>,
pub associated_token_account: Account<'info, TokenAccount>,

pub token_program: Interface<'info, TokenInterface>,
pub token_program: Program<'info, Token>,
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_2022::instruction::mint_to(
ctx.accounts.token_program.to_account_info().key,
let ix = spl_token::instruction::mint_to(
&splId,
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,6 +1,8 @@
use {
anchor_lang::prelude::*,
anchor_spl::token_interface::{Mint},
anchor_spl::{
token::{ Mint },
},
};
use crate::*;

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

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

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

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

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

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

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

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

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

// Mint account address is a PDA
#[account()]
pub mint_account: InterfaceAccount<'info, Mint>,
pub mint_account: Account<'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!("DWGSMEEzjofw9Xd1rSUHr71HNgtmotoUbWuqRyfLcMWk");
declare_id!("wKv26ghpb9Dtxd4ba8RtAndZKuGh1HjrEU2FRSFSPN6");


#[program]
Expand Down
Loading

0 comments on commit 917a149

Please sign in to comment.