|
| 1 | +using System.Collections.Generic; |
| 2 | +using Solnet.Rpc.Models; |
| 3 | +using Solnet.Wallet; |
| 4 | + |
| 5 | +namespace Solnet.Programs |
| 6 | +{ |
| 7 | + public static class AddressLookupTableProgram |
| 8 | + { |
| 9 | + /// <summary> |
| 10 | + /// The public key of the ATL Program. |
| 11 | + /// </summary> |
| 12 | + public static readonly PublicKey ProgramIdKey = new("AddressLookupTab1e1111111111111111111111111"); |
| 13 | + |
| 14 | + /// <summary> |
| 15 | + /// The program's name. |
| 16 | + /// </summary> |
| 17 | + private const string ProgramName = "Address Lookup Table Program"; |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Create New Address Lookup Table Instruction |
| 21 | + /// </summary> |
| 22 | + /// <param name="Authority"></param> |
| 23 | + /// <param name="Payer"></param> |
| 24 | + /// <param name="RecentSlot"></param> |
| 25 | + /// <returns></returns> |
| 26 | + public static TransactionInstruction CreateAddressLookupTable( |
| 27 | + PublicKey Authority, PublicKey Payer, PublicKey ALT,byte bump, ulong RecentSlot) |
| 28 | + { |
| 29 | + //byte[] recentSlotBytes = BitConverter.GetBytes(RecentSlot); |
| 30 | + //byte[] seed = Authority.KeyBytes.Concat(recentSlotBytes).ToArray(); |
| 31 | + //PublicKey.TryFindProgramAddress(new List<byte[]> { seed }, ProgramIdKey, out PublicKey ALTaddress, out byte bump); |
| 32 | + |
| 33 | + List<AccountMeta> keys = new() |
| 34 | + { |
| 35 | + AccountMeta.Writable(ALT, false), |
| 36 | + AccountMeta.ReadOnly(Authority, false), |
| 37 | + AccountMeta.Writable(Payer, true), |
| 38 | + AccountMeta.ReadOnly(SystemProgram.ProgramIdKey, false) |
| 39 | + }; |
| 40 | + return new TransactionInstruction |
| 41 | + { |
| 42 | + ProgramId = ProgramIdKey.KeyBytes, |
| 43 | + Keys = keys, |
| 44 | + Data = AddressLookupTableProgramData.EncodeCreateAddressLookupTableData(RecentSlot, bump) |
| 45 | + }; |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Freeze Lookup Table Instruction |
| 50 | + /// </summary> |
| 51 | + /// <param name="LookupTable"></param> |
| 52 | + /// <param name="Authority"></param> |
| 53 | + /// <returns></returns> |
| 54 | + public static TransactionInstruction FreezeLookupTable(PublicKey LookupTable, PublicKey Authority) |
| 55 | + { |
| 56 | + List<AccountMeta> keys = new() |
| 57 | + { |
| 58 | + AccountMeta.Writable(LookupTable, false), |
| 59 | + AccountMeta.ReadOnly(Authority, true) |
| 60 | + }; |
| 61 | + return new TransactionInstruction |
| 62 | + { |
| 63 | + ProgramId = ProgramIdKey.KeyBytes, |
| 64 | + Keys = keys, |
| 65 | + Data = AddressLookupTableProgramData.EncodeFreezeLookupTableData() |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Extend Lookup Table Instruction |
| 71 | + /// </summary> |
| 72 | + /// <param name="LookupTable"></param> |
| 73 | + /// <param name="Authority"></param> |
| 74 | + /// <param name="Payer"></param> |
| 75 | + /// <param name="keys"></param> |
| 76 | + /// <returns></returns> |
| 77 | + public static TransactionInstruction ExtendLookupTable(PublicKey LookupTable, PublicKey Authority, PublicKey Payer, List<PublicKey> keys) |
| 78 | + { |
| 79 | + List<AccountMeta> meta = new() |
| 80 | + { |
| 81 | + AccountMeta.Writable(LookupTable, false), |
| 82 | + AccountMeta.ReadOnly(Authority, true), |
| 83 | + AccountMeta.Writable(Payer, true), |
| 84 | + AccountMeta.ReadOnly(SystemProgram.ProgramIdKey, false) |
| 85 | + }; |
| 86 | + return new TransactionInstruction |
| 87 | + { |
| 88 | + ProgramId = ProgramIdKey.KeyBytes, |
| 89 | + Keys = meta, |
| 90 | + Data = AddressLookupTableProgramData.EncodeExtendLookupTableData((ulong)keys.Count, keys) |
| 91 | + }; |
| 92 | + } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Deactivate Lookup Table Instruction |
| 96 | + /// </summary> |
| 97 | + /// <param name="LookupTable"></param> |
| 98 | + /// <param name="Authority"></param> |
| 99 | + /// <returns></returns> |
| 100 | + public static TransactionInstruction DeactivateLookupTable(PublicKey LookupTable, PublicKey Authority) |
| 101 | + { |
| 102 | + List<AccountMeta> keys = new() |
| 103 | + { |
| 104 | + AccountMeta.Writable(LookupTable, false), |
| 105 | + AccountMeta.ReadOnly(Authority, true) |
| 106 | + }; |
| 107 | + return new TransactionInstruction |
| 108 | + { |
| 109 | + ProgramId = ProgramIdKey.KeyBytes, |
| 110 | + Keys = keys, |
| 111 | + Data = AddressLookupTableProgramData.EncodeDeactivateLookupTableData() |
| 112 | + }; |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Close Lookup Table Instruction |
| 117 | + /// </summary> |
| 118 | + /// <param name="LookupTable"></param> |
| 119 | + /// <param name="Authority"></param> |
| 120 | + /// <param name="Recipient"></param> |
| 121 | + /// <returns></returns> |
| 122 | + public static TransactionInstruction CloseLookupTable(PublicKey LookupTable, PublicKey Authority, PublicKey Recipient) |
| 123 | + { |
| 124 | + List<AccountMeta> keys = new() |
| 125 | + { |
| 126 | + AccountMeta.Writable(LookupTable, false), |
| 127 | + AccountMeta.ReadOnly(Authority, true), |
| 128 | + AccountMeta.Writable(Recipient, false) |
| 129 | + }; |
| 130 | + return new TransactionInstruction |
| 131 | + { |
| 132 | + ProgramId = ProgramIdKey.KeyBytes, |
| 133 | + Keys = keys, |
| 134 | + Data = AddressLookupTableProgramData.EncodeCloseLookupTableData() |
| 135 | + }; |
| 136 | + } |
| 137 | + |
| 138 | + |
| 139 | + } |
| 140 | +} |
0 commit comments