3land_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. package/README.md +352 -0
  2. package/assets/3land_rebrand.gif +0 -0
  3. package/assets/battle_sol.gif +0 -0
  4. package/assets/ds.jpeg +0 -0
  5. package/assets/future.webp +0 -0
  6. package/assets/music.mp3 +0 -0
  7. package/assets/niicl.gif +0 -0
  8. package/assets/og.png +0 -0
  9. package/assets/phone.glb +0 -0
  10. package/assets/testvid.mp4 +0 -0
  11. package/idl.json +7652 -0
  12. package/package.json +35 -0
  13. package/src/index.ts +89 -0
  14. package/src/library/Irys/irys.ts +412 -0
  15. package/src/library/Store.ts +613 -0
  16. package/src/library/implementation/storeImplementation.ts +385 -0
  17. package/src/library/instructions/store/buySingleEdition.ts +227 -0
  18. package/src/library/instructions/store/createSingleEdition.ts +49 -0
  19. package/src/library/instructions/store/createStore.ts +19 -0
  20. package/src/library/instructions/store/idl.ts +7622 -0
  21. package/src/library/instructions/store/uploadFilesIryis.ts +133 -0
  22. package/src/types/accounts/ArchiveDeposit.ts +207 -0
  23. package/src/types/accounts/Authority.ts +73 -0
  24. package/src/types/accounts/BurnDeposit.ts +111 -0
  25. package/src/types/accounts/BurnProgress.ts +97 -0
  26. package/src/types/accounts/BuyHistory.ts +121 -0
  27. package/src/types/accounts/BuyTrack.ts +94 -0
  28. package/src/types/accounts/Card.ts +185 -0
  29. package/src/types/accounts/CollectionRegistry.ts +145 -0
  30. package/src/types/accounts/CollectorRegistry.ts +145 -0
  31. package/src/types/accounts/CreatorRegistry.ts +153 -0
  32. package/src/types/accounts/CurrencyArtistProof.ts +113 -0
  33. package/src/types/accounts/GenericUser.ts +185 -0
  34. package/src/types/accounts/ItemArchive.ts +223 -0
  35. package/src/types/accounts/ItemReserveList.ts +87 -0
  36. package/src/types/accounts/ItemReserveList2.ts +73 -0
  37. package/src/types/accounts/LutVault.ts +97 -0
  38. package/src/types/accounts/Pack.ts +367 -0
  39. package/src/types/accounts/PackContent.ts +97 -0
  40. package/src/types/accounts/PackOpenHolder.ts +141 -0
  41. package/src/types/accounts/PackReceipt.ts +145 -0
  42. package/src/types/accounts/PackTraits.ts +101 -0
  43. package/src/types/accounts/Payment.ts +97 -0
  44. package/src/types/accounts/PoolVault.ts +177 -0
  45. package/src/types/accounts/RevealForMe.ts +139 -0
  46. package/src/types/accounts/SecureHolder.ts +97 -0
  47. package/src/types/accounts/Single.ts +301 -0
  48. package/src/types/accounts/Store.ts +180 -0
  49. package/src/types/accounts/StoresHolder.ts +131 -0
  50. package/src/types/accounts/ThreeId.ts +189 -0
  51. package/src/types/accounts/TokenManager.ts +217 -0
  52. package/src/types/accounts/ZeroCard.ts +73 -0
  53. package/src/types/accounts/ZeroContent.ts +89 -0
  54. package/src/types/accounts/ZeroOpenHolder.ts +183 -0
  55. package/src/types/accounts/index.ts +84 -0
  56. package/src/types/errors/anchor.ts +773 -0
  57. package/src/types/errors/index.ts +59 -0
  58. package/src/types/implementation/implementationTypes.ts +27 -0
  59. package/src/types/instructions/addBurn.ts +56 -0
  60. package/src/types/instructions/adjustDepositBurn.ts +33 -0
  61. package/src/types/instructions/archiveItem.ts +60 -0
  62. package/src/types/instructions/assignPackDelegate.ts +30 -0
  63. package/src/types/instructions/burnPay.ts +55 -0
  64. package/src/types/instructions/buyPack.ts +69 -0
  65. package/src/types/instructions/buyPay.ts +71 -0
  66. package/src/types/instructions/buyToken.ts +64 -0
  67. package/src/types/instructions/claimZeroCard.ts +106 -0
  68. package/src/types/instructions/closeDepositBurn.ts +47 -0
  69. package/src/types/instructions/closeRegisterTraits.ts +28 -0
  70. package/src/types/instructions/createCard.ts +56 -0
  71. package/src/types/instructions/createCollection.ts +68 -0
  72. package/src/types/instructions/createPack.ts +71 -0
  73. package/src/types/instructions/createSingle.ts +71 -0
  74. package/src/types/instructions/createStore.ts +50 -0
  75. package/src/types/instructions/createTokenLauncher.ts +82 -0
  76. package/src/types/instructions/createZeroCard.ts +76 -0
  77. package/src/types/instructions/deleteCard.ts +32 -0
  78. package/src/types/instructions/deletePack.ts +40 -0
  79. package/src/types/instructions/deleteSingle.ts +36 -0
  80. package/src/types/instructions/deleteTokenLauncher.ts +38 -0
  81. package/src/types/instructions/depositBurn.ts +55 -0
  82. package/src/types/instructions/donateUser.ts +84 -0
  83. package/src/types/instructions/feedPool.ts +61 -0
  84. package/src/types/instructions/feedTraits.ts +44 -0
  85. package/src/types/instructions/feedTree.ts +63 -0
  86. package/src/types/instructions/flagPack.ts +50 -0
  87. package/src/types/instructions/flagSingle.ts +47 -0
  88. package/src/types/instructions/gatePay.ts +59 -0
  89. package/src/types/instructions/index.ts +140 -0
  90. package/src/types/instructions/initialize.ts +46 -0
  91. package/src/types/instructions/openPack.ts +79 -0
  92. package/src/types/instructions/prepareCreator.ts +30 -0
  93. package/src/types/instructions/preparePack.ts +51 -0
  94. package/src/types/instructions/prepareTraits.ts +28 -0
  95. package/src/types/instructions/printPack.ts +95 -0
  96. package/src/types/instructions/printSingle.ts +108 -0
  97. package/src/types/instructions/recoverDepositBurn.ts +80 -0
  98. package/src/types/instructions/registerActivity.ts +43 -0
  99. package/src/types/instructions/registerCollector.ts +63 -0
  100. package/src/types/instructions/registerCreator.ts +48 -0
  101. package/src/types/instructions/registerGenericUser.ts +94 -0
  102. package/src/types/instructions/registerPackUploads.ts +44 -0
  103. package/src/types/instructions/registerTraits.ts +42 -0
  104. package/src/types/instructions/registerUser.ts +50 -0
  105. package/src/types/instructions/storeLutFor.ts +44 -0
  106. package/src/types/instructions/unwrapAndDestroy.ts +56 -0
  107. package/src/types/instructions/updateCard.ts +54 -0
  108. package/src/types/instructions/updatePack.ts +71 -0
  109. package/src/types/instructions/updateSingle.ts +64 -0
  110. package/src/types/instructions/updateStore.ts +47 -0
  111. package/src/types/instructions/withdrawFromStore.ts +26 -0
  112. package/src/types/programId.ts +42 -0
  113. package/src/types/types/AccountClass.ts +868 -0
  114. package/src/types/types/AccountHasher.ts +89 -0
  115. package/src/types/types/ActionAfter.ts +202 -0
  116. package/src/types/types/AllowedCurrencyArgs.ts +53 -0
  117. package/src/types/types/AuthorityGateTypes.ts +90 -0
  118. package/src/types/types/BurnCount.ts +60 -0
  119. package/src/types/types/BurnState.ts +88 -0
  120. package/src/types/types/BurnTrack.ts +64 -0
  121. package/src/types/types/BurnType.ts +118 -0
  122. package/src/types/types/BurnTypeBurn.ts +56 -0
  123. package/src/types/types/BuyHistoryClass.ts +90 -0
  124. package/src/types/types/CardClass.ts +56 -0
  125. package/src/types/types/CardState.ts +238 -0
  126. package/src/types/types/CardTrack.ts +76 -0
  127. package/src/types/types/Category.ts +72 -0
  128. package/src/types/types/CnftData.ts +85 -0
  129. package/src/types/types/CollectTrack.ts +61 -0
  130. package/src/types/types/Collection.ts +64 -0
  131. package/src/types/types/CompactCnftData.ts +76 -0
  132. package/src/types/types/CoolTimePerAmountArgs.ts +72 -0
  133. package/src/types/types/Creator.ts +72 -0
  134. package/src/types/types/CreatorGateArgs.ts +53 -0
  135. package/src/types/types/CurrencyArtistProof.ts +85 -0
  136. package/src/types/types/CurrencyType.ts +259 -0
  137. package/src/types/types/DateTraitInit.ts +61 -0
  138. package/src/types/types/DateTraitInitMap.ts +72 -0
  139. package/src/types/types/Deposit.ts +85 -0
  140. package/src/types/types/DepositFormat.ts +90 -0
  141. package/src/types/types/DepositState.ts +88 -0
  142. package/src/types/types/DepositSubtype.ts +90 -0
  143. package/src/types/types/DepositTrack.ts +69 -0
  144. package/src/types/types/DepositTrackType.ts +120 -0
  145. package/src/types/types/DepositType.ts +245 -0
  146. package/src/types/types/Earnings.ts +37 -0
  147. package/src/types/types/EditionStoreType.ts +120 -0
  148. package/src/types/types/EncryptedPayload.ts +61 -0
  149. package/src/types/types/ExtraParameter.ts +117 -0
  150. package/src/types/types/FakeBurnCount.ts +64 -0
  151. package/src/types/types/FakeDeposit.ts +64 -0
  152. package/src/types/types/FakeTraitPair.ts +61 -0
  153. package/src/types/types/FakeTraitValue.ts +61 -0
  154. package/src/types/types/FakeVolumeTrack.ts +64 -0
  155. package/src/types/types/FeeType.ts +118 -0
  156. package/src/types/types/FeedingTraits.ts +57 -0
  157. package/src/types/types/Filter.ts +64 -0
  158. package/src/types/types/FilterType.ts +56 -0
  159. package/src/types/types/GeneralStore.ts +56 -0
  160. package/src/types/types/GenericStore.ts +64 -0
  161. package/src/types/types/GenericValue.ts +172 -0
  162. package/src/types/types/GlobalFee.ts +85 -0
  163. package/src/types/types/GlobalState.ts +148 -0
  164. package/src/types/types/IndexDate.ts +94 -0
  165. package/src/types/types/IndexDates.ts +64 -0
  166. package/src/types/types/Item.ts +53 -0
  167. package/src/types/types/ItemClass.ts +88 -0
  168. package/src/types/types/ItemState.ts +298 -0
  169. package/src/types/types/ItemTrack.ts +76 -0
  170. package/src/types/types/ListingPerWalletArgs.ts +53 -0
  171. package/src/types/types/MemeVaultProof.ts +64 -0
  172. package/src/types/types/MetadataArgs.ts +207 -0
  173. package/src/types/types/NonFungibleTraitInit.ts +64 -0
  174. package/src/types/types/NonFungibleTraitInitMap.ts +84 -0
  175. package/src/types/types/OnlyBetweenTimesArgs.ts +76 -0
  176. package/src/types/types/OnlyTheseDOWArgs.ts +53 -0
  177. package/src/types/types/PackConfig.ts +98 -0
  178. package/src/types/types/PackOpenHolderState.ts +120 -0
  179. package/src/types/types/PackRule.ts +85 -0
  180. package/src/types/types/PackState.ts +118 -0
  181. package/src/types/types/PackType.ts +118 -0
  182. package/src/types/types/PaymentClass.ts +118 -0
  183. package/src/types/types/PoolAccess.ts +88 -0
  184. package/src/types/types/PoolState.ts +88 -0
  185. package/src/types/types/PoolType.ts +88 -0
  186. package/src/types/types/Popularity.ts +76 -0
  187. package/src/types/types/PopularityState.ts +630 -0
  188. package/src/types/types/PreviousDonationRecord.ts +76 -0
  189. package/src/types/types/Price.ts +64 -0
  190. package/src/types/types/PriceRule.ts +216 -0
  191. package/src/types/types/RecoverDeposit.ts +56 -0
  192. package/src/types/types/Rule.ts +199 -0
  193. package/src/types/types/SaleConfig.ts +102 -0
  194. package/src/types/types/SaleTrack.ts +85 -0
  195. package/src/types/types/SaleType.ts +148 -0
  196. package/src/types/types/Seed.ts +61 -0
  197. package/src/types/types/SelectedCard.ts +61 -0
  198. package/src/types/types/SelectedZeroCard.ts +61 -0
  199. package/src/types/types/SemiFungibleTraitInit.ts +61 -0
  200. package/src/types/types/SemiFungibleTraitInitMap.ts +72 -0
  201. package/src/types/types/ShortCreator.ts +64 -0
  202. package/src/types/types/ShortMetadata.ts +145 -0
  203. package/src/types/types/ShortMetadataArgs.ts +111 -0
  204. package/src/types/types/StoreConfig.ts +98 -0
  205. package/src/types/types/StoreRule.ts +145 -0
  206. package/src/types/types/SuperCategory.ts +61 -0
  207. package/src/types/types/TightCardMetadata.ts +120 -0
  208. package/src/types/types/TimeRangeType.ts +120 -0
  209. package/src/types/types/TimedPerWalletArgs.ts +53 -0
  210. package/src/types/types/TokenMetadata.ts +72 -0
  211. package/src/types/types/TokenProgramVersion.ts +90 -0
  212. package/src/types/types/TokenStandard.ts +150 -0
  213. package/src/types/types/TokenState.ts +88 -0
  214. package/src/types/types/TokenType.ts +88 -0
  215. package/src/types/types/TotalPerTimeArgs.ts +85 -0
  216. package/src/types/types/TotalPerTimeWalletArgs.ts +61 -0
  217. package/src/types/types/TrackRegistry.ts +90 -0
  218. package/src/types/types/TraitInit.ts +210 -0
  219. package/src/types/types/TraitPass.ts +60 -0
  220. package/src/types/types/TraitPassType.ts +225 -0
  221. package/src/types/types/TraitType.ts +267 -0
  222. package/src/types/types/TraitValue.ts +72 -0
  223. package/src/types/types/UnlocksAfter.ts +172 -0
  224. package/src/types/types/UnwrapMetadata.ts +156 -0
  225. package/src/types/types/UseMethod.ts +118 -0
  226. package/src/types/types/Uses.ts +76 -0
  227. package/src/types/types/VerifyCollectionMetadata.ts +109 -0
  228. package/src/types/types/VolumeTrack.ts +61 -0
  229. package/src/types/types/WrappedSource.ts +85 -0
  230. package/src/types/types/ZeroConfig.ts +85 -0
  231. package/src/types/types/index.ts +798 -0
  232. package/src/utility/Connection.ts +9 -0
  233. package/src/utility/Holders.ts +8 -0
  234. package/src/utility/PdaManager.ts +230 -0
  235. package/src/utility/config.ts +32 -0
  236. package/src/utility/utils.ts +191 -0
  237. package/src/utility/validation.ts +229 -0
  238. package/tsconfig.json +12 -0
@@ -0,0 +1,613 @@
1
+ import {
2
+ Connection,
3
+ PublicKey,
4
+ Transaction,
5
+ sendAndConfirmTransaction,
6
+ Signer,
7
+ SystemProgram,
8
+ clusterApiUrl as clusterApiUrl2,
9
+ Keypair,
10
+ } from "@solana/web3.js";
11
+ import {
12
+ createCreateMasterEditionV3Instruction,
13
+ createCreateMetadataAccountV3Instruction,
14
+ PROGRAM_ID as metaPROGRAM_ID,
15
+ } from "@metaplex-foundation/mpl-token-metadata";
16
+
17
+ import {
18
+ MintLayout,
19
+ createAssociatedTokenAccountInstruction,
20
+ createMintToInstruction,
21
+ createInitializeMintInstruction,
22
+ } from "@solana/spl-token";
23
+ import { getConnection } from "../utility/Connection";
24
+ import { createStoreInstruction } from "./instructions/store/createStore";
25
+ import { createSingleEditionInstruction } from "./instructions/store/createSingleEdition";
26
+ import { buySingleEditionInstruction } from "./instructions/store/buySingleEdition";
27
+ import {
28
+ StoreConfig,
29
+ MetadataArgs,
30
+ SaleConfig,
31
+ ShortMetadataArgs,
32
+ ShortMetadataArgsJSON,
33
+ } from "../types/types";
34
+ import {
35
+ holderPDA,
36
+ storePDA,
37
+ itemAccountPDA,
38
+ creatorAuthorityPDA,
39
+ toPublicKey,
40
+ userActivityPDA,
41
+ creatorRegistryPDA,
42
+ getMetadataPDA,
43
+ collectionAuthorityRecord,
44
+ collectorArtistRegistryPDA,
45
+ collectorGlobalRegistryPDA,
46
+ buyPaymentPDA,
47
+ getATAPDA,
48
+ getEditionPDA,
49
+ } from "../utility/PdaManager";
50
+ import { devnetHolder } from "../utility/Holders";
51
+ import BN from "bn.js";
52
+ import { uploadFilesIrysInstruction } from "./instructions/store/uploadFilesIryis";
53
+ import {
54
+ DEVNET_PROGRAM_ID,
55
+ PROGRAM_CNFT,
56
+ PROGRAM_ID,
57
+ TOKEN_PROGRAM_ID,
58
+ } from "../types/programId";
59
+
60
+ import { registerCreator } from "../types/instructions/registerCreator";
61
+ import { init as Irys } from "./Irys/irys";
62
+ import { createApproveCollectionAuthorityInstruction } from "@metaplex-foundation/mpl-token-metadata";
63
+ import { registerCollector } from "../types/instructions";
64
+ import {
65
+ validateBuySingleArgs,
66
+ validateCollectionArgs,
67
+ validateIdentifier,
68
+ validateMetadata,
69
+ validateSaleConfig,
70
+ validateStoreConfig,
71
+ validateSupply,
72
+ ValidationError,
73
+ } from "../utility/validation";
74
+ import { NetworkType, NetworkConfig, NETWORK_CONFIGS } from "../utility/config";
75
+ import { Single } from "../types/accounts";
76
+
77
+ export interface StoreOptions {
78
+ network?: NetworkType;
79
+ customEndpoint?: string;
80
+ customConfig?: Partial<NetworkConfig>;
81
+ }
82
+
83
+ const extraAccount = [
84
+ {
85
+ pubkey: new PublicKey("GyPCu89S63P9NcCQAtuSJesiefhhgpGWrNVJs4bF2cSK"), //global store
86
+ isSigner: false,
87
+ isWritable: true,
88
+ },
89
+ ];
90
+
91
+ export class Store {
92
+ private connection: Connection;
93
+ private networkConfig: NetworkConfig;
94
+
95
+ constructor(options: StoreOptions = {}) {
96
+ const {
97
+ network = NetworkType.DEVNET,
98
+ // network = NetworkType.MAINNET,
99
+ customEndpoint,
100
+ customConfig,
101
+ } = options;
102
+
103
+ const baseConfig = NETWORK_CONFIGS[network];
104
+
105
+ this.networkConfig = {
106
+ ...baseConfig,
107
+ ...customConfig,
108
+ endpoint: customEndpoint || baseConfig.endpoint,
109
+ };
110
+
111
+ this.connection = getConnection(this.networkConfig.endpoint);
112
+ }
113
+
114
+ async createStore(
115
+ payer: Signer,
116
+ name: string,
117
+ storeConfig: StoreConfig,
118
+ creator?: PublicKey,
119
+ storeId?: number
120
+ ): Promise<string> {
121
+ if (!payer || !payer.publicKey) {
122
+ throw new ValidationError("Invalid payer");
123
+ }
124
+
125
+ if (!name || name.length > 32) {
126
+ throw new ValidationError(
127
+ "Store name is required and must be <= 32 characters"
128
+ );
129
+ }
130
+
131
+ storeId = Math.floor(Math.random() * 10000);
132
+ creator = payer.publicKey;
133
+
134
+ validateStoreConfig(storeConfig);
135
+ validateIdentifier(storeId);
136
+
137
+ try {
138
+ const [holderAccount] = await holderPDA({
139
+ creator: devnetHolder.creator,
140
+ slot: devnetHolder.slot,
141
+ });
142
+ const [storeAccount] = await storePDA({
143
+ storeId: storeId,
144
+ creator: creator.toString(),
145
+ holder: holderAccount.toString(),
146
+ });
147
+
148
+ const instruction = createStoreInstruction(
149
+ holderAccount,
150
+ storeAccount,
151
+ payer.publicKey,
152
+ name,
153
+ storeConfig,
154
+ storeId
155
+ );
156
+
157
+ const transaction = new Transaction().add(instruction);
158
+ return sendAndConfirmTransaction(this.connection, transaction, [payer]);
159
+ } catch (error) {
160
+ if (error instanceof ValidationError) {
161
+ throw error;
162
+ }
163
+ throw new Error(`Failed to create store: ${error}`);
164
+ }
165
+ }
166
+
167
+ async createCollection(
168
+ payer: Signer,
169
+ collectionDetails: any,
170
+ metadata: any,
171
+ irysData: any,
172
+ mutable: Boolean = false,
173
+ supply: number = 0
174
+ ) {
175
+ try {
176
+ if (!payer || !payer.publicKey) {
177
+ throw new ValidationError("Invalid payer");
178
+ }
179
+
180
+ validateCollectionArgs(collectionDetails, supply, metadata, irysData);
181
+
182
+ if (typeof mutable !== "boolean") {
183
+ throw new ValidationError("Mutable parameter must be a boolean");
184
+ }
185
+
186
+ if (metadata.uri.length !== 0) {
187
+ throw new ValidationError("URI must be empty");
188
+ }
189
+
190
+ let instructions = [];
191
+ let signers = [payer];
192
+
193
+ if (metadata.uri.length !== 0) throw new Error("-- URI must be empty --");
194
+
195
+ const irys = await Irys(payer.publicKey.toBase58(), {});
196
+ const uuid = "random_uuid_per_upload_session";
197
+
198
+ const { instruction, signerIrys, metadataUrl } =
199
+ await uploadFilesIrysInstruction(irysData.options, irys, uuid);
200
+ instructions.push(instruction);
201
+ signers.push(signerIrys);
202
+
203
+ const mint = Keypair.generate();
204
+ const connection = this.connection;
205
+ const updateAuthority = payer.publicKey;
206
+ collectionDetails = collectionDetails || null;
207
+
208
+ const mintRent = await connection.getMinimumBalanceForRentExemption(
209
+ MintLayout.span
210
+ );
211
+ instructions.push(
212
+ SystemProgram.createAccount({
213
+ fromPubkey: payer.publicKey,
214
+ newAccountPubkey: mint.publicKey,
215
+ lamports: mintRent,
216
+ space: MintLayout.span,
217
+ programId: TOKEN_PROGRAM_ID,
218
+ })
219
+ );
220
+
221
+ const owner = payer.publicKey;
222
+ const freezeAuthority = owner;
223
+ instructions.push(
224
+ createInitializeMintInstruction(
225
+ mint.publicKey, //mint
226
+ 0, //decimals
227
+ owner, //mintAuthority
228
+ freezeAuthority, //freezeAuthority
229
+ TOKEN_PROGRAM_ID
230
+ )
231
+ );
232
+ signers.push(mint);
233
+
234
+ const ownerATA = await getATAPDA({ owner, mint: mint.publicKey });
235
+ instructions.push(
236
+ createAssociatedTokenAccountInstruction(
237
+ payer.publicKey,
238
+ ownerATA, //associatedTokenAddress
239
+ owner, //walletAddress
240
+ mint.publicKey
241
+ )
242
+ );
243
+
244
+ const metadataAccount = await getMetadataPDA(mint.publicKey);
245
+
246
+ const create_accounts = {
247
+ metadata: metadataAccount,
248
+ mint: mint.publicKey,
249
+ mintAuthority: payer.publicKey,
250
+ payer: payer.publicKey,
251
+ updateAuthority,
252
+ };
253
+
254
+ const metadataObj = { ...metadata, uri: metadataUrl };
255
+
256
+ console.log("metatadaobj: ", metadataObj);
257
+
258
+ const create_args = {
259
+ createMetadataAccountArgsV3: {
260
+ data: metadataObj,
261
+ isMutable: mutable === false ? false : true,
262
+ collectionDetails,
263
+ },
264
+ };
265
+
266
+ instructions.push(
267
+ createCreateMetadataAccountV3Instruction(create_accounts, create_args)
268
+ );
269
+
270
+ instructions.push(
271
+ createMintToInstruction(
272
+ mint.publicKey,
273
+ ownerATA,
274
+ owner /*authority*/,
275
+ 1,
276
+ []
277
+ )
278
+ );
279
+
280
+ const supplies = {
281
+ maxSupply: supply || supply === 0 ? new BN(supply) : null,
282
+ };
283
+ const [editionAccount] = await getEditionPDA(mint.publicKey, false);
284
+ const accounts = {
285
+ edition: editionAccount,
286
+ mint: mint.publicKey,
287
+ updateAuthority,
288
+ mintAuthority: owner,
289
+ payer: payer.publicKey,
290
+ metadata: metadataAccount,
291
+ };
292
+
293
+ const args = { createMasterEditionArgs: { ...supplies } };
294
+ instructions.push(createCreateMasterEditionV3Instruction(accounts, args));
295
+
296
+ const transaction = new Transaction().add(...instructions);
297
+
298
+ const sendedconfirmedTransaction = await sendAndConfirmTransaction(
299
+ this.connection,
300
+ transaction,
301
+ signers
302
+ );
303
+ const { errors, succeeds }: any = await irys?.uploadFiles({
304
+ uuid,
305
+ signature: sendedconfirmedTransaction,
306
+ });
307
+ return sendedconfirmedTransaction;
308
+ } catch (error) {
309
+ if (error instanceof ValidationError) {
310
+ throw error;
311
+ }
312
+ throw new Error(`Failed to create collection: ${error}`);
313
+ }
314
+ }
315
+
316
+ async createSingleEdition(
317
+ payer: Signer,
318
+ storeAccount: PublicKey,
319
+ supply: number,
320
+ metadata: ShortMetadataArgs,
321
+ saleConfig: SaleConfig,
322
+ category: number[],
323
+ superCategory: number[],
324
+ eventCategory: number,
325
+ hashTraits: number,
326
+ collection: PublicKey,
327
+ irysData: any
328
+ ): Promise<string> {
329
+ const identifier = Math.floor(Math.random() * 1000000);
330
+ const creator = payer.publicKey;
331
+
332
+ if (!payer || !payer.publicKey) {
333
+ throw new ValidationError("Invalid payer");
334
+ }
335
+
336
+ if (!storeAccount) {
337
+ throw new ValidationError("Store account is required");
338
+ }
339
+
340
+ validateSupply(supply);
341
+ validateMetadata(metadata);
342
+ validateSaleConfig(saleConfig);
343
+ validateIdentifier(identifier);
344
+
345
+ try {
346
+ const irys = await Irys(payer.publicKey.toBase58(), {});
347
+ const uuid = "random_uuid_per_upload_session";
348
+
349
+ const [itemAccount] = await itemAccountPDA({
350
+ creator: creator,
351
+ store: storeAccount,
352
+ identifier: new BN(identifier),
353
+ });
354
+ const [creatorAuthority] = await creatorAuthorityPDA({
355
+ creator: payer.publicKey,
356
+ store: storeAccount,
357
+ });
358
+
359
+ let instructions = [];
360
+ let signers = [payer];
361
+
362
+ const { instruction, signerIrys, metadataUrl } =
363
+ await uploadFilesIrysInstruction(irysData.options, irys, uuid);
364
+ instructions.push(instruction);
365
+ signers.push(signerIrys);
366
+
367
+ const collection_mint = toPublicKey(collection);
368
+
369
+ const new_authority = creatorAuthority;
370
+
371
+ const [authRecord] = await collectionAuthorityRecord({
372
+ mint: collection_mint,
373
+ new_authority: new_authority,
374
+ });
375
+
376
+ let collection_permission = false;
377
+
378
+ try {
379
+ const res = await this.connection.getAccountInfo(authRecord);
380
+ if (res) collection_permission = true;
381
+ } catch (e) {
382
+ collection_permission = false;
383
+ }
384
+
385
+ if (!collection_permission) {
386
+ const metadataPda = await getMetadataPDA(collection_mint);
387
+
388
+ const accounts = {
389
+ collectionAuthorityRecord: authRecord,
390
+ newCollectionAuthority: new_authority,
391
+ updateAuthority: payer.publicKey,
392
+ payer: payer.publicKey,
393
+ metadata: metadataPda,
394
+ mint: collection_mint,
395
+ };
396
+ const approveInstruction =
397
+ createApproveCollectionAuthorityInstruction(accounts);
398
+ instructions.push(approveInstruction);
399
+ // signers.push(new_authority)
400
+ }
401
+ console.log("metadataurl: ", metadataUrl);
402
+ const meta: ShortMetadataArgs = {
403
+ name: metadata.name,
404
+ uri: metadataUrl ? metadataUrl.split(".net/")[1] : "",
405
+ uriType: 1,
406
+ sellerFeeBasisPoints: metadata.sellerFeeBasisPoints,
407
+ collection: metadata.collection,
408
+ creators: metadata.creators,
409
+ toJSON: function (): ShortMetadataArgsJSON {
410
+ throw new Error("Function not implemented.");
411
+ },
412
+ toEncodable: function () {
413
+ throw new Error("Function not implemented.");
414
+ },
415
+ };
416
+ console.log("meta: ", meta);
417
+
418
+ const instructionSing = createSingleEditionInstruction(
419
+ storeAccount,
420
+ itemAccount,
421
+ creatorAuthority,
422
+ PROGRAM_ID,
423
+ payer.publicKey,
424
+ payer.publicKey,
425
+ supply,
426
+ meta,
427
+ saleConfig,
428
+ identifier,
429
+ category,
430
+ superCategory,
431
+ eventCategory,
432
+ hashTraits
433
+ );
434
+ instructions.push(instructionSing);
435
+
436
+ const [userActivity, userActivityBump] = await userActivityPDA({
437
+ user: creator,
438
+ store: storeAccount,
439
+ });
440
+
441
+ const [creatorRegistry] = await creatorRegistryPDA({
442
+ user: creator,
443
+ store: storeAccount,
444
+ currency: toPublicKey(PROGRAM_CNFT),
445
+ });
446
+
447
+ const registerIX = registerCreator(
448
+ {
449
+ userActivityBump: userActivityBump,
450
+ },
451
+ {
452
+ creatorRegistry,
453
+ userActivity,
454
+ itemAccount,
455
+ store: storeAccount,
456
+ payer: payer.publicKey,
457
+ systemProgram: SystemProgram.programId,
458
+ }
459
+ );
460
+
461
+ instructions.push(registerIX);
462
+
463
+ const transaction = new Transaction().add(...instructions);
464
+
465
+ const sendedconfirmedTransaction = await sendAndConfirmTransaction(
466
+ this.connection,
467
+ transaction,
468
+ signers
469
+ );
470
+ const { errors, succeeds }: any = await irys?.uploadFiles({
471
+ uuid,
472
+ signature: sendedconfirmedTransaction,
473
+ });
474
+ return sendedconfirmedTransaction;
475
+ } catch (error) {
476
+ if (error instanceof ValidationError) {
477
+ throw error;
478
+ }
479
+ throw new Error(`Failed to create single edition: ${error}`);
480
+ }
481
+ }
482
+
483
+ async buySingleEdition(
484
+ payer: Signer,
485
+ distributionBumps: number[],
486
+ itemAddress: PublicKey,
487
+ extraAccounts: any[] = extraAccount,
488
+ globalStoreAccount: PublicKey = DEVNET_PROGRAM_ID,
489
+ packAccount: PublicKey = PROGRAM_CNFT,
490
+ burnProgress: PublicKey = PROGRAM_CNFT,
491
+ poolVault: PublicKey = PROGRAM_CNFT
492
+ ): Promise<string> {
493
+ try {
494
+ const owner = payer.publicKey;
495
+ //const storedata = await this.connection.getAccountInfo(itemAddress);
496
+ const single = await Single.fetch(
497
+ this.connection,
498
+ itemAddress,
499
+ PROGRAM_ID
500
+ );
501
+ const identifier = parseInt(single?.identifier?.toString() || "none");
502
+ const creator = single?.creator;
503
+ const storeAccount = single?.holder;
504
+ const collectionAddress = single?.item?.metadata?.collection;
505
+
506
+ validateIdentifier(identifier);
507
+
508
+ if (!creator) throw new Error("Missing creator...");
509
+ if (!storeAccount) throw new Error("Missing creator...");
510
+ if (!collectionAddress) throw new Error("Missing collection...");
511
+
512
+ validateBuySingleArgs(
513
+ payer,
514
+ packAccount,
515
+ burnProgress,
516
+ owner,
517
+ distributionBumps,
518
+ globalStoreAccount,
519
+ extraAccounts,
520
+ collectionAddress.key,
521
+ storeAccount,
522
+ creator
523
+ );
524
+
525
+ const [itemAccount] = await itemAccountPDA({
526
+ creator: creator,
527
+ store: storeAccount,
528
+ identifier: new BN(identifier),
529
+ });
530
+
531
+ const [paymentAccount] = await buyPaymentPDA({
532
+ owner: owner,
533
+ itemAccount,
534
+ });
535
+
536
+ const holderAccount = storeAccount;
537
+
538
+ let instructions = [];
539
+ const instruction = await buySingleEditionInstruction(
540
+ paymentAccount,
541
+ itemAccount,
542
+ packAccount,
543
+ burnProgress,
544
+ poolVault,
545
+ holderAccount,
546
+ owner,
547
+ payer.publicKey,
548
+ distributionBumps,
549
+ {},
550
+ storeAccount,
551
+ globalStoreAccount,
552
+ identifier,
553
+ extraAccounts,
554
+ creator,
555
+ collectionAddress.key,
556
+ this.connection
557
+ );
558
+ instructions.push(...instruction);
559
+
560
+ const [userActivity, userActivityBump] = await userActivityPDA({
561
+ user: payer.publicKey,
562
+ store: storeAccount,
563
+ });
564
+
565
+ const [collectorRegistry] = await collectorArtistRegistryPDA({
566
+ user: payer.publicKey,
567
+ artist: creator,
568
+ store: storeAccount,
569
+ currency: toPublicKey(PROGRAM_CNFT),
570
+ });
571
+
572
+ const [creatorRegistry, creatorBump] = await creatorRegistryPDA({
573
+ user: creator,
574
+ currency: toPublicKey(PROGRAM_CNFT),
575
+ store: storeAccount,
576
+ });
577
+
578
+ const [collectorGlobalRegistry] = await collectorGlobalRegistryPDA({
579
+ user: payer.publicKey,
580
+ currency: toPublicKey(PROGRAM_CNFT),
581
+ store: storeAccount,
582
+ });
583
+
584
+ const registerIX = registerCollector(
585
+ {
586
+ creatorBump: creatorBump,
587
+ activityBump: userActivityBump,
588
+ },
589
+ {
590
+ collectorArtistRegistry: collectorRegistry,
591
+ collectorGlobalRegistry: collectorGlobalRegistry,
592
+ userActivity: userActivity,
593
+ creatorRegistry: creatorRegistry,
594
+ store: storeAccount,
595
+ payer: payer.publicKey,
596
+ systemProgram: SystemProgram.programId,
597
+ }
598
+ );
599
+ instructions.push(registerIX);
600
+
601
+ const transaction = new Transaction().add(...instructions);
602
+ console.log("transaction: ", payer.publicKey);
603
+ return sendAndConfirmTransaction(this.connection, transaction, [payer]);
604
+ } catch (error) {
605
+ if (error instanceof ValidationError) {
606
+ throw error;
607
+ }
608
+ throw new Error(`Failed to buy single edition: ${error}`);
609
+ }
610
+ }
611
+ }
612
+
613
+ export { StoreConfig, MetadataArgs, SaleConfig };