#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 Position; using Position.Program; using Position.Errors; using Position.Accounts; using Position.Types; namespace Position { 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 Position { public static ulong ACCOUNT_DISCRIMINATOR => 15057574775701355690UL; public static ReadOnlySpan ACCOUNT_DISCRIMINATOR_BYTES => new byte[]{170, 188, 143, 228, 122, 64, 247, 208}; public static string ACCOUNT_DISCRIMINATOR_B58 => "VZMoMoKgZQb"; public long X { get; set; } public long Y { get; set; } public long Z { get; set; } public BoltMetadata BoltMetadata { get; set; } public static Position Deserialize(ReadOnlySpan _data) { int offset = 0; ulong accountHashValue = _data.GetU64(offset); offset += 8; if (accountHashValue != ACCOUNT_DISCRIMINATOR) { return null; } Position result = new Position(); result.X = _data.GetS64(offset); offset += 8; result.Y = _data.GetS64(offset); offset += 8; result.Z = _data.GetS64(offset); offset += 8; offset += BoltMetadata.Deserialize(_data, offset, out var resultBoltMetadata); result.BoltMetadata = resultBoltMetadata; 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; } } } namespace Errors { public enum PositionErrorKind : 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 PositionClient : TransactionalBaseClient { public PositionClient(IRpcClient rpcClient, IStreamingRpcClient streamingRpcClient, PublicKey programId = null) : base(rpcClient, streamingRpcClient, programId ?? new PublicKey(PositionProgram.ID)) { } public async Task>> GetEntitysAsync(string programAddress = PositionProgram.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>> GetPositionsAsync(string programAddress = PositionProgram.ID, Commitment commitment = Commitment.Confirmed) { var list = new List{new Solana.Unity.Rpc.Models.MemCmp{Bytes = Position.Accounts.Position.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 => Position.Accounts.Position.Deserialize(Convert.FromBase64String(result.Account.Data[0])))); return new Solana.Unity.Programs.Models.ProgramAccountsResultWrapper>(res, resultingAccounts); } public async Task>> GetSessionTokensAsync(string programAddress = PositionProgram.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> 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> GetPositionAsync(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 = Position.Accounts.Position.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 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 SubscribePositionAsync(string accountAddress, Action, Position.Accounts.Position> callback, Commitment commitment = Commitment.Finalized) { SubscriptionState res = await StreamingRpcClient.SubscribeAccountInfoAsync(accountAddress, (s, e) => { Position.Accounts.Position parsingResult = null; if (e.Value?.Data?.Count > 0) parsingResult = Position.Accounts.Position.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; } protected override Dictionary> BuildErrorsDictionary() { return new Dictionary>{}; } } namespace Program { public class DelegateAccounts { public PublicKey Payer { get; set; } public PublicKey Entity { get; set; } public PublicKey Account { get; set; } public PublicKey OwnerProgram { get; set; } public PublicKey Buffer { get; set; } public PublicKey DelegationRecord { get; set; } public PublicKey DelegationMetadata { get; set; } public PublicKey DelegationProgram { get; set; } public PublicKey SystemProgram { get; set; } } 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 ProcessUndelegationAccounts { public PublicKey DelegatedAccount { get; set; } public PublicKey Buffer { get; set; } public PublicKey Payer { get; set; } public PublicKey SystemProgram { get; set; } } public class UndelegateAccounts { public PublicKey Payer { get; set; } public PublicKey DelegatedAccount { get; set; } public PublicKey MagicContext { get; set; } = new PublicKey("MagicContext1111111111111111111111111111111"); public PublicKey MagicProgram { get; set; } = new PublicKey("Magic11111111111111111111111111111111111111"); } 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 PositionProgram { public const string ID = "Fn1JzzEdyb55fsyduWS94mYHizGhJZuhvjX6DVvrmGbQ"; public static Solana.Unity.Rpc.Models.TransactionInstruction Delegate(DelegateAccounts accounts, uint commit_frequency_ms, PublicKey validator, PublicKey programId = null) { programId ??= new(ID); List keys = new() {Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Payer, true), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Entity, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Account, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.OwnerProgram, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.DelegationRecord, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.DelegationMetadata, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.DelegationProgram, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)}; byte[] _data = new byte[1200]; int offset = 0; _data.WriteU64(9873113408189731674UL, offset); offset += 8; _data.WriteU32(commit_frequency_ms, offset); offset += 4; if (validator != null) { _data.WriteU8(1, offset); offset += 1; _data.WritePubKey(validator, offset); offset += 32; } else { _data.WriteU8(0, offset); offset += 1; } 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 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 ProcessUndelegation(ProcessUndelegationAccounts accounts, byte[][] account_seeds, PublicKey programId = null) { programId ??= new(ID); List keys = new() {Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.DelegatedAccount, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.Buffer, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.Payer, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.SystemProgram, false)}; byte[] _data = new byte[1200]; int offset = 0; _data.WriteU64(12048014319693667524UL, offset); offset += 8; _data.WriteS32(account_seeds.Length, offset); offset += 4; foreach (var account_seedsElement in account_seeds) { _data.WriteS32(account_seedsElement.Length, offset); offset += 4; _data.WriteSpan(account_seedsElement, offset); offset += account_seedsElement.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}; } public static Solana.Unity.Rpc.Models.TransactionInstruction Undelegate(UndelegateAccounts 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.DelegatedAccount, false), Solana.Unity.Rpc.Models.AccountMeta.Writable(accounts.MagicContext, false), Solana.Unity.Rpc.Models.AccountMeta.ReadOnly(accounts.MagicProgram, false)}; byte[] _data = new byte[1200]; int offset = 0; _data.WriteU64(17161644073433732227UL, 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}; } } } }