@@ -28,9 +28,10 @@ import (
2828// address and token mint, if it doesn't already exist.
2929// Returns an error if the account exists but with a different owner.
3030type CreateIdempotent struct {
31- Payer solana.PublicKey `bin:"-" borsh_skip:"true"`
32- Wallet solana.PublicKey `bin:"-" borsh_skip:"true"`
33- Mint solana.PublicKey `bin:"-" borsh_skip:"true"`
31+ Payer solana.PublicKey `bin:"-" borsh_skip:"true"`
32+ Wallet solana.PublicKey `bin:"-" borsh_skip:"true"`
33+ Mint solana.PublicKey `bin:"-" borsh_skip:"true"`
34+ TokenProgram solana.PublicKey `bin:"-" borsh_skip:"true"`
3435
3536 // [0] = [WRITE, SIGNER] Payer
3637 // ··········· Funding account
@@ -54,7 +55,9 @@ type CreateIdempotent struct {
5455
5556// NewCreateIdempotentInstructionBuilder creates a new `CreateIdempotent` instruction builder.
5657func NewCreateIdempotentInstructionBuilder () * CreateIdempotent {
57- return & CreateIdempotent {}
58+ return & CreateIdempotent {
59+ TokenProgram : solana .TokenProgramID ,
60+ }
5861}
5962
6063func (inst * CreateIdempotent ) SetPayer (payer solana.PublicKey ) * CreateIdempotent {
@@ -72,6 +75,11 @@ func (inst *CreateIdempotent) SetMint(mint solana.PublicKey) *CreateIdempotent {
7275 return inst
7376}
7477
78+ func (inst * CreateIdempotent ) SetTokenProgram (tokenProgram solana.PublicKey ) * CreateIdempotent {
79+ inst .TokenProgram = tokenProgram
80+ return inst
81+ }
82+
7583func (inst * CreateIdempotent ) SetAccounts (accounts []* solana.AccountMeta ) error {
7684 inst .AccountMetaSlice = accounts
7785 if len (accounts ) < 6 {
@@ -80,13 +88,19 @@ func (inst *CreateIdempotent) SetAccounts(accounts []*solana.AccountMeta) error
8088 inst .Payer = accounts [0 ].PublicKey
8189 inst .Wallet = accounts [2 ].PublicKey
8290 inst .Mint = accounts [3 ].PublicKey
91+ inst .TokenProgram = accounts [5 ].PublicKey
8392 return nil
8493}
8594
8695func (inst CreateIdempotent ) Build () * Instruction {
87- associatedTokenAddress , _ , _ := solana .FindAssociatedTokenAddress (
96+ tokenProgram := inst .TokenProgram
97+ if tokenProgram .IsZero () {
98+ tokenProgram = solana .TokenProgramID
99+ }
100+ associatedTokenAddress , _ , _ := solana .FindAssociatedTokenAddressWithProgram (
88101 inst .Wallet ,
89102 inst .Mint ,
103+ tokenProgram ,
90104 )
91105
92106 keys := []* solana.AccountMeta {
@@ -116,7 +130,7 @@ func (inst CreateIdempotent) Build() *Instruction {
116130 IsWritable : false ,
117131 },
118132 {
119- PublicKey : solana . TokenProgramID ,
133+ PublicKey : tokenProgram ,
120134 IsSigner : false ,
121135 IsWritable : false ,
122136 },
@@ -150,9 +164,14 @@ func (inst *CreateIdempotent) Validate() error {
150164 if inst .Mint .IsZero () {
151165 return errors .New ("mint not set" )
152166 }
153- _ , _ , err := solana .FindAssociatedTokenAddress (
167+ tokenProgram := inst .TokenProgram
168+ if tokenProgram .IsZero () {
169+ tokenProgram = solana .TokenProgramID
170+ }
171+ _ , _ , err := solana .FindAssociatedTokenAddressWithProgram (
154172 inst .Wallet ,
155173 inst .Mint ,
174+ tokenProgram ,
156175 )
157176 if err != nil {
158177 return fmt .Errorf ("error while FindAssociatedTokenAddress: %w" , err )
@@ -192,11 +211,26 @@ func NewCreateIdempotentInstruction(
192211 payer solana.PublicKey ,
193212 walletAddress solana.PublicKey ,
194213 splTokenMintAddress solana.PublicKey ,
214+ ) * CreateIdempotent {
215+ return NewCreateIdempotentInstructionWithTokenProgram (
216+ payer ,
217+ walletAddress ,
218+ splTokenMintAddress ,
219+ solana .TokenProgramID ,
220+ )
221+ }
222+
223+ func NewCreateIdempotentInstructionWithTokenProgram (
224+ payer solana.PublicKey ,
225+ walletAddress solana.PublicKey ,
226+ splTokenMintAddress solana.PublicKey ,
227+ tokenProgram solana.PublicKey ,
195228) * CreateIdempotent {
196229 return NewCreateIdempotentInstructionBuilder ().
197230 SetPayer (payer ).
198231 SetWallet (walletAddress ).
199- SetMint (splTokenMintAddress )
232+ SetMint (splTokenMintAddress ).
233+ SetTokenProgram (tokenProgram )
200234}
201235
202236func (inst * CreateIdempotent ) GetPayerAccount () * solana.AccountMeta {
0 commit comments