@silvana-one/abi 0.1.17 → 0.1.19
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 +160 -1
- package/dist/node/nft/build.d.ts +26 -3
- package/dist/node/nft/build.js +430 -1
- package/dist/node/nft/build.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/nft/build.d.ts +26 -3
- package/dist/web/nft/build.js +430 -1
- package/dist/web/nft/build.js.map +1 -1
- package/package.json +9 -9
- package/src/nft/build.ts +515 -0
package/dist/node/index.cjs
CHANGED
|
@@ -23,6 +23,7 @@ __export(index_exports, {
|
|
|
23
23
|
LAUNCH_FEE: () => LAUNCH_FEE,
|
|
24
24
|
TRANSACTION_FEE: () => TRANSACTION_FEE,
|
|
25
25
|
buildNftCollectionLaunchTransaction: () => buildNftCollectionLaunchTransaction,
|
|
26
|
+
buildNftMintTransaction: () => buildNftMintTransaction,
|
|
26
27
|
buildNftTransaction: () => buildNftTransaction,
|
|
27
28
|
buildTokenLaunchTransaction: () => buildTokenLaunchTransaction,
|
|
28
29
|
buildTokenTransaction: () => buildTokenTransaction,
|
|
@@ -1259,6 +1260,142 @@ async function buildNftCollectionLaunchTransaction(params) {
|
|
|
1259
1260
|
};
|
|
1260
1261
|
}
|
|
1261
1262
|
async function buildNftTransaction(params) {
|
|
1263
|
+
const { chain, args } = params;
|
|
1264
|
+
const { nonce, txType } = args;
|
|
1265
|
+
if (nonce === void 0)
|
|
1266
|
+
throw new Error("Nonce is required");
|
|
1267
|
+
if (typeof nonce !== "number")
|
|
1268
|
+
throw new Error("Nonce must be a number");
|
|
1269
|
+
if (txType === void 0)
|
|
1270
|
+
throw new Error("Tx type is required");
|
|
1271
|
+
if (typeof txType !== "string")
|
|
1272
|
+
throw new Error("Tx type must be a string");
|
|
1273
|
+
if (args.sender === void 0 || typeof args.sender !== "string")
|
|
1274
|
+
throw new Error("Sender is required");
|
|
1275
|
+
if (args.collectionAddress === void 0 || typeof args.collectionAddress !== "string")
|
|
1276
|
+
throw new Error("Collection address is required");
|
|
1277
|
+
if (args.nftAddress === void 0 || typeof args.nftAddress !== "string")
|
|
1278
|
+
throw new Error("NFT address is required");
|
|
1279
|
+
const sender = import_o1js5.PublicKey.fromBase58(args.sender);
|
|
1280
|
+
const collectionAddress = import_o1js5.PublicKey.fromBase58(args.collectionAddress);
|
|
1281
|
+
if (txType === "nft:transfer" && args.nftTransferParams === void 0) {
|
|
1282
|
+
throw new Error("NFT transfer params are required");
|
|
1283
|
+
}
|
|
1284
|
+
if (txType === "nft:sell" && args.nftSellParams === void 0) {
|
|
1285
|
+
throw new Error("NFT sell params are required");
|
|
1286
|
+
}
|
|
1287
|
+
if (txType === "nft:buy" && args.nftBuyParams === void 0) {
|
|
1288
|
+
throw new Error("NFT buy params are required");
|
|
1289
|
+
}
|
|
1290
|
+
const nftAddress = import_o1js5.PublicKey.fromBase58(args.nftAddress);
|
|
1291
|
+
const to = "nftTransferParams" in args && args.nftTransferParams && args.nftTransferParams.to && typeof args.nftTransferParams.to === "string" ? import_o1js5.PublicKey.fromBase58(args.nftTransferParams.to) : void 0;
|
|
1292
|
+
if (!to && txType === "nft:transfer")
|
|
1293
|
+
throw new Error("To address is required");
|
|
1294
|
+
let buyer = "nftBuyParams" in args && args.nftBuyParams && args.nftBuyParams.buyer && typeof args.nftBuyParams.buyer === "string" ? import_o1js5.PublicKey.fromBase58(args.nftBuyParams.buyer) : void 0;
|
|
1295
|
+
if (!buyer && txType === "nft:buy")
|
|
1296
|
+
buyer = sender;
|
|
1297
|
+
const from = "nftTransferParams" in args && args.nftTransferParams && args.nftTransferParams.from && typeof args.nftTransferParams.from === "string" ? import_o1js5.PublicKey.fromBase58(args.nftTransferParams.from) : void 0;
|
|
1298
|
+
if (!from && txType === "nft:transfer")
|
|
1299
|
+
throw new Error("From address is required for nft:transfer");
|
|
1300
|
+
const price = "nftSellParams" in args ? args.nftSellParams && args.nftSellParams.price && typeof args.nftSellParams.price === "number" ? import_o1js5.UInt64.from(Math.round(args.nftSellParams.price * 1e9)) : void 0 : "nftTransferParams" in args && args.nftTransferParams && args.nftTransferParams.price && typeof args.nftTransferParams.price === "number" ? import_o1js5.UInt64.from(Math.round(args.nftTransferParams.price * 1e9)) : void 0;
|
|
1301
|
+
if (price === void 0 && txType === "nft:sell")
|
|
1302
|
+
throw new Error("Price is required for nft:sell");
|
|
1303
|
+
await fetchMinaAccount({
|
|
1304
|
+
publicKey: sender,
|
|
1305
|
+
force: true
|
|
1306
|
+
});
|
|
1307
|
+
if (!import_o1js5.Mina.hasAccount(sender)) {
|
|
1308
|
+
throw new Error("Sender does not have account");
|
|
1309
|
+
}
|
|
1310
|
+
const { symbol, adminContractAddress, adminType, verificationKeyHashes, collectionName, nftName, storage, metadataRoot } = await getNftSymbolAndAdmin({
|
|
1311
|
+
txType,
|
|
1312
|
+
collectionAddress,
|
|
1313
|
+
chain,
|
|
1314
|
+
nftAddress
|
|
1315
|
+
});
|
|
1316
|
+
if (storage === void 0)
|
|
1317
|
+
throw new Error("storage is required, but not provided");
|
|
1318
|
+
if (metadataRoot === void 0)
|
|
1319
|
+
throw new Error("metadataRoot is required");
|
|
1320
|
+
if (nftName === void 0)
|
|
1321
|
+
throw new Error("nftName is required");
|
|
1322
|
+
const memo = args.memo ?? `${txType.split(":")[1]} ${symbol} ${nftName}`;
|
|
1323
|
+
const fee = 1e8;
|
|
1324
|
+
const provingKey = params.provingKey ? import_o1js5.PublicKey.fromBase58(params.provingKey) : sender;
|
|
1325
|
+
const provingFee = params.provingFee ? import_o1js5.UInt64.from(Math.round(params.provingFee)) : void 0;
|
|
1326
|
+
const developerFee = args.developerFee ? import_o1js5.UInt64.from(Math.round(args.developerFee)) : void 0;
|
|
1327
|
+
const developerAddress = params.developerAddress ? import_o1js5.PublicKey.fromBase58(params.developerAddress) : void 0;
|
|
1328
|
+
const advancedAdminContract = new import_nft.NFTAdvancedAdmin(adminContractAddress);
|
|
1329
|
+
const adminContract = new import_nft.NFTAdmin(adminContractAddress);
|
|
1330
|
+
const collectionContract = adminType === "advanced" ? import_nft.AdvancedCollection : import_nft.Collection;
|
|
1331
|
+
const zkCollection = new collectionContract(collectionAddress);
|
|
1332
|
+
const tokenId = zkCollection.deriveTokenId();
|
|
1333
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
1334
|
+
if (!vk || !vk.Collection || !vk.Collection.hash || !vk.Collection.data || !vk.AdvancedCollection || !vk.AdvancedCollection.hash || !vk.AdvancedCollection.data || !vk.NFT || !vk.NFT.hash || !vk.NFT.data || !vk.NFTAdmin || !vk.NFTAdmin.hash || !vk.NFTAdmin.data || !vk.NFTAdvancedAdmin || !vk.NFTAdvancedAdmin.hash || !vk.NFTAdvancedAdmin.data)
|
|
1335
|
+
throw new Error("Cannot get verification key from vk");
|
|
1336
|
+
const accountCreationFee = 0;
|
|
1337
|
+
const tx = await import_o1js5.Mina.transaction({ sender, fee, memo, nonce }, async () => {
|
|
1338
|
+
const feeAccountUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
1339
|
+
if (accountCreationFee > 0) {
|
|
1340
|
+
feeAccountUpdate.balance.subInPlace(accountCreationFee);
|
|
1341
|
+
}
|
|
1342
|
+
if (provingKey && provingFee)
|
|
1343
|
+
feeAccountUpdate.send({
|
|
1344
|
+
to: provingKey,
|
|
1345
|
+
amount: provingFee
|
|
1346
|
+
});
|
|
1347
|
+
if (developerAddress && developerFee) {
|
|
1348
|
+
feeAccountUpdate.send({
|
|
1349
|
+
to: developerAddress,
|
|
1350
|
+
amount: developerFee
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
switch (txType) {
|
|
1354
|
+
case "nft:transfer":
|
|
1355
|
+
if (!from || !to || !price)
|
|
1356
|
+
throw new Error("From, to and price are required for nft:transfer");
|
|
1357
|
+
const context = args.nftTransferParams?.context?.custom ? new import_nft.NFTTransactionContext({
|
|
1358
|
+
custom: args.nftTransferParams.context.custom.map((x) => import_o1js5.Field.fromJSON(x))
|
|
1359
|
+
}) : new import_nft.NFTTransactionContext({
|
|
1360
|
+
custom: [(0, import_o1js5.Field)(0), (0, import_o1js5.Field)(0), (0, import_o1js5.Field)(0)]
|
|
1361
|
+
});
|
|
1362
|
+
const transferParams = {
|
|
1363
|
+
address: nftAddress,
|
|
1364
|
+
from,
|
|
1365
|
+
to,
|
|
1366
|
+
price: price ? import_nft.UInt64Option.from(price) : import_nft.UInt64Option.none(),
|
|
1367
|
+
context
|
|
1368
|
+
};
|
|
1369
|
+
if (args.nftTransferParams.requireApproval === true)
|
|
1370
|
+
await zkCollection.approvedTransferBySignature(transferParams);
|
|
1371
|
+
else
|
|
1372
|
+
await zkCollection.transferBySignature(transferParams);
|
|
1373
|
+
break;
|
|
1374
|
+
case "nft:approve":
|
|
1375
|
+
if (!to)
|
|
1376
|
+
throw new Error("To address is required for nft:approve");
|
|
1377
|
+
await zkCollection.approveAddress(nftAddress, to);
|
|
1378
|
+
break;
|
|
1379
|
+
default:
|
|
1380
|
+
throw new Error(`Unknown transaction type: ${txType}`);
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
return {
|
|
1384
|
+
request: args,
|
|
1385
|
+
tx,
|
|
1386
|
+
adminType,
|
|
1387
|
+
adminContractAddress,
|
|
1388
|
+
symbol,
|
|
1389
|
+
collectionName,
|
|
1390
|
+
nftName,
|
|
1391
|
+
verificationKeyHashes,
|
|
1392
|
+
metadataRoot,
|
|
1393
|
+
privateMetadata: void 0,
|
|
1394
|
+
storage,
|
|
1395
|
+
map: void 0
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
async function buildNftMintTransaction(params) {
|
|
1262
1399
|
const { chain, args } = params;
|
|
1263
1400
|
const { nonce, txType } = args;
|
|
1264
1401
|
if (nonce === void 0)
|
|
@@ -1380,6 +1517,9 @@ async function getNftSymbolAndAdmin(params) {
|
|
|
1380
1517
|
const { txType, collectionAddress, chain, nftAddress } = params;
|
|
1381
1518
|
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
1382
1519
|
let verificationKeyHashes = [];
|
|
1520
|
+
let nftName = void 0;
|
|
1521
|
+
let storage = void 0;
|
|
1522
|
+
let metadataRoot = void 0;
|
|
1383
1523
|
await fetchMinaAccount({ publicKey: collectionAddress, force: true });
|
|
1384
1524
|
if (!import_o1js5.Mina.hasAccount(collectionAddress)) {
|
|
1385
1525
|
throw new Error("Collection contract account not found");
|
|
@@ -1394,6 +1534,21 @@ async function getNftSymbolAndAdmin(params) {
|
|
|
1394
1534
|
if (!import_o1js5.Mina.hasAccount(nftAddress, tokenId)) {
|
|
1395
1535
|
throw new Error("NFT account not found");
|
|
1396
1536
|
}
|
|
1537
|
+
const nftAccount = import_o1js5.Mina.getAccount(nftAddress, tokenId);
|
|
1538
|
+
const verificationKey2 = nftAccount.zkapp?.verificationKey;
|
|
1539
|
+
if (!verificationKey2) {
|
|
1540
|
+
throw new Error("NFT contract verification key not found");
|
|
1541
|
+
}
|
|
1542
|
+
if (!verificationKeyHashes.includes(verificationKey2.hash.toJSON())) {
|
|
1543
|
+
verificationKeyHashes.push(verificationKey2.hash.toJSON());
|
|
1544
|
+
}
|
|
1545
|
+
if (nftAccount.zkapp?.appState === void 0) {
|
|
1546
|
+
throw new Error("NFT contract state not found");
|
|
1547
|
+
}
|
|
1548
|
+
const nft = new import_nft.NFT(nftAddress, tokenId);
|
|
1549
|
+
nftName = (0, import_nft.fieldToString)(nft.name.get());
|
|
1550
|
+
storage = nft.storage.get().toString();
|
|
1551
|
+
metadataRoot = nft.metadata.get().toJSON();
|
|
1397
1552
|
}
|
|
1398
1553
|
const account = import_o1js5.Mina.getAccount(collectionAddress);
|
|
1399
1554
|
const verificationKey = account.zkapp?.verificationKey;
|
|
@@ -1465,7 +1620,10 @@ async function getNftSymbolAndAdmin(params) {
|
|
|
1465
1620
|
symbol,
|
|
1466
1621
|
collectionName,
|
|
1467
1622
|
adminType,
|
|
1468
|
-
verificationKeyHashes
|
|
1623
|
+
verificationKeyHashes,
|
|
1624
|
+
nftName,
|
|
1625
|
+
storage,
|
|
1626
|
+
metadataRoot
|
|
1469
1627
|
};
|
|
1470
1628
|
}
|
|
1471
1629
|
|
|
@@ -1495,6 +1653,7 @@ var contractList = {
|
|
|
1495
1653
|
LAUNCH_FEE,
|
|
1496
1654
|
TRANSACTION_FEE,
|
|
1497
1655
|
buildNftCollectionLaunchTransaction,
|
|
1656
|
+
buildNftMintTransaction,
|
|
1498
1657
|
buildNftTransaction,
|
|
1499
1658
|
buildTokenLaunchTransaction,
|
|
1500
1659
|
buildTokenTransaction,
|
package/dist/node/nft/build.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IndexedMapSerialized } from "@silvana-one/storage";
|
|
2
|
-
import { NftTransactionType, NftTransactionParams, LaunchNftCollectionStandardAdminParams, LaunchNftCollectionAdvancedAdminParams } from "@silvana-one/api";
|
|
2
|
+
import { NftTransactionType, NftTransactionParams, LaunchNftCollectionStandardAdminParams, LaunchNftCollectionAdvancedAdminParams, NftMintTransactionParams } from "@silvana-one/api";
|
|
3
3
|
import { blockchain } from "../types.js";
|
|
4
4
|
import { PublicKey, Transaction } from "o1js";
|
|
5
5
|
export type NftAdminType = "standard" | "advanced" | "unknown";
|
|
@@ -23,12 +23,32 @@ export declare function buildNftCollectionLaunchTransaction(params: {
|
|
|
23
23
|
}>;
|
|
24
24
|
export declare function buildNftTransaction(params: {
|
|
25
25
|
chain: blockchain;
|
|
26
|
-
args: Exclude<NftTransactionParams, LaunchNftCollectionStandardAdminParams | LaunchNftCollectionAdvancedAdminParams>;
|
|
26
|
+
args: Exclude<NftTransactionParams, LaunchNftCollectionStandardAdminParams | LaunchNftCollectionAdvancedAdminParams | NftMintTransactionParams>;
|
|
27
27
|
developerAddress?: string;
|
|
28
28
|
provingKey?: string;
|
|
29
29
|
provingFee?: number;
|
|
30
30
|
}): Promise<{
|
|
31
|
-
request: Exclude<NftTransactionParams, LaunchNftCollectionStandardAdminParams | LaunchNftCollectionAdvancedAdminParams>;
|
|
31
|
+
request: Exclude<NftTransactionParams, LaunchNftCollectionStandardAdminParams | LaunchNftCollectionAdvancedAdminParams | NftMintTransactionParams>;
|
|
32
|
+
tx: Transaction<false, false>;
|
|
33
|
+
adminType: NftAdminType;
|
|
34
|
+
adminContractAddress: PublicKey;
|
|
35
|
+
symbol: string;
|
|
36
|
+
collectionName: string;
|
|
37
|
+
nftName: string;
|
|
38
|
+
verificationKeyHashes: string[];
|
|
39
|
+
metadataRoot: string;
|
|
40
|
+
storage: string;
|
|
41
|
+
privateMetadata?: string;
|
|
42
|
+
map?: IndexedMapSerialized;
|
|
43
|
+
}>;
|
|
44
|
+
export declare function buildNftMintTransaction(params: {
|
|
45
|
+
chain: blockchain;
|
|
46
|
+
args: NftMintTransactionParams;
|
|
47
|
+
developerAddress?: string;
|
|
48
|
+
provingKey?: string;
|
|
49
|
+
provingFee?: number;
|
|
50
|
+
}): Promise<{
|
|
51
|
+
request: NftMintTransactionParams;
|
|
32
52
|
tx: Transaction<false, false>;
|
|
33
53
|
adminType: NftAdminType;
|
|
34
54
|
adminContractAddress: PublicKey;
|
|
@@ -52,4 +72,7 @@ export declare function getNftSymbolAndAdmin(params: {
|
|
|
52
72
|
collectionName: string;
|
|
53
73
|
adminType: NftAdminType;
|
|
54
74
|
verificationKeyHashes: string[];
|
|
75
|
+
nftName?: string;
|
|
76
|
+
storage?: string;
|
|
77
|
+
metadataRoot?: string;
|
|
55
78
|
}>;
|