• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 8950601615

04 May 2024 12:47PM UTC coverage: 77.239% (-3.7%) from 80.902%
8950601615

push

github

web-flow
Update dotnet.yml

1123 of 1710 branches covered (65.67%)

Branch coverage included in aggregate %.

5199 of 6475 relevant lines covered (80.29%)

1304486.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.68
/src/Solnet.Programs/TokenProgramData.cs
1
using Solnet.Programs.Utilities;
2
using Solnet.Wallet;
3
using System;
4
using System.Collections.Generic;
5

6
namespace Solnet.Programs
7
{
8
    /// <summary>
9
    /// Implements the token program data encodings.
10
    /// </summary>
11
    internal static class TokenProgramData
12
    {
13
        /// <summary>
14
        /// The offset at which the value which defines the method begins.
15
        /// </summary>
16
        internal const int MethodOffset = 0;
17

18
        /// <summary>
19
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.Revoke"/> method.
20
        /// </summary>
21
        /// <returns>The byte array with the encoded data.</returns>
22
        internal static byte[] EncodeRevokeData() => new[] { (byte)TokenProgramInstructions.Values.Revoke };
2✔
23

24
        /// <summary>
25
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.Approve"/> method.
26
        /// </summary>
27
        /// <param name="amount">The amount of tokens to approve the transfer of.</param>
28
        /// <returns>The byte array with the encoded data.</returns>
29
        internal static byte[] EncodeApproveData(ulong amount)
30
            => EncodeAmountLayout((byte)TokenProgramInstructions.Values.Approve, amount);
3✔
31

32
        /// <summary>
33
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.InitializeAccount"/> method.
34
        /// </summary>
35
        /// <returns>The byte array with the encoded data.</returns>
36
        internal static byte[] EncodeInitializeAccountData() =>
37
            new[] { (byte)TokenProgramInstructions.Values.InitializeAccount };
4✔
38

39
        /// <summary>
40
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.InitializeMint"/> method.
41
        /// </summary>
42
        /// <param name="mintAuthority">The mint authority for the token.</param>
43
        /// <param name="freezeAuthority">The freeze authority for the token.</param>
44
        /// <param name="decimals">The amount of decimals.</param>
45
        /// <param name="freezeAuthorityOption">The freeze authority option for the token.</param>
46
        /// <remarks>The <c>freezeAuthorityOption</c> parameter is related to the existence or not of a freeze authority.</remarks>
47
        /// <returns>The byte array with the encoded data.</returns>
48
        internal static byte[] EncodeInitializeMintData(
49
            PublicKey mintAuthority, PublicKey freezeAuthority, int decimals, int freezeAuthorityOption)
50
        {
51
            byte[] methodBuffer = new byte[67];
4✔
52

53
            methodBuffer.WriteU8((byte)TokenProgramInstructions.Values.InitializeMint, MethodOffset);
4✔
54
            methodBuffer.WriteU8((byte)decimals, 1);
4✔
55
            methodBuffer.WritePubKey(mintAuthority, 2);
4✔
56
            methodBuffer.WriteU8((byte)freezeAuthorityOption, 34);
4✔
57
            methodBuffer.WritePubKey(freezeAuthority, 35);
4✔
58

59
            return methodBuffer;
4✔
60
        }
61

62
        /// <summary>
63
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.Transfer"/> method.
64
        /// </summary>
65
        /// <param name="amount">The amount of tokens.</param>
66
        /// <returns>The byte array with the encoded data.</returns>
67
        internal static byte[] EncodeTransferData(ulong amount)
68
            => EncodeAmountLayout((byte)TokenProgramInstructions.Values.Transfer, amount);
2✔
69

70
        /// <summary>
71
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.TransferChecked"/> method.
72
        /// </summary>
73
        /// <param name="amount">The amount of tokens.</param>
74
        /// <param name="decimals">The number of decimals of the token.</param>
75
        /// <returns>The byte array with the encoded data.</returns>
76
        internal static byte[] EncodeTransferCheckedData(ulong amount, int decimals)
77
            => EncodeAmountCheckedLayout((byte)TokenProgramInstructions.Values.TransferChecked, amount, (byte)decimals);
2✔
78

79
        /// <summary>
80
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.MintTo"/> method.
81
        /// </summary>
82
        /// <param name="amount">The amount of tokens.</param>
83
        /// <returns>The byte array with the encoded data.</returns>
84
        internal static byte[] EncodeMintToData(ulong amount)
85
            => EncodeAmountLayout((byte)TokenProgramInstructions.Values.MintTo, amount);
4✔
86

87
        /// <summary>
88
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.InitializeMultiSignature"/> method.
89
        /// </summary>
90
        /// <param name="m">The number of signers necessary to validate the account.</param>
91
        /// <returns>The byte array with the encoded data.</returns>
92
        internal static byte[] EncodeInitializeMultiSignatureData(int m)
93
        {
94
            byte[] methodBuffer = new byte[2];
1✔
95

96
            methodBuffer.WriteU8((byte)TokenProgramInstructions.Values.InitializeMultiSignature, MethodOffset);
1✔
97
            methodBuffer.WriteU8((byte)m, 1);
1✔
98

99
            return methodBuffer;
1✔
100
        }
101

102
        /// <summary>
103
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.SetAuthority"/> method.
104
        /// </summary>
105
        /// <returns>The byte array with the encoded data.</returns>
106
        internal static byte[] EncodeSetAuthorityData(AuthorityType authorityType, int newAuthorityOption,
107
            PublicKey newAuthority)
108
        {
109
            byte[] methodBuffer = new byte[35];
5✔
110

111
            methodBuffer.WriteU8((byte)TokenProgramInstructions.Values.SetAuthority, MethodOffset);
5✔
112
            methodBuffer.WriteU8((byte)authorityType, 1);
5✔
113
            methodBuffer.WriteU8((byte)newAuthorityOption, 2);
5✔
114
            methodBuffer.WritePubKey(newAuthority, 3);
5✔
115

116
            return methodBuffer;
5✔
117
        }
118

119
        /// <summary>
120
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.Burn"/> method.
121
        /// </summary>
122
        /// <param name="amount">The amount of tokens.</param>
123
        /// <returns>The byte array with the encoded data.</returns>
124
        internal static byte[] EncodeBurnData(ulong amount)
125
            => EncodeAmountLayout((byte)TokenProgramInstructions.Values.Burn, amount);
2✔
126

127
        /// <summary>
128
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.CloseAccount"/> method.
129
        /// </summary>
130
        /// <returns>The byte array with the encoded data.</returns>
131
        internal static byte[] EncodeCloseAccountData() => new[] { (byte)TokenProgramInstructions.Values.CloseAccount };
2✔
132

133
        /// <summary>
134
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.FreezeAccount"/> method.
135
        /// </summary>
136
        /// <returns>The byte array with the encoded data.</returns>
137
        internal static byte[] EncodeFreezeAccountData() =>
138
            new[] { (byte)TokenProgramInstructions.Values.FreezeAccount };
2✔
139

140
        /// <summary>
141
        /// Encode the transaction instruction data for the <see cref="TokenProgramInstructions.Values.ThawAccount"/> method.
142
        /// </summary>
143
        /// <returns>The byte array with the encoded data.</returns>
144
        internal static byte[] EncodeThawAccountData() => new[] { (byte)TokenProgramInstructions.Values.ThawAccount };
2✔
145

146
        /// <summary>
147
        /// Encodes the transaction instruction data for the <see cref="TokenProgramInstructions.Values.ApproveChecked"/> method.
148
        /// </summary>
149
        /// <param name="amount">The amount of tokens.</param>
150
        /// <param name="decimals">The decimals of the token.</param>
151
        /// <returns>The byte array with the encoded data.</returns>
152
        internal static byte[] EncodeApproveCheckedData(ulong amount, int decimals)
153
            => EncodeAmountCheckedLayout((byte)TokenProgramInstructions.Values.ApproveChecked, amount, (byte)decimals);
1✔
154

155
        /// <summary>
156
        /// Encodes the transaction instruction data for the <see cref="TokenProgramInstructions.Values.MintToChecked"/> method.
157
        /// </summary>
158
        /// <param name="amount">The amount of tokens.</param>
159
        /// <param name="decimals">The decimals of the token.</param>
160
        /// <returns>The byte array with the encoded data.</returns>
161
        internal static byte[] EncodeMintToCheckedData(ulong amount, int decimals)
162
            => EncodeAmountCheckedLayout((byte)TokenProgramInstructions.Values.MintToChecked, amount, (byte)decimals);
2✔
163

164
        /// <summary>
165
        /// Encodes the transaction instruction data for the <see cref="TokenProgramInstructions.Values.BurnChecked"/> method.
166
        /// </summary>
167
        /// <param name="amount">The amount of tokens.</param>
168
        /// <param name="decimals">The decimals of the token.</param>
169
        /// <returns>The byte array with the encoded data.</returns>
170
        internal static byte[] EncodeBurnCheckedData(ulong amount, int decimals)
171
            => EncodeAmountCheckedLayout((byte)TokenProgramInstructions.Values.BurnChecked, amount, (byte)decimals);
2✔
172

173
        /// <summary>
174
        /// Encodes the transaction instruction data for the <see cref="TokenProgramInstructions.Values.SyncNative"/> method.
175
        /// </summary>
176
        /// <returns>The byte array with the encoded data.</returns>
177
        internal static byte[] EncodeSyncNativeData() =>
178
            new[] { (byte) TokenProgramInstructions.Values.SyncNative };
1✔
179

180
        /// <summary>
181
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeMint"/> method
182
        /// </summary>
183
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
184
        /// <param name="data">The instruction data to decode.</param>
185
        /// <param name="keys">The account keys present in the transaction.</param>
186
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
187
        internal static void DecodeInitializeMintData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
188
            IList<PublicKey> keys, byte[] keyIndices)
189
        {
190
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
3✔
191
            decodedInstruction.Values.Add("Decimals", data.GetU8(1));
3✔
192
            decodedInstruction.Values.Add("Mint Authority", data.GetPubKey(2));
3✔
193

194
            var hasFreezeAuthority = data.GetBool(34);
3✔
195
            
196
            decodedInstruction.Values.Add("Freeze Authority Option", hasFreezeAuthority);
3✔
197
            if(hasFreezeAuthority)
3✔
198
                decodedInstruction.Values.Add("Freeze Authority", data.GetPubKey(35));
2✔
199
        }
3✔
200

201
        /// <summary>
202
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeAccount"/> method
203
        /// </summary>
204
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
205
        /// <param name="keys">The account keys present in the transaction.</param>
206
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
207
        internal static void DecodeInitializeAccountData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
208
            byte[] keyIndices)
209
        {
210
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
9✔
211
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
9✔
212
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
9✔
213
        }
9✔
214

215
        /// <summary>
216
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeMultiSignature"/> method
217
        /// </summary>
218
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
219
        /// <param name="data">The instruction data to decode.</param>
220
        /// <param name="keys">The account keys present in the transaction.</param>
221
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
222
        internal static void DecodeInitializeMultiSignatureData(DecodedInstruction decodedInstruction,
223
            ReadOnlySpan<byte> data, IList<PublicKey> keys, byte[] keyIndices)
224
        {
225
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
1✔
226
            byte numSigners = data.GetU8(1);
1✔
227
            decodedInstruction.Values.Add("Required Signers", numSigners);
1✔
228
            for (int i = 2; i < keyIndices.Length; i++)
12✔
229
            {
230
                decodedInstruction.Values.Add($"Signer {i - 1}", keys[keyIndices[i]]);
5✔
231
            }
232
        }
1✔
233

234
        /// <summary>
235
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.Transfer"/> method
236
        /// </summary>
237
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
238
        /// <param name="data">The instruction data to decode.</param>
239
        /// <param name="keys">The account keys present in the transaction.</param>
240
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
241
        internal static void DecodeTransferData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
242
            IList<PublicKey> keys, byte[] keyIndices)
243
        {
244
            decodedInstruction.Values.Add("Source", keys[keyIndices[0]]);
8✔
245
            decodedInstruction.Values.Add("Destination", keys[keyIndices[1]]);
8✔
246
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
8✔
247
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
8✔
248
            for (int i = 3; i < keyIndices.Length; i++)
22✔
249
            {
250
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
251
            }
252
        }
8✔
253

254
        /// <summary>
255
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.Approve"/> method
256
        /// </summary>
257
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
258
        /// <param name="data">The instruction data to decode.</param>
259
        /// <param name="keys">The account keys present in the transaction.</param>
260
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
261
        internal static void DecodeApproveData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
262
            IList<PublicKey> keys, byte[] keyIndices)
263
        {
264
            decodedInstruction.Values.Add("Source", keys[keyIndices[0]]);
1✔
265
            decodedInstruction.Values.Add("Delegate", keys[keyIndices[1]]);
1✔
266
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
1✔
267
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
1✔
268
            for (int i = 3; i < keyIndices.Length; i++)
8✔
269
            {
270
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
271
            }
272
        }
1✔
273

274
        /// <summary>
275
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.Revoke"/> method
276
        /// </summary>
277
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
278
        /// <param name="keys">The account keys present in the transaction.</param>
279
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
280
        internal static void DecodeRevokeData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
281
            byte[] keyIndices)
282
        {
283
            decodedInstruction.Values.Add("Source", keys[keyIndices[0]]);
1✔
284
            decodedInstruction.Values.Add("Authority", keys[keyIndices[1]]);
1✔
285
            for (int i = 2; i < keyIndices.Length; i++)
8✔
286
            {
287
                decodedInstruction.Values.Add($"Signer {i - 1}", keys[keyIndices[i]]);
3✔
288
            }
289
        }
1✔
290

291
        /// <summary>
292
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.SetAuthority"/> method
293
        /// </summary>
294
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
295
        /// <param name="data">The instruction data to decode.</param>
296
        /// <param name="keys">The account keys present in the transaction.</param>
297
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
298
        internal static void DecodeSetAuthorityData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
299
            IList<PublicKey> keys, byte[] keyIndices)
300
        {
301
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
1✔
302
            decodedInstruction.Values.Add("Current Authority", keys[keyIndices[1]]);
1✔
303
            decodedInstruction.Values.Add("Authority Type", Enum.Parse(typeof(AuthorityType), data.GetU8(1).ToString()));
1✔
304
            decodedInstruction.Values.Add("New Authority Option", data.GetU8(2));
1✔
305
            if (data.Length >= 34)
1✔
306
            {
307
                decodedInstruction.Values.Add("New Authority", data.GetPubKey(3));
1✔
308
            }
309
            for (int i = 2; i < keyIndices.Length; i++)
8✔
310
            {
311
                decodedInstruction.Values.Add($"Signer {i - 1}", keys[keyIndices[i]]);
3✔
312
            }
313
        }
1✔
314

315
        /// <summary>
316
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.MintTo"/> method
317
        /// </summary>
318
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
319
        /// <param name="data">The instruction data to decode.</param>
320
        /// <param name="keys">The account keys present in the transaction.</param>
321
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
322
        internal static void DecodeMintToData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
323
            IList<PublicKey> keys, byte[] keyIndices)
324
        {
325
            decodedInstruction.Values.Add("Mint", keys[keyIndices[0]]);
4✔
326
            decodedInstruction.Values.Add("Destination", keys[keyIndices[1]]);
4✔
327
            decodedInstruction.Values.Add("Mint Authority", keys[keyIndices[2]]);
4✔
328
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
4✔
329
            for (int i = 3; i < keyIndices.Length; i++)
20✔
330
            {
331
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
6✔
332
            }
333
        }
4✔
334

335
        /// <summary>
336
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.Burn"/> method
337
        /// </summary>
338
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
339
        /// <param name="data">The instruction data to decode.</param>
340
        /// <param name="keys">The account keys present in the transaction.</param>
341
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
342
        internal static void DecodeBurnData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
343
            IList<PublicKey> keys, byte[] keyIndices)
344
        {
345
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
2✔
346
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
2✔
347
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
2✔
348
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
2✔
349
            for (int i = 3; i < keyIndices.Length; i++)
10✔
350
            {
351
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
352
            }
353
        }
2✔
354

355
        /// <summary>
356
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.CloseAccount"/> method
357
        /// </summary>
358
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
359
        /// <param name="keys">The account keys present in the transaction.</param>
360
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
361
        internal static void DecodeCloseAccountData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
362
            byte[] keyIndices)
363
        {
364
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
3✔
365
            decodedInstruction.Values.Add("Destination", keys[keyIndices[1]]);
3✔
366
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
3✔
367
            for (int i = 3; i < keyIndices.Length; i++)
12✔
368
            {
369
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
370
            }
371
        }
3✔
372

373
        /// <summary>
374
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.FreezeAccount"/> method
375
        /// </summary>
376
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
377
        /// <param name="keys">The account keys present in the transaction.</param>
378
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
379
        internal static void DecodeFreezeAccountData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
380
            byte[] keyIndices)
381
        {
382
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
1✔
383
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
1✔
384
            decodedInstruction.Values.Add("Freeze Authority", keys[keyIndices[2]]);
1✔
385
            for (int i = 3; i < keyIndices.Length; i++)
8✔
386
            {
387
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
388
            }
389
        }
1✔
390

391
        /// <summary>
392
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.ThawAccount"/> method
393
        /// </summary>
394
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
395
        /// <param name="keys">The account keys present in the transaction.</param>
396
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
397
        internal static void DecodeThawAccountData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
398
            byte[] keyIndices)
399
        {
400
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
1✔
401
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
1✔
402
            decodedInstruction.Values.Add("Freeze Authority", keys[keyIndices[2]]);
1✔
403
            for (int i = 3; i < keyIndices.Length; i++)
8✔
404
            {
405
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
3✔
406
            }
407
        }
1✔
408

409
        /// <summary>
410
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.TransferChecked"/> method
411
        /// </summary>
412
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
413
        /// <param name="data">The instruction data to decode.</param>
414
        /// <param name="keys">The account keys present in the transaction.</param>
415
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
416
        internal static void DecodeTransferCheckedData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
417
            IList<PublicKey> keys, byte[] keyIndices)
418
        {
419
            decodedInstruction.Values.Add("Source", keys[keyIndices[0]]);
3✔
420
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
3✔
421
            decodedInstruction.Values.Add("Destination", keys[keyIndices[2]]);
3✔
422
            decodedInstruction.Values.Add("Authority", keys[keyIndices[3]]);
3✔
423
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
3✔
424
            decodedInstruction.Values.Add("Decimals", data.GetU8(9));
3✔
425
            for (int i = 4; i < keyIndices.Length; i++)
12✔
426
            {
427
                decodedInstruction.Values.Add($"Signer {i - 3}", keys[keyIndices[i]]);
3✔
428
            }
429
        }
3✔
430

431
        /// <summary>
432
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.ApproveChecked"/> method
433
        /// </summary>
434
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
435
        /// <param name="data">The instruction data to decode.</param>
436
        /// <param name="keys">The account keys present in the transaction.</param>
437
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
438
        internal static void DecodeApproveCheckedData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
439
            IList<PublicKey> keys, byte[] keyIndices)
440
        {
441
            decodedInstruction.Values.Add("Source", keys[keyIndices[0]]);
1✔
442
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
1✔
443
            decodedInstruction.Values.Add("Delegate", keys[keyIndices[2]]);
1✔
444
            decodedInstruction.Values.Add("Authority", keys[keyIndices[3]]);
1✔
445
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
1✔
446
            decodedInstruction.Values.Add("Decimals", data.GetU8(9));
1✔
447
            for (int i = 4; i < keyIndices.Length; i++)
8✔
448
            {
449
                decodedInstruction.Values.Add($"Signer {i - 3}", keys[keyIndices[i]]);
3✔
450
            }
451
        }
1✔
452

453
        /// <summary>
454
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.MintToChecked"/> method
455
        /// </summary>
456
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
457
        /// <param name="data">The instruction data to decode.</param>
458
        /// <param name="keys">The account keys present in the transaction.</param>
459
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
460
        internal static void DecodeMintToCheckedData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
461
            IList<PublicKey> keys, byte[] keyIndices)
462
        {
463
            decodedInstruction.Values.Add("Mint", keys[keyIndices[0]]);
2✔
464
            decodedInstruction.Values.Add("Destination", keys[keyIndices[1]]);
2✔
465
            decodedInstruction.Values.Add("Mint Authority", keys[keyIndices[2]]);
2✔
466
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
2✔
467
            decodedInstruction.Values.Add("Decimals", data.GetU8(9));
2✔
468
            for (int i = 3; i < keyIndices.Length; i++)
16✔
469
            {
470
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
6✔
471
            }
472
        }
2✔
473

474
        /// <summary>
475
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.BurnChecked"/> method
476
        /// </summary>
477
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
478
        /// <param name="data">The instruction data to decode.</param>
479
        /// <param name="keys">The account keys present in the transaction.</param>
480
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
481
        internal static void DecodeBurnCheckedData(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
482
            IList<PublicKey> keys, byte[] keyIndices)
483
        {
484
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
3✔
485
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
3✔
486
            decodedInstruction.Values.Add("Authority", keys[keyIndices[2]]);
3✔
487
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
3✔
488
            decodedInstruction.Values.Add("Decimals", data.GetU8(9));
3✔
489
            for (int i = 3; i < keyIndices.Length; i++)
18✔
490
            {
491
                decodedInstruction.Values.Add($"Signer {i - 2}", keys[keyIndices[i]]);
6✔
492
            }
493
        }
3✔
494

495
        /// <summary>
496
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.SyncNative"/> method
497
        /// </summary>
498
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
499
        /// <param name="keys">The account keys present in the transaction.</param>
500
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
501
        internal static void DecodeSyncNativeData(DecodedInstruction decodedInstruction, IList<PublicKey> keys,
502
            byte[] keyIndices)
503
        {
504
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
×
505
        }
×
506

507
        /// <summary>
508
        /// Encodes the transaction instruction data for the methods which only require the amount.
509
        /// </summary>
510
        /// <param name="method">The method identifier.</param>
511
        /// <param name="amount">The amount of tokens.</param>
512
        /// <returns>The byte array with the encoded data.</returns>
513
        private static byte[] EncodeAmountLayout(byte method, ulong amount)
514
        {
515
            byte[] methodBuffer = new byte[9];
11✔
516

517
            methodBuffer.WriteU8(method, MethodOffset);
11✔
518
            methodBuffer.WriteU64(amount, 1);
11✔
519

520
            return methodBuffer;
11✔
521
        }
522

523
        /// <summary>
524
        /// Encodes the transaction instruction data for the methods which only require the amount and the number of decimals.
525
        /// </summary>
526
        /// <param name="method">The method identifier.</param>
527
        /// <param name="amount">The amount of tokens.</param>
528
        /// <param name="decimals">The decimals of the token.</param>
529
        /// <returns>The byte array with the encoded data.</returns>
530
        private static byte[] EncodeAmountCheckedLayout(byte method, ulong amount, byte decimals)
531
        {
532
            byte[] methodBuffer = new byte[10];
7✔
533

534
            methodBuffer.WriteU8(method, MethodOffset);
7✔
535
            methodBuffer.WriteU64(amount, 1);
7✔
536
            methodBuffer.WriteU8(decimals, 9);
7✔
537

538
            return methodBuffer;
7✔
539
        }
540

541

542
        /// <summary>
543
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeAccount2"/> method
544
        /// </summary>
545
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
546
        /// <param name="data">The instruction data to decode.</param>
547
        /// <param name="keys">The account keys present in the transaction.</param>
548
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
549
        internal static void DecodeInitializeAccount2(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data, IList<PublicKey> keys, byte[] keyIndices)
550
        {
551
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
×
552
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
×
553
            decodedInstruction.Values.Add("Authority", data.GetPubKey(1));
×
554
        }
×
555

556

557
        /// <summary>
558
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeAccount3"/> method
559
        /// </summary>
560
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
561
        /// <param name="data">The instruction data to decode.</param>
562
        /// <param name="keys">The account keys present in the transaction.</param>
563
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
564
        internal static void DecodeInitializeAccount3(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data, IList<PublicKey> keys, byte[] keyIndices)
565
        {
566
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
1✔
567
            decodedInstruction.Values.Add("Mint", keys[keyIndices[1]]);
1✔
568
            decodedInstruction.Values.Add("Authority", data.GetPubKey(1));
1✔
569
        }
1✔
570

571
        /// <summary>
572
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeMultiSignature2"/> method
573
        /// </summary>
574
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
575
        /// <param name="data">The instruction data to decode.</param>
576
        /// <param name="keys">The account keys present in the transaction.</param>
577
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
578
        internal static void DecodeInitializeMultiSignature2(DecodedInstruction decodedInstruction,
579
            ReadOnlySpan<byte> data, IList<PublicKey> keys, byte[] keyIndices)
580
        {
581
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
×
582
            byte numSigners = data.GetU8(1);
×
583
            decodedInstruction.Values.Add("Required Signers", numSigners);
×
584
            for (int i = 1; i < keyIndices.Length; i++)
×
585
            {
586
                decodedInstruction.Values.Add($"Signer {i - 1}", keys[keyIndices[i]]);
×
587
            }
588
        }
×
589

590
        /// <summary>
591
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.InitializeMint2"/> method
592
        /// </summary>
593
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
594
        /// <param name="data">The instruction data to decode.</param>
595
        /// <param name="keys">The account keys present in the transaction.</param>
596
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
597
        internal static void DecodeInitializeMint2(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
598
            IList<PublicKey> keys, byte[] keyIndices)
599
        {
600
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
×
601
            decodedInstruction.Values.Add("Decimals", data.GetU8(1));
×
602
            decodedInstruction.Values.Add("Mint Authority", data.GetPubKey(2));
×
603

604
            var hasFreezeAuthority = data.GetBool(34);
×
605

606
            decodedInstruction.Values.Add("Freeze Authority Option", hasFreezeAuthority);
×
607
            if (hasFreezeAuthority)
×
608
                decodedInstruction.Values.Add("Freeze Authority", data.GetPubKey(35));
×
609
        }
×
610

611
        /// <summary>
612
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.AmountToUiAmount"/> method
613
        /// </summary>
614
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
615
        /// <param name="data">The instruction data to decode.</param>
616
        /// <param name="keys">The account keys present in the transaction.</param>
617
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
618
        internal static void DecodeAmountToUiAmount(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
619
            IList<PublicKey> keys, byte[] keyIndices)
620
        {
621
            decodedInstruction.Values.Add("Mint", keys[keyIndices[0]]);
×
622
            decodedInstruction.Values.Add("Amount", data.GetU64(1));
×
623
        }
×
624

625
        /// <summary>
626
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.UiAmountToAmount"/> method
627
        /// </summary>
628
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
629
        /// <param name="data">The instruction data to decode.</param>
630
        /// <param name="keys">The account keys present in the transaction.</param>
631
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
632
        internal static void DecodeUiAmountToAmount(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
633
            IList<PublicKey> keys, byte[] keyIndices)
634
        {
635
            decodedInstruction.Values.Add("Mint", keys[keyIndices[0]]);
×
636
            decodedInstruction.Values.Add("Amount", data.DecodeBincodeString(1).EncodedString);
×
637
        }
×
638

639
        /// <summary>
640
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.UiAmountToAmount"/> method
641
        /// </summary>
642
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
643
        /// <param name="data">The instruction data to decode.</param>
644
        /// <param name="keys">The account keys present in the transaction.</param>
645
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
646
        internal static void DecodeGetAccountDataSize(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
647
            IList<PublicKey> keys, byte[] keyIndices)
648
        {
649
            decodedInstruction.Values.Add("Mint", keys[keyIndices[0]]);
×
650
        }
×
651

652
        /// <summary>
653
        /// Decodes the instruction instruction data  for the <see cref="TokenProgramInstructions.Values.UiAmountToAmount"/> method
654
        /// </summary>
655
        /// <param name="decodedInstruction">The decoded instruction to add data to.</param>
656
        /// <param name="data">The instruction data to decode.</param>
657
        /// <param name="keys">The account keys present in the transaction.</param>
658
        /// <param name="keyIndices">The indices of the account keys for the instruction as they appear in the transaction.</param>
659
        internal static void DecodeInitializeImmutableOwner(DecodedInstruction decodedInstruction, ReadOnlySpan<byte> data,
660
            IList<PublicKey> keys, byte[] keyIndices)
661
        {
662
            decodedInstruction.Values.Add("Account", keys[keyIndices[0]]);
×
663
        }
×
664
    }
665
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc