@silvana-one/abi 0.1.2 → 0.1.3
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/{token/contracts.d.ts → compile.d.ts} +1 -2
- package/dist/node/compile.js +2 -0
- package/dist/node/compile.js.map +1 -0
- package/dist/node/contracts.d.ts +1 -16
- package/dist/node/contracts.js +2 -2
- package/dist/node/contracts.js.map +1 -1
- package/dist/node/index.cjs +398 -18
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/nft/build.js +8 -6
- package/dist/node/nft/build.js.map +1 -1
- package/dist/node/nft/index.d.ts +1 -0
- package/dist/node/nft/index.js +2 -0
- package/dist/node/nft/index.js.map +1 -0
- package/dist/node/token/index.d.ts +0 -1
- package/dist/node/token/index.js +0 -1
- package/dist/node/token/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/{token/contracts.d.ts → compile.d.ts} +1 -2
- package/dist/web/compile.js +2 -0
- package/dist/web/compile.js.map +1 -0
- package/dist/web/contracts.d.ts +1 -16
- package/dist/web/contracts.js +2 -2
- package/dist/web/contracts.js.map +1 -1
- package/dist/web/index.d.ts +2 -0
- package/dist/web/index.js +2 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/nft/build.js +8 -6
- package/dist/web/nft/build.js.map +1 -1
- package/dist/web/nft/index.d.ts +1 -0
- package/dist/web/nft/index.js +2 -0
- package/dist/web/nft/index.js.map +1 -0
- package/dist/web/token/index.d.ts +0 -1
- package/dist/web/token/index.js +0 -1
- package/dist/web/token/index.js.map +1 -1
- package/package.json +9 -9
- package/src/compile.ts +17 -0
- package/src/contracts.ts +3 -19
- package/src/index.ts +2 -0
- package/src/nft/build.ts +8 -6
- package/src/nft/index.ts +1 -0
- package/src/token/index.ts +0 -1
- package/dist/node/token/contracts.js +0 -13
- package/dist/node/token/contracts.js.map +0 -1
- package/dist/web/token/contracts.js +0 -13
- package/dist/web/token/contracts.js.map +0 -1
- package/src/token/contracts.ts +0 -40
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cache, Field } from "o1js";
|
|
2
2
|
export type Compilable = {
|
|
3
|
-
compile(
|
|
3
|
+
compile(options?: {
|
|
4
4
|
cache: Cache;
|
|
5
5
|
}): Promise<{
|
|
6
6
|
verificationKey: {
|
|
@@ -9,7 +9,6 @@ export type Compilable = {
|
|
|
9
9
|
};
|
|
10
10
|
}>;
|
|
11
11
|
};
|
|
12
|
-
export declare const tokenContracts: Record<string, Compilable>;
|
|
13
12
|
export type CompileDependencies = Record<
|
|
14
13
|
/** Transaction type */
|
|
15
14
|
string,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.js","sourceRoot":"","sources":["../../src/compile.ts"],"names":[],"mappings":""}
|
package/dist/node/contracts.d.ts
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export type Compilable = {
|
|
3
|
-
compile({ cache }?: {
|
|
4
|
-
cache: Cache;
|
|
5
|
-
}): Promise<{
|
|
6
|
-
verificationKey: {
|
|
7
|
-
data: string;
|
|
8
|
-
hash: Field;
|
|
9
|
-
};
|
|
10
|
-
}>;
|
|
11
|
-
};
|
|
12
|
-
export type CompileDependencies = Record<
|
|
13
|
-
/** Transaction type */
|
|
14
|
-
string,
|
|
15
|
-
/** List of contract names */
|
|
16
|
-
string[]>;
|
|
1
|
+
import { Compilable } from "./compile.js";
|
|
17
2
|
export declare const contractList: Record<string, Compilable>;
|
package/dist/node/contracts.js
CHANGED
|
@@ -10,8 +10,8 @@ export const contractList = {
|
|
|
10
10
|
FungibleTokenOfferContract: FungibleTokenOfferContract,
|
|
11
11
|
FungibleTokenClaimContract: FungibleTokenClaimContract,
|
|
12
12
|
NFT: NFT,
|
|
13
|
-
Collection: Collection,
|
|
14
|
-
AdvancedCollection: AdvancedCollection,
|
|
13
|
+
Collection: Collection,
|
|
14
|
+
AdvancedCollection: AdvancedCollection,
|
|
15
15
|
NFTAdmin: NFTAdmin,
|
|
16
16
|
NFTAdvancedAdmin: NFTAdvancedAdmin,
|
|
17
17
|
VerificationKeyUpgradeAuthority: VerificationKeyUpgradeAuthority,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/contracts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,GAAG,EACH,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAG1E,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,aAAa,EAAE,aAAa;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,qBAAqB,EAAE,qBAAqB;IAC5C,0BAA0B,EAAE,0BAA0B;IACtD,wBAAwB,EAAE,wBAAwB;IAClD,0BAA0B,EAAE,0BAA0B;IACtD,0BAA0B,EAAE,0BAA0B;IACtD,GAAG,EAAE,GAAG;IACR,UAAU,EAAE,UAAU;IACtB,kBAAkB,EAAE,kBAAkB;IACtC,QAAQ,EAAE,QAAQ;IAClB,gBAAgB,EAAE,gBAAgB;IAClC,+BAA+B,EAAE,+BAA+B;CACjE,CAAC"}
|
package/dist/node/index.cjs
CHANGED
|
@@ -22,16 +22,19 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
LAUNCH_FEE: () => LAUNCH_FEE,
|
|
24
24
|
TRANSACTION_FEE: () => TRANSACTION_FEE,
|
|
25
|
+
buildNftCollectionLaunchTransaction: () => buildNftCollectionLaunchTransaction,
|
|
26
|
+
buildNftTransaction: () => buildNftTransaction,
|
|
25
27
|
buildTokenLaunchTransaction: () => buildTokenLaunchTransaction,
|
|
26
28
|
buildTokenTransaction: () => buildTokenTransaction,
|
|
27
29
|
checkAddress: () => checkAddress,
|
|
30
|
+
contractList: () => contractList,
|
|
28
31
|
devnet: () => devnet,
|
|
29
32
|
fetchMinaAccount: () => fetchMinaAccount,
|
|
30
33
|
getContractInfo: () => getContractInfo,
|
|
34
|
+
getNftSymbolAndAdmin: () => getNftSymbolAndAdmin,
|
|
31
35
|
getTokenSymbolAndAdmin: () => getTokenSymbolAndAdmin,
|
|
32
36
|
mainnet: () => mainnet,
|
|
33
37
|
tokenBalance: () => tokenBalance,
|
|
34
|
-
tokenContracts: () => tokenContracts,
|
|
35
38
|
tokenVerificationKeys: () => tokenVerificationKeys
|
|
36
39
|
});
|
|
37
40
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -900,20 +903,6 @@ async function getTokenSymbolAndAdmin(params) {
|
|
|
900
903
|
};
|
|
901
904
|
}
|
|
902
905
|
|
|
903
|
-
// dist/node/token/contracts.js
|
|
904
|
-
var import_token2 = require("@silvana-one/token");
|
|
905
|
-
var tokenContracts = {
|
|
906
|
-
FungibleToken: import_token2.FungibleToken,
|
|
907
|
-
FungibleTokenAdmin: import_token2.FungibleTokenAdmin,
|
|
908
|
-
AdvancedFungibleToken: import_token2.AdvancedFungibleToken,
|
|
909
|
-
BondingCurveFungibleToken: import_token2.BondingCurveFungibleToken,
|
|
910
|
-
FungibleTokenAdvancedAdmin: import_token2.FungibleTokenAdvancedAdmin,
|
|
911
|
-
FungibleTokenBondingCurveAdmin: import_token2.FungibleTokenBondingCurveAdmin,
|
|
912
|
-
FungibleTokenBidContract: import_token2.FungibleTokenBidContract,
|
|
913
|
-
FungibleTokenOfferContract: import_token2.FungibleTokenOfferContract,
|
|
914
|
-
FungibleTokenClaimContract: import_token2.FungibleTokenClaimContract
|
|
915
|
-
};
|
|
916
|
-
|
|
917
906
|
// dist/node/token/info.js
|
|
918
907
|
var import_o1js4 = require("o1js");
|
|
919
908
|
|
|
@@ -938,7 +927,7 @@ async function checkAddress(address) {
|
|
|
938
927
|
}
|
|
939
928
|
|
|
940
929
|
// dist/node/token/info.js
|
|
941
|
-
var
|
|
930
|
+
var import_token2 = require("@silvana-one/token");
|
|
942
931
|
async function getContractInfo(params) {
|
|
943
932
|
const { address, chain, parentTokenId, decimals } = params;
|
|
944
933
|
const vk = tokenVerificationKeys[chain].vk;
|
|
@@ -988,7 +977,7 @@ async function getContractInfo(params) {
|
|
|
988
977
|
case "FungibleToken":
|
|
989
978
|
case "AdvancedFungibleToken":
|
|
990
979
|
{
|
|
991
|
-
const zkApp = new
|
|
980
|
+
const zkApp = new import_token2.FungibleToken(publicKey, tokenId);
|
|
992
981
|
const admin = zkApp.admin.get();
|
|
993
982
|
const decimals2 = zkApp.decimals.get();
|
|
994
983
|
const paused = zkApp.paused.get();
|
|
@@ -1103,19 +1092,410 @@ async function tokenBalance(params) {
|
|
|
1103
1092
|
};
|
|
1104
1093
|
}
|
|
1105
1094
|
}
|
|
1095
|
+
|
|
1096
|
+
// dist/node/nft/build.js
|
|
1097
|
+
var import_storage2 = require("@silvana-one/storage");
|
|
1098
|
+
var import_nft = require("@silvana-one/nft");
|
|
1099
|
+
var import_o1js5 = require("o1js");
|
|
1100
|
+
async function buildNftCollectionLaunchTransaction(params) {
|
|
1101
|
+
const { chain, args } = params;
|
|
1102
|
+
const { url = chain === "mainnet" ? "https://minanft.io" : `https://${chain}.minanft.io`, symbol = "NFT", memo, nonce, adminContract: adminType, masterNFT } = args;
|
|
1103
|
+
if (memo && typeof memo !== "string")
|
|
1104
|
+
throw new Error("Memo must be a string");
|
|
1105
|
+
if (memo && memo.length > 30)
|
|
1106
|
+
throw new Error("Memo must be less than 30 characters");
|
|
1107
|
+
if (!symbol || typeof symbol !== "string")
|
|
1108
|
+
throw new Error("Symbol must be a string");
|
|
1109
|
+
if (symbol.length >= 7)
|
|
1110
|
+
throw new Error("Symbol must be less than 7 characters");
|
|
1111
|
+
if (masterNFT === void 0) {
|
|
1112
|
+
throw new Error("masterNFT is required");
|
|
1113
|
+
}
|
|
1114
|
+
if (masterNFT.metadata === void 0) {
|
|
1115
|
+
throw new Error("masterNFT.metadata is required");
|
|
1116
|
+
}
|
|
1117
|
+
if (typeof masterNFT.metadata === "string" && masterNFT.storage === void 0) {
|
|
1118
|
+
throw new Error("masterNFT.storage is required if metadata is a string");
|
|
1119
|
+
}
|
|
1120
|
+
const sender = import_o1js5.PublicKey.fromBase58(args.sender);
|
|
1121
|
+
if (nonce === void 0)
|
|
1122
|
+
throw new Error("Nonce is required");
|
|
1123
|
+
if (typeof nonce !== "number")
|
|
1124
|
+
throw new Error("Nonce must be a number");
|
|
1125
|
+
const fee = 1e8;
|
|
1126
|
+
if (url && typeof url !== "string")
|
|
1127
|
+
throw new Error("Url must be a string");
|
|
1128
|
+
if (!args.collectionAddress || typeof args.collectionAddress !== "string")
|
|
1129
|
+
throw new Error("collectionAddress is required");
|
|
1130
|
+
if (!args.adminContractAddress || typeof args.adminContractAddress !== "string")
|
|
1131
|
+
throw new Error("adminContractAddress is required");
|
|
1132
|
+
const adminContract = adminType === "advanced" ? import_nft.NFTAdvancedAdmin : import_nft.NFTAdmin;
|
|
1133
|
+
const collectionContract = adminType === "advanced" ? import_nft.AdvancedCollection : import_nft.Collection;
|
|
1134
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
1135
|
+
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)
|
|
1136
|
+
throw new Error("Cannot get verification key from vk");
|
|
1137
|
+
const adminVerificationKey = adminType === "advanced" ? vk.NFTAdvancedAdmin : vk.NFTAdmin;
|
|
1138
|
+
const collectionVerificationKey = adminType === "advanced" ? vk.AdvancedCollection : vk.Collection;
|
|
1139
|
+
if (!adminVerificationKey || !collectionVerificationKey)
|
|
1140
|
+
throw new Error("Cannot get verification keys");
|
|
1141
|
+
await fetchMinaAccount({
|
|
1142
|
+
publicKey: sender,
|
|
1143
|
+
force: true
|
|
1144
|
+
});
|
|
1145
|
+
if (!import_o1js5.Mina.hasAccount(sender)) {
|
|
1146
|
+
throw new Error("Sender does not have account");
|
|
1147
|
+
}
|
|
1148
|
+
const whitelist = "whitelist" in args && args.whitelist ? typeof args.whitelist === "string" ? import_storage2.Whitelist.fromString(args.whitelist) : (await import_storage2.Whitelist.create({ list: args.whitelist, name: symbol })).whitelist : import_storage2.Whitelist.empty();
|
|
1149
|
+
const collectionAddress = import_o1js5.PublicKey.fromBase58(args.collectionAddress);
|
|
1150
|
+
const adminContractAddress = import_o1js5.PublicKey.fromBase58(args.adminContractAddress);
|
|
1151
|
+
const creator = args.creator ? import_o1js5.PublicKey.fromBase58(args.creator) : sender;
|
|
1152
|
+
const zkCollection = new collectionContract(collectionAddress);
|
|
1153
|
+
const zkAdmin = new adminContract(adminContractAddress);
|
|
1154
|
+
const metadataVerificationKeyHash = masterNFT.metadataVerificationKeyHash ? import_o1js5.Field.fromJSON(masterNFT.metadataVerificationKeyHash) : (0, import_o1js5.Field)(0);
|
|
1155
|
+
const provingKey = params.provingKey ? import_o1js5.PublicKey.fromBase58(params.provingKey) : sender;
|
|
1156
|
+
const provingFee = params.provingFee ? import_o1js5.UInt64.from(Math.round(params.provingFee)) : void 0;
|
|
1157
|
+
const developerFee = args.developerFee ? import_o1js5.UInt64.from(Math.round(args.developerFee)) : void 0;
|
|
1158
|
+
const developerAddress = params.developerAddress ? import_o1js5.PublicKey.fromBase58(params.developerAddress) : void 0;
|
|
1159
|
+
const { name, ipfsHash, metadataRoot, privateMetadata, serializedMap } = typeof masterNFT.metadata === "string" ? {
|
|
1160
|
+
name: masterNFT.name,
|
|
1161
|
+
ipfsHash: masterNFT.storage,
|
|
1162
|
+
metadataRoot: import_o1js5.Field.fromJSON(masterNFT.metadata),
|
|
1163
|
+
privateMetadata: void 0,
|
|
1164
|
+
serializedMap: void 0
|
|
1165
|
+
} : await (0, import_nft.pinMetadata)(import_nft.Metadata.fromOpenApiJSON({ json: masterNFT.metadata }));
|
|
1166
|
+
if (ipfsHash === void 0)
|
|
1167
|
+
throw new Error("storage is required, but not provided");
|
|
1168
|
+
if (metadataRoot === void 0)
|
|
1169
|
+
throw new Error("metadataRoot is required");
|
|
1170
|
+
const slot = chain === "local" ? import_o1js5.Mina.currentSlot() : chain === "zeko" ? import_o1js5.UInt32.zero : (await (0, import_o1js5.fetchLastBlock)()).globalSlotSinceGenesis;
|
|
1171
|
+
const expiry = slot.add(import_o1js5.UInt32.from(chain === "mainnet" || chain === "devnet" ? 20 : 1e5));
|
|
1172
|
+
const nftData = import_nft.NFTData.new({
|
|
1173
|
+
owner: creator,
|
|
1174
|
+
approved: void 0,
|
|
1175
|
+
version: void 0,
|
|
1176
|
+
id: masterNFT.data.id ? BigInt(masterNFT.data.id) : void 0,
|
|
1177
|
+
canChangeOwnerByProof: masterNFT.data.canChangeOwnerByProof,
|
|
1178
|
+
canTransfer: masterNFT.data.canTransfer,
|
|
1179
|
+
canApprove: masterNFT.data.canApprove,
|
|
1180
|
+
canChangeMetadata: masterNFT.data.canChangeMetadata,
|
|
1181
|
+
canChangeStorage: masterNFT.data.canChangeStorage,
|
|
1182
|
+
canChangeName: masterNFT.data.canChangeName,
|
|
1183
|
+
canChangeMetadataVerificationKeyHash: masterNFT.data.canChangeMetadataVerificationKeyHash,
|
|
1184
|
+
canPause: masterNFT.data.canPause,
|
|
1185
|
+
isPaused: masterNFT.data.isPaused,
|
|
1186
|
+
requireOwnerAuthorizationToUpgrade: masterNFT.data.requireOwnerAuthorizationToUpgrade
|
|
1187
|
+
});
|
|
1188
|
+
const mintParams = new import_nft.MintParams({
|
|
1189
|
+
name: (0, import_nft.fieldFromString)(name),
|
|
1190
|
+
address: collectionAddress,
|
|
1191
|
+
tokenId: import_o1js5.TokenId.derive(collectionAddress),
|
|
1192
|
+
data: nftData,
|
|
1193
|
+
fee: args.masterNFT.fee ? import_o1js5.UInt64.from(Math.round(args.masterNFT.fee * 1e9)) : import_o1js5.UInt64.zero,
|
|
1194
|
+
metadata: metadataRoot,
|
|
1195
|
+
storage: import_storage2.Storage.fromString(ipfsHash),
|
|
1196
|
+
metadataVerificationKeyHash,
|
|
1197
|
+
expiry: masterNFT.expiry ? import_o1js5.UInt32.from(Math.round(masterNFT.expiry)) : expiry
|
|
1198
|
+
});
|
|
1199
|
+
const collectionData = import_nft.CollectionData.new(args.collectionData ?? {});
|
|
1200
|
+
const tx = await import_o1js5.Mina.transaction({
|
|
1201
|
+
sender,
|
|
1202
|
+
fee,
|
|
1203
|
+
memo: memo ?? `${args.collectionName} NFT collection launch`.substring(0, 30),
|
|
1204
|
+
nonce
|
|
1205
|
+
}, async () => {
|
|
1206
|
+
const feeAccountUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
1207
|
+
feeAccountUpdate.balance.subInPlace(3e9);
|
|
1208
|
+
if (provingFee && provingKey)
|
|
1209
|
+
feeAccountUpdate.send({
|
|
1210
|
+
to: provingKey,
|
|
1211
|
+
amount: provingFee
|
|
1212
|
+
});
|
|
1213
|
+
if (developerAddress && developerFee) {
|
|
1214
|
+
feeAccountUpdate.send({
|
|
1215
|
+
to: developerAddress,
|
|
1216
|
+
amount: developerFee
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
if (zkAdmin instanceof import_nft.NFTAdvancedAdmin) {
|
|
1220
|
+
throw new Error("Advanced admin is not supported");
|
|
1221
|
+
} else if (zkAdmin instanceof import_nft.NFTAdmin) {
|
|
1222
|
+
await zkAdmin.deploy({
|
|
1223
|
+
admin: sender,
|
|
1224
|
+
uri: `NFT Admin`,
|
|
1225
|
+
verificationKey: adminVerificationKey
|
|
1226
|
+
});
|
|
1227
|
+
await zkCollection.deploy({
|
|
1228
|
+
creator,
|
|
1229
|
+
collectionName: (0, import_nft.fieldFromString)(args.collectionName),
|
|
1230
|
+
baseURL: (0, import_nft.fieldFromString)(args.baseURL ?? "ipfs"),
|
|
1231
|
+
admin: adminContractAddress,
|
|
1232
|
+
symbol,
|
|
1233
|
+
url,
|
|
1234
|
+
verificationKey: collectionVerificationKey
|
|
1235
|
+
});
|
|
1236
|
+
await zkCollection.initialize(mintParams, collectionData);
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
return {
|
|
1240
|
+
request: adminType === "advanced" ? {
|
|
1241
|
+
...args,
|
|
1242
|
+
whitelist: whitelist.toString()
|
|
1243
|
+
} : args,
|
|
1244
|
+
tx,
|
|
1245
|
+
adminType,
|
|
1246
|
+
name: args.collectionName,
|
|
1247
|
+
verificationKeyHashes: [
|
|
1248
|
+
adminVerificationKey.hash,
|
|
1249
|
+
collectionVerificationKey.hash
|
|
1250
|
+
],
|
|
1251
|
+
metadataRoot: metadataRoot.toJSON(),
|
|
1252
|
+
storage: ipfsHash,
|
|
1253
|
+
privateMetadata,
|
|
1254
|
+
map: serializedMap
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
async function buildNftTransaction(params) {
|
|
1258
|
+
const { chain, args } = params;
|
|
1259
|
+
const { nonce, txType } = args;
|
|
1260
|
+
if (nonce === void 0)
|
|
1261
|
+
throw new Error("Nonce is required");
|
|
1262
|
+
if (typeof nonce !== "number")
|
|
1263
|
+
throw new Error("Nonce must be a number");
|
|
1264
|
+
if (txType === void 0)
|
|
1265
|
+
throw new Error("Tx type is required");
|
|
1266
|
+
if (typeof txType !== "string")
|
|
1267
|
+
throw new Error("Tx type must be a string");
|
|
1268
|
+
const sender = import_o1js5.PublicKey.fromBase58(args.sender);
|
|
1269
|
+
const collectionAddress = import_o1js5.PublicKey.fromBase58(args.collectionAddress);
|
|
1270
|
+
if (args.nftMintParams.address === void 0) {
|
|
1271
|
+
throw new Error("NFT address is required");
|
|
1272
|
+
}
|
|
1273
|
+
const nftAddress = import_o1js5.PublicKey.fromBase58(args.nftMintParams.address);
|
|
1274
|
+
await fetchMinaAccount({
|
|
1275
|
+
publicKey: sender,
|
|
1276
|
+
force: true
|
|
1277
|
+
});
|
|
1278
|
+
if (!import_o1js5.Mina.hasAccount(sender)) {
|
|
1279
|
+
throw new Error("Sender does not have account");
|
|
1280
|
+
}
|
|
1281
|
+
const { symbol, adminContractAddress, adminType, verificationKeyHashes } = await getNftSymbolAndAdmin({
|
|
1282
|
+
txType,
|
|
1283
|
+
collectionAddress,
|
|
1284
|
+
chain,
|
|
1285
|
+
nftAddress: void 0
|
|
1286
|
+
// TODO: add nft address
|
|
1287
|
+
});
|
|
1288
|
+
const memo = args.memo ?? `${txType} ${symbol} ${args.nftMintParams.name}`;
|
|
1289
|
+
const fee = 1e8;
|
|
1290
|
+
const provingKey = params.provingKey ? import_o1js5.PublicKey.fromBase58(params.provingKey) : sender;
|
|
1291
|
+
const provingFee = params.provingFee ? import_o1js5.UInt64.from(Math.round(params.provingFee)) : void 0;
|
|
1292
|
+
const developerFee = args.developerFee ? import_o1js5.UInt64.from(Math.round(args.developerFee)) : void 0;
|
|
1293
|
+
const developerAddress = params.developerAddress ? import_o1js5.PublicKey.fromBase58(params.developerAddress) : void 0;
|
|
1294
|
+
const advancedAdminContract = new import_nft.NFTAdvancedAdmin(adminContractAddress);
|
|
1295
|
+
const adminContract = new import_nft.NFTAdmin(adminContractAddress);
|
|
1296
|
+
const collectionContract = adminType === "advanced" ? import_nft.AdvancedCollection : import_nft.Collection;
|
|
1297
|
+
const zkCollection = new collectionContract(collectionAddress);
|
|
1298
|
+
const tokenId = zkCollection.deriveTokenId();
|
|
1299
|
+
await fetchMinaAccount({
|
|
1300
|
+
publicKey: nftAddress,
|
|
1301
|
+
tokenId,
|
|
1302
|
+
force: ["nft:transfer"].includes(txType)
|
|
1303
|
+
});
|
|
1304
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
1305
|
+
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)
|
|
1306
|
+
throw new Error("Cannot get verification key from vk");
|
|
1307
|
+
const { name, ipfsHash, metadataRoot, privateMetadata, serializedMap } = typeof args.nftMintParams.metadata === "string" ? {
|
|
1308
|
+
name: args.nftMintParams.name,
|
|
1309
|
+
ipfsHash: args.nftMintParams.storage,
|
|
1310
|
+
metadataRoot: import_o1js5.Field.fromJSON(args.nftMintParams.metadata),
|
|
1311
|
+
privateMetadata: void 0,
|
|
1312
|
+
serializedMap: void 0
|
|
1313
|
+
} : await (0, import_nft.pinMetadata)(import_nft.Metadata.fromOpenApiJSON({ json: args.nftMintParams.metadata }));
|
|
1314
|
+
if (ipfsHash === void 0)
|
|
1315
|
+
throw new Error("storage is required, but not provided");
|
|
1316
|
+
if (metadataRoot === void 0)
|
|
1317
|
+
throw new Error("metadataRoot is required");
|
|
1318
|
+
const slot = chain === "local" ? import_o1js5.Mina.currentSlot() : chain === "zeko" ? import_o1js5.UInt32.zero : (await (0, import_o1js5.fetchLastBlock)()).globalSlotSinceGenesis;
|
|
1319
|
+
const expiry = slot.add(import_o1js5.UInt32.from(chain === "mainnet" || chain === "devnet" ? 20 : 1e5));
|
|
1320
|
+
const nftData = import_nft.NFTData.new(args.nftMintParams.data);
|
|
1321
|
+
if (!args.nftMintParams.address)
|
|
1322
|
+
throw new Error("NFT address is required");
|
|
1323
|
+
const mintParams = new import_nft.MintParams({
|
|
1324
|
+
name: (0, import_nft.fieldFromString)(name),
|
|
1325
|
+
address: import_o1js5.PublicKey.fromBase58(args.nftMintParams.address),
|
|
1326
|
+
tokenId: import_o1js5.TokenId.derive(collectionAddress),
|
|
1327
|
+
data: nftData,
|
|
1328
|
+
fee: args.nftMintParams.fee ? import_o1js5.UInt64.from(Math.round(args.nftMintParams.fee * 1e9)) : import_o1js5.UInt64.zero,
|
|
1329
|
+
metadata: metadataRoot,
|
|
1330
|
+
storage: import_storage2.Storage.fromString(ipfsHash),
|
|
1331
|
+
metadataVerificationKeyHash: args.nftMintParams.metadataVerificationKeyHash ? import_o1js5.Field.fromJSON(args.nftMintParams.metadataVerificationKeyHash) : (0, import_o1js5.Field)(0),
|
|
1332
|
+
expiry: args.nftMintParams.expiry ? import_o1js5.UInt32.from(Math.round(args.nftMintParams.expiry)) : expiry
|
|
1333
|
+
});
|
|
1334
|
+
const accountCreationFee = 0;
|
|
1335
|
+
const tx = await import_o1js5.Mina.transaction({ sender, fee, memo, nonce }, async () => {
|
|
1336
|
+
const feeAccountUpdate = import_o1js5.AccountUpdate.createSigned(sender);
|
|
1337
|
+
if (accountCreationFee > 0) {
|
|
1338
|
+
feeAccountUpdate.balance.subInPlace(accountCreationFee);
|
|
1339
|
+
}
|
|
1340
|
+
if (provingKey && provingFee)
|
|
1341
|
+
feeAccountUpdate.send({
|
|
1342
|
+
to: provingKey,
|
|
1343
|
+
amount: provingFee
|
|
1344
|
+
});
|
|
1345
|
+
if (developerAddress && developerFee) {
|
|
1346
|
+
feeAccountUpdate.send({
|
|
1347
|
+
to: developerAddress,
|
|
1348
|
+
amount: developerFee
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
switch (txType) {
|
|
1352
|
+
case "nft:mint":
|
|
1353
|
+
await zkCollection.mintByCreator(mintParams);
|
|
1354
|
+
break;
|
|
1355
|
+
default:
|
|
1356
|
+
throw new Error(`Unknown transaction type: ${txType}`);
|
|
1357
|
+
}
|
|
1358
|
+
});
|
|
1359
|
+
return {
|
|
1360
|
+
request: args,
|
|
1361
|
+
tx,
|
|
1362
|
+
adminType,
|
|
1363
|
+
adminContractAddress,
|
|
1364
|
+
symbol,
|
|
1365
|
+
name,
|
|
1366
|
+
verificationKeyHashes,
|
|
1367
|
+
metadataRoot: metadataRoot.toJSON(),
|
|
1368
|
+
privateMetadata,
|
|
1369
|
+
storage: ipfsHash,
|
|
1370
|
+
map: serializedMap
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
async function getNftSymbolAndAdmin(params) {
|
|
1374
|
+
const { txType, collectionAddress, chain, nftAddress } = params;
|
|
1375
|
+
const vk = tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
|
|
1376
|
+
let verificationKeyHashes = [];
|
|
1377
|
+
await fetchMinaAccount({ publicKey: collectionAddress, force: true });
|
|
1378
|
+
if (!import_o1js5.Mina.hasAccount(collectionAddress)) {
|
|
1379
|
+
throw new Error("Collection contract account not found");
|
|
1380
|
+
}
|
|
1381
|
+
const tokenId = import_o1js5.TokenId.derive(collectionAddress);
|
|
1382
|
+
if (nftAddress) {
|
|
1383
|
+
await fetchMinaAccount({
|
|
1384
|
+
publicKey: nftAddress,
|
|
1385
|
+
tokenId,
|
|
1386
|
+
force: true
|
|
1387
|
+
});
|
|
1388
|
+
if (!import_o1js5.Mina.hasAccount(nftAddress, tokenId)) {
|
|
1389
|
+
throw new Error("NFT account not found");
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
const account = import_o1js5.Mina.getAccount(collectionAddress);
|
|
1393
|
+
const verificationKey = account.zkapp?.verificationKey;
|
|
1394
|
+
if (!verificationKey) {
|
|
1395
|
+
throw new Error("Collection contract verification key not found");
|
|
1396
|
+
}
|
|
1397
|
+
if (!verificationKeyHashes.includes(verificationKey.hash.toJSON())) {
|
|
1398
|
+
verificationKeyHashes.push(verificationKey.hash.toJSON());
|
|
1399
|
+
}
|
|
1400
|
+
if (account.zkapp?.appState === void 0) {
|
|
1401
|
+
throw new Error("Collection contract state not found");
|
|
1402
|
+
}
|
|
1403
|
+
const collection = new import_nft.Collection(collectionAddress);
|
|
1404
|
+
const symbol = account.tokenSymbol;
|
|
1405
|
+
const adminContractPublicKey = collection.admin.get();
|
|
1406
|
+
await fetchMinaAccount({
|
|
1407
|
+
publicKey: adminContractPublicKey,
|
|
1408
|
+
force: true
|
|
1409
|
+
});
|
|
1410
|
+
if (!import_o1js5.Mina.hasAccount(adminContractPublicKey)) {
|
|
1411
|
+
throw new Error("Admin contract account not found");
|
|
1412
|
+
}
|
|
1413
|
+
const adminContract = import_o1js5.Mina.getAccount(adminContractPublicKey);
|
|
1414
|
+
const adminVerificationKey = adminContract.zkapp?.verificationKey;
|
|
1415
|
+
if (!adminVerificationKey) {
|
|
1416
|
+
throw new Error("Admin verification key not found");
|
|
1417
|
+
}
|
|
1418
|
+
if (!verificationKeyHashes.includes(adminVerificationKey.hash.toJSON())) {
|
|
1419
|
+
verificationKeyHashes.push(adminVerificationKey.hash.toJSON());
|
|
1420
|
+
}
|
|
1421
|
+
let adminType = "unknown";
|
|
1422
|
+
if (vk.NFTAdvancedAdmin.hash === adminVerificationKey.hash.toJSON() && vk.NFTAdvancedAdmin.data === adminVerificationKey.data) {
|
|
1423
|
+
adminType = "advanced";
|
|
1424
|
+
} else if (vk.NFTAdmin.hash === adminVerificationKey.hash.toJSON() && vk.NFTAdmin.data === adminVerificationKey.data) {
|
|
1425
|
+
adminType = "standard";
|
|
1426
|
+
} else {
|
|
1427
|
+
console.error("Unknown admin verification key", {
|
|
1428
|
+
hash: adminVerificationKey.hash.toJSON(),
|
|
1429
|
+
symbol,
|
|
1430
|
+
address: adminContractPublicKey.toBase58()
|
|
1431
|
+
});
|
|
1432
|
+
}
|
|
1433
|
+
for (const hash of verificationKeyHashes) {
|
|
1434
|
+
const found = Object.values(vk).some((key) => key.hash === hash);
|
|
1435
|
+
if (!found) {
|
|
1436
|
+
console.error(`Final check: unknown verification key hash: ${hash}`);
|
|
1437
|
+
verificationKeyHashes = verificationKeyHashes.filter((h) => h !== hash);
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
verificationKeyHashes.sort((a, b) => {
|
|
1441
|
+
const typeA = Object.values(vk).find((key) => key.hash === a)?.type;
|
|
1442
|
+
const typeB = Object.values(vk).find((key) => key.hash === b)?.type;
|
|
1443
|
+
if (typeA === void 0 || typeB === void 0) {
|
|
1444
|
+
throw new Error("Unknown verification key hash");
|
|
1445
|
+
}
|
|
1446
|
+
const typeOrder = {
|
|
1447
|
+
upgrade: 0,
|
|
1448
|
+
nft: 1,
|
|
1449
|
+
admin: 2,
|
|
1450
|
+
collection: 3,
|
|
1451
|
+
token: 4,
|
|
1452
|
+
user: 5
|
|
1453
|
+
};
|
|
1454
|
+
return typeOrder[typeA] - typeOrder[typeB];
|
|
1455
|
+
});
|
|
1456
|
+
return {
|
|
1457
|
+
adminContractAddress: adminContractPublicKey,
|
|
1458
|
+
symbol,
|
|
1459
|
+
adminType,
|
|
1460
|
+
verificationKeyHashes
|
|
1461
|
+
};
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// dist/node/contracts.js
|
|
1465
|
+
var import_token3 = require("@silvana-one/token");
|
|
1466
|
+
var import_nft2 = require("@silvana-one/nft");
|
|
1467
|
+
var import_upgradable = require("@silvana-one/upgradable");
|
|
1468
|
+
var contractList = {
|
|
1469
|
+
FungibleToken: import_token3.FungibleToken,
|
|
1470
|
+
FungibleTokenAdmin: import_token3.FungibleTokenAdmin,
|
|
1471
|
+
AdvancedFungibleToken: import_token3.AdvancedFungibleToken,
|
|
1472
|
+
FungibleTokenAdvancedAdmin: import_token3.FungibleTokenAdvancedAdmin,
|
|
1473
|
+
FungibleTokenBidContract: import_token3.FungibleTokenBidContract,
|
|
1474
|
+
FungibleTokenOfferContract: import_token3.FungibleTokenOfferContract,
|
|
1475
|
+
FungibleTokenClaimContract: import_token3.FungibleTokenClaimContract,
|
|
1476
|
+
NFT: import_nft2.NFT,
|
|
1477
|
+
Collection: import_nft2.Collection,
|
|
1478
|
+
AdvancedCollection: import_nft2.AdvancedCollection,
|
|
1479
|
+
NFTAdmin: import_nft2.NFTAdmin,
|
|
1480
|
+
NFTAdvancedAdmin: import_nft2.NFTAdvancedAdmin,
|
|
1481
|
+
VerificationKeyUpgradeAuthority: import_upgradable.VerificationKeyUpgradeAuthority
|
|
1482
|
+
};
|
|
1106
1483
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1107
1484
|
0 && (module.exports = {
|
|
1108
1485
|
LAUNCH_FEE,
|
|
1109
1486
|
TRANSACTION_FEE,
|
|
1487
|
+
buildNftCollectionLaunchTransaction,
|
|
1488
|
+
buildNftTransaction,
|
|
1110
1489
|
buildTokenLaunchTransaction,
|
|
1111
1490
|
buildTokenTransaction,
|
|
1112
1491
|
checkAddress,
|
|
1492
|
+
contractList,
|
|
1113
1493
|
devnet,
|
|
1114
1494
|
fetchMinaAccount,
|
|
1115
1495
|
getContractInfo,
|
|
1496
|
+
getNftSymbolAndAdmin,
|
|
1116
1497
|
getTokenSymbolAndAdmin,
|
|
1117
1498
|
mainnet,
|
|
1118
1499
|
tokenBalance,
|
|
1119
|
-
tokenContracts,
|
|
1120
1500
|
tokenVerificationKeys
|
|
1121
1501
|
});
|
package/dist/node/index.d.ts
CHANGED
package/dist/node/index.js
CHANGED
package/dist/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
|
package/dist/node/nft/build.js
CHANGED
|
@@ -60,7 +60,7 @@ export async function buildNftCollectionLaunchTransaction(params) {
|
|
|
60
60
|
!vk.NFTAdvancedAdmin.data)
|
|
61
61
|
throw new Error("Cannot get verification key from vk");
|
|
62
62
|
const adminVerificationKey = adminType === "advanced" ? vk.NFTAdvancedAdmin : vk.NFTAdmin;
|
|
63
|
-
const collectionVerificationKey = adminType === "advanced" ? vk.
|
|
63
|
+
const collectionVerificationKey = adminType === "advanced" ? vk.AdvancedCollection : vk.Collection;
|
|
64
64
|
if (!adminVerificationKey || !collectionVerificationKey)
|
|
65
65
|
throw new Error("Cannot get verification keys");
|
|
66
66
|
await fetchMinaAccount({
|
|
@@ -173,6 +173,7 @@ export async function buildNftCollectionLaunchTransaction(params) {
|
|
|
173
173
|
await zkAdmin.deploy({
|
|
174
174
|
admin: sender,
|
|
175
175
|
uri: `NFT Admin`,
|
|
176
|
+
verificationKey: adminVerificationKey,
|
|
176
177
|
});
|
|
177
178
|
// deploy() and initialize() create 2 account updates for the same publicKey, it is intended
|
|
178
179
|
await zkCollection.deploy({
|
|
@@ -182,6 +183,7 @@ export async function buildNftCollectionLaunchTransaction(params) {
|
|
|
182
183
|
admin: adminContractAddress,
|
|
183
184
|
symbol,
|
|
184
185
|
url,
|
|
186
|
+
verificationKey: collectionVerificationKey,
|
|
185
187
|
});
|
|
186
188
|
await zkCollection.initialize(mintParams, collectionData);
|
|
187
189
|
}
|
|
@@ -555,7 +557,7 @@ export async function buildNftTransaction(params) {
|
|
|
555
557
|
? UInt32.from(Math.round(args.nftMintParams.expiry))
|
|
556
558
|
: expiry,
|
|
557
559
|
});
|
|
558
|
-
const accountCreationFee =
|
|
560
|
+
const accountCreationFee = 0;
|
|
559
561
|
const tx = await Mina.transaction({ sender, fee, memo, nonce }, async () => {
|
|
560
562
|
const feeAccountUpdate = AccountUpdate.createSigned(sender);
|
|
561
563
|
if (accountCreationFee > 0) {
|
|
@@ -649,12 +651,12 @@ export async function getNftSymbolAndAdmin(params) {
|
|
|
649
651
|
verificationKeyHashes.push(adminVerificationKey.hash.toJSON());
|
|
650
652
|
}
|
|
651
653
|
let adminType = "unknown";
|
|
652
|
-
if (vk.
|
|
653
|
-
vk.
|
|
654
|
+
if (vk.NFTAdvancedAdmin.hash === adminVerificationKey.hash.toJSON() &&
|
|
655
|
+
vk.NFTAdvancedAdmin.data === adminVerificationKey.data) {
|
|
654
656
|
adminType = "advanced";
|
|
655
657
|
}
|
|
656
|
-
else if (vk.
|
|
657
|
-
vk.
|
|
658
|
+
else if (vk.NFTAdmin.hash === adminVerificationKey.hash.toJSON() &&
|
|
659
|
+
vk.NFTAdmin.data === adminVerificationKey.data) {
|
|
658
660
|
adminType = "standard";
|
|
659
661
|
}
|
|
660
662
|
else {
|