@mirrorworld/library.assetminting.new
Version:
asset minting SDK
1,497 lines (1,472 loc) • 77.9 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var anchor = require('@project-serum/anchor');
var web3_js = require('@solana/web3.js');
var splToken = require('@solana/spl-token');
var base58 = require('bs58');
var nacl = require('tweetnacl');
var mplTokenMetadata = require('@metaplex-foundation/mpl-token-metadata');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var base58__namespace = /*#__PURE__*/_interopNamespace(base58);
var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
if (null != _i) {
var _s,
_e,
_x,
_r,
_arr = [],
_n = !0,
_d = !1;
try {
if (_x = (_i = _i.call(arr)).next, 0 === i) {
if (Object(_i) !== _i) return;
_n = !1;
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
} catch (err) {
_d = !0, _e = err;
} finally {
try {
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
} finally {
if (_d) throw _e;
}
}
return _arr;
}
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
return exports;
};
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
defineProperty = Object.defineProperty || function (obj, key, desc) {
obj[key] = desc.value;
},
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return defineProperty(generator, "_invoke", {
value: makeInvokeMethod(innerFn, self, context)
}), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
exports.wrap = wrap;
var ContinueSentinel = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
defineProperty(this, "_invoke", {
value: function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
}
});
}
function makeInvokeMethod(innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}
function maybeInvokeDelegate(delegate, context) {
var methodName = context.method,
method = delegate.iterator[methodName];
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
function doneResult() {
return {
value: undefined,
done: !0
};
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
value: GeneratorFunctionPrototype,
configurable: !0
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
value: GeneratorFunction,
configurable: !0
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (val) {
var object = Object(val),
keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
var IDL = {
"version": "0.1.1",
"name": "asset_minting",
"instructions": [{
"name": "initializeConfig",
"accounts": [{
"name": "payer",
"isMut": true,
"isSigner": true
}, {
"name": "signingAuthority",
"isMut": false,
"isSigner": true
}, {
"name": "config",
"isMut": true,
"isSigner": false
}, {
"name": "systemProgram",
"isMut": false,
"isSigner": false
}, {
"name": "rent",
"isMut": false,
"isSigner": false
}],
"args": [{
"name": "configName",
"type": "string"
}]
}, {
"name": "createMintToken",
"accounts": [{
"name": "payer",
"isMut": true,
"isSigner": true
}, {
"name": "signingAuthority",
"isMut": false,
"isSigner": true
}, {
"name": "config",
"isMut": true,
"isSigner": false
}, {
"name": "mint",
"isMut": true,
"isSigner": false
}, {
"name": "mintAuthority",
"isMut": false,
"isSigner": false
}, {
"name": "tokenProgram",
"isMut": false,
"isSigner": false
}, {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
}, {
"name": "systemProgram",
"isMut": false,
"isSigner": false
}, {
"name": "rent",
"isMut": false,
"isSigner": false
}],
"args": [{
"name": "configName",
"type": "string"
}, {
"name": "configAccountBump",
"type": "u8"
}, {
"name": "mintUuid",
"type": "string"
}]
}, {
"name": "createCollection",
"accounts": [{
"name": "payer",
"isMut": true,
"isSigner": true
}, {
"name": "signingAuthority",
"isMut": false,
"isSigner": true
}, {
"name": "config",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMintAuthority",
"isMut": true,
"isSigner": true
}, {
"name": "collectionOwner",
"isMut": false,
"isSigner": false
}, {
"name": "collectionMintAccount",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMintTokenAccount",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMetadata",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMasterEdition",
"isMut": true,
"isSigner": false
}, {
"name": "mplProgram",
"isMut": false,
"isSigner": false
}, {
"name": "tokenProgram",
"isMut": false,
"isSigner": false
}, {
"name": "systemProgram",
"isMut": false,
"isSigner": false
}, {
"name": "rent",
"isMut": false,
"isSigner": false
}, {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
}],
"args": [{
"name": "configName",
"type": "string"
}, {
"name": "configAccountBump",
"type": "u8"
}, {
"name": "collectionMintTokenUuid",
"type": "string"
}, {
"name": "collectionMintTokenBump",
"type": "u8"
}, {
"name": "name",
"type": "string"
}, {
"name": "symbol",
"type": "string"
}, {
"name": "baseUrl",
"type": "string"
}, {
"name": "isMutable",
"type": "bool"
}, {
"name": "sellerBasePoint",
"type": "u16"
}, {
"name": "creatorsArgs",
"type": {
"vec": {
"defined": "CreatorType"
}
}
}]
}, {
"name": "createSubCollection",
"accounts": [{
"name": "payer",
"isMut": true,
"isSigner": true
}, {
"name": "signingAuthority",
"isMut": false,
"isSigner": true
}, {
"name": "config",
"isMut": true,
"isSigner": false
}, {
"name": "collectionUpdateAuthority",
"isMut": true,
"isSigner": true
}, {
"name": "collectionMintAccount",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMetadata",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMasterEdition",
"isMut": true,
"isSigner": false
}, {
"name": "subCollectionMintAuthority",
"isMut": true,
"isSigner": true
}, {
"name": "subCollectionOwner",
"isMut": false,
"isSigner": false
}, {
"name": "subCollectionMintAccount",
"isMut": true,
"isSigner": false
}, {
"name": "subCollectionMintTokenAccount",
"isMut": true,
"isSigner": false
}, {
"name": "subCollectionMetadata",
"isMut": true,
"isSigner": false
}, {
"name": "subCollectionMasterEdition",
"isMut": true,
"isSigner": false
}, {
"name": "mplProgram",
"isMut": false,
"isSigner": false
}, {
"name": "tokenProgram",
"isMut": false,
"isSigner": false
}, {
"name": "systemProgram",
"isMut": false,
"isSigner": false
}, {
"name": "rent",
"isMut": false,
"isSigner": false
}, {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
}],
"args": [{
"name": "configName",
"type": "string"
}, {
"name": "configAccountBump",
"type": "u8"
}, {
"name": "collectionMintTokenUuid",
"type": "string"
}, {
"name": "collectionMintTokenBump",
"type": "u8"
}, {
"name": "subCollectionMintTokenUuid",
"type": "string"
}, {
"name": "subCollectionMintTokenBump",
"type": "u8"
}, {
"name": "name",
"type": "string"
}, {
"name": "symbol",
"type": "string"
}, {
"name": "baseUrl",
"type": "string"
}, {
"name": "isMutable",
"type": "bool"
}, {
"name": "sellerBasePoint",
"type": "u16"
}, {
"name": "creatorsArgs",
"type": {
"vec": {
"defined": "CreatorType"
}
}
}]
}, {
"name": "createAsset",
"accounts": [{
"name": "payer",
"isMut": true,
"isSigner": true
}, {
"name": "signingAuthority",
"isMut": false,
"isSigner": true
}, {
"name": "user",
"isMut": false,
"isSigner": false
}, {
"name": "config",
"isMut": true,
"isSigner": false
}, {
"name": "collectionUpdateAuthority",
"isMut": true,
"isSigner": true
}, {
"name": "collectionMintAccount",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMetadata",
"isMut": true,
"isSigner": false
}, {
"name": "collectionMasterEdition",
"isMut": true,
"isSigner": false
}, {
"name": "assetMintAuthority",
"isMut": true,
"isSigner": true
}, {
"name": "assetMintAccount",
"isMut": true,
"isSigner": false
}, {
"name": "assetMintTokenAccount",
"isMut": true,
"isSigner": false
}, {
"name": "assetMetadata",
"isMut": true,
"isSigner": false
}, {
"name": "assetMasterEdition",
"isMut": true,
"isSigner": false
}, {
"name": "mplProgram",
"isMut": false,
"isSigner": false
}, {
"name": "tokenProgram",
"isMut": false,
"isSigner": false
}, {
"name": "systemProgram",
"isMut": false,
"isSigner": false
}, {
"name": "rent",
"isMut": false,
"isSigner": false
}, {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
}],
"args": [{
"name": "configName",
"type": "string"
}, {
"name": "configAccountBump",
"type": "u8"
}, {
"name": "collectionMintTokenUuid",
"type": "string"
}, {
"name": "collectionMintTokenBump",
"type": "u8"
}, {
"name": "assetUuid",
"type": "string"
}, {
"name": "assetBump",
"type": "u8"
}, {
"name": "name",
"type": "string"
}, {
"name": "symbol",
"type": "string"
}, {
"name": "baseUrl",
"type": "string"
}, {
"name": "isMutable",
"type": "bool"
}, {
"name": "sellerBasePoint",
"type": "u16"
}, {
"name": "creatorsArgs",
"type": {
"vec": {
"defined": "CreatorType"
}
}
}]
}],
"accounts": [{
"name": "configAccount",
"type": {
"kind": "struct",
"fields": [{
"name": "signingAuthority",
"type": "publicKey"
}, {
"name": "lastUsedBlockTimestamp",
"type": "i64"
}]
}
}],
"types": [{
"name": "CreatorType",
"type": {
"kind": "struct",
"fields": [{
"name": "address",
"type": "publicKey"
}, {
"name": "verified",
"type": "bool"
}, {
"name": "share",
"type": "u8"
}]
}
}],
"events": [{
"name": "AssetEvent",
"fields": [{
"name": "mintUuid",
"type": "string",
"index": false
}, {
"name": "mintAddress",
"type": "publicKey",
"index": false
}, {
"name": "metadataAddress",
"type": "publicKey",
"index": false
}, {
"name": "masterEditionAddress",
"type": "publicKey",
"index": false
}, {
"name": "owner",
"type": "publicKey",
"index": false
}, {
"name": "collectionUuid",
"type": "string",
"index": false
}, {
"name": "collectionMintAddress",
"type": "publicKey",
"index": false
}, {
"name": "collectionMetadataAddress",
"type": "publicKey",
"index": false
}, {
"name": "collectionMasterEditionAddress",
"type": "publicKey",
"index": false
}]
}, {
"name": "CollectionEvent",
"fields": [{
"name": "mintUuid",
"type": "string",
"index": false
}, {
"name": "mintAddress",
"type": "publicKey",
"index": false
}, {
"name": "metadataAddress",
"type": "publicKey",
"index": false
}, {
"name": "masterEditionAddress",
"type": "publicKey",
"index": false
}, {
"name": "owner",
"type": "publicKey",
"index": false
}]
}, {
"name": "MintEvent",
"fields": [{
"name": "mintUuid",
"type": "string",
"index": false
}, {
"name": "mintAddress",
"type": "publicKey",
"index": false
}]
}, {
"name": "SubCollectionEvent",
"fields": [{
"name": "mintUuid",
"type": "string",
"index": false
}, {
"name": "mintAddress",
"type": "publicKey",
"index": false
}, {
"name": "metadataAddress",
"type": "publicKey",
"index": false
}, {
"name": "masterEditionAddress",
"type": "publicKey",
"index": false
}, {
"name": "owner",
"type": "publicKey",
"index": false
}, {
"name": "collectionUuid",
"type": "string",
"index": false
}, {
"name": "collectionMintAddress",
"type": "publicKey",
"index": false
}, {
"name": "collectionMetadataAddress",
"type": "publicKey",
"index": false
}, {
"name": "collectionMasterEditionAddress",
"type": "publicKey",
"index": false
}]
}],
"errors": [{
"code": 6000,
"name": "InvalidSigningAuthority",
"msg": "Invalid Signing Authority"
}, {
"code": 6001,
"name": "InvalidTimestamp",
"msg": "Invalid Timestamp"
}]
};
var MINT_EVENT_NAME = "MintEvent";
var COLLECTION_EVENT_NAME = "CollectionEvent";
var SUB_COLLECTION_EVENT_NAME = "SubCollectionEvent";
var ASSET_EVENT_NAME = "AssetEvent";
var CONFIG_ACCOUNT_PREFIX = "CONFIG";
var NAME = "MirrorWorld";
var AssetMintingLib = /*#__PURE__*/function () {
function AssetMintingLib(programId, connection, wallet) {
_classCallCheck(this, AssetMintingLib);
this.connection = connection;
var provider = new anchor.AnchorProvider(connection, wallet, anchor.AnchorProvider.defaultOptions());
this.program = new anchor.Program(IDL, programId, provider);
}
/**
* Sign the transaction and add the signature in the transaction.
* @param tx Transaction object which needs to sign.
* @param secretKey Transaction signer secret key (secret key in base58 string).
*/
_createClass(AssetMintingLib, [{
key: "signTransaction",
value: function signTransaction(tx, secretKey) {
var keypair = web3_js.Keypair.fromSecretKey(base58__namespace.decode(secretKey));
var signature = nacl__namespace.sign.detached(tx.serializeMessage(), keypair.secretKey);
tx.addSignature(keypair.publicKey, Buffer.from(signature));
return tx;
}
/**
* Add signature in the transaction.
* @param tx Transaction object where signature needs to add.
* @param signerAddress Signer public key from which secret key transaction is signed.
* @param signature Signed transaction message signature.
*/
}, {
key: "addSignatureInTransaction",
value: function addSignatureInTransaction(tx, signerAddress, signature) {
tx.addSignature(signerAddress, signature);
return tx;
}
/**
* Add signature in the transaction.
* @param tx Transaction object where signature needs to add.
* @param feePayer public key of the address which going to pay the fee.
*/
}, {
key: "addFeePayerAndRecentBlockHashInTransaction",
value: function () {
var _addFeePayerAndRecentBlockHashInTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(tx, feePayer) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
tx.feePayer = feePayer;
_context.next = 3;
return this.connection.getLatestBlockhash();
case 3:
tx.recentBlockhash = _context.sent.blockhash;
return _context.abrupt("return", tx);
case 5:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));
function addFeePayerAndRecentBlockHashInTransaction(_x, _x2) {
return _addFeePayerAndRecentBlockHashInTransaction.apply(this, arguments);
}
return addFeePayerAndRecentBlockHashInTransaction;
}()
/**
* Is pda address initialize.
*/
}, {
key: "isPdaAddressInitialize",
value: function () {
var _isPdaAddressInitialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(pdaAddress) {
var pdaAccountInfo;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return this.connection.getAccountInfo(pdaAddress);
case 2:
pdaAccountInfo = _context2.sent;
return _context2.abrupt("return", pdaAccountInfo != null);
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2, this);
}));
function isPdaAddressInitialize(_x3) {
return _isPdaAddressInitialize.apply(this, arguments);
}
return isPdaAddressInitialize;
}()
/**
* get the config account pda and bump.
* @param name seed for the config account.
*/
}, {
key: "getConfigAccountPdaAndBump",
value: function () {
var _getConfigAccountPdaAndBump = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
var name,
_args3 = arguments;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
name = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : NAME;
return _context3.abrupt("return", web3_js.PublicKey.findProgramAddressSync([Buffer.from(name), Buffer.from(CONFIG_ACCOUNT_PREFIX)], this.program.programId));
case 2:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));
function getConfigAccountPdaAndBump() {
return _getConfigAccountPdaAndBump.apply(this, arguments);
}
return getConfigAccountPdaAndBump;
}()
/**
* get the mint account pda and bump.
* @param uuid seed for the mint account.
*/
}, {
key: "getMintAccountPdaAndBump",
value: function () {
var _getMintAccountPdaAndBump = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(uuid) {
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
return _context4.abrupt("return", web3_js.PublicKey.findProgramAddressSync([Buffer.from(uuid)], this.program.programId));
case 1:
case "end":
return _context4.stop();
}
}
}, _callee4, this);
}));
function getMintAccountPdaAndBump(_x4) {
return _getMintAccountPdaAndBump.apply(this, arguments);
}
return getMintAccountPdaAndBump;
}()
/**
* Get metadata account pda.
* @param mintAccountPda token mint account
* @param mplProgramId metadata program id
*/
}, {
key: "getMetadataAccountPda",
value: function () {
var _getMetadataAccountPda = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(mintAccountPda) {
var mplProgramId,
_args5 = arguments;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
mplProgramId = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : mplTokenMetadata.PROGRAM_ID;
return _context5.abrupt("return", web3_js.PublicKey.findProgramAddressSync([Buffer.from('metadata'), mplProgramId.toBuffer(), mintAccountPda.toBuffer()], mplProgramId));
case 2:
case "end":
return _context5.stop();
}
}
}, _callee5);
}));
function getMetadataAccountPda(_x5) {
return _getMetadataAccountPda.apply(this, arguments);
}
return getMetadataAccountPda;
}()
/**
* Get master edition account pda.
* @param mintAccountPda token mint account
* @param mplProgramId metadata program id
*/
}, {
key: "getMasterEditionAccountPda",
value: function () {
var _getMasterEditionAccountPda = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(mintAccountPda) {
var mplProgramId,
_args6 = arguments;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
mplProgramId = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : mplTokenMetadata.PROGRAM_ID;
return _context6.abrupt("return", web3_js.PublicKey.findProgramAddressSync([Buffer.from('metadata'), mplProgramId.toBuffer(), mintAccountPda.toBuffer(), Buffer.from('edition')], mplProgramId));
case 2:
case "end":
return _context6.stop();
}
}
}, _callee6);
}));
function getMasterEditionAccountPda(_x6) {
return _getMasterEditionAccountPda.apply(this, arguments);
}
return getMasterEditionAccountPda;
}()
/**
* Get config account pda data
* @param configAccountPda pda address for data
*/
}, {
key: "getConfigAccountData",
value: function () {
var _getConfigAccountData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(configAccountPda) {
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return this.program.account.configAccount.fetch(configAccountPda);
case 2:
return _context7.abrupt("return", _context7.sent);
case 3:
case "end":
return _context7.stop();
}
}
}, _callee7, this);
}));
function getConfigAccountData(_x7) {
return _getConfigAccountData.apply(this, arguments);
}
return getConfigAccountData;
}()
/**
* Get current block time
*/
}, {
key: "getCurrentBlockTime",
value: function () {
var _getCurrentBlockTime = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.t0 = anchor.BN;
_context8.t1 = this.connection;
_context8.next = 4;
return this.connection.getSlot(undefined);
case 4:
_context8.t2 = _context8.sent;
_context8.next = 7;
return _context8.t1.getBlockTime.call(_context8.t1, _context8.t2);
case 7:
_context8.t3 = _context8.sent;
return _context8.abrupt("return", new _context8.t0(_context8.t3));
case 9:
case "end":
return _context8.stop();
}
}
}, _callee8, this);
}));
function getCurrentBlockTime() {
return _getCurrentBlockTime.apply(this, arguments);
}
return getCurrentBlockTime;
}()
/**
* Create initialize config transaction
* @param payer transaction fee payer public key
* @param signingAuthority signing authority public key
* @param configName config account seed for pda
* @param systemProgram system program id
* @param rent rent program id
*/
}, {
key: "createInitializeConfigTransaction",
value: function () {
var _createInitializeConfigTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(payer, signingAuthority) {
var configName,
systemProgram,
rent,
_yield$this$getConfig,
_yield$this$getConfig2,
configAccount,
tx,
_args9 = arguments;
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
configName = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : NAME;
systemProgram = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : web3_js.SystemProgram.programId;
rent = _args9.length > 4 && _args9[4] !== undefined ? _args9[4] : web3_js.SYSVAR_RENT_PUBKEY;
_context9.next = 5;
return this.getConfigAccountPdaAndBump(configName);
case 5:
_yield$this$getConfig = _context9.sent;
_yield$this$getConfig2 = _slicedToArray(_yield$this$getConfig, 1);
configAccount = _yield$this$getConfig2[0];
_context9.next = 10;
return this.program.methods.initializeConfig(configName).accounts({
payer: payer,
signingAuthority: signingAuthority,
config: configAccount,
systemProgram: systemProgram,
rent: rent
}).transaction();
case 10:
tx = _context9.sent;
return _context9.abrupt("return", tx);
case 12:
case "end":
return _context9.stop();
}
}
}, _callee9, this);
}));
function createInitializeConfigTransaction(_x8, _x9) {
return _createInitializeConfigTransaction.apply(this, arguments);
}
return createInitializeConfigTransaction;
}()
/**
* Create mint token transaction
* @param assetUuid seed for the mint account
* @param payer transaction fee payer public key
* @param signingAuthority signing authority public key
* @param mintAuthority token mint authority
* @param configName config account seed for pda
* @param tokenProgram token program id
* @param associatedTokenProgram associated token program id
* @param systemProgram system program id
* @param rent rent program id
*/
}, {
key: "createMintTokenTransaction",
value: function () {
var _createMintTokenTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(assetUuid, payer, signingAuthority, mintAuthority) {
var configName,
systemProgram,
rent,
associatedTokenProgram,
tokenProgram,
_yield$this$getConfig3,
_yield$this$getConfig4,
configAccount,
configAccountBump,
_yield$this$getMintAc,
_yield$this$getMintAc2,
mintAccount,
tx,
_args10 = arguments;
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
configName = _args10.length > 4 && _args10[4] !== undefined ? _args10[4] : NAME;
systemProgram = _args10.length > 5 && _args10[5] !== undefined ? _args10[5] : web3_js.SystemProgram.programId;
rent = _args10.length > 6 && _args10[6] !== undefined ? _args10[6] : web3_js.SYSVAR_RENT_PUBKEY;
associatedTokenProgram = _args10.length > 7 && _args10[7] !== undefined ? _args10[7] : splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
tokenProgram = _args10.length > 8 && _args10[8] !== undefined ? _args10[8] : splToken.TOKEN_PROGRAM_ID;
_context10.next = 7;
return this.getConfigAccountPdaAndBump(configName);
case 7:
_yield$this$getConfig3 = _context10.sent;
_yield$this$getConfig4 = _slicedToArray(_yield$this$getConfig3, 2);
configAccount = _yield$this$getConfig4[0];
configAccountBump = _yield$this$getConfig4[1];
_context10.next = 13;
return this.getMintAccountPdaAndBump(assetUuid);
case 13:
_yield$this$getMintAc = _context10.sent;
_yield$this$getMintAc2 = _slicedToArray(_yield$this$getMintAc, 1);
mintAccount = _yield$this$getMintAc2[0];
_context10.next = 18;
return this.program.methods.createMintToken(configName, configAccountBump, assetUuid).accounts({
payer: payer,
signingAuthority: signingAuthority,
config: configAccount,
mint: mintAccount,
mintAuthority: mintAuthority,
associatedTokenProgram: associatedTokenProgram,
tokenProgram: tokenProgram,
systemProgram: systemProgram,
rent: rent
}).transaction();
case 18:
tx = _context10.sent;
return _context10.abrupt("return", tx);
case 20:
case "end":
return _context10.stop();
}
}
}, _callee10, this);
}));
function createMintTokenTransaction(_x10, _x11, _x12, _x13) {
return _createMintTokenTransaction.apply(this, arguments);
}
return createMintTokenTransaction;
}()
/**
* Create collection token transaction
* @param collectionUuid seed for the collection mint account
* @param payer transaction fee payer public key
* @param signingAuthority signing authority public key
* @param collectionMintAuthority collection mint authority public key
* @param collectionOwner collection owner
* @param tokenName token name
* @param tokenSymbol token symbol
* @param tokenUrl token url
* @param tokenIsMutable token is mutable
* @param tokenSellerPoint token seller point
* @param creators List of the creators
* @param configName config account seed for pda
* @param tokenProgram token program id
* @param associatedTokenProgram associated token program id
* @param systemProgram system program id
* @param rent rent program id
* @param mplProgram Metadata program id
*/
}, {
key: "createCollectionTokenTransaction",
value: function () {
var _createCollectionTokenTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(collectionUuid, payer, signingAuthority, collectionMintAuthority, collectionOwner, tokenName, tokenSymbol, tokenUrl, tokenIsMutable, tokenSellerPoint, creators) {
var configName,
systemProgram,
rent,
associatedTokenProgram,
tokenProgram,
mplProgram,
_yield$this$getConfig5,
_yield$this$getConfig6,
configAccount,
configAccountBump,
_yield$this$getMintAc3,
_yield$this$getMintAc4,
collectionMintAccount,
collectionMintAccountBump,
_yield$this$getMetada,
_yield$this$getMetada2,
collectionMetadata,
_yield$this$getMaster,
_yield$this$getMaster2,
collectionMasterEdition,
collectionTokenAccount,
tx,
collectionTx,
_args11 = arguments;
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
configName = _args11.length > 11 && _args11[11] !== undefined ? _args11[11] : NAME;
systemProgram = _args11.length > 12 && _args11[12] !== undefined ? _args11[12] : web3_js.SystemProgram.programId;
rent = _args11.length > 13 && _args11[13] !== undefined ? _args11[13] : web3_js.SYSVAR_RENT_PUBKEY;
associatedTokenProgram = _args11.length > 14 && _args11[14] !== undefined ? _args11[14] : splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
tokenProgram = _args11.length > 15 && _args11[15] !== undefined ? _args11[15] : splToken.TOKEN_PROGRAM_ID;
mplProgram = _args11.length > 16 && _args11[16] !== undefined ? _args11[16] : mplTokenMetadata.PROGRAM_ID;
_context11.next = 8;
return this.getConfigAccountPdaAndBump(configName);
case 8:
_yield$this$getConfig5 = _context11.sent;
_yield$this$getConfig6 = _slicedToArray(_yield$this$getConfig5, 2);
configAccount = _yield$this$getConfig6[0];
configAccountBump = _yield