Skip to content

Commit d892938

Browse files
committed
solana: Add accept_token_authority ix and TS helper function
1 parent b0a0ecf commit d892938

File tree

5 files changed

+158
-3
lines changed

5 files changed

+158
-3
lines changed

solana/programs/example-native-token-transfers/src/instructions/admin.rs

+40-3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,43 @@ pub fn claim_ownership(ctx: Context<ClaimOwnership>) -> Result<()> {
158158

159159
// * Set token authority
160160

161+
#[derive(Accounts)]
162+
pub struct AcceptTokenAuthority<'info> {
163+
#[account(
164+
has_one = mint,
165+
constraint = config.paused @ NTTError::NotPaused,
166+
)]
167+
pub config: Account<'info, Config>,
168+
169+
#[account(mut)]
170+
pub mint: InterfaceAccount<'info, token_interface::Mint>,
171+
172+
#[account(
173+
seeds = [crate::TOKEN_AUTHORITY_SEED],
174+
bump,
175+
)]
176+
/// CHECK: The constraints enforce this is valid mint authority
177+
pub token_authority: UncheckedAccount<'info>,
178+
179+
pub current_authority: Signer<'info>,
180+
181+
pub token_program: Interface<'info, token_interface::TokenInterface>,
182+
}
183+
184+
pub fn accept_token_authority(ctx: Context<AcceptTokenAuthority>) -> Result<()> {
185+
token_interface::set_authority(
186+
CpiContext::new(
187+
ctx.accounts.token_program.to_account_info(),
188+
token_interface::SetAuthority {
189+
account_or_mint: ctx.accounts.mint.to_account_info(),
190+
current_authority: ctx.accounts.current_authority.to_account_info(),
191+
},
192+
),
193+
AuthorityType::MintTokens,
194+
Some(ctx.accounts.token_authority.key()),
195+
)
196+
}
197+
161198
#[derive(Accounts)]
162199
pub struct SetTokenAuthority<'info> {
163200
#[account(
@@ -170,7 +207,6 @@ pub struct SetTokenAuthority<'info> {
170207
pub owner: Signer<'info>,
171208

172209
#[account(mut)]
173-
/// CHECK: the mint address matches the config
174210
pub mint: InterfaceAccount<'info, token_interface::Mint>,
175211

176212
#[account(
@@ -244,6 +280,8 @@ pub fn set_token_authority_one_step_unchecked(
244280
)
245281
}
246282

283+
// * Claim token authority
284+
247285
#[derive(Accounts)]
248286
pub struct RevertTokenAuthority<'info> {
249287
#[account(
@@ -253,7 +291,6 @@ pub struct RevertTokenAuthority<'info> {
253291
pub config: Account<'info, Config>,
254292

255293
#[account(mut)]
256-
/// CHECK: the mint address matches the config
257294
pub mint: InterfaceAccount<'info, token_interface::Mint>,
258295

259296
#[account(
@@ -264,7 +301,7 @@ pub struct RevertTokenAuthority<'info> {
264301
pub token_authority: UncheckedAccount<'info>,
265302

266303
#[account(mut)]
267-
/// CHECK: the constraint enforces that this is the correct address
304+
/// CHECK: the `pending_token_authority` constraint enforces that this is the correct address
268305
pub rent_payer: UncheckedAccount<'info>,
269306

270307
#[account(

solana/programs/example-native-token-transfers/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ pub mod example_native_token_transfers {
127127
instructions::claim_ownership(ctx)
128128
}
129129

130+
pub fn accept_token_authority(ctx: Context<AcceptTokenAuthority>) -> Result<()> {
131+
instructions::accept_token_authority(ctx)
132+
}
133+
130134
pub fn set_token_authority(ctx: Context<SetTokenAuthorityChecked>) -> Result<()> {
131135
instructions::set_token_authority(ctx)
132136
}

solana/ts/idl/3_0_0/json/example_native_token_transfers.json

+31
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,37 @@
719719
],
720720
"args": []
721721
},
722+
{
723+
"name": "acceptTokenAuthority",
724+
"accounts": [
725+
{
726+
"name": "config",
727+
"isMut": false,
728+
"isSigner": false
729+
},
730+
{
731+
"name": "mint",
732+
"isMut": true,
733+
"isSigner": false
734+
},
735+
{
736+
"name": "tokenAuthority",
737+
"isMut": false,
738+
"isSigner": false
739+
},
740+
{
741+
"name": "currentAuthority",
742+
"isMut": false,
743+
"isSigner": true
744+
},
745+
{
746+
"name": "tokenProgram",
747+
"isMut": false,
748+
"isSigner": false
749+
}
750+
],
751+
"args": []
752+
},
722753
{
723754
"name": "setTokenAuthority",
724755
"accounts": [

solana/ts/idl/3_0_0/ts/example_native_token_transfers.ts

+62
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,37 @@ export type ExampleNativeTokenTransfers = {
719719
],
720720
"args": []
721721
},
722+
{
723+
"name": "acceptTokenAuthority",
724+
"accounts": [
725+
{
726+
"name": "config",
727+
"isMut": false,
728+
"isSigner": false
729+
},
730+
{
731+
"name": "mint",
732+
"isMut": true,
733+
"isSigner": false
734+
},
735+
{
736+
"name": "tokenAuthority",
737+
"isMut": false,
738+
"isSigner": false
739+
},
740+
{
741+
"name": "currentAuthority",
742+
"isMut": false,
743+
"isSigner": true
744+
},
745+
{
746+
"name": "tokenProgram",
747+
"isMut": false,
748+
"isSigner": false
749+
}
750+
],
751+
"args": []
752+
},
722753
{
723754
"name": "setTokenAuthority",
724755
"accounts": [
@@ -2962,6 +2993,37 @@ export const IDL: ExampleNativeTokenTransfers = {
29622993
],
29632994
"args": []
29642995
},
2996+
{
2997+
"name": "acceptTokenAuthority",
2998+
"accounts": [
2999+
{
3000+
"name": "config",
3001+
"isMut": false,
3002+
"isSigner": false
3003+
},
3004+
{
3005+
"name": "mint",
3006+
"isMut": true,
3007+
"isSigner": false
3008+
},
3009+
{
3010+
"name": "tokenAuthority",
3011+
"isMut": false,
3012+
"isSigner": false
3013+
},
3014+
{
3015+
"name": "currentAuthority",
3016+
"isMut": false,
3017+
"isSigner": true
3018+
},
3019+
{
3020+
"name": "tokenProgram",
3021+
"isMut": false,
3022+
"isSigner": false
3023+
}
3024+
],
3025+
"args": []
3026+
},
29653027
{
29663028
"name": "setTokenAuthority",
29673029
"accounts": [

solana/ts/lib/ntt.ts

+21
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,27 @@ export namespace NTT {
713713
.instruction();
714714
}
715715

716+
export async function createAcceptTokenAuthorityInstruction(
717+
program: Program<NttBindings.NativeTokenTransfer<IdlVersion>>,
718+
config: NttBindings.Config<IdlVersion>,
719+
args: {
720+
currentAuthority: PublicKey;
721+
},
722+
pdas?: Pdas
723+
) {
724+
pdas = pdas ?? NTT.pdas(program.programId);
725+
return await program.methods
726+
.acceptTokenAuthority()
727+
.accountsStrict({
728+
config: pdas.configAccount(),
729+
mint: config.mint,
730+
tokenProgram: config.tokenProgram,
731+
tokenAuthority: pdas.tokenAuthority(),
732+
currentAuthority: args.currentAuthority,
733+
})
734+
.instruction();
735+
}
736+
716737
export async function createSetTokenAuthorityInstruction(
717738
program: Program<NttBindings.NativeTokenTransfer<IdlVersion>>,
718739
config: NttBindings.Config<IdlVersion>,

0 commit comments

Comments
 (0)