Skip to content

Commit

Permalink
Add CandyGuard program from IDL, Update CandyMachine IDL generated co…
Browse files Browse the repository at this point in the history
…de (#5)

* Update all CandyMachine generated types to latest IDL for CMv3.

* Update incorrect PDALookup + Add CandyGuard generated code.

* Add missing GuardData type for combining guard sets.

* Add GuardData deserialization.
  • Loading branch information
danbedford56 authored Jul 28, 2023
1 parent 4925fa6 commit feea78c
Show file tree
Hide file tree
Showing 12 changed files with 2,030 additions and 661 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Solana.Unity.Programs.Utilities;
using Solana.Unity.Wallet;
using System;

namespace Solana.Unity.Metaplex.CandyGuard.Accounts
{
public class CandyGuardAccounts

Check warning on line 7 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts'
{
public partial class FreezeEscrow

Check warning on line 9 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow'
{
public static ulong ACCOUNT_DISCRIMINATOR => 13295661872568646371UL;

Check warning on line 11 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.ACCOUNT_DISCRIMINATOR'
public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[] { 227, 186, 40, 152, 7, 174, 131, 184 };

Check warning on line 12 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.ACCOUNT_DISCRIMINATOR_BYTES'
public static string ACCOUNT_DISCRIMINATOR_B58 => "f6ErkZturrj";

Check warning on line 13 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.ACCOUNT_DISCRIMINATOR_B58'
public PublicKey CandyGuard { get; set; }

Check warning on line 14 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.CandyGuard'

public PublicKey CandyMachine { get; set; }

Check warning on line 16 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.CandyMachine'

public ulong FrozenCount { get; set; }

Check warning on line 18 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.FrozenCount'

public long? FirstMintTime { get; set; }

Check warning on line 20 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.FirstMintTime'

public long FreezePeriod { get; set; }

Check warning on line 22 in Solana.Unity.Metaplex/Candy Guard Program/Accounts/CandyGuardAccounts.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'CandyGuardAccounts.FreezeEscrow.FreezePeriod'

public PublicKey Destination { get; set; }

public PublicKey Authority { get; set; }

public static FreezeEscrow Deserialize(ReadOnlySpan<byte> _data)
{
int offset = 0;
ulong accountHashValue = _data.GetU64(offset);
offset += 8;
if (accountHashValue != ACCOUNT_DISCRIMINATOR)
{
return null;
}

FreezeEscrow result = new FreezeEscrow();
result.CandyGuard = _data.GetPubKey(offset);
offset += 32;
result.CandyMachine = _data.GetPubKey(offset);
offset += 32;
result.FrozenCount = _data.GetU64(offset);
offset += 8;
if (_data.GetBool(offset++))
{
result.FirstMintTime = _data.GetS64(offset);
offset += 8;
}

result.FreezePeriod = _data.GetS64(offset);
offset += 8;
result.Destination = _data.GetPubKey(offset);
offset += 32;
result.Authority = _data.GetPubKey(offset);
offset += 32;
return result;
}
}

public partial class CandyGuard
{
public static ulong ACCOUNT_DISCRIMINATOR => 13052108403907219244UL;
public static ReadOnlySpan<byte> ACCOUNT_DISCRIMINATOR_BYTES => new byte[] { 44, 207, 199, 184, 112, 103, 34, 181 };
public static string ACCOUNT_DISCRIMINATOR_B58 => "8VjHY4paKeL";
public PublicKey Base { get; set; }

public byte Bump { get; set; }

public PublicKey Authority { get; set; }

public static CandyGuard Deserialize(ReadOnlySpan<byte> _data)
{
int offset = 0;
ulong accountHashValue = _data.GetU64(offset);
offset += 8;
if (accountHashValue != ACCOUNT_DISCRIMINATOR)
{
return null;
}

CandyGuard result = new CandyGuard();
result.Base = _data.GetPubKey(offset);
offset += 32;
result.Bump = _data.GetU8(offset);
offset += 1;
result.Authority = _data.GetPubKey(offset);
offset += 32;
return result;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace Solana.Unity.Metaplex.CandyGuard.Errors
{
public enum CandyGuardErrorKind : uint
{
InvalidAccountSize = 6000U,
DeserializationError = 6001U,
PublicKeyMismatch = 6002U,
DataIncrementLimitExceeded = 6003U,
IncorrectOwner = 6004U,
Uninitialized = 6005U,
MissingRemainingAccount = 6006U,
NumericalOverflowError = 6007U,
RequiredGroupLabelNotFound = 6008U,
GroupNotFound = 6009U,
ExceededLength = 6010U,
CandyMachineEmpty = 6011U,
InstructionNotFound = 6012U,
CollectionKeyMismatch = 6013U,
MissingCollectionAccounts = 6014U,
CollectionUpdateAuthorityKeyMismatch = 6015U,
MintNotLastTransaction = 6016U,
MintNotLive = 6017U,
NotEnoughSOL = 6018U,
TokenBurnFailed = 6019U,
NotEnoughTokens = 6020U,
TokenTransferFailed = 6021U,
MissingRequiredSignature = 6022U,
GatewayTokenInvalid = 6023U,
AfterEndDate = 6024U,
InvalidMintTime = 6025U,
AddressNotFoundInAllowedList = 6026U,
MissingAllowedListProof = 6027U,
AllowedListNotEnabled = 6028U,
AllowedMintLimitReached = 6029U,
InvalidNftCollection = 6030U,
MissingNft = 6031U,
MaximumRedeemedAmount = 6032U,
AddressNotAuthorized = 6033U,
MissingFreezeInstruction = 6034U,
FreezeGuardNotEnabled = 6035U,
FreezeNotInitialized = 6036U,
MissingFreezePeriod = 6037U,
FreezeEscrowAlreadyExists = 6038U,
ExceededMaximumFreezePeriod = 6039U,
ThawNotEnabled = 6040U,
UnlockNotEnabled = 6041U,
DuplicatedGroupLabel = 6042U,
DuplicatedMintLimitId = 6043U,
UnauthorizedProgramFound = 6044U,
ExceededProgramListSize = 6045U,
AllocationNotInitialized = 6046U,
AllocationLimitReached = 6047U,
AllocationGuardNotEnabled = 6048U,
InvalidMintAuthority = 6049U,
InstructionBuilderFailed = 6050U,
InvalidAccountVersion = 6051U
}
}
144 changes: 144 additions & 0 deletions Solana.Unity.Metaplex/Candy Guard Program/Program/CandyGuardClient.cs

Large diffs are not rendered by default.

Loading

0 comments on commit feea78c

Please sign in to comment.