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,9 @@
1
+ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
2
+
3
+ export function getConnection(endpoint: string): Connection {
4
+ return new Connection(endpoint);
5
+ }
6
+
7
+ export function createKeypairFromSecretKey(secretKey: Uint8Array): Keypair {
8
+ return Keypair.fromSecretKey(secretKey);
9
+ }
@@ -0,0 +1,8 @@
1
+ export const devnetHolder = {
2
+ creator: "7fmpv3iEP1EYVgbnbvfrv8r99hdqpvGAPmtkpqGXztAv",
3
+ slot: 26,
4
+ };
5
+ export const mainnetHolder = {
6
+ creator: "6xzPPWsWjV2bvAufWHJHdfNrNqgbeS46yVPPofEQuJPL",
7
+ slot: 69,
8
+ };
@@ -0,0 +1,230 @@
1
+ import BN from "bn.js";
2
+ import {
3
+ BUBBLEGUM_PROGRAM_ID,
4
+ PROGRAM_ID,
5
+ SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
6
+ TOKEN_METADATA_PROGRAM_ID,
7
+ TOKEN_PROGRAM_ID,
8
+ } from "../types/programId";
9
+ import { PublicKey } from "@solana/web3.js";
10
+
11
+ export const METADATA_PREFIX = "metadata";
12
+
13
+ export function holderPDA({ creator, slot }: any) {
14
+ if (!slot) slot = 0;
15
+ creator = toPublicKey(creator);
16
+ return PublicKey.findProgramAddress(
17
+ [
18
+ Buffer.from("holder"),
19
+ creator.toBytes(),
20
+ new BN(slot).toArrayLike(Buffer, "le", 8),
21
+ ],
22
+ toPublicKey(PROGRAM_ID)
23
+ );
24
+ }
25
+
26
+ export function holderAccountPDA({ creator, slot }: any) {
27
+ if (!slot) slot = 0;
28
+ creator = toPublicKey(creator);
29
+ return PublicKey.findProgramAddress(
30
+ [
31
+ Buffer.from("holder_account"),
32
+ creator.toBytes(),
33
+ new BN(slot).toArrayLike(Buffer, "le", 8),
34
+ ],
35
+ toPublicKey(PROGRAM_ID)
36
+ );
37
+ }
38
+
39
+ export function storePDA({ storeId, creator, holder }: any) {
40
+ holder = toPublicKey(holder);
41
+ creator = toPublicKey(creator);
42
+ if (!storeId?.toNumber) storeId = new BN(storeId);
43
+ return PublicKey.findProgramAddress(
44
+ [
45
+ Buffer.from("store"),
46
+ holder.toBytes(),
47
+ creator.toBytes(),
48
+ storeId.toArrayLike(Buffer, "le", 2),
49
+ ],
50
+ toPublicKey(PROGRAM_ID)
51
+ );
52
+ }
53
+
54
+ export function creatorAuthorityPDA({ creator, store }: any) {
55
+ store = toPublicKey(store);
56
+ creator = toPublicKey(creator);
57
+ return PublicKey.findProgramAddress(
58
+ [Buffer.from("creator_authority"), store.toBytes(), creator.toBytes()],
59
+ toPublicKey(PROGRAM_ID)
60
+ );
61
+ }
62
+
63
+ export function itemAccountPDA({ creator, store, identifier }: any) {
64
+ store = toPublicKey(store);
65
+ creator = toPublicKey(creator);
66
+
67
+ return PublicKey.findProgramAddress(
68
+ [
69
+ Buffer.from("item_account"),
70
+ store.toBytes(),
71
+ creator.toBytes(),
72
+ identifier.toArrayLike(Buffer, "le", 8),
73
+ ],
74
+ toPublicKey(PROGRAM_ID)
75
+ );
76
+ }
77
+
78
+ export function itemReserveListPDA({ item }: any) {
79
+ item = toPublicKey(item);
80
+ return PublicKey.findProgramAddress(
81
+ [Buffer.from("item_reserve_list"), item.toBytes()],
82
+ toPublicKey(PROGRAM_ID)
83
+ );
84
+ }
85
+
86
+ export const toPublicKey = (key: string | PublicKey | boolean) => {
87
+ if (typeof key !== "string") return key;
88
+ const PubKeysInternedMap = new Map();
89
+ let result = PubKeysInternedMap.get(key);
90
+ if (!result) {
91
+ result = new PublicKey(key);
92
+ PubKeysInternedMap.set(key, result);
93
+ }
94
+ return result;
95
+ };
96
+
97
+ export const getMetadataPDA = async (mint: any) => {
98
+ const [publicKey] = await PublicKey.findProgramAddress(
99
+ [
100
+ Buffer.from("metadata"),
101
+ TOKEN_METADATA_PROGRAM_ID.toBuffer(),
102
+ mint.toBuffer(),
103
+ ],
104
+ TOKEN_METADATA_PROGRAM_ID //PROGRAM_ID
105
+ );
106
+ return publicKey;
107
+ };
108
+
109
+ export const getEditionPDA = async (mint: any, full: any) => {
110
+ return await PublicKey.findProgramAddress(
111
+ [
112
+ Buffer.from(METADATA_PREFIX),
113
+ toPublicKey(TOKEN_METADATA_PROGRAM_ID).toBuffer(),
114
+ mint.toBuffer(),
115
+ Buffer.from("edition"),
116
+ ],
117
+ toPublicKey(TOKEN_METADATA_PROGRAM_ID)
118
+ );
119
+ };
120
+
121
+ export const collectionAuthorityRecord = async ({
122
+ mint,
123
+ new_authority,
124
+ }: any) => {
125
+ mint = toPublicKey(mint);
126
+ new_authority = toPublicKey(new_authority);
127
+ return PublicKey.findProgramAddress(
128
+ [
129
+ Buffer.from("metadata"),
130
+ TOKEN_METADATA_PROGRAM_ID.toBuffer(),
131
+ mint.toBuffer(),
132
+ Buffer.from("collection_authority"),
133
+ new_authority.toBuffer(),
134
+ ],
135
+ TOKEN_METADATA_PROGRAM_ID
136
+ );
137
+ };
138
+
139
+ export const creatorRegistryPDA = ({ user, currency, store }: any) => {
140
+ user = toPublicKey(user);
141
+ currency = toPublicKey(currency);
142
+ store = toPublicKey(store);
143
+
144
+ return PublicKey.findProgramAddress(
145
+ [
146
+ Buffer.from("creator_registry"),
147
+ currency.toBytes(),
148
+ user.toBytes(),
149
+ store.toBytes(),
150
+ ],
151
+ toPublicKey(PROGRAM_ID)
152
+ );
153
+ };
154
+
155
+ export const userActivityPDA = async ({ user, store }: any) => {
156
+ user = toPublicKey(user);
157
+
158
+ store = toPublicKey(store);
159
+ return PublicKey.findProgramAddress(
160
+ [Buffer.from("user_activity_tracking"), user.toBytes(), store.toBytes()],
161
+ toPublicKey(PROGRAM_ID)
162
+ );
163
+ };
164
+
165
+ export const collectorArtistRegistryPDA = async ({
166
+ user,
167
+ artist,
168
+ currency,
169
+ store,
170
+ }: any) => {
171
+ user = toPublicKey(user);
172
+ currency = toPublicKey(currency);
173
+ artist = toPublicKey(artist);
174
+ store = toPublicKey(store);
175
+ return PublicKey.findProgramAddress(
176
+ [
177
+ Buffer.from("collectors_artist_registry"),
178
+ user.toBytes(),
179
+ currency.toBytes(),
180
+ artist.toBytes(),
181
+ store.toBytes(),
182
+ ],
183
+ toPublicKey(PROGRAM_ID)
184
+ );
185
+ };
186
+
187
+ export const collectorGlobalRegistryPDA = ({ user, currency, store }: any) => {
188
+ user = toPublicKey(user);
189
+ currency = toPublicKey(currency);
190
+ store = toPublicKey(store);
191
+ return PublicKey.findProgramAddress(
192
+ [
193
+ Buffer.from("collectors_global_registry"),
194
+ user.toBytes(),
195
+ currency.toBytes(),
196
+ store.toBytes(),
197
+ ],
198
+ toPublicKey(PROGRAM_ID)
199
+ );
200
+ };
201
+
202
+ export const buyPaymentPDA = ({ owner, itemAccount }: any) => {
203
+ owner = toPublicKey(owner);
204
+ itemAccount = toPublicKey(itemAccount);
205
+ return PublicKey.findProgramAddress(
206
+ [Buffer.from("buy_payment"), owner.toBytes(), itemAccount.toBytes()],
207
+ toPublicKey(PROGRAM_ID)
208
+ );
209
+ };
210
+
211
+ export const treeAuthority = ({ tree }: any) => {
212
+ tree = toPublicKey(tree);
213
+
214
+ return PublicKey.findProgramAddressSync(
215
+ [tree.toBuffer()],
216
+ toPublicKey(BUBBLEGUM_PROGRAM_ID)
217
+ );
218
+ };
219
+
220
+ export const getATAPDA = async ({ owner, mint }: any) => {
221
+ const [publicKey] = await PublicKey.findProgramAddress(
222
+ [
223
+ toPublicKey(owner).toBuffer(),
224
+ TOKEN_PROGRAM_ID.toBuffer(),
225
+ toPublicKey(mint).toBuffer(),
226
+ ],
227
+ SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID
228
+ );
229
+ return publicKey;
230
+ };
@@ -0,0 +1,32 @@
1
+ import {
2
+ PROGRAM_CNFT,
3
+ TOKEN_METADATA_PROGRAM_ID,
4
+ TOKEN_PROGRAM_ID,
5
+ } from "../types/programId";
6
+
7
+ export enum NetworkType {
8
+ DEVNET = "devnet",
9
+ MAINNET = "mainnet-beta",
10
+ }
11
+
12
+ export interface NetworkConfig {
13
+ endpoint: string;
14
+ programId: string;
15
+ tokenProgramId: string;
16
+ metadataProgramId: string;
17
+ }
18
+
19
+ export const NETWORK_CONFIGS: Record<NetworkType, NetworkConfig> = {
20
+ [NetworkType.DEVNET]: {
21
+ endpoint: "https://api.devnet.solana.com",
22
+ programId: PROGRAM_CNFT,
23
+ tokenProgramId: TOKEN_PROGRAM_ID,
24
+ metadataProgramId: TOKEN_METADATA_PROGRAM_ID,
25
+ },
26
+ [NetworkType.MAINNET]: {
27
+ endpoint: "https://api.mainnet-beta.solana.com",
28
+ programId: PROGRAM_CNFT,
29
+ tokenProgramId: TOKEN_PROGRAM_ID,
30
+ metadataProgramId: TOKEN_METADATA_PROGRAM_ID,
31
+ },
32
+ };
@@ -0,0 +1,191 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { FileData } from "../library/instructions/store/uploadFilesIryis";
3
+
4
+ export function bytesToU32(slice: any) {
5
+ let result = 0;
6
+ for (let i = slice.length - 1; i >= 0; i--) {
7
+ result = (result << 8) | slice[i];
8
+ }
9
+ return result >>> 0;
10
+ }
11
+
12
+ export const cyrb53 = (str: any, seed = 0) => {
13
+ let h1 = 0xdeadbeef ^ seed,
14
+ h2 = 0x41c6ce57 ^ seed;
15
+
16
+ let arr = null;
17
+ if (typeof str != "string") {
18
+ if (Array.isArray(str)) {
19
+ arr = str;
20
+ } else {
21
+ str = str + "";
22
+ }
23
+ }
24
+ if (arr) {
25
+ for (const ch of arr) {
26
+ h1 = Math.imul(h1 ^ ch, 2654435761);
27
+ h2 = Math.imul(h2 ^ ch, 1597334677);
28
+ }
29
+ } else {
30
+ for (let i = 0, ch; i < str.length; i++) {
31
+ ch = str.charCodeAt(i);
32
+ h1 = Math.imul(h1 ^ ch, 2654435761);
33
+ h2 = Math.imul(h2 ^ ch, 1597334677);
34
+ }
35
+ }
36
+ h1 =
37
+ Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
38
+ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
39
+ h2 =
40
+ Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
41
+ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
42
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0);
43
+ };
44
+
45
+ export const sleep = (t: any) => {
46
+ return new Promise((res) => {
47
+ setTimeout(res, t);
48
+ });
49
+ };
50
+
51
+ export const nowS = () => Date.now() / 1000;
52
+
53
+ export const validateSolAddress = (address: any) => {
54
+ try {
55
+ let pubkey = new PublicKey(address);
56
+ return PublicKey.isOnCurve(pubkey.toBuffer());
57
+ } catch (error) {
58
+ return false;
59
+ }
60
+ };
61
+
62
+ export const checkFileType = (file: any) => {
63
+ return file?.type?.includes("video/webp")
64
+ ? "video/webp"
65
+ : file?.type?.includes("image/webp")
66
+ ? "image/webp"
67
+ : file?.type?.includes("jpeg") || file?.type?.includes("jpg")
68
+ ? "image/jpeg"
69
+ : file?.type?.includes("gif")
70
+ ? "image/gif"
71
+ : file?.type?.includes("png")
72
+ ? "image/png"
73
+ : file?.type?.includes("audio")
74
+ ? "audio"
75
+ : file?.type?.includes("mp4")
76
+ ? "video/mp4"
77
+ : file?.name?.includes("glb") || file?.type?.includes("model")
78
+ ? "model/gltf-binary"
79
+ : null;
80
+ };
81
+
82
+ export const checkCategory = (file: any) => {
83
+ return file?.type?.includes("image")
84
+ ? "image"
85
+ : file?.type?.includes("audio")
86
+ ? "audio"
87
+ : file?.type?.includes("video")
88
+ ? "video"
89
+ : file?.name?.includes("glb") || file?.type?.includes("model")
90
+ ? "vr"
91
+ : null;
92
+ };
93
+
94
+ export async function normalizeFileData(fileData: any): Promise<FileData> {
95
+ try {
96
+ const buffer = await (fileData.arrayBuffer instanceof Function
97
+ ? fileData.arrayBuffer()
98
+ : Promise.resolve(fileData.arrayBuffer));
99
+
100
+ const type = fileData.type || getMimeTypeFromBuffer(buffer);
101
+
102
+ return {
103
+ arrayBuffer: () => buffer,
104
+ type,
105
+ size: buffer.byteLength,
106
+ name: fileData.name,
107
+ };
108
+ } catch (error) {
109
+ throw new Error(`Failed to normalize file data: ${error}`);
110
+ }
111
+ }
112
+
113
+ function getMimeTypeFromBuffer(buffer: ArrayBuffer): string {
114
+ const arr = new Uint8Array(buffer).subarray(0, 12);
115
+ const header = Array.from(arr)
116
+ .map((byte) => byte.toString(16))
117
+ .join("");
118
+
119
+ if (header.startsWith("89504e47")) return "image/png";
120
+ if (header.startsWith("474946")) return "image/gif";
121
+ if (header.startsWith("ffd8ff")) return "image/jpeg";
122
+ if (header.startsWith("52494646") && header.includes("57454250"))
123
+ return "image/webp";
124
+ if (header.startsWith("494433") || header.startsWith("fffb"))
125
+ return "audio/mp3";
126
+ if (
127
+ header.startsWith("000000") &&
128
+ (header.includes("66747970") || header.includes("6d6f6f76"))
129
+ )
130
+ return "video/mp4";
131
+ if (header.startsWith("676c5446")) return "model/gltf-binary";
132
+
133
+ return "application/octet-stream";
134
+ }
135
+
136
+ export function getFileType(file: any): string | null {
137
+ if (!file) return null;
138
+
139
+ const type = file.type?.toLowerCase() || "";
140
+ const name = (file.name || "").toLowerCase();
141
+
142
+ if (type.includes("video/webp")) return "video/webp";
143
+ if (type.includes("image/webp")) return "image/webp";
144
+ if (type.includes("jpeg") || type.includes("jpg")) return "image/jpeg";
145
+ if (type.includes("gif")) return "image/gif";
146
+ if (type.includes("png")) return "image/png";
147
+ if (type.includes("mp3") || type.includes("audio/mp3")) return "audio/mp3";
148
+ if (type.includes("mp4")) return "video/mp4";
149
+ if (type.includes("glb") || name.endsWith(".glb")) return "model/gltf-binary";
150
+
151
+ return type || null;
152
+ }
153
+
154
+ export function validateFileType(type: string): void {
155
+ const allowedTypes = [
156
+ "image/png",
157
+ "image/jpeg",
158
+ "image/gif",
159
+ "image/webp",
160
+ "video/mp4",
161
+ "audio/mp3",
162
+ "model/gltf-binary",
163
+ "application/octet-stream",
164
+ ];
165
+
166
+ if (!allowedTypes.includes(type)) {
167
+ throw new Error(`Unsupported file type: ${type}`);
168
+ }
169
+ }
170
+
171
+ export function getFileCategory(file: any): string | null {
172
+ if (!file) return null;
173
+
174
+ const type = (file.type || "").toLowerCase();
175
+ const name = (file.name || "").toLowerCase();
176
+
177
+ if (type.includes("image")) return "image";
178
+ if (type.includes("audio")) return "audio";
179
+ if (type.includes("video")) return "video";
180
+ if (type.includes("model") || name.endsWith(".glb")) return "vr";
181
+
182
+ return null;
183
+ }
184
+
185
+ export function isAnimatable(type: string): boolean {
186
+ return (
187
+ type?.includes("video/") ||
188
+ type?.includes("audio/") ||
189
+ type === "model/gltf-binary"
190
+ );
191
+ }
@@ -0,0 +1,229 @@
1
+ import { PublicKey, Signer } from "@solana/web3.js";
2
+ import { StoreConfig, SaleConfig, ShortMetadataArgs } from "../types/types";
3
+ import { BN } from "bn.js";
4
+
5
+ export class ValidationError extends Error {
6
+ constructor(message: string) {
7
+ super(message);
8
+ this.name = "ValidationError";
9
+ }
10
+ }
11
+
12
+ export function validateStoreConfig(config: StoreConfig) {
13
+ if (!config.fee || !(config.fee instanceof BN)) {
14
+ throw new ValidationError("Store fee must be a valid BN instance");
15
+ }
16
+
17
+ if (
18
+ typeof config.feePercentage !== "number" ||
19
+ config.feePercentage < 0 ||
20
+ config.feePercentage > 100
21
+ ) {
22
+ throw new ValidationError(
23
+ "Fee percentage must be a number between 0 and 100"
24
+ );
25
+ }
26
+
27
+ if (!config.trust || !(config.trust instanceof PublicKey)) {
28
+ throw new ValidationError("Trust must be a valid PublicKey");
29
+ }
30
+ }
31
+
32
+ export function validateMetadata(metadata: ShortMetadataArgs) {
33
+ if (!metadata.name || metadata.name.length > 32) {
34
+ throw new ValidationError(
35
+ "Metadata name is required and must be <= 32 characters"
36
+ );
37
+ }
38
+
39
+ if (metadata.uriType !== 0 && metadata.uriType !== 1) {
40
+ throw new ValidationError("Invalid URI type");
41
+ }
42
+
43
+ if (!metadata.creators || !metadata.creators.length) {
44
+ throw new ValidationError("At least one creator is required");
45
+ }
46
+
47
+ const totalShares = metadata.creators.reduce(
48
+ (sum, creator) => sum + creator.share,
49
+ 0
50
+ );
51
+ if (totalShares !== 100) {
52
+ throw new ValidationError("Creator shares must sum to 100");
53
+ }
54
+ }
55
+
56
+ export function validateSaleConfig(config: SaleConfig) {
57
+ if (!config.prices || !config.prices.length) {
58
+ throw new ValidationError("At least one price configuration is required");
59
+ }
60
+
61
+ config.prices.forEach((price) => {
62
+ if (!price.amount || !(price.amount instanceof BN)) {
63
+ throw new ValidationError(
64
+ "Each price amount must be a valid BN instance"
65
+ );
66
+ }
67
+ });
68
+
69
+ if (config.sendToVault < 0) {
70
+ throw new ValidationError("sendToVault must be non-negative");
71
+ }
72
+ }
73
+
74
+ export function validateSupply(supply: number) {
75
+ if (typeof supply !== "number" || supply < 0) {
76
+ throw new ValidationError("Supply must be a non-negative number");
77
+ }
78
+ }
79
+
80
+ export function validateIdentifier(identifier: number) {
81
+ if (typeof identifier !== "number" || identifier < 0) {
82
+ throw new ValidationError("Identifier must be a non-negative number");
83
+ }
84
+ }
85
+
86
+ export function validateCollectionArgs(
87
+ collectionDetails: any,
88
+ supply: number,
89
+ metadata: any,
90
+ irysData: any
91
+ ) {
92
+ if (!collectionDetails || typeof collectionDetails.__kind !== "string") {
93
+ throw new ValidationError("Invalid collection details format");
94
+ }
95
+
96
+ if (typeof supply !== "number" || supply < 0) {
97
+ throw new ValidationError("Supply must be a non-negative number");
98
+ }
99
+
100
+ if (!metadata) {
101
+ throw new ValidationError("Metadata is required");
102
+ }
103
+
104
+ // Validate metadata fields
105
+ if (!metadata.symbol || metadata.symbol.length > 10) {
106
+ throw new ValidationError(
107
+ "Symbol is required and must be <= 10 characters"
108
+ );
109
+ }
110
+
111
+ if (!metadata.name || metadata.name.length > 32) {
112
+ throw new ValidationError("Name is required and must be <= 32 characters");
113
+ }
114
+
115
+ if (!metadata.creators || !Array.isArray(metadata.creators)) {
116
+ throw new ValidationError("Creators array is required");
117
+ }
118
+
119
+ const totalShares = metadata.creators.reduce(
120
+ (sum: number, creator: any) => sum + creator.share,
121
+ 0
122
+ );
123
+ if (totalShares !== 100) {
124
+ throw new ValidationError("Creator shares must sum to 100");
125
+ }
126
+
127
+ // Validate Irys data
128
+ if (!irysData || !irysData.options || !irysData.options.metadata) {
129
+ throw new ValidationError("Invalid Irys data format");
130
+ }
131
+
132
+ if (
133
+ !irysData.options.metadata.files ||
134
+ !irysData.options.metadata.files.file
135
+ ) {
136
+ throw new ValidationError("Collection image file is required");
137
+ }
138
+ }
139
+
140
+ export function validateBuySingleArgs(
141
+ payer: Signer,
142
+ packAccount: PublicKey,
143
+ burnProgress: PublicKey,
144
+ owner: PublicKey,
145
+ distributionBumps: number[],
146
+ globalStoreAccount: PublicKey,
147
+ extraAccounts: any[],
148
+ collectionAddress?: PublicKey,
149
+ storeAccount?: PublicKey,
150
+ creator?: PublicKey
151
+ ) {
152
+ if (!payer || !payer.publicKey) {
153
+ throw new ValidationError("Invalid payer");
154
+ }
155
+
156
+ if (!PublicKey.isOnCurve(packAccount)) {
157
+ throw new ValidationError("Invalid pack account public key");
158
+ }
159
+
160
+ if (!PublicKey.isOnCurve(burnProgress)) {
161
+ throw new ValidationError("Invalid burn progress public key");
162
+ }
163
+
164
+ if (!PublicKey.isOnCurve(owner)) {
165
+ throw new ValidationError("Invalid owner public key");
166
+ }
167
+
168
+ if (!Array.isArray(distributionBumps) || distributionBumps.length !== 6) {
169
+ throw new ValidationError(
170
+ "Distribution bumps must be an array of length 6"
171
+ );
172
+ }
173
+
174
+ distributionBumps.forEach((bump, index) => {
175
+ if (typeof bump !== "number" || bump < 0 || bump > 255) {
176
+ throw new ValidationError(`Invalid distribution bump at index ${index}`);
177
+ }
178
+ });
179
+
180
+ if (!storeAccount) {
181
+ throw new ValidationError("Store account missing");
182
+ }
183
+
184
+ if (PublicKey.isOnCurve(storeAccount)) {
185
+ throw new ValidationError("Invalid store account public key");
186
+ }
187
+
188
+ if (PublicKey.isOnCurve(globalStoreAccount)) {
189
+ throw new ValidationError("Invalid global store account public key");
190
+ }
191
+
192
+ if (!collectionAddress) {
193
+ throw new ValidationError("Collection address missing");
194
+ }
195
+
196
+ if (!PublicKey.isOnCurve(collectionAddress)) {
197
+ throw new ValidationError("Invalid collection address public key");
198
+ }
199
+
200
+ if (!creator) {
201
+ throw new ValidationError("Creator public key missing");
202
+ }
203
+
204
+ if (!PublicKey.isOnCurve(creator)) {
205
+ throw new ValidationError("Invalid creator public key");
206
+ }
207
+
208
+ if (!Array.isArray(extraAccounts)) {
209
+ throw new ValidationError("Extra accounts must be an array");
210
+ }
211
+
212
+ extraAccounts.forEach((account, index) => {
213
+ if (!account.pubkey || PublicKey.isOnCurve(account.pubkey)) {
214
+ throw new ValidationError(
215
+ `Invalid public key in extra accounts at index ${index}`
216
+ );
217
+ }
218
+ if (typeof account.isSigner !== "boolean") {
219
+ throw new ValidationError(
220
+ `Invalid isSigner flag in extra accounts at index ${index}`
221
+ );
222
+ }
223
+ if (typeof account.isWritable !== "boolean") {
224
+ throw new ValidationError(
225
+ `Invalid isWritable flag in extra accounts at index ${index}`
226
+ );
227
+ }
228
+ });
229
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6",
4
+ "module": "commonjs",
5
+ "strict": true,
6
+ "esModuleInterop": true,
7
+ "outDir": "./dist",
8
+ "declaration": true
9
+ },
10
+ "include": ["src"],
11
+ "exclude": ["node_modules"]
12
+ }