@silvana-one/abi 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/index.cjs +136 -134
- package/dist/node/nft/build.d.ts +52 -0
- package/dist/node/nft/build.js +724 -0
- package/dist/node/nft/build.js.map +1 -0
- package/dist/node/token/info.js +4 -2
- package/dist/node/token/info.js.map +1 -1
- package/dist/node/vk/devnet.js +83 -83
- package/dist/node/vk/devnet.js.map +1 -1
- package/dist/node/vk/mainnet.js +83 -83
- package/dist/node/vk/mainnet.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/nft/build.d.ts +52 -0
- package/dist/web/nft/build.js +724 -0
- package/dist/web/nft/build.js.map +1 -0
- package/dist/web/token/info.js +4 -2
- package/dist/web/token/info.js.map +1 -1
- package/dist/web/vk/devnet.js +83 -83
- package/dist/web/vk/devnet.js.map +1 -1
- package/dist/web/vk/mainnet.js +83 -83
- package/dist/web/vk/mainnet.js.map +1 -1
- package/package.json +10 -9
- package/src/nft/build.ts +927 -0
- package/src/token/info.ts +4 -2
- package/src/vk/devnet.ts +85 -84
- package/src/vk/mainnet.ts +85 -84
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import { Whitelist, Storage, } from "@silvana-one/storage";
|
|
2
|
+
import { fetchMinaAccount } from "../fetch.js";
|
|
3
|
+
import { Collection, AdvancedCollection, NFTAdmin, NFTAdvancedAdmin, Metadata, pinMetadata, fieldFromString, CollectionData, MintParams, NFTData, } from "@silvana-one/nft";
|
|
4
|
+
import { tokenVerificationKeys } from "../vk/index.js";
|
|
5
|
+
import { PublicKey, Mina, AccountUpdate, UInt64, Field, TokenId, UInt32, fetchLastBlock, } from "o1js";
|
|
6
|
+
export async function buildNftCollectionLaunchTransaction(params) {
|
|
7
|
+
const { chain, args } = params;
|
|
8
|
+
const { url = chain === "mainnet"
|
|
9
|
+
? "https://minanft.io"
|
|
10
|
+
: `https://${chain}.minanft.io`, symbol = "NFT", memo, nonce, adminContract: adminType, masterNFT, } = args;
|
|
11
|
+
if (memo && typeof memo !== "string")
|
|
12
|
+
throw new Error("Memo must be a string");
|
|
13
|
+
if (memo && memo.length > 30)
|
|
14
|
+
throw new Error("Memo must be less than 30 characters");
|
|
15
|
+
if (!symbol || typeof symbol !== "string")
|
|
16
|
+
throw new Error("Symbol must be a string");
|
|
17
|
+
if (symbol.length >= 7)
|
|
18
|
+
throw new Error("Symbol must be less than 7 characters");
|
|
19
|
+
if (masterNFT === undefined) {
|
|
20
|
+
throw new Error("masterNFT is required");
|
|
21
|
+
}
|
|
22
|
+
if (masterNFT.metadata === undefined) {
|
|
23
|
+
throw new Error("masterNFT.metadata is required");
|
|
24
|
+
}
|
|
25
|
+
if (typeof masterNFT.metadata === "string" &&
|
|
26
|
+
masterNFT.storage === undefined) {
|
|
27
|
+
throw new Error("masterNFT.storage is required if metadata is a string");
|
|
28
|
+
}
|
|
29
|
+
const sender = PublicKey.fromBase58(args.sender);
|
|
30
|
+
if (nonce === undefined)
|
|
31
|
+
throw new Error("Nonce is required");
|
|
32
|
+
if (typeof nonce !== "number")
|
|
33
|
+
throw new Error("Nonce must be a number");
|
|
34
|
+
const fee = 100_000_000;
|
|
35
|
+
if (url && typeof url !== "string")
|
|
36
|
+
throw new Error("Url must be a string");
|
|
37
|
+
if (!args.collectionAddress || typeof args.collectionAddress !== "string")
|
|
38
|
+
throw new Error("collectionAddress is required");
|
|
39
|
+
if (!args.adminContractAddress ||
|
|
40
|
+
typeof args.adminContractAddress !== "string")
|
|
41
|
+
throw new Error("adminContractAddress is required");
|
|
42
|
+
const adminContract = adminType === "advanced" ? NFTAdvancedAdmin : NFTAdmin;
|
|
43
|
+
const collectionContract = adminType === "advanced" ? AdvancedCollection : Collection;
|
|
44
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
45
|
+
if (!vk ||
|
|
46
|
+
!vk.Collection ||
|
|
47
|
+
!vk.Collection.hash ||
|
|
48
|
+
!vk.Collection.data ||
|
|
49
|
+
!vk.AdvancedCollection ||
|
|
50
|
+
!vk.AdvancedCollection.hash ||
|
|
51
|
+
!vk.AdvancedCollection.data ||
|
|
52
|
+
!vk.NFT ||
|
|
53
|
+
!vk.NFT.hash ||
|
|
54
|
+
!vk.NFT.data ||
|
|
55
|
+
!vk.NFTAdmin ||
|
|
56
|
+
!vk.NFTAdmin.hash ||
|
|
57
|
+
!vk.NFTAdmin.data ||
|
|
58
|
+
!vk.NFTAdvancedAdmin ||
|
|
59
|
+
!vk.NFTAdvancedAdmin.hash ||
|
|
60
|
+
!vk.NFTAdvancedAdmin.data)
|
|
61
|
+
throw new Error("Cannot get verification key from vk");
|
|
62
|
+
const adminVerificationKey = adminType === "advanced" ? vk.NFTAdvancedAdmin : vk.NFTAdmin;
|
|
63
|
+
const collectionVerificationKey = adminType === "advanced" ? vk.NFTAdvancedCollection : vk.NFTCollection;
|
|
64
|
+
if (!adminVerificationKey || !collectionVerificationKey)
|
|
65
|
+
throw new Error("Cannot get verification keys");
|
|
66
|
+
await fetchMinaAccount({
|
|
67
|
+
publicKey: sender,
|
|
68
|
+
force: true,
|
|
69
|
+
});
|
|
70
|
+
if (!Mina.hasAccount(sender)) {
|
|
71
|
+
throw new Error("Sender does not have account");
|
|
72
|
+
}
|
|
73
|
+
const whitelist = "whitelist" in args && args.whitelist
|
|
74
|
+
? typeof args.whitelist === "string"
|
|
75
|
+
? Whitelist.fromString(args.whitelist)
|
|
76
|
+
: (await Whitelist.create({ list: args.whitelist, name: symbol }))
|
|
77
|
+
.whitelist
|
|
78
|
+
: Whitelist.empty();
|
|
79
|
+
const collectionAddress = PublicKey.fromBase58(args.collectionAddress);
|
|
80
|
+
const adminContractAddress = PublicKey.fromBase58(args.adminContractAddress);
|
|
81
|
+
const creator = args.creator ? PublicKey.fromBase58(args.creator) : sender;
|
|
82
|
+
const zkCollection = new collectionContract(collectionAddress);
|
|
83
|
+
const zkAdmin = new adminContract(adminContractAddress);
|
|
84
|
+
const metadataVerificationKeyHash = masterNFT.metadataVerificationKeyHash
|
|
85
|
+
? Field.fromJSON(masterNFT.metadataVerificationKeyHash)
|
|
86
|
+
: Field(0);
|
|
87
|
+
const provingKey = params.provingKey
|
|
88
|
+
? PublicKey.fromBase58(params.provingKey)
|
|
89
|
+
: sender;
|
|
90
|
+
const provingFee = params.provingFee
|
|
91
|
+
? UInt64.from(Math.round(params.provingFee))
|
|
92
|
+
: undefined;
|
|
93
|
+
const developerFee = args.developerFee
|
|
94
|
+
? UInt64.from(Math.round(args.developerFee))
|
|
95
|
+
: undefined;
|
|
96
|
+
const developerAddress = params.developerAddress
|
|
97
|
+
? PublicKey.fromBase58(params.developerAddress)
|
|
98
|
+
: undefined;
|
|
99
|
+
const { name, ipfsHash, metadataRoot, privateMetadata, serializedMap } = typeof masterNFT.metadata === "string"
|
|
100
|
+
? {
|
|
101
|
+
name: masterNFT.name,
|
|
102
|
+
ipfsHash: masterNFT.storage,
|
|
103
|
+
metadataRoot: Field.fromJSON(masterNFT.metadata),
|
|
104
|
+
privateMetadata: undefined,
|
|
105
|
+
serializedMap: undefined,
|
|
106
|
+
}
|
|
107
|
+
: await pinMetadata(Metadata.fromOpenApiJSON({ json: masterNFT.metadata }));
|
|
108
|
+
if (ipfsHash === undefined)
|
|
109
|
+
throw new Error("storage is required, but not provided");
|
|
110
|
+
if (metadataRoot === undefined)
|
|
111
|
+
throw new Error("metadataRoot is required");
|
|
112
|
+
const slot = chain === "local"
|
|
113
|
+
? Mina.currentSlot()
|
|
114
|
+
: chain === "zeko"
|
|
115
|
+
? UInt32.zero
|
|
116
|
+
: (await fetchLastBlock()).globalSlotSinceGenesis;
|
|
117
|
+
const expiry = slot.add(UInt32.from(chain === "mainnet" || chain === "devnet" ? 20 : 100000));
|
|
118
|
+
const nftData = NFTData.new({
|
|
119
|
+
owner: creator,
|
|
120
|
+
approved: undefined,
|
|
121
|
+
version: undefined,
|
|
122
|
+
id: masterNFT.data.id ? BigInt(masterNFT.data.id) : undefined,
|
|
123
|
+
canChangeOwnerByProof: masterNFT.data.canChangeOwnerByProof,
|
|
124
|
+
canTransfer: masterNFT.data.canTransfer,
|
|
125
|
+
canApprove: masterNFT.data.canApprove,
|
|
126
|
+
canChangeMetadata: masterNFT.data.canChangeMetadata,
|
|
127
|
+
canChangeStorage: masterNFT.data.canChangeStorage,
|
|
128
|
+
canChangeName: masterNFT.data.canChangeName,
|
|
129
|
+
canChangeMetadataVerificationKeyHash: masterNFT.data.canChangeMetadataVerificationKeyHash,
|
|
130
|
+
canPause: masterNFT.data.canPause,
|
|
131
|
+
isPaused: masterNFT.data.isPaused,
|
|
132
|
+
requireOwnerAuthorizationToUpgrade: masterNFT.data.requireOwnerAuthorizationToUpgrade,
|
|
133
|
+
});
|
|
134
|
+
const mintParams = new MintParams({
|
|
135
|
+
name: fieldFromString(name),
|
|
136
|
+
address: collectionAddress,
|
|
137
|
+
tokenId: TokenId.derive(collectionAddress),
|
|
138
|
+
data: nftData,
|
|
139
|
+
fee: args.masterNFT.fee
|
|
140
|
+
? UInt64.from(Math.round(args.masterNFT.fee * 1_000_000_000))
|
|
141
|
+
: UInt64.zero,
|
|
142
|
+
metadata: metadataRoot,
|
|
143
|
+
storage: Storage.fromString(ipfsHash),
|
|
144
|
+
metadataVerificationKeyHash,
|
|
145
|
+
expiry: masterNFT.expiry
|
|
146
|
+
? UInt32.from(Math.round(masterNFT.expiry))
|
|
147
|
+
: expiry,
|
|
148
|
+
});
|
|
149
|
+
const collectionData = CollectionData.new(args.collectionData ?? {});
|
|
150
|
+
const tx = await Mina.transaction({
|
|
151
|
+
sender,
|
|
152
|
+
fee,
|
|
153
|
+
memo: memo ?? `${args.collectionName} NFT collection launch`.substring(0, 30),
|
|
154
|
+
nonce,
|
|
155
|
+
}, async () => {
|
|
156
|
+
const feeAccountUpdate = AccountUpdate.createSigned(sender);
|
|
157
|
+
feeAccountUpdate.balance.subInPlace(3_000_000_000);
|
|
158
|
+
if (provingFee && provingKey)
|
|
159
|
+
feeAccountUpdate.send({
|
|
160
|
+
to: provingKey,
|
|
161
|
+
amount: provingFee,
|
|
162
|
+
});
|
|
163
|
+
if (developerAddress && developerFee) {
|
|
164
|
+
feeAccountUpdate.send({
|
|
165
|
+
to: developerAddress,
|
|
166
|
+
amount: developerFee,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (zkAdmin instanceof NFTAdvancedAdmin) {
|
|
170
|
+
throw new Error("Advanced admin is not supported");
|
|
171
|
+
}
|
|
172
|
+
else if (zkAdmin instanceof NFTAdmin) {
|
|
173
|
+
await zkAdmin.deploy({
|
|
174
|
+
admin: sender,
|
|
175
|
+
uri: `NFT Admin`,
|
|
176
|
+
});
|
|
177
|
+
// deploy() and initialize() create 2 account updates for the same publicKey, it is intended
|
|
178
|
+
await zkCollection.deploy({
|
|
179
|
+
creator,
|
|
180
|
+
collectionName: fieldFromString(args.collectionName),
|
|
181
|
+
baseURL: fieldFromString(args.baseURL ?? "ipfs"),
|
|
182
|
+
admin: adminContractAddress,
|
|
183
|
+
symbol,
|
|
184
|
+
url,
|
|
185
|
+
});
|
|
186
|
+
await zkCollection.initialize(mintParams, collectionData);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
return {
|
|
190
|
+
request: adminType === "advanced"
|
|
191
|
+
? {
|
|
192
|
+
...args,
|
|
193
|
+
whitelist: whitelist.toString(),
|
|
194
|
+
}
|
|
195
|
+
: args,
|
|
196
|
+
tx,
|
|
197
|
+
adminType,
|
|
198
|
+
name: args.collectionName,
|
|
199
|
+
verificationKeyHashes: [
|
|
200
|
+
adminVerificationKey.hash,
|
|
201
|
+
collectionVerificationKey.hash,
|
|
202
|
+
],
|
|
203
|
+
metadataRoot: metadataRoot.toJSON(),
|
|
204
|
+
storage: ipfsHash,
|
|
205
|
+
privateMetadata,
|
|
206
|
+
map: serializedMap,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
export async function buildNftTransaction(params) {
|
|
210
|
+
const { chain, args } = params;
|
|
211
|
+
const { nonce, txType } = args;
|
|
212
|
+
if (nonce === undefined)
|
|
213
|
+
throw new Error("Nonce is required");
|
|
214
|
+
if (typeof nonce !== "number")
|
|
215
|
+
throw new Error("Nonce must be a number");
|
|
216
|
+
if (txType === undefined)
|
|
217
|
+
throw new Error("Tx type is required");
|
|
218
|
+
if (typeof txType !== "string")
|
|
219
|
+
throw new Error("Tx type must be a string");
|
|
220
|
+
const sender = PublicKey.fromBase58(args.sender);
|
|
221
|
+
const collectionAddress = PublicKey.fromBase58(args.collectionAddress);
|
|
222
|
+
if (args.nftMintParams.address === undefined) {
|
|
223
|
+
throw new Error("NFT address is required");
|
|
224
|
+
}
|
|
225
|
+
const nftAddress = PublicKey.fromBase58(args.nftMintParams.address);
|
|
226
|
+
// const offerAddress =
|
|
227
|
+
// "offerAddress" in args && args.offerAddress
|
|
228
|
+
// ? PublicKey.fromBase58(args.offerAddress)
|
|
229
|
+
// : undefined;
|
|
230
|
+
// if (
|
|
231
|
+
// !offerAddress &&
|
|
232
|
+
// (txType === "token:offer:create" ||
|
|
233
|
+
// txType === "token:offer:buy" ||
|
|
234
|
+
// txType === "token:offer:withdraw")
|
|
235
|
+
// )
|
|
236
|
+
// throw new Error("Offer address is required");
|
|
237
|
+
// const bidAddress =
|
|
238
|
+
// "bidAddress" in args && args.bidAddress
|
|
239
|
+
// ? PublicKey.fromBase58(args.bidAddress)
|
|
240
|
+
// : undefined;
|
|
241
|
+
// if (
|
|
242
|
+
// !bidAddress &&
|
|
243
|
+
// (txType === "token:bid:create" ||
|
|
244
|
+
// txType === "token:bid:sell" ||
|
|
245
|
+
// txType === "token:bid:withdraw")
|
|
246
|
+
// )
|
|
247
|
+
// throw new Error("Bid address is required");
|
|
248
|
+
// const to =
|
|
249
|
+
// "to" in args && args.to ? PublicKey.fromBase58(args.to) : undefined;
|
|
250
|
+
// if (
|
|
251
|
+
// !to &&
|
|
252
|
+
// (txType === "token:transfer" ||
|
|
253
|
+
// txType === "token:airdrop" ||
|
|
254
|
+
// txType === "token:mint")
|
|
255
|
+
// )
|
|
256
|
+
// throw new Error("To address is required");
|
|
257
|
+
// const from =
|
|
258
|
+
// "from" in args && args.from ? PublicKey.fromBase58(args.from) : undefined;
|
|
259
|
+
// if (!from && txType === "token:burn")
|
|
260
|
+
// throw new Error("From address is required for token:burn");
|
|
261
|
+
// const amount =
|
|
262
|
+
// "amount" in args ? UInt64.from(Math.round(args.amount)) : undefined;
|
|
263
|
+
// const price =
|
|
264
|
+
// "price" in args && args.price
|
|
265
|
+
// ? UInt64.from(Math.round(args.price))
|
|
266
|
+
// : undefined;
|
|
267
|
+
// const slippage = UInt32.from(
|
|
268
|
+
// Math.round(
|
|
269
|
+
// "slippage" in args && args.slippage !== undefined ? args.slippage : 50
|
|
270
|
+
// )
|
|
271
|
+
// );
|
|
272
|
+
await fetchMinaAccount({
|
|
273
|
+
publicKey: sender,
|
|
274
|
+
force: true,
|
|
275
|
+
});
|
|
276
|
+
if (!Mina.hasAccount(sender)) {
|
|
277
|
+
throw new Error("Sender does not have account");
|
|
278
|
+
}
|
|
279
|
+
const { symbol, adminContractAddress, adminType, verificationKeyHashes } = await getNftSymbolAndAdmin({
|
|
280
|
+
txType,
|
|
281
|
+
collectionAddress,
|
|
282
|
+
chain,
|
|
283
|
+
nftAddress: undefined, // TODO: add nft address
|
|
284
|
+
});
|
|
285
|
+
const memo = args.memo ?? `${txType} ${symbol} ${args.nftMintParams.name}`;
|
|
286
|
+
const fee = 100_000_000;
|
|
287
|
+
const provingKey = params.provingKey
|
|
288
|
+
? PublicKey.fromBase58(params.provingKey)
|
|
289
|
+
: sender;
|
|
290
|
+
const provingFee = params.provingFee
|
|
291
|
+
? UInt64.from(Math.round(params.provingFee))
|
|
292
|
+
: undefined;
|
|
293
|
+
const developerFee = args.developerFee
|
|
294
|
+
? UInt64.from(Math.round(args.developerFee))
|
|
295
|
+
: undefined;
|
|
296
|
+
const developerAddress = params.developerAddress
|
|
297
|
+
? PublicKey.fromBase58(params.developerAddress)
|
|
298
|
+
: undefined;
|
|
299
|
+
//const adminContract = new FungibleTokenAdmin(adminContractAddress);
|
|
300
|
+
const advancedAdminContract = new NFTAdvancedAdmin(adminContractAddress);
|
|
301
|
+
const adminContract = new NFTAdmin(adminContractAddress);
|
|
302
|
+
const collectionContract = adminType === "advanced" ? AdvancedCollection : Collection;
|
|
303
|
+
// if (
|
|
304
|
+
// (txType === "token:admin:whitelist" ||
|
|
305
|
+
// txType === "token:bid:whitelist" ||
|
|
306
|
+
// txType === "token:offer:whitelist") &&
|
|
307
|
+
// !args.whitelist
|
|
308
|
+
// ) {
|
|
309
|
+
// throw new Error("Whitelist is required");
|
|
310
|
+
// }
|
|
311
|
+
// const whitelist =
|
|
312
|
+
// "whitelist" in args && args.whitelist
|
|
313
|
+
// ? typeof args.whitelist === "string"
|
|
314
|
+
// ? Whitelist.fromString(args.whitelist)
|
|
315
|
+
// : (await Whitelist.create({ list: args.whitelist, name: symbol }))
|
|
316
|
+
// .whitelist
|
|
317
|
+
// : Whitelist.empty();
|
|
318
|
+
const zkCollection = new collectionContract(collectionAddress);
|
|
319
|
+
const tokenId = zkCollection.deriveTokenId();
|
|
320
|
+
// if (
|
|
321
|
+
// txType === "nft:mint" &&
|
|
322
|
+
// adminType === "standard" &&
|
|
323
|
+
// adminAddress.toBase58() !== sender.toBase58()
|
|
324
|
+
// )
|
|
325
|
+
// throw new Error(
|
|
326
|
+
// "Invalid sender for FungibleToken mint with standard admin"
|
|
327
|
+
// );
|
|
328
|
+
await fetchMinaAccount({
|
|
329
|
+
publicKey: nftAddress,
|
|
330
|
+
tokenId,
|
|
331
|
+
force: ["nft:transfer"].includes(txType),
|
|
332
|
+
});
|
|
333
|
+
// if (to) {
|
|
334
|
+
// await fetchMinaAccount({
|
|
335
|
+
// publicKey: to,
|
|
336
|
+
// tokenId,
|
|
337
|
+
// force: false,
|
|
338
|
+
// });
|
|
339
|
+
// }
|
|
340
|
+
// if (from) {
|
|
341
|
+
// await fetchMinaAccount({
|
|
342
|
+
// publicKey: from,
|
|
343
|
+
// tokenId,
|
|
344
|
+
// force: false,
|
|
345
|
+
// });
|
|
346
|
+
// }
|
|
347
|
+
// if (offerAddress)
|
|
348
|
+
// await fetchMinaAccount({
|
|
349
|
+
// publicKey: offerAddress,
|
|
350
|
+
// tokenId,
|
|
351
|
+
// force: (
|
|
352
|
+
// [
|
|
353
|
+
// "token:offer:whitelist",
|
|
354
|
+
// "token:offer:buy",
|
|
355
|
+
// "token:offer:withdraw",
|
|
356
|
+
// ] satisfies TokenTransactionType[] as TokenTransactionType[]
|
|
357
|
+
// ).includes(txType),
|
|
358
|
+
// });
|
|
359
|
+
// if (bidAddress)
|
|
360
|
+
// await fetchMinaAccount({
|
|
361
|
+
// publicKey: bidAddress,
|
|
362
|
+
// force: (
|
|
363
|
+
// [
|
|
364
|
+
// "token:bid:whitelist",
|
|
365
|
+
// "token:bid:sell",
|
|
366
|
+
// "token:bid:withdraw",
|
|
367
|
+
// ] satisfies TokenTransactionType[] as TokenTransactionType[]
|
|
368
|
+
// ).includes(txType),
|
|
369
|
+
// });
|
|
370
|
+
// const offerContract = offerAddress
|
|
371
|
+
// ? new FungibleTokenOfferContract(offerAddress, tokenId)
|
|
372
|
+
// : undefined;
|
|
373
|
+
// const bidContract = bidAddress
|
|
374
|
+
// ? new FungibleTokenBidContract(bidAddress)
|
|
375
|
+
// : undefined;
|
|
376
|
+
// const offerContractDeployment = offerAddress
|
|
377
|
+
// ? new FungibleTokenOfferContract(offerAddress, tokenId)
|
|
378
|
+
// : undefined;
|
|
379
|
+
// const bidContractDeployment = bidAddress
|
|
380
|
+
// ? new FungibleTokenBidContract(bidAddress)
|
|
381
|
+
// : undefined;
|
|
382
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
383
|
+
if (!vk ||
|
|
384
|
+
!vk.Collection ||
|
|
385
|
+
!vk.Collection.hash ||
|
|
386
|
+
!vk.Collection.data ||
|
|
387
|
+
!vk.AdvancedCollection ||
|
|
388
|
+
!vk.AdvancedCollection.hash ||
|
|
389
|
+
!vk.AdvancedCollection.data ||
|
|
390
|
+
!vk.NFT ||
|
|
391
|
+
!vk.NFT.hash ||
|
|
392
|
+
!vk.NFT.data ||
|
|
393
|
+
!vk.NFTAdmin ||
|
|
394
|
+
!vk.NFTAdmin.hash ||
|
|
395
|
+
!vk.NFTAdmin.data ||
|
|
396
|
+
!vk.NFTAdvancedAdmin ||
|
|
397
|
+
!vk.NFTAdvancedAdmin.hash ||
|
|
398
|
+
!vk.NFTAdvancedAdmin.data)
|
|
399
|
+
throw new Error("Cannot get verification key from vk");
|
|
400
|
+
// const offerVerificationKey = FungibleTokenOfferContract._verificationKey ?? {
|
|
401
|
+
// hash: Field(vk.FungibleTokenOfferContract.hash),
|
|
402
|
+
// data: vk.FungibleTokenOfferContract.data,
|
|
403
|
+
// };
|
|
404
|
+
// const bidVerificationKey = FungibleTokenBidContract._verificationKey ?? {
|
|
405
|
+
// hash: Field(vk.FungibleTokenBidContract.hash),
|
|
406
|
+
// data: vk.FungibleTokenBidContract.data,
|
|
407
|
+
// };
|
|
408
|
+
// const isNewBidOfferAccount =
|
|
409
|
+
// txType === "token:offer:create" && offerAddress
|
|
410
|
+
// ? !Mina.hasAccount(offerAddress, tokenId)
|
|
411
|
+
// : txType === "token:bid:create" && bidAddress
|
|
412
|
+
// ? !Mina.hasAccount(bidAddress)
|
|
413
|
+
// : false;
|
|
414
|
+
// const isNewBuyAccount =
|
|
415
|
+
// txType === "token:offer:buy" ? !Mina.hasAccount(sender, tokenId) : false;
|
|
416
|
+
// let isNewSellAccount: boolean = false;
|
|
417
|
+
// if (txType === "token:bid:sell") {
|
|
418
|
+
// if (!bidAddress || !bidContract) throw new Error("Bid address is required");
|
|
419
|
+
// await fetchMinaAccount({
|
|
420
|
+
// publicKey: bidAddress,
|
|
421
|
+
// force: true,
|
|
422
|
+
// });
|
|
423
|
+
// const buyer = bidContract.buyer.get();
|
|
424
|
+
// await fetchMinaAccount({
|
|
425
|
+
// publicKey: buyer,
|
|
426
|
+
// tokenId,
|
|
427
|
+
// force: false,
|
|
428
|
+
// });
|
|
429
|
+
// isNewSellAccount = !Mina.hasAccount(buyer, tokenId);
|
|
430
|
+
// }
|
|
431
|
+
// if (txType === "token:burn") {
|
|
432
|
+
// await fetchMinaAccount({
|
|
433
|
+
// publicKey: sender,
|
|
434
|
+
// force: true,
|
|
435
|
+
// });
|
|
436
|
+
// await fetchMinaAccount({
|
|
437
|
+
// publicKey: sender,
|
|
438
|
+
// tokenId,
|
|
439
|
+
// force: false,
|
|
440
|
+
// });
|
|
441
|
+
// if (!Mina.hasAccount(sender, tokenId))
|
|
442
|
+
// throw new Error("Sender does not have tokens to burn");
|
|
443
|
+
// }
|
|
444
|
+
// const isNewTransferMintAccount =
|
|
445
|
+
// (txType === "token:transfer" ||
|
|
446
|
+
// txType === "token:airdrop" ||
|
|
447
|
+
// txType === "token:mint") &&
|
|
448
|
+
// to
|
|
449
|
+
// ? !Mina.hasAccount(to, tokenId)
|
|
450
|
+
// : false;
|
|
451
|
+
// const accountCreationFee =
|
|
452
|
+
// (isNewBidOfferAccount ? 1_000_000_000 : 0) +
|
|
453
|
+
// (isNewBuyAccount ? 1_000_000_000 : 0) +
|
|
454
|
+
// (isNewSellAccount ? 1_000_000_000 : 0) +
|
|
455
|
+
// (isNewTransferMintAccount ? 1_000_000_000 : 0) +
|
|
456
|
+
// (isToNewAccount &&
|
|
457
|
+
// txType === "token:mint" &&
|
|
458
|
+
// adminType === "advanced" &&
|
|
459
|
+
// advancedAdminContract.whitelist.get().isSome().toBoolean()
|
|
460
|
+
// ? 1_000_000_000
|
|
461
|
+
// : 0);
|
|
462
|
+
// console.log("accountCreationFee", accountCreationFee / 1_000_000_000);
|
|
463
|
+
// switch (txType) {
|
|
464
|
+
// case "token:offer:buy":
|
|
465
|
+
// case "token:offer:withdraw":
|
|
466
|
+
// case "token:offer:whitelist":
|
|
467
|
+
// if (offerContract === undefined)
|
|
468
|
+
// throw new Error("Offer contract is required");
|
|
469
|
+
// if (
|
|
470
|
+
// Mina.getAccount(
|
|
471
|
+
// offerContract.address,
|
|
472
|
+
// tokenId
|
|
473
|
+
// ).zkapp?.verificationKey?.hash.toJSON() !==
|
|
474
|
+
// vk.FungibleTokenOfferContract.hash
|
|
475
|
+
// )
|
|
476
|
+
// throw new Error(
|
|
477
|
+
// "Invalid offer verification key, offer contract has to be upgraded"
|
|
478
|
+
// );
|
|
479
|
+
// break;
|
|
480
|
+
// }
|
|
481
|
+
// switch (txType) {
|
|
482
|
+
// case "token:bid:sell":
|
|
483
|
+
// case "token:bid:withdraw":
|
|
484
|
+
// case "token:bid:whitelist":
|
|
485
|
+
// if (bidContract === undefined)
|
|
486
|
+
// throw new Error("Bid contract is required");
|
|
487
|
+
// if (
|
|
488
|
+
// Mina.getAccount(
|
|
489
|
+
// bidContract.address
|
|
490
|
+
// ).zkapp?.verificationKey?.hash.toJSON() !==
|
|
491
|
+
// vk.FungibleTokenBidContract.hash
|
|
492
|
+
// )
|
|
493
|
+
// throw new Error(
|
|
494
|
+
// "Invalid bid verification key, bid contract has to be upgraded"
|
|
495
|
+
// );
|
|
496
|
+
// break;
|
|
497
|
+
// }
|
|
498
|
+
// switch (txType) {
|
|
499
|
+
// case "token:mint":
|
|
500
|
+
// case "token:burn":
|
|
501
|
+
// case "token:redeem":
|
|
502
|
+
// case "token:transfer":
|
|
503
|
+
// case "token:airdrop":
|
|
504
|
+
// case "token:offer:create":
|
|
505
|
+
// case "token:bid:create":
|
|
506
|
+
// case "token:offer:buy":
|
|
507
|
+
// case "token:offer:withdraw":
|
|
508
|
+
// case "token:bid:sell":
|
|
509
|
+
// if (
|
|
510
|
+
// Mina.getAccount(
|
|
511
|
+
// zkToken.address
|
|
512
|
+
// ).zkapp?.verificationKey?.hash.toJSON() !== vk.FungibleToken.hash
|
|
513
|
+
// )
|
|
514
|
+
// throw new Error(
|
|
515
|
+
// "Invalid token verification key, token contract has to be upgraded"
|
|
516
|
+
// );
|
|
517
|
+
// break;
|
|
518
|
+
// }
|
|
519
|
+
const { name, ipfsHash, metadataRoot, privateMetadata, serializedMap } = typeof args.nftMintParams.metadata === "string"
|
|
520
|
+
? {
|
|
521
|
+
name: args.nftMintParams.name,
|
|
522
|
+
ipfsHash: args.nftMintParams.storage,
|
|
523
|
+
metadataRoot: Field.fromJSON(args.nftMintParams.metadata),
|
|
524
|
+
privateMetadata: undefined,
|
|
525
|
+
serializedMap: undefined,
|
|
526
|
+
}
|
|
527
|
+
: await pinMetadata(Metadata.fromOpenApiJSON({ json: args.nftMintParams.metadata }));
|
|
528
|
+
if (ipfsHash === undefined)
|
|
529
|
+
throw new Error("storage is required, but not provided");
|
|
530
|
+
if (metadataRoot === undefined)
|
|
531
|
+
throw new Error("metadataRoot is required");
|
|
532
|
+
const slot = chain === "local"
|
|
533
|
+
? Mina.currentSlot()
|
|
534
|
+
: chain === "zeko"
|
|
535
|
+
? UInt32.zero
|
|
536
|
+
: (await fetchLastBlock()).globalSlotSinceGenesis;
|
|
537
|
+
const expiry = slot.add(UInt32.from(chain === "mainnet" || chain === "devnet" ? 20 : 100000));
|
|
538
|
+
const nftData = NFTData.new(args.nftMintParams.data);
|
|
539
|
+
if (!args.nftMintParams.address)
|
|
540
|
+
throw new Error("NFT address is required");
|
|
541
|
+
const mintParams = new MintParams({
|
|
542
|
+
name: fieldFromString(name),
|
|
543
|
+
address: PublicKey.fromBase58(args.nftMintParams.address),
|
|
544
|
+
tokenId: TokenId.derive(collectionAddress),
|
|
545
|
+
data: nftData,
|
|
546
|
+
fee: args.nftMintParams.fee
|
|
547
|
+
? UInt64.from(Math.round(args.nftMintParams.fee * 1_000_000_000))
|
|
548
|
+
: UInt64.zero,
|
|
549
|
+
metadata: metadataRoot,
|
|
550
|
+
storage: Storage.fromString(ipfsHash),
|
|
551
|
+
metadataVerificationKeyHash: args.nftMintParams.metadataVerificationKeyHash
|
|
552
|
+
? Field.fromJSON(args.nftMintParams.metadataVerificationKeyHash)
|
|
553
|
+
: Field(0),
|
|
554
|
+
expiry: args.nftMintParams.expiry
|
|
555
|
+
? UInt32.from(Math.round(args.nftMintParams.expiry))
|
|
556
|
+
: expiry,
|
|
557
|
+
});
|
|
558
|
+
const accountCreationFee = 1_000_000_000;
|
|
559
|
+
const tx = await Mina.transaction({ sender, fee, memo, nonce }, async () => {
|
|
560
|
+
const feeAccountUpdate = AccountUpdate.createSigned(sender);
|
|
561
|
+
if (accountCreationFee > 0) {
|
|
562
|
+
feeAccountUpdate.balance.subInPlace(accountCreationFee);
|
|
563
|
+
}
|
|
564
|
+
if (provingKey && provingFee)
|
|
565
|
+
feeAccountUpdate.send({
|
|
566
|
+
to: provingKey,
|
|
567
|
+
amount: provingFee,
|
|
568
|
+
});
|
|
569
|
+
if (developerAddress && developerFee) {
|
|
570
|
+
feeAccountUpdate.send({
|
|
571
|
+
to: developerAddress,
|
|
572
|
+
amount: developerFee,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
switch (txType) {
|
|
576
|
+
case "nft:mint":
|
|
577
|
+
await zkCollection.mintByCreator(mintParams);
|
|
578
|
+
break;
|
|
579
|
+
default:
|
|
580
|
+
throw new Error(`Unknown transaction type: ${txType}`);
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
return {
|
|
584
|
+
request: args,
|
|
585
|
+
tx,
|
|
586
|
+
adminType,
|
|
587
|
+
adminContractAddress,
|
|
588
|
+
symbol,
|
|
589
|
+
name,
|
|
590
|
+
verificationKeyHashes,
|
|
591
|
+
metadataRoot: metadataRoot.toJSON(),
|
|
592
|
+
privateMetadata,
|
|
593
|
+
storage: ipfsHash,
|
|
594
|
+
map: serializedMap,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
export async function getNftSymbolAndAdmin(params) {
|
|
598
|
+
const { txType, collectionAddress, chain, nftAddress } = params;
|
|
599
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
600
|
+
let verificationKeyHashes = [];
|
|
601
|
+
// if (bidAddress) {
|
|
602
|
+
// verificationKeyHashes.push(vk.FungibleTokenBidContract.hash);
|
|
603
|
+
// }
|
|
604
|
+
// if (offerAddress) {
|
|
605
|
+
// verificationKeyHashes.push(vk.FungibleTokenOfferContract.hash);
|
|
606
|
+
// }
|
|
607
|
+
await fetchMinaAccount({ publicKey: collectionAddress, force: true });
|
|
608
|
+
if (!Mina.hasAccount(collectionAddress)) {
|
|
609
|
+
throw new Error("Collection contract account not found");
|
|
610
|
+
}
|
|
611
|
+
const tokenId = TokenId.derive(collectionAddress);
|
|
612
|
+
if (nftAddress) {
|
|
613
|
+
await fetchMinaAccount({
|
|
614
|
+
publicKey: nftAddress,
|
|
615
|
+
tokenId,
|
|
616
|
+
force: true,
|
|
617
|
+
});
|
|
618
|
+
if (!Mina.hasAccount(nftAddress, tokenId)) {
|
|
619
|
+
throw new Error("NFT account not found");
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
const account = Mina.getAccount(collectionAddress);
|
|
623
|
+
const verificationKey = account.zkapp?.verificationKey;
|
|
624
|
+
if (!verificationKey) {
|
|
625
|
+
throw new Error("Collection contract verification key not found");
|
|
626
|
+
}
|
|
627
|
+
if (!verificationKeyHashes.includes(verificationKey.hash.toJSON())) {
|
|
628
|
+
verificationKeyHashes.push(verificationKey.hash.toJSON());
|
|
629
|
+
}
|
|
630
|
+
if (account.zkapp?.appState === undefined) {
|
|
631
|
+
throw new Error("Collection contract state not found");
|
|
632
|
+
}
|
|
633
|
+
const collection = new Collection(collectionAddress);
|
|
634
|
+
const symbol = account.tokenSymbol;
|
|
635
|
+
const adminContractPublicKey = collection.admin.get();
|
|
636
|
+
await fetchMinaAccount({
|
|
637
|
+
publicKey: adminContractPublicKey,
|
|
638
|
+
force: true,
|
|
639
|
+
});
|
|
640
|
+
if (!Mina.hasAccount(adminContractPublicKey)) {
|
|
641
|
+
throw new Error("Admin contract account not found");
|
|
642
|
+
}
|
|
643
|
+
const adminContract = Mina.getAccount(adminContractPublicKey);
|
|
644
|
+
const adminVerificationKey = adminContract.zkapp?.verificationKey;
|
|
645
|
+
if (!adminVerificationKey) {
|
|
646
|
+
throw new Error("Admin verification key not found");
|
|
647
|
+
}
|
|
648
|
+
if (!verificationKeyHashes.includes(adminVerificationKey.hash.toJSON())) {
|
|
649
|
+
verificationKeyHashes.push(adminVerificationKey.hash.toJSON());
|
|
650
|
+
}
|
|
651
|
+
let adminType = "unknown";
|
|
652
|
+
if (vk.FungibleTokenAdvancedAdmin.hash === adminVerificationKey.hash.toJSON() &&
|
|
653
|
+
vk.FungibleTokenAdvancedAdmin.data === adminVerificationKey.data) {
|
|
654
|
+
adminType = "advanced";
|
|
655
|
+
}
|
|
656
|
+
else if (vk.FungibleTokenAdmin.hash === adminVerificationKey.hash.toJSON() &&
|
|
657
|
+
vk.FungibleTokenAdmin.data === adminVerificationKey.data) {
|
|
658
|
+
adminType = "standard";
|
|
659
|
+
}
|
|
660
|
+
else {
|
|
661
|
+
console.error("Unknown admin verification key", {
|
|
662
|
+
hash: adminVerificationKey.hash.toJSON(),
|
|
663
|
+
symbol,
|
|
664
|
+
address: adminContractPublicKey.toBase58(),
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
// let isToNewAccount: boolean | undefined = undefined;
|
|
668
|
+
// if (to) {
|
|
669
|
+
// if (adminType === "advanced") {
|
|
670
|
+
// const adminTokenId = TokenId.derive(adminContractPublicKey);
|
|
671
|
+
// await fetchMinaAccount({
|
|
672
|
+
// publicKey: to,
|
|
673
|
+
// tokenId: adminTokenId,
|
|
674
|
+
// force: false,
|
|
675
|
+
// });
|
|
676
|
+
// isToNewAccount = !Mina.hasAccount(to, adminTokenId);
|
|
677
|
+
// }
|
|
678
|
+
// if (adminType === "bondingCurve") {
|
|
679
|
+
// const adminTokenId = TokenId.derive(adminContractPublicKey);
|
|
680
|
+
// await fetchMinaAccount({
|
|
681
|
+
// publicKey: adminContractPublicKey,
|
|
682
|
+
// tokenId: adminTokenId,
|
|
683
|
+
// force: true,
|
|
684
|
+
// });
|
|
685
|
+
// }
|
|
686
|
+
// }
|
|
687
|
+
// const adminAddress0 = adminContract.zkapp?.appState[0];
|
|
688
|
+
// const adminAddress1 = adminContract.zkapp?.appState[1];
|
|
689
|
+
// if (adminAddress0 === undefined || adminAddress1 === undefined) {
|
|
690
|
+
// throw new Error("Cannot fetch admin address from admin contract");
|
|
691
|
+
// }
|
|
692
|
+
// const adminAddress = PublicKey.fromFields([adminAddress0, adminAddress1]);
|
|
693
|
+
for (const hash of verificationKeyHashes) {
|
|
694
|
+
const found = Object.values(vk).some((key) => key.hash === hash);
|
|
695
|
+
if (!found) {
|
|
696
|
+
console.error(`Final check: unknown verification key hash: ${hash}`);
|
|
697
|
+
verificationKeyHashes = verificationKeyHashes.filter((h) => h !== hash);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
// Sort verification key hashes by type
|
|
701
|
+
verificationKeyHashes.sort((a, b) => {
|
|
702
|
+
const typeA = Object.values(vk).find((key) => key.hash === a)?.type;
|
|
703
|
+
const typeB = Object.values(vk).find((key) => key.hash === b)?.type;
|
|
704
|
+
if (typeA === undefined || typeB === undefined) {
|
|
705
|
+
throw new Error("Unknown verification key hash");
|
|
706
|
+
}
|
|
707
|
+
const typeOrder = {
|
|
708
|
+
upgrade: 0,
|
|
709
|
+
nft: 1,
|
|
710
|
+
admin: 2,
|
|
711
|
+
collection: 3,
|
|
712
|
+
token: 4,
|
|
713
|
+
user: 5,
|
|
714
|
+
};
|
|
715
|
+
return typeOrder[typeA] - typeOrder[typeB];
|
|
716
|
+
});
|
|
717
|
+
return {
|
|
718
|
+
adminContractAddress: adminContractPublicKey,
|
|
719
|
+
symbol,
|
|
720
|
+
adminType,
|
|
721
|
+
verificationKeyHashes,
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
//# sourceMappingURL=build.js.map
|