3land_sdk 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +352 -0
- package/assets/3land_rebrand.gif +0 -0
- package/assets/battle_sol.gif +0 -0
- package/assets/ds.jpeg +0 -0
- package/assets/future.webp +0 -0
- package/assets/music.mp3 +0 -0
- package/assets/niicl.gif +0 -0
- package/assets/og.png +0 -0
- package/assets/phone.glb +0 -0
- package/assets/testvid.mp4 +0 -0
- package/idl.json +7652 -0
- package/package.json +35 -0
- package/src/index.ts +89 -0
- package/src/library/Irys/irys.ts +412 -0
- package/src/library/Store.ts +613 -0
- package/src/library/implementation/storeImplementation.ts +385 -0
- package/src/library/instructions/store/buySingleEdition.ts +227 -0
- package/src/library/instructions/store/createSingleEdition.ts +49 -0
- package/src/library/instructions/store/createStore.ts +19 -0
- package/src/library/instructions/store/idl.ts +7622 -0
- package/src/library/instructions/store/uploadFilesIryis.ts +133 -0
- package/src/types/accounts/ArchiveDeposit.ts +207 -0
- package/src/types/accounts/Authority.ts +73 -0
- package/src/types/accounts/BurnDeposit.ts +111 -0
- package/src/types/accounts/BurnProgress.ts +97 -0
- package/src/types/accounts/BuyHistory.ts +121 -0
- package/src/types/accounts/BuyTrack.ts +94 -0
- package/src/types/accounts/Card.ts +185 -0
- package/src/types/accounts/CollectionRegistry.ts +145 -0
- package/src/types/accounts/CollectorRegistry.ts +145 -0
- package/src/types/accounts/CreatorRegistry.ts +153 -0
- package/src/types/accounts/CurrencyArtistProof.ts +113 -0
- package/src/types/accounts/GenericUser.ts +185 -0
- package/src/types/accounts/ItemArchive.ts +223 -0
- package/src/types/accounts/ItemReserveList.ts +87 -0
- package/src/types/accounts/ItemReserveList2.ts +73 -0
- package/src/types/accounts/LutVault.ts +97 -0
- package/src/types/accounts/Pack.ts +367 -0
- package/src/types/accounts/PackContent.ts +97 -0
- package/src/types/accounts/PackOpenHolder.ts +141 -0
- package/src/types/accounts/PackReceipt.ts +145 -0
- package/src/types/accounts/PackTraits.ts +101 -0
- package/src/types/accounts/Payment.ts +97 -0
- package/src/types/accounts/PoolVault.ts +177 -0
- package/src/types/accounts/RevealForMe.ts +139 -0
- package/src/types/accounts/SecureHolder.ts +97 -0
- package/src/types/accounts/Single.ts +301 -0
- package/src/types/accounts/Store.ts +180 -0
- package/src/types/accounts/StoresHolder.ts +131 -0
- package/src/types/accounts/ThreeId.ts +189 -0
- package/src/types/accounts/TokenManager.ts +217 -0
- package/src/types/accounts/ZeroCard.ts +73 -0
- package/src/types/accounts/ZeroContent.ts +89 -0
- package/src/types/accounts/ZeroOpenHolder.ts +183 -0
- package/src/types/accounts/index.ts +84 -0
- package/src/types/errors/anchor.ts +773 -0
- package/src/types/errors/index.ts +59 -0
- package/src/types/implementation/implementationTypes.ts +27 -0
- package/src/types/instructions/addBurn.ts +56 -0
- package/src/types/instructions/adjustDepositBurn.ts +33 -0
- package/src/types/instructions/archiveItem.ts +60 -0
- package/src/types/instructions/assignPackDelegate.ts +30 -0
- package/src/types/instructions/burnPay.ts +55 -0
- package/src/types/instructions/buyPack.ts +69 -0
- package/src/types/instructions/buyPay.ts +71 -0
- package/src/types/instructions/buyToken.ts +64 -0
- package/src/types/instructions/claimZeroCard.ts +106 -0
- package/src/types/instructions/closeDepositBurn.ts +47 -0
- package/src/types/instructions/closeRegisterTraits.ts +28 -0
- package/src/types/instructions/createCard.ts +56 -0
- package/src/types/instructions/createCollection.ts +68 -0
- package/src/types/instructions/createPack.ts +71 -0
- package/src/types/instructions/createSingle.ts +71 -0
- package/src/types/instructions/createStore.ts +50 -0
- package/src/types/instructions/createTokenLauncher.ts +82 -0
- package/src/types/instructions/createZeroCard.ts +76 -0
- package/src/types/instructions/deleteCard.ts +32 -0
- package/src/types/instructions/deletePack.ts +40 -0
- package/src/types/instructions/deleteSingle.ts +36 -0
- package/src/types/instructions/deleteTokenLauncher.ts +38 -0
- package/src/types/instructions/depositBurn.ts +55 -0
- package/src/types/instructions/donateUser.ts +84 -0
- package/src/types/instructions/feedPool.ts +61 -0
- package/src/types/instructions/feedTraits.ts +44 -0
- package/src/types/instructions/feedTree.ts +63 -0
- package/src/types/instructions/flagPack.ts +50 -0
- package/src/types/instructions/flagSingle.ts +47 -0
- package/src/types/instructions/gatePay.ts +59 -0
- package/src/types/instructions/index.ts +140 -0
- package/src/types/instructions/initialize.ts +46 -0
- package/src/types/instructions/openPack.ts +79 -0
- package/src/types/instructions/prepareCreator.ts +30 -0
- package/src/types/instructions/preparePack.ts +51 -0
- package/src/types/instructions/prepareTraits.ts +28 -0
- package/src/types/instructions/printPack.ts +95 -0
- package/src/types/instructions/printSingle.ts +108 -0
- package/src/types/instructions/recoverDepositBurn.ts +80 -0
- package/src/types/instructions/registerActivity.ts +43 -0
- package/src/types/instructions/registerCollector.ts +63 -0
- package/src/types/instructions/registerCreator.ts +48 -0
- package/src/types/instructions/registerGenericUser.ts +94 -0
- package/src/types/instructions/registerPackUploads.ts +44 -0
- package/src/types/instructions/registerTraits.ts +42 -0
- package/src/types/instructions/registerUser.ts +50 -0
- package/src/types/instructions/storeLutFor.ts +44 -0
- package/src/types/instructions/unwrapAndDestroy.ts +56 -0
- package/src/types/instructions/updateCard.ts +54 -0
- package/src/types/instructions/updatePack.ts +71 -0
- package/src/types/instructions/updateSingle.ts +64 -0
- package/src/types/instructions/updateStore.ts +47 -0
- package/src/types/instructions/withdrawFromStore.ts +26 -0
- package/src/types/programId.ts +42 -0
- package/src/types/types/AccountClass.ts +868 -0
- package/src/types/types/AccountHasher.ts +89 -0
- package/src/types/types/ActionAfter.ts +202 -0
- package/src/types/types/AllowedCurrencyArgs.ts +53 -0
- package/src/types/types/AuthorityGateTypes.ts +90 -0
- package/src/types/types/BurnCount.ts +60 -0
- package/src/types/types/BurnState.ts +88 -0
- package/src/types/types/BurnTrack.ts +64 -0
- package/src/types/types/BurnType.ts +118 -0
- package/src/types/types/BurnTypeBurn.ts +56 -0
- package/src/types/types/BuyHistoryClass.ts +90 -0
- package/src/types/types/CardClass.ts +56 -0
- package/src/types/types/CardState.ts +238 -0
- package/src/types/types/CardTrack.ts +76 -0
- package/src/types/types/Category.ts +72 -0
- package/src/types/types/CnftData.ts +85 -0
- package/src/types/types/CollectTrack.ts +61 -0
- package/src/types/types/Collection.ts +64 -0
- package/src/types/types/CompactCnftData.ts +76 -0
- package/src/types/types/CoolTimePerAmountArgs.ts +72 -0
- package/src/types/types/Creator.ts +72 -0
- package/src/types/types/CreatorGateArgs.ts +53 -0
- package/src/types/types/CurrencyArtistProof.ts +85 -0
- package/src/types/types/CurrencyType.ts +259 -0
- package/src/types/types/DateTraitInit.ts +61 -0
- package/src/types/types/DateTraitInitMap.ts +72 -0
- package/src/types/types/Deposit.ts +85 -0
- package/src/types/types/DepositFormat.ts +90 -0
- package/src/types/types/DepositState.ts +88 -0
- package/src/types/types/DepositSubtype.ts +90 -0
- package/src/types/types/DepositTrack.ts +69 -0
- package/src/types/types/DepositTrackType.ts +120 -0
- package/src/types/types/DepositType.ts +245 -0
- package/src/types/types/Earnings.ts +37 -0
- package/src/types/types/EditionStoreType.ts +120 -0
- package/src/types/types/EncryptedPayload.ts +61 -0
- package/src/types/types/ExtraParameter.ts +117 -0
- package/src/types/types/FakeBurnCount.ts +64 -0
- package/src/types/types/FakeDeposit.ts +64 -0
- package/src/types/types/FakeTraitPair.ts +61 -0
- package/src/types/types/FakeTraitValue.ts +61 -0
- package/src/types/types/FakeVolumeTrack.ts +64 -0
- package/src/types/types/FeeType.ts +118 -0
- package/src/types/types/FeedingTraits.ts +57 -0
- package/src/types/types/Filter.ts +64 -0
- package/src/types/types/FilterType.ts +56 -0
- package/src/types/types/GeneralStore.ts +56 -0
- package/src/types/types/GenericStore.ts +64 -0
- package/src/types/types/GenericValue.ts +172 -0
- package/src/types/types/GlobalFee.ts +85 -0
- package/src/types/types/GlobalState.ts +148 -0
- package/src/types/types/IndexDate.ts +94 -0
- package/src/types/types/IndexDates.ts +64 -0
- package/src/types/types/Item.ts +53 -0
- package/src/types/types/ItemClass.ts +88 -0
- package/src/types/types/ItemState.ts +298 -0
- package/src/types/types/ItemTrack.ts +76 -0
- package/src/types/types/ListingPerWalletArgs.ts +53 -0
- package/src/types/types/MemeVaultProof.ts +64 -0
- package/src/types/types/MetadataArgs.ts +207 -0
- package/src/types/types/NonFungibleTraitInit.ts +64 -0
- package/src/types/types/NonFungibleTraitInitMap.ts +84 -0
- package/src/types/types/OnlyBetweenTimesArgs.ts +76 -0
- package/src/types/types/OnlyTheseDOWArgs.ts +53 -0
- package/src/types/types/PackConfig.ts +98 -0
- package/src/types/types/PackOpenHolderState.ts +120 -0
- package/src/types/types/PackRule.ts +85 -0
- package/src/types/types/PackState.ts +118 -0
- package/src/types/types/PackType.ts +118 -0
- package/src/types/types/PaymentClass.ts +118 -0
- package/src/types/types/PoolAccess.ts +88 -0
- package/src/types/types/PoolState.ts +88 -0
- package/src/types/types/PoolType.ts +88 -0
- package/src/types/types/Popularity.ts +76 -0
- package/src/types/types/PopularityState.ts +630 -0
- package/src/types/types/PreviousDonationRecord.ts +76 -0
- package/src/types/types/Price.ts +64 -0
- package/src/types/types/PriceRule.ts +216 -0
- package/src/types/types/RecoverDeposit.ts +56 -0
- package/src/types/types/Rule.ts +199 -0
- package/src/types/types/SaleConfig.ts +102 -0
- package/src/types/types/SaleTrack.ts +85 -0
- package/src/types/types/SaleType.ts +148 -0
- package/src/types/types/Seed.ts +61 -0
- package/src/types/types/SelectedCard.ts +61 -0
- package/src/types/types/SelectedZeroCard.ts +61 -0
- package/src/types/types/SemiFungibleTraitInit.ts +61 -0
- package/src/types/types/SemiFungibleTraitInitMap.ts +72 -0
- package/src/types/types/ShortCreator.ts +64 -0
- package/src/types/types/ShortMetadata.ts +145 -0
- package/src/types/types/ShortMetadataArgs.ts +111 -0
- package/src/types/types/StoreConfig.ts +98 -0
- package/src/types/types/StoreRule.ts +145 -0
- package/src/types/types/SuperCategory.ts +61 -0
- package/src/types/types/TightCardMetadata.ts +120 -0
- package/src/types/types/TimeRangeType.ts +120 -0
- package/src/types/types/TimedPerWalletArgs.ts +53 -0
- package/src/types/types/TokenMetadata.ts +72 -0
- package/src/types/types/TokenProgramVersion.ts +90 -0
- package/src/types/types/TokenStandard.ts +150 -0
- package/src/types/types/TokenState.ts +88 -0
- package/src/types/types/TokenType.ts +88 -0
- package/src/types/types/TotalPerTimeArgs.ts +85 -0
- package/src/types/types/TotalPerTimeWalletArgs.ts +61 -0
- package/src/types/types/TrackRegistry.ts +90 -0
- package/src/types/types/TraitInit.ts +210 -0
- package/src/types/types/TraitPass.ts +60 -0
- package/src/types/types/TraitPassType.ts +225 -0
- package/src/types/types/TraitType.ts +267 -0
- package/src/types/types/TraitValue.ts +72 -0
- package/src/types/types/UnlocksAfter.ts +172 -0
- package/src/types/types/UnwrapMetadata.ts +156 -0
- package/src/types/types/UseMethod.ts +118 -0
- package/src/types/types/Uses.ts +76 -0
- package/src/types/types/VerifyCollectionMetadata.ts +109 -0
- package/src/types/types/VolumeTrack.ts +61 -0
- package/src/types/types/WrappedSource.ts +85 -0
- package/src/types/types/ZeroConfig.ts +85 -0
- package/src/types/types/index.ts +798 -0
- package/src/utility/Connection.ts +9 -0
- package/src/utility/Holders.ts +8 -0
- package/src/utility/PdaManager.ts +230 -0
- package/src/utility/config.ts +32 -0
- package/src/utility/utils.ts +191 -0
- package/src/utility/validation.ts +229 -0
- package/tsconfig.json +12 -0
@@ -0,0 +1,385 @@
|
|
1
|
+
import { BN } from "bn.js";
|
2
|
+
import { StoreConfig, SaleConfig, Store } from "../Store";
|
3
|
+
import { Keypair, PublicKey, SendTransactionError } from "@solana/web3.js";
|
4
|
+
import {
|
5
|
+
Creator,
|
6
|
+
CurrencyType,
|
7
|
+
FeeType,
|
8
|
+
PriceJSON,
|
9
|
+
PriceRule,
|
10
|
+
SaleConfigJSON,
|
11
|
+
SaleType,
|
12
|
+
ShortMetadataArgs,
|
13
|
+
ShortMetadataArgsJSON,
|
14
|
+
StoreConfigJSON,
|
15
|
+
} from "../../types/types";
|
16
|
+
import { Wallet } from "@project-serum/anchor";
|
17
|
+
import * as fs2 from "fs";
|
18
|
+
import { PROGRAM_CNFT, SOLANA_ENDPOINT } from "../../types/programId";
|
19
|
+
import path from "path";
|
20
|
+
import { arrayBuffer } from "stream/consumers";
|
21
|
+
import { bs58 } from "@project-serum/anchor/dist/cjs/utils/bytes";
|
22
|
+
import {
|
23
|
+
CreateCollectionOptions,
|
24
|
+
CreateSingleOptions,
|
25
|
+
CreateStoreParams,
|
26
|
+
StoreInitOptions,
|
27
|
+
} from "../../types/implementation/implementationTypes";
|
28
|
+
|
29
|
+
function initializeSDKAndWallet(options: StoreInitOptions) {
|
30
|
+
const sdk = new Store();
|
31
|
+
let walletKeypair: Keypair;
|
32
|
+
|
33
|
+
if (options.privateKey) {
|
34
|
+
if (typeof options.privateKey === "string") {
|
35
|
+
// Decode base58 string to Uint8Array
|
36
|
+
try {
|
37
|
+
const decoded = bs58.decode(options.privateKey);
|
38
|
+
walletKeypair = Keypair.fromSecretKey(decoded);
|
39
|
+
} catch (error) {
|
40
|
+
throw new Error(`Invalid base58 private key: ${error}`);
|
41
|
+
}
|
42
|
+
} else if (Array.isArray(options.privateKey)) {
|
43
|
+
// Handle array of numbers
|
44
|
+
walletKeypair = Keypair.fromSecretKey(
|
45
|
+
Uint8Array.from(options.privateKey)
|
46
|
+
);
|
47
|
+
} else {
|
48
|
+
// Handle Uint8Array directly
|
49
|
+
walletKeypair = Keypair.fromSecretKey(options.privateKey);
|
50
|
+
}
|
51
|
+
} else if (options.walletPath) {
|
52
|
+
// Existing file-based initialization
|
53
|
+
const secretKey = JSON.parse(fs2.readFileSync(options.walletPath, "utf-8"));
|
54
|
+
walletKeypair = Keypair.fromSecretKey(Uint8Array.from(secretKey));
|
55
|
+
} else {
|
56
|
+
throw new Error("Either walletPath or privateKey must be provided");
|
57
|
+
}
|
58
|
+
|
59
|
+
const payer = new Wallet(walletKeypair);
|
60
|
+
return { sdk, walletKeypair, payer };
|
61
|
+
}
|
62
|
+
|
63
|
+
async function createStoreImp(
|
64
|
+
options: StoreInitOptions,
|
65
|
+
storeSetup: CreateStoreParams
|
66
|
+
) {
|
67
|
+
const { sdk, walletKeypair, payer } = initializeSDKAndWallet(options);
|
68
|
+
|
69
|
+
try {
|
70
|
+
const storeConfig: StoreConfig = {
|
71
|
+
fee: new BN(1000000),
|
72
|
+
feePercentage: storeSetup.storeFee,
|
73
|
+
feeType: new FeeType.AllMints(),
|
74
|
+
trust: payer.publicKey,
|
75
|
+
rules: [],
|
76
|
+
toJSON: function (): StoreConfigJSON {
|
77
|
+
throw new Error("Function not implemented.");
|
78
|
+
},
|
79
|
+
toEncodable: function () {
|
80
|
+
throw new Error("Function not implemented.");
|
81
|
+
},
|
82
|
+
};
|
83
|
+
|
84
|
+
const createStoreTxId = await sdk.createStore(
|
85
|
+
walletKeypair,
|
86
|
+
storeSetup.storeName,
|
87
|
+
storeConfig
|
88
|
+
);
|
89
|
+
|
90
|
+
return {
|
91
|
+
transactionId: createStoreTxId,
|
92
|
+
payerPublicKey: payer.publicKey.toString(),
|
93
|
+
};
|
94
|
+
} catch (error) {
|
95
|
+
handleError(error);
|
96
|
+
throw error;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
async function createCollectionTest(
|
101
|
+
options: StoreInitOptions,
|
102
|
+
collectionOpts: CreateCollectionOptions
|
103
|
+
) {
|
104
|
+
const { sdk, walletKeypair, payer } = initializeSDKAndWallet(options);
|
105
|
+
|
106
|
+
const collectionDetails = { __kind: "V1", size: 0 };
|
107
|
+
const creator = new Creator({
|
108
|
+
address: payer.publicKey,
|
109
|
+
verified: false,
|
110
|
+
share: 100,
|
111
|
+
});
|
112
|
+
|
113
|
+
const metadata = {
|
114
|
+
symbol: collectionOpts.collectionSymbol, //max 10 chars
|
115
|
+
name: collectionOpts.collectionName, //max 32 chars
|
116
|
+
uri: "",
|
117
|
+
sellerFeeBasisPoints: new BN(5),
|
118
|
+
creators: [creator],
|
119
|
+
collection: null,
|
120
|
+
uses: null,
|
121
|
+
};
|
122
|
+
|
123
|
+
const imageBuffer = fs2.readFileSync(
|
124
|
+
path.join(process.cwd(), "assets", "ds.jpeg")
|
125
|
+
).buffer;
|
126
|
+
const coverBuffer = fs2.readFileSync(
|
127
|
+
path.join(process.cwd(), "assets", "3land_rebrand.gif")
|
128
|
+
).buffer;
|
129
|
+
|
130
|
+
const optionsCollection = {
|
131
|
+
symbol: metadata.symbol,
|
132
|
+
metadata: {
|
133
|
+
name: metadata.name,
|
134
|
+
description: collectionOpts.collectionDescription,
|
135
|
+
files: {
|
136
|
+
file: {
|
137
|
+
arrayBuffer() {
|
138
|
+
return imageBuffer;
|
139
|
+
},
|
140
|
+
type: "image/gif",
|
141
|
+
},
|
142
|
+
cover: {
|
143
|
+
arrayBuffer() {
|
144
|
+
return coverBuffer;
|
145
|
+
},
|
146
|
+
type: "image/gif",
|
147
|
+
},
|
148
|
+
},
|
149
|
+
},
|
150
|
+
creators: metadata.creators,
|
151
|
+
traits: [],
|
152
|
+
sellerFeeBasisPoints: metadata.sellerFeeBasisPoints,
|
153
|
+
};
|
154
|
+
|
155
|
+
try {
|
156
|
+
const collectionTx = await sdk.createCollection(
|
157
|
+
walletKeypair,
|
158
|
+
collectionDetails,
|
159
|
+
metadata,
|
160
|
+
{
|
161
|
+
options: optionsCollection,
|
162
|
+
}
|
163
|
+
);
|
164
|
+
console.log("create collection tx: ", collectionTx);
|
165
|
+
return collectionTx;
|
166
|
+
} catch (error) {
|
167
|
+
handleError(error);
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
async function createSingleImp(
|
172
|
+
options: StoreInitOptions,
|
173
|
+
storeAccount: string,
|
174
|
+
collectionAccount: string,
|
175
|
+
createOptions: CreateSingleOptions
|
176
|
+
) {
|
177
|
+
const { sdk, walletKeypair, payer } = initializeSDKAndWallet(options);
|
178
|
+
|
179
|
+
try {
|
180
|
+
const creator = new Creator({
|
181
|
+
address: payer.publicKey,
|
182
|
+
verified: false,
|
183
|
+
share: 100,
|
184
|
+
});
|
185
|
+
|
186
|
+
const metadata: ShortMetadataArgs = {
|
187
|
+
name: createOptions.itemName,
|
188
|
+
uri: "",
|
189
|
+
uriType: 1,
|
190
|
+
sellerFeeBasisPoints: createOptions.sellerFee,
|
191
|
+
collection: new PublicKey(collectionAccount),
|
192
|
+
creators: [creator],
|
193
|
+
toJSON: function (): ShortMetadataArgsJSON {
|
194
|
+
throw new Error("Function not implemented.");
|
195
|
+
},
|
196
|
+
toEncodable: function () {
|
197
|
+
throw new Error("Function not implemented.");
|
198
|
+
},
|
199
|
+
};
|
200
|
+
|
201
|
+
/*
|
202
|
+
For MP4
|
203
|
+
const videoBuffer = await fs2.promises.readFile(
|
204
|
+
path.join(process.cwd(), "assets", "video.mp4")
|
205
|
+
);
|
206
|
+
|
207
|
+
For MP3
|
208
|
+
const audioBuffer = await fs2.promises.readFile(
|
209
|
+
path.join(process.cwd(), "assets", "audio.mp3")
|
210
|
+
);
|
211
|
+
|
212
|
+
For WebP
|
213
|
+
const webpBuffer = await fs2.promises.readFile(
|
214
|
+
path.join(process.cwd(), "assets", "image.webp")
|
215
|
+
);
|
216
|
+
|
217
|
+
For GLB
|
218
|
+
const glbBuffer = await fs2.promises.readFile(
|
219
|
+
path.join(process.cwd(), "assets", "model.glb")
|
220
|
+
);
|
221
|
+
*/
|
222
|
+
let options;
|
223
|
+
if (createOptions.mainImageUrl) {
|
224
|
+
// Define the type for metadata files
|
225
|
+
interface MetadataFiles {
|
226
|
+
file: {
|
227
|
+
url: string;
|
228
|
+
};
|
229
|
+
cover?: {
|
230
|
+
url: string;
|
231
|
+
};
|
232
|
+
}
|
233
|
+
|
234
|
+
// Create base metadata files object
|
235
|
+
let baseMetadataFiles: MetadataFiles = {
|
236
|
+
file: {
|
237
|
+
url: createOptions.mainImageUrl,
|
238
|
+
},
|
239
|
+
};
|
240
|
+
|
241
|
+
// Add cover if present
|
242
|
+
if (createOptions.coverImageUrl) {
|
243
|
+
baseMetadataFiles.cover = {
|
244
|
+
url: createOptions.coverImageUrl,
|
245
|
+
};
|
246
|
+
}
|
247
|
+
|
248
|
+
options = {
|
249
|
+
symbol: createOptions.itemSymbol,
|
250
|
+
metadata: {
|
251
|
+
name: metadata.name,
|
252
|
+
description: createOptions.itemDescription,
|
253
|
+
files: baseMetadataFiles,
|
254
|
+
},
|
255
|
+
creators: metadata.creators,
|
256
|
+
traits: createOptions.traits,
|
257
|
+
sellerFeeBasisPoints: metadata.sellerFeeBasisPoints,
|
258
|
+
};
|
259
|
+
} else {
|
260
|
+
const imageBuffer = await fs2.promises.readFile(
|
261
|
+
path.join(process.cwd(), "assets", "og.png")
|
262
|
+
);
|
263
|
+
|
264
|
+
if (!imageBuffer || imageBuffer.byteLength === 0) {
|
265
|
+
throw new Error("Failed to read main image file");
|
266
|
+
}
|
267
|
+
|
268
|
+
const coverBuffer = await fs2.promises.readFile(
|
269
|
+
path.join(process.cwd(), "assets", "niicl.gif")
|
270
|
+
);
|
271
|
+
|
272
|
+
if (!coverBuffer) {
|
273
|
+
throw new Error("Failed to read cover file");
|
274
|
+
}
|
275
|
+
options = {
|
276
|
+
symbol: createOptions.itemSymbol,
|
277
|
+
metadata: {
|
278
|
+
name: metadata.name,
|
279
|
+
description: createOptions.itemDescription,
|
280
|
+
files: {
|
281
|
+
file: {
|
282
|
+
arrayBuffer: () => imageBuffer,
|
283
|
+
type: "image/png",
|
284
|
+
name: "og.png",
|
285
|
+
size: imageBuffer.length,
|
286
|
+
},
|
287
|
+
cover: {
|
288
|
+
arrayBuffer: () => coverBuffer,
|
289
|
+
type: "image/gif",
|
290
|
+
name: "niicl.gif",
|
291
|
+
size: coverBuffer.length,
|
292
|
+
},
|
293
|
+
},
|
294
|
+
},
|
295
|
+
creators: metadata.creators,
|
296
|
+
traits: createOptions.traits,
|
297
|
+
sellerFeeBasisPoints: metadata.sellerFeeBasisPoints,
|
298
|
+
};
|
299
|
+
}
|
300
|
+
|
301
|
+
console.log("cover options: ", options);
|
302
|
+
|
303
|
+
const saleConfig: SaleConfig = {
|
304
|
+
prices: [
|
305
|
+
{
|
306
|
+
amount: new BN(createOptions.price),
|
307
|
+
priceType: new CurrencyType.Native(),
|
308
|
+
toJSON: function (): PriceJSON {
|
309
|
+
throw new Error("Function not implemented.");
|
310
|
+
},
|
311
|
+
toEncodable: function () {
|
312
|
+
throw new Error("Function not implemented.");
|
313
|
+
},
|
314
|
+
},
|
315
|
+
],
|
316
|
+
priceType: new PriceRule.None(),
|
317
|
+
rules: [],
|
318
|
+
sendToVault: 0,
|
319
|
+
saleType: new SaleType.Normal(),
|
320
|
+
toJSON: function (): SaleConfigJSON {
|
321
|
+
throw new Error("Function not implemented.");
|
322
|
+
},
|
323
|
+
toEncodable: function () {
|
324
|
+
throw new Error("Function not implemented.");
|
325
|
+
},
|
326
|
+
};
|
327
|
+
|
328
|
+
const createSingleEditionTxId = await sdk.createSingleEdition(
|
329
|
+
walletKeypair,
|
330
|
+
new PublicKey(storeAccount),
|
331
|
+
100,
|
332
|
+
metadata,
|
333
|
+
saleConfig,
|
334
|
+
[1, 0, 0],
|
335
|
+
[1, 0],
|
336
|
+
0,
|
337
|
+
12345,
|
338
|
+
new PublicKey(collectionAccount),
|
339
|
+
{
|
340
|
+
options: options,
|
341
|
+
}
|
342
|
+
);
|
343
|
+
|
344
|
+
return {
|
345
|
+
transactionId: createSingleEditionTxId,
|
346
|
+
payerPublicKey: payer.publicKey.toString(),
|
347
|
+
};
|
348
|
+
} catch (error) {
|
349
|
+
handleError(error);
|
350
|
+
throw error;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
|
354
|
+
async function buySingleImp(options: StoreInitOptions, item: string) {
|
355
|
+
const { sdk, walletKeypair, payer } = initializeSDKAndWallet(options);
|
356
|
+
|
357
|
+
try {
|
358
|
+
const owner = payer;
|
359
|
+
|
360
|
+
const buySingleEditionTxId = await sdk.buySingleEdition(
|
361
|
+
walletKeypair,
|
362
|
+
[0, 0, 0, 0, 0, 0],
|
363
|
+
new PublicKey(item)
|
364
|
+
);
|
365
|
+
console.log("** buy single tx: ", buySingleEditionTxId);
|
366
|
+
return {
|
367
|
+
transactionId: buySingleEditionTxId,
|
368
|
+
ownerPublicKey: owner.publicKey.toString(),
|
369
|
+
};
|
370
|
+
} catch (error) {
|
371
|
+
handleError(error);
|
372
|
+
throw error;
|
373
|
+
}
|
374
|
+
}
|
375
|
+
|
376
|
+
function handleError(error: unknown) {
|
377
|
+
if (error instanceof SendTransactionError) {
|
378
|
+
console.error("Transaction failed. Error message:", error.message);
|
379
|
+
console.error("Transaction logs:", error.logs);
|
380
|
+
} else {
|
381
|
+
console.error("An unexpected error occurred:", error);
|
382
|
+
}
|
383
|
+
}
|
384
|
+
|
385
|
+
export { createStoreImp, createSingleImp, buySingleImp, handleError };
|
@@ -0,0 +1,227 @@
|
|
1
|
+
import {
|
2
|
+
Connection,
|
3
|
+
PublicKey,
|
4
|
+
SystemProgram,
|
5
|
+
TransactionInstruction,
|
6
|
+
} from "@solana/web3.js";
|
7
|
+
import {
|
8
|
+
PROGRAM_ID,
|
9
|
+
BUBBLEGUM_PROGRAM_ID,
|
10
|
+
SPL_NOOP_PROGRAM_ID,
|
11
|
+
TOKEN_METADATA_PROGRAM_ID,
|
12
|
+
SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
|
13
|
+
PROGRAM_CNFT,
|
14
|
+
} from "../../../types/programId";
|
15
|
+
import { buyPay, printSingle } from "../../../types/instructions";
|
16
|
+
import {
|
17
|
+
creatorAuthorityPDA,
|
18
|
+
getEditionPDA,
|
19
|
+
getMetadataPDA,
|
20
|
+
itemAccountPDA,
|
21
|
+
storePDA,
|
22
|
+
toPublicKey,
|
23
|
+
collectionAuthorityRecord,
|
24
|
+
} from "../../../utility/PdaManager";
|
25
|
+
import { bytesToU32, cyrb53 } from "../../../utility/utils";
|
26
|
+
import { BN } from "bn.js";
|
27
|
+
import { ExtraParameter } from "../../../types/types";
|
28
|
+
import { BorshCoder } from "@project-serum/anchor";
|
29
|
+
import { idl } from "./idl";
|
30
|
+
export let lutAccount = toPublicKey(
|
31
|
+
"EJbrXVgac2wEL2H7FJr38vD7LQpEujWZiSPHSYZ3htCa"
|
32
|
+
);
|
33
|
+
export let merkleTree = toPublicKey(
|
34
|
+
"4GQ32bJ6F6hGnASo836rVbpxWRaeGzj3xkP3pmHnRwiz"
|
35
|
+
);
|
36
|
+
export let merkleOptions = {
|
37
|
+
merkleTree,
|
38
|
+
lutAccount,
|
39
|
+
mainnet: {
|
40
|
+
merkleTree: "Ccw1HJ6U4uVHbmXWogUGA3YCtwQEoeb5ta9zF3o1QJBM",
|
41
|
+
lutAccount: "5keha7sPVfoK1A7kpBUaAox11xHBCremixsUmQ1ZDAiG",
|
42
|
+
},
|
43
|
+
devnet: {
|
44
|
+
merkleTree: "2t66TFv7rV69puPqPjU7T9wCwmCGRPnSJy7mbcrrZ5KU",
|
45
|
+
lutAccount: "Bpp4MKTVrtr1RajivpbMrEbqbYu8KEFbt1LzW8xAJqkE",
|
46
|
+
},
|
47
|
+
};
|
48
|
+
|
49
|
+
const logWrapper = SPL_NOOP_PROGRAM_ID;
|
50
|
+
const bubblegumProgram = BUBBLEGUM_PROGRAM_ID;
|
51
|
+
const tokenMetadataProgram = TOKEN_METADATA_PROGRAM_ID;
|
52
|
+
const compressionProgram = SPL_ACCOUNT_COMPRESSION_PROGRAM_ID;
|
53
|
+
|
54
|
+
let connection: Connection;
|
55
|
+
|
56
|
+
export async function buySingleEditionInstruction(
|
57
|
+
paymentAccount: PublicKey,
|
58
|
+
itemAccount: PublicKey,
|
59
|
+
packAccount: PublicKey,
|
60
|
+
burnDeposit: PublicKey,
|
61
|
+
poolVault: PublicKey,
|
62
|
+
holderAccount: PublicKey,
|
63
|
+
owner: PublicKey,
|
64
|
+
payer: PublicKey,
|
65
|
+
distributionBumps: number[],
|
66
|
+
data: any,
|
67
|
+
storeAccount: PublicKey,
|
68
|
+
globalStoreAccount: PublicKey,
|
69
|
+
identifier: number,
|
70
|
+
extraAccounts: any[],
|
71
|
+
creator: PublicKey,
|
72
|
+
collectionAddress: PublicKey,
|
73
|
+
connectionInstance: Connection
|
74
|
+
): Promise<TransactionInstruction[]> {
|
75
|
+
const systemProgram = SystemProgram.programId;
|
76
|
+
connection = connectionInstance;
|
77
|
+
const endpoint = connection.rpcEndpoint.toLocaleLowerCase();
|
78
|
+
const pay = buyPay(
|
79
|
+
{ distributionBumps },
|
80
|
+
{
|
81
|
+
paymentAccount,
|
82
|
+
itemAccount,
|
83
|
+
packAccount,
|
84
|
+
burnDeposit,
|
85
|
+
poolVault,
|
86
|
+
holderAccount,
|
87
|
+
owner,
|
88
|
+
payer,
|
89
|
+
systemProgram,
|
90
|
+
},
|
91
|
+
extraAccounts,
|
92
|
+
PROGRAM_ID
|
93
|
+
);
|
94
|
+
|
95
|
+
let itemCreator = creator;
|
96
|
+
const currency = toPublicKey(data?.track?.currency || PROGRAM_ID);
|
97
|
+
|
98
|
+
const bubblegumSigner = toPublicKey(
|
99
|
+
"4ewWZC5gT6TGpm5LZNDs9wVonfUT2q5PP5sc9kVbwMAK"
|
100
|
+
);
|
101
|
+
|
102
|
+
const useGlobal = false;
|
103
|
+
const merkle = useGlobal
|
104
|
+
? merkleOptions?.merkleTree
|
105
|
+
: endpoint.includes("mainnet")
|
106
|
+
? toPublicKey(merkleOptions?.mainnet?.merkleTree)
|
107
|
+
: toPublicKey(merkleOptions?.devnet?.merkleTree);
|
108
|
+
|
109
|
+
const [treeAuthority, _bump] = PublicKey.findProgramAddressSync(
|
110
|
+
[merkle.toBuffer()],
|
111
|
+
BUBBLEGUM_PROGRAM_ID
|
112
|
+
);
|
113
|
+
|
114
|
+
const seeds = [Buffer.from("tree"), merkle.toBuffer()];
|
115
|
+
if (useGlobal) {
|
116
|
+
seeds.pop();
|
117
|
+
}
|
118
|
+
|
119
|
+
const [merkleManager, treeBump] = PublicKey.findProgramAddressSync(
|
120
|
+
seeds,
|
121
|
+
PROGRAM_CNFT
|
122
|
+
);
|
123
|
+
|
124
|
+
const collectionMint = collectionAddress;
|
125
|
+
const [creatorAuthority, creatorAuthBump] = await creatorAuthorityPDA({
|
126
|
+
creator: itemCreator,
|
127
|
+
store: storeAccount,
|
128
|
+
});
|
129
|
+
|
130
|
+
let [collectionAuthorityRecordPda] = await collectionAuthorityRecord({
|
131
|
+
mint: collectionMint,
|
132
|
+
new_authority: creatorAuthority,
|
133
|
+
});
|
134
|
+
|
135
|
+
const collectionMetadata = await getMetadataPDA(collectionMint);
|
136
|
+
const [editionAccount] = await getEditionPDA(collectionMint, false);
|
137
|
+
|
138
|
+
const joint_bytes = [...itemCreator.toBytes(), ...currency.toBytes()];
|
139
|
+
|
140
|
+
const proof = {
|
141
|
+
proofHash: new BN(cyrb53(joint_bytes, 1)),
|
142
|
+
amount: new BN(1000000),
|
143
|
+
currencyVerifier: new BN(bytesToU32(currency.toBytes().slice(0, 4))),
|
144
|
+
artistVerifier: new BN(bytesToU32(itemCreator.toBytes().slice(0, 4))),
|
145
|
+
};
|
146
|
+
|
147
|
+
if (!data.storeBump) {
|
148
|
+
const storedata = await connection.getAccountInfo(
|
149
|
+
toPublicKey(globalStoreAccount)
|
150
|
+
);
|
151
|
+
if (!storedata) {
|
152
|
+
throw new Error("-- No Store data store bump");
|
153
|
+
}
|
154
|
+
|
155
|
+
const [_, storeBump] = await storePDA({
|
156
|
+
storeId: 1,
|
157
|
+
creator: itemCreator,
|
158
|
+
holder: holderAccount,
|
159
|
+
});
|
160
|
+
data.storeBump = storeBump;
|
161
|
+
}
|
162
|
+
|
163
|
+
if (!data.itemBump) {
|
164
|
+
// const storedata = await connection.getAccountInfo(itemAccount);
|
165
|
+
// if (!storedata) {
|
166
|
+
// throw new Error("-- No Store data item bump");
|
167
|
+
// }
|
168
|
+
// const tipo = "Single";
|
169
|
+
// const tipofn = "itemAccountPDA";
|
170
|
+
const identifierdt = new BN(identifier);
|
171
|
+
const [_, itemBump] = await itemAccountPDA({
|
172
|
+
creator: itemCreator,
|
173
|
+
store: storeAccount,
|
174
|
+
identifier: identifierdt,
|
175
|
+
});
|
176
|
+
data.itemBump = itemBump;
|
177
|
+
}
|
178
|
+
|
179
|
+
if (!data) data = {};
|
180
|
+
if (!data?.pre) data.pre = [];
|
181
|
+
if (!data?.post) data.post = [];
|
182
|
+
|
183
|
+
const coder = new BorshCoder(idl);
|
184
|
+
const storedata = await connection.getAccountInfo(toPublicKey(storeAccount));
|
185
|
+
if (!storedata) {
|
186
|
+
throw new Error("no store data in print single");
|
187
|
+
}
|
188
|
+
const store_decoded = coder.accounts.decode("Store", storedata.data);
|
189
|
+
const [_, storeBump] = await storePDA({ ...store_decoded });
|
190
|
+
data.storeBump = storeBump;
|
191
|
+
|
192
|
+
const single = printSingle(
|
193
|
+
{
|
194
|
+
proof,
|
195
|
+
storeBump: data.storeBump,
|
196
|
+
creatorAuthBump,
|
197
|
+
itemBump: data.itemBump,
|
198
|
+
treeBump,
|
199
|
+
extra: new ExtraParameter.None(),
|
200
|
+
},
|
201
|
+
{
|
202
|
+
owner,
|
203
|
+
itemAccount,
|
204
|
+
treeAuthority,
|
205
|
+
storeAccount,
|
206
|
+
creatorAuthority,
|
207
|
+
paymentAccount,
|
208
|
+
merkleTree: merkle,
|
209
|
+
merkleManager,
|
210
|
+
collectionAuthorityRecordPda,
|
211
|
+
editionAccount,
|
212
|
+
collectionMetadata,
|
213
|
+
collectionMint,
|
214
|
+
bubblegumSigner,
|
215
|
+
buytrackAccount: PROGRAM_CNFT,
|
216
|
+
revealForMe: PROGRAM_CNFT,
|
217
|
+
payer,
|
218
|
+
logWrapper,
|
219
|
+
bubblegumProgram,
|
220
|
+
compressionProgram,
|
221
|
+
tokenMetadataProgram,
|
222
|
+
systemProgram,
|
223
|
+
},
|
224
|
+
PROGRAM_ID
|
225
|
+
);
|
226
|
+
return [pay, single];
|
227
|
+
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
|
+
import { PROGRAM_ID } from "../../../types/programId";
|
3
|
+
import {
|
4
|
+
MetadataArgs,
|
5
|
+
SaleConfig,
|
6
|
+
ShortMetadataArgs,
|
7
|
+
} from "../../../types/types";
|
8
|
+
import { createSingle } from "../../../types/instructions";
|
9
|
+
import BN from "bn.js";
|
10
|
+
|
11
|
+
export function createSingleEditionInstruction(
|
12
|
+
storeAccount: PublicKey,
|
13
|
+
itemAccount: PublicKey,
|
14
|
+
creatorAuthority: PublicKey,
|
15
|
+
itemReserveList: PublicKey,
|
16
|
+
creator: PublicKey,
|
17
|
+
payer: PublicKey,
|
18
|
+
supply: number,
|
19
|
+
shortMetadata: ShortMetadataArgs,
|
20
|
+
saleConfig: SaleConfig,
|
21
|
+
identifier: number,
|
22
|
+
category: number[],
|
23
|
+
superCategory: number[],
|
24
|
+
eventCategory: number,
|
25
|
+
hashTraits: number
|
26
|
+
): TransactionInstruction {
|
27
|
+
return createSingle(
|
28
|
+
{
|
29
|
+
supply: new BN(supply),
|
30
|
+
shortMetadata,
|
31
|
+
saleConfig,
|
32
|
+
identifier: new BN(identifier),
|
33
|
+
category,
|
34
|
+
superCategory,
|
35
|
+
eventCategory,
|
36
|
+
hashTraits: new BN(hashTraits),
|
37
|
+
},
|
38
|
+
{
|
39
|
+
storeAccount,
|
40
|
+
itemAccount,
|
41
|
+
creatorAuthority,
|
42
|
+
itemReserveList,
|
43
|
+
creator,
|
44
|
+
payer,
|
45
|
+
systemProgram: PublicKey.default,
|
46
|
+
},
|
47
|
+
PROGRAM_ID
|
48
|
+
);
|
49
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
2
|
+
import { PROGRAM_ID } from "../../../types/programId";
|
3
|
+
import { StoreConfig } from "../../../types/types";
|
4
|
+
import { createStore } from "../../../types/instructions";
|
5
|
+
|
6
|
+
export function createStoreInstruction(
|
7
|
+
holderAccount: PublicKey,
|
8
|
+
storeAccount: PublicKey,
|
9
|
+
creator: PublicKey,
|
10
|
+
name: string,
|
11
|
+
storeConfig: StoreConfig,
|
12
|
+
storeId: number
|
13
|
+
): TransactionInstruction {
|
14
|
+
return createStore(
|
15
|
+
{ name, storeConfig, storeId },
|
16
|
+
{ holderAccount, storeAccount, creator, systemProgram: PublicKey.default },
|
17
|
+
PROGRAM_ID
|
18
|
+
);
|
19
|
+
}
|