emblem-vault-sdk 1.8.2 → 1.9.1

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/bundle.js CHANGED
@@ -711195,7 +711195,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
711195
711195
  Object.defineProperty(exports, "__esModule", { value: true });
711196
711196
  const bignumber_1 = require("@ethersproject/bignumber");
711197
711197
  const utils_1 = require("./utils");
711198
- const SDK_VERSION = '1.8.2';
711198
+ const SDK_VERSION = '1.9.1';
711199
711199
  class EmblemVaultSDK {
711200
711200
  constructor(apiKey, baseUrl) {
711201
711201
  this.apiKey = apiKey;
@@ -711265,6 +711265,7 @@ class EmblemVaultSDK {
711265
711265
  createCuratedVault(template, callback = null) {
711266
711266
  return __awaiter(this, void 0, void 0, function* () {
711267
711267
  (0, utils_1.templateGuard)(template);
711268
+ template.chainId == 1 ? delete template.targetContract[5] : delete template.targetContract[1];
711268
711269
  let url = `${this.baseUrl}/create-curated`;
711269
711270
  if (callback) {
711270
711271
  callback(`creating Vault for user`, template.toAddress);
@@ -711648,8 +711649,21 @@ const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
711648
711649
  const abi_json_1 = __importDefault(require("./abi/abi.json"));
711649
711650
  const derive_1 = require("./derive");
711650
711651
  exports.NFT_DATA = metadata_json_1.default;
711652
+ // PROJECTS_DATA is list of projects i.e. curated collection names
711653
+ // that are present in metadataJson file
711654
+ const PROJECTS_DATA = projectsFromMetadataJson();
711651
711655
  const TORUS_CLIENT_ID = 'BOqGGv-Yx7Dp5RdvD9R3DgSC8jv66gQGwT3w22L7fj3Fg5WQ8AEUjJzyyEwD-qvq5eUQiVipyzOmRZTWBAxaoj0';
711652
711656
  const TORUS_VERIFIER = 'tor-us-signer-vercel';
711657
+ function projectsFromMetadataJson() {
711658
+ let projects = [];
711659
+ for (var key in exports.NFT_DATA) {
711660
+ const projectName = exports.NFT_DATA[key]["projectName"];
711661
+ if (!projects.includes(projectName)) {
711662
+ projects.push();
711663
+ }
711664
+ }
711665
+ return projects;
711666
+ }
711653
711667
  const pad = (num, size) => {
711654
711668
  if (!num)
711655
711669
  return null;
@@ -711834,6 +711848,15 @@ function generateImageTemplate(record) {
711834
711848
  return template;
711835
711849
  }
711836
711850
  exports.generateImageTemplate = generateImageTemplate;
711851
+ /**
711852
+ * generateTemplate defines rules and utilitites for a given curated
711853
+ * collection. This is used by callers, like emblem.finance website
711854
+ * to display vaults belonging to a curated collection with appropriate
711855
+ * data and actions.
711856
+ *
711857
+ * @param record is a curated collection record as defined in
711858
+ * the Emblem database.
711859
+ */
711837
711860
  function generateTemplate(record) {
711838
711861
  let addressChain = record.addressChain;
711839
711862
  let attributes = generateAttributeTemplate(record);
@@ -711842,115 +711865,109 @@ function generateTemplate(record) {
711842
711865
  let balanceQty = record.balanceQty;
711843
711866
  let template = {
711844
711867
  attributes,
711868
+ /**
711869
+ * allowed function is used by callers, like the Emblem website
711870
+ * to determine if a vault belonging to a curated collection
711871
+ * has assets matching that curated collection. A vault can't be
711872
+ * minted until it has at least one qualifying asset.
711873
+ * Currently, we run qualifying checks only on the first asset in the vault.
711874
+ *
711875
+ * @param {Array} data - data is a list of balance Value objects
711876
+ * (see Value's interface definition in emblemvault.io-v3)
711877
+ * @param {function} - msgCallback should be a function that takes a string message
711878
+ */
711845
711879
  allowed: (data, _this, msgCallback = null) => {
711846
711880
  var _a;
711881
+ if (!data || data.length == 0) {
711882
+ return false;
711883
+ }
711847
711884
  let allowed = false;
711885
+ let firstAsset = data[0];
711886
+ let assetName = firstAsset.name ? firstAsset.name : "";
711887
+ let message = null;
711848
711888
  if (recordName == "Cursed Ordinal") {
711849
- allowed = data && data.length > 0 ? data[0].content_type != "application/json" && data[0].coin == "cursedordinalsbtc" : false;
711889
+ if (data && data.length > 0) {
711890
+ let allowedCoin = firstAsset.content_type != "application/json" && firstAsset.coin == "cursedordinalsbtc";
711891
+ let pieces = assetName.split(' ');
711892
+ let allowedName = assetName.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
711893
+ allowed = allowedCoin && allowedName;
711894
+ }
711850
711895
  }
711851
711896
  else if (recordName == "BitcoinOrdinals") {
711852
711897
  data = _this.filterNativeBalances({ balances: data }, _this);
711853
711898
  allowed = data && data.length > 0 && data[0].coin == _this.collectionChain.toLowerCase();
711854
711899
  }
711855
711900
  else if (recordName == "Ethscription") {
711856
- allowed = data && data.length > 0 && data[0].coin == recordName.toLowerCase() ? true : false;
711901
+ allowed = firstAsset.coin == recordName.toLowerCase();
711857
711902
  }
711858
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
711859
- if (data && data.length > 0 && data[0].balance == balanceQty) {
711860
- msgCallback ? msgCallback("") : null;
711861
- allowed = true;
711862
- }
711863
- else if (data && data.length > 0 && data[0].balance != balanceQty && msgCallback) {
711864
- msgCallback ? msgCallback(`Load vault with exactly ${balanceQty} ${recordName}`) : null;
711865
- allowed = false;
711903
+ else if (balanceQty && balanceQty > 0) { // $ORDI, $OXBT
711904
+ allowed = firstAsset.balance == balanceQty && assetName == `${balanceQty} ${recordName}`;
711905
+ if (!allowed) {
711906
+ message = `Load vault with exactly ${balanceQty} ${recordName}`;
711866
711907
  }
711867
711908
  }
711868
711909
  else if (recordName == "Counterparty") {
711869
711910
  let facts = [
711870
- { eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin), msg: `Vaults should only contain assets native to ${recordName}` },
711911
+ {
711912
+ eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin),
711913
+ msg: `Vaults should only contain assets native to ${recordName}`
711914
+ },
711871
711915
  { eval: data.length == 1, msg: `Vaults should only contain a single item` },
711872
711916
  // { eval: data[0].projectName && data[0].projectName == recordName, msg: `Vaults should only contain a single item` }
711873
711917
  ];
711874
711918
  allowed = (0, exports.evaluateFacts)(allowed, facts, msgCallback);
711875
711919
  }
711876
711920
  else if (recordName == "Stamps") {
711877
- allowed = data && data.length > 0 && data[0].project && record.nativeAssets.includes(data[0].coin) && (recordName.toLowerCase() == data[0].project.toLowerCase() || data[0].project.toLowerCase() == "stampunks");
711921
+ let allowedName = assetName.toLowerCase().includes("stamp");
711922
+ allowed = allowedName &&
711923
+ firstAsset.project &&
711924
+ record.nativeAssets.includes(firstAsset.coin) &&
711925
+ (recordName.toLowerCase() == firstAsset.project.toLowerCase() || firstAsset.project.toLowerCase() == "stampunks");
711878
711926
  }
711879
711927
  else if (recordName == "EmblemOpen") {
711880
- allowed = data && data.length > 0 ? true : false;
711928
+ allowed = true;
711881
711929
  }
711882
711930
  else if (recordName == "Bells") {
711883
- allowed = data && data.length > 0 && data[0].name == "Bel" && data[0].balance > 0 && Number.isInteger(data[0].balance);
711931
+ allowed = assetName == "Bel" && firstAsset.balance > 0 && Number.isInteger(data[0].balance);
711884
711932
  }
711885
711933
  else if (recordName == "Namecoin") {
711886
- allowed = data && data.length > 0 && record.nativeAssets.includes(data[0].coin) ? true : false;
711934
+ allowed = record.nativeAssets.includes(data[0].coin);
711887
711935
  }
711888
711936
  else if (recordName == "Embels") {
711889
711937
  allowed = _this.name.toLowerCase() == recordName.toLowerCase();
711890
- if (allowed && data && data.length > 0 && data[0].coin) {
711938
+ if (allowed && firstAsset.coin) {
711891
711939
  allowed = _this.nativeAssets.includes(data[0].coin);
711892
711940
  }
711893
711941
  }
711894
711942
  else if (recordName == "Bitcoin DeGods") {
711895
- allowed = data && data.length > 0 && data[0].coin == "ordinalsbtc" && data[0].balance == 1 && data[0].project == "DeGods";
711943
+ allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods";
711944
+ }
711945
+ else if (PROJECTS_DATA.includes(recordName)) { // XCP
711946
+ allowed = !!exports.NFT_DATA[assetName];
711896
711947
  }
711897
711948
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "protocol") {
711898
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project && data[0].project == recordName;
711949
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project && firstAsset.project == recordName;
711899
711950
  }
711900
711951
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "collection") {
711901
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project == recordName;
711952
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project == recordName;
711902
711953
  }
711903
711954
  else { // XCP
711904
- allowed = data && data.length > 0 && data[0].project == _this.name && data[0].balance == 1;
711955
+ allowed = firstAsset.project == _this.name && firstAsset.balance == 1;
711956
+ }
711957
+ if (message && msgCallback) {
711958
+ msgCallback(message);
711905
711959
  }
711906
711960
  return allowed;
711907
711961
  },
711962
+ /**
711963
+ * allowedName function is deprecated. It used to be called by callers like Emblem website
711964
+ * to determine if an asset with a given name was allowed in a vault.
711965
+ * This functionality is now part of the "allowed" function instead.
711966
+ *
711967
+ * @deprecated
711968
+ */
711908
711969
  allowedName: (asset, msgCallback = null) => {
711909
- let allowedName = false;
711910
- if (recordName == "Cursed Ordinal") {
711911
- let pieces = asset.split(' ');
711912
- allowedName = asset.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
711913
- }
711914
- else if (recordName == "Ethscription") {
711915
- if (asset) {
711916
- allowedName = true;
711917
- }
711918
- }
711919
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
711920
- if (asset == `${balanceQty} ${recordName}`) {
711921
- allowedName = true;
711922
- }
711923
- else {
711924
- msgCallback ? msgCallback("Incorrect Asset Or Qty In Vault") : null;
711925
- allowedName = false;
711926
- }
711927
- }
711928
- else if (recordName == "Counterparty") {
711929
- allowedName = asset ? true : false;
711930
- }
711931
- else if (recordName == "Stamps") {
711932
- allowedName = asset && asset.toLowerCase().includes("stamp") ? true : false;
711933
- }
711934
- else if (recordName == "EmblemOpen") {
711935
- allowedName = asset ? true : false;
711936
- }
711937
- else if (recordName == "Bells") {
711938
- allowedName = asset == "Bel" ? true : false;
711939
- }
711940
- else if (recordName == "Namecoin") {
711941
- allowedName = asset ? true : false;
711942
- }
711943
- else if (recordName == "Embels") {
711944
- allowedName = true;
711945
- }
711946
- else if (recordName == "BitcoinOrdinals" || recordName == "BitcoinPunks" || recordName == "filthyFiat" || recordName == "Megapunks" || recordName == "TwelveFold" || recordName == "Bitcoin DeGods" || recordName == "Bitcoin Frogs" || recordName == "Ordinal Maxi Biz" || recordName == "NodeMonkes" || recordName == "Bitmap" || recordName == "Ordinal Punks" || recordName == "Bitcoin Rocks" || recordName == "OnChainMonkey (OCM) Dimentions") {
711947
- allowedName = true;
711948
- }
711949
- else { // XCP
711950
- let curatedItemFound = exports.NFT_DATA[asset];
711951
- allowedName = asset && curatedItemFound ? true : false;
711952
- }
711953
- return allowedName;
711970
+ return true;
711954
711971
  },
711955
711972
  allowedJump: (ownership_balances, _this) => {
711956
711973
  let hasAnyBalance = ownership_balances && ownership_balances.status != "claimed";
@@ -712092,7 +712109,7 @@ function generateTemplate(record) {
712092
712109
  let template = {
712093
712110
  fromAddress: { type: "user-provided" },
712094
712111
  toAddress: { type: "user-provided" },
712095
- chainId: 1,
712112
+ chainId: { type: "user-provided" },
712096
712113
  experimental: true,
712097
712114
  targetContract: Object.assign(Object.assign({}, _this.contracts), { name: _this.name, description: _this.loadTypes.includes('detailed') ? null : _this.description }),
712098
712115
  targetAsset: {
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const bignumber_1 = require("@ethersproject/bignumber");
36
36
  const utils_1 = require("./utils");
37
- const SDK_VERSION = '1.8.2';
37
+ const SDK_VERSION = '1.9.1';
38
38
  class EmblemVaultSDK {
39
39
  constructor(apiKey, baseUrl) {
40
40
  this.apiKey = apiKey;
@@ -104,6 +104,7 @@ class EmblemVaultSDK {
104
104
  createCuratedVault(template, callback = null) {
105
105
  return __awaiter(this, void 0, void 0, function* () {
106
106
  (0, utils_1.templateGuard)(template);
107
+ template.chainId == 1 ? delete template.targetContract[5] : delete template.targetContract[1];
107
108
  let url = `${this.baseUrl}/create-curated`;
108
109
  if (callback) {
109
110
  callback(`creating Vault for user`, template.toAddress);
package/dist/utils.js CHANGED
@@ -18,8 +18,21 @@ const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
18
18
  const abi_json_1 = __importDefault(require("./abi/abi.json"));
19
19
  const derive_1 = require("./derive");
20
20
  exports.NFT_DATA = metadata_json_1.default;
21
+ // PROJECTS_DATA is list of projects i.e. curated collection names
22
+ // that are present in metadataJson file
23
+ const PROJECTS_DATA = projectsFromMetadataJson();
21
24
  const TORUS_CLIENT_ID = 'BOqGGv-Yx7Dp5RdvD9R3DgSC8jv66gQGwT3w22L7fj3Fg5WQ8AEUjJzyyEwD-qvq5eUQiVipyzOmRZTWBAxaoj0';
22
25
  const TORUS_VERIFIER = 'tor-us-signer-vercel';
26
+ function projectsFromMetadataJson() {
27
+ let projects = [];
28
+ for (var key in exports.NFT_DATA) {
29
+ const projectName = exports.NFT_DATA[key]["projectName"];
30
+ if (!projects.includes(projectName)) {
31
+ projects.push();
32
+ }
33
+ }
34
+ return projects;
35
+ }
23
36
  const pad = (num, size) => {
24
37
  if (!num)
25
38
  return null;
@@ -204,6 +217,15 @@ function generateImageTemplate(record) {
204
217
  return template;
205
218
  }
206
219
  exports.generateImageTemplate = generateImageTemplate;
220
+ /**
221
+ * generateTemplate defines rules and utilitites for a given curated
222
+ * collection. This is used by callers, like emblem.finance website
223
+ * to display vaults belonging to a curated collection with appropriate
224
+ * data and actions.
225
+ *
226
+ * @param record is a curated collection record as defined in
227
+ * the Emblem database.
228
+ */
207
229
  function generateTemplate(record) {
208
230
  let addressChain = record.addressChain;
209
231
  let attributes = generateAttributeTemplate(record);
@@ -212,115 +234,109 @@ function generateTemplate(record) {
212
234
  let balanceQty = record.balanceQty;
213
235
  let template = {
214
236
  attributes,
237
+ /**
238
+ * allowed function is used by callers, like the Emblem website
239
+ * to determine if a vault belonging to a curated collection
240
+ * has assets matching that curated collection. A vault can't be
241
+ * minted until it has at least one qualifying asset.
242
+ * Currently, we run qualifying checks only on the first asset in the vault.
243
+ *
244
+ * @param {Array} data - data is a list of balance Value objects
245
+ * (see Value's interface definition in emblemvault.io-v3)
246
+ * @param {function} - msgCallback should be a function that takes a string message
247
+ */
215
248
  allowed: (data, _this, msgCallback = null) => {
216
249
  var _a;
250
+ if (!data || data.length == 0) {
251
+ return false;
252
+ }
217
253
  let allowed = false;
254
+ let firstAsset = data[0];
255
+ let assetName = firstAsset.name ? firstAsset.name : "";
256
+ let message = null;
218
257
  if (recordName == "Cursed Ordinal") {
219
- allowed = data && data.length > 0 ? data[0].content_type != "application/json" && data[0].coin == "cursedordinalsbtc" : false;
258
+ if (data && data.length > 0) {
259
+ let allowedCoin = firstAsset.content_type != "application/json" && firstAsset.coin == "cursedordinalsbtc";
260
+ let pieces = assetName.split(' ');
261
+ let allowedName = assetName.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
262
+ allowed = allowedCoin && allowedName;
263
+ }
220
264
  }
221
265
  else if (recordName == "BitcoinOrdinals") {
222
266
  data = _this.filterNativeBalances({ balances: data }, _this);
223
267
  allowed = data && data.length > 0 && data[0].coin == _this.collectionChain.toLowerCase();
224
268
  }
225
269
  else if (recordName == "Ethscription") {
226
- allowed = data && data.length > 0 && data[0].coin == recordName.toLowerCase() ? true : false;
270
+ allowed = firstAsset.coin == recordName.toLowerCase();
227
271
  }
228
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
229
- if (data && data.length > 0 && data[0].balance == balanceQty) {
230
- msgCallback ? msgCallback("") : null;
231
- allowed = true;
232
- }
233
- else if (data && data.length > 0 && data[0].balance != balanceQty && msgCallback) {
234
- msgCallback ? msgCallback(`Load vault with exactly ${balanceQty} ${recordName}`) : null;
235
- allowed = false;
272
+ else if (balanceQty && balanceQty > 0) { // $ORDI, $OXBT
273
+ allowed = firstAsset.balance == balanceQty && assetName == `${balanceQty} ${recordName}`;
274
+ if (!allowed) {
275
+ message = `Load vault with exactly ${balanceQty} ${recordName}`;
236
276
  }
237
277
  }
238
278
  else if (recordName == "Counterparty") {
239
279
  let facts = [
240
- { eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin), msg: `Vaults should only contain assets native to ${recordName}` },
280
+ {
281
+ eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin),
282
+ msg: `Vaults should only contain assets native to ${recordName}`
283
+ },
241
284
  { eval: data.length == 1, msg: `Vaults should only contain a single item` },
242
285
  // { eval: data[0].projectName && data[0].projectName == recordName, msg: `Vaults should only contain a single item` }
243
286
  ];
244
287
  allowed = (0, exports.evaluateFacts)(allowed, facts, msgCallback);
245
288
  }
246
289
  else if (recordName == "Stamps") {
247
- allowed = data && data.length > 0 && data[0].project && record.nativeAssets.includes(data[0].coin) && (recordName.toLowerCase() == data[0].project.toLowerCase() || data[0].project.toLowerCase() == "stampunks");
290
+ let allowedName = assetName.toLowerCase().includes("stamp");
291
+ allowed = allowedName &&
292
+ firstAsset.project &&
293
+ record.nativeAssets.includes(firstAsset.coin) &&
294
+ (recordName.toLowerCase() == firstAsset.project.toLowerCase() || firstAsset.project.toLowerCase() == "stampunks");
248
295
  }
249
296
  else if (recordName == "EmblemOpen") {
250
- allowed = data && data.length > 0 ? true : false;
297
+ allowed = true;
251
298
  }
252
299
  else if (recordName == "Bells") {
253
- allowed = data && data.length > 0 && data[0].name == "Bel" && data[0].balance > 0 && Number.isInteger(data[0].balance);
300
+ allowed = assetName == "Bel" && firstAsset.balance > 0 && Number.isInteger(data[0].balance);
254
301
  }
255
302
  else if (recordName == "Namecoin") {
256
- allowed = data && data.length > 0 && record.nativeAssets.includes(data[0].coin) ? true : false;
303
+ allowed = record.nativeAssets.includes(data[0].coin);
257
304
  }
258
305
  else if (recordName == "Embels") {
259
306
  allowed = _this.name.toLowerCase() == recordName.toLowerCase();
260
- if (allowed && data && data.length > 0 && data[0].coin) {
307
+ if (allowed && firstAsset.coin) {
261
308
  allowed = _this.nativeAssets.includes(data[0].coin);
262
309
  }
263
310
  }
264
311
  else if (recordName == "Bitcoin DeGods") {
265
- allowed = data && data.length > 0 && data[0].coin == "ordinalsbtc" && data[0].balance == 1 && data[0].project == "DeGods";
312
+ allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods";
313
+ }
314
+ else if (PROJECTS_DATA.includes(recordName)) { // XCP
315
+ allowed = !!exports.NFT_DATA[assetName];
266
316
  }
267
317
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "protocol") {
268
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project && data[0].project == recordName;
318
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project && firstAsset.project == recordName;
269
319
  }
270
320
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "collection") {
271
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project == recordName;
321
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project == recordName;
272
322
  }
273
323
  else { // XCP
274
- allowed = data && data.length > 0 && data[0].project == _this.name && data[0].balance == 1;
324
+ allowed = firstAsset.project == _this.name && firstAsset.balance == 1;
325
+ }
326
+ if (message && msgCallback) {
327
+ msgCallback(message);
275
328
  }
276
329
  return allowed;
277
330
  },
331
+ /**
332
+ * allowedName function is deprecated. It used to be called by callers like Emblem website
333
+ * to determine if an asset with a given name was allowed in a vault.
334
+ * This functionality is now part of the "allowed" function instead.
335
+ *
336
+ * @deprecated
337
+ */
278
338
  allowedName: (asset, msgCallback = null) => {
279
- let allowedName = false;
280
- if (recordName == "Cursed Ordinal") {
281
- let pieces = asset.split(' ');
282
- allowedName = asset.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
283
- }
284
- else if (recordName == "Ethscription") {
285
- if (asset) {
286
- allowedName = true;
287
- }
288
- }
289
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
290
- if (asset == `${balanceQty} ${recordName}`) {
291
- allowedName = true;
292
- }
293
- else {
294
- msgCallback ? msgCallback("Incorrect Asset Or Qty In Vault") : null;
295
- allowedName = false;
296
- }
297
- }
298
- else if (recordName == "Counterparty") {
299
- allowedName = asset ? true : false;
300
- }
301
- else if (recordName == "Stamps") {
302
- allowedName = asset && asset.toLowerCase().includes("stamp") ? true : false;
303
- }
304
- else if (recordName == "EmblemOpen") {
305
- allowedName = asset ? true : false;
306
- }
307
- else if (recordName == "Bells") {
308
- allowedName = asset == "Bel" ? true : false;
309
- }
310
- else if (recordName == "Namecoin") {
311
- allowedName = asset ? true : false;
312
- }
313
- else if (recordName == "Embels") {
314
- allowedName = true;
315
- }
316
- else if (recordName == "BitcoinOrdinals" || recordName == "BitcoinPunks" || recordName == "filthyFiat" || recordName == "Megapunks" || recordName == "TwelveFold" || recordName == "Bitcoin DeGods" || recordName == "Bitcoin Frogs" || recordName == "Ordinal Maxi Biz" || recordName == "NodeMonkes" || recordName == "Bitmap" || recordName == "Ordinal Punks" || recordName == "Bitcoin Rocks" || recordName == "OnChainMonkey (OCM) Dimentions") {
317
- allowedName = true;
318
- }
319
- else { // XCP
320
- let curatedItemFound = exports.NFT_DATA[asset];
321
- allowedName = asset && curatedItemFound ? true : false;
322
- }
323
- return allowedName;
339
+ return true;
324
340
  },
325
341
  allowedJump: (ownership_balances, _this) => {
326
342
  let hasAnyBalance = ownership_balances && ownership_balances.status != "claimed";
@@ -462,7 +478,7 @@ function generateTemplate(record) {
462
478
  let template = {
463
479
  fromAddress: { type: "user-provided" },
464
480
  toAddress: { type: "user-provided" },
465
- chainId: 1,
481
+ chainId: { type: "user-provided" },
466
482
  experimental: true,
467
483
  targetContract: Object.assign(Object.assign({}, _this.contracts), { name: _this.name, description: _this.loadTypes.includes('detailed') ? null : _this.description }),
468
484
  targetAsset: {
package/docs/DeGods.html CHANGED
@@ -27,6 +27,7 @@
27
27
  "experimental":true,
28
28
  "targetContract":{
29
29
  "1":"0x345eF9d7E75aEEb979053AA41BB6330683353B7b",
30
+ "5":"0x582699d2c58A38056Cf02875540705137f0bbbF7",
30
31
  "name":"Bitcoin DeGods",
31
32
  "description":"Bitcoin DeGods is a collection of 535 Bitcoin Ordinals inscribed in the 77236 to 77770 range. This collection is curated by Emblem Vault. "
32
33
  },
@@ -50,10 +51,11 @@
50
51
  defaultAccount = await web3.eth.getAccounts().then(accounts => accounts[0]).catch(err=>console) // Minter's address
51
52
  }
52
53
  if (!vaultData) {
54
+ let chainId = Number(await web3.eth.net.getId())
53
55
  // populate the template
54
56
  contractTemplate.toAddress = defaultAccount;
55
57
  contractTemplate.fromAddress = defaultAccount;
56
-
58
+ contractTemplate.chainId = chainId;
57
59
  // Create a vault
58
60
  vaultData = await sdk.createCuratedVault(contractTemplate, updateLogCallback).catch(err=>console.log(err));
59
61
  if (!vaultData || vaultData.err) { // Temporary fix while I fix a race condition
package/docs/bundle.js CHANGED
@@ -711195,7 +711195,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
711195
711195
  Object.defineProperty(exports, "__esModule", { value: true });
711196
711196
  const bignumber_1 = require("@ethersproject/bignumber");
711197
711197
  const utils_1 = require("./utils");
711198
- const SDK_VERSION = '1.8.2';
711198
+ const SDK_VERSION = '1.9.1';
711199
711199
  class EmblemVaultSDK {
711200
711200
  constructor(apiKey, baseUrl) {
711201
711201
  this.apiKey = apiKey;
@@ -711265,6 +711265,7 @@ class EmblemVaultSDK {
711265
711265
  createCuratedVault(template, callback = null) {
711266
711266
  return __awaiter(this, void 0, void 0, function* () {
711267
711267
  (0, utils_1.templateGuard)(template);
711268
+ template.chainId == 1 ? delete template.targetContract[5] : delete template.targetContract[1];
711268
711269
  let url = `${this.baseUrl}/create-curated`;
711269
711270
  if (callback) {
711270
711271
  callback(`creating Vault for user`, template.toAddress);
@@ -711648,8 +711649,21 @@ const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
711648
711649
  const abi_json_1 = __importDefault(require("./abi/abi.json"));
711649
711650
  const derive_1 = require("./derive");
711650
711651
  exports.NFT_DATA = metadata_json_1.default;
711652
+ // PROJECTS_DATA is list of projects i.e. curated collection names
711653
+ // that are present in metadataJson file
711654
+ const PROJECTS_DATA = projectsFromMetadataJson();
711651
711655
  const TORUS_CLIENT_ID = 'BOqGGv-Yx7Dp5RdvD9R3DgSC8jv66gQGwT3w22L7fj3Fg5WQ8AEUjJzyyEwD-qvq5eUQiVipyzOmRZTWBAxaoj0';
711652
711656
  const TORUS_VERIFIER = 'tor-us-signer-vercel';
711657
+ function projectsFromMetadataJson() {
711658
+ let projects = [];
711659
+ for (var key in exports.NFT_DATA) {
711660
+ const projectName = exports.NFT_DATA[key]["projectName"];
711661
+ if (!projects.includes(projectName)) {
711662
+ projects.push();
711663
+ }
711664
+ }
711665
+ return projects;
711666
+ }
711653
711667
  const pad = (num, size) => {
711654
711668
  if (!num)
711655
711669
  return null;
@@ -711834,6 +711848,15 @@ function generateImageTemplate(record) {
711834
711848
  return template;
711835
711849
  }
711836
711850
  exports.generateImageTemplate = generateImageTemplate;
711851
+ /**
711852
+ * generateTemplate defines rules and utilitites for a given curated
711853
+ * collection. This is used by callers, like emblem.finance website
711854
+ * to display vaults belonging to a curated collection with appropriate
711855
+ * data and actions.
711856
+ *
711857
+ * @param record is a curated collection record as defined in
711858
+ * the Emblem database.
711859
+ */
711837
711860
  function generateTemplate(record) {
711838
711861
  let addressChain = record.addressChain;
711839
711862
  let attributes = generateAttributeTemplate(record);
@@ -711842,115 +711865,109 @@ function generateTemplate(record) {
711842
711865
  let balanceQty = record.balanceQty;
711843
711866
  let template = {
711844
711867
  attributes,
711868
+ /**
711869
+ * allowed function is used by callers, like the Emblem website
711870
+ * to determine if a vault belonging to a curated collection
711871
+ * has assets matching that curated collection. A vault can't be
711872
+ * minted until it has at least one qualifying asset.
711873
+ * Currently, we run qualifying checks only on the first asset in the vault.
711874
+ *
711875
+ * @param {Array} data - data is a list of balance Value objects
711876
+ * (see Value's interface definition in emblemvault.io-v3)
711877
+ * @param {function} - msgCallback should be a function that takes a string message
711878
+ */
711845
711879
  allowed: (data, _this, msgCallback = null) => {
711846
711880
  var _a;
711881
+ if (!data || data.length == 0) {
711882
+ return false;
711883
+ }
711847
711884
  let allowed = false;
711885
+ let firstAsset = data[0];
711886
+ let assetName = firstAsset.name ? firstAsset.name : "";
711887
+ let message = null;
711848
711888
  if (recordName == "Cursed Ordinal") {
711849
- allowed = data && data.length > 0 ? data[0].content_type != "application/json" && data[0].coin == "cursedordinalsbtc" : false;
711889
+ if (data && data.length > 0) {
711890
+ let allowedCoin = firstAsset.content_type != "application/json" && firstAsset.coin == "cursedordinalsbtc";
711891
+ let pieces = assetName.split(' ');
711892
+ let allowedName = assetName.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
711893
+ allowed = allowedCoin && allowedName;
711894
+ }
711850
711895
  }
711851
711896
  else if (recordName == "BitcoinOrdinals") {
711852
711897
  data = _this.filterNativeBalances({ balances: data }, _this);
711853
711898
  allowed = data && data.length > 0 && data[0].coin == _this.collectionChain.toLowerCase();
711854
711899
  }
711855
711900
  else if (recordName == "Ethscription") {
711856
- allowed = data && data.length > 0 && data[0].coin == recordName.toLowerCase() ? true : false;
711901
+ allowed = firstAsset.coin == recordName.toLowerCase();
711857
711902
  }
711858
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
711859
- if (data && data.length > 0 && data[0].balance == balanceQty) {
711860
- msgCallback ? msgCallback("") : null;
711861
- allowed = true;
711862
- }
711863
- else if (data && data.length > 0 && data[0].balance != balanceQty && msgCallback) {
711864
- msgCallback ? msgCallback(`Load vault with exactly ${balanceQty} ${recordName}`) : null;
711865
- allowed = false;
711903
+ else if (balanceQty && balanceQty > 0) { // $ORDI, $OXBT
711904
+ allowed = firstAsset.balance == balanceQty && assetName == `${balanceQty} ${recordName}`;
711905
+ if (!allowed) {
711906
+ message = `Load vault with exactly ${balanceQty} ${recordName}`;
711866
711907
  }
711867
711908
  }
711868
711909
  else if (recordName == "Counterparty") {
711869
711910
  let facts = [
711870
- { eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin), msg: `Vaults should only contain assets native to ${recordName}` },
711911
+ {
711912
+ eval: record.nativeAssets.includes((_a = data[0]) === null || _a === void 0 ? void 0 : _a.coin),
711913
+ msg: `Vaults should only contain assets native to ${recordName}`
711914
+ },
711871
711915
  { eval: data.length == 1, msg: `Vaults should only contain a single item` },
711872
711916
  // { eval: data[0].projectName && data[0].projectName == recordName, msg: `Vaults should only contain a single item` }
711873
711917
  ];
711874
711918
  allowed = (0, exports.evaluateFacts)(allowed, facts, msgCallback);
711875
711919
  }
711876
711920
  else if (recordName == "Stamps") {
711877
- allowed = data && data.length > 0 && data[0].project && record.nativeAssets.includes(data[0].coin) && (recordName.toLowerCase() == data[0].project.toLowerCase() || data[0].project.toLowerCase() == "stampunks");
711921
+ let allowedName = assetName.toLowerCase().includes("stamp");
711922
+ allowed = allowedName &&
711923
+ firstAsset.project &&
711924
+ record.nativeAssets.includes(firstAsset.coin) &&
711925
+ (recordName.toLowerCase() == firstAsset.project.toLowerCase() || firstAsset.project.toLowerCase() == "stampunks");
711878
711926
  }
711879
711927
  else if (recordName == "EmblemOpen") {
711880
- allowed = data && data.length > 0 ? true : false;
711928
+ allowed = true;
711881
711929
  }
711882
711930
  else if (recordName == "Bells") {
711883
- allowed = data && data.length > 0 && data[0].name == "Bel" && data[0].balance > 0 && Number.isInteger(data[0].balance);
711931
+ allowed = assetName == "Bel" && firstAsset.balance > 0 && Number.isInteger(data[0].balance);
711884
711932
  }
711885
711933
  else if (recordName == "Namecoin") {
711886
- allowed = data && data.length > 0 && record.nativeAssets.includes(data[0].coin) ? true : false;
711934
+ allowed = record.nativeAssets.includes(data[0].coin);
711887
711935
  }
711888
711936
  else if (recordName == "Embels") {
711889
711937
  allowed = _this.name.toLowerCase() == recordName.toLowerCase();
711890
- if (allowed && data && data.length > 0 && data[0].coin) {
711938
+ if (allowed && firstAsset.coin) {
711891
711939
  allowed = _this.nativeAssets.includes(data[0].coin);
711892
711940
  }
711893
711941
  }
711894
711942
  else if (recordName == "Bitcoin DeGods") {
711895
- allowed = data && data.length > 0 && data[0].coin == "ordinalsbtc" && data[0].balance == 1 && data[0].project == "DeGods";
711943
+ allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods";
711944
+ }
711945
+ else if (PROJECTS_DATA.includes(recordName)) { // XCP
711946
+ allowed = !!exports.NFT_DATA[assetName];
711896
711947
  }
711897
711948
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "protocol") {
711898
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project && data[0].project == recordName;
711949
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project && firstAsset.project == recordName;
711899
711950
  }
711900
711951
  else if (_this.vaultCollectionType && _this.vaultCollectionType == "collection") {
711901
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project == recordName;
711952
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project == recordName;
711902
711953
  }
711903
711954
  else { // XCP
711904
- allowed = data && data.length > 0 && data[0].project == _this.name && data[0].balance == 1;
711955
+ allowed = firstAsset.project == _this.name && firstAsset.balance == 1;
711956
+ }
711957
+ if (message && msgCallback) {
711958
+ msgCallback(message);
711905
711959
  }
711906
711960
  return allowed;
711907
711961
  },
711962
+ /**
711963
+ * allowedName function is deprecated. It used to be called by callers like Emblem website
711964
+ * to determine if an asset with a given name was allowed in a vault.
711965
+ * This functionality is now part of the "allowed" function instead.
711966
+ *
711967
+ * @deprecated
711968
+ */
711908
711969
  allowedName: (asset, msgCallback = null) => {
711909
- let allowedName = false;
711910
- if (recordName == "Cursed Ordinal") {
711911
- let pieces = asset.split(' ');
711912
- allowedName = asset.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0;
711913
- }
711914
- else if (recordName == "Ethscription") {
711915
- if (asset) {
711916
- allowedName = true;
711917
- }
711918
- }
711919
- else if (recordName == "$OXBT" || recordName == "$ORDI") {
711920
- if (asset == `${balanceQty} ${recordName}`) {
711921
- allowedName = true;
711922
- }
711923
- else {
711924
- msgCallback ? msgCallback("Incorrect Asset Or Qty In Vault") : null;
711925
- allowedName = false;
711926
- }
711927
- }
711928
- else if (recordName == "Counterparty") {
711929
- allowedName = asset ? true : false;
711930
- }
711931
- else if (recordName == "Stamps") {
711932
- allowedName = asset && asset.toLowerCase().includes("stamp") ? true : false;
711933
- }
711934
- else if (recordName == "EmblemOpen") {
711935
- allowedName = asset ? true : false;
711936
- }
711937
- else if (recordName == "Bells") {
711938
- allowedName = asset == "Bel" ? true : false;
711939
- }
711940
- else if (recordName == "Namecoin") {
711941
- allowedName = asset ? true : false;
711942
- }
711943
- else if (recordName == "Embels") {
711944
- allowedName = true;
711945
- }
711946
- else if (recordName == "BitcoinOrdinals" || recordName == "BitcoinPunks" || recordName == "filthyFiat" || recordName == "Megapunks" || recordName == "TwelveFold" || recordName == "Bitcoin DeGods" || recordName == "Bitcoin Frogs" || recordName == "Ordinal Maxi Biz" || recordName == "NodeMonkes" || recordName == "Bitmap" || recordName == "Ordinal Punks" || recordName == "Bitcoin Rocks" || recordName == "OnChainMonkey (OCM) Dimentions") {
711947
- allowedName = true;
711948
- }
711949
- else { // XCP
711950
- let curatedItemFound = exports.NFT_DATA[asset];
711951
- allowedName = asset && curatedItemFound ? true : false;
711952
- }
711953
- return allowedName;
711970
+ return true;
711954
711971
  },
711955
711972
  allowedJump: (ownership_balances, _this) => {
711956
711973
  let hasAnyBalance = ownership_balances && ownership_balances.status != "claimed";
@@ -712092,7 +712109,7 @@ function generateTemplate(record) {
712092
712109
  let template = {
712093
712110
  fromAddress: { type: "user-provided" },
712094
712111
  toAddress: { type: "user-provided" },
712095
- chainId: 1,
712112
+ chainId: { type: "user-provided" },
712096
712113
  experimental: true,
712097
712114
  targetContract: Object.assign(Object.assign({}, _this.contracts), { name: _this.name, description: _this.loadTypes.includes('detailed') ? null : _this.description }),
712098
712115
  targetAsset: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emblem-vault-sdk",
3
- "version": "1.8.2",
3
+ "version": "1.9.1",
4
4
  "description": "Emblem Vault Software Development Kit",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -78,6 +78,7 @@ class EmblemVaultSDK {
78
78
 
79
79
  async createCuratedVault(template: any, callback: any = null): Promise<Vault> {
80
80
  templateGuard(template);
81
+ template.chainId == 1? delete template.targetContract[5]: delete template.targetContract[1]
81
82
  let url = `${this.baseUrl}/create-curated`;
82
83
  if (callback) { callback(`creating Vault for user`, template.toAddress)}
83
84
  let vaultCreationResponse = await fetchData(url, this.apiKey, 'POST', template);
package/src/utils.ts CHANGED
@@ -3,9 +3,26 @@ import { MetaData } from "./types";
3
3
  import metadataJson from './curated/metadata.json';
4
4
  import abi from './abi/abi.json';
5
5
  import { phrasePathToKey } from './derive'
6
+
6
7
  export const NFT_DATA: any = metadataJson
8
+ // PROJECTS_DATA is list of projects i.e. curated collection names
9
+ // that are present in metadataJson file
10
+ const PROJECTS_DATA = projectsFromMetadataJson()
7
11
  const TORUS_CLIENT_ID = 'BOqGGv-Yx7Dp5RdvD9R3DgSC8jv66gQGwT3w22L7fj3Fg5WQ8AEUjJzyyEwD-qvq5eUQiVipyzOmRZTWBAxaoj0'
8
12
  const TORUS_VERIFIER = 'tor-us-signer-vercel'
13
+
14
+ function projectsFromMetadataJson() {
15
+ let projects:any[] = []
16
+ for (var key in NFT_DATA) {
17
+ const projectName = NFT_DATA[key]["projectName"]
18
+ if (!projects.includes(projectName)) {
19
+ projects.push()
20
+ }
21
+ }
22
+ return projects
23
+ }
24
+
25
+
9
26
  export const pad = (num: string | any[], size: number) => {
10
27
  if (!num) return null;
11
28
  num = num.toString();
@@ -186,6 +203,15 @@ export function generateImageTemplate(record: any) {
186
203
  return template
187
204
  }
188
205
 
206
+ /**
207
+ * generateTemplate defines rules and utilitites for a given curated
208
+ * collection. This is used by callers, like emblem.finance website
209
+ * to display vaults belonging to a curated collection with appropriate
210
+ * data and actions.
211
+ *
212
+ * @param record is a curated collection record as defined in
213
+ * the Emblem database.
214
+ */
189
215
  export function generateTemplate(record: any) {
190
216
  let addressChain = record.addressChain
191
217
  let attributes = generateAttributeTemplate(record)
@@ -194,90 +220,97 @@ export function generateTemplate(record: any) {
194
220
  let balanceQty = record.balanceQty
195
221
  let template: any = {
196
222
  attributes,
223
+ /**
224
+ * allowed function is used by callers, like the Emblem website
225
+ * to determine if a vault belonging to a curated collection
226
+ * has assets matching that curated collection. A vault can't be
227
+ * minted until it has at least one qualifying asset.
228
+ * Currently, we run qualifying checks only on the first asset in the vault.
229
+ *
230
+ * @param {Array} data - data is a list of balance Value objects
231
+ * (see Value's interface definition in emblemvault.io-v3)
232
+ * @param {function} - msgCallback should be a function that takes a string message
233
+ */
197
234
  allowed: (data: any[], _this: any, msgCallback: any = null) => {
235
+ if (!data || data.length == 0) {
236
+ return false
237
+ }
238
+
198
239
  let allowed = false
240
+ let firstAsset = data[0]
241
+ let assetName = firstAsset.name ? firstAsset.name : ""
242
+ let message = null
243
+
199
244
  if (recordName == "Cursed Ordinal") {
200
- allowed = data && data.length > 0 ? data[0].content_type != "application/json" && data[0].coin == "cursedordinalsbtc" : false
245
+ if (data && data.length > 0) {
246
+ let allowedCoin = firstAsset.content_type != "application/json" && firstAsset.coin == "cursedordinalsbtc"
247
+ let pieces = assetName.split(' ')
248
+ let allowedName = assetName.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0
249
+ allowed = allowedCoin && allowedName
250
+ }
201
251
  } else if (recordName == "BitcoinOrdinals") {
202
252
  data = _this.filterNativeBalances({balances: data}, _this)
203
253
  allowed = data && data.length > 0 && data[0].coin == _this.collectionChain.toLowerCase()
204
254
  } else if (recordName == "Ethscription") {
205
- allowed = data && data.length > 0 && data[0].coin == recordName.toLowerCase()? true : false
206
- } else if (recordName == "$OXBT" || recordName == "$ORDI") {
207
- if (data && data.length > 0 && data[0].balance == balanceQty) {
208
- msgCallback ? msgCallback("") : null
209
- allowed = true
210
- } else if (data && data.length > 0 && data[0].balance != balanceQty && msgCallback) {
211
- msgCallback ? msgCallback(`Load vault with exactly ${balanceQty} ${recordName}`) : null
212
- allowed = false
255
+ allowed = firstAsset.coin == recordName.toLowerCase()
256
+ } else if (balanceQty && balanceQty > 0) { // $ORDI, $OXBT
257
+ allowed = firstAsset.balance == balanceQty && assetName == `${balanceQty} ${recordName}`
258
+ if (!allowed) {
259
+ message = `Load vault with exactly ${balanceQty} ${recordName}`
213
260
  }
214
261
  } else if (recordName == "Counterparty") {
215
262
  let facts = [
216
- { eval: record.nativeAssets.includes(data[0]?.coin), msg: `Vaults should only contain assets native to ${recordName}` },
217
- { eval: data.length == 1, msg: `Vaults should only contain a single item` },
263
+ {
264
+ eval: record.nativeAssets.includes(data[0]?.coin),
265
+ msg: `Vaults should only contain assets native to ${recordName}`
266
+ },
267
+ {eval: data.length == 1, msg: `Vaults should only contain a single item`},
218
268
  // { eval: data[0].projectName && data[0].projectName == recordName, msg: `Vaults should only contain a single item` }
219
269
  ]
220
270
  allowed = evaluateFacts(allowed, facts, msgCallback)
221
271
  } else if (recordName == "Stamps") {
222
- allowed = data && data.length > 0 && data[0].project && record.nativeAssets.includes(data[0].coin) && (recordName.toLowerCase() == data[0].project.toLowerCase() || data[0].project.toLowerCase() == "stampunks")
272
+ let allowedName = assetName.toLowerCase().includes("stamp")
273
+ allowed = allowedName &&
274
+ firstAsset.project &&
275
+ record.nativeAssets.includes(firstAsset.coin) &&
276
+ (recordName.toLowerCase() == firstAsset.project.toLowerCase() || firstAsset.project.toLowerCase() == "stampunks")
223
277
  } else if (recordName == "EmblemOpen") {
224
- allowed = data && data.length > 0 ? true : false
278
+ allowed = true
225
279
  } else if (recordName == "Bells") {
226
- allowed = data && data.length > 0 && data[0].name == "Bel" && data[0].balance > 0 && Number.isInteger(data[0].balance)
280
+ allowed = assetName == "Bel" && firstAsset.balance > 0 && Number.isInteger(data[0].balance)
227
281
  } else if (recordName == "Namecoin") {
228
- allowed = data && data.length > 0 && record.nativeAssets.includes(data[0].coin) ? true: false
282
+ allowed = record.nativeAssets.includes(data[0].coin)
229
283
  } else if (recordName == "Embels") {
230
284
  allowed = _this.name.toLowerCase() == recordName.toLowerCase()
231
- if (allowed && data && data.length > 0 && data[0].coin) {
285
+ if (allowed && firstAsset.coin) {
232
286
  allowed = _this.nativeAssets.includes(data[0].coin)
233
287
  }
234
- } else if (recordName == "Bitcoin DeGods"){
235
- allowed = data && data.length > 0 && data[0].coin == "ordinalsbtc" && data[0].balance == 1 && data[0].project == "DeGods"
236
- } else if (_this.vaultCollectionType && _this.vaultCollectionType == "protocol") {
237
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project && data[0].project == recordName
238
- } else if (_this.vaultCollectionType && _this.vaultCollectionType == "collection" ) {
239
- allowed = data && data.length > 0 && data[0].coin.toLowerCase() == _this.collectionChain.toLowerCase() && data[0].project == recordName
288
+ } else if (recordName == "Bitcoin DeGods") {
289
+ allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods"
290
+ } else if (PROJECTS_DATA.includes(recordName)) { // XCP
291
+ allowed = !!NFT_DATA[assetName];
292
+ } else if (_this.vaultCollectionType && _this.vaultCollectionType == "protocol") {
293
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project && firstAsset.project == recordName
294
+ } else if (_this.vaultCollectionType && _this.vaultCollectionType == "collection") {
295
+ allowed = firstAsset.coin.toLowerCase() == _this.collectionChain.toLowerCase() && firstAsset.project == recordName
240
296
  } else { // XCP
241
- allowed = data && data.length > 0 && data[0].project == _this.name && data[0].balance == 1;
297
+ allowed = firstAsset.project == _this.name && firstAsset.balance == 1;
298
+ }
299
+
300
+ if (message && msgCallback) {
301
+ msgCallback(message)
242
302
  }
243
303
  return allowed
244
304
  },
305
+ /**
306
+ * allowedName function is deprecated. It used to be called by callers like Emblem website
307
+ * to determine if an asset with a given name was allowed in a vault.
308
+ * This functionality is now part of the "allowed" function instead.
309
+ *
310
+ * @deprecated
311
+ */
245
312
  allowedName: (asset: any, msgCallback: any = null) => {
246
- let allowedName = false
247
- if (recordName == "Cursed Ordinal") {
248
- let pieces = asset.split(' ')
249
- allowedName = asset.includes(recordName) && pieces.length === 3 && Number(pieces.reverse()[0]) < 0
250
- } else if (recordName == "Ethscription") {
251
- if (asset) {
252
- allowedName = true
253
- }
254
- } else if (recordName == "$OXBT" || recordName == "$ORDI") {
255
- if (asset == `${balanceQty} ${recordName}`) {
256
- allowedName = true
257
- } else {
258
- msgCallback ? msgCallback("Incorrect Asset Or Qty In Vault") : null
259
- allowedName = false
260
- }
261
- } else if (recordName == "Counterparty") {
262
- allowedName = asset ? true : false
263
- } else if (recordName == "Stamps") {
264
- allowedName = asset && asset.toLowerCase().includes("stamp") ? true : false
265
- } else if (recordName == "EmblemOpen") {
266
- allowedName = asset ? true : false
267
- } else if (recordName == "Bells") {
268
- allowedName = asset == "Bel" ? true : false
269
- } else if (recordName == "Namecoin") {
270
- allowedName = asset? true: false
271
- } else if (recordName == "Embels"){
272
- allowedName = true
273
- } else if (recordName == "BitcoinOrdinals" || recordName == "BitcoinPunks" || recordName == "filthyFiat" || recordName == "Megapunks" || recordName == "TwelveFold" || recordName == "Bitcoin DeGods" || recordName == "Bitcoin Frogs" || recordName == "Ordinal Maxi Biz" || recordName == "NodeMonkes" || recordName == "Bitmap" || recordName == "Ordinal Punks" || recordName == "Bitcoin Rocks" || recordName == "OnChainMonkey (OCM) Dimentions") {
274
- allowedName = true
275
- } else { // XCP
276
- let curatedItemFound = NFT_DATA[asset];
277
- allowedName = asset && curatedItemFound ? true : false;
278
- }
279
-
280
- return allowedName
313
+ return true
281
314
  },
282
315
  allowedJump: (ownership_balances: any, _this: any): boolean => {
283
316
  let hasAnyBalance = ownership_balances && ownership_balances.status != "claimed"
@@ -422,7 +455,7 @@ export function generateTemplate(record: any) {
422
455
  let template: any = {
423
456
  fromAddress: { type: "user-provided" },
424
457
  toAddress: { type: "user-provided" },
425
- chainId: 1,
458
+ chainId: { type: "user-provided" },
426
459
  experimental: true,
427
460
  targetContract: {
428
461
  ..._this.contracts,
@@ -93,7 +93,7 @@ const mocks = {
93
93
  emblemopen_create_template: {
94
94
  "fromAddress": { "type": "user-provided" },
95
95
  "toAddress": { "type": "user-provided" },
96
- "chainId": 1,
96
+ "chainId": { "type": "user-provided" },
97
97
  "experimental": true,
98
98
  "targetContract": {
99
99
  "1": "0x184ddb67E2EF517f6754F055b56905f2A9b29b6A",
@@ -109,7 +109,8 @@ const mocks = {
109
109
  empty_create_template: {
110
110
  "fromAddress": { "type": "user-provided" },
111
111
  "toAddress": { "type": "user-provided" },
112
- "chainId": 1, "experimental": true,
112
+ "chainId": { "type": "user-provided" },
113
+ "experimental": true,
113
114
  "targetContract": {
114
115
  "1": "0xEAD67175CDb9CBDeA5bDDC36015e52f4A954E3fD",
115
116
  "name": "BitcoinOrdinals",
package/types/utils.d.ts CHANGED
@@ -9,6 +9,15 @@ export declare const metadataAllProjects: (projects: any[]) => any[];
9
9
  export declare const fetchData: (url: string, apiKey: string, method?: string, body?: any, headers?: any) => Promise<any>;
10
10
  export declare function generateAttributeTemplate(record: any): any;
11
11
  export declare function generateImageTemplate(record: any): any;
12
+ /**
13
+ * generateTemplate defines rules and utilitites for a given curated
14
+ * collection. This is used by callers, like emblem.finance website
15
+ * to display vaults belonging to a curated collection with appropriate
16
+ * data and actions.
17
+ *
18
+ * @param record is a curated collection record as defined in
19
+ * the Emblem database.
20
+ */
12
21
  export declare function generateTemplate(record: any): any;
13
22
  export declare function templateGuard(input: {
14
23
  [x: string]: any;