#pragma warning disable CS8600 #pragma warning disable CS8604 #pragma warning disable CS8618 #pragma warning disable CS8603 #pragma warning disable CS8625 using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Threading.Tasks; using Solana.Unity; using Solana.Unity.Programs.Abstract; using Solana.Unity.Programs.Utilities; using Solana.Unity.Rpc; using Solana.Unity.Rpc.Builders; using Solana.Unity.Rpc.Core.Http; using Solana.Unity.Rpc.Core.Sockets; using Solana.Unity.Rpc.Types; using Solana.Unity.Wallet; using Velocity; using Velocity.Program; using Velocity.Errors; using Velocity.Accounts; using Velocity.Types; namespace Velocity { namespace Accounts { public partial class Entity { public static ulong ACCOUNT_DISCRIMINATOR => 1751670451238706478UL; public static ReadOnlySpan ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{46, 157, 161, 161, 254, 46, 79, 24}; public static string ACCOUNT_DISCRIMINATOR_B58 => "8oEQa6zH67R"; public ulong Id { get; set; } public static Entity Deserialize(ReadOnlySpan _data) { int offset = 0; ulong accountHashValue = _data.GetU64(offset); offset += 8; if (accountHashValue != ACCOUNT_DISCRIMINATOR) { return null; } Entity result = new Entity(); result.Id = _data.GetU64(offset); offset += 8; return result; } } public partial class SessionToken { public static ulong ACCOUNT_DISCRIMINATOR => 1081168673100727529UL; public static ReadOnlySpan ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{233, 4, 115, 14, 46, 21, 1, 15}; public static string ACCOUNT_DISCRIMINATOR_B58 => "fyZWTdUu1pS"; public PublicKey Authority { get; set; } public PublicKey TargetProgram { get; set; } public PublicKey SessionSigner { get; set; } public long ValidUntil { get; set; } public static SessionToken Deserialize(ReadOnlySpan _data) { int offset = 0; ulong accountHashValue = _data.GetU64(offset); offset += 8; if (accountHashValue != ACCOUNT_DISCRIMINATOR) { return null; } SessionToken result = new SessionToken(); result.Authority = _data.GetPubKey(offset); offset += 32; result.TargetProgram = _data.GetPubKey(offset); offset += 32; result.SessionSigner = _data.GetPubKey(offset); offset += 32; result.ValidUntil = _data.GetS64(offset); offset += 8; return result; } } public partial class Velocity { public static ulong ACCOUNT_DISCRIMINATOR => 17932774833452681865UL; public static ReadOnlySpan ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{137, 10, 3, 249, 178, 3, 222, 248}; public static string ACCOUNT_DISCRIMINATOR_B58 => "PvTAh7RLish"; public long X { get; set; } public long Y { get; set; } public long Z { get; set; } public long LastApplied { get; set; } public string Description { get; set; } public BoltMetadata BoltMetadata { get; set; } public static Velocity Deserialize(ReadOnlySpan _data) { int offset = 0; ulong accountHashValue = _data.GetU64(offset); offset += 8; if (accountHashValue != ACCOUNT_DISCRIMINATOR) { return null; } Velocity result = new Velocity(); result.X = _data.GetS64(offset); offset += 8; result.Y = _data.GetS64(offset); offset += 8; result.Z = _data.GetS64(offset); offset += 8; result.LastApplied = _data.GetS64(offset); offset += 8; offset += _data.GetBorshString(offset, out var resultDescription); result.Description = resultDescription; offset += BoltMetadata.Deserialize(_data, offset, out var resultBoltMetadata); result.BoltMetadata = resultBoltMetadata; return result; } } } namespace Errors { public enum VelocityErrorKind : uint { } } namespace Types { public partial class BoltMetadata { public PublicKey Authority { get; set; } public int Serialize(byte[] _data, int initialOffset) { int offset = initialOffset; _data.WritePubKey(Authority, offset); offset += 32; return offset - initialOffset; } public static int Deserialize(ReadOnlySpan _data, int initialOffset, out BoltMetadata result) { int offset = initialOffset; result = new BoltMetadata(); result.Authority = _data.GetPubKey(offset); offset += 32; return offset - initialOffset; } } } public partial class VelocityClient : TransactionalBaseClient { public VelocityClient(IRpcClient rpcClient, IStreamingRpcClient streamingRpcClient, PublicKey programId = null) : base(rpcClient, streamingRpcClient, programId ?? new PublicKey(VelocityProgram.ID)) { } public async Task>> GetEntitysAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed) { var list = new List{new Solana.Unity.Rpc.Models.MemCmp{Bytes = Entity.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}}; var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list); if (!res.WasSuccessful || !(res.Result?.Count > 0)) return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res); List resultingAccounts = new List(res.Result.Count); resultingAccounts.AddRange(res.Result.Select(result => Entity.Deserialize(Convert.FromBase64String(result.Account.Data[0])))); return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res, resultingAccounts); } public async Task>> GetSessionTokensAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed) { var list = new List{new Solana.Unity.Rpc.Models.MemCmp{Bytes = SessionToken.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}}; var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list); if (!res.WasSuccessful || !(res.Result?.Count > 0)) return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res); List resultingAccounts = new List(res.Result.Count); resultingAccounts.AddRange(res.Result.Select(result => SessionToken.Deserialize(Convert.FromBase64String(result.Account.Data[0])))); return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res, resultingAccounts); } public async Task>> GetVelocitysAsync(string programAddress = VelocityProgram.ID, Commitment commitment = Commitment.Confirmed) { var list = new List{new Solana.Unity.Rpc.Models.MemCmp{Bytes = Velocity.Accounts.Velocity.ACCOUNT_DISCRIMINATOR_B58, Offset = 0}}; var res = await RpcClient.GetProgramAccountsAsync(programAddress, commitment, memCmpList: list); if (!res.WasSuccessful || !(res.Result?.Count > 0)) return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res); List resultingAccounts = new List(res.Result.Count); resultingAccounts.AddRange(res.Result.Select(result => Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(result.Account.Data[0])))); return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res, resultingAccounts); } public async Task> GetEntityAsync(string accountAddress, Commitment commitment = Commitment.Finalized) { var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment); if (!res.WasSuccessful) return new Solana.Unity.Programs.Models.AccountResultWrapper(res); var resultingAccount = Entity.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0])); return new Solana.Unity.Programs.Models.AccountResultWrapper(res, resultingAccount); } public async Task> GetSessionTokenAsync(string accountAddress, Commitment commitment = Commitment.Finalized) { var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment); if (!res.WasSuccessful) return new Solana.Unity.Programs.Models.AccountResultWrapper(res); var resultingAccount = SessionToken.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0])); return new Solana.Unity.Programs.Models.AccountResultWrapper(res, resultingAccount); } public async Task> GetVelocityAsync(string accountAddress, Commitment commitment = Commitment.Finalized) { var res = await RpcClient.GetAccountInfoAsync(accountAddress, commitment); if (!res.WasSuccessful) return new Solana.Unity.Programs.Models.AccountResultWrapper(res); var resultingAccount = Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(res.Result.Value.Data[0])); return new Solana.Unity.Programs.Models.AccountResultWrapper(res, resultingAccount); } public async Task SubscribeEntityAsync(string accountAddress, Action, Entity> callback, Commitment commitment = Commitment.Finalized) { SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) => { Entity parsingResult = null; if (e.Value?.Data?.Count > 0) parsingResult = Entity.Deserialize(Convert.FromBase64String(e.Value.Data[0])); callback(s, e, parsingResult); }, commitment); return res; } public async Task SubscribeSessionTokenAsync(string accountAddress, Action, SessionToken> callback, Commitment commitment = Commitment.Finalized) { SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) => { SessionToken parsingResult = null; if (e.Value?.Data?.Count > 0) parsingResult = SessionToken.Deserialize(Convert.FromBase64String(e.Value.Data[0])); callback(s, e, parsingResult); }, commitment); return res; } public async Task SubscribeVelocityAsync(string accountAddress, Action, Velocity.Accounts.Velocity> callback, Commitment commitment = Commitment.Finalized) { SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) => { Velocity.Accounts.Velocity parsingResult = null; if (e.Value?.Data?.Count > 0) parsingResult = Velocity.Accounts.Velocity.Deserialize(Convert.FromBase64String(e.Value.Data[0])); callback(s, e, parsingResult); }, commitment); return res; } protected override Dictionary> BuildErrorsDictionary() { return new Dictionary>{}; } } namespace Program { public class InitializeAccounts { public PublicKey Payer { get; set; } public PublicKey Data { get; set; } public PublicKey Entity { get; set; } public PublicKey Authority { get; set; } public PublicKey InstructionSysvarAccount { get; set; } = new PublicKey("Sysvar1nstructions1111111111111111111111111"); public PublicKey SystemProgram { get; set; } = new PublicKey("11111111111111111111111111111111"); } public class UpdateAccounts { public PublicKey BoltComponent { get; set; } public PublicKey Authority { get; set; } public PublicKey InstructionSysvarAccount { get; set; } = new PublicKey("Sysvar1nstructions1111111111111111111111111"); public PublicKey SessionToken { get; set; } } public static class VelocityProgram { public const string ID = "CbHEFbSQdRN4Wnoby9r16umnJ1zWbULBHg4yqzGQonU1"; public static Solana.Unity.Rpc.Models.TransactionInstruction Initialize(InitializeAccounts accounts, PublicKey programId = null) { programId ??= new(ID); List keys = new() {Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Payer, true), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Data, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Entity, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.InstructionSysvarAccount, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)}; byte[] _data = new byte[1200]; int offset = 0; _data.WriteU64(17121445590508351407UL, offset); offset += 8; byte[] resultData = new byte[offset]; Array.Copy(_data, resultData, offset); return new Solana.Unity.Rpc.Models.TransactionInstruction{Keys = keys, ProgramId = programId.KeyBytes, Data = resultData}; } public static Solana.Unity.Rpc.Models.TransactionInstruction Update(UpdateAccounts accounts, byte[] data, PublicKey programId = null) { programId ??= new(ID); List keys = new() {Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.BoltComponent, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Authority, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.InstructionSysvarAccount, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SessionToken == null ? programId : accounts.SessionToken, false)}; byte[] _data = new byte[1200]; int offset = 0; _data.WriteU64(9222597562720635099UL, offset); offset += 8; _data.WriteS32(data.Length, offset); offset += 4; _data.WriteSpan(data, offset); offset += data.Length; byte[] resultData = new byte[offset]; Array.Copy(_data, resultData, offset); return new Solana.Unity.Rpc.Models.TransactionInstruction{Keys = keys, ProgramId = programId.KeyBytes, Data = resultData}; } } } }