@@ -2,8 +2,12 @@ const std = @import("std");
22const bincode = @import ("bincode" );
33const sol = @import ("solana_program_sdk" );
44
5+ const Account = sol .account .Account ;
6+ const ProgramDerivedAddress = sol .public_key .ProgramDerivedAddress ;
7+ const PublicKey = sol .public_key .PublicKey ;
8+
59const AssociatedTokenAccountProgram = @This ();
6- pub const id = sol . PublicKey .comptimeFromBase58 ("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" );
10+ pub const id = PublicKey .comptimeFromBase58 ("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" );
711
812pub const Instruction = union (enum (u8 )) {
913 /// Creates an associated token account for the given wallet address and token mint
@@ -48,31 +52,31 @@ pub const Instruction = union(enum(u8)) {
4852 recover_nested : void ,
4953};
5054
51- pub fn getAssociatedTokenAccountAddressWithProgramId (wallet_address : sol. PublicKey , mint_address : sol. PublicKey ) ! sol. PublicKey {
55+ pub fn getAssociatedTokenAccountAddressWithProgramId (wallet_address : PublicKey , mint_address : PublicKey ) ! PublicKey {
5256 const pda = try getAssociatedTokenAccountAddressAndBumpSeed (wallet_address , mint_address );
5357 return pda .address ;
5458}
5559
56- pub fn getAssociatedTokenAccountAddressAndBumpSeed (wallet_address : sol. PublicKey , mint_address : sol. PublicKey , token_program_id : sol. PublicKey ) ! sol. ProgramDerivedAddress {
57- return sol . PublicKey .findProgramAddress (.{ wallet_address , token_program_id , mint_address }, id );
60+ pub fn getAssociatedTokenAccountAddressAndBumpSeed (wallet_address : PublicKey , mint_address : PublicKey , token_program_id : PublicKey ) ! ProgramDerivedAddress {
61+ return PublicKey .findProgramAddress (.{ wallet_address , token_program_id , mint_address }, id );
5862}
5963
6064pub fn createAccount (params : struct {
61- funder : sol. Account.Info ,
62- account : sol. Account.Info ,
63- owner : sol. Account.Info ,
64- mint : sol. Account.Info ,
65- system_program : sol. Account.Info ,
66- token_program : sol. Account.Info ,
67- rent : sol. Account.Info ,
65+ funder : Account.Info ,
66+ account : Account.Info ,
67+ owner : Account.Info ,
68+ mint : Account.Info ,
69+ system_program : Account.Info ,
70+ token_program : Account.Info ,
71+ rent : Account.Info ,
6872 seeds : []const []const []const u8 = &.{},
6973}) ! void {
7074 var data : [1 ]u8 = undefined ;
7175 _ = try bincode .writeToSlice (& data , AssociatedTokenAccountProgram .Instruction .create , .default );
7276
73- const instruction = sol .Instruction .from (.{
77+ const instruction = sol .instruction . Instruction .from (.{
7478 .program_id = & id ,
75- .accounts = &[_ ]sol. Account.Param {
79+ .accounts = &[_ ]Account.Param {
7680 .{ .id = params .funder .id , .is_writable = true , .is_signer = true },
7781 .{ .id = params .account .id , .is_writable = true , .is_signer = false },
7882 .{ .id = params .owner .id , .is_writable = false , .is_signer = false },
@@ -96,21 +100,21 @@ pub fn createAccount(params: struct {
96100}
97101
98102pub fn createIdempotentAccount (params : struct {
99- funder : sol. Account.Info ,
100- account : sol. Account.Info ,
101- owner : sol. Account.Info ,
102- mint : sol. Account.Info ,
103- system_program : sol. Account.Info ,
104- token_program : sol. Account.Info ,
105- associated_token_program : sol. Account.Info ,
103+ funder : Account.Info ,
104+ account : Account.Info ,
105+ owner : Account.Info ,
106+ mint : Account.Info ,
107+ system_program : Account.Info ,
108+ token_program : Account.Info ,
109+ associated_token_program : Account.Info ,
106110 seeds : []const []const []const u8 = &.{},
107111}) ! void {
108112 var data : [1 ]u8 = undefined ;
109113 _ = try bincode .writeToSlice (& data , AssociatedTokenAccountProgram .Instruction .create_idempotent , .default );
110114
111- const instruction = sol .Instruction .from (.{
115+ const instruction = sol .instruction . Instruction .from (.{
112116 .program_id = & id ,
113- .accounts = &[_ ]sol. Account.Param {
117+ .accounts = &[_ ]Account.Param {
114118 .{ .id = params .funder .id , .is_writable = true , .is_signer = true },
115119 .{ .id = params .account .id , .is_writable = true , .is_signer = false },
116120 .{ .id = params .owner .id , .is_writable = false , .is_signer = false },
@@ -133,22 +137,22 @@ pub fn createIdempotentAccount(params: struct {
133137}
134138
135139pub fn recoverNestedAccount (params : struct {
136- account : sol. Account.Info ,
137- nested_mint : sol. Account.Info ,
138- destination_associated_account : sol. Account.Info ,
139- owner_associated_account : sol. Account.Info ,
140- owner_mint : sol. Account.Info ,
141- owner : sol. Account.Info ,
142- token_program : sol. Account.Info ,
143- associated_token_program : sol. Account.Info ,
140+ account : Account.Info ,
141+ nested_mint : Account.Info ,
142+ destination_associated_account : Account.Info ,
143+ owner_associated_account : Account.Info ,
144+ owner_mint : Account.Info ,
145+ owner : Account.Info ,
146+ token_program : Account.Info ,
147+ associated_token_program : Account.Info ,
144148 seeds : []const []const []const u8 = &.{},
145149}) ! void {
146150 var data : [1 ]u8 = undefined ;
147151 _ = try bincode .writeToSlice (& data , AssociatedTokenAccountProgram .Instruction .recover_nested , .default );
148152
149- const instruction = sol .Instruction .from (.{
153+ const instruction = sol .instruction . Instruction .from (.{
150154 .program_id = & id ,
151- .accounts = &[_ ]sol. Account.Param {
155+ .accounts = &[_ ]Account.Param {
152156 .{ .id = params .account .id , .is_writable = true , .is_signer = false },
153157 .{ .id = params .nested_mint .id , .is_writable = false , .is_signer = false },
154158 .{ .id = params .destination_associated_account .id , .is_writable = true , .is_signer = false },
0 commit comments