@silvana-one/abi 1.0.6 → 1.0.8

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/src/nft/build.ts CHANGED
@@ -919,62 +919,14 @@ export async function buildNftMintTransaction(params: {
919
919
  if (typeof txType !== "string") throw new Error("Tx type must be a string");
920
920
  const sender = PublicKey.fromBase58(args.sender);
921
921
  const collectionAddress = PublicKey.fromBase58(args.collectionAddress);
922
- if (args.nftMintParams.address === undefined) {
922
+ if (args?.nftMintParams?.address === undefined) {
923
923
  throw new Error("NFT address is required");
924
924
  }
925
+ if (args?.nftMintParams?.data?.owner === undefined) {
926
+ throw new Error("NFT owner is required");
927
+ }
925
928
  const nftAddress = PublicKey.fromBase58(args.nftMintParams.address);
926
929
 
927
- // const offerAddress =
928
- // "offerAddress" in args && args.offerAddress
929
- // ? PublicKey.fromBase58(args.offerAddress)
930
- // : undefined;
931
- // if (
932
- // !offerAddress &&
933
- // (txType === "token:offer:create" ||
934
- // txType === "token:offer:buy" ||
935
- // txType === "token:offer:withdraw")
936
- // )
937
- // throw new Error("Offer address is required");
938
-
939
- // const bidAddress =
940
- // "bidAddress" in args && args.bidAddress
941
- // ? PublicKey.fromBase58(args.bidAddress)
942
- // : undefined;
943
- // if (
944
- // !bidAddress &&
945
- // (txType === "token:bid:create" ||
946
- // txType === "token:bid:sell" ||
947
- // txType === "token:bid:withdraw")
948
- // )
949
- // throw new Error("Bid address is required");
950
-
951
- // const to =
952
- // "to" in args && args.to ? PublicKey.fromBase58(args.to) : undefined;
953
- // if (
954
- // !to &&
955
- // (txType === "token:transfer" ||
956
- // txType === "token:airdrop" ||
957
- // txType === "token:mint")
958
- // )
959
- // throw new Error("To address is required");
960
-
961
- // const from =
962
- // "from" in args && args.from ? PublicKey.fromBase58(args.from) : undefined;
963
- // if (!from && txType === "token:burn")
964
- // throw new Error("From address is required for token:burn");
965
-
966
- // const amount =
967
- // "amount" in args ? UInt64.from(Math.round(args.amount)) : undefined;
968
- // const price =
969
- // "price" in args && args.price
970
- // ? UInt64.from(Math.round(args.price))
971
- // : undefined;
972
- // const slippage = UInt32.from(
973
- // Math.round(
974
- // "slippage" in args && args.slippage !== undefined ? args.slippage : 50
975
- // )
976
- // );
977
-
978
930
  await fetchMinaAccount({
979
931
  publicKey: sender,
980
932
  force: true,
@@ -1012,41 +964,14 @@ export async function buildNftMintTransaction(params: {
1012
964
  ? PublicKey.fromBase58(params.developerAddress)
1013
965
  : undefined;
1014
966
 
1015
- //const adminContract = new FungibleTokenAdmin(adminContractAddress);
1016
967
  const advancedAdminContract = new NFTAdvancedAdmin(adminContractAddress);
1017
968
  const adminContract = new NFTAdmin(adminContractAddress);
1018
969
  const collectionContract =
1019
970
  adminType === "advanced" ? AdvancedCollection : Collection;
1020
971
 
1021
- // if (
1022
- // (txType === "token:admin:whitelist" ||
1023
- // txType === "token:bid:whitelist" ||
1024
- // txType === "token:offer:whitelist") &&
1025
- // !args.whitelist
1026
- // ) {
1027
- // throw new Error("Whitelist is required");
1028
- // }
1029
-
1030
- // const whitelist =
1031
- // "whitelist" in args && args.whitelist
1032
- // ? typeof args.whitelist === "string"
1033
- // ? Whitelist.fromString(args.whitelist)
1034
- // : (await Whitelist.create({ list: args.whitelist, name: symbol }))
1035
- // .whitelist
1036
- // : Whitelist.empty();
1037
-
1038
972
  const zkCollection = new collectionContract(collectionAddress);
1039
973
  const tokenId = zkCollection.deriveTokenId();
1040
974
 
1041
- // if (
1042
- // txType === "nft:mint" &&
1043
- // adminType === "standard" &&
1044
- // adminAddress.toBase58() !== sender.toBase58()
1045
- // )
1046
- // throw new Error(
1047
- // "Invalid sender for FungibleToken mint with standard admin"
1048
- // );
1049
-
1050
975
  await fetchMinaAccount({
1051
976
  publicKey: nftAddress,
1052
977
  tokenId,
@@ -1055,59 +980,6 @@ export async function buildNftMintTransaction(params: {
1055
980
  ).includes(txType),
1056
981
  });
1057
982
 
1058
- // if (to) {
1059
- // await fetchMinaAccount({
1060
- // publicKey: to,
1061
- // tokenId,
1062
- // force: false,
1063
- // });
1064
- // }
1065
-
1066
- // if (from) {
1067
- // await fetchMinaAccount({
1068
- // publicKey: from,
1069
- // tokenId,
1070
- // force: false,
1071
- // });
1072
- // }
1073
-
1074
- // if (offerAddress)
1075
- // await fetchMinaAccount({
1076
- // publicKey: offerAddress,
1077
- // tokenId,
1078
- // force: (
1079
- // [
1080
- // "token:offer:whitelist",
1081
- // "token:offer:buy",
1082
- // "token:offer:withdraw",
1083
- // ] satisfies TokenTransactionType[] as TokenTransactionType[]
1084
- // ).includes(txType),
1085
- // });
1086
- // if (bidAddress)
1087
- // await fetchMinaAccount({
1088
- // publicKey: bidAddress,
1089
- // force: (
1090
- // [
1091
- // "token:bid:whitelist",
1092
- // "token:bid:sell",
1093
- // "token:bid:withdraw",
1094
- // ] satisfies TokenTransactionType[] as TokenTransactionType[]
1095
- // ).includes(txType),
1096
- // });
1097
-
1098
- // const offerContract = offerAddress
1099
- // ? new FungibleTokenOfferContract(offerAddress, tokenId)
1100
- // : undefined;
1101
-
1102
- // const bidContract = bidAddress
1103
- // ? new FungibleTokenBidContract(bidAddress)
1104
- // : undefined;
1105
- // const offerContractDeployment = offerAddress
1106
- // ? new FungibleTokenOfferContract(offerAddress, tokenId)
1107
- // : undefined;
1108
- // const bidContractDeployment = bidAddress
1109
- // ? new FungibleTokenBidContract(bidAddress)
1110
- // : undefined;
1111
983
  const vk =
1112
984
  tokenVerificationKeys[chain === "mainnet" ? "mainnet" : "devnet"].vk;
1113
985
  if (
@@ -1130,133 +1002,6 @@ export async function buildNftMintTransaction(params: {
1130
1002
  )
1131
1003
  throw new Error("Cannot get verification key from vk");
1132
1004
 
1133
- // const offerVerificationKey = FungibleTokenOfferContract._verificationKey ?? {
1134
- // hash: Field(vk.FungibleTokenOfferContract.hash),
1135
- // data: vk.FungibleTokenOfferContract.data,
1136
- // };
1137
- // const bidVerificationKey = FungibleTokenBidContract._verificationKey ?? {
1138
- // hash: Field(vk.FungibleTokenBidContract.hash),
1139
- // data: vk.FungibleTokenBidContract.data,
1140
- // };
1141
-
1142
- // const isNewBidOfferAccount =
1143
- // txType === "token:offer:create" && offerAddress
1144
- // ? !Mina.hasAccount(offerAddress, tokenId)
1145
- // : txType === "token:bid:create" && bidAddress
1146
- // ? !Mina.hasAccount(bidAddress)
1147
- // : false;
1148
-
1149
- // const isNewBuyAccount =
1150
- // txType === "token:offer:buy" ? !Mina.hasAccount(sender, tokenId) : false;
1151
- // let isNewSellAccount: boolean = false;
1152
- // if (txType === "token:bid:sell") {
1153
- // if (!bidAddress || !bidContract) throw new Error("Bid address is required");
1154
- // await fetchMinaAccount({
1155
- // publicKey: bidAddress,
1156
- // force: true,
1157
- // });
1158
- // const buyer = bidContract.buyer.get();
1159
- // await fetchMinaAccount({
1160
- // publicKey: buyer,
1161
- // tokenId,
1162
- // force: false,
1163
- // });
1164
- // isNewSellAccount = !Mina.hasAccount(buyer, tokenId);
1165
- // }
1166
-
1167
- // if (txType === "token:burn") {
1168
- // await fetchMinaAccount({
1169
- // publicKey: sender,
1170
- // force: true,
1171
- // });
1172
- // await fetchMinaAccount({
1173
- // publicKey: sender,
1174
- // tokenId,
1175
- // force: false,
1176
- // });
1177
- // if (!Mina.hasAccount(sender, tokenId))
1178
- // throw new Error("Sender does not have tokens to burn");
1179
- // }
1180
-
1181
- // const isNewTransferMintAccount =
1182
- // (txType === "token:transfer" ||
1183
- // txType === "token:airdrop" ||
1184
- // txType === "token:mint") &&
1185
- // to
1186
- // ? !Mina.hasAccount(to, tokenId)
1187
- // : false;
1188
-
1189
- // const accountCreationFee =
1190
- // (isNewBidOfferAccount ? 1_000_000_000 : 0) +
1191
- // (isNewBuyAccount ? 1_000_000_000 : 0) +
1192
- // (isNewSellAccount ? 1_000_000_000 : 0) +
1193
- // (isNewTransferMintAccount ? 1_000_000_000 : 0) +
1194
- // (isToNewAccount &&
1195
- // txType === "token:mint" &&
1196
- // adminType === "advanced" &&
1197
- // advancedAdminContract.whitelist.get().isSome().toBoolean()
1198
- // ? 1_000_000_000
1199
- // : 0);
1200
- // console.log("accountCreationFee", accountCreationFee / 1_000_000_000);
1201
-
1202
- // switch (txType) {
1203
- // case "token:offer:buy":
1204
- // case "token:offer:withdraw":
1205
- // case "token:offer:whitelist":
1206
- // if (offerContract === undefined)
1207
- // throw new Error("Offer contract is required");
1208
- // if (
1209
- // Mina.getAccount(
1210
- // offerContract.address,
1211
- // tokenId
1212
- // ).zkapp?.verificationKey?.hash.toJSON() !==
1213
- // vk.FungibleTokenOfferContract.hash
1214
- // )
1215
- // throw new Error(
1216
- // "Invalid offer verification key, offer contract has to be upgraded"
1217
- // );
1218
- // break;
1219
- // }
1220
- // switch (txType) {
1221
- // case "token:bid:sell":
1222
- // case "token:bid:withdraw":
1223
- // case "token:bid:whitelist":
1224
- // if (bidContract === undefined)
1225
- // throw new Error("Bid contract is required");
1226
- // if (
1227
- // Mina.getAccount(
1228
- // bidContract.address
1229
- // ).zkapp?.verificationKey?.hash.toJSON() !==
1230
- // vk.FungibleTokenBidContract.hash
1231
- // )
1232
- // throw new Error(
1233
- // "Invalid bid verification key, bid contract has to be upgraded"
1234
- // );
1235
- // break;
1236
- // }
1237
-
1238
- // switch (txType) {
1239
- // case "token:mint":
1240
- // case "token:burn":
1241
- // case "token:redeem":
1242
- // case "token:transfer":
1243
- // case "token:airdrop":
1244
- // case "token:offer:create":
1245
- // case "token:bid:create":
1246
- // case "token:offer:buy":
1247
- // case "token:offer:withdraw":
1248
- // case "token:bid:sell":
1249
- // if (
1250
- // Mina.getAccount(
1251
- // zkToken.address
1252
- // ).zkapp?.verificationKey?.hash.toJSON() !== vk.FungibleToken.hash
1253
- // )
1254
- // throw new Error(
1255
- // "Invalid token verification key, token contract has to be upgraded"
1256
- // );
1257
- // break;
1258
- // }
1259
-
1260
1005
  const { name, ipfsHash, metadataRoot, privateMetadata, serializedMap } =
1261
1006
  typeof args.nftMintParams.metadata === "string"
1262
1007
  ? {
@@ -1284,7 +1029,11 @@ export async function buildNftMintTransaction(params: {
1284
1029
  UInt32.from(chain === "mainnet" || chain === "devnet" ? 20 : 100000)
1285
1030
  );
1286
1031
 
1287
- const nftData = NFTData.new(args.nftMintParams.data);
1032
+ const nftDataArgs = args.nftMintParams.data;
1033
+ if (nftDataArgs.owner === undefined) {
1034
+ throw new Error("NFT owner is required");
1035
+ }
1036
+ const nftData = NFTData.new({ ...nftDataArgs, owner: nftDataArgs.owner });
1288
1037
 
1289
1038
  if (!args.nftMintParams.address) throw new Error("NFT address is required");
1290
1039