spb/os-vault Public
Self-custody, multi-chain crypto wallet for macOS. One recovery phrase, six chain families, zero API keys — nothing leaves your Mac.
Swift 96%
Shell 3.4%
Makefile 0.6%
1import Foundation23public enum LookUpTableProgram {4 public static var id: PublicKey {5 "AddressLookupTab1e1111111111111111111111111"6 }78 public static func createLookupTable(9 authority: PublicKey,10 payer: PublicKey,11 recentSlot: UInt6412 ) throws -> (TransactionInstruction, PublicKey) {13 let (lookupTableAddress, bump) = try PublicKey.findProgramAddress(14 seeds: [15 authority.data,16 Data(recentSlot.bytes),17 ],18 programId: id19 )2021 return (22 TransactionInstruction(23 keys: [24 .init(publicKey: lookupTableAddress, isSigner: false, isWritable: true),25 .init(publicKey: authority, isSigner: true, isWritable: false),26 .init(publicKey: payer, isSigner: true, isWritable: true),27 .init(publicKey: SystemProgram.id, isSigner: false, isWritable: false),28 ],29 programId: id,30 data: [31 UInt32(0),32 recentSlot,33 bump,34 ]35 ),36 lookupTableAddress37 )38 }3940 public static func extendLookupTable(41 lookupTable: PublicKey,42 authority: PublicKey,43 payer: PublicKey?,44 addresses: [PublicKey]45 ) -> TransactionInstruction {46 var keys: [AccountMeta] = [47 .init(publicKey: lookupTable, isSigner: false, isWritable: true),48 .init(publicKey: authority, isSigner: true, isWritable: false),49 ]5051 if let payer = payer {52 keys.append(contentsOf: [53 .init(publicKey: payer, isSigner: true, isWritable: true),54 .init(publicKey: SystemProgram.id, isSigner: false, isWritable: false),55 ])56 }5758 return TransactionInstruction(59 keys: keys,60 programId: id,61 data: [62 UInt32(2),63 UInt64(addresses.count),64 addresses.map { $0.bytes }.reduce([], +),65 ]66 )67 }6869 public static func closeLookupTable(70 lookupTable: PublicKey,71 authority: PublicKey,72 recipient: PublicKey73 ) -> TransactionInstruction {74 return TransactionInstruction(75 keys: [76 .init(publicKey: lookupTable, isSigner: false, isWritable: true),77 .init(publicKey: authority, isSigner: true, isWritable: false),78 .init(publicKey: recipient, isSigner: false, isWritable: true),79 ],80 programId: id,81 data: [UInt32(4)]82 )83 }84}85