mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-25 13:54:05 -06:00
30102 lines
909 KiB
JavaScript
30102 lines
909 KiB
JavaScript
import fetch$1 from 'node-fetch';
|
|
import { arrayify, hexlify, hexZeroPad } from '@ethersproject/bytes';
|
|
import { Contract } from '@ethersproject/contracts';
|
|
import { ERC20__factory, SignatureMint1155__factory, ERC721__factory, Coin__factory, ProtocolControl__factory, Royalty__factory, NFTCollection__factory, Splits__factory, SignatureMint721__factory, Market__factory, Pack__factory, LazyMintERC721__factory, LazyMintERC1155__factory, DataStore__factory, VotingGovernor__factory, IERC20__factory, Marketplace__factory, LazyNFT__factory, ERC1155__factory, ERC165__factory, NFT__factory, Registry__factory, Forwarder__factory } from '@3rdweb/contracts';
|
|
import { AddressZero } from '@ethersproject/constants';
|
|
import { formatUnits, parseUnits } from '@ethersproject/units';
|
|
import { Signer, ethers, BigNumber, Contract as Contract$1 } from 'ethers';
|
|
import { $enum } from 'ts-enum-util';
|
|
import { BigNumber as BigNumber$1 } from '@ethersproject/bignumber';
|
|
import { toUtf8Bytes, isAddress, hexlify as hexlify$1 } from 'ethers/lib/utils';
|
|
import { v4 } from 'uuid';
|
|
import { Provider } from '@ethersproject/providers';
|
|
import { EventEmitter2 } from 'eventemitter2';
|
|
import { JsonProperty, PropertyConvertingMode, JsonObject, JsonConvert } from 'json2typescript';
|
|
import MerkleTree, { MerkleTree as MerkleTree$1 } from 'merkletreejs';
|
|
import { __decorate } from 'tslib';
|
|
import { isAddress as isAddress$1 } from '@ethersproject/address';
|
|
import { SHA256 } from 'crypto-js';
|
|
|
|
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 _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, 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;
|
|
}
|
|
|
|
function _extends() {
|
|
_extends = Object.assign || function (target) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
var source = arguments[i];
|
|
|
|
for (var key in source) {
|
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
target[key] = source[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
return target;
|
|
};
|
|
|
|
return _extends.apply(this, arguments);
|
|
}
|
|
|
|
function _inheritsLoose(subClass, superClass) {
|
|
subClass.prototype = Object.create(superClass.prototype);
|
|
subClass.prototype.constructor = subClass;
|
|
|
|
_setPrototypeOf(subClass, superClass);
|
|
}
|
|
|
|
function _getPrototypeOf(o) {
|
|
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
};
|
|
return _getPrototypeOf(o);
|
|
}
|
|
|
|
function _setPrototypeOf(o, p) {
|
|
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
o.__proto__ = p;
|
|
return o;
|
|
};
|
|
|
|
return _setPrototypeOf(o, p);
|
|
}
|
|
|
|
function _isNativeReflectConstruct() {
|
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
if (Reflect.construct.sham) return false;
|
|
if (typeof Proxy === "function") return true;
|
|
|
|
try {
|
|
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function _construct(Parent, args, Class) {
|
|
if (_isNativeReflectConstruct()) {
|
|
_construct = Reflect.construct;
|
|
} else {
|
|
_construct = function _construct(Parent, args, Class) {
|
|
var a = [null];
|
|
a.push.apply(a, args);
|
|
var Constructor = Function.bind.apply(Parent, a);
|
|
var instance = new Constructor();
|
|
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
return instance;
|
|
};
|
|
}
|
|
|
|
return _construct.apply(null, arguments);
|
|
}
|
|
|
|
function _isNativeFunction(fn) {
|
|
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
}
|
|
|
|
function _wrapNativeSuper(Class) {
|
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
|
|
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
|
|
if (typeof Class !== "function") {
|
|
throw new TypeError("Super expression must either be null or a function");
|
|
}
|
|
|
|
if (typeof _cache !== "undefined") {
|
|
if (_cache.has(Class)) return _cache.get(Class);
|
|
|
|
_cache.set(Class, Wrapper);
|
|
}
|
|
|
|
function Wrapper() {
|
|
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
}
|
|
|
|
Wrapper.prototype = Object.create(Class.prototype, {
|
|
constructor: {
|
|
value: Wrapper,
|
|
enumerable: false,
|
|
writable: true,
|
|
configurable: true
|
|
}
|
|
});
|
|
return _setPrototypeOf(Wrapper, Class);
|
|
};
|
|
|
|
return _wrapNativeSuper(Class);
|
|
}
|
|
|
|
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 _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 _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
if (it) return (it = it.call(o)).next.bind(it);
|
|
|
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
if (it) o = it;
|
|
var i = 0;
|
|
return function () {
|
|
if (i >= o.length) return {
|
|
done: true
|
|
};
|
|
return {
|
|
done: false,
|
|
value: o[i++]
|
|
};
|
|
};
|
|
}
|
|
|
|
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
}
|
|
|
|
function createCommonjsModule(fn, module) {
|
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
}
|
|
|
|
var runtime_1 = createCommonjsModule(function (module) {
|
|
/**
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
var runtime = (function (exports) {
|
|
|
|
var Op = Object.prototype;
|
|
var hasOwn = Op.hasOwnProperty;
|
|
var undefined$1; // More compressible than void 0.
|
|
var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
|
var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
|
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
|
|
function define(obj, key, value) {
|
|
Object.defineProperty(obj, key, {
|
|
value: value,
|
|
enumerable: true,
|
|
configurable: true,
|
|
writable: true
|
|
});
|
|
return obj[key];
|
|
}
|
|
try {
|
|
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
define({}, "");
|
|
} catch (err) {
|
|
define = function(obj, key, value) {
|
|
return obj[key] = value;
|
|
};
|
|
}
|
|
|
|
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
|
|
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
|
var generator = Object.create(protoGenerator.prototype);
|
|
var context = new Context(tryLocsList || []);
|
|
|
|
// The ._invoke method unifies the implementations of the .next,
|
|
// .throw, and .return methods.
|
|
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
|
|
return generator;
|
|
}
|
|
exports.wrap = wrap;
|
|
|
|
// Try/catch helper to minimize deoptimizations. Returns a completion
|
|
// record like context.tryEntries[i].completion. This interface could
|
|
// have been (and was previously) designed to take a closure to be
|
|
// invoked without arguments, but in all the cases we care about we
|
|
// already have an existing method we want to call, so there's no need
|
|
// to create a new function object. We can even get away with assuming
|
|
// the method takes exactly one argument, since that happens to be true
|
|
// in every case, so we don't have to touch the arguments object. The
|
|
// only additional allocation required is the completion record, which
|
|
// has a stable shape and so hopefully should be cheap to allocate.
|
|
function tryCatch(fn, obj, arg) {
|
|
try {
|
|
return { type: "normal", arg: fn.call(obj, arg) };
|
|
} catch (err) {
|
|
return { type: "throw", arg: err };
|
|
}
|
|
}
|
|
|
|
var GenStateSuspendedStart = "suspendedStart";
|
|
var GenStateSuspendedYield = "suspendedYield";
|
|
var GenStateExecuting = "executing";
|
|
var GenStateCompleted = "completed";
|
|
|
|
// Returning this object from the innerFn has the same effect as
|
|
// breaking out of the dispatch switch statement.
|
|
var ContinueSentinel = {};
|
|
|
|
// Dummy constructor functions that we use as the .constructor and
|
|
// .constructor.prototype properties for functions that return Generator
|
|
// objects. For full spec compliance, you may wish to configure your
|
|
// minifier not to mangle the names of these two functions.
|
|
function Generator() {}
|
|
function GeneratorFunction() {}
|
|
function GeneratorFunctionPrototype() {}
|
|
|
|
// This is a polyfill for %IteratorPrototype% for environments that
|
|
// don't natively support it.
|
|
var IteratorPrototype = {};
|
|
define(IteratorPrototype, iteratorSymbol, function () {
|
|
return this;
|
|
});
|
|
|
|
var getProto = Object.getPrototypeOf;
|
|
var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
if (NativeIteratorPrototype &&
|
|
NativeIteratorPrototype !== Op &&
|
|
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
// This environment has a native %IteratorPrototype%; use it instead
|
|
// of the polyfill.
|
|
IteratorPrototype = NativeIteratorPrototype;
|
|
}
|
|
|
|
var Gp = GeneratorFunctionPrototype.prototype =
|
|
Generator.prototype = Object.create(IteratorPrototype);
|
|
GeneratorFunction.prototype = GeneratorFunctionPrototype;
|
|
define(Gp, "constructor", GeneratorFunctionPrototype);
|
|
define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
|
|
GeneratorFunction.displayName = define(
|
|
GeneratorFunctionPrototype,
|
|
toStringTagSymbol,
|
|
"GeneratorFunction"
|
|
);
|
|
|
|
// Helper for defining the .next, .throw, and .return methods of the
|
|
// Iterator interface in terms of a single ._invoke method.
|
|
function defineIteratorMethods(prototype) {
|
|
["next", "throw", "return"].forEach(function(method) {
|
|
define(prototype, method, function(arg) {
|
|
return this._invoke(method, arg);
|
|
});
|
|
});
|
|
}
|
|
|
|
exports.isGeneratorFunction = function(genFun) {
|
|
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
return ctor
|
|
? ctor === GeneratorFunction ||
|
|
// For the native GeneratorFunction constructor, the best we can
|
|
// do is to check its .name property.
|
|
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
: false;
|
|
};
|
|
|
|
exports.mark = function(genFun) {
|
|
if (Object.setPrototypeOf) {
|
|
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
} else {
|
|
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
}
|
|
genFun.prototype = Object.create(Gp);
|
|
return genFun;
|
|
};
|
|
|
|
// Within the body of any async function, `await x` is transformed to
|
|
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
// meant to be awaited.
|
|
exports.awrap = function(arg) {
|
|
return { __await: arg };
|
|
};
|
|
|
|
function AsyncIterator(generator, PromiseImpl) {
|
|
function invoke(method, arg, resolve, reject) {
|
|
var record = tryCatch(generator[method], generator, arg);
|
|
if (record.type === "throw") {
|
|
reject(record.arg);
|
|
} else {
|
|
var result = record.arg;
|
|
var value = result.value;
|
|
if (value &&
|
|
typeof value === "object" &&
|
|
hasOwn.call(value, "__await")) {
|
|
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
invoke("next", value, resolve, reject);
|
|
}, function(err) {
|
|
invoke("throw", err, resolve, reject);
|
|
});
|
|
}
|
|
|
|
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
// When a yielded Promise is resolved, its final value becomes
|
|
// the .value of the Promise<{value,done}> result for the
|
|
// current iteration.
|
|
result.value = unwrapped;
|
|
resolve(result);
|
|
}, function(error) {
|
|
// If a rejected Promise was yielded, throw the rejection back
|
|
// into the async generator function so it can be handled there.
|
|
return invoke("throw", error, resolve, reject);
|
|
});
|
|
}
|
|
}
|
|
|
|
var previousPromise;
|
|
|
|
function enqueue(method, arg) {
|
|
function callInvokeWithMethodAndArg() {
|
|
return new PromiseImpl(function(resolve, reject) {
|
|
invoke(method, arg, resolve, reject);
|
|
});
|
|
}
|
|
|
|
return previousPromise =
|
|
// If enqueue has been called before, then we want to wait until
|
|
// all previous Promises have been resolved before calling invoke,
|
|
// so that results are always delivered in the correct order. If
|
|
// enqueue has not been called before, then it is important to
|
|
// call invoke immediately, without waiting on a callback to fire,
|
|
// so that the async generator function has the opportunity to do
|
|
// any necessary setup in a predictable way. This predictability
|
|
// is why the Promise constructor synchronously invokes its
|
|
// executor callback, and why async functions synchronously
|
|
// execute code before the first await. Since we implement simple
|
|
// async functions in terms of async generators, it is especially
|
|
// important to get this right, even though it requires care.
|
|
previousPromise ? previousPromise.then(
|
|
callInvokeWithMethodAndArg,
|
|
// Avoid propagating failures to Promises returned by later
|
|
// invocations of the iterator.
|
|
callInvokeWithMethodAndArg
|
|
) : callInvokeWithMethodAndArg();
|
|
}
|
|
|
|
// Define the unified helper method that is used to implement .next,
|
|
// .throw, and .return (see defineIteratorMethods).
|
|
this._invoke = enqueue;
|
|
}
|
|
|
|
defineIteratorMethods(AsyncIterator.prototype);
|
|
define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
return this;
|
|
});
|
|
exports.AsyncIterator = AsyncIterator;
|
|
|
|
// Note that simple async functions are implemented on top of
|
|
// AsyncIterator objects; they just return a Promise for the value of
|
|
// the final result produced by the iterator.
|
|
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
|
|
var iter = new AsyncIterator(
|
|
wrap(innerFn, outerFn, self, tryLocsList),
|
|
PromiseImpl
|
|
);
|
|
|
|
return exports.isGeneratorFunction(outerFn)
|
|
? iter // If outerFn is a generator, return the full iterator.
|
|
: iter.next().then(function(result) {
|
|
return result.done ? result.value : iter.next();
|
|
});
|
|
};
|
|
|
|
function makeInvokeMethod(innerFn, self, context) {
|
|
var state = GenStateSuspendedStart;
|
|
|
|
return function invoke(method, arg) {
|
|
if (state === GenStateExecuting) {
|
|
throw new Error("Generator is already running");
|
|
}
|
|
|
|
if (state === GenStateCompleted) {
|
|
if (method === "throw") {
|
|
throw arg;
|
|
}
|
|
|
|
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
return doneResult();
|
|
}
|
|
|
|
context.method = method;
|
|
context.arg = arg;
|
|
|
|
while (true) {
|
|
var delegate = context.delegate;
|
|
if (delegate) {
|
|
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
if (delegateResult) {
|
|
if (delegateResult === ContinueSentinel) continue;
|
|
return delegateResult;
|
|
}
|
|
}
|
|
|
|
if (context.method === "next") {
|
|
// Setting context._sent for legacy support of Babel's
|
|
// function.sent implementation.
|
|
context.sent = context._sent = context.arg;
|
|
|
|
} else if (context.method === "throw") {
|
|
if (state === GenStateSuspendedStart) {
|
|
state = GenStateCompleted;
|
|
throw context.arg;
|
|
}
|
|
|
|
context.dispatchException(context.arg);
|
|
|
|
} else if (context.method === "return") {
|
|
context.abrupt("return", context.arg);
|
|
}
|
|
|
|
state = GenStateExecuting;
|
|
|
|
var record = tryCatch(innerFn, self, context);
|
|
if (record.type === "normal") {
|
|
// If an exception is thrown from innerFn, we leave state ===
|
|
// GenStateExecuting and loop back for another invocation.
|
|
state = context.done
|
|
? GenStateCompleted
|
|
: GenStateSuspendedYield;
|
|
|
|
if (record.arg === ContinueSentinel) {
|
|
continue;
|
|
}
|
|
|
|
return {
|
|
value: record.arg,
|
|
done: context.done
|
|
};
|
|
|
|
} else if (record.type === "throw") {
|
|
state = GenStateCompleted;
|
|
// Dispatch the exception by looping back around to the
|
|
// context.dispatchException(context.arg) call above.
|
|
context.method = "throw";
|
|
context.arg = record.arg;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
// result, either by returning a { value, done } result from the
|
|
// delegate iterator, or by modifying context.method and context.arg,
|
|
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
function maybeInvokeDelegate(delegate, context) {
|
|
var method = delegate.iterator[context.method];
|
|
if (method === undefined$1) {
|
|
// A .throw or .return when the delegate iterator has no .throw
|
|
// method always terminates the yield* loop.
|
|
context.delegate = null;
|
|
|
|
if (context.method === "throw") {
|
|
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
if (delegate.iterator["return"]) {
|
|
// If the delegate iterator has a return method, give it a
|
|
// chance to clean up.
|
|
context.method = "return";
|
|
context.arg = undefined$1;
|
|
maybeInvokeDelegate(delegate, context);
|
|
|
|
if (context.method === "throw") {
|
|
// If maybeInvokeDelegate(context) changed context.method from
|
|
// "return" to "throw", let that override the TypeError below.
|
|
return ContinueSentinel;
|
|
}
|
|
}
|
|
|
|
context.method = "throw";
|
|
context.arg = new TypeError(
|
|
"The iterator does not provide a 'throw' method");
|
|
}
|
|
|
|
return ContinueSentinel;
|
|
}
|
|
|
|
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
|
|
if (record.type === "throw") {
|
|
context.method = "throw";
|
|
context.arg = record.arg;
|
|
context.delegate = null;
|
|
return ContinueSentinel;
|
|
}
|
|
|
|
var info = record.arg;
|
|
|
|
if (! info) {
|
|
context.method = "throw";
|
|
context.arg = new TypeError("iterator result is not an object");
|
|
context.delegate = null;
|
|
return ContinueSentinel;
|
|
}
|
|
|
|
if (info.done) {
|
|
// Assign the result of the finished delegate to the temporary
|
|
// variable specified by delegate.resultName (see delegateYield).
|
|
context[delegate.resultName] = info.value;
|
|
|
|
// Resume execution at the desired location (see delegateYield).
|
|
context.next = delegate.nextLoc;
|
|
|
|
// If context.method was "throw" but the delegate handled the
|
|
// exception, let the outer generator proceed normally. If
|
|
// context.method was "next", forget context.arg since it has been
|
|
// "consumed" by the delegate iterator. If context.method was
|
|
// "return", allow the original .return call to continue in the
|
|
// outer generator.
|
|
if (context.method !== "return") {
|
|
context.method = "next";
|
|
context.arg = undefined$1;
|
|
}
|
|
|
|
} else {
|
|
// Re-yield the result returned by the delegate method.
|
|
return info;
|
|
}
|
|
|
|
// The delegate iterator is finished, so forget it and continue with
|
|
// the outer generator.
|
|
context.delegate = null;
|
|
return ContinueSentinel;
|
|
}
|
|
|
|
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
// unified ._invoke helper method.
|
|
defineIteratorMethods(Gp);
|
|
|
|
define(Gp, toStringTagSymbol, "Generator");
|
|
|
|
// A Generator should always return itself as the iterator object when the
|
|
// @@iterator function is called on it. Some browsers' implementations of the
|
|
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
// object to not be returned from this call. This ensures that doesn't happen.
|
|
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
define(Gp, iteratorSymbol, function() {
|
|
return this;
|
|
});
|
|
|
|
define(Gp, "toString", function() {
|
|
return "[object Generator]";
|
|
});
|
|
|
|
function pushTryEntry(locs) {
|
|
var entry = { tryLoc: locs[0] };
|
|
|
|
if (1 in locs) {
|
|
entry.catchLoc = locs[1];
|
|
}
|
|
|
|
if (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) {
|
|
// The root entry object (effectively a try statement without a catch
|
|
// or a finally block) gives us a place to store values thrown from
|
|
// locations where there is no enclosing try statement.
|
|
this.tryEntries = [{ tryLoc: "root" }];
|
|
tryLocsList.forEach(pushTryEntry, this);
|
|
this.reset(true);
|
|
}
|
|
|
|
exports.keys = function(object) {
|
|
var keys = [];
|
|
for (var key in object) {
|
|
keys.push(key);
|
|
}
|
|
keys.reverse();
|
|
|
|
// Rather than returning an object with a next method, we keep
|
|
// things simple and return the next function itself.
|
|
return function next() {
|
|
while (keys.length) {
|
|
var key = keys.pop();
|
|
if (key in object) {
|
|
next.value = key;
|
|
next.done = false;
|
|
return next;
|
|
}
|
|
}
|
|
|
|
// To avoid creating an additional object, we just hang the .value
|
|
// and .done properties off the next function object itself. This
|
|
// also ensures that the minifier will not anonymize the function.
|
|
next.done = true;
|
|
return next;
|
|
};
|
|
};
|
|
|
|
function values(iterable) {
|
|
if (iterable) {
|
|
var iteratorMethod = iterable[iteratorSymbol];
|
|
if (iteratorMethod) {
|
|
return iteratorMethod.call(iterable);
|
|
}
|
|
|
|
if (typeof iterable.next === "function") {
|
|
return iterable;
|
|
}
|
|
|
|
if (!isNaN(iterable.length)) {
|
|
var i = -1, next = function next() {
|
|
while (++i < iterable.length) {
|
|
if (hasOwn.call(iterable, i)) {
|
|
next.value = iterable[i];
|
|
next.done = false;
|
|
return next;
|
|
}
|
|
}
|
|
|
|
next.value = undefined$1;
|
|
next.done = true;
|
|
|
|
return next;
|
|
};
|
|
|
|
return next.next = next;
|
|
}
|
|
}
|
|
|
|
// Return an iterator with no values.
|
|
return { next: doneResult };
|
|
}
|
|
exports.values = values;
|
|
|
|
function doneResult() {
|
|
return { value: undefined$1, done: true };
|
|
}
|
|
|
|
Context.prototype = {
|
|
constructor: Context,
|
|
|
|
reset: function(skipTempReset) {
|
|
this.prev = 0;
|
|
this.next = 0;
|
|
// Resetting context._sent for legacy support of Babel's
|
|
// function.sent implementation.
|
|
this.sent = this._sent = undefined$1;
|
|
this.done = false;
|
|
this.delegate = null;
|
|
|
|
this.method = "next";
|
|
this.arg = undefined$1;
|
|
|
|
this.tryEntries.forEach(resetTryEntry);
|
|
|
|
if (!skipTempReset) {
|
|
for (var name in this) {
|
|
// Not sure about the optimal order of these conditions:
|
|
if (name.charAt(0) === "t" &&
|
|
hasOwn.call(this, name) &&
|
|
!isNaN(+name.slice(1))) {
|
|
this[name] = undefined$1;
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
stop: function() {
|
|
this.done = true;
|
|
|
|
var rootEntry = this.tryEntries[0];
|
|
var rootRecord = rootEntry.completion;
|
|
if (rootRecord.type === "throw") {
|
|
throw rootRecord.arg;
|
|
}
|
|
|
|
return this.rval;
|
|
},
|
|
|
|
dispatchException: function(exception) {
|
|
if (this.done) {
|
|
throw exception;
|
|
}
|
|
|
|
var context = this;
|
|
function handle(loc, caught) {
|
|
record.type = "throw";
|
|
record.arg = exception;
|
|
context.next = loc;
|
|
|
|
if (caught) {
|
|
// If the dispatched exception was caught by a catch block,
|
|
// then let that catch block handle the exception normally.
|
|
context.method = "next";
|
|
context.arg = undefined$1;
|
|
}
|
|
|
|
return !! caught;
|
|
}
|
|
|
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
var entry = this.tryEntries[i];
|
|
var record = entry.completion;
|
|
|
|
if (entry.tryLoc === "root") {
|
|
// Exception thrown outside of any try block that could handle
|
|
// it, so set the completion value of the entire function to
|
|
// throw the exception.
|
|
return handle("end");
|
|
}
|
|
|
|
if (entry.tryLoc <= this.prev) {
|
|
var hasCatch = hasOwn.call(entry, "catchLoc");
|
|
var hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
|
|
if (hasCatch && hasFinally) {
|
|
if (this.prev < entry.catchLoc) {
|
|
return handle(entry.catchLoc, true);
|
|
} else if (this.prev < entry.finallyLoc) {
|
|
return handle(entry.finallyLoc);
|
|
}
|
|
|
|
} else if (hasCatch) {
|
|
if (this.prev < entry.catchLoc) {
|
|
return handle(entry.catchLoc, true);
|
|
}
|
|
|
|
} else if (hasFinally) {
|
|
if (this.prev < entry.finallyLoc) {
|
|
return handle(entry.finallyLoc);
|
|
}
|
|
|
|
} else {
|
|
throw new Error("try statement without catch or finally");
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
if (finallyEntry &&
|
|
(type === "break" ||
|
|
type === "continue") &&
|
|
finallyEntry.tryLoc <= arg &&
|
|
arg <= finallyEntry.finallyLoc) {
|
|
// Ignore the finally entry if control is not jumping to a
|
|
// location outside the try/catch block.
|
|
finallyEntry = null;
|
|
}
|
|
|
|
var record = finallyEntry ? finallyEntry.completion : {};
|
|
record.type = type;
|
|
record.arg = arg;
|
|
|
|
if (finallyEntry) {
|
|
this.method = "next";
|
|
this.next = finallyEntry.finallyLoc;
|
|
return ContinueSentinel;
|
|
}
|
|
|
|
return this.complete(record);
|
|
},
|
|
|
|
complete: function(record, afterLoc) {
|
|
if (record.type === "throw") {
|
|
throw record.arg;
|
|
}
|
|
|
|
if (record.type === "break" ||
|
|
record.type === "continue") {
|
|
this.next = record.arg;
|
|
} else if (record.type === "return") {
|
|
this.rval = this.arg = record.arg;
|
|
this.method = "return";
|
|
this.next = "end";
|
|
} else if (record.type === "normal" && afterLoc) {
|
|
this.next = afterLoc;
|
|
}
|
|
|
|
return ContinueSentinel;
|
|
},
|
|
|
|
finish: function(finallyLoc) {
|
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
var entry = this.tryEntries[i];
|
|
if (entry.finallyLoc === finallyLoc) {
|
|
this.complete(entry.completion, entry.afterLoc);
|
|
resetTryEntry(entry);
|
|
return 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 (record.type === "throw") {
|
|
var thrown = record.arg;
|
|
resetTryEntry(entry);
|
|
}
|
|
return thrown;
|
|
}
|
|
}
|
|
|
|
// The context.catch method must only be called with a location
|
|
// argument that corresponds to a known catch block.
|
|
throw new Error("illegal catch attempt");
|
|
},
|
|
|
|
delegateYield: function(iterable, resultName, nextLoc) {
|
|
this.delegate = {
|
|
iterator: values(iterable),
|
|
resultName: resultName,
|
|
nextLoc: nextLoc
|
|
};
|
|
|
|
if (this.method === "next") {
|
|
// Deliberately forget the last sent value so that we don't
|
|
// accidentally pass it on to the delegate.
|
|
this.arg = undefined$1;
|
|
}
|
|
|
|
return ContinueSentinel;
|
|
}
|
|
};
|
|
|
|
// Regardless of whether this script is executing as a CommonJS module
|
|
// or not, return the runtime object so that we can declare the variable
|
|
// regeneratorRuntime in the outer scope, which allows this module to be
|
|
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
return exports;
|
|
|
|
}(
|
|
// If this script is executing as a CommonJS module, use module.exports
|
|
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
// object. Either way, the resulting object will be used to initialize
|
|
// the regeneratorRuntime variable at the top of this file.
|
|
module.exports
|
|
));
|
|
|
|
try {
|
|
regeneratorRuntime = runtime;
|
|
} catch (accidentalStrictMode) {
|
|
// This module should not be running in strict mode, so the above
|
|
// assignment should always work unless something is misconfigured. Just
|
|
// in case runtime.js accidentally runs in strict mode, in modern engines
|
|
// we can explicitly access globalThis. In older engines we can escape
|
|
// strict mode using a global Function call. This could conceivably fail
|
|
// if a Content Security Policy forbids using Function, but in that case
|
|
// the proper solution is to fix the accidental strict mode problem. If
|
|
// you've misconfigured your bundler to force strict mode and applied a
|
|
// CSP to forbid Function, and you're not willing to fix either of those
|
|
// problems, please detail your unique predicament in a GitHub issue.
|
|
if (typeof globalThis === "object") {
|
|
globalThis.regeneratorRuntime = runtime;
|
|
} else {
|
|
Function("r", "regeneratorRuntime = r")(runtime);
|
|
}
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Error that may get thrown if IPFS returns nothing for a given uri.
|
|
* @public
|
|
*/
|
|
var NotFoundError = /*#__PURE__*/function (_Error) {
|
|
_inheritsLoose(NotFoundError, _Error);
|
|
|
|
/** @internal */
|
|
function NotFoundError(identifier) {
|
|
return _Error.call(this, identifier ? "Object with id " + identifier + " NOT FOUND" : "NOT_FOUND") || this;
|
|
}
|
|
|
|
return NotFoundError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Error that may get thrown if an invalid address was passed
|
|
* @public
|
|
*/
|
|
|
|
var InvalidAddressError = /*#__PURE__*/function (_Error2) {
|
|
_inheritsLoose(InvalidAddressError, _Error2);
|
|
|
|
/** @internal */
|
|
function InvalidAddressError(address) {
|
|
return _Error2.call(this, address ? "'" + address + "' is an invalid address" : "Invalid address passed") || this;
|
|
}
|
|
|
|
return InvalidAddressError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var MissingRoleError = /*#__PURE__*/function (_Error3) {
|
|
_inheritsLoose(MissingRoleError, _Error3);
|
|
|
|
/** @internal */
|
|
|
|
/** @internal */
|
|
function MissingRoleError(address, role) {
|
|
return _Error3.call(this, "MISSING ROLE: " + address + " does not have the '" + role + "' role") || this;
|
|
}
|
|
|
|
return MissingRoleError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var AssetNotFoundError = /*#__PURE__*/function (_Error4) {
|
|
_inheritsLoose(AssetNotFoundError, _Error4);
|
|
|
|
/** @internal */
|
|
|
|
/** @internal */
|
|
function AssetNotFoundError(message) {
|
|
if (message === void 0) {
|
|
message = "The asset you're trying to use could not be found.";
|
|
}
|
|
|
|
return _Error4.call(this, "message: " + message) || this;
|
|
}
|
|
|
|
return AssetNotFoundError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var UploadError = /*#__PURE__*/function (_Error5) {
|
|
_inheritsLoose(UploadError, _Error5);
|
|
|
|
/** @internal */
|
|
function UploadError(message) {
|
|
return _Error5.call(this, "UPLOAD_FAILED: " + message) || this;
|
|
}
|
|
|
|
return UploadError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var FileNameMissingError = /*#__PURE__*/function (_Error6) {
|
|
_inheritsLoose(FileNameMissingError, _Error6);
|
|
|
|
/** @internal */
|
|
function FileNameMissingError() {
|
|
return _Error6.call(this, "File name is required when object is not a `File` type object.") || this;
|
|
}
|
|
|
|
return FileNameMissingError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var DuplicateFileNameError = /*#__PURE__*/function (_Error7) {
|
|
_inheritsLoose(DuplicateFileNameError, _Error7);
|
|
|
|
/** @internal */
|
|
function DuplicateFileNameError(fileName) {
|
|
return _Error7.call(this, "DUPLICATE_FILE_NAME_ERROR: File name " + fileName + " was passed for more than one file.") || this;
|
|
}
|
|
|
|
return DuplicateFileNameError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var NotEnoughTokensError = /*#__PURE__*/function (_Error8) {
|
|
_inheritsLoose(NotEnoughTokensError, _Error8);
|
|
|
|
/** @internal */
|
|
function NotEnoughTokensError(contractAddress, quantity, available) {
|
|
return _Error8.call(this, "BALANCE ERROR: you do not have enough balance on contract " + contractAddress + " to use " + quantity + " tokens. You have " + available + " tokens available.") || this;
|
|
}
|
|
|
|
return NotEnoughTokensError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var MissingOwnerRoleError = /*#__PURE__*/function (_Error9) {
|
|
_inheritsLoose(MissingOwnerRoleError, _Error9);
|
|
|
|
/** @internal */
|
|
function MissingOwnerRoleError() {
|
|
return _Error9.call(this, "LIST ERROR: you should be the owner of the token to list it.") || this;
|
|
}
|
|
|
|
return MissingOwnerRoleError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var QuantityAboveLimitError = /*#__PURE__*/function (_Error10) {
|
|
_inheritsLoose(QuantityAboveLimitError, _Error10);
|
|
|
|
/** @internal */
|
|
function QuantityAboveLimitError(quantity) {
|
|
return _Error10.call(this, "BUY ERROR: You cannot buy more than " + quantity + " tokens") || this;
|
|
}
|
|
|
|
return QuantityAboveLimitError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when data fails to fetch from storage.
|
|
*/
|
|
|
|
var FetchError = /*#__PURE__*/function (_Error11) {
|
|
_inheritsLoose(FetchError, _Error11);
|
|
|
|
/** @internal */
|
|
function FetchError(message, innerError) {
|
|
var _this;
|
|
|
|
_this = _Error11.call(this, "FETCH_FAILED: " + message) || this;
|
|
_this.innerError = void 0;
|
|
_this.innerError = innerError;
|
|
return _this;
|
|
}
|
|
|
|
return FetchError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when attempting to create a snapshot with duplicate leafs
|
|
*/
|
|
|
|
var DuplicateLeafsError = /*#__PURE__*/function (_Error12) {
|
|
_inheritsLoose(DuplicateLeafsError, _Error12);
|
|
|
|
function DuplicateLeafsError(message) {
|
|
return _Error12.call(this, "DUPLICATE_LEAFS" + (message ? " : " + message : "")) || this;
|
|
}
|
|
|
|
return DuplicateLeafsError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when attempting to update/cancel an auction that already started
|
|
*/
|
|
|
|
var AuctionAlreadyStartedError = /*#__PURE__*/function (_Error13) {
|
|
_inheritsLoose(AuctionAlreadyStartedError, _Error13);
|
|
|
|
function AuctionAlreadyStartedError(id) {
|
|
return _Error13.call(this, "Auction already started with existing bid" + (id ? ", id: " + id : "")) || this;
|
|
}
|
|
|
|
return AuctionAlreadyStartedError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
var FunctionDeprecatedError = /*#__PURE__*/function (_Error14) {
|
|
_inheritsLoose(FunctionDeprecatedError, _Error14);
|
|
|
|
/** @internal */
|
|
function FunctionDeprecatedError(message) {
|
|
return _Error14.call(this, "FUNCTION DEPRECATED. " + (message ? "Use " + message + " instead" : "")) || this;
|
|
}
|
|
|
|
return FunctionDeprecatedError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when trying to retrieve a listing from a marketplace that doesn't exist
|
|
*/
|
|
|
|
var ListingNotFoundError = /*#__PURE__*/function (_Error15) {
|
|
_inheritsLoose(ListingNotFoundError, _Error15);
|
|
|
|
function ListingNotFoundError(marketplaceContractAddress, listingId) {
|
|
return _Error15.call(this, "Could not find listing." + (marketplaceContractAddress ? " marketplace address: " + marketplaceContractAddress : "") + (listingId ? " listing id: " + listingId : "")) || this;
|
|
}
|
|
|
|
return ListingNotFoundError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when trying to retrieve a listing of the wrong type
|
|
*/
|
|
|
|
var WrongListingTypeError = /*#__PURE__*/function (_Error16) {
|
|
_inheritsLoose(WrongListingTypeError, _Error16);
|
|
|
|
function WrongListingTypeError(marketplaceContractAddress, listingId, actualType, expectedType) {
|
|
return _Error16.call(this, "Incorrect listing type. Are you sure you're using the right method?." + (marketplaceContractAddress ? " marketplace address: " + marketplaceContractAddress : "") + (listingId ? " listing id: " + listingId : "") + (expectedType ? " expected type: " + expectedType : "") + (actualType ? " actual type: " + actualType : "")) || this;
|
|
}
|
|
|
|
return WrongListingTypeError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when attempting to transfer an asset that has restricted transferability
|
|
*/
|
|
|
|
var RestrictedTransferError = /*#__PURE__*/function (_Error17) {
|
|
_inheritsLoose(RestrictedTransferError, _Error17);
|
|
|
|
function RestrictedTransferError(assetAddress) {
|
|
return _Error17.call(this, "Failed to transfer asset, transfer is restricted." + (assetAddress ? " Address : " + assetAddress : "")) || this;
|
|
}
|
|
|
|
return RestrictedTransferError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when attempting to execute an admin-role function.
|
|
*/
|
|
|
|
var AdminRoleMissingError = /*#__PURE__*/function (_Error18) {
|
|
_inheritsLoose(AdminRoleMissingError, _Error18);
|
|
|
|
function AdminRoleMissingError(address, contractAddress, message) {
|
|
if (message === void 0) {
|
|
message = "Failed to execute transaction";
|
|
}
|
|
|
|
return _Error18.call(this, message + ", admin role is missing" + (address ? " on address: " + address : "") + (contractAddress ? " on contract: " + contractAddress : "")) || this;
|
|
}
|
|
|
|
return AdminRoleMissingError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
/**
|
|
* Thrown when attempting to close an auction that has not ended
|
|
*/
|
|
|
|
var AuctionHasNotEndedError = /*#__PURE__*/function (_Error19) {
|
|
_inheritsLoose(AuctionHasNotEndedError, _Error19);
|
|
|
|
function AuctionHasNotEndedError(id, endTime) {
|
|
return _Error19.call(this, "Auction has not ended yet" + (id ? ", id: " + id : "") + (endTime ? ", end time: " + endTime.toString() : "")) || this;
|
|
}
|
|
|
|
return AuctionHasNotEndedError;
|
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
|
|
if (!globalThis.FormData) {
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
globalThis.FormData = /*#__PURE__*/require("form-data");
|
|
}
|
|
|
|
if (!globalThis.File) {
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
globalThis.File = /*#__PURE__*/require("@web-std/file").File;
|
|
}
|
|
/**
|
|
*
|
|
* @param ipfsUrl - the ipfs:// uri
|
|
* @param gatewayUrl - the gateway url
|
|
* @returns the fully formed IPFS url
|
|
* @internal
|
|
*/
|
|
|
|
|
|
function replaceIpfsWithGateway(ipfsUrl, gatewayUrl) {
|
|
if (!ipfsUrl || typeof ipfsUrl !== "string") {
|
|
return "";
|
|
}
|
|
|
|
if (!gatewayUrl.endsWith("/")) {
|
|
gatewayUrl = gatewayUrl + "/";
|
|
}
|
|
|
|
return ipfsUrl.replace("ipfs://", gatewayUrl);
|
|
}
|
|
function recursiveResolveGatewayUrl(json, storage) {
|
|
if (typeof json === "object") {
|
|
var keylist = Object.keys(json);
|
|
keylist.forEach(function (key) {
|
|
if (typeof json[key] === "object") {
|
|
json[key] = recursiveResolveGatewayUrl(json[key], storage);
|
|
} else if (typeof json[key] === "string") {
|
|
json[key] = storage.resolveFullUrl(json[key]);
|
|
}
|
|
});
|
|
}
|
|
|
|
return json;
|
|
}
|
|
/**
|
|
* A helper function to upload arbitrary data to IPFS and return the resulting IPFS uri.
|
|
* @param data - stringified JSON || File
|
|
* @param contractAddress - (Optional) the contract address to associate the data with
|
|
* @param signerAddress - (Optional) the wallet address of the actor that is uploading the file
|
|
* @returns The `ipfs://<hash>` uri of the uploaded file
|
|
* @public
|
|
*/
|
|
|
|
function uploadToIPFS(_x, _x2, _x3) {
|
|
return _uploadToIPFS.apply(this, arguments);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function _uploadToIPFS() {
|
|
_uploadToIPFS = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(data, contractAddress, signerAddress) {
|
|
var headers, formData, res, body;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
headers = {
|
|
"X-App-Name": "CONSOLE-TS-SDK-" + contractAddress,
|
|
"X-Public-Address": signerAddress || ""
|
|
};
|
|
formData = new FormData();
|
|
formData.append("file", data);
|
|
_context.next = 5;
|
|
return fetch("https://upload.nftlabs.co/upload", {
|
|
method: "POST",
|
|
body: formData,
|
|
headers: headers
|
|
});
|
|
|
|
case 5:
|
|
res = _context.sent;
|
|
_context.prev = 6;
|
|
_context.next = 9;
|
|
return res.json();
|
|
|
|
case 9:
|
|
body = _context.sent;
|
|
return _context.abrupt("return", body.IpfsUri);
|
|
|
|
case 13:
|
|
_context.prev = 13;
|
|
_context.t0 = _context["catch"](6);
|
|
throw new UploadError("Failed to upload to IPFS: " + _context.t0);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[6, 13]]);
|
|
}));
|
|
return _uploadToIPFS.apply(this, arguments);
|
|
}
|
|
|
|
function uploadMetadata(_x4, _x5, _x6) {
|
|
return _uploadMetadata.apply(this, arguments);
|
|
}
|
|
|
|
function _uploadMetadata() {
|
|
_uploadMetadata = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(metadata, contractAddress, signerAddress) {
|
|
var _fileHandler, _fileHandler2;
|
|
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_fileHandler2 = function _fileHandler4() {
|
|
_fileHandler2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(object) {
|
|
var keys, key, val, shouldUpload;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
keys = Object.keys(object);
|
|
_context2.t0 = runtime_1.keys(keys);
|
|
|
|
case 2:
|
|
if ((_context2.t1 = _context2.t0()).done) {
|
|
_context2.next = 18;
|
|
break;
|
|
}
|
|
|
|
key = _context2.t1.value;
|
|
val = object[keys[key]];
|
|
shouldUpload = val instanceof File || val instanceof Buffer;
|
|
|
|
if (!shouldUpload) {
|
|
_context2.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context2.next = 9;
|
|
return uploadToIPFS(object[keys[key]], contractAddress, signerAddress);
|
|
|
|
case 9:
|
|
object[keys[key]] = _context2.sent;
|
|
|
|
case 10:
|
|
if (!(shouldUpload && typeof object[keys[key]] !== "string")) {
|
|
_context2.next = 12;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Upload to IPFS failed");
|
|
|
|
case 12:
|
|
if (!(typeof val === "object")) {
|
|
_context2.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context2.next = 15;
|
|
return _fileHandler(object[keys[key]]);
|
|
|
|
case 15:
|
|
object[keys[key]] = _context2.sent;
|
|
|
|
case 16:
|
|
_context2.next = 2;
|
|
break;
|
|
|
|
case 18:
|
|
return _context2.abrupt("return", object);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2);
|
|
}));
|
|
return _fileHandler2.apply(this, arguments);
|
|
};
|
|
|
|
_fileHandler = function _fileHandler3(_x7) {
|
|
return _fileHandler2.apply(this, arguments);
|
|
};
|
|
|
|
if (!(typeof metadata === "string")) {
|
|
_context3.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context3.abrupt("return", metadata);
|
|
|
|
case 4:
|
|
_context3.next = 6;
|
|
return _fileHandler(metadata);
|
|
|
|
case 6:
|
|
metadata = _context3.sent;
|
|
_context3.next = 9;
|
|
return uploadToIPFS(JSON.stringify(metadata), contractAddress, signerAddress);
|
|
|
|
case 9:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3);
|
|
}));
|
|
return _uploadMetadata.apply(this, arguments);
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var InterfaceId_IERC721 = /*#__PURE__*/arrayify("0x80ac58cd");
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var InterfaceId_IERC1155 = /*#__PURE__*/arrayify("0xd9b67a26");
|
|
var contractUriABI = [{
|
|
inputs: [],
|
|
name: "contractURI",
|
|
outputs: [{
|
|
internalType: "string",
|
|
name: "",
|
|
type: "string"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getContractMetadata(_x, _x2, _x3, _x4) {
|
|
return _getContractMetadata.apply(this, arguments);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function _getContractMetadata() {
|
|
_getContractMetadata = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, address, storage, resolveGateway) {
|
|
var contract, uri, meta, json, entity;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
if (resolveGateway === void 0) {
|
|
resolveGateway = false;
|
|
}
|
|
|
|
contract = new Contract(address, contractUriABI, provider);
|
|
_context.next = 4;
|
|
return contract.contractURI();
|
|
|
|
case 4:
|
|
uri = _context.sent;
|
|
_context.next = 7;
|
|
return storage.get(uri);
|
|
|
|
case 7:
|
|
meta = _context.sent;
|
|
_context.prev = 8;
|
|
json = JSON.parse(meta);
|
|
|
|
if (resolveGateway) {
|
|
json = recursiveResolveGatewayUrl(json, storage);
|
|
}
|
|
|
|
entity = _extends({}, json);
|
|
return _context.abrupt("return", entity);
|
|
|
|
case 15:
|
|
_context.prev = 15;
|
|
_context.t0 = _context["catch"](8);
|
|
throw new Error("Failed to parse metadata for contract " + address + " with uri " + uri);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[8, 15]]);
|
|
}));
|
|
return _getContractMetadata.apply(this, arguments);
|
|
}
|
|
|
|
function isContract(_x5, _x6) {
|
|
return _isContract.apply(this, arguments);
|
|
}
|
|
|
|
function _isContract() {
|
|
_isContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(provider, address) {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return provider.getCode(address);
|
|
|
|
case 2:
|
|
_context2.t0 = _context2.sent;
|
|
return _context2.abrupt("return", _context2.t0 !== "0x");
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2);
|
|
}));
|
|
return _isContract.apply(this, arguments);
|
|
}
|
|
|
|
var ChainId;
|
|
|
|
(function (ChainId) {
|
|
ChainId[ChainId["Mainnet"] = 1] = "Mainnet";
|
|
ChainId[ChainId["Ropsten"] = 3] = "Ropsten";
|
|
ChainId[ChainId["Rinkeby"] = 4] = "Rinkeby";
|
|
ChainId[ChainId["Goerli"] = 5] = "Goerli";
|
|
ChainId[ChainId["Kovan"] = 42] = "Kovan";
|
|
ChainId[ChainId["BSC"] = 56] = "BSC";
|
|
ChainId[ChainId["xDai"] = 100] = "xDai";
|
|
ChainId[ChainId["Polygon"] = 137] = "Polygon";
|
|
ChainId[ChainId["Moonriver"] = 1285] = "Moonriver";
|
|
ChainId[ChainId["Mumbai"] = 80001] = "Mumbai";
|
|
ChainId[ChainId["Harmony"] = 1666600000] = "Harmony";
|
|
ChainId[ChainId["Localhost"] = 1337] = "Localhost";
|
|
ChainId[ChainId["Hardhat"] = 31337] = "Hardhat";
|
|
ChainId[ChainId["Fantom"] = 250] = "Fantom";
|
|
ChainId[ChainId["FantomTestnet"] = 4002] = "FantomTestnet";
|
|
ChainId[ChainId["Avalanche"] = 43114] = "Avalanche";
|
|
ChainId[ChainId["AvalancheFujiTestnet"] = 43113] = "AvalancheFujiTestnet";
|
|
})(ChainId || (ChainId = {}));
|
|
|
|
var SUPPORTED_CHAIN_IDS = [ChainId.Mainnet, ChainId.Rinkeby, ChainId.Polygon, ChainId.Mumbai, ChainId.Fantom, ChainId.FantomTestnet, ChainId.Avalanche, ChainId.AvalancheFujiTestnet];
|
|
|
|
var _NATIVE_TOKENS;
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
var NATIVE_TOKENS = (_NATIVE_TOKENS = {}, _NATIVE_TOKENS[ChainId.Mainnet] = {
|
|
name: "Ether",
|
|
symbol: "ETH",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
name: "Wrapped Ether",
|
|
symbol: "WETH"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Rinkeby] = {
|
|
name: "Ether",
|
|
symbol: "ETH",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0xc778417E063141139Fce010982780140Aa0cD5Ab",
|
|
name: "Wrapped Ether",
|
|
symbol: "WETH"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Polygon] = {
|
|
name: "Matic",
|
|
symbol: "MATIC",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
|
|
name: "Wrapped Matic",
|
|
symbol: "WMATIC"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Mumbai] = {
|
|
name: "Matic",
|
|
symbol: "MATIC",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889",
|
|
name: "Wrapped Matic",
|
|
symbol: "WMATIC"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Avalanche] = {
|
|
name: "Avalanche",
|
|
symbol: "AVAX",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7",
|
|
name: "Wrapped AVAX",
|
|
symbol: "WAVAX"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.AvalancheFujiTestnet] = {
|
|
name: "Avalanche",
|
|
symbol: "AVAX",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0xd00ae08403B9bbb9124bB305C09058E32C39A48c",
|
|
name: "Wrapped AVAX",
|
|
symbol: "WAVAX"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Fantom] = {
|
|
name: "Fantom",
|
|
symbol: "FTM",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0x21be370D5312f44cB42ce377BC9b8a0cEF1A4C83",
|
|
name: "Wrapped Fantom",
|
|
symbol: "WFTM"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.FantomTestnet] = {
|
|
name: "Fantom",
|
|
symbol: "FTM",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0xf1277d1Ed8AD466beddF92ef448A132661956621",
|
|
name: "Wrapped Fantom",
|
|
symbol: "WFTM"
|
|
}
|
|
}, _NATIVE_TOKENS[ChainId.Hardhat] = {
|
|
name: "Ether",
|
|
symbol: "ETH",
|
|
decimals: 18,
|
|
wrapped: {
|
|
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
|
|
name: "Wrapped Ether",
|
|
symbol: "WETH"
|
|
}
|
|
}, _NATIVE_TOKENS);
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getCurrencyMetadata(_x, _x2) {
|
|
return _getCurrencyMetadata.apply(this, arguments);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function _getCurrencyMetadata() {
|
|
_getCurrencyMetadata = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(providerOrSigner, asset) {
|
|
var provider, network, nativeToken, erc20, _yield$Promise$all, name, symbol, decimals;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.prev = 0;
|
|
|
|
if (!isNativeToken(asset)) {
|
|
_context.next = 10;
|
|
break;
|
|
}
|
|
|
|
if (Signer.isSigner(providerOrSigner)) {
|
|
provider = providerOrSigner.provider;
|
|
} else {
|
|
provider = providerOrSigner;
|
|
}
|
|
|
|
_context.next = 5;
|
|
return provider.getNetwork();
|
|
|
|
case 5:
|
|
network = _context.sent;
|
|
nativeToken = getNativeTokenByChainId(network.chainId);
|
|
return _context.abrupt("return", {
|
|
name: nativeToken.name,
|
|
symbol: nativeToken.symbol,
|
|
decimals: nativeToken.decimals
|
|
});
|
|
|
|
case 10:
|
|
erc20 = ERC20__factory.connect(asset, providerOrSigner);
|
|
_context.next = 13;
|
|
return Promise.all([erc20.name(), erc20.symbol(), erc20.decimals()]);
|
|
|
|
case 13:
|
|
_yield$Promise$all = _context.sent;
|
|
name = _yield$Promise$all[0];
|
|
symbol = _yield$Promise$all[1];
|
|
decimals = _yield$Promise$all[2];
|
|
return _context.abrupt("return", {
|
|
name: name,
|
|
symbol: symbol,
|
|
decimals: decimals
|
|
});
|
|
|
|
case 18:
|
|
_context.next = 22;
|
|
break;
|
|
|
|
case 20:
|
|
_context.prev = 20;
|
|
_context.t0 = _context["catch"](0);
|
|
|
|
case 22:
|
|
return _context.abrupt("return", {
|
|
name: "",
|
|
symbol: "",
|
|
decimals: 0
|
|
});
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[0, 20]]);
|
|
}));
|
|
return _getCurrencyMetadata.apply(this, arguments);
|
|
}
|
|
|
|
function getCurrencyValue(_x3, _x4, _x5) {
|
|
return _getCurrencyValue.apply(this, arguments);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function _getCurrencyValue() {
|
|
_getCurrencyValue = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(providerOrSigner, asset, price) {
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return getCurrencyMetadata(providerOrSigner, asset);
|
|
|
|
case 2:
|
|
metadata = _context2.sent;
|
|
return _context2.abrupt("return", _extends({}, metadata, {
|
|
value: price.toString(),
|
|
displayValue: formatUnits(price, metadata.decimals)
|
|
}));
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2);
|
|
}));
|
|
return _getCurrencyValue.apply(this, arguments);
|
|
}
|
|
|
|
function isNativeToken(tokenAddress) {
|
|
return tokenAddress.toLowerCase() === NATIVE_TOKEN_ADDRESS || tokenAddress.toLowerCase() === AddressZero;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getCurrencyBalance(_x6, _x7, _x8) {
|
|
return _getCurrencyBalance.apply(this, arguments);
|
|
}
|
|
|
|
function _getCurrencyBalance() {
|
|
_getCurrencyBalance = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(providerOrSigner, tokenAddress, walletAddress) {
|
|
var provider, balance, erc20;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
provider = getProvider(providerOrSigner);
|
|
|
|
if (!isNativeToken(tokenAddress)) {
|
|
_context3.next = 7;
|
|
break;
|
|
}
|
|
|
|
_context3.next = 4;
|
|
return provider.getBalance(walletAddress);
|
|
|
|
case 4:
|
|
balance = _context3.sent;
|
|
_context3.next = 18;
|
|
break;
|
|
|
|
case 7:
|
|
_context3.prev = 7;
|
|
erc20 = ERC20__factory.connect(tokenAddress, provider);
|
|
_context3.next = 11;
|
|
return erc20.balanceOf(walletAddress);
|
|
|
|
case 11:
|
|
balance = _context3.sent;
|
|
_context3.next = 18;
|
|
break;
|
|
|
|
case 14:
|
|
_context3.prev = 14;
|
|
_context3.t0 = _context3["catch"](7);
|
|
console.error(_context3.t0);
|
|
throw new Error("invalid ERC20 token address");
|
|
|
|
case 18:
|
|
return _context3.abrupt("return", getCurrencyValue(providerOrSigner, tokenAddress, balance));
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, null, [[7, 14]]);
|
|
}));
|
|
return _getCurrencyBalance.apply(this, arguments);
|
|
}
|
|
|
|
function getProvider(providerOrSigner) {
|
|
if (Signer.isSigner(providerOrSigner)) {
|
|
return providerOrSigner.provider;
|
|
} else {
|
|
return providerOrSigner;
|
|
}
|
|
}
|
|
|
|
function getNativeTokenByChainId(chainId) {
|
|
return NATIVE_TOKENS[chainId];
|
|
}
|
|
|
|
var _ChainlinkVrf;
|
|
/**
|
|
*
|
|
* @internal
|
|
*/
|
|
|
|
var ChainlinkVrf = (_ChainlinkVrf = {}, _ChainlinkVrf[ChainId.Polygon] = {
|
|
vrfCoordinator: "0x3d2341ADb2D31f1c5530cDC622016af293177AE0",
|
|
linkTokenAddress: "0xb0897686c545045aFc77CF20eC7A532E3120E0F1",
|
|
keyHash: "0xf86195cf7690c55907b2b611ebb7343a6f649bff128701cc542f0569e2c549da",
|
|
fees: /*#__PURE__*/ethers.utils.parseEther("0.0001")
|
|
}, _ChainlinkVrf[ChainId.Mumbai] = {
|
|
vrfCoordinator: "0x8C7382F9D8f56b33781fE506E897a4F1e2d17255",
|
|
linkTokenAddress: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB",
|
|
keyHash: "0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4",
|
|
fees: /*#__PURE__*/ethers.utils.parseEther("0.0001")
|
|
}, _ChainlinkVrf[ChainId.Rinkeby] = {
|
|
vrfCoordinator: "0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B",
|
|
linkTokenAddress: "0x01be23585060835e02b77ef475b0cc51aa1e0709",
|
|
keyHash: "0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311",
|
|
fees: /*#__PURE__*/ethers.utils.parseEther("0.1")
|
|
}, _ChainlinkVrf[ChainId.Mainnet] = {
|
|
vrfCoordinator: "0xf0d54349aDdcf704F77AE15b96510dEA15cb7952",
|
|
linkTokenAddress: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
|
|
keyHash: "0xAA77729D3466CA35AE8D28B3BBAC7CC36A5031EFDC430821C02BC31A238AF445",
|
|
fees: /*#__PURE__*/ethers.utils.parseEther("2")
|
|
}, _ChainlinkVrf[ChainId.Hardhat] = {
|
|
vrfCoordinator: "0x8C7382F9D8f56b33781fE506E897a4F1e2d17255",
|
|
linkTokenAddress: "0x326C977E6efc84E512bB9C30f76E30c160eD06FB",
|
|
keyHash: "0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4",
|
|
fees: /*#__PURE__*/ethers.utils.parseEther("0.0001")
|
|
}, _ChainlinkVrf);
|
|
|
|
/**
|
|
* The type of Modules that are available.
|
|
* @public
|
|
*/
|
|
|
|
var ModuleType;
|
|
|
|
(function (ModuleType) {
|
|
ModuleType[ModuleType["CURRENCY"] = 0] = "CURRENCY";
|
|
ModuleType[ModuleType["TOKEN"] = 0] = "TOKEN";
|
|
ModuleType[ModuleType["COLLECTION"] = 1] = "COLLECTION";
|
|
ModuleType[ModuleType["BUNDLE"] = 1] = "BUNDLE";
|
|
ModuleType[ModuleType["NFT"] = 2] = "NFT";
|
|
ModuleType[ModuleType["DYNAMIC_NFT"] = 3] = "DYNAMIC_NFT";
|
|
ModuleType[ModuleType["ACCESS_NFT"] = 4] = "ACCESS_NFT";
|
|
ModuleType[ModuleType["PACK"] = 5] = "PACK";
|
|
ModuleType[ModuleType["MARKET"] = 6] = "MARKET";
|
|
ModuleType[ModuleType["DROP"] = 7] = "DROP";
|
|
ModuleType[ModuleType["DATASTORE"] = 8] = "DATASTORE";
|
|
ModuleType[ModuleType["SPLITS"] = 9] = "SPLITS";
|
|
ModuleType[ModuleType["VOTE"] = 10] = "VOTE";
|
|
ModuleType[ModuleType["BUNDLE_DROP"] = 11] = "BUNDLE_DROP";
|
|
ModuleType[ModuleType["MARKETPLACE"] = 12] = "MARKETPLACE";
|
|
ModuleType[ModuleType["BUNDLE_SIGNATURE"] = 13] = "BUNDLE_SIGNATURE";
|
|
})(ModuleType || (ModuleType = {}));
|
|
/**
|
|
*
|
|
* @param moduleName - a supported module name
|
|
* @returns The {@link ModuleType} or undefined
|
|
* @public
|
|
*/
|
|
|
|
|
|
function convertNameToModuleType(moduleName) {
|
|
return $enum(ModuleType).getValueOrDefault(moduleName == null ? void 0 : moduleName.toUpperCase(), undefined);
|
|
}
|
|
/**
|
|
*
|
|
* @param moduleType - A {@link ModuleType}
|
|
* @returns The name of the given {@link ModuleType} or undefined
|
|
* @public
|
|
*/
|
|
|
|
function convertModuleTypeToName(moduleType) {
|
|
return $enum(ModuleType).getKeyOrDefault(moduleType, undefined);
|
|
}
|
|
|
|
var tokenUriABI = [{
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "tokenId",
|
|
type: "uint256"
|
|
}],
|
|
name: "tokenURI",
|
|
outputs: [{
|
|
internalType: "string",
|
|
name: "",
|
|
type: "string"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}, {
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "",
|
|
type: "uint256"
|
|
}],
|
|
name: "uri",
|
|
outputs: [{
|
|
internalType: "string",
|
|
name: "",
|
|
type: "string"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
/**
|
|
/* @internal
|
|
*/
|
|
|
|
function getMetadataWithoutContract(_x, _x2, _x3, _x4) {
|
|
return _getMetadataWithoutContract.apply(this, arguments);
|
|
}
|
|
/**
|
|
/* @internal
|
|
*/
|
|
|
|
function _getMetadataWithoutContract() {
|
|
_getMetadataWithoutContract = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(provider, contractAddress, tokenId, storage) {
|
|
var contract;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
contract = new Contract(contractAddress, tokenUriABI, provider);
|
|
return _context.abrupt("return", getTokenMetadata(contract, tokenId, storage));
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee);
|
|
}));
|
|
return _getMetadataWithoutContract.apply(this, arguments);
|
|
}
|
|
|
|
function getTokenMetadata(_x5, _x6, _x7) {
|
|
return _getTokenMetadata.apply(this, arguments);
|
|
}
|
|
|
|
function _getTokenMetadata() {
|
|
_getTokenMetadata = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(contract, tokenId, storage) {
|
|
var uri, meta, json, entity;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return getTokenUri(contract, tokenId);
|
|
|
|
case 2:
|
|
uri = _context2.sent;
|
|
|
|
if (uri) {
|
|
_context2.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new NotFoundError();
|
|
|
|
case 5:
|
|
_context2.prev = 5;
|
|
_context2.next = 8;
|
|
return storage.get(uri);
|
|
|
|
case 8:
|
|
meta = _context2.sent;
|
|
json = recursiveResolveGatewayUrl(JSON.parse(meta), storage);
|
|
entity = _extends({}, json, {
|
|
id: tokenId,
|
|
uri: uri
|
|
});
|
|
return _context2.abrupt("return", entity);
|
|
|
|
case 14:
|
|
_context2.prev = 14;
|
|
_context2.t0 = _context2["catch"](5);
|
|
console.error("failed to fetch nft", _context2.t0);
|
|
return _context2.abrupt("return", {
|
|
id: tokenId,
|
|
uri: uri
|
|
});
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, null, [[5, 14]]);
|
|
}));
|
|
return _getTokenMetadata.apply(this, arguments);
|
|
}
|
|
|
|
function getTokenMetadataUsingStorage(_x8, _x9, _x10, _x11) {
|
|
return _getTokenMetadataUsingStorage.apply(this, arguments);
|
|
}
|
|
/**
|
|
/* @internal
|
|
*/
|
|
|
|
function _getTokenMetadataUsingStorage() {
|
|
_getTokenMetadataUsingStorage = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(contractAddress, provider, tokenId, storage) {
|
|
var contract, uri, json, entity;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
contract = new Contract(contractAddress, tokenUriABI, provider);
|
|
_context3.next = 3;
|
|
return getTokenUri(contract, tokenId);
|
|
|
|
case 3:
|
|
uri = _context3.sent;
|
|
|
|
if (uri) {
|
|
_context3.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new NotFoundError();
|
|
|
|
case 6:
|
|
_context3.prev = 6;
|
|
_context3.t0 = JSON;
|
|
_context3.next = 10;
|
|
return storage.get(uri);
|
|
|
|
case 10:
|
|
_context3.t1 = _context3.sent;
|
|
json = _context3.t0.parse.call(_context3.t0, _context3.t1);
|
|
entity = _extends({}, json, {
|
|
id: tokenId
|
|
});
|
|
return _context3.abrupt("return", entity);
|
|
|
|
case 16:
|
|
_context3.prev = 16;
|
|
_context3.t2 = _context3["catch"](6);
|
|
console.error("failed to fetch nft", _context3.t2);
|
|
return _context3.abrupt("return", {
|
|
id: tokenId,
|
|
uri: uri
|
|
});
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, null, [[6, 16]]);
|
|
}));
|
|
return _getTokenMetadataUsingStorage.apply(this, arguments);
|
|
}
|
|
|
|
function getTokenUri(_x12, _x13) {
|
|
return _getTokenUri.apply(this, arguments);
|
|
}
|
|
|
|
function _getTokenUri() {
|
|
_getTokenUri = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(contract, tokenId) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
uri = "";
|
|
_context4.prev = 1;
|
|
_context4.next = 4;
|
|
return contract.tokenURI(tokenId);
|
|
|
|
case 4:
|
|
uri = _context4.sent;
|
|
_context4.next = 9;
|
|
break;
|
|
|
|
case 7:
|
|
_context4.prev = 7;
|
|
_context4.t0 = _context4["catch"](1);
|
|
|
|
case 9:
|
|
if (uri) {
|
|
_context4.next = 18;
|
|
break;
|
|
}
|
|
|
|
_context4.prev = 10;
|
|
_context4.next = 13;
|
|
return contract.uri(tokenId);
|
|
|
|
case 13:
|
|
uri = _context4.sent;
|
|
_context4.next = 18;
|
|
break;
|
|
|
|
case 16:
|
|
_context4.prev = 16;
|
|
_context4.t1 = _context4["catch"](10);
|
|
|
|
case 18:
|
|
if (uri) {
|
|
_context4.next = 27;
|
|
break;
|
|
}
|
|
|
|
_context4.prev = 19;
|
|
_context4.next = 22;
|
|
return contract.uri(tokenId);
|
|
|
|
case 22:
|
|
uri = _context4.sent;
|
|
_context4.next = 27;
|
|
break;
|
|
|
|
case 25:
|
|
_context4.prev = 25;
|
|
_context4.t2 = _context4["catch"](19);
|
|
|
|
case 27:
|
|
return _context4.abrupt("return", uri);
|
|
|
|
case 28:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, null, [[1, 7], [10, 16], [19, 25]]);
|
|
}));
|
|
return _getTokenUri.apply(this, arguments);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @internal
|
|
*/
|
|
|
|
var RolesMap = {
|
|
admin: "admin",
|
|
minter: "minter",
|
|
pauser: "pauser",
|
|
transfer: "transfer",
|
|
editor: "editor",
|
|
lister: "lister",
|
|
asset: "asset"
|
|
};
|
|
/**
|
|
*
|
|
* @internal
|
|
*/
|
|
|
|
var _role = {
|
|
admin: "",
|
|
transfer: "TRANSFER_ROLE",
|
|
minter: "MINTER_ROLE",
|
|
pauser: "PAUSER_ROLE",
|
|
editor: "EDITOR_ROLE",
|
|
lister: "LISTER_ROLE",
|
|
asset: "ASSET_ROLE"
|
|
};
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getRoleHash(role) {
|
|
if (role === "admin") {
|
|
return ethers.utils.hexZeroPad([0], 32);
|
|
}
|
|
|
|
return ethers.utils.id(_role[role]);
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getGasStationUrl(chainId) {
|
|
if (!chainId) {
|
|
return null;
|
|
}
|
|
|
|
if (chainId === ChainId.Polygon) {
|
|
return "https://gasstation-mainnet.matic.network";
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/**
|
|
*
|
|
* @returns the gas price
|
|
* @internal
|
|
*/
|
|
|
|
|
|
function getGasPriceForChain(_x, _x2, _x3) {
|
|
return _getGasPriceForChain.apply(this, arguments);
|
|
}
|
|
|
|
function _getGasPriceForChain() {
|
|
_getGasPriceForChain = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(chainId, speed, maxGasPrice) {
|
|
var gasStationUrl, data, gas;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
gasStationUrl = getGasStationUrl(chainId);
|
|
|
|
if (gasStationUrl) {
|
|
_context.next = 3;
|
|
break;
|
|
}
|
|
|
|
return _context.abrupt("return", null);
|
|
|
|
case 3:
|
|
_context.prev = 3;
|
|
_context.next = 6;
|
|
return fetch(gasStationUrl);
|
|
|
|
case 6:
|
|
_context.next = 8;
|
|
return _context.sent.json();
|
|
|
|
case 8:
|
|
data = _context.sent;
|
|
gas = data[speed];
|
|
|
|
if (chainId === ChainId.Polygon || chainId === ChainId.Mumbai) {
|
|
// the minimum gas on chain is 30, +1 for priority. prevent gas station report false price and cause tx to fail.
|
|
gas = Math.max(gas, 31);
|
|
}
|
|
|
|
if (!(gas > 0)) {
|
|
_context.next = 13;
|
|
break;
|
|
}
|
|
|
|
return _context.abrupt("return", Math.min(gas, maxGasPrice));
|
|
|
|
case 13:
|
|
_context.next = 18;
|
|
break;
|
|
|
|
case 15:
|
|
_context.prev = 15;
|
|
_context.t0 = _context["catch"](3);
|
|
console.error("failed to fetch gas", _context.t0);
|
|
|
|
case 18:
|
|
return _context.abrupt("return", null);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[3, 15]]);
|
|
}));
|
|
return _getGasPriceForChain.apply(this, arguments);
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
* @param condition - any truthy condition to assert
|
|
* @param message - optional message to use if the condition is falsy
|
|
*/
|
|
|
|
function invariant(condition, message) {
|
|
if (!condition) {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* eip712 sign typed data with different wallet handling including ledger live
|
|
* @internal
|
|
*/
|
|
|
|
function signTypedData(_x, _x2, _x3, _x4) {
|
|
return _signTypedData.apply(this, arguments);
|
|
}
|
|
|
|
function _signTypedData() {
|
|
_signTypedData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(signer, domain, types, message) {
|
|
var _provider$provider;
|
|
|
|
var provider, payload, signature, _err$message;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
provider = signer == null ? void 0 : signer.provider;
|
|
|
|
if (provider) {
|
|
_context.next = 3;
|
|
break;
|
|
}
|
|
|
|
throw new Error("missing provider");
|
|
|
|
case 3:
|
|
payload = ethers.utils._TypedDataEncoder.getPayload(domain, types, message);
|
|
signature = ""; // an indirect way for accessing walletconnect's underlying provider
|
|
|
|
if (!(provider != null && (_provider$provider = provider.provider) != null && _provider$provider.isWalletConnect)) {
|
|
_context.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context.t0 = provider;
|
|
_context.next = 9;
|
|
return signer.getAddress();
|
|
|
|
case 9:
|
|
_context.t1 = _context.sent.toLowerCase();
|
|
_context.t2 = JSON.stringify(payload);
|
|
_context.t3 = [_context.t1, _context.t2];
|
|
_context.next = 14;
|
|
return _context.t0.send.call(_context.t0, "eth_signTypedData", _context.t3);
|
|
|
|
case 14:
|
|
signature = _context.sent;
|
|
_context.next = 38;
|
|
break;
|
|
|
|
case 17:
|
|
_context.prev = 17;
|
|
_context.next = 20;
|
|
return signer._signTypedData(domain, types, message);
|
|
|
|
case 20:
|
|
signature = _context.sent;
|
|
_context.next = 38;
|
|
break;
|
|
|
|
case 23:
|
|
_context.prev = 23;
|
|
_context.t4 = _context["catch"](17);
|
|
|
|
if (!(_context.t4 != null && (_err$message = _context.t4.message) != null && _err$message.includes("Method eth_signTypedData_v4 not supported"))) {
|
|
_context.next = 37;
|
|
break;
|
|
}
|
|
|
|
_context.t5 = provider;
|
|
_context.next = 29;
|
|
return signer.getAddress();
|
|
|
|
case 29:
|
|
_context.t6 = _context.sent.toLowerCase();
|
|
_context.t7 = JSON.stringify(payload);
|
|
_context.t8 = [_context.t6, _context.t7];
|
|
_context.next = 34;
|
|
return _context.t5.send.call(_context.t5, "eth_signTypedData", _context.t8);
|
|
|
|
case 34:
|
|
signature = _context.sent;
|
|
_context.next = 38;
|
|
break;
|
|
|
|
case 37:
|
|
throw _context.t4;
|
|
|
|
case 38:
|
|
return _context.abrupt("return", {
|
|
payload: payload,
|
|
signature: ethers.utils.joinSignature(ethers.utils.splitSignature(signature))
|
|
});
|
|
|
|
case 39:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[17, 23]]);
|
|
}));
|
|
return _signTypedData.apply(this, arguments);
|
|
}
|
|
|
|
var EventType;
|
|
|
|
(function (EventType) {
|
|
/**
|
|
* The event is triggered when the transaction is submitted and completed.
|
|
* The transaction is submitted when it is sent to the relayer or the blockchain.
|
|
* The transaction is completed when it is confirmed by the blockchain.
|
|
*
|
|
* status: "submitted" | "completed"
|
|
* transactionHash: string of the transaction hash
|
|
*/
|
|
EventType["Transaction"] = "transaction";
|
|
/**
|
|
* The event is triggered when wallet sign message is requested and completed.
|
|
*
|
|
* status: "submitted" | "completed"
|
|
* message: message to sign
|
|
* signature: signature of the message (only available when status is "completed")
|
|
*/
|
|
|
|
EventType["Signature"] = "signature";
|
|
})(EventType || (EventType = {}));
|
|
|
|
/**
|
|
* The root Module class. All other Modules extend this.
|
|
* @remarks This should never be instantiated directly.
|
|
* @public
|
|
*/
|
|
|
|
var Module = /*#__PURE__*/function () {
|
|
/**
|
|
* @internal
|
|
*/
|
|
function Module(providerOrSigner, address, options, sdk) {
|
|
this.address = void 0;
|
|
this.ipfsGatewayUrl = void 0;
|
|
this.options = void 0;
|
|
this.sdk = void 0;
|
|
this._providerOrSigner = null;
|
|
this._signer = null;
|
|
this.contract = void 0;
|
|
this.readOnlyContract = void 0;
|
|
this.address = address;
|
|
this.options = options;
|
|
this.ipfsGatewayUrl = options.ipfsGatewayUrl;
|
|
this.setProviderOrSigner(providerOrSigner);
|
|
this.contract = this.connectContract();
|
|
this.readOnlyContract = this.options.readOnlyRpcUrl ? this.contract.connect(ethers.getDefaultProvider(this.options.readOnlyRpcUrl)) : this.contract;
|
|
this.sdk = sdk;
|
|
}
|
|
/**
|
|
* @public
|
|
* @returns whether the given contract exists on-chain
|
|
*/
|
|
|
|
|
|
var _proto = Module.prototype;
|
|
|
|
_proto.exists =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _exists = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var provider;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return this.getProvider();
|
|
|
|
case 2:
|
|
provider = _context.sent;
|
|
!provider ? process.env.NODE_ENV !== "production" ? invariant(false, "exists() -- No Provider") : invariant(false) : void 0;
|
|
return _context.abrupt("return", isContract(provider, this.address));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function exists() {
|
|
return _exists.apply(this, arguments);
|
|
}
|
|
|
|
return exists;
|
|
}()
|
|
/**
|
|
* @public
|
|
* Get the metadata of the contract.
|
|
*
|
|
* @param resolveUrls - Whether to resolve the urls in the metadata to a gateway.
|
|
*/
|
|
;
|
|
|
|
_proto.getMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(resolveUrls) {
|
|
var contract, type;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
if (resolveUrls === void 0) {
|
|
resolveUrls = true;
|
|
}
|
|
|
|
_context2.next = 3;
|
|
return this.exists();
|
|
|
|
case 3:
|
|
if (_context2.sent) {
|
|
_context2.next = 7;
|
|
break;
|
|
}
|
|
|
|
process.env.NODE_ENV !== "production" ? invariant(false, "contract does not exist") : invariant(false);
|
|
_context2.next = 8;
|
|
break;
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
contract = this.connectContract();
|
|
type = this.getModuleType();
|
|
_context2.t0 = getContractMetadata;
|
|
_context2.next = 13;
|
|
return this.getProvider();
|
|
|
|
case 13:
|
|
_context2.t1 = _context2.sent;
|
|
_context2.t2 = contract.address;
|
|
_context2.t3 = this.sdk.getStorage();
|
|
_context2.t4 = resolveUrls;
|
|
_context2.next = 19;
|
|
return (0, _context2.t0)(_context2.t1, _context2.t2, _context2.t3, _context2.t4);
|
|
|
|
case 19:
|
|
_context2.t5 = _context2.sent;
|
|
_context2.t6 = contract.address;
|
|
_context2.t7 = type;
|
|
return _context2.abrupt("return", {
|
|
metadata: _context2.t5,
|
|
address: _context2.t6,
|
|
type: _context2.t7
|
|
});
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getMetadata(_x) {
|
|
return _getMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return getMetadata;
|
|
}()
|
|
/**
|
|
* @public
|
|
* Set new metadata on the contract and return it if successful.
|
|
* @param metadata - The metadata to set.
|
|
*/
|
|
;
|
|
|
|
_proto.setMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.exists();
|
|
|
|
case 2:
|
|
if (_context3.sent) {
|
|
_context3.next = 6;
|
|
break;
|
|
}
|
|
|
|
process.env.NODE_ENV !== "production" ? invariant(false, "contract does not exist") : invariant(false);
|
|
_context3.next = 7;
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
_context3.next = 9;
|
|
return uploadMetadata(metadata);
|
|
|
|
case 9:
|
|
uri = _context3.sent;
|
|
_context3.next = 12;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 12:
|
|
return _context3.abrupt("return", this.getMetadata());
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function setMetadata(_x2) {
|
|
return _setMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setMetadata;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.setProviderOrSigner = function setProviderOrSigner(providerOrSigner) {
|
|
this.providerOrSigner = providerOrSigner;
|
|
|
|
if (Signer.isSigner(providerOrSigner)) {
|
|
this.signer = providerOrSigner;
|
|
}
|
|
|
|
this.contract = this.connectContract();
|
|
this.readOnlyContract = this.options.readOnlyRpcUrl ? this.contract.connect(ethers.getDefaultProvider(this.options.readOnlyRpcUrl)) : this.contract;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.clearSigner = function clearSigner() {
|
|
this.signer = null;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getProviderOrSigner = function getProviderOrSigner() {
|
|
return this.signer || this.providerOrSigner;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getSigner = function getSigner() {
|
|
if (Signer.isSigner(this.signer)) {
|
|
return this.signer;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.hasValidSigner = function hasValidSigner() {
|
|
return Signer.isSigner(this.signer);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getSignerAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getSignerAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
var signer;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
signer = this.getSigner();
|
|
!signer ? process.env.NODE_ENV !== "production" ? invariant(false, "Cannot get signer address without valid signer") : invariant(false) : void 0;
|
|
_context4.next = 4;
|
|
return signer.getAddress();
|
|
|
|
case 4:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getSignerAddress() {
|
|
return _getSignerAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getSignerAddress;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getProvider =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getProvider = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
return _context5.abrupt("return", this.readOnlyContract.provider);
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getProvider() {
|
|
return _getProvider.apply(this, arguments);
|
|
}
|
|
|
|
return getProvider;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getChainID =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getChainID = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() {
|
|
var provider, _yield$provider$getNe, chainId;
|
|
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.next = 2;
|
|
return this.getProvider();
|
|
|
|
case 2:
|
|
provider = _context6.sent;
|
|
!provider ? process.env.NODE_ENV !== "production" ? invariant(false, "getChainID() -- No Provider") : invariant(false) : void 0;
|
|
_context6.next = 6;
|
|
return provider.getNetwork();
|
|
|
|
case 6:
|
|
_yield$provider$getNe = _context6.sent;
|
|
chainId = _yield$provider$getNe.chainId;
|
|
return _context6.abrupt("return", chainId);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function getChainID() {
|
|
return _getChainID.apply(this, arguments);
|
|
}
|
|
|
|
return getChainID;
|
|
}()
|
|
/**
|
|
* @virtual
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
throw new Error("connectContract has to be implemented");
|
|
}
|
|
/**
|
|
* @virtual
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
throw new Error("getModuleType has to be implemented");
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getCallOverrides =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getCallOverrides = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
|
|
var chainId, speed, maxGasPrice, gasPriceChain;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.getChainID();
|
|
|
|
case 2:
|
|
chainId = _context7.sent;
|
|
speed = this.options.gasSpeed;
|
|
maxGasPrice = this.options.maxGasPriceInGwei;
|
|
_context7.next = 7;
|
|
return getGasPriceForChain(chainId, speed, maxGasPrice);
|
|
|
|
case 7:
|
|
gasPriceChain = _context7.sent;
|
|
|
|
if (gasPriceChain) {
|
|
_context7.next = 10;
|
|
break;
|
|
}
|
|
|
|
return _context7.abrupt("return", {});
|
|
|
|
case 10:
|
|
return _context7.abrupt("return", {
|
|
gasPrice: ethers.utils.parseUnits(gasPriceChain.toString(), "gwei")
|
|
});
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getCallOverrides() {
|
|
return _getCallOverrides.apply(this, arguments);
|
|
}
|
|
|
|
return getCallOverrides;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.emitTransactionEvent = function emitTransactionEvent(status, transactionHash) {
|
|
this.sdk.event.emit(EventType.Transaction, {
|
|
status: status,
|
|
transactionHash: transactionHash
|
|
});
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.sendTransaction =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _sendTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(fn, args, callOverrides) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
return _context8.abrupt("return", this.sendContractTransaction(this.contract, fn, args, callOverrides));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function sendTransaction(_x3, _x4, _x5) {
|
|
return _sendTransaction.apply(this, arguments);
|
|
}
|
|
|
|
return sendTransaction;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.sendContractTransaction =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _sendContractTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(contract, fn, args, callOverrides) {
|
|
var provider, txHash, receipt, tx, _receipt;
|
|
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
if (callOverrides) {
|
|
_context9.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context9.next = 3;
|
|
return this.getCallOverrides();
|
|
|
|
case 3:
|
|
callOverrides = _context9.sent;
|
|
|
|
case 4:
|
|
if (!(this.options.transactionRelayerUrl || this.options.gasless.biconomy.apiKey)) {
|
|
_context9.next = 19;
|
|
break;
|
|
}
|
|
|
|
_context9.next = 7;
|
|
return this.getProvider();
|
|
|
|
case 7:
|
|
provider = _context9.sent;
|
|
_context9.next = 10;
|
|
return this.sendGaslessTransaction(contract, fn, args, callOverrides);
|
|
|
|
case 10:
|
|
txHash = _context9.sent;
|
|
this.emitTransactionEvent("submitted", txHash);
|
|
_context9.next = 14;
|
|
return provider.waitForTransaction(txHash);
|
|
|
|
case 14:
|
|
receipt = _context9.sent;
|
|
this.emitTransactionEvent("completed", txHash);
|
|
return _context9.abrupt("return", receipt);
|
|
|
|
case 19:
|
|
_context9.next = 21;
|
|
return this.sendTransactionByFunction(contract, fn, args, callOverrides);
|
|
|
|
case 21:
|
|
tx = _context9.sent;
|
|
this.emitTransactionEvent("submitted", tx.hash);
|
|
_receipt = tx.wait();
|
|
this.emitTransactionEvent("completed", tx.hash);
|
|
return _context9.abrupt("return", _receipt);
|
|
|
|
case 26:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function sendContractTransaction(_x6, _x7, _x8, _x9) {
|
|
return _sendContractTransaction.apply(this, arguments);
|
|
}
|
|
|
|
return sendContractTransaction;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.sendTransactionByFunction =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _sendTransactionByFunction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(contract, fn, args, callOverrides) {
|
|
var func;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
func = contract.functions[fn];
|
|
|
|
if (func) {
|
|
_context10.next = 3;
|
|
break;
|
|
}
|
|
|
|
throw new Error("invalid function");
|
|
|
|
case 3:
|
|
_context10.next = 5;
|
|
return func.apply(void 0, args.concat([callOverrides]));
|
|
|
|
case 5:
|
|
return _context10.abrupt("return", _context10.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10);
|
|
}));
|
|
|
|
function sendTransactionByFunction(_x10, _x11, _x12, _x13) {
|
|
return _sendTransactionByFunction.apply(this, arguments);
|
|
}
|
|
|
|
return sendTransactionByFunction;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.sendGaslessTransaction =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _sendGaslessTransaction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(contract, fn, args, callOverrides) {
|
|
var _contract$estimateGas;
|
|
|
|
var signer, provider, chainId, from, to, value, data, gasEstimate, gas, tx, txHash;
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
signer = this.getSigner();
|
|
!signer ? process.env.NODE_ENV !== "production" ? invariant(false, "Cannot execute gasless transaction without valid signer") : invariant(false) : void 0;
|
|
_context11.next = 4;
|
|
return this.getProvider();
|
|
|
|
case 4:
|
|
provider = _context11.sent;
|
|
!provider ? process.env.NODE_ENV !== "production" ? invariant(false, "no provider to execute transaction") : invariant(false) : void 0;
|
|
_context11.next = 8;
|
|
return this.getChainID();
|
|
|
|
case 8:
|
|
chainId = _context11.sent;
|
|
_context11.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
from = _context11.sent;
|
|
to = this.address;
|
|
value = (callOverrides == null ? void 0 : callOverrides.value) || 0;
|
|
|
|
if (!BigNumber.from(value).gt(0)) {
|
|
_context11.next = 16;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Cannot send native token value with gasless transaction");
|
|
|
|
case 16:
|
|
data = contract["interface"].encodeFunctionData(fn, args);
|
|
_context11.next = 19;
|
|
return (_contract$estimateGas = contract.estimateGas)[fn].apply(_contract$estimateGas, args);
|
|
|
|
case 19:
|
|
gasEstimate = _context11.sent;
|
|
gas = gasEstimate.mul(2); // in some cases WalletConnect doesn't properly gives an estimate for how much gas it would actually use.
|
|
// it'd estimate ~21740 on polygon.
|
|
// as a fix, we're setting it to a high arbitrary number (500k) as the gas limit that should cover for most function calls.
|
|
|
|
if (gasEstimate.lt(25000)) {
|
|
gas = BigNumber.from(500000);
|
|
}
|
|
|
|
tx = {
|
|
from: from,
|
|
to: to,
|
|
data: data,
|
|
chainId: chainId,
|
|
gasLimit: gas,
|
|
functionName: fn,
|
|
functionArgs: args,
|
|
callOverrides: callOverrides
|
|
};
|
|
_context11.next = 25;
|
|
return this.options.gaslessSendFunction(contract, tx);
|
|
|
|
case 25:
|
|
txHash = _context11.sent;
|
|
return _context11.abrupt("return", txHash);
|
|
|
|
case 27:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function sendGaslessTransaction(_x14, _x15, _x16, _x17) {
|
|
return _sendGaslessTransaction.apply(this, arguments);
|
|
}
|
|
|
|
return sendGaslessTransaction;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.signTypedDataEmitEvent =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _signTypedDataEmitEvent = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(signer, domain, types, message) {
|
|
var signature, _yield$signTypedData, sig;
|
|
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
signature = "";
|
|
this.sdk.event.emit(EventType.Signature, {
|
|
status: "submitted",
|
|
message: message,
|
|
signature: signature
|
|
});
|
|
_context12.next = 4;
|
|
return signTypedData(signer, domain, types, message);
|
|
|
|
case 4:
|
|
_yield$signTypedData = _context12.sent;
|
|
sig = _yield$signTypedData.signature;
|
|
signature = sig;
|
|
this.sdk.event.emit(EventType.Signature, {
|
|
status: "completed",
|
|
message: message,
|
|
signature: signature
|
|
});
|
|
return _context12.abrupt("return", signature);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function signTypedDataEmitEvent(_x18, _x19, _x20, _x21) {
|
|
return _signTypedDataEmitEvent.apply(this, arguments);
|
|
}
|
|
|
|
return signTypedDataEmitEvent;
|
|
}();
|
|
|
|
_proto.parseEventLogs = function parseEventLogs(eventName, logs) {
|
|
if (!logs) {
|
|
return null;
|
|
}
|
|
|
|
for (var _iterator = _createForOfIteratorHelperLoose(logs), _step; !(_step = _iterator()).done;) {
|
|
var log = _step.value;
|
|
|
|
try {
|
|
var event = this.contract["interface"].decodeEventLog(eventName, log.data, log.topics);
|
|
return event; // eslint-disable-next-line no-empty
|
|
} catch (e) {}
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
_proto.parseLogs = function parseLogs(eventName, logs, contract) {
|
|
if (contract === void 0) {
|
|
contract = this.contract;
|
|
}
|
|
|
|
if (!logs || logs.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
var topic = contract["interface"].getEventTopic(eventName);
|
|
var parsedLogs = logs.filter(function (x) {
|
|
return x.topics.indexOf(topic) >= 0;
|
|
});
|
|
return parsedLogs.map(function (l) {
|
|
return contract["interface"].parseLog(l);
|
|
});
|
|
};
|
|
|
|
_createClass(Module, [{
|
|
key: "providerOrSigner",
|
|
get:
|
|
/**
|
|
* @readonly
|
|
*/
|
|
|
|
/**
|
|
* @internal
|
|
* @readonly
|
|
*/
|
|
|
|
/**
|
|
* @internal
|
|
* @readonly
|
|
*/
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
function get() {
|
|
return this.signer || this._providerOrSigner || this.getProviderOrSigner();
|
|
},
|
|
set: function set(value) {
|
|
this._providerOrSigner = value;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
}, {
|
|
key: "signer",
|
|
get:
|
|
/**
|
|
* @internal
|
|
*/
|
|
function get() {
|
|
return this._signer;
|
|
},
|
|
set: function set(value) {
|
|
this._signer = value;
|
|
}
|
|
/**
|
|
* Contract connects to the SDK signer or provider
|
|
* @internal
|
|
*/
|
|
|
|
}]);
|
|
|
|
return Module;
|
|
}();
|
|
/**
|
|
* Extends the {@link Module} class to add {@link Role} functionality.
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var ModuleWithRoles = /*#__PURE__*/function (_Module) {
|
|
_inheritsLoose(ModuleWithRoles, _Module);
|
|
|
|
var _proto2 = ModuleWithRoles.prototype;
|
|
|
|
/**
|
|
* @virtual
|
|
* @internal
|
|
*/
|
|
_proto2.getModuleRoles = function getModuleRoles() {
|
|
throw new Error("getModuleRoles has to be implemented by a subclass");
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
/** @internal */
|
|
function ModuleWithRoles(providerOrSigner, address, options, sdk) {
|
|
return _Module.call(this, providerOrSigner, address, options, sdk) || this;
|
|
}
|
|
/**
|
|
* Call this to get a list of addresses that are members of a specific role.
|
|
*
|
|
* @param role - The {@link IRoles | role} to to get a memberlist for.
|
|
* @returns The list of addresses that are members of the specific role.
|
|
* @throws If you are requestiong a role that does not exist on the module this will throw an {@link InvariantError}.
|
|
* @see {@link ModuleWithRoles.getAllRoleMembers | getAllRoleMembers} to get get a list of addresses for all supported roles on the module.
|
|
* @example Say you want to get the list of addresses that are members of the {@link IRoles.minter | minter} role.
|
|
* ```typescript
|
|
* const minterAddresses: string[] = await module.getRoleMemberList("minter");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
|
|
_proto2.getRoleMembers =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoleMembers = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(role) {
|
|
var contract, roleHash, count;
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
!this.roles.includes(role) ? process.env.NODE_ENV !== "production" ? invariant(false, "this module does not support the \"" + role + "\" role") : invariant(false) : void 0;
|
|
contract = this.readOnlyContract;
|
|
roleHash = getRoleHash(role);
|
|
_context13.next = 5;
|
|
return contract.getRoleMemberCount(roleHash);
|
|
|
|
case 5:
|
|
count = _context13.sent.toNumber();
|
|
_context13.next = 8;
|
|
return Promise.all(Array.from(Array(count).keys()).map(function (i) {
|
|
return contract.getRoleMember(roleHash, i);
|
|
}));
|
|
|
|
case 8:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function getRoleMembers(_x22) {
|
|
return _getRoleMembers.apply(this, arguments);
|
|
}
|
|
|
|
return getRoleMembers;
|
|
}()
|
|
/**
|
|
* Call this to get get a list of addresses for all supported roles on the module.
|
|
*
|
|
* @see {@link ModuleWithRoles.getRoleMembers | getRoleMembers} to get a list of addresses that are members of a specific role.
|
|
* @returns A record of {@link Role}s to lists of addresses that are members of the given role.
|
|
* @throws If the module does not support roles this will throw an {@link InvariantError}.
|
|
*
|
|
* @public
|
|
*/
|
|
;
|
|
|
|
_proto2.getAllRoleMembers =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllRoleMembers = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14() {
|
|
var roles, _iterator2, _step2, role;
|
|
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
!this.roles.length ? process.env.NODE_ENV !== "production" ? invariant(false, "this module has no support for roles") : invariant(false) : void 0;
|
|
roles = {};
|
|
_iterator2 = _createForOfIteratorHelperLoose(this.roles);
|
|
|
|
case 3:
|
|
if ((_step2 = _iterator2()).done) {
|
|
_context14.next = 10;
|
|
break;
|
|
}
|
|
|
|
role = _step2.value;
|
|
_context14.next = 7;
|
|
return this.getRoleMembers(role);
|
|
|
|
case 7:
|
|
roles[role] = _context14.sent;
|
|
|
|
case 8:
|
|
_context14.next = 3;
|
|
break;
|
|
|
|
case 10:
|
|
return _context14.abrupt("return", roles);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function getAllRoleMembers() {
|
|
return _getAllRoleMembers.apply(this, arguments);
|
|
}
|
|
|
|
return getAllRoleMembers;
|
|
}()
|
|
/**
|
|
* Call this to OVERWRITE the list of addresses that are members of specific roles.
|
|
*
|
|
* Every role in the list will be overwritten with the new list of addresses provided with them.
|
|
* If you want to add or remove addresses for a single address use {@link ModuleWithRoles.grantRole | grantRole} and {@link ModuleWithRoles.grantRole | revokeRole} respectively instead.
|
|
* @param rolesWithAddresses - A record of {@link Role}s to lists of addresses that should be members of the given role.
|
|
* @throws If you are requestiong a role that does not exist on the module this will throw an {@link InvariantError}.
|
|
* @example Say you want to overwrite the list of addresses that are members of the {@link IRoles.minter | minter} role.
|
|
* ```typescript
|
|
* const minterAddresses: string[] = await module.getRoleMemberList("minter");
|
|
* await module.setAllRoleMembers({
|
|
* minter: []
|
|
* });
|
|
* console.log(await module.getRoleMemberList("minter")); // No matter what members had the role before, the new list will be set to []
|
|
* ```
|
|
* @public
|
|
*
|
|
* */
|
|
;
|
|
|
|
_proto2.setAllRoleMembers =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setAllRoleMembers = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(rolesWithAddresses) {
|
|
var _this = this;
|
|
|
|
var roles, currentRoles, encoded;
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
roles = Object.keys(rolesWithAddresses);
|
|
!roles.length ? process.env.NODE_ENV !== "production" ? invariant(false, "you must provide at least one role to set") : invariant(false) : void 0;
|
|
!roles.every(function (role) {
|
|
return _this.roles.includes(role);
|
|
}) ? process.env.NODE_ENV !== "production" ? invariant(false, "this module does not support the given role") : invariant(false) : void 0;
|
|
_context17.next = 5;
|
|
return this.getAllRoleMembers();
|
|
|
|
case 5:
|
|
currentRoles = _context17.sent;
|
|
encoded = []; // add / rmove admin role at the end so we don't revoke admin then grant
|
|
|
|
roles.sort(function (role) {
|
|
return role === "admin" ? 1 : -1;
|
|
}).forEach( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(role) {
|
|
var addresses, currentAddresses, toAdd, toRemove;
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
addresses = rolesWithAddresses[role] || [];
|
|
currentAddresses = currentRoles[role] || [];
|
|
toAdd = addresses.filter(function (address) {
|
|
return !currentAddresses.includes(address);
|
|
});
|
|
toRemove = currentAddresses.filter(function (address) {
|
|
return !addresses.includes(address);
|
|
});
|
|
|
|
if (toAdd.length) {
|
|
toAdd.forEach(function (address) {
|
|
encoded.push(_this.contract["interface"].encodeFunctionData("grantRole", [getRoleHash(role), address]));
|
|
});
|
|
}
|
|
|
|
if (toRemove.length) {
|
|
toRemove.forEach( /*#__PURE__*/function () {
|
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(address) {
|
|
var revokeFunctionName;
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.next = 2;
|
|
return _this.getRevokeRoleFunctionName(address);
|
|
|
|
case 2:
|
|
revokeFunctionName = _context15.sent;
|
|
encoded.push(_this.contract["interface"].encodeFunctionData(revokeFunctionName, [getRoleHash(role), address]));
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15);
|
|
}));
|
|
|
|
return function (_x25) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}());
|
|
}
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16);
|
|
}));
|
|
|
|
return function (_x24) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}());
|
|
_context17.next = 10;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 10:
|
|
return _context17.abrupt("return", _context17.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function setAllRoleMembers(_x23) {
|
|
return _setAllRoleMembers.apply(this, arguments);
|
|
}
|
|
|
|
return setAllRoleMembers;
|
|
}()
|
|
/**
|
|
*
|
|
* Call this to revoke all roles given to a specific address.
|
|
* @param address - The address to revoke all roles for.
|
|
* @returns A list of roles that were revoked.
|
|
*
|
|
* @public
|
|
*
|
|
*/
|
|
;
|
|
|
|
_proto2.revokeAllRolesFromAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _revokeAllRolesFromAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(address) {
|
|
var _this2 = this;
|
|
|
|
var currentRoles, encoded, rolesRemoved;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return this.getAllRoleMembers();
|
|
|
|
case 2:
|
|
currentRoles = _context19.sent;
|
|
encoded = [];
|
|
rolesRemoved = []; // revoke / renounce admin role at the end
|
|
|
|
Object.keys(currentRoles).sort(function (role) {
|
|
return role === "admin" ? 1 : -1;
|
|
}).forEach( /*#__PURE__*/function () {
|
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(role) {
|
|
var _currentRoles$role;
|
|
|
|
var revokeFunctionName;
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
if (!((_currentRoles$role = currentRoles[role]) != null && _currentRoles$role.includes(address))) {
|
|
_context18.next = 6;
|
|
break;
|
|
}
|
|
|
|
_context18.next = 3;
|
|
return _this2.getRevokeRoleFunctionName(address);
|
|
|
|
case 3:
|
|
revokeFunctionName = _context18.sent;
|
|
encoded.push(_this2.contract["interface"].encodeFunctionData(revokeFunctionName, [getRoleHash(role), address]));
|
|
rolesRemoved.push(role);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18);
|
|
}));
|
|
|
|
return function (_x27) {
|
|
return _ref3.apply(this, arguments);
|
|
};
|
|
}());
|
|
_context19.next = 8;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 8:
|
|
return _context19.abrupt("return", rolesRemoved);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function revokeAllRolesFromAddress(_x26) {
|
|
return _revokeAllRolesFromAddress.apply(this, arguments);
|
|
}
|
|
|
|
return revokeAllRolesFromAddress;
|
|
}()
|
|
/**
|
|
* Call this to grant a role to a specific address.
|
|
*
|
|
* @remarks
|
|
*
|
|
* Make sure you are sure you want to grant the role to the address.
|
|
*
|
|
* @param role - The {@link IRoles | role} to grant to the address
|
|
* @param address - The address to grant the role to
|
|
* @returns The transaction receipt
|
|
* @throws If you are trying to grant does not exist on the module this will throw an {@link InvariantError}.
|
|
*
|
|
* @public
|
|
*/
|
|
;
|
|
|
|
_proto2.grantRole =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _grantRole = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(role, address) {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
!this.roles.includes(role) ? process.env.NODE_ENV !== "production" ? invariant(false, "this module does not support the \"" + role + "\" role") : invariant(false) : void 0;
|
|
_context20.next = 3;
|
|
return this.sendTransaction("grantRole", [getRoleHash(role), address]);
|
|
|
|
case 3:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function grantRole(_x28, _x29) {
|
|
return _grantRole.apply(this, arguments);
|
|
}
|
|
|
|
return grantRole;
|
|
}()
|
|
/**
|
|
* Call this to revoke a role from a specific address.
|
|
*
|
|
* @remarks
|
|
*
|
|
* -- Caution --
|
|
*
|
|
* This will let you remove yourself from the role, too.
|
|
* If you remove yourself from the {@link IRoles.admin | admin} role, you will no longer be able to administer the module.
|
|
* There is no way to recover from this.
|
|
*
|
|
* @param role - The {@link IRoles | role} to revoke
|
|
* @param address - The address to revoke the role from
|
|
* @returns The transaction receipt
|
|
* @throws If you are trying to revoke does not exist on the module this will throw an {@link InvariantError}.
|
|
*
|
|
* @public
|
|
*/
|
|
;
|
|
|
|
_proto2.revokeRole =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _revokeRole = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(role, address) {
|
|
var revokeFunctionName;
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
!this.roles.includes(role) ? process.env.NODE_ENV !== "production" ? invariant(false, "this module does not support the \"" + role + "\" role") : invariant(false) : void 0;
|
|
_context21.next = 3;
|
|
return this.getRevokeRoleFunctionName(address);
|
|
|
|
case 3:
|
|
revokeFunctionName = _context21.sent;
|
|
_context21.next = 6;
|
|
return this.sendTransaction(revokeFunctionName, [getRoleHash(role), address]);
|
|
|
|
case 6:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function revokeRole(_x30, _x31) {
|
|
return _revokeRole.apply(this, arguments);
|
|
}
|
|
|
|
return revokeRole;
|
|
}();
|
|
|
|
_proto2.getRevokeRoleFunctionName = /*#__PURE__*/function () {
|
|
var _getRevokeRoleFunctionName = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(address) {
|
|
var signerAddress;
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.next = 2;
|
|
return this.getSignerAddress();
|
|
|
|
case 2:
|
|
signerAddress = _context22.sent;
|
|
|
|
if (!(signerAddress.toLowerCase() === address.toLowerCase())) {
|
|
_context22.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context22.abrupt("return", "renounceRole");
|
|
|
|
case 5:
|
|
return _context22.abrupt("return", "revokeRole");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function getRevokeRoleFunctionName(_x32) {
|
|
return _getRevokeRoleFunctionName.apply(this, arguments);
|
|
}
|
|
|
|
return getRevokeRoleFunctionName;
|
|
}()
|
|
/**
|
|
* Prepares any set of metadata for uploading by recursively converting all Buffer|Blob|File objects
|
|
* into a hash of the object after its been uploaded to distributed storage (e.g. IPFS). After uploading
|
|
* any File|Buffer|Blob, the metadata is serialized to a string.
|
|
*
|
|
* @param metadata - The list of metadata to prepare for upload.
|
|
* @returns - The serialized metadata object.
|
|
*/
|
|
;
|
|
|
|
_proto2.prepareMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _prepareMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(metadata) {
|
|
var _this3 = this;
|
|
|
|
var _fileHandler;
|
|
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
if (!(typeof metadata === "string")) {
|
|
_context24.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context24.abrupt("return", metadata);
|
|
|
|
case 2:
|
|
_fileHandler = /*#__PURE__*/function () {
|
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(object) {
|
|
var keys, key, val, shouldUpload;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
keys = Object.keys(object);
|
|
_context23.t0 = runtime_1.keys(keys);
|
|
|
|
case 2:
|
|
if ((_context23.t1 = _context23.t0()).done) {
|
|
_context23.next = 18;
|
|
break;
|
|
}
|
|
|
|
key = _context23.t1.value;
|
|
val = object[keys[key]];
|
|
shouldUpload = val instanceof File || val instanceof Buffer;
|
|
|
|
if (!shouldUpload) {
|
|
_context23.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context23.next = 9;
|
|
return _this3.sdk.getStorage().upload(object[keys[key]]);
|
|
|
|
case 9:
|
|
object[keys[key]] = _context23.sent;
|
|
|
|
case 10:
|
|
if (!(shouldUpload && typeof object[keys[key]] !== "string")) {
|
|
_context23.next = 12;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Upload to IPFS failed");
|
|
|
|
case 12:
|
|
if (!(typeof val === "object")) {
|
|
_context23.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context23.next = 15;
|
|
return _fileHandler(object[keys[key]]);
|
|
|
|
case 15:
|
|
object[keys[key]] = _context23.sent;
|
|
|
|
case 16:
|
|
_context23.next = 2;
|
|
break;
|
|
|
|
case 18:
|
|
return _context23.abrupt("return", object);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23);
|
|
}));
|
|
|
|
return function _fileHandler(_x34) {
|
|
return _ref4.apply(this, arguments);
|
|
};
|
|
}();
|
|
|
|
_context24.next = 5;
|
|
return _fileHandler(metadata);
|
|
|
|
case 5:
|
|
metadata = _context24.sent;
|
|
return _context24.abrupt("return", JSON.stringify(metadata));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24);
|
|
}));
|
|
|
|
function prepareMetadata(_x33) {
|
|
return _prepareMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return prepareMetadata;
|
|
}()
|
|
/**
|
|
* Prepares a list of metadata for uploading.
|
|
*
|
|
* @param metadata - List of metadata to prepare for upload.
|
|
* @returns - List of metadata prepared for upload.
|
|
*/
|
|
;
|
|
|
|
_proto2.prepareBatchMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _prepareBatchMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(metadata) {
|
|
var _this4 = this;
|
|
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return Promise.all(metadata.map( /*#__PURE__*/function () {
|
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(m) {
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
_context25.next = 2;
|
|
return _this4.prepareMetadata(m);
|
|
|
|
case 2:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25);
|
|
}));
|
|
|
|
return function (_x36) {
|
|
return _ref5.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 2:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26);
|
|
}));
|
|
|
|
function prepareBatchMetadata(_x35) {
|
|
return _prepareBatchMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return prepareBatchMetadata;
|
|
}()
|
|
/**
|
|
* Throws an error if an address is missing the roles specified.
|
|
*
|
|
* @param roles - The roles to check
|
|
* @param address - The address to check
|
|
*/
|
|
;
|
|
|
|
_proto2.onlyRoles =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _onlyRoles = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(roles, address) {
|
|
var _this5 = this;
|
|
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return Promise.all(roles.map( /*#__PURE__*/function () {
|
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(role) {
|
|
var members;
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
_context27.next = 2;
|
|
return _this5.getRoleMembers(role);
|
|
|
|
case 2:
|
|
members = _context27.sent;
|
|
|
|
if (members.map(function (a) {
|
|
return a.toLowerCase();
|
|
}).includes(address.toLowerCase())) {
|
|
_context27.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new MissingRoleError(address, role);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27);
|
|
}));
|
|
|
|
return function (_x39) {
|
|
return _ref6.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28);
|
|
}));
|
|
|
|
function onlyRoles(_x37, _x38) {
|
|
return _onlyRoles.apply(this, arguments);
|
|
}
|
|
|
|
return onlyRoles;
|
|
}();
|
|
|
|
_createClass(ModuleWithRoles, [{
|
|
key: "roles",
|
|
get: function get() {
|
|
return this.getModuleRoles();
|
|
}
|
|
}]);
|
|
|
|
return ModuleWithRoles;
|
|
}(Module);
|
|
|
|
var MintRequest = [{
|
|
name: "to",
|
|
type: "address"
|
|
}, {
|
|
name: "royaltyRecipient",
|
|
type: "address"
|
|
}, {
|
|
name: "royaltyBps",
|
|
type: "uint256"
|
|
}, {
|
|
name: "primarySaleRecipient",
|
|
type: "address"
|
|
}, {
|
|
name: "tokenId",
|
|
type: "uint256"
|
|
}, {
|
|
name: "uri",
|
|
type: "string"
|
|
}, {
|
|
name: "quantity",
|
|
type: "uint256"
|
|
}, {
|
|
name: "pricePerToken",
|
|
type: "uint256"
|
|
}, {
|
|
name: "currency",
|
|
type: "address"
|
|
}, {
|
|
name: "validityStartTimestamp",
|
|
type: "uint128"
|
|
}, {
|
|
name: "validityEndTimestamp",
|
|
type: "uint128"
|
|
}, {
|
|
name: "uid",
|
|
type: "bytes32"
|
|
}];
|
|
/**
|
|
* Create a collection of NFTs that lets you optionally mint multiple copies of each NFT.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getBundleModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var SignatureMint1155Module = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(SignatureMint1155Module, _ModuleWithRoles);
|
|
|
|
function SignatureMint1155Module() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = SignatureMint1155Module.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return SignatureMint1155Module.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return SignatureMint1155__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return SignatureMint1155Module.moduleType;
|
|
}
|
|
/**
|
|
*
|
|
* Get a single bundle item by tokenId.
|
|
* @param tokenId - the unique token id of the nft
|
|
* @returns A promise that resolves to a `BundleMetadata`.
|
|
*/
|
|
;
|
|
|
|
_proto.get =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tokenId, address) {
|
|
var _yield$Promise$all, metadata, supply, ownedByAddress;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.t0 = Promise;
|
|
_context.t1 = getTokenMetadata(this.readOnlyContract, tokenId, this.sdk.getStorage());
|
|
_context.t2 = this.readOnlyContract.totalSupply(tokenId)["catch"](function () {
|
|
return BigNumber$1.from("0");
|
|
});
|
|
|
|
if (!address) {
|
|
_context.next = 9;
|
|
break;
|
|
}
|
|
|
|
_context.next = 6;
|
|
return this.balanceOf(address, tokenId);
|
|
|
|
case 6:
|
|
_context.t3 = _context.sent.toNumber();
|
|
_context.next = 10;
|
|
break;
|
|
|
|
case 9:
|
|
_context.t3 = 0;
|
|
|
|
case 10:
|
|
_context.t4 = _context.t3;
|
|
_context.t5 = [_context.t1, _context.t2, _context.t4];
|
|
_context.next = 14;
|
|
return _context.t0.all.call(_context.t0, _context.t5);
|
|
|
|
case 14:
|
|
_yield$Promise$all = _context.sent;
|
|
metadata = _yield$Promise$all[0];
|
|
supply = _yield$Promise$all[1];
|
|
ownedByAddress = _yield$Promise$all[2];
|
|
return _context.abrupt("return", {
|
|
supply: supply,
|
|
metadata: metadata,
|
|
quantityOwnedByAddress: BigNumber$1.from(ownedByAddress)
|
|
});
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function get(_x, _x2) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get NFT Data
|
|
*
|
|
* @remarks Get data associated with NFTs in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // You can get every NFT in the module
|
|
* const nfts = await module.getAll();
|
|
* console.log(nfts);
|
|
*
|
|
* // Or you can get optionally get the NFTs owned by a specific wallet
|
|
* const address = "{{wallet_address}}"; // The address you want to get the NFTs for;
|
|
* const ownedNfts = await module.getAll(address);
|
|
* console.log(ownedNfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(address) {
|
|
var _this = this;
|
|
|
|
var maxId;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 2:
|
|
maxId = _context2.sent.toNumber();
|
|
_context2.next = 5;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this.get(i.toString(), address);
|
|
}));
|
|
|
|
case 5:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getAll(_x3) {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}()
|
|
/**
|
|
* Get NFT Balance
|
|
*
|
|
* @remarks Get a wallets NFT balance (number of a specific NFT in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check NFT balance
|
|
* const address = "{{wallet_address}}";
|
|
* // The token ID of the NFT you want to check the wallets balance of
|
|
* const tokenId = "0"
|
|
*
|
|
* const balance = await module.balanceOf(address, tokenId);
|
|
* console.log(balance);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(address, tokenId) {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.readOnlyContract.balanceOf(address, tokenId);
|
|
|
|
case 2:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function balanceOf(_x4, _x5) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tokenId) {
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.t0 = this.readOnlyContract;
|
|
_context4.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context4.t1 = _context4.sent;
|
|
_context4.t2 = tokenId;
|
|
_context4.next = 7;
|
|
return _context4.t0.balanceOf.call(_context4.t0, _context4.t1, _context4.t2);
|
|
|
|
case 7:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function balance(_x6) {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address, operator, assetContract, assetId) {
|
|
var contract, approved, isTokenApproved;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
if (assetContract) {
|
|
_context5.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context5.next = 3;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 3:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 4:
|
|
if (assetId) {
|
|
_context5.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("tokenId is required");
|
|
|
|
case 6:
|
|
contract = ERC721__factory.connect(assetContract, this.providerOrSigner);
|
|
_context5.t0 = contract;
|
|
_context5.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
_context5.t1 = _context5.sent;
|
|
_context5.t2 = this.address;
|
|
_context5.next = 14;
|
|
return _context5.t0.isApprovedForAll.call(_context5.t0, _context5.t1, _context5.t2);
|
|
|
|
case 14:
|
|
approved = _context5.sent;
|
|
_context5.next = 17;
|
|
return contract.getApproved(assetId);
|
|
|
|
case 17:
|
|
_context5.t3 = _context5.sent.toLowerCase();
|
|
_context5.t4 = this.address.toLowerCase();
|
|
isTokenApproved = _context5.t3 === _context5.t4;
|
|
return _context5.abrupt("return", approved || isTokenApproved);
|
|
|
|
case 21:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function isApproved(_x7, _x8, _x9, _x10) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.setApproval =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(operator, approved) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context6.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function setApproval(_x11, _x12) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer NFT
|
|
*
|
|
* @remarks Transfer an NFT from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The token ID of the NFT you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* // The number of NFTs you want to send
|
|
* const amount = 1;
|
|
*
|
|
* await module.transfer(toAddress, tokenId, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(to, tokenId, amount) {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.t0 = this;
|
|
_context7.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context7.t1 = _context7.sent;
|
|
_context7.t2 = to;
|
|
_context7.t3 = {
|
|
tokenId: tokenId,
|
|
amount: amount
|
|
};
|
|
_context7.t4 = [0];
|
|
_context7.next = 9;
|
|
return _context7.t0.transferFrom.call(_context7.t0, _context7.t1, _context7.t2, _context7.t3, _context7.t4);
|
|
|
|
case 9:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function transfer(_x13, _x14, _x15) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}();
|
|
|
|
_proto.createAndMint = /*#__PURE__*/function () {
|
|
var _createAndMint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(args) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.t0 = this;
|
|
_context8.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context8.t1 = _context8.sent;
|
|
_context8.t2 = args;
|
|
_context8.next = 7;
|
|
return _context8.t0.createAndMintTo.call(_context8.t0, _context8.t1, _context8.t2);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function createAndMint(_x16) {
|
|
return _createAndMint.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMint;
|
|
}();
|
|
|
|
_proto.createAndMintTo = /*#__PURE__*/function () {
|
|
var _createAndMintTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(to, args) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(args.metadata);
|
|
|
|
case 2:
|
|
uri = _context9.sent;
|
|
_context9.next = 5;
|
|
return this.sendTransaction("mintTo", [to, ethers.constants.MaxUint256, uri, args.supply]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function createAndMintTo(_x17, _x18) {
|
|
return _createAndMintTo.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMintTo;
|
|
}();
|
|
|
|
_proto.createAndMintBatch = /*#__PURE__*/function () {
|
|
var _createAndMintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(args) {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.t0 = this;
|
|
_context10.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context10.t1 = _context10.sent;
|
|
_context10.t2 = args;
|
|
_context10.next = 7;
|
|
return _context10.t0.createAndMintBatchTo.call(_context10.t0, _context10.t1, _context10.t2);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function createAndMintBatch(_x19) {
|
|
return _createAndMintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMintBatch;
|
|
}();
|
|
|
|
_proto.createAndMintBatchTo = /*#__PURE__*/function () {
|
|
var _createAndMintBatchTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(to, args) {
|
|
var _this2 = this;
|
|
|
|
var metadatas, amounts, _yield$this$sdk$getSt, uris, encoded;
|
|
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
metadatas = args.map(function (a) {
|
|
return a.metadata;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.supply;
|
|
});
|
|
_context11.next = 4;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas);
|
|
|
|
case 4:
|
|
_yield$this$sdk$getSt = _context11.sent;
|
|
uris = _yield$this$sdk$getSt.metadataUris;
|
|
encoded = uris.map(function (uri, index) {
|
|
return _this2.readOnlyContract["interface"].encodeFunctionData("mintTo", [to, ethers.constants.MaxUint256, uri, amounts[index]]);
|
|
});
|
|
_context11.next = 9;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function createAndMintBatchTo(_x20, _x21) {
|
|
return _createAndMintBatchTo.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMintBatchTo;
|
|
}();
|
|
|
|
_proto.mintAdditionalCopiesTo = /*#__PURE__*/function () {
|
|
var _mintAdditionalCopiesTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(to, args) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.sendTransaction("mintTo", [to, args.tokenId, "", args.amount]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function mintAdditionalCopiesTo(_x22, _x23) {
|
|
return _mintAdditionalCopiesTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintAdditionalCopiesTo;
|
|
}();
|
|
|
|
_proto.mintAdditionalCopiesBatchTo = /*#__PURE__*/function () {
|
|
var _mintAdditionalCopiesBatchTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(to, args) {
|
|
var _this3 = this;
|
|
|
|
var ids, amounts, encoded;
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
encoded = ids.map(function (id, index) {
|
|
return _this3.readOnlyContract["interface"].encodeFunctionData("mintTo", [to, id, "", amounts[index]]);
|
|
});
|
|
_context13.next = 5;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function mintAdditionalCopiesBatchTo(_x24, _x25) {
|
|
return _mintAdditionalCopiesBatchTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintAdditionalCopiesBatchTo;
|
|
}()
|
|
/**
|
|
* Burn NFT
|
|
*
|
|
* @remarks Burn an NFT, permanently taking it out of circulation and reducing the supply.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The token ID of the NFT you want to burn
|
|
* const tokenId = 0;
|
|
* // The number of specified NFTs you want to burn
|
|
* const amount = 1
|
|
*
|
|
* await module.burn({ tokenId, amount });
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.burn =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(args) {
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.t0 = this;
|
|
_context14.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context14.t1 = _context14.sent;
|
|
_context14.t2 = args;
|
|
_context14.next = 7;
|
|
return _context14.t0.burnFrom.call(_context14.t0, _context14.t1, _context14.t2);
|
|
|
|
case 7:
|
|
return _context14.abrupt("return", _context14.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function burn(_x26) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.burnBatch = /*#__PURE__*/function () {
|
|
var _burnBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(args) {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.t0 = this;
|
|
_context15.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context15.t1 = _context15.sent;
|
|
_context15.t2 = args;
|
|
_context15.next = 7;
|
|
return _context15.t0.burnBatchFrom.call(_context15.t0, _context15.t1, _context15.t2);
|
|
|
|
case 7:
|
|
return _context15.abrupt("return", _context15.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function burnBatch(_x27) {
|
|
return _burnBatch.apply(this, arguments);
|
|
}
|
|
|
|
return burnBatch;
|
|
}();
|
|
|
|
_proto.burnFrom = /*#__PURE__*/function () {
|
|
var _burnFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(account, args) {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.sendTransaction("burn", [account, args.tokenId, args.amount]);
|
|
|
|
case 2:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function burnFrom(_x28, _x29) {
|
|
return _burnFrom.apply(this, arguments);
|
|
}
|
|
|
|
return burnFrom;
|
|
}();
|
|
|
|
_proto.burnBatchFrom = /*#__PURE__*/function () {
|
|
var _burnBatchFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(account, args) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context17.next = 4;
|
|
return this.sendTransaction("burnBatch", [account, ids, amounts]);
|
|
|
|
case 4:
|
|
return _context17.abrupt("return", _context17.sent);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function burnBatchFrom(_x30, _x31) {
|
|
return _burnBatchFrom.apply(this, arguments);
|
|
}
|
|
|
|
return burnBatchFrom;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(from, to, args, data) {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context18.next = 3;
|
|
return this.sendTransaction("safeTransferFrom", [from, to, args.tokenId, args.amount, data]);
|
|
|
|
case 3:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function transferFrom(_x32, _x33, _x34, _x35) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}()
|
|
/**
|
|
* Transfer Many NFTs
|
|
*
|
|
* @remarks Transfer NFTs from the one wallet to another.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to send the NFT from
|
|
* const fromAddress = "{{wallet_address}}";
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The data of the NFTs you want to send
|
|
* const data = [{
|
|
* tokenId: 1, // The token ID of the NFT you want to send
|
|
* amount: 1, // The number of this NFT you want to send
|
|
* }, {
|
|
* tokenId: 2,
|
|
* amount: 1,
|
|
* }]
|
|
*
|
|
* // Note that the connected wallet must have approval to transfer the tokens of the fromAddress
|
|
* await module.transferBatchFrom(fromAddress, toAddress, data);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transferBatchFrom =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transferBatchFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(from, to, args, data) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context19.next = 5;
|
|
return this.sendTransaction("safeBatchTransferFrom", [from, to, ids, amounts, data]);
|
|
|
|
case 5:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function transferBatchFrom(_x36, _x37, _x38, _x39) {
|
|
return _transferBatchFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferBatchFrom;
|
|
}()
|
|
/**
|
|
* Set the royalty recipient and fee for this contract
|
|
* @param recipientAddress
|
|
* @param fee
|
|
*/
|
|
;
|
|
|
|
_proto.setDefaultRoyaltyInfo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setDefaultRoyaltyInfo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(recipientAddress, fee) {
|
|
var _yield$this$getMetada, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada = _context20.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context20.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.fee_recipient = recipientAddress;
|
|
metadata.seller_fee_basis_points = fee;
|
|
_context20.t0 = this.sdk.getStorage();
|
|
_context20.t1 = _extends({}, metadata);
|
|
_context20.t2 = this.address;
|
|
_context20.next = 14;
|
|
return this.getSignerAddress();
|
|
|
|
case 14:
|
|
_context20.t3 = _context20.sent;
|
|
_context20.next = 17;
|
|
return _context20.t0.uploadMetadata.call(_context20.t0, _context20.t1, _context20.t2, _context20.t3);
|
|
|
|
case 17:
|
|
uri = _context20.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setDefaultRoyaltyInfo", [recipientAddress, fee]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context20.next = 22;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 22:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function setDefaultRoyaltyInfo(_x40, _x41) {
|
|
return _setDefaultRoyaltyInfo.apply(this, arguments);
|
|
}
|
|
|
|
return setDefaultRoyaltyInfo;
|
|
}()
|
|
/**
|
|
* Set the royalty recipient and fee for a particular token
|
|
* @param recipientAddress
|
|
* @param fee
|
|
*/
|
|
;
|
|
|
|
_proto.setTokenRoyaltyInfo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setTokenRoyaltyInfo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(tokenId, recipientAddress, fee) {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.sendTransaction("setRoyaltyInfoForToken", [tokenId, recipientAddress, fee]);
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function setTokenRoyaltyInfo(_x42, _x43, _x44) {
|
|
return _setTokenRoyaltyInfo.apply(this, arguments);
|
|
}
|
|
|
|
return setTokenRoyaltyInfo;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context22.sent;
|
|
_context22.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context22.abrupt("return", _context22.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x45) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}()
|
|
/**
|
|
* `getOwned` is a convenience method for getting all owned tokens
|
|
* for a particular wallet.
|
|
*
|
|
* @param _address - The address to check for token ownership
|
|
* @returns An array of BundleMetadata objects that are owned by the address
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(_address) {
|
|
var _this4 = this;
|
|
|
|
var address, maxId, balances, ownedBalances;
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context24.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context24.t0 = _address;
|
|
_context24.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context24.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context24.t0 = _context24.sent;
|
|
|
|
case 7:
|
|
address = _context24.t0;
|
|
_context24.next = 10;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 10:
|
|
maxId = _context24.sent;
|
|
_context24.next = 13;
|
|
return this.readOnlyContract.balanceOfBatch(Array(maxId.toNumber()).fill(address), Array.from(Array(maxId.toNumber()).keys()));
|
|
|
|
case 13:
|
|
balances = _context24.sent;
|
|
ownedBalances = balances.map(function (b, i) {
|
|
return {
|
|
tokenId: i,
|
|
balance: b
|
|
};
|
|
}).filter(function (b) {
|
|
return b.balance.gt(0);
|
|
});
|
|
_context24.next = 17;
|
|
return Promise.all(ownedBalances.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(item) {
|
|
var token;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.next = 2;
|
|
return _this4.get(item.tokenId.toString());
|
|
|
|
case 2:
|
|
token = _context23.sent;
|
|
return _context23.abrupt("return", _extends({}, token, {
|
|
ownedByAddress: item.balance
|
|
}));
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23);
|
|
}));
|
|
|
|
return function (_x47) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 17:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function getOwned(_x46) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}()
|
|
/**
|
|
* Gets the royalty recipient and BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty recipient and BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getDefaultRoyaltyInfo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getDefaultRoyaltyInfo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25() {
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
_context25.next = 2;
|
|
return this.readOnlyContract.getDefaultRoyaltyInfo();
|
|
|
|
case 2:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function getDefaultRoyaltyInfo() {
|
|
return _getDefaultRoyaltyInfo.apply(this, arguments);
|
|
}
|
|
|
|
return getDefaultRoyaltyInfo;
|
|
}()
|
|
/**
|
|
* Gets the royalty recipient and BPS (basis points) of a particular token
|
|
*
|
|
* @returns - The royalty recipient and BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getTokenRoyaltyInfo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getTokenRoyaltyInfo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(tokenId) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return this.readOnlyContract.getRoyaltyInfoForToken(tokenId);
|
|
|
|
case 2:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function getTokenRoyaltyInfo(_x48) {
|
|
return _getTokenRoyaltyInfo.apply(this, arguments);
|
|
}
|
|
|
|
return getTokenRoyaltyInfo;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27() {
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
return _context27.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(restricted) {
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context28.t0 = this;
|
|
_context28.t1 = ["admin"];
|
|
_context28.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context28.t2 = _context28.sent;
|
|
_context28.next = 8;
|
|
return _context28.t0.onlyRoles.call(_context28.t0, _context28.t1, _context28.t2);
|
|
|
|
case 8:
|
|
_context28.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context28.abrupt("return", _context28.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x49) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}() // Signature based minting
|
|
;
|
|
|
|
_proto.mintWithSignature =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mintWithSignature = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(req, signature) {
|
|
var message, overrides, receipt, t;
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
message = _extends({}, this.mapPayload(req), {
|
|
uri: req.uri
|
|
});
|
|
_context29.next = 3;
|
|
return this.getCallOverrides();
|
|
|
|
case 3:
|
|
overrides = _context29.sent;
|
|
_context29.next = 6;
|
|
return this.setAllowance(BigNumber$1.from(message.pricePerToken).mul(req.quantity), req.currencyAddress, overrides);
|
|
|
|
case 6:
|
|
_context29.next = 8;
|
|
return this.sendTransaction("mintWithSignature", [message, signature], overrides);
|
|
|
|
case 8:
|
|
receipt = _context29.sent;
|
|
_context29.next = 11;
|
|
return this.parseLogs("MintWithSignature", receipt.logs);
|
|
|
|
case 11:
|
|
t = _context29.sent;
|
|
|
|
if (!(t.length === 0)) {
|
|
_context29.next = 14;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No MintWithSignature event found");
|
|
|
|
case 14:
|
|
return _context29.abrupt("return", t[0].args.tokenIdMinted);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function mintWithSignature(_x50, _x51) {
|
|
return _mintWithSignature.apply(this, arguments);
|
|
}
|
|
|
|
return mintWithSignature;
|
|
}();
|
|
|
|
_proto.verify = /*#__PURE__*/function () {
|
|
var _verify = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30(mintRequest, signature) {
|
|
var message, v;
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
message = this.mapPayload(mintRequest);
|
|
_context30.next = 3;
|
|
return this.readOnlyContract.verify(_extends({}, message, {
|
|
uri: mintRequest.uri
|
|
}), signature);
|
|
|
|
case 3:
|
|
v = _context30.sent;
|
|
return _context30.abrupt("return", v[0]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function verify(_x52, _x53) {
|
|
return _verify.apply(this, arguments);
|
|
}
|
|
|
|
return verify;
|
|
}();
|
|
|
|
_proto.generateSignatureBatch = /*#__PURE__*/function () {
|
|
var _generateSignatureBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(payloads) {
|
|
var _this5 = this;
|
|
|
|
var resolveId, _yield$this$sdk$getSt2, uris, chainId, signer;
|
|
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
resolveId = function resolveId(mintRequest) {
|
|
if (mintRequest.id === undefined) {
|
|
var buffer = Buffer.alloc(16);
|
|
v4({}, buffer);
|
|
return hexlify(toUtf8Bytes(buffer.toString("hex")));
|
|
} else {
|
|
return hexlify(mintRequest.id);
|
|
}
|
|
};
|
|
|
|
_context32.t0 = this;
|
|
_context32.t1 = ["minter"];
|
|
_context32.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context32.t2 = _context32.sent;
|
|
_context32.next = 8;
|
|
return _context32.t0.onlyRoles.call(_context32.t0, _context32.t1, _context32.t2);
|
|
|
|
case 8:
|
|
_context32.next = 10;
|
|
return this.sdk.getStorage().uploadMetadataBatch(payloads.map(function (r) {
|
|
return r.metadata;
|
|
}));
|
|
|
|
case 10:
|
|
_yield$this$sdk$getSt2 = _context32.sent;
|
|
uris = _yield$this$sdk$getSt2.metadataUris;
|
|
_context32.next = 14;
|
|
return this.getChainID();
|
|
|
|
case 14:
|
|
chainId = _context32.sent;
|
|
signer = this.getSigner();
|
|
_context32.next = 18;
|
|
return Promise.all(payloads.map( /*#__PURE__*/function () {
|
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(m, i) {
|
|
var id, uri;
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
id = resolveId(m);
|
|
uri = uris[i];
|
|
_context31.t0 = _extends({}, m, {
|
|
id: id,
|
|
uri: uri
|
|
});
|
|
_context31.next = 5;
|
|
return _this5.signTypedDataEmitEvent(signer, {
|
|
name: "SignatureMint1155",
|
|
version: "1",
|
|
chainId: chainId,
|
|
verifyingContract: _this5.address
|
|
}, {
|
|
MintRequest: MintRequest
|
|
}, _extends({
|
|
uri: uri
|
|
}, _this5.mapPayload(m), {
|
|
uid: id
|
|
}));
|
|
|
|
case 5:
|
|
_context31.t1 = _context31.sent.toString();
|
|
return _context31.abrupt("return", {
|
|
payload: _context31.t0,
|
|
signature: _context31.t1
|
|
});
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31);
|
|
}));
|
|
|
|
return function (_x55, _x56) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 18:
|
|
return _context32.abrupt("return", _context32.sent);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function generateSignatureBatch(_x54) {
|
|
return _generateSignatureBatch.apply(this, arguments);
|
|
}
|
|
|
|
return generateSignatureBatch;
|
|
}();
|
|
|
|
_proto.generateSignature = /*#__PURE__*/function () {
|
|
var _generateSignature = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(mintRequest) {
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
_context33.next = 2;
|
|
return this.generateSignatureBatch([mintRequest]);
|
|
|
|
case 2:
|
|
return _context33.abrupt("return", _context33.sent[0]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function generateSignature(_x57) {
|
|
return _generateSignature.apply(this, arguments);
|
|
}
|
|
|
|
return generateSignature;
|
|
}()
|
|
/**
|
|
* Maps a payload to the format expected by the contract
|
|
*
|
|
* @internal
|
|
*
|
|
* @param mintRequest - The payload to map.
|
|
* @returns - The mapped payload.
|
|
*/
|
|
;
|
|
|
|
_proto.mapPayload = function mapPayload(mintRequest) {
|
|
return {
|
|
to: mintRequest.to,
|
|
royaltyRecipient: mintRequest.royaltyRecipient,
|
|
royaltyBps: mintRequest.royaltyBps,
|
|
primarySaleRecipient: mintRequest.primarySaleRecipient,
|
|
tokenId: mintRequest.tokenId,
|
|
quantity: mintRequest.quantity,
|
|
pricePerToken: mintRequest.price,
|
|
currency: mintRequest.currencyAddress,
|
|
validityEndTimestamp: mintRequest.mintEndTimeEpochSeconds,
|
|
validityStartTimestamp: mintRequest.mintStartTimeEpochSeconds,
|
|
uid: mintRequest.id
|
|
};
|
|
} // TODO: write in common place and stop duping
|
|
;
|
|
|
|
_proto.setAllowance =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setAllowance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(value, currencyAddress, overrides) {
|
|
var erc20, owner, spender, allowance;
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
if (!(currencyAddress === NATIVE_TOKEN_ADDRESS || currencyAddress === AddressZero)) {
|
|
_context34.next = 4;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = value;
|
|
_context34.next = 16;
|
|
break;
|
|
|
|
case 4:
|
|
erc20 = ERC20__factory.connect(currencyAddress, this.providerOrSigner);
|
|
_context34.next = 7;
|
|
return this.getSignerAddress();
|
|
|
|
case 7:
|
|
owner = _context34.sent;
|
|
spender = this.address;
|
|
_context34.next = 11;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 11:
|
|
allowance = _context34.sent;
|
|
|
|
if (!allowance.lt(value)) {
|
|
_context34.next = 15;
|
|
break;
|
|
}
|
|
|
|
_context34.next = 15;
|
|
return this.sendContractTransaction(erc20, "increaseAllowance", [spender, value.sub(allowance)]);
|
|
|
|
case 15:
|
|
return _context34.abrupt("return", overrides);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this);
|
|
}));
|
|
|
|
function setAllowance(_x58, _x59, _x60) {
|
|
return _setAllowance.apply(this, arguments);
|
|
}
|
|
|
|
return setAllowance;
|
|
}();
|
|
|
|
return SignatureMint1155Module;
|
|
}(ModuleWithRoles);
|
|
SignatureMint1155Module.moduleType = ModuleType.BUNDLE_SIGNATURE;
|
|
SignatureMint1155Module.roles = [RolesMap.admin, RolesMap.minter, RolesMap.pauser, RolesMap.transfer];
|
|
|
|
var _CONTRACT_ADDRESSES;
|
|
var FORWARDER_ADDRESS = "0xc82BbE41f2cF04e3a8efA18F7032BDD7f6d98a81";
|
|
var CONTRACT_ADDRESSES = (_CONTRACT_ADDRESSES = {}, _CONTRACT_ADDRESSES[ChainId.Mainnet] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0x84a0856b038eaAd1cC7E297cF34A7e72685A8693"
|
|
}, _CONTRACT_ADDRESSES[ChainId.Rinkeby] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0xFD4973FeB2031D4409fB57afEE5dF2051b171104"
|
|
}, _CONTRACT_ADDRESSES[ChainId.Polygon] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0x86C80a8aa58e0A4fa09A69624c31Ab2a6CAD56b8"
|
|
}, _CONTRACT_ADDRESSES[ChainId.Mumbai] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0x9399BB24DBB5C4b782C70c2969F58716Ebbd6a3b"
|
|
}, _CONTRACT_ADDRESSES[ChainId.Avalanche] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0x64CD353384109423a966dCd3Aa30D884C9b2E057"
|
|
}, _CONTRACT_ADDRESSES[ChainId.AvalancheFujiTestnet] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: "0x6271Ca63D30507f2Dcbf99B52787032506D75BBF"
|
|
}, _CONTRACT_ADDRESSES[ChainId.Fantom] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: ethers.constants.AddressZero
|
|
}, _CONTRACT_ADDRESSES[ChainId.FantomTestnet] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: ethers.constants.AddressZero
|
|
}, _CONTRACT_ADDRESSES[ChainId.Hardhat] = {
|
|
registry: "0x902a29f2cfe9f8580ad672AaAD7E917d85ca9a2E",
|
|
biconomyForwarder: ethers.constants.AddressZero
|
|
}, _CONTRACT_ADDRESSES);
|
|
function getContractAddressByChainId(chainId, contractName) {
|
|
if (contractName === void 0) {
|
|
contractName = "registry";
|
|
}
|
|
|
|
return CONTRACT_ADDRESSES[chainId][contractName];
|
|
}
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var ForwardRequest = [{
|
|
name: "from",
|
|
type: "address"
|
|
}, {
|
|
name: "to",
|
|
type: "address"
|
|
}, {
|
|
name: "value",
|
|
type: "uint256"
|
|
}, {
|
|
name: "gas",
|
|
type: "uint256"
|
|
}, {
|
|
name: "nonce",
|
|
type: "uint256"
|
|
}, {
|
|
name: "data",
|
|
type: "bytes"
|
|
}];
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var BiconomyForwarderAbi = [{
|
|
inputs: [{
|
|
internalType: "address",
|
|
name: "from",
|
|
type: "address"
|
|
}, {
|
|
internalType: "uint256",
|
|
name: "batchId",
|
|
type: "uint256"
|
|
}],
|
|
name: "getNonce",
|
|
outputs: [{
|
|
internalType: "uint256",
|
|
name: "",
|
|
type: "uint256"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
var _nonces = {};
|
|
var _noncesSyncTimestamp = {};
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
function getAndIncrementNonce(_x, _x2, _x3) {
|
|
return _getAndIncrementNonce.apply(this, arguments);
|
|
}
|
|
|
|
function _getAndIncrementNonce() {
|
|
_getAndIncrementNonce = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(forwarder, forwarderFunction, forwarderArgs) {
|
|
var address, timestamp, shouldSync, _forwarder$functions, nonceResult, nonce;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
// address is only used for internal caching :)
|
|
address = forwarderArgs.join("|");
|
|
timestamp = _noncesSyncTimestamp[address]; // if it's within 2 seconds we're optimistically increment the nonce
|
|
// should we always sync?
|
|
|
|
shouldSync = Date.now() - timestamp >= 2000;
|
|
|
|
if (!(!(address in _nonces) || shouldSync)) {
|
|
_context.next = 9;
|
|
break;
|
|
}
|
|
|
|
_context.next = 6;
|
|
return (_forwarder$functions = forwarder.functions)[forwarderFunction].apply(_forwarder$functions, forwarderArgs);
|
|
|
|
case 6:
|
|
nonceResult = _context.sent;
|
|
|
|
if (Array.isArray(nonceResult) && nonceResult.length > 0) {
|
|
_nonces[address] = BigNumber.from(nonceResult[0]);
|
|
} else {
|
|
_nonces[address] = BigNumber.from(nonceResult);
|
|
}
|
|
|
|
_noncesSyncTimestamp[address] = Date.now();
|
|
|
|
case 9:
|
|
nonce = _nonces[address];
|
|
_nonces[address] = BigNumber.from(_nonces[address]).add(1);
|
|
return _context.abrupt("return", nonce);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee);
|
|
}));
|
|
return _getAndIncrementNonce.apply(this, arguments);
|
|
}
|
|
|
|
var NAME_ABI = [{
|
|
inputs: [],
|
|
name: "name",
|
|
outputs: [{
|
|
internalType: "string",
|
|
name: "",
|
|
type: "string"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
var DOMAIN_SEPARATOR_ABI = [{
|
|
constant: true,
|
|
inputs: [],
|
|
name: "DOMAIN_SEPARATOR",
|
|
outputs: [{
|
|
internalType: "bytes32",
|
|
name: "",
|
|
type: "bytes32"
|
|
}],
|
|
payable: false,
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}, {
|
|
inputs: [],
|
|
name: "getDomainSeperator",
|
|
outputs: [{
|
|
internalType: "bytes32",
|
|
name: "",
|
|
type: "bytes32"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
var NONCES_ABI = [{
|
|
inputs: [{
|
|
internalType: "address",
|
|
name: "owner",
|
|
type: "address"
|
|
}],
|
|
name: "nonces",
|
|
outputs: [{
|
|
internalType: "uint256",
|
|
name: "",
|
|
type: "uint256"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}, {
|
|
inputs: [{
|
|
internalType: "address",
|
|
name: "user",
|
|
type: "address"
|
|
}],
|
|
name: "getNonce",
|
|
outputs: [{
|
|
internalType: "uint256",
|
|
name: "nonce",
|
|
type: "uint256"
|
|
}],
|
|
stateMutability: "view",
|
|
type: "function"
|
|
}];
|
|
|
|
function getSignerNonce(_x, _x2) {
|
|
return _getSignerNonce.apply(this, arguments);
|
|
}
|
|
|
|
function _getSignerNonce() {
|
|
_getSignerNonce = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(signer, contractAddress) {
|
|
var contract;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
contract = new Contract$1(contractAddress, NONCES_ABI, signer);
|
|
_context.prev = 1;
|
|
_context.t0 = contract;
|
|
_context.next = 5;
|
|
return signer.getAddress();
|
|
|
|
case 5:
|
|
_context.t1 = _context.sent;
|
|
_context.next = 8;
|
|
return _context.t0.nonces.call(_context.t0, _context.t1);
|
|
|
|
case 8:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 11:
|
|
_context.prev = 11;
|
|
_context.t2 = _context["catch"](1);
|
|
_context.t3 = contract;
|
|
_context.next = 16;
|
|
return signer.getAddress();
|
|
|
|
case 16:
|
|
_context.t4 = _context.sent;
|
|
_context.next = 19;
|
|
return _context.t3.getNonce.call(_context.t3, _context.t4);
|
|
|
|
case 19:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, null, [[1, 11]]);
|
|
}));
|
|
return _getSignerNonce.apply(this, arguments);
|
|
}
|
|
|
|
function getDomainSeperator(_x3, _x4) {
|
|
return _getDomainSeperator.apply(this, arguments);
|
|
}
|
|
|
|
function _getDomainSeperator() {
|
|
_getDomainSeperator = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(signer, contractAddress) {
|
|
var contract;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
contract = new Contract$1(contractAddress, DOMAIN_SEPARATOR_ABI, signer);
|
|
_context2.prev = 1;
|
|
_context2.next = 4;
|
|
return contract.DOMAIN_SEPARATOR();
|
|
|
|
case 4:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 7:
|
|
_context2.prev = 7;
|
|
_context2.t0 = _context2["catch"](1);
|
|
_context2.next = 11;
|
|
return contract.getDomainSeperator();
|
|
|
|
case 11:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, null, [[1, 7]]);
|
|
}));
|
|
return _getDomainSeperator.apply(this, arguments);
|
|
}
|
|
|
|
function getTokenName(_x5, _x6) {
|
|
return _getTokenName.apply(this, arguments);
|
|
}
|
|
/**
|
|
* Polygon chain has different EIP712 domain separator for USDC, DAI compared to other chains and slightly different than EIP-2612.
|
|
*/
|
|
|
|
|
|
function _getTokenName() {
|
|
_getTokenName = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(signer, contractAddress) {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
return _context3.abrupt("return", new Contract$1(contractAddress, NAME_ABI, signer).name());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3);
|
|
}));
|
|
return _getTokenName.apply(this, arguments);
|
|
}
|
|
|
|
function getChainDomainSeperator(_x7, _x8) {
|
|
return _getChainDomainSeperator.apply(this, arguments);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
|
|
function _getChainDomainSeperator() {
|
|
_getChainDomainSeperator = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(signer, domain) {
|
|
var contractDomainSeparator, polygonDomain;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return getDomainSeperator(signer, domain.verifyingContract);
|
|
|
|
case 2:
|
|
contractDomainSeparator = _context4.sent;
|
|
polygonDomain = {
|
|
name: domain.name,
|
|
version: domain.version,
|
|
verifyingContract: domain.verifyingContract,
|
|
salt: ethers.utils.hexZeroPad(BigNumber.from(domain.chainId).toHexString(), 32)
|
|
};
|
|
|
|
if (!(ethers.utils._TypedDataEncoder.hashDomain(polygonDomain) === contractDomainSeparator)) {
|
|
_context4.next = 6;
|
|
break;
|
|
}
|
|
|
|
return _context4.abrupt("return", polygonDomain);
|
|
|
|
case 6:
|
|
return _context4.abrupt("return", domain);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4);
|
|
}));
|
|
return _getChainDomainSeperator.apply(this, arguments);
|
|
}
|
|
|
|
function signEIP2612Permit(_x16, _x17, _x18, _x19, _x20, _x21, _x22) {
|
|
return _signEIP2612Permit.apply(this, arguments);
|
|
}
|
|
|
|
function _signEIP2612Permit() {
|
|
_signEIP2612Permit = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(signer, currencyAddress, owner, spender, value, deadline, nonce) {
|
|
var _nonce2, _deadline2;
|
|
|
|
var domain, message, types, _yield$signTypedData2, signature;
|
|
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.t0 = getChainDomainSeperator;
|
|
_context6.t1 = signer;
|
|
_context6.next = 4;
|
|
return getTokenName(signer, currencyAddress);
|
|
|
|
case 4:
|
|
_context6.t2 = _context6.sent;
|
|
_context6.next = 7;
|
|
return signer.getChainId();
|
|
|
|
case 7:
|
|
_context6.t3 = _context6.sent;
|
|
_context6.t4 = currencyAddress;
|
|
_context6.t5 = {
|
|
name: _context6.t2,
|
|
version: "1",
|
|
chainId: _context6.t3,
|
|
verifyingContract: _context6.t4
|
|
};
|
|
_context6.next = 12;
|
|
return (0, _context6.t0)(_context6.t1, _context6.t5);
|
|
|
|
case 12:
|
|
domain = _context6.sent;
|
|
|
|
if (!((_nonce2 = nonce) != null)) {
|
|
_context6.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context6.t6 = _nonce2;
|
|
_context6.next = 20;
|
|
break;
|
|
|
|
case 17:
|
|
_context6.next = 19;
|
|
return getSignerNonce(signer, currencyAddress);
|
|
|
|
case 19:
|
|
_context6.t6 = _context6.sent.toString();
|
|
|
|
case 20:
|
|
nonce = _context6.t6;
|
|
deadline = (_deadline2 = deadline) != null ? _deadline2 : ethers.constants.MaxUint256;
|
|
message = {
|
|
owner: owner,
|
|
spender: spender,
|
|
value: value,
|
|
nonce: nonce,
|
|
deadline: deadline
|
|
};
|
|
types = {
|
|
Permit: [{
|
|
name: "owner",
|
|
type: "address"
|
|
}, {
|
|
name: "spender",
|
|
type: "address"
|
|
}, {
|
|
name: "value",
|
|
type: "uint256"
|
|
}, {
|
|
name: "nonce",
|
|
type: "uint256"
|
|
}, {
|
|
name: "deadline",
|
|
type: "uint256"
|
|
}]
|
|
};
|
|
_context6.next = 26;
|
|
return signTypedData(signer, domain, types, message);
|
|
|
|
case 26:
|
|
_yield$signTypedData2 = _context6.sent;
|
|
signature = _yield$signTypedData2.signature;
|
|
return _context6.abrupt("return", {
|
|
message: message,
|
|
signature: signature
|
|
});
|
|
|
|
case 29:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6);
|
|
}));
|
|
return _signEIP2612Permit.apply(this, arguments);
|
|
}
|
|
|
|
/**
|
|
* CommonModuleMetadata defines the common properties of a module deployment.
|
|
*/
|
|
|
|
var CommonModuleMetadata = function CommonModuleMetadata() {
|
|
this.name = "";
|
|
this.description = undefined;
|
|
this.image = undefined;
|
|
this.externalLink = undefined;
|
|
};
|
|
|
|
__decorate([JsonProperty("name", String)], CommonModuleMetadata.prototype, "name", void 0);
|
|
|
|
__decorate([JsonProperty("description", String, PropertyConvertingMode.IGNORE_NULLABLE)], CommonModuleMetadata.prototype, "description", void 0);
|
|
|
|
__decorate([JsonProperty("image", String, PropertyConvertingMode.IGNORE_NULLABLE)], CommonModuleMetadata.prototype, "image", void 0);
|
|
|
|
__decorate([JsonProperty("external_link", String, PropertyConvertingMode.IGNORE_NULLABLE)], CommonModuleMetadata.prototype, "externalLink", void 0);
|
|
|
|
CommonModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("CommonModuleMetadata")], CommonModuleMetadata);
|
|
var CommonModuleMetadata$1 = CommonModuleMetadata;
|
|
|
|
var BundleDropModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(BundleDropModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function BundleDropModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.sellerFeeBasisPoints = 0;
|
|
_this.primarySaleFeeBasisPoints = 0;
|
|
_this.feeRecipient = undefined;
|
|
_this.primarySaleRecipientAddress = "";
|
|
return _this;
|
|
}
|
|
|
|
return BundleDropModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], BundleDropModuleMetadata.prototype, "sellerFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("primary_sale_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], BundleDropModuleMetadata.prototype, "primarySaleFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("fee_recipient", String, PropertyConvertingMode.IGNORE_NULLABLE)], BundleDropModuleMetadata.prototype, "feeRecipient", void 0);
|
|
|
|
__decorate([JsonProperty("primary_sale_recipient_address", String)], BundleDropModuleMetadata.prototype, "primarySaleRecipientAddress", void 0);
|
|
|
|
BundleDropModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("BundleDropModuleMetadata")], BundleDropModuleMetadata);
|
|
|
|
var BundleModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(BundleModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function BundleModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.sellerFeeBasisPoints = 0;
|
|
_this.feeRecipient = undefined;
|
|
return _this;
|
|
}
|
|
|
|
return BundleModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], BundleModuleMetadata.prototype, "sellerFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("fee_recipient", String, PropertyConvertingMode.IGNORE_NULLABLE)], BundleModuleMetadata.prototype, "feeRecipient", void 0);
|
|
|
|
BundleModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("CollectionModuleMetadata")], BundleModuleMetadata);
|
|
|
|
var CurrencyModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(CurrencyModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function CurrencyModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.symbol = "";
|
|
return _this;
|
|
}
|
|
|
|
return CurrencyModuleMetadata;
|
|
}(CommonModuleMetadata);
|
|
|
|
__decorate([JsonProperty("symbol", String)], CurrencyModuleMetadata.prototype, "symbol", void 0);
|
|
|
|
CurrencyModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("CurrencyModuleMetadata")], CurrencyModuleMetadata);
|
|
|
|
var DatastoreModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(DatastoreModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function DatastoreModuleMetadata() {
|
|
return _CommonModuleMetadata.apply(this, arguments) || this;
|
|
}
|
|
|
|
return DatastoreModuleMetadata;
|
|
}(CommonModuleMetadata);
|
|
|
|
DatastoreModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("DatastoreModuleMetadata")], DatastoreModuleMetadata);
|
|
|
|
var DropModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(DropModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function DropModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.sellerFeeBasisPoints = 0;
|
|
_this.primarySaleFeeBasisPoints = 0;
|
|
_this.feeRecipient = undefined;
|
|
_this.symbol = void 0;
|
|
_this.maxSupply = 1;
|
|
_this.primarySaleRecipientAddress = "";
|
|
_this.baseTokenUri = "";
|
|
return _this;
|
|
}
|
|
|
|
return DropModuleMetadata;
|
|
}(CommonModuleMetadata);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "sellerFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("primary_sale_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "primarySaleFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("fee_recipient", String, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "feeRecipient", void 0);
|
|
|
|
__decorate([JsonProperty("symbol", String, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "symbol", void 0);
|
|
|
|
__decorate([JsonProperty("max_supply", Number, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "maxSupply", void 0);
|
|
|
|
__decorate([JsonProperty("primary_sale_recipient_address", String)], DropModuleMetadata.prototype, "primarySaleRecipientAddress", void 0);
|
|
|
|
__decorate([JsonProperty("base_token_uri", String, PropertyConvertingMode.IGNORE_NULLABLE)], DropModuleMetadata.prototype, "baseTokenUri", void 0);
|
|
|
|
DropModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("DropModuleMetadata")], DropModuleMetadata);
|
|
|
|
var MarketModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(MarketModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function MarketModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.marketFeeBasisPoints = 0;
|
|
return _this;
|
|
}
|
|
|
|
return MarketModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], MarketModuleMetadata.prototype, "marketFeeBasisPoints", void 0);
|
|
|
|
MarketModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("MarketModuleMetadata")], MarketModuleMetadata);
|
|
|
|
var MarketplaceModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(MarketplaceModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function MarketplaceModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.marketFeeBasisPoints = 0;
|
|
return _this;
|
|
}
|
|
|
|
return MarketplaceModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], MarketplaceModuleMetadata.prototype, "marketFeeBasisPoints", void 0);
|
|
|
|
MarketplaceModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("MarketplaceModuleMetadata")], MarketplaceModuleMetadata);
|
|
var MarketplaceModuleMetadata$1 = MarketplaceModuleMetadata;
|
|
|
|
var NftModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(NftModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function NftModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.sellerFeeBasisPoints = 0;
|
|
_this.feeRecipient = undefined;
|
|
_this.symbol = void 0;
|
|
_this.defaultSaleRecipientAddress = "";
|
|
_this.primarySaleFeeBasisPoints = 0;
|
|
return _this;
|
|
}
|
|
|
|
return NftModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], NftModuleMetadata.prototype, "sellerFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("fee_recipient", String, PropertyConvertingMode.IGNORE_NULLABLE)], NftModuleMetadata.prototype, "feeRecipient", void 0);
|
|
|
|
__decorate([JsonProperty("symbol", String, PropertyConvertingMode.IGNORE_NULLABLE)], NftModuleMetadata.prototype, "symbol", void 0);
|
|
|
|
__decorate([JsonProperty("default_sale_recipient_address", String, PropertyConvertingMode.IGNORE_NULLABLE)], NftModuleMetadata.prototype, "defaultSaleRecipientAddress", void 0);
|
|
|
|
__decorate([JsonProperty("sale_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], NftModuleMetadata.prototype, "primarySaleFeeBasisPoints", void 0);
|
|
|
|
NftModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("NftModuleMetadata")], NftModuleMetadata);
|
|
|
|
var PackModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(PackModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function PackModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.sellerFeeBasisPoints = 0;
|
|
_this.feeRecipient = undefined;
|
|
return _this;
|
|
}
|
|
|
|
return PackModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("seller_fee_basis_points", Number, PropertyConvertingMode.IGNORE_NULLABLE)], PackModuleMetadata.prototype, "sellerFeeBasisPoints", void 0);
|
|
|
|
__decorate([JsonProperty("fee_recipient", String, PropertyConvertingMode.IGNORE_NULLABLE)], PackModuleMetadata.prototype, "feeRecipient", void 0);
|
|
|
|
PackModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("PackModuleMetadata")], PackModuleMetadata);
|
|
|
|
var SplitsModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(SplitsModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function SplitsModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.recipientSplits = [];
|
|
_this.isRoyalty = false;
|
|
return _this;
|
|
}
|
|
|
|
return SplitsModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("is_royalty", Boolean, PropertyConvertingMode.IGNORE_NULLABLE)], SplitsModuleMetadata.prototype, "isRoyalty", void 0);
|
|
|
|
SplitsModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("SplitsModuleMetadata")], SplitsModuleMetadata);
|
|
|
|
var TokenModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(TokenModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function TokenModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.symbol = "";
|
|
return _this;
|
|
}
|
|
|
|
return TokenModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("symbol", String)], TokenModuleMetadata.prototype, "symbol", void 0);
|
|
|
|
TokenModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("TokenModuleMetadata")], TokenModuleMetadata);
|
|
|
|
var VoteModuleMetadata = /*#__PURE__*/function (_CommonModuleMetadata) {
|
|
_inheritsLoose(VoteModuleMetadata, _CommonModuleMetadata);
|
|
|
|
function VoteModuleMetadata() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _CommonModuleMetadata.call.apply(_CommonModuleMetadata, [this].concat(args)) || this;
|
|
_this.proposalStartWaitTimeInSeconds = 0;
|
|
_this.proposalVotingTimeInSeconds = 0;
|
|
_this.votingDelay = 0;
|
|
_this.votingPeriod = 0;
|
|
_this.votingTokenAddress = "";
|
|
_this.votingQuorumFraction = 0;
|
|
_this.minimumNumberOfTokensNeededToPropose = "0";
|
|
return _this;
|
|
}
|
|
|
|
return VoteModuleMetadata;
|
|
}(CommonModuleMetadata$1);
|
|
|
|
__decorate([JsonProperty("proposal_start_time_in_seconds", Number)], VoteModuleMetadata.prototype, "proposalStartWaitTimeInSeconds", void 0);
|
|
|
|
__decorate([JsonProperty("proposal_voting_time_in_seconds", Number)], VoteModuleMetadata.prototype, "proposalVotingTimeInSeconds", void 0);
|
|
|
|
__decorate([JsonProperty("voting_delay", Number)], VoteModuleMetadata.prototype, "votingDelay", void 0);
|
|
|
|
__decorate([JsonProperty("voting_period", Number)], VoteModuleMetadata.prototype, "votingPeriod", void 0);
|
|
|
|
__decorate([JsonProperty("voting_token_address", String)], VoteModuleMetadata.prototype, "votingTokenAddress", void 0);
|
|
|
|
__decorate([JsonProperty("voting_quorum_fraction", Number)], VoteModuleMetadata.prototype, "votingQuorumFraction", void 0);
|
|
|
|
__decorate([JsonProperty("proposal_token_threshold", String)], VoteModuleMetadata.prototype, "minimumNumberOfTokensNeededToPropose", void 0);
|
|
|
|
VoteModuleMetadata = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("VoteModuleMetadata")], VoteModuleMetadata);
|
|
|
|
var _DEFAULT_BLOCK_TIMES_;
|
|
/**
|
|
* Fallback map of default block mining times in seconds.
|
|
|
|
*/
|
|
|
|
var DEFAULT_BLOCK_TIMES_FALLBACK = (_DEFAULT_BLOCK_TIMES_ = {}, _DEFAULT_BLOCK_TIMES_[ChainId.Mainnet] = {
|
|
secondsBetweenBlocks: 15,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Rinkeby] = {
|
|
secondsBetweenBlocks: 15,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Polygon] = {
|
|
secondsBetweenBlocks: 2.5,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Mumbai] = {
|
|
secondsBetweenBlocks: 2.5,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Fantom] = {
|
|
secondsBetweenBlocks: 1,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.FantomTestnet] = {
|
|
secondsBetweenBlocks: 1,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Avalanche] = {
|
|
secondsBetweenBlocks: 1,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.AvalancheFujiTestnet] = {
|
|
secondsBetweenBlocks: 1,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_[ChainId.Hardhat] = {
|
|
secondsBetweenBlocks: 1,
|
|
synced: false
|
|
}, _DEFAULT_BLOCK_TIMES_);
|
|
/**
|
|
* Given a time in second, return the block number that the time is in.
|
|
*
|
|
* @param timeInEpochSeconds - The time in seconds.
|
|
* @param chainId - The chain id.
|
|
* @returns - The block number.
|
|
*/
|
|
|
|
function estimateBlockAtTime(_x, _x2) {
|
|
return _estimateBlockAtTime.apply(this, arguments);
|
|
}
|
|
|
|
function _estimateBlockAtTime() {
|
|
_estimateBlockAtTime = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(timeInEpochSeconds, provider) {
|
|
var secondsUntil, chainId, estimateSecondsBetweenBlocks, latestBlock, secondsBetweenBlocks, blocksUntil;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
secondsUntil = Math.floor(timeInEpochSeconds - Date.now() / 1000);
|
|
_context2.next = 3;
|
|
return provider.getNetwork();
|
|
|
|
case 3:
|
|
chainId = _context2.sent.chainId;
|
|
!SUPPORTED_CHAIN_IDS.includes(chainId) ? process.env.NODE_ENV !== "production" ? invariant(false, "Chain id " + chainId + " is not supported") : invariant(false) : void 0;
|
|
!(timeInEpochSeconds >= Date.now() / 1000) ? process.env.NODE_ENV !== "production" ? invariant(false, "This function should not be used to estimate past block times") : invariant(false) : void 0;
|
|
|
|
estimateSecondsBetweenBlocks = /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var blockTimes, latest, i, current, previous, diff, sum;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
blockTimes = [];
|
|
_context.next = 3;
|
|
return provider.getBlock("latest");
|
|
|
|
case 3:
|
|
latest = _context.sent;
|
|
i = 0;
|
|
|
|
case 5:
|
|
if (!(i < 5)) {
|
|
_context.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context.next = 8;
|
|
return provider.getBlock(latest.number - i);
|
|
|
|
case 8:
|
|
current = _context.sent;
|
|
_context.next = 11;
|
|
return provider.getBlock(latest.number - i - 1);
|
|
|
|
case 11:
|
|
previous = _context.sent;
|
|
diff = current.timestamp - previous.timestamp;
|
|
blockTimes.push(diff);
|
|
|
|
case 14:
|
|
i++;
|
|
_context.next = 5;
|
|
break;
|
|
|
|
case 17:
|
|
sum = blockTimes.reduce(function (result, a) {
|
|
return result + a;
|
|
}, 0);
|
|
return _context.abrupt("return", sum / blockTimes.length);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee);
|
|
}));
|
|
|
|
return function estimateSecondsBetweenBlocks() {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}();
|
|
|
|
if (!DEFAULT_BLOCK_TIMES_FALLBACK[chainId].synced) {
|
|
_context2.next = 9;
|
|
break;
|
|
}
|
|
|
|
return _context2.abrupt("return", DEFAULT_BLOCK_TIMES_FALLBACK[chainId].secondsBetweenBlocks);
|
|
|
|
case 9:
|
|
_context2.next = 11;
|
|
return provider.getBlock("latest");
|
|
|
|
case 11:
|
|
latestBlock = _context2.sent;
|
|
_context2.prev = 12;
|
|
_context2.next = 15;
|
|
return estimateSecondsBetweenBlocks();
|
|
|
|
case 15:
|
|
secondsBetweenBlocks = _context2.sent;
|
|
DEFAULT_BLOCK_TIMES_FALLBACK[chainId] = {
|
|
synced: true,
|
|
secondsBetweenBlocks: secondsBetweenBlocks
|
|
};
|
|
_context2.next = 22;
|
|
break;
|
|
|
|
case 19:
|
|
_context2.prev = 19;
|
|
_context2.t0 = _context2["catch"](12);
|
|
secondsBetweenBlocks = DEFAULT_BLOCK_TIMES_FALLBACK[chainId].secondsBetweenBlocks;
|
|
|
|
case 22:
|
|
console.log("Seconds until block", secondsUntil);
|
|
blocksUntil = Math.ceil(secondsUntil / secondsBetweenBlocks);
|
|
return _context2.abrupt("return", latestBlock.number + blocksUntil);
|
|
|
|
case 25:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, null, [[12, 19]]);
|
|
}));
|
|
return _estimateBlockAtTime.apply(this, arguments);
|
|
}
|
|
|
|
/**
|
|
* Create a standard crypto token or crypto currency.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getTokenModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var TokenModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(TokenModule, _ModuleWithRoles);
|
|
|
|
function TokenModule() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = TokenModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return TokenModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return Coin__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return TokenModule.moduleType;
|
|
};
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return getCurrencyMetadata(this.providerOrSigner, this.address);
|
|
|
|
case 2:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function get() {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}();
|
|
|
|
_proto.getValue = /*#__PURE__*/function () {
|
|
var _getValue = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(value) {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return getCurrencyValue(this.providerOrSigner, this.address, BigNumber.from(value));
|
|
|
|
case 2:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getValue(_x) {
|
|
return _getValue.apply(this, arguments);
|
|
}
|
|
|
|
return getValue;
|
|
}();
|
|
|
|
_proto.totalSupply = /*#__PURE__*/function () {
|
|
var _totalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.readOnlyContract.totalSupply();
|
|
|
|
case 2:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function totalSupply() {
|
|
return _totalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalSupply;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.t0 = this;
|
|
_context4.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context4.t1 = _context4.sent;
|
|
_context4.next = 6;
|
|
return _context4.t0.balanceOf.call(_context4.t0, _context4.t1);
|
|
|
|
case 6:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}()
|
|
/**
|
|
* Get Token Balance
|
|
*
|
|
* @remarks Get a wallets token balance.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check token balance
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* const balance = await module.balanceOf(address);
|
|
* console.log(balance);
|
|
* ```
|
|
*
|
|
* @returns The balance of a specific wallet.
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address) {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.t0 = this;
|
|
_context5.next = 3;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 3:
|
|
_context5.t1 = _context5.sent;
|
|
_context5.next = 6;
|
|
return _context5.t0.getValue.call(_context5.t0, _context5.t1);
|
|
|
|
case 6:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function balanceOf(_x2) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.allowance = /*#__PURE__*/function () {
|
|
var _allowance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(spender) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.t0 = this;
|
|
_context6.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context6.t1 = _context6.sent;
|
|
_context6.t2 = spender;
|
|
_context6.next = 7;
|
|
return _context6.t0.allowanceOf.call(_context6.t0, _context6.t1, _context6.t2);
|
|
|
|
case 7:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function allowance(_x3) {
|
|
return _allowance.apply(this, arguments);
|
|
}
|
|
|
|
return allowance;
|
|
}()
|
|
/**
|
|
* Get Token Allowance
|
|
*
|
|
* @remarks Get the allowance of one wallet over another's funds - the allowance of a different address for a token is the amount of tokens that the wallet is allowed to spend on behalf of the connected wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet who owns the funds
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* // Address of the wallet to check token allowance
|
|
* const otherAddress = "0x...";
|
|
*
|
|
* const allowance = await module.allowanceOf(address, otherAddress);
|
|
* console.log(allowance);
|
|
* ```
|
|
*
|
|
* @returns The allowance of one wallet over anothers funds.
|
|
*/
|
|
;
|
|
|
|
_proto.allowanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _allowanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(owner, spender) {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.readOnlyContract.allowance(owner, spender);
|
|
|
|
case 2:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function allowanceOf(_x4, _x5) {
|
|
return _allowanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return allowanceOf;
|
|
}()
|
|
/**
|
|
* Get your wallet voting power for the current checkpoints
|
|
*
|
|
* @returns the amount of voting power in tokens
|
|
*/
|
|
;
|
|
|
|
_proto.getVoteBalance =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getVoteBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.t0 = this;
|
|
_context8.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context8.t1 = _context8.sent;
|
|
_context8.next = 6;
|
|
return _context8.t0.getVoteBalanceOf.call(_context8.t0, _context8.t1);
|
|
|
|
case 6:
|
|
return _context8.abrupt("return", _context8.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function getVoteBalance() {
|
|
return _getVoteBalance.apply(this, arguments);
|
|
}
|
|
|
|
return getVoteBalance;
|
|
}();
|
|
|
|
_proto.getVoteBalanceOf = /*#__PURE__*/function () {
|
|
var _getVoteBalanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(account) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.getVotes(account);
|
|
|
|
case 2:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function getVoteBalanceOf(_x6) {
|
|
return _getVoteBalanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return getVoteBalanceOf;
|
|
}()
|
|
/**
|
|
* Get your voting delegatee address
|
|
*
|
|
* @returns the address of your vote delegatee
|
|
*/
|
|
;
|
|
|
|
_proto.getDelegation =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getDelegation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10() {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.t0 = this;
|
|
_context10.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context10.t1 = _context10.sent;
|
|
_context10.next = 6;
|
|
return _context10.t0.getDelegationOf.call(_context10.t0, _context10.t1);
|
|
|
|
case 6:
|
|
return _context10.abrupt("return", _context10.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function getDelegation() {
|
|
return _getDelegation.apply(this, arguments);
|
|
}
|
|
|
|
return getDelegation;
|
|
}();
|
|
|
|
_proto.getDelegationOf = /*#__PURE__*/function () {
|
|
var _getDelegationOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(account) {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.readOnlyContract.delegates(account);
|
|
|
|
case 2:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function getDelegationOf(_x7) {
|
|
return _getDelegationOf.apply(this, arguments);
|
|
}
|
|
|
|
return getDelegationOf;
|
|
}()
|
|
/**
|
|
* Lets you delegate your voting power to the delegateeAddress
|
|
*
|
|
* @param delegateeAddress - delegatee wallet address
|
|
* @alpha
|
|
*/
|
|
;
|
|
|
|
_proto.delegateTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _delegateTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(delegateeAddress) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.sendTransaction("delegate", [delegateeAddress]);
|
|
|
|
case 2:
|
|
return _context12.abrupt("return", _context12.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function delegateTo(_x8) {
|
|
return _delegateTo.apply(this, arguments);
|
|
}
|
|
|
|
return delegateTo;
|
|
}()
|
|
/**
|
|
* Transfer Tokens
|
|
*
|
|
* @remarks Transfer tokens from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the tokens to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The amount of tokens you want to send
|
|
* const amount = 0;
|
|
*
|
|
* await module.transfer(toAddress, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(to, amount) {
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.sendTransaction("transfer", [to, amount]);
|
|
|
|
case 2:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function transfer(_x9, _x10) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}();
|
|
|
|
_proto.setAllowance = /*#__PURE__*/function () {
|
|
var _setAllowance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(spender, amount) {
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.next = 2;
|
|
return this.sendTransaction("approve", [spender, amount]);
|
|
|
|
case 2:
|
|
return _context14.abrupt("return", _context14.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function setAllowance(_x11, _x12) {
|
|
return _setAllowance.apply(this, arguments);
|
|
}
|
|
|
|
return setAllowance;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.mint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(amount) {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.t0 = this;
|
|
_context15.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context15.t1 = _context15.sent;
|
|
_context15.t2 = amount;
|
|
_context15.next = 7;
|
|
return _context15.t0.mintTo.call(_context15.t0, _context15.t1, _context15.t2);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function mint(_x13) {
|
|
return _mint.apply(this, arguments);
|
|
}
|
|
|
|
return mint;
|
|
}()
|
|
/**
|
|
* Mint Tokens
|
|
*
|
|
* @remarks Mint tokens to a specified address
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to mint the tokens to
|
|
* const toAddress = "{{wallet_address}}";
|
|
*
|
|
* // The amount of this token you want to mint
|
|
* const amount = ethers.utils.parseEther("1.5");
|
|
*
|
|
* await module.mintTo(toAddress, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.mintTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mintTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(to, amount) {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.sendTransaction("mint", [to, amount]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function mintTo(_x14, _x15) {
|
|
return _mintTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintTo;
|
|
}()
|
|
/**
|
|
* Mint Tokens To Many Wallets
|
|
*
|
|
* @remarks Mint tokens to many different wallets
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Data of the tokens you want to mint
|
|
* const data = [
|
|
* {
|
|
* address: "{{wallet_address}}", // Address to mint tokens to
|
|
* amount: 100, // How many tokens to mint to specified address
|
|
* },
|
|
* {
|
|
* address: "0x...",
|
|
* amount: 100,
|
|
* }
|
|
* ]
|
|
*
|
|
* await module.mintBatchTo(data);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.mintBatchTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mintBatchTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(args) {
|
|
var encoded, _iterator, _step, arg;
|
|
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
encoded = [];
|
|
|
|
for (_iterator = _createForOfIteratorHelperLoose(args); !(_step = _iterator()).done;) {
|
|
arg = _step.value;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("mint", [arg.address, arg.amount]));
|
|
}
|
|
|
|
_context17.next = 4;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function mintBatchTo(_x16) {
|
|
return _mintBatchTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintBatchTo;
|
|
}()
|
|
/**
|
|
* Lets you get a all token holders and their corresponding balances
|
|
* @beta - This can be very slow for large numbers of token holders
|
|
* @param queryParams - Optional query params
|
|
* @returns - A JSON object of all token holders and their corresponding balances
|
|
*/
|
|
;
|
|
|
|
_proto.getAllHolderBalances =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllHolderBalances = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18() {
|
|
var a, txns, balances;
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
_context18.next = 2;
|
|
return this.contract.queryFilter(this.contract.filters.Transfer());
|
|
|
|
case 2:
|
|
a = _context18.sent;
|
|
txns = a.map(function (b) {
|
|
return b.args;
|
|
});
|
|
balances = {};
|
|
txns.forEach(function (item) {
|
|
var from = item.from;
|
|
var to = item.to;
|
|
var amount = item.value;
|
|
|
|
if (!(from === AddressZero)) {
|
|
if (!(from in balances)) {
|
|
balances[from] = BigNumber.from(0);
|
|
}
|
|
|
|
balances[from] = balances[from].sub(amount);
|
|
}
|
|
|
|
if (!(to === AddressZero)) {
|
|
if (!(to in balances)) {
|
|
balances[to] = BigNumber.from(0);
|
|
}
|
|
|
|
balances[to] = balances[to].add(amount);
|
|
}
|
|
});
|
|
return _context18.abrupt("return", balances);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function getAllHolderBalances() {
|
|
return _getAllHolderBalances.apply(this, arguments);
|
|
}
|
|
|
|
return getAllHolderBalances;
|
|
}()
|
|
/**
|
|
* Burn Tokens
|
|
*
|
|
* @remarks Burn tokens held by the connected wallet
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The amount of this token you want to burn
|
|
* const amount = 100;
|
|
*
|
|
* await module.burn(amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.burn =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(amount) {
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return this.sendTransaction("burn", [amount]);
|
|
|
|
case 2:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function burn(_x17) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.burnFrom = /*#__PURE__*/function () {
|
|
var _burnFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(from, amount) {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.next = 2;
|
|
return this.sendTransaction("burnFrom", [from, amount]);
|
|
|
|
case 2:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function burnFrom(_x18, _x19) {
|
|
return _burnFrom.apply(this, arguments);
|
|
}
|
|
|
|
return burnFrom;
|
|
}()
|
|
/**
|
|
* Transfer Tokens From Address
|
|
*
|
|
* @remarks Transfer tokens from one wallet to another
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet sending the tokens
|
|
* const fromAddress = "{{wallet_address}}";
|
|
* // Address of the wallet you want to send the tokens to
|
|
* const toAddress = "0x...";
|
|
* // The number of tokens you want to send
|
|
* const amount = 100
|
|
*
|
|
* // Note that the connected wallet must have approval to transfer the tokens of the fromAddress
|
|
* await module.transferFrom(fromAddress, toAddress, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transferFrom =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(from, to, amount) {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.sendTransaction("transferFrom", [from, to, amount]);
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function transferFrom(_x20, _x21, _x22) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context22.sent;
|
|
_context22.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context22.abrupt("return", _context22.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x23) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto.transferBatch = /*#__PURE__*/function () {
|
|
var _transferBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(args) {
|
|
var _this = this;
|
|
|
|
var encoded;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
encoded = args.map(function (arg) {
|
|
return _this.contract["interface"].encodeFunctionData("transfer", [arg.address, arg.amount]);
|
|
});
|
|
_context23.next = 3;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function transferBatch(_x24) {
|
|
return _transferBatch.apply(this, arguments);
|
|
}
|
|
|
|
return transferBatch;
|
|
}();
|
|
|
|
_proto.transferFromBatch = /*#__PURE__*/function () {
|
|
var _transferFromBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(args) {
|
|
var _this2 = this;
|
|
|
|
var encoded;
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
encoded = args.map(function (arg) {
|
|
return _this2.contract["interface"].encodeFunctionData("transferFrom", [arg.fromAddress, arg.address, arg.amount]);
|
|
});
|
|
_context24.next = 3;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function transferFromBatch(_x25) {
|
|
return _transferFromBatch.apply(this, arguments);
|
|
}
|
|
|
|
return transferFromBatch;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25() {
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
return _context25.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(restricted) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context26.t0 = this;
|
|
_context26.t1 = ["admin"];
|
|
_context26.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context26.t2 = _context26.sent;
|
|
_context26.next = 8;
|
|
return _context26.t0.onlyRoles.call(_context26.t0, _context26.t1, _context26.t2);
|
|
|
|
case 8:
|
|
_context26.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x26) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}();
|
|
|
|
return TokenModule;
|
|
}(ModuleWithRoles);
|
|
/**
|
|
* @deprecated - see {@link TokenModule}
|
|
*/
|
|
|
|
TokenModule.moduleType = ModuleType.CURRENCY;
|
|
TokenModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.pauser, RolesMap.transfer];
|
|
var CurrencyModule = /*#__PURE__*/function (_TokenModule) {
|
|
_inheritsLoose(CurrencyModule, _TokenModule);
|
|
|
|
function CurrencyModule() {
|
|
return _TokenModule.apply(this, arguments) || this;
|
|
}
|
|
|
|
return CurrencyModule;
|
|
}(TokenModule);
|
|
|
|
/**
|
|
* Access this module by calling {@link ThirdwebSDK.getAppModule}
|
|
* @public
|
|
*/
|
|
|
|
var AppModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(AppModule, _ModuleWithRoles);
|
|
|
|
function AppModule() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _ModuleWithRoles.call.apply(_ModuleWithRoles, [this].concat(args)) || this;
|
|
_this._shouldCheckVersion = true;
|
|
_this._isV1 = false;
|
|
_this.jsonConvert = new JsonConvert();
|
|
_this.moduleType = -1;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = AppModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return CurrencyModule.roles;
|
|
}
|
|
/**
|
|
* The internal module type for the app module.
|
|
* We do not treat it as a fully fledged module on the contract level, so it does not have a real type.
|
|
* @internal
|
|
* @readonly
|
|
*/
|
|
;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
_proto.connectContract = function connectContract() {
|
|
return ProtocolControl__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return this.moduleType;
|
|
}
|
|
/**
|
|
* @internal
|
|
*
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getModuleAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(moduleType) {
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return this.readOnlyContract.getAllModulesOfType(moduleType);
|
|
|
|
case 2:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function getModuleAddress(_x) {
|
|
return _getModuleAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getModuleAddress;
|
|
}();
|
|
|
|
_proto.getNFTAddress = /*#__PURE__*/function () {
|
|
var _getNFTAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
return _context2.abrupt("return", this.getModuleAddress(ModuleType.NFT));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getNFTAddress() {
|
|
return _getNFTAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getNFTAddress;
|
|
}();
|
|
|
|
_proto.getBundleAddress = /*#__PURE__*/function () {
|
|
var _getBundleAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
return _context3.abrupt("return", this.getModuleAddress(ModuleType.BUNDLE));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getBundleAddress() {
|
|
return _getBundleAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getBundleAddress;
|
|
}();
|
|
|
|
_proto.getPackAddress = /*#__PURE__*/function () {
|
|
var _getPackAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
return _context4.abrupt("return", this.getModuleAddress(ModuleType.PACK));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getPackAddress() {
|
|
return _getPackAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getPackAddress;
|
|
}();
|
|
|
|
_proto.getCurrencyAddress = /*#__PURE__*/function () {
|
|
var _getCurrencyAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
return _context5.abrupt("return", this.getModuleAddress(ModuleType.CURRENCY));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getCurrencyAddress() {
|
|
return _getCurrencyAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getCurrencyAddress;
|
|
}();
|
|
|
|
_proto.getMarketAddress = /*#__PURE__*/function () {
|
|
var _getMarketAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
return _context6.abrupt("return", this.getModuleAddress(ModuleType.MARKET));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function getMarketAddress() {
|
|
return _getMarketAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getMarketAddress;
|
|
}();
|
|
|
|
_proto.getDropAddress = /*#__PURE__*/function () {
|
|
var _getDropAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
return _context7.abrupt("return", this.getModuleAddress(ModuleType.DROP));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getDropAddress() {
|
|
return _getDropAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getDropAddress;
|
|
}();
|
|
|
|
_proto.getDatastoreAddress = /*#__PURE__*/function () {
|
|
var _getDatastoreAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
return _context8.abrupt("return", this.getModuleAddress(ModuleType.DATASTORE));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function getDatastoreAddress() {
|
|
return _getDatastoreAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getDatastoreAddress;
|
|
}();
|
|
|
|
_proto.getRoyaltyTreasury = /*#__PURE__*/function () {
|
|
var _getRoyaltyTreasury = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(address) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.getRoyaltyTreasury(address || AddressZero);
|
|
|
|
case 2:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function getRoyaltyTreasury(_x2) {
|
|
return _getRoyaltyTreasury.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyTreasury;
|
|
}()
|
|
/**
|
|
* @internal
|
|
* @param addresses - The addresses of the modules to get metadata for.
|
|
*/
|
|
;
|
|
|
|
_proto.getAllContractMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllContractMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(addresses, resolveGateway) {
|
|
var _this2 = this;
|
|
|
|
var metadatas;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
if (resolveGateway === void 0) {
|
|
resolveGateway = true;
|
|
}
|
|
|
|
_context10.next = 3;
|
|
return Promise.all(addresses.map(function (address) {
|
|
return getContractMetadata(_this2.providerOrSigner, address, _this2.sdk.getStorage(), resolveGateway);
|
|
}));
|
|
|
|
case 3:
|
|
metadatas = _context10.sent;
|
|
return _context10.abrupt("return", addresses.filter(function (d) {
|
|
return d;
|
|
}).map(function (address, i) {
|
|
return {
|
|
address: address,
|
|
metadata: metadatas[i]
|
|
};
|
|
}));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10);
|
|
}));
|
|
|
|
function getAllContractMetadata(_x3, _x4) {
|
|
return _getAllContractMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return getAllContractMetadata;
|
|
}()
|
|
/**
|
|
* Method to get a list of pack module metadata.
|
|
* @returns A promise of an array of Pack modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getPackModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getPackModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11() {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.t0 = this;
|
|
_context11.next = 3;
|
|
return this.getPackAddress();
|
|
|
|
case 3:
|
|
_context11.t1 = _context11.sent;
|
|
_context11.next = 6;
|
|
return _context11.t0.getAllContractMetadata.call(_context11.t0, _context11.t1);
|
|
|
|
case 6:
|
|
return _context11.abrupt("return", _context11.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.PACK
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function getPackModules() {
|
|
return _getPackModules.apply(this, arguments);
|
|
}
|
|
|
|
return getPackModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of NFT module metadata.
|
|
* @returns A promise of an array of NFT modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getNFTModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getNFTModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12() {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.t0 = this;
|
|
_context12.next = 3;
|
|
return this.getNFTAddress();
|
|
|
|
case 3:
|
|
_context12.t1 = _context12.sent;
|
|
_context12.next = 6;
|
|
return _context12.t0.getAllContractMetadata.call(_context12.t0, _context12.t1);
|
|
|
|
case 6:
|
|
return _context12.abrupt("return", _context12.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.NFT
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function getNFTModules() {
|
|
return _getNFTModules.apply(this, arguments);
|
|
}
|
|
|
|
return getNFTModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of Bundle module metadata.
|
|
* @returns A promise of an array of Bundle modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getCollectionModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getCollectionModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13() {
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.getBundleModules();
|
|
|
|
case 2:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function getCollectionModules() {
|
|
return _getCollectionModules.apply(this, arguments);
|
|
}
|
|
|
|
return getCollectionModules;
|
|
}();
|
|
|
|
_proto.getBundleModules = /*#__PURE__*/function () {
|
|
var _getBundleModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14() {
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.t0 = this;
|
|
_context14.next = 3;
|
|
return this.getBundleAddress();
|
|
|
|
case 3:
|
|
_context14.t1 = _context14.sent;
|
|
_context14.next = 6;
|
|
return _context14.t0.getAllContractMetadata.call(_context14.t0, _context14.t1);
|
|
|
|
case 6:
|
|
return _context14.abrupt("return", _context14.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.BUNDLE
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function getBundleModules() {
|
|
return _getBundleModules.apply(this, arguments);
|
|
}
|
|
|
|
return getBundleModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of Currency module metadata.
|
|
* @returns A promise of an array of Currency modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getCurrencyModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getCurrencyModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15() {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.t0 = this;
|
|
_context15.next = 3;
|
|
return this.getCurrencyAddress();
|
|
|
|
case 3:
|
|
_context15.t1 = _context15.sent;
|
|
_context15.next = 6;
|
|
return _context15.t0.getAllContractMetadata.call(_context15.t0, _context15.t1);
|
|
|
|
case 6:
|
|
return _context15.abrupt("return", _context15.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.CURRENCY
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function getCurrencyModules() {
|
|
return _getCurrencyModules.apply(this, arguments);
|
|
}
|
|
|
|
return getCurrencyModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of Datastore module metadata.
|
|
* @alpha
|
|
* @returns A promise of an array of Datastore modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getDatastoreModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getDatastoreModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16() {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.t0 = this;
|
|
_context16.next = 3;
|
|
return this.getDatastoreAddress();
|
|
|
|
case 3:
|
|
_context16.t1 = _context16.sent;
|
|
_context16.next = 6;
|
|
return _context16.t0.getAllContractMetadata.call(_context16.t0, _context16.t1);
|
|
|
|
case 6:
|
|
return _context16.abrupt("return", _context16.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.DATASTORE
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function getDatastoreModules() {
|
|
return _getDatastoreModules.apply(this, arguments);
|
|
}
|
|
|
|
return getDatastoreModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of Market module metadata.
|
|
* @returns A promise of an array of Market modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getMarketModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getMarketModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17() {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
_context17.t0 = this;
|
|
_context17.next = 3;
|
|
return this.getMarketAddress();
|
|
|
|
case 3:
|
|
_context17.t1 = _context17.sent;
|
|
_context17.next = 6;
|
|
return _context17.t0.getAllContractMetadata.call(_context17.t0, _context17.t1);
|
|
|
|
case 6:
|
|
return _context17.abrupt("return", _context17.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.MARKET
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function getMarketModules() {
|
|
return _getMarketModules.apply(this, arguments);
|
|
}
|
|
|
|
return getMarketModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of Drop module metadata.
|
|
* @returns A promise of an array of Drop modules.
|
|
* @deprecated - Use {@link AppModule.getAllModuleMetadata} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getDropModules =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getDropModules = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18() {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
_context18.t0 = this;
|
|
_context18.next = 3;
|
|
return this.getDropAddress();
|
|
|
|
case 3:
|
|
_context18.t1 = _context18.sent;
|
|
_context18.next = 6;
|
|
return _context18.t0.getAllContractMetadata.call(_context18.t0, _context18.t1);
|
|
|
|
case 6:
|
|
return _context18.abrupt("return", _context18.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: ModuleType.DROP
|
|
});
|
|
}));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function getDropModules() {
|
|
return _getDropModules.apply(this, arguments);
|
|
}
|
|
|
|
return getDropModules;
|
|
}()
|
|
/**
|
|
* Method to get a list of all module metadata on a given app.
|
|
* @public
|
|
* @param filterByModuleType - Optional array of {@link ModuleType} to filter by.
|
|
* @returns Array of module metadata
|
|
*/
|
|
;
|
|
|
|
_proto.getAllModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(filterByModuleType, resolveGateway) {
|
|
var _this3 = this;
|
|
|
|
var moduleTypesToGet;
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
if (resolveGateway === void 0) {
|
|
resolveGateway = true;
|
|
}
|
|
|
|
moduleTypesToGet = filterByModuleType || [ModuleType.NFT, ModuleType.BUNDLE, ModuleType.PACK, ModuleType.TOKEN, ModuleType.MARKET, ModuleType.DATASTORE, ModuleType.DROP, ModuleType.BUNDLE_DROP, ModuleType.VOTE];
|
|
_context20.next = 4;
|
|
return Promise.all(moduleTypesToGet.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(moduleType) {
|
|
var moduleAddresses;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return _this3.getModuleAddress(moduleType);
|
|
|
|
case 2:
|
|
moduleAddresses = _context19.sent;
|
|
_context19.next = 5;
|
|
return _this3.getAllContractMetadata(moduleAddresses, resolveGateway);
|
|
|
|
case 5:
|
|
return _context19.abrupt("return", _context19.sent.map(function (m) {
|
|
return _extends({}, m, {
|
|
type: moduleType
|
|
});
|
|
}));
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19);
|
|
}));
|
|
|
|
return function (_x7) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 4:
|
|
return _context20.abrupt("return", _context20.sent.reduce(function (acc, curr) {
|
|
return acc.concat(curr);
|
|
}, []));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20);
|
|
}));
|
|
|
|
function getAllModuleMetadata(_x5, _x6) {
|
|
return _getAllModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return getAllModuleMetadata;
|
|
}()
|
|
/**
|
|
* Trusted forwarder is used to forward gasless transactions. Trusted Forwarder of each module cannot be changed once it is deployed.
|
|
*
|
|
* @returns The address of the trusted forwarder contract
|
|
*/
|
|
;
|
|
|
|
_proto.getForwarder =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getForwarder = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21() {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.readOnlyContract.getForwarder();
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function getForwarder() {
|
|
return _getForwarder.apply(this, arguments);
|
|
}
|
|
|
|
return getForwarder;
|
|
}() // owner functions
|
|
|
|
/**
|
|
* Set trusted forwarder for the modules. Every module that is deployed after this call will use the new forwarder.
|
|
* Trusted forwarder is used to forward gasless transactions. Trusted Forwarder of each module cannot be changed once it is deployed.
|
|
*
|
|
* @param address - The address of the trusted forwarder contract
|
|
*/
|
|
;
|
|
|
|
_proto.setForwarder =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setForwarder = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(address) {
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.next = 2;
|
|
return this.contract.setForwarder(address);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setForwarder(_x8) {
|
|
return _setForwarder.apply(this, arguments);
|
|
}
|
|
|
|
return setForwarder;
|
|
}()
|
|
/**
|
|
* @deprecated - Use setMetadata() instead
|
|
*/
|
|
;
|
|
|
|
_proto.setModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context23.sent;
|
|
_context23.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context23.abrupt("return", _context23.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x9) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto.setRoyaltyTreasury = /*#__PURE__*/function () {
|
|
var _setRoyaltyTreasury = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(treasury) {
|
|
var _e$message;
|
|
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
_context24.prev = 0;
|
|
_context24.next = 3;
|
|
return this.sendTransaction("setRoyaltyTreasury", [treasury]);
|
|
|
|
case 3:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 6:
|
|
_context24.prev = 6;
|
|
_context24.t0 = _context24["catch"](0);
|
|
|
|
if (!(_context24.t0 != null && (_e$message = _context24.t0.message) != null && _e$message.includes("provider shares too low"))) {
|
|
_context24.next = 10;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Missing thirdweb fees. Please set it to a Royalty Splits address, which can deployed using \"deployRoyaltySplitsModule({...})\".");
|
|
|
|
case 10:
|
|
throw _context24.t0;
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this, [[0, 6]]);
|
|
}));
|
|
|
|
function setRoyaltyTreasury(_x10) {
|
|
return _setRoyaltyTreasury.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyTreasury;
|
|
}();
|
|
|
|
_proto.setModuleRoyaltyTreasury = /*#__PURE__*/function () {
|
|
var _setModuleRoyaltyTreasury = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(moduleAddress, treasury) {
|
|
var moduleContract, metadata, uri, _e$message2;
|
|
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
// Note: connecting module address contract. Only need to access setContractURI abi
|
|
// any Interface with setContractURI can be used.
|
|
moduleContract = new Contract$1(moduleAddress, ProtocolControl__factory.createInterface(), this.providerOrSigner);
|
|
_context25.next = 3;
|
|
return getContractMetadata(this.providerOrSigner, moduleAddress, this.sdk.getStorage(), false);
|
|
|
|
case 3:
|
|
metadata = _context25.sent;
|
|
_context25.next = 6;
|
|
return this.sdk.getStorage().uploadMetadata(_extends({}, metadata, {
|
|
fee_recipient: treasury
|
|
}));
|
|
|
|
case 6:
|
|
uri = _context25.sent;
|
|
_context25.prev = 7;
|
|
_context25.next = 10;
|
|
return this.contract.callStatic.setModuleRoyaltyTreasury(moduleAddress, treasury);
|
|
|
|
case 10:
|
|
_context25.next = 12;
|
|
return moduleContract.callStatic.setContractURI(uri);
|
|
|
|
case 12:
|
|
_context25.next = 19;
|
|
break;
|
|
|
|
case 14:
|
|
_context25.prev = 14;
|
|
_context25.t0 = _context25["catch"](7);
|
|
|
|
if (!(_context25.t0 != null && (_e$message2 = _context25.t0.message) != null && _e$message2.includes("provider shares too low"))) {
|
|
_context25.next = 18;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Missing thirdweb fees. Please set it to a Royalty Splits address, which can deployed using \"deployRoyaltySplitsModule({...})\".");
|
|
|
|
case 18:
|
|
throw _context25.t0;
|
|
|
|
case 19:
|
|
_context25.next = 21;
|
|
return this.sendContractTransaction(moduleContract, "setContractURI", [uri]);
|
|
|
|
case 21:
|
|
_context25.next = 23;
|
|
return this.sendTransaction("setModuleRoyaltyTreasury", [moduleAddress, treasury]);
|
|
|
|
case 23:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this, [[7, 14]]);
|
|
}));
|
|
|
|
function setModuleRoyaltyTreasury(_x11, _x12) {
|
|
return _setModuleRoyaltyTreasury.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleRoyaltyTreasury;
|
|
}()
|
|
/**
|
|
* Checks to see if an address is either the current protocol
|
|
* control address, or a splits module address.
|
|
*
|
|
* @internal
|
|
* @param address - The address to check.
|
|
* @returns - True if the address is of this protocol control or if its a split module.
|
|
*/
|
|
;
|
|
|
|
_proto.isValidRoyaltyRecipient =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isValidRoyaltyRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(address) {
|
|
var contract;
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
if (!(address.toLowerCase() === this.address.toLowerCase())) {
|
|
_context26.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context26.abrupt("return", true);
|
|
|
|
case 2:
|
|
contract = this.sdk.getSplitsModule(address);
|
|
_context26.prev = 3;
|
|
_context26.next = 6;
|
|
return contract.balanceOf(this.address);
|
|
|
|
case 6:
|
|
return _context26.abrupt("return", true);
|
|
|
|
case 9:
|
|
_context26.prev = 9;
|
|
_context26.t0 = _context26["catch"](3);
|
|
return _context26.abrupt("return", false);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this, [[3, 9]]);
|
|
}));
|
|
|
|
function isValidRoyaltyRecipient(_x13) {
|
|
return _isValidRoyaltyRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return isValidRoyaltyRecipient;
|
|
}();
|
|
|
|
_proto.withdrawFunds = /*#__PURE__*/function () {
|
|
var _withdrawFunds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(to, currency) {
|
|
var provider, lastTransaction, isNative, balance, bn, isV2, treasury, treasuryBalance, royalty;
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
provider = this.readOnlyContract.provider;
|
|
lastTransaction = null;
|
|
isNative = isNativeToken(currency);
|
|
|
|
if (isNative) {
|
|
currency = ethers.constants.AddressZero;
|
|
} // should fetch for contract only, not treasury
|
|
|
|
|
|
_context27.next = 6;
|
|
return getCurrencyBalance(provider, currency, this.address);
|
|
|
|
case 6:
|
|
balance = _context27.sent;
|
|
bn = BigNumber.from(balance.value); // tries to withdraw from the project
|
|
|
|
if (!bn.gt(0)) {
|
|
_context27.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context27.next = 11;
|
|
return this.isV1();
|
|
|
|
case 11:
|
|
isV2 = !_context27.sent;
|
|
|
|
if (!(isV2 || isNative)) {
|
|
_context27.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context27.next = 15;
|
|
return this.sendTransaction("withdrawFunds", [to, currency]);
|
|
|
|
case 15:
|
|
lastTransaction = _context27.sent;
|
|
|
|
case 16:
|
|
_context27.next = 18;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 18:
|
|
treasury = _context27.sent;
|
|
|
|
if (!(treasury !== this.address)) {
|
|
_context27.next = 34;
|
|
break;
|
|
}
|
|
|
|
_context27.next = 22;
|
|
return getCurrencyBalance(provider, currency, treasury);
|
|
|
|
case 22:
|
|
treasuryBalance = _context27.sent;
|
|
|
|
if (!BigNumber.from(treasuryBalance.value).gt(0)) {
|
|
_context27.next = 34;
|
|
break;
|
|
}
|
|
|
|
royalty = Royalty__factory.connect(treasury, this.getSigner());
|
|
|
|
if (!isNative) {
|
|
_context27.next = 31;
|
|
break;
|
|
}
|
|
|
|
_context27.next = 28;
|
|
return this.sendContractTransaction(royalty, "distribute()", []);
|
|
|
|
case 28:
|
|
lastTransaction = _context27.sent;
|
|
_context27.next = 34;
|
|
break;
|
|
|
|
case 31:
|
|
_context27.next = 33;
|
|
return this.sendContractTransaction(royalty, "distribute(address)", [currency]);
|
|
|
|
case 33:
|
|
lastTransaction = _context27.sent;
|
|
|
|
case 34:
|
|
if (lastTransaction) {
|
|
_context27.next = 36;
|
|
break;
|
|
}
|
|
|
|
throw new Error("no funds to withdraw");
|
|
|
|
case 36:
|
|
return _context27.abrupt("return", lastTransaction);
|
|
|
|
case 37:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function withdrawFunds(_x14, _x15) {
|
|
return _withdrawFunds.apply(this, arguments);
|
|
}
|
|
|
|
return withdrawFunds;
|
|
}()
|
|
/**
|
|
* Helper method that handles `image` property uploads if its a file
|
|
*
|
|
* @param metadata - The metadata of the module to be deployed
|
|
* @returns - The sanitized metadata with an uploaded image ipfs hash
|
|
*/
|
|
;
|
|
|
|
_proto._prepareMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _prepareMetadata2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(metadata) {
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
if (!(typeof metadata.image === "string")) {
|
|
_context28.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context28.abrupt("return", Promise.resolve(metadata));
|
|
|
|
case 2:
|
|
if (!(metadata.image === undefined)) {
|
|
_context28.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context28.abrupt("return", Promise.resolve(metadata));
|
|
|
|
case 4:
|
|
_context28.t0 = this.sdk.getStorage();
|
|
_context28.t1 = metadata.image;
|
|
_context28.t2 = this.address;
|
|
_context28.next = 9;
|
|
return this.getSignerAddress();
|
|
|
|
case 9:
|
|
_context28.t3 = _context28.sent;
|
|
_context28.next = 12;
|
|
return _context28.t0.upload.call(_context28.t0, _context28.t1, _context28.t2, _context28.t3);
|
|
|
|
case 12:
|
|
metadata.image = _context28.sent;
|
|
return _context28.abrupt("return", Promise.resolve(metadata));
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function _prepareMetadata(_x16) {
|
|
return _prepareMetadata2.apply(this, arguments);
|
|
}
|
|
|
|
return _prepareMetadata;
|
|
}()
|
|
/**
|
|
* Helper method that deploys a module and returns its address
|
|
*
|
|
* @internal
|
|
*
|
|
* @param moduleType - The ModuleType to deploy
|
|
* @param args - Constructor arguments for the module
|
|
* @param factory - The ABI factory used to call the `deploy` method
|
|
* @returns The address of the deployed module
|
|
*/
|
|
;
|
|
|
|
_proto._deployModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployModule2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(moduleType, args, factory) {
|
|
var _ethers$ContractFacto;
|
|
|
|
var gasPrice, txOpts, tx, contractAddress, addModuleTx;
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
_context29.t0 = this;
|
|
_context29.t1 = ["admin"];
|
|
_context29.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context29.t2 = _context29.sent;
|
|
_context29.next = 7;
|
|
return _context29.t0.onlyRoles.call(_context29.t0, _context29.t1, _context29.t2);
|
|
|
|
case 7:
|
|
_context29.next = 9;
|
|
return this.sdk.getGasPrice();
|
|
|
|
case 9:
|
|
gasPrice = _context29.sent;
|
|
txOpts = gasPrice ? {
|
|
gasPrice: ethers.utils.parseUnits(gasPrice.toString(), "gwei")
|
|
} : {};
|
|
_context29.next = 13;
|
|
return (_ethers$ContractFacto = new ethers.ContractFactory(factory.abi, factory.bytecode).connect(this.signer)).deploy.apply(_ethers$ContractFacto, args.concat([txOpts]));
|
|
|
|
case 13:
|
|
tx = _context29.sent;
|
|
_context29.next = 16;
|
|
return tx.deployed();
|
|
|
|
case 16:
|
|
contractAddress = tx.address;
|
|
_context29.next = 19;
|
|
return this.contract.addModule(contractAddress, moduleType, txOpts);
|
|
|
|
case 19:
|
|
addModuleTx = _context29.sent;
|
|
_context29.next = 22;
|
|
return addModuleTx.wait();
|
|
|
|
case 22:
|
|
return _context29.abrupt("return", contractAddress);
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function _deployModule(_x17, _x18, _x19) {
|
|
return _deployModule2.apply(this, arguments);
|
|
}
|
|
|
|
return _deployModule;
|
|
}()
|
|
/**
|
|
* Throws an error if metadata is invalid
|
|
*
|
|
* @param metadata - The metadata to validate
|
|
*/
|
|
;
|
|
|
|
_proto.verifyMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _verifyMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30(metadata) {
|
|
var shouldUpdateRecipient, isValidFeeRecipient;
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
shouldUpdateRecipient = metadata.feeRecipient && metadata.feeRecipient !== this.address;
|
|
_context30.next = 3;
|
|
return this.isValidRoyaltyRecipient(metadata.feeRecipient ? metadata.feeRecipient : this.address);
|
|
|
|
case 3:
|
|
isValidFeeRecipient = _context30.sent;
|
|
|
|
if (!(shouldUpdateRecipient && !isValidFeeRecipient)) {
|
|
_context30.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Invalid fee recipient, can only be the Project address or a Splits module address");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function verifyMetadata(_x20) {
|
|
return _verifyMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return verifyMetadata;
|
|
}()
|
|
/**
|
|
* Deploys a collection module.
|
|
*
|
|
* @param metadata - Metadata about the module.
|
|
* @returns A promise with the newly created module.
|
|
*/
|
|
;
|
|
|
|
_proto.deployBundleModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployBundleModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
_context31.t0 = this.jsonConvert;
|
|
_context31.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context31.t1 = _context31.sent;
|
|
_context31.t2 = BundleModuleMetadata;
|
|
serializedMetadata = _context31.t0.serializeObject.call(_context31.t0, _context31.t1, _context31.t2);
|
|
_context31.next = 8;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 8:
|
|
_context31.t3 = this.sdk.getStorage();
|
|
_context31.t4 = serializedMetadata;
|
|
_context31.t5 = this.address;
|
|
_context31.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context31.t6 = _context31.sent;
|
|
_context31.next = 16;
|
|
return _context31.t3.uploadMetadata.call(_context31.t3, _context31.t4, _context31.t5, _context31.t6);
|
|
|
|
case 16:
|
|
metadataUri = _context31.sent;
|
|
_context31.t7 = this;
|
|
_context31.t8 = ModuleType.COLLECTION;
|
|
_context31.t9 = this.address;
|
|
_context31.next = 22;
|
|
return this.getForwarder();
|
|
|
|
case 22:
|
|
_context31.t10 = _context31.sent;
|
|
_context31.t11 = metadataUri;
|
|
_context31.t12 = BigNumber.from(metadata.sellerFeeBasisPoints ? metadata.sellerFeeBasisPoints : 0);
|
|
_context31.t13 = [_context31.t9, _context31.t10, _context31.t11, _context31.t12];
|
|
_context31.t14 = NFTCollection__factory;
|
|
_context31.next = 29;
|
|
return _context31.t7._deployModule.call(_context31.t7, _context31.t8, _context31.t13, _context31.t14);
|
|
|
|
case 29:
|
|
address = _context31.sent;
|
|
_context31.t15 = metadata.feeRecipient;
|
|
|
|
if (!_context31.t15) {
|
|
_context31.next = 37;
|
|
break;
|
|
}
|
|
|
|
_context31.t16 = metadata.feeRecipient;
|
|
_context31.next = 35;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 35:
|
|
_context31.t17 = _context31.sent;
|
|
_context31.t15 = _context31.t16 !== _context31.t17;
|
|
|
|
case 37:
|
|
if (!_context31.t15) {
|
|
_context31.next = 40;
|
|
break;
|
|
}
|
|
|
|
_context31.next = 40;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 40:
|
|
return _context31.abrupt("return", this.sdk.getBundleModule(address));
|
|
|
|
case 41:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this);
|
|
}));
|
|
|
|
function deployBundleModule(_x21) {
|
|
return _deployBundleModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployBundleModule;
|
|
}()
|
|
/**
|
|
* Deploys a Splits module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed splits module
|
|
*/
|
|
;
|
|
|
|
_proto.deploySplitsModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deploySplitsModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
_context32.t0 = this.jsonConvert;
|
|
_context32.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context32.t1 = _context32.sent;
|
|
_context32.t2 = SplitsModuleMetadata;
|
|
serializedMetadata = _context32.t0.serializeObject.call(_context32.t0, _context32.t1, _context32.t2);
|
|
_context32.t3 = this.sdk.getStorage();
|
|
_context32.t4 = serializedMetadata;
|
|
_context32.t5 = this.address;
|
|
_context32.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context32.t6 = _context32.sent;
|
|
_context32.next = 14;
|
|
return _context32.t3.uploadMetadata.call(_context32.t3, _context32.t4, _context32.t5, _context32.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context32.sent;
|
|
_context32.t7 = this;
|
|
_context32.t8 = ModuleType.SPLITS;
|
|
_context32.t9 = this.address;
|
|
_context32.next = 20;
|
|
return this.getForwarder();
|
|
|
|
case 20:
|
|
_context32.t10 = _context32.sent;
|
|
_context32.t11 = metadataUri;
|
|
_context32.t12 = metadata.recipientSplits.map(function (s) {
|
|
return s.address;
|
|
});
|
|
_context32.t13 = metadata.recipientSplits.map(function (s) {
|
|
return s.shares;
|
|
});
|
|
_context32.t14 = [_context32.t9, _context32.t10, _context32.t11, _context32.t12, _context32.t13];
|
|
_context32.t15 = metadata.isRoyalty ? Royalty__factory : Splits__factory;
|
|
_context32.next = 28;
|
|
return _context32.t7._deployModule.call(_context32.t7, _context32.t8, _context32.t14, _context32.t15);
|
|
|
|
case 28:
|
|
address = _context32.sent;
|
|
return _context32.abrupt("return", this.sdk.getSplitsModule(address));
|
|
|
|
case 30:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function deploySplitsModule(_x22) {
|
|
return _deploySplitsModule.apply(this, arguments);
|
|
}
|
|
|
|
return deploySplitsModule;
|
|
}()
|
|
/**
|
|
* Deploys a Royalty Splits module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed splits module
|
|
*/
|
|
;
|
|
|
|
_proto.deployRoyaltySplitsModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployRoyaltySplitsModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
metadata.isRoyalty = true;
|
|
_context33.t0 = this.jsonConvert;
|
|
_context33.next = 4;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 4:
|
|
_context33.t1 = _context33.sent;
|
|
_context33.t2 = SplitsModuleMetadata;
|
|
serializedMetadata = _context33.t0.serializeObject.call(_context33.t0, _context33.t1, _context33.t2);
|
|
_context33.t3 = this.sdk.getStorage();
|
|
_context33.t4 = serializedMetadata;
|
|
_context33.t5 = this.address;
|
|
_context33.next = 12;
|
|
return this.getSignerAddress();
|
|
|
|
case 12:
|
|
_context33.t6 = _context33.sent;
|
|
_context33.next = 15;
|
|
return _context33.t3.uploadMetadata.call(_context33.t3, _context33.t4, _context33.t5, _context33.t6);
|
|
|
|
case 15:
|
|
metadataUri = _context33.sent;
|
|
_context33.t7 = this;
|
|
_context33.t8 = ModuleType.SPLITS;
|
|
_context33.t9 = this.address;
|
|
_context33.next = 21;
|
|
return this.getForwarder();
|
|
|
|
case 21:
|
|
_context33.t10 = _context33.sent;
|
|
_context33.t11 = metadataUri;
|
|
_context33.t12 = metadata.recipientSplits.map(function (s) {
|
|
return s.address;
|
|
});
|
|
_context33.t13 = metadata.recipientSplits.map(function (s) {
|
|
return s.shares;
|
|
});
|
|
_context33.t14 = [_context33.t9, _context33.t10, _context33.t11, _context33.t12, _context33.t13];
|
|
_context33.t15 = Royalty__factory;
|
|
_context33.next = 29;
|
|
return _context33.t7._deployModule.call(_context33.t7, _context33.t8, _context33.t14, _context33.t15);
|
|
|
|
case 29:
|
|
address = _context33.sent;
|
|
return _context33.abrupt("return", this.sdk.getSplitsModule(address));
|
|
|
|
case 31:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function deployRoyaltySplitsModule(_x23) {
|
|
return _deployRoyaltySplitsModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployRoyaltySplitsModule;
|
|
}()
|
|
/**
|
|
* Deploys a NFT module.
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed NFT module
|
|
*/
|
|
;
|
|
|
|
_proto.deployNftModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployNftModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(metadata) {
|
|
var serializedMetadata, metadataUri, nativeTokenWrapperAddress, address;
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
_context34.t0 = this.jsonConvert;
|
|
_context34.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context34.t1 = _context34.sent;
|
|
_context34.t2 = NftModuleMetadata;
|
|
serializedMetadata = _context34.t0.serializeObject.call(_context34.t0, _context34.t1, _context34.t2);
|
|
_context34.next = 8;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 8:
|
|
_context34.t3 = this.sdk.getStorage();
|
|
_context34.t4 = serializedMetadata;
|
|
_context34.t5 = this.address;
|
|
_context34.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context34.t6 = _context34.sent;
|
|
_context34.next = 16;
|
|
return _context34.t3.uploadMetadata.call(_context34.t3, _context34.t4, _context34.t5, _context34.t6);
|
|
|
|
case 16:
|
|
metadataUri = _context34.sent;
|
|
_context34.t7 = getNativeTokenByChainId;
|
|
_context34.next = 20;
|
|
return this.getChainID();
|
|
|
|
case 20:
|
|
_context34.t8 = _context34.sent;
|
|
nativeTokenWrapperAddress = (0, _context34.t7)(_context34.t8).wrapped.address;
|
|
_context34.t9 = this;
|
|
_context34.t10 = ModuleType.NFT;
|
|
_context34.t11 = metadata.name;
|
|
_context34.t12 = metadata.symbol ? metadata.symbol : "";
|
|
_context34.t13 = metadataUri;
|
|
_context34.t14 = this.address;
|
|
_context34.next = 30;
|
|
return this.getForwarder();
|
|
|
|
case 30:
|
|
_context34.t15 = _context34.sent;
|
|
_context34.t16 = nativeTokenWrapperAddress;
|
|
|
|
if (!metadata.defaultSaleRecipientAddress) {
|
|
_context34.next = 36;
|
|
break;
|
|
}
|
|
|
|
_context34.t17 = metadata.defaultSaleRecipientAddress;
|
|
_context34.next = 39;
|
|
break;
|
|
|
|
case 36:
|
|
_context34.next = 38;
|
|
return this.getSignerAddress();
|
|
|
|
case 38:
|
|
_context34.t17 = _context34.sent;
|
|
|
|
case 39:
|
|
_context34.t18 = _context34.t17;
|
|
_context34.t19 = metadata.sellerFeeBasisPoints;
|
|
_context34.t20 = metadata.primarySaleFeeBasisPoints ? metadata.primarySaleFeeBasisPoints : 0;
|
|
_context34.t21 = [_context34.t11, _context34.t12, _context34.t13, _context34.t14, _context34.t15, _context34.t16, _context34.t18, _context34.t19, _context34.t20];
|
|
_context34.t22 = SignatureMint721__factory;
|
|
_context34.next = 46;
|
|
return _context34.t9._deployModule.call(_context34.t9, _context34.t10, _context34.t21, _context34.t22);
|
|
|
|
case 46:
|
|
address = _context34.sent;
|
|
_context34.t23 = metadata.feeRecipient;
|
|
|
|
if (!_context34.t23) {
|
|
_context34.next = 54;
|
|
break;
|
|
}
|
|
|
|
_context34.t24 = metadata.feeRecipient;
|
|
_context34.next = 52;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 52:
|
|
_context34.t25 = _context34.sent;
|
|
_context34.t23 = _context34.t24 !== _context34.t25;
|
|
|
|
case 54:
|
|
if (!_context34.t23) {
|
|
_context34.next = 57;
|
|
break;
|
|
}
|
|
|
|
_context34.next = 57;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 57:
|
|
return _context34.abrupt("return", this.sdk.getNFTModule(address));
|
|
|
|
case 58:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this);
|
|
}));
|
|
|
|
function deployNftModule(_x24) {
|
|
return _deployNftModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployNftModule;
|
|
}()
|
|
/**
|
|
* Deploys a currency module.
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed currency module
|
|
*/
|
|
;
|
|
|
|
_proto.deployCurrencyModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployCurrencyModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
_context35.t0 = this.jsonConvert;
|
|
_context35.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context35.t1 = _context35.sent;
|
|
_context35.t2 = CurrencyModuleMetadata;
|
|
serializedMetadata = _context35.t0.serializeObject.call(_context35.t0, _context35.t1, _context35.t2);
|
|
_context35.t3 = this.sdk.getStorage();
|
|
_context35.t4 = serializedMetadata;
|
|
_context35.t5 = this.address;
|
|
_context35.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context35.t6 = _context35.sent;
|
|
_context35.next = 14;
|
|
return _context35.t3.uploadMetadata.call(_context35.t3, _context35.t4, _context35.t5, _context35.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context35.sent;
|
|
_context35.t7 = this;
|
|
_context35.t8 = ModuleType.CURRENCY;
|
|
_context35.t9 = this.address;
|
|
_context35.t10 = metadata.name;
|
|
_context35.t11 = metadata.symbol ? metadata.symbol : "";
|
|
_context35.next = 22;
|
|
return this.getForwarder();
|
|
|
|
case 22:
|
|
_context35.t12 = _context35.sent;
|
|
_context35.t13 = metadataUri;
|
|
_context35.t14 = [_context35.t9, _context35.t10, _context35.t11, _context35.t12, _context35.t13];
|
|
_context35.t15 = Coin__factory;
|
|
_context35.next = 28;
|
|
return _context35.t7._deployModule.call(_context35.t7, _context35.t8, _context35.t14, _context35.t15);
|
|
|
|
case 28:
|
|
address = _context35.sent;
|
|
return _context35.abrupt("return", this.sdk.getCurrencyModule(address));
|
|
|
|
case 30:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35, this);
|
|
}));
|
|
|
|
function deployCurrencyModule(_x25) {
|
|
return _deployCurrencyModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployCurrencyModule;
|
|
}()
|
|
/**
|
|
* Deploys a token module.
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed currency module
|
|
*/
|
|
;
|
|
|
|
_proto.deployTokenModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployTokenModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee36(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee36$(_context36) {
|
|
while (1) {
|
|
switch (_context36.prev = _context36.next) {
|
|
case 0:
|
|
_context36.t0 = this.jsonConvert;
|
|
_context36.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context36.t1 = _context36.sent;
|
|
_context36.t2 = CurrencyModuleMetadata;
|
|
serializedMetadata = _context36.t0.serializeObject.call(_context36.t0, _context36.t1, _context36.t2);
|
|
_context36.t3 = this.sdk.getStorage();
|
|
_context36.t4 = serializedMetadata;
|
|
_context36.t5 = this.address;
|
|
_context36.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context36.t6 = _context36.sent;
|
|
_context36.next = 14;
|
|
return _context36.t3.uploadMetadata.call(_context36.t3, _context36.t4, _context36.t5, _context36.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context36.sent;
|
|
_context36.t7 = this;
|
|
_context36.t8 = ModuleType.CURRENCY;
|
|
_context36.t9 = this.address;
|
|
_context36.t10 = metadata.name;
|
|
_context36.t11 = metadata.symbol ? metadata.symbol : "";
|
|
_context36.next = 22;
|
|
return this.getForwarder();
|
|
|
|
case 22:
|
|
_context36.t12 = _context36.sent;
|
|
_context36.t13 = metadataUri;
|
|
_context36.t14 = [_context36.t9, _context36.t10, _context36.t11, _context36.t12, _context36.t13];
|
|
_context36.t15 = Coin__factory;
|
|
_context36.next = 28;
|
|
return _context36.t7._deployModule.call(_context36.t7, _context36.t8, _context36.t14, _context36.t15);
|
|
|
|
case 28:
|
|
address = _context36.sent;
|
|
return _context36.abrupt("return", this.sdk.getTokenModule(address));
|
|
|
|
case 30:
|
|
case "end":
|
|
return _context36.stop();
|
|
}
|
|
}
|
|
}, _callee36, this);
|
|
}));
|
|
|
|
function deployTokenModule(_x26) {
|
|
return _deployTokenModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployTokenModule;
|
|
}()
|
|
/**
|
|
* Deploys a Marketplace module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed Marketplace module
|
|
*/
|
|
;
|
|
|
|
_proto.deployMarketModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployMarketModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee37(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee37$(_context37) {
|
|
while (1) {
|
|
switch (_context37.prev = _context37.next) {
|
|
case 0:
|
|
_context37.t0 = this.jsonConvert;
|
|
_context37.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context37.t1 = _context37.sent;
|
|
_context37.t2 = MarketModuleMetadata;
|
|
serializedMetadata = _context37.t0.serializeObject.call(_context37.t0, _context37.t1, _context37.t2);
|
|
_context37.t3 = this.sdk.getStorage();
|
|
_context37.t4 = serializedMetadata;
|
|
_context37.t5 = this.address;
|
|
_context37.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context37.t6 = _context37.sent;
|
|
_context37.next = 14;
|
|
return _context37.t3.uploadMetadata.call(_context37.t3, _context37.t4, _context37.t5, _context37.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context37.sent;
|
|
_context37.t7 = this;
|
|
_context37.t8 = ModuleType.MARKET;
|
|
_context37.t9 = this.address;
|
|
_context37.next = 20;
|
|
return this.getForwarder();
|
|
|
|
case 20:
|
|
_context37.t10 = _context37.sent;
|
|
_context37.t11 = metadataUri;
|
|
_context37.t12 = metadata.marketFeeBasisPoints ? metadata.marketFeeBasisPoints : 0;
|
|
_context37.t13 = [_context37.t9, _context37.t10, _context37.t11, _context37.t12];
|
|
_context37.t14 = Market__factory;
|
|
_context37.next = 27;
|
|
return _context37.t7._deployModule.call(_context37.t7, _context37.t8, _context37.t13, _context37.t14);
|
|
|
|
case 27:
|
|
address = _context37.sent;
|
|
return _context37.abrupt("return", this.sdk.getMarketModule(address));
|
|
|
|
case 29:
|
|
case "end":
|
|
return _context37.stop();
|
|
}
|
|
}
|
|
}, _callee37, this);
|
|
}));
|
|
|
|
function deployMarketModule(_x27) {
|
|
return _deployMarketModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployMarketModule;
|
|
}()
|
|
/**
|
|
* Deploys a Pack module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed Pack module
|
|
*/
|
|
;
|
|
|
|
_proto.deployPackModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployPackModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee38(metadata) {
|
|
var serializedMetadata, metadataUri, chainId, _ChainlinkVrf$chainId, vrfCoordinator, linkTokenAddress, keyHash, fees, address;
|
|
|
|
return runtime_1.wrap(function _callee38$(_context38) {
|
|
while (1) {
|
|
switch (_context38.prev = _context38.next) {
|
|
case 0:
|
|
_context38.t0 = this.jsonConvert;
|
|
_context38.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context38.t1 = _context38.sent;
|
|
_context38.t2 = PackModuleMetadata;
|
|
serializedMetadata = _context38.t0.serializeObject.call(_context38.t0, _context38.t1, _context38.t2);
|
|
_context38.next = 8;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 8:
|
|
_context38.t3 = this.sdk.getStorage();
|
|
_context38.t4 = serializedMetadata;
|
|
_context38.t5 = this.address;
|
|
_context38.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context38.t6 = _context38.sent;
|
|
_context38.next = 16;
|
|
return _context38.t3.uploadMetadata.call(_context38.t3, _context38.t4, _context38.t5, _context38.t6);
|
|
|
|
case 16:
|
|
metadataUri = _context38.sent;
|
|
_context38.next = 19;
|
|
return this.getChainID();
|
|
|
|
case 19:
|
|
chainId = _context38.sent;
|
|
_ChainlinkVrf$chainId = ChainlinkVrf[chainId], vrfCoordinator = _ChainlinkVrf$chainId.vrfCoordinator, linkTokenAddress = _ChainlinkVrf$chainId.linkTokenAddress, keyHash = _ChainlinkVrf$chainId.keyHash, fees = _ChainlinkVrf$chainId.fees;
|
|
_context38.t7 = this;
|
|
_context38.t8 = ModuleType.PACK;
|
|
_context38.t9 = this.address;
|
|
_context38.t10 = metadataUri;
|
|
_context38.t11 = vrfCoordinator;
|
|
_context38.t12 = linkTokenAddress;
|
|
_context38.t13 = keyHash;
|
|
_context38.t14 = fees;
|
|
_context38.next = 31;
|
|
return this.getForwarder();
|
|
|
|
case 31:
|
|
_context38.t15 = _context38.sent;
|
|
_context38.t16 = metadata.sellerFeeBasisPoints ? metadata.sellerFeeBasisPoints : 0;
|
|
_context38.t17 = [_context38.t9, _context38.t10, _context38.t11, _context38.t12, _context38.t13, _context38.t14, _context38.t15, _context38.t16];
|
|
_context38.t18 = Pack__factory;
|
|
_context38.next = 37;
|
|
return _context38.t7._deployModule.call(_context38.t7, _context38.t8, _context38.t17, _context38.t18);
|
|
|
|
case 37:
|
|
address = _context38.sent;
|
|
_context38.t19 = metadata.feeRecipient;
|
|
|
|
if (!_context38.t19) {
|
|
_context38.next = 45;
|
|
break;
|
|
}
|
|
|
|
_context38.t20 = metadata.feeRecipient;
|
|
_context38.next = 43;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 43:
|
|
_context38.t21 = _context38.sent;
|
|
_context38.t19 = _context38.t20 !== _context38.t21;
|
|
|
|
case 45:
|
|
if (!_context38.t19) {
|
|
_context38.next = 48;
|
|
break;
|
|
}
|
|
|
|
_context38.next = 48;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 48:
|
|
return _context38.abrupt("return", this.sdk.getPackModule(address));
|
|
|
|
case 49:
|
|
case "end":
|
|
return _context38.stop();
|
|
}
|
|
}
|
|
}, _callee38, this);
|
|
}));
|
|
|
|
function deployPackModule(_x28) {
|
|
return _deployPackModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployPackModule;
|
|
}()
|
|
/**
|
|
* Deploys a Drop module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed Drop module
|
|
*/
|
|
;
|
|
|
|
_proto.deployDropModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployDropModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee39(metadata) {
|
|
var serializedMetadata, metadataUri, nativeTokenWrapperAddress, address;
|
|
return runtime_1.wrap(function _callee39$(_context39) {
|
|
while (1) {
|
|
switch (_context39.prev = _context39.next) {
|
|
case 0:
|
|
!(metadata.primarySaleRecipientAddress !== "" && isAddress(metadata.primarySaleRecipientAddress)) ? process.env.NODE_ENV !== "production" ? invariant(false, "Primary sale recipient address must be specified and must be a valid address") : invariant(false) : void 0;
|
|
_context39.t0 = this.jsonConvert;
|
|
_context39.next = 4;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 4:
|
|
_context39.t1 = _context39.sent;
|
|
_context39.t2 = DropModuleMetadata;
|
|
serializedMetadata = _context39.t0.serializeObject.call(_context39.t0, _context39.t1, _context39.t2);
|
|
_context39.next = 9;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 9:
|
|
_context39.t3 = this.sdk.getStorage();
|
|
_context39.t4 = serializedMetadata;
|
|
_context39.t5 = this.address;
|
|
_context39.next = 14;
|
|
return this.getSignerAddress();
|
|
|
|
case 14:
|
|
_context39.t6 = _context39.sent;
|
|
_context39.next = 17;
|
|
return _context39.t3.uploadMetadata.call(_context39.t3, _context39.t4, _context39.t5, _context39.t6);
|
|
|
|
case 17:
|
|
metadataUri = _context39.sent;
|
|
_context39.t7 = getNativeTokenByChainId;
|
|
_context39.next = 21;
|
|
return this.getChainID();
|
|
|
|
case 21:
|
|
_context39.t8 = _context39.sent;
|
|
nativeTokenWrapperAddress = (0, _context39.t7)(_context39.t8).wrapped.address;
|
|
_context39.t9 = this;
|
|
_context39.t10 = ModuleType.DROP;
|
|
_context39.t11 = metadata.name;
|
|
_context39.t12 = metadata.symbol ? metadata.symbol : "";
|
|
_context39.t13 = metadataUri;
|
|
_context39.t14 = this.address;
|
|
_context39.next = 31;
|
|
return this.getForwarder();
|
|
|
|
case 31:
|
|
_context39.t15 = _context39.sent;
|
|
_context39.t16 = nativeTokenWrapperAddress;
|
|
_context39.t17 = metadata.primarySaleRecipientAddress;
|
|
_context39.t18 = metadata.sellerFeeBasisPoints ? metadata.sellerFeeBasisPoints : 0;
|
|
_context39.t19 = metadata.primarySaleFeeBasisPoints ? metadata.primarySaleFeeBasisPoints : 0;
|
|
_context39.t20 = [_context39.t11, _context39.t12, _context39.t13, _context39.t14, _context39.t15, _context39.t16, _context39.t17, _context39.t18, _context39.t19];
|
|
_context39.t21 = LazyMintERC721__factory;
|
|
_context39.next = 40;
|
|
return _context39.t9._deployModule.call(_context39.t9, _context39.t10, _context39.t20, _context39.t21);
|
|
|
|
case 40:
|
|
address = _context39.sent;
|
|
_context39.t22 = metadata.feeRecipient;
|
|
|
|
if (!_context39.t22) {
|
|
_context39.next = 48;
|
|
break;
|
|
}
|
|
|
|
_context39.t23 = metadata.feeRecipient;
|
|
_context39.next = 46;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 46:
|
|
_context39.t24 = _context39.sent;
|
|
_context39.t22 = _context39.t23 !== _context39.t24;
|
|
|
|
case 48:
|
|
if (!_context39.t22) {
|
|
_context39.next = 51;
|
|
break;
|
|
}
|
|
|
|
_context39.next = 51;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 51:
|
|
return _context39.abrupt("return", this.sdk.getDropModule(address));
|
|
|
|
case 52:
|
|
case "end":
|
|
return _context39.stop();
|
|
}
|
|
}
|
|
}, _callee39, this);
|
|
}));
|
|
|
|
function deployDropModule(_x29) {
|
|
return _deployDropModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployDropModule;
|
|
}()
|
|
/**
|
|
* Deploys a BundleSignature module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed BundleSignature module
|
|
*/
|
|
;
|
|
|
|
_proto.deployBundleSignatureModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployBundleSignatureModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee40(metadata) {
|
|
var serializedMetadata, metadataUri, nativeTokenWrapperAddress, royaltyTreasury, address;
|
|
return runtime_1.wrap(function _callee40$(_context40) {
|
|
while (1) {
|
|
switch (_context40.prev = _context40.next) {
|
|
case 0:
|
|
!(metadata.primarySaleRecipientAddress !== "" && isAddress(metadata.primarySaleRecipientAddress)) ? process.env.NODE_ENV !== "production" ? invariant(false, "Primary sale recipient address must be specified and must be a valid address") : invariant(false) : void 0;
|
|
_context40.t0 = this.jsonConvert;
|
|
_context40.next = 4;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 4:
|
|
_context40.t1 = _context40.sent;
|
|
_context40.t2 = DropModuleMetadata;
|
|
serializedMetadata = _context40.t0.serializeObject.call(_context40.t0, _context40.t1, _context40.t2);
|
|
_context40.next = 9;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 9:
|
|
_context40.t3 = this.sdk.getStorage();
|
|
_context40.t4 = serializedMetadata;
|
|
_context40.t5 = this.address;
|
|
_context40.next = 14;
|
|
return this.getSignerAddress();
|
|
|
|
case 14:
|
|
_context40.t6 = _context40.sent;
|
|
_context40.next = 17;
|
|
return _context40.t3.uploadMetadata.call(_context40.t3, _context40.t4, _context40.t5, _context40.t6);
|
|
|
|
case 17:
|
|
metadataUri = _context40.sent;
|
|
_context40.t7 = getNativeTokenByChainId;
|
|
_context40.next = 21;
|
|
return this.getChainID();
|
|
|
|
case 21:
|
|
_context40.t8 = _context40.sent;
|
|
nativeTokenWrapperAddress = (0, _context40.t7)(_context40.t8).wrapped.address;
|
|
_context40.next = 25;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 25:
|
|
royaltyTreasury = _context40.sent;
|
|
_context40.t9 = this;
|
|
_context40.t10 = ModuleType.BUNDLE_SIGNATURE;
|
|
_context40.t11 = metadataUri;
|
|
_context40.t12 = this.address;
|
|
_context40.next = 32;
|
|
return this.getForwarder();
|
|
|
|
case 32:
|
|
_context40.t13 = _context40.sent;
|
|
_context40.t14 = nativeTokenWrapperAddress;
|
|
_context40.t15 = metadata.primarySaleRecipientAddress;
|
|
_context40.t16 = metadata.feeRecipient ? metadata.feeRecipient : royaltyTreasury;
|
|
_context40.t17 = metadata.sellerFeeBasisPoints ? metadata.sellerFeeBasisPoints : 0;
|
|
_context40.t18 = metadata.primarySaleFeeBasisPoints ? metadata.primarySaleFeeBasisPoints : 0;
|
|
_context40.t19 = [_context40.t11, _context40.t12, _context40.t13, _context40.t14, _context40.t15, _context40.t16, _context40.t17, _context40.t18];
|
|
_context40.t20 = SignatureMint1155__factory;
|
|
_context40.next = 42;
|
|
return _context40.t9._deployModule.call(_context40.t9, _context40.t10, _context40.t19, _context40.t20);
|
|
|
|
case 42:
|
|
address = _context40.sent;
|
|
|
|
if (!(metadata.feeRecipient && metadata.feeRecipient !== royaltyTreasury)) {
|
|
_context40.next = 46;
|
|
break;
|
|
}
|
|
|
|
_context40.next = 46;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 46:
|
|
return _context40.abrupt("return", this.sdk.getBundleSignatureModule(address));
|
|
|
|
case 47:
|
|
case "end":
|
|
return _context40.stop();
|
|
}
|
|
}
|
|
}, _callee40, this);
|
|
}));
|
|
|
|
function deployBundleSignatureModule(_x30) {
|
|
return _deployBundleSignatureModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployBundleSignatureModule;
|
|
}()
|
|
/**
|
|
* Deploys a Bundle Drop module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed Bundle Drop module
|
|
*/
|
|
;
|
|
|
|
_proto.deployBundleDropModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployBundleDropModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee41(metadata) {
|
|
var serializedMetadata, metadataUri, nativeTokenWrapperAddress, address;
|
|
return runtime_1.wrap(function _callee41$(_context41) {
|
|
while (1) {
|
|
switch (_context41.prev = _context41.next) {
|
|
case 0:
|
|
!(metadata.primarySaleRecipientAddress !== "" && isAddress(metadata.primarySaleRecipientAddress)) ? process.env.NODE_ENV !== "production" ? invariant(false, "Primary sale recipient address must be specified and must be a valid address") : invariant(false) : void 0;
|
|
_context41.next = 3;
|
|
return this.verifyMetadata(metadata);
|
|
|
|
case 3:
|
|
_context41.t0 = this.jsonConvert;
|
|
_context41.next = 6;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 6:
|
|
_context41.t1 = _context41.sent;
|
|
_context41.t2 = DropModuleMetadata;
|
|
serializedMetadata = _context41.t0.serializeObject.call(_context41.t0, _context41.t1, _context41.t2);
|
|
_context41.t3 = this.sdk.getStorage();
|
|
_context41.t4 = serializedMetadata;
|
|
_context41.t5 = this.address;
|
|
_context41.next = 14;
|
|
return this.getSignerAddress();
|
|
|
|
case 14:
|
|
_context41.t6 = _context41.sent;
|
|
_context41.next = 17;
|
|
return _context41.t3.uploadMetadata.call(_context41.t3, _context41.t4, _context41.t5, _context41.t6);
|
|
|
|
case 17:
|
|
metadataUri = _context41.sent;
|
|
_context41.t7 = getNativeTokenByChainId;
|
|
_context41.next = 21;
|
|
return this.getChainID();
|
|
|
|
case 21:
|
|
_context41.t8 = _context41.sent;
|
|
nativeTokenWrapperAddress = (0, _context41.t7)(_context41.t8).wrapped.address;
|
|
_context41.t9 = this;
|
|
_context41.t10 = ModuleType.BUNDLE_DROP;
|
|
_context41.t11 = metadataUri;
|
|
_context41.t12 = this.address;
|
|
_context41.next = 29;
|
|
return this.getForwarder();
|
|
|
|
case 29:
|
|
_context41.t13 = _context41.sent;
|
|
_context41.t14 = nativeTokenWrapperAddress;
|
|
_context41.t15 = metadata.primarySaleRecipientAddress;
|
|
_context41.t16 = metadata.sellerFeeBasisPoints ? metadata.sellerFeeBasisPoints : 0;
|
|
_context41.t17 = metadata.primarySaleFeeBasisPoints ? metadata.primarySaleFeeBasisPoints : 0;
|
|
_context41.t18 = [_context41.t11, _context41.t12, _context41.t13, _context41.t14, _context41.t15, _context41.t16, _context41.t17];
|
|
_context41.t19 = LazyMintERC1155__factory;
|
|
_context41.next = 38;
|
|
return _context41.t9._deployModule.call(_context41.t9, _context41.t10, _context41.t18, _context41.t19);
|
|
|
|
case 38:
|
|
address = _context41.sent;
|
|
_context41.t20 = metadata.feeRecipient;
|
|
|
|
if (!_context41.t20) {
|
|
_context41.next = 46;
|
|
break;
|
|
}
|
|
|
|
_context41.t21 = metadata.feeRecipient;
|
|
_context41.next = 44;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 44:
|
|
_context41.t22 = _context41.sent;
|
|
_context41.t20 = _context41.t21 !== _context41.t22;
|
|
|
|
case 46:
|
|
if (!_context41.t20) {
|
|
_context41.next = 49;
|
|
break;
|
|
}
|
|
|
|
_context41.next = 49;
|
|
return this.setModuleRoyaltyTreasury(address, metadata.feeRecipient);
|
|
|
|
case 49:
|
|
return _context41.abrupt("return", this.sdk.getBundleDropModule(address));
|
|
|
|
case 50:
|
|
case "end":
|
|
return _context41.stop();
|
|
}
|
|
}
|
|
}, _callee41, this);
|
|
}));
|
|
|
|
function deployBundleDropModule(_x31) {
|
|
return _deployBundleDropModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployBundleDropModule;
|
|
}()
|
|
/**
|
|
* Deploys a Datastore module
|
|
*
|
|
* @alpha
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed Datastore module
|
|
*/
|
|
;
|
|
|
|
_proto.deployDatastoreModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployDatastoreModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee42(metadata) {
|
|
var serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee42$(_context42) {
|
|
while (1) {
|
|
switch (_context42.prev = _context42.next) {
|
|
case 0:
|
|
_context42.t0 = this.jsonConvert;
|
|
_context42.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context42.t1 = _context42.sent;
|
|
_context42.t2 = DatastoreModuleMetadata;
|
|
serializedMetadata = _context42.t0.serializeObject.call(_context42.t0, _context42.t1, _context42.t2);
|
|
_context42.t3 = this.sdk.getStorage();
|
|
_context42.t4 = serializedMetadata;
|
|
_context42.t5 = this.address;
|
|
_context42.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context42.t6 = _context42.sent;
|
|
_context42.next = 14;
|
|
return _context42.t3.uploadMetadata.call(_context42.t3, _context42.t4, _context42.t5, _context42.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context42.sent;
|
|
_context42.t7 = this;
|
|
_context42.t8 = ModuleType.DATASTORE;
|
|
_context42.t9 = this.address;
|
|
_context42.next = 20;
|
|
return this.getForwarder();
|
|
|
|
case 20:
|
|
_context42.t10 = _context42.sent;
|
|
_context42.t11 = metadataUri;
|
|
_context42.t12 = [_context42.t9, _context42.t10, _context42.t11];
|
|
_context42.t13 = DataStore__factory;
|
|
_context42.next = 26;
|
|
return _context42.t7._deployModule.call(_context42.t7, _context42.t8, _context42.t12, _context42.t13);
|
|
|
|
case 26:
|
|
address = _context42.sent;
|
|
return _context42.abrupt("return", this.sdk.getDatastoreModule(address));
|
|
|
|
case 28:
|
|
case "end":
|
|
return _context42.stop();
|
|
}
|
|
}
|
|
}, _callee42, this);
|
|
}));
|
|
|
|
function deployDatastoreModule(_x32) {
|
|
return _deployDatastoreModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployDatastoreModule;
|
|
}()
|
|
/**
|
|
* Deploys a Vote module
|
|
*
|
|
* @param metadata - The module metadata
|
|
* @returns - The deployed vote module
|
|
*/
|
|
;
|
|
|
|
_proto.deployVoteModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deployVoteModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee43(metadata) {
|
|
var chainId, timeBetweenBlocks, waitTimeInBlocks, votingTimeInBlocks, serializedMetadata, metadataUri, address;
|
|
return runtime_1.wrap(function _callee43$(_context43) {
|
|
while (1) {
|
|
switch (_context43.prev = _context43.next) {
|
|
case 0:
|
|
!(metadata.votingTokenAddress !== "" && isAddress(metadata.votingTokenAddress)) ? process.env.NODE_ENV !== "production" ? invariant(false, "Voting Token Address must be a valid address") : invariant(false) : void 0;
|
|
!(metadata.votingQuorumFraction >= 0 && metadata.votingQuorumFraction <= 100) ? process.env.NODE_ENV !== "production" ? invariant(false, "Quofrum Fraction must be in the range of 0-100 representing percentage") : invariant(false) : void 0;
|
|
_context43.next = 4;
|
|
return this.getChainID();
|
|
|
|
case 4:
|
|
chainId = _context43.sent;
|
|
timeBetweenBlocks = DEFAULT_BLOCK_TIMES_FALLBACK[chainId];
|
|
waitTimeInBlocks = metadata.proposalStartWaitTimeInSeconds / timeBetweenBlocks.secondsBetweenBlocks;
|
|
votingTimeInBlocks = metadata.proposalVotingTimeInSeconds / timeBetweenBlocks.secondsBetweenBlocks;
|
|
metadata.votingDelay = waitTimeInBlocks;
|
|
metadata.votingPeriod = votingTimeInBlocks; // verify making sure that the voting token address is valid
|
|
|
|
_context43.prev = 10;
|
|
_context43.next = 13;
|
|
return Coin__factory.connect(metadata.votingTokenAddress, this.readOnlyContract.provider).callStatic.getPastTotalSupply(0);
|
|
|
|
case 13:
|
|
_context43.next = 18;
|
|
break;
|
|
|
|
case 15:
|
|
_context43.prev = 15;
|
|
_context43.t0 = _context43["catch"](10);
|
|
process.env.NODE_ENV !== "production" ? invariant(false, "Token is not compatible with the vote module") : invariant(false) ;
|
|
|
|
case 18:
|
|
_context43.t1 = this.jsonConvert;
|
|
_context43.next = 21;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 21:
|
|
_context43.t2 = _context43.sent;
|
|
_context43.t3 = VoteModuleMetadata;
|
|
serializedMetadata = _context43.t1.serializeObject.call(_context43.t1, _context43.t2, _context43.t3);
|
|
_context43.t4 = this.sdk.getStorage();
|
|
_context43.t5 = serializedMetadata;
|
|
_context43.t6 = this.address;
|
|
_context43.next = 29;
|
|
return this.getSignerAddress();
|
|
|
|
case 29:
|
|
_context43.t7 = _context43.sent;
|
|
_context43.next = 32;
|
|
return _context43.t4.uploadMetadata.call(_context43.t4, _context43.t5, _context43.t6, _context43.t7);
|
|
|
|
case 32:
|
|
metadataUri = _context43.sent;
|
|
_context43.t8 = this;
|
|
_context43.t9 = ModuleType.VOTE;
|
|
_context43.t10 = metadata.name;
|
|
_context43.t11 = metadata.votingTokenAddress;
|
|
_context43.t12 = BigNumber.from(Math.ceil(metadata.votingDelay));
|
|
_context43.t13 = BigNumber.from(Math.ceil(metadata.votingPeriod));
|
|
_context43.t14 = BigNumber.from(metadata.minimumNumberOfTokensNeededToPropose);
|
|
_context43.t15 = metadata.votingQuorumFraction;
|
|
_context43.next = 43;
|
|
return this.getForwarder();
|
|
|
|
case 43:
|
|
_context43.t16 = _context43.sent;
|
|
_context43.t17 = metadataUri;
|
|
_context43.t18 = [_context43.t10, _context43.t11, _context43.t12, _context43.t13, _context43.t14, _context43.t15, _context43.t16, _context43.t17];
|
|
_context43.t19 = VotingGovernor__factory;
|
|
_context43.next = 49;
|
|
return _context43.t8._deployModule.call(_context43.t8, _context43.t9, _context43.t18, _context43.t19);
|
|
|
|
case 49:
|
|
address = _context43.sent;
|
|
return _context43.abrupt("return", this.sdk.getVoteModule(address));
|
|
|
|
case 51:
|
|
case "end":
|
|
return _context43.stop();
|
|
}
|
|
}
|
|
}, _callee43, this, [[10, 15]]);
|
|
}));
|
|
|
|
function deployVoteModule(_x33) {
|
|
return _deployVoteModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployVoteModule;
|
|
}();
|
|
|
|
_proto.shouldUpgradeToV2 = /*#__PURE__*/function () {
|
|
var _shouldUpgradeToV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee44() {
|
|
var isAdmin;
|
|
return runtime_1.wrap(function _callee44$(_context44) {
|
|
while (1) {
|
|
switch (_context44.prev = _context44.next) {
|
|
case 0:
|
|
_context44.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
_context44.t0 = _context44.sent;
|
|
|
|
if (!_context44.t0) {
|
|
_context44.next = 5;
|
|
break;
|
|
}
|
|
|
|
_context44.t0 = this.hasValidSigner();
|
|
|
|
case 5:
|
|
if (!_context44.t0) {
|
|
_context44.next = 23;
|
|
break;
|
|
}
|
|
|
|
_context44.t1 = this.readOnlyContract;
|
|
_context44.t2 = ethers.utils.hexZeroPad([0], 32);
|
|
_context44.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
_context44.t3 = _context44.sent;
|
|
_context44.next = 13;
|
|
return _context44.t1.hasRole.call(_context44.t1, _context44.t2, _context44.t3);
|
|
|
|
case 13:
|
|
isAdmin = _context44.sent;
|
|
_context44.t4 = isAdmin;
|
|
|
|
if (!_context44.t4) {
|
|
_context44.next = 21;
|
|
break;
|
|
}
|
|
|
|
_context44.next = 18;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 18:
|
|
_context44.t5 = _context44.sent;
|
|
_context44.t6 = this.address;
|
|
_context44.t4 = _context44.t5 === _context44.t6;
|
|
|
|
case 21:
|
|
if (!_context44.t4) {
|
|
_context44.next = 23;
|
|
break;
|
|
}
|
|
|
|
return _context44.abrupt("return", true);
|
|
|
|
case 23:
|
|
return _context44.abrupt("return", false);
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context44.stop();
|
|
}
|
|
}
|
|
}, _callee44, this);
|
|
}));
|
|
|
|
function shouldUpgradeToV2() {
|
|
return _shouldUpgradeToV.apply(this, arguments);
|
|
}
|
|
|
|
return shouldUpgradeToV2;
|
|
}();
|
|
|
|
_proto.shouldUpgradeModuleList = /*#__PURE__*/function () {
|
|
var _shouldUpgradeModuleList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee45() {
|
|
var _this4 = this;
|
|
|
|
var modules;
|
|
return runtime_1.wrap(function _callee45$(_context45) {
|
|
while (1) {
|
|
switch (_context45.prev = _context45.next) {
|
|
case 0:
|
|
_context45.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
if (_context45.sent) {
|
|
_context45.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context45.abrupt("return", []);
|
|
|
|
case 4:
|
|
_context45.next = 6;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 6:
|
|
_context45.t0 = _context45.sent;
|
|
_context45.t1 = this.address;
|
|
|
|
if (!(_context45.t0 === _context45.t1)) {
|
|
_context45.next = 10;
|
|
break;
|
|
}
|
|
|
|
return _context45.abrupt("return", []);
|
|
|
|
case 10:
|
|
_context45.next = 12;
|
|
return this.getAllModuleMetadata([ModuleType.NFT, ModuleType.BUNDLE, ModuleType.PACK, ModuleType.DROP, ModuleType.BUNDLE_DROP], false);
|
|
|
|
case 12:
|
|
modules = _context45.sent;
|
|
return _context45.abrupt("return", modules.filter(function (m) {
|
|
var _m$metadata, _m$metadata$fee_recip;
|
|
|
|
return ((_m$metadata = m.metadata) == null ? void 0 : (_m$metadata$fee_recip = _m$metadata.fee_recipient) == null ? void 0 : _m$metadata$fee_recip.toLowerCase()) === _this4.address.toLowerCase();
|
|
}));
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context45.stop();
|
|
}
|
|
}
|
|
}, _callee45, this);
|
|
}));
|
|
|
|
function shouldUpgradeModuleList() {
|
|
return _shouldUpgradeModuleList.apply(this, arguments);
|
|
}
|
|
|
|
return shouldUpgradeModuleList;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.upgradeModuleList =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _upgradeModuleList = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee46(moduleAddresses) {
|
|
var _this5 = this;
|
|
|
|
var signer, allUpgradableModules, moduleMetadatas, royaltyTreasury, metadataUris, nonce, txData, txs, txns;
|
|
return runtime_1.wrap(function _callee46$(_context46) {
|
|
while (1) {
|
|
switch (_context46.prev = _context46.next) {
|
|
case 0:
|
|
signer = this.getSigner();
|
|
!signer ? process.env.NODE_ENV !== "production" ? invariant(false, "needs a signer") : invariant(false) : void 0; // already filtered to make sure that the fee_recipient is set to the app
|
|
|
|
_context46.next = 4;
|
|
return this.shouldUpgradeModuleList();
|
|
|
|
case 4:
|
|
allUpgradableModules = _context46.sent;
|
|
// this already returns the correct metadata array with non-resolved metadata...
|
|
moduleMetadatas = allUpgradableModules.filter(function (m) {
|
|
return moduleAddresses.includes(m.address);
|
|
});
|
|
_context46.next = 8;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 8:
|
|
royaltyTreasury = _context46.sent;
|
|
_context46.next = 11;
|
|
return Promise.all(moduleMetadatas.map(function (m) {
|
|
return _this5.sdk.getStorage().uploadMetadata(_extends({}, m.metadata, {
|
|
fee_recipient: royaltyTreasury
|
|
}));
|
|
}));
|
|
|
|
case 11:
|
|
metadataUris = _context46.sent;
|
|
_context46.next = 14;
|
|
return signer.getTransactionCount("pending");
|
|
|
|
case 14:
|
|
nonce = _context46.sent;
|
|
txData = metadataUris.map(function (uri) {
|
|
return _this5.contract["interface"].encodeFunctionData("setContractURI", [uri]);
|
|
});
|
|
txs = txData.map(function (data, i) {
|
|
return {
|
|
to: moduleMetadatas[i].address,
|
|
nonce: nonce + i,
|
|
data: data
|
|
};
|
|
}); // batch send :)
|
|
|
|
_context46.next = 19;
|
|
return Promise.all(txs.map(function (tx) {
|
|
return signer.sendTransaction(tx);
|
|
}));
|
|
|
|
case 19:
|
|
txns = _context46.sent;
|
|
_context46.next = 22;
|
|
return Promise.all(txns.map(function (tx) {
|
|
return tx.wait();
|
|
}));
|
|
|
|
case 22:
|
|
return _context46.abrupt("return", _context46.sent);
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context46.stop();
|
|
}
|
|
}
|
|
}, _callee46, this);
|
|
}));
|
|
|
|
function upgradeModuleList(_x34) {
|
|
return _upgradeModuleList.apply(this, arguments);
|
|
}
|
|
|
|
return upgradeModuleList;
|
|
}()
|
|
/**
|
|
* @internal
|
|
* Upgrades the protocol control to v2. In v2, the royalty treasury needs to be set to be set to a splits contract.
|
|
*
|
|
* @param splitsModuleAddress - Optional. By default, it automatically creates a Splits for the project.
|
|
* @param splitsRecipients - Optiional. By default, it is the signer who upgrades.
|
|
*/
|
|
;
|
|
|
|
_proto.upgradeToV2 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _upgradeToV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee47(upgradeOptions) {
|
|
var splitsAddress, metadata;
|
|
return runtime_1.wrap(function _callee47$(_context47) {
|
|
while (1) {
|
|
switch (_context47.prev = _context47.next) {
|
|
case 0:
|
|
if (upgradeOptions === void 0) {
|
|
upgradeOptions = {};
|
|
}
|
|
|
|
_context47.next = 3;
|
|
return this.isV1UpgradedOrV2();
|
|
|
|
case 3:
|
|
if (!_context47.sent) {
|
|
_context47.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context47.abrupt("return");
|
|
|
|
case 5:
|
|
splitsAddress = "";
|
|
|
|
if (!upgradeOptions.splitsModuleAddress) {
|
|
_context47.next = 10;
|
|
break;
|
|
}
|
|
|
|
splitsAddress = upgradeOptions.splitsModuleAddress;
|
|
_context47.next = 22;
|
|
break;
|
|
|
|
case 10:
|
|
if (upgradeOptions.splitsRecipients) {
|
|
_context47.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context47.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context47.t0 = _context47.sent;
|
|
_context47.t1 = {
|
|
address: _context47.t0,
|
|
shares: 100
|
|
};
|
|
upgradeOptions.splitsRecipients = [_context47.t1];
|
|
|
|
case 16:
|
|
_context47.next = 18;
|
|
return this.getMetadata();
|
|
|
|
case 18:
|
|
metadata = _context47.sent.metadata;
|
|
_context47.next = 21;
|
|
return this.deploySplitsModule({
|
|
name: (metadata == null ? void 0 : metadata.name) + " Royalty Treasury",
|
|
recipientSplits: upgradeOptions.splitsRecipients,
|
|
isRoyalty: true
|
|
});
|
|
|
|
case 21:
|
|
splitsAddress = _context47.sent.address;
|
|
|
|
case 22:
|
|
_context47.next = 24;
|
|
return this.setRoyaltyTreasury(splitsAddress);
|
|
|
|
case 24:
|
|
return _context47.abrupt("return", _context47.sent);
|
|
|
|
case 25:
|
|
case "end":
|
|
return _context47.stop();
|
|
}
|
|
}
|
|
}, _callee47, this);
|
|
}));
|
|
|
|
function upgradeToV2(_x35) {
|
|
return _upgradeToV.apply(this, arguments);
|
|
}
|
|
|
|
return upgradeToV2;
|
|
}()
|
|
/**
|
|
* Check the balance of the project wallet in the native token of the chain
|
|
*
|
|
* @returns - The balance of the project in the native token of the chain
|
|
*/
|
|
;
|
|
|
|
_proto.balance =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee48() {
|
|
var projectBalance, treasuryBalance, treasury;
|
|
return runtime_1.wrap(function _callee48$(_context48) {
|
|
while (1) {
|
|
switch (_context48.prev = _context48.next) {
|
|
case 0:
|
|
_context48.next = 2;
|
|
return this.readOnlyContract.provider.getBalance(this.address);
|
|
|
|
case 2:
|
|
projectBalance = _context48.sent;
|
|
treasuryBalance = BigNumber.from(0);
|
|
_context48.next = 6;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 6:
|
|
treasury = _context48.sent;
|
|
|
|
if (!(treasury.toLowerCase() !== this.address.toLowerCase())) {
|
|
_context48.next = 11;
|
|
break;
|
|
}
|
|
|
|
_context48.next = 10;
|
|
return this.readOnlyContract.provider.getBalance(treasury);
|
|
|
|
case 10:
|
|
treasuryBalance = _context48.sent;
|
|
|
|
case 11:
|
|
return _context48.abrupt("return", projectBalance.add(treasuryBalance));
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context48.stop();
|
|
}
|
|
}
|
|
}, _callee48, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}()
|
|
/**
|
|
* Check the balance of the project wallet in a particular
|
|
* ERC20 token contract
|
|
*
|
|
* @returns - The balance of the project in the native token of the chain
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOfToken =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOfToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee49(tokenAddress) {
|
|
var balance, erc20, treasury;
|
|
return runtime_1.wrap(function _callee49$(_context49) {
|
|
while (1) {
|
|
switch (_context49.prev = _context49.next) {
|
|
case 0:
|
|
balance = BigNumber.from(0);
|
|
|
|
if (!isNativeToken(tokenAddress)) {
|
|
_context49.next = 7;
|
|
break;
|
|
}
|
|
|
|
_context49.next = 4;
|
|
return this.balance();
|
|
|
|
case 4:
|
|
balance = _context49.sent;
|
|
_context49.next = 39;
|
|
break;
|
|
|
|
case 7:
|
|
erc20 = IERC20__factory.connect(tokenAddress, this.readOnlyContract.provider); // TODO: multicall :)
|
|
// only fetch project's erc20 balance if it's not v1
|
|
|
|
_context49.next = 10;
|
|
return this.isV1();
|
|
|
|
case 10:
|
|
if (_context49.sent) {
|
|
_context49.next = 23;
|
|
break;
|
|
}
|
|
|
|
_context49.prev = 11;
|
|
_context49.t0 = balance;
|
|
_context49.next = 15;
|
|
return erc20.balanceOf(this.address);
|
|
|
|
case 15:
|
|
_context49.t1 = _context49.sent;
|
|
balance = _context49.t0.add.call(_context49.t0, _context49.t1);
|
|
_context49.next = 23;
|
|
break;
|
|
|
|
case 19:
|
|
_context49.prev = 19;
|
|
_context49.t2 = _context49["catch"](11);
|
|
// invalid token address
|
|
console.error(_context49.t2);
|
|
throw new Error("invalid token address");
|
|
|
|
case 23:
|
|
_context49.next = 25;
|
|
return this.getRoyaltyTreasury();
|
|
|
|
case 25:
|
|
treasury = _context49.sent;
|
|
|
|
if (!(treasury.toLowerCase() !== this.address.toLowerCase())) {
|
|
_context49.next = 39;
|
|
break;
|
|
}
|
|
|
|
_context49.prev = 27;
|
|
_context49.t3 = balance;
|
|
_context49.next = 31;
|
|
return erc20.balanceOf(treasury);
|
|
|
|
case 31:
|
|
_context49.t4 = _context49.sent;
|
|
balance = _context49.t3.add.call(_context49.t3, _context49.t4);
|
|
_context49.next = 39;
|
|
break;
|
|
|
|
case 35:
|
|
_context49.prev = 35;
|
|
_context49.t5 = _context49["catch"](27);
|
|
// invalid token address
|
|
console.error(_context49.t5);
|
|
throw new Error("invalid token address");
|
|
|
|
case 39:
|
|
_context49.next = 41;
|
|
return getCurrencyValue(this.providerOrSigner, tokenAddress, balance);
|
|
|
|
case 41:
|
|
return _context49.abrupt("return", _context49.sent);
|
|
|
|
case 42:
|
|
case "end":
|
|
return _context49.stop();
|
|
}
|
|
}
|
|
}, _callee49, this, [[11, 19], [27, 35]]);
|
|
}));
|
|
|
|
function balanceOfToken(_x36) {
|
|
return _balanceOfToken.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOfToken;
|
|
}()
|
|
/**
|
|
* @internal
|
|
* Check if contract is v1 or v2. If the contract doesn't have version = v1 contract.
|
|
*/
|
|
;
|
|
|
|
_proto.isV1 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee50() {
|
|
return runtime_1.wrap(function _callee50$(_context50) {
|
|
while (1) {
|
|
switch (_context50.prev = _context50.next) {
|
|
case 0:
|
|
if (!this._shouldCheckVersion) {
|
|
_context50.next = 11;
|
|
break;
|
|
}
|
|
|
|
_context50.prev = 1;
|
|
_context50.next = 4;
|
|
return this.readOnlyContract.callStatic.version();
|
|
|
|
case 4:
|
|
this._isV1 = false;
|
|
_context50.next = 10;
|
|
break;
|
|
|
|
case 7:
|
|
_context50.prev = 7;
|
|
_context50.t0 = _context50["catch"](1);
|
|
this._isV1 = true;
|
|
|
|
case 10:
|
|
this._shouldCheckVersion = false;
|
|
|
|
case 11:
|
|
return _context50.abrupt("return", this._isV1);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context50.stop();
|
|
}
|
|
}
|
|
}, _callee50, this, [[1, 7]]);
|
|
}));
|
|
|
|
function isV1() {
|
|
return _isV.apply(this, arguments);
|
|
}
|
|
|
|
return isV1;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isV1UpgradedOrV2 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isV1UpgradedOrV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee51() {
|
|
return runtime_1.wrap(function _callee51$(_context51) {
|
|
while (1) {
|
|
switch (_context51.prev = _context51.next) {
|
|
case 0:
|
|
_context51.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
_context51.t0 = !_context51.sent;
|
|
|
|
if (_context51.t0) {
|
|
_context51.next = 7;
|
|
break;
|
|
}
|
|
|
|
_context51.next = 6;
|
|
return this.shouldUpgradeToV2();
|
|
|
|
case 6:
|
|
_context51.t0 = !_context51.sent;
|
|
|
|
case 7:
|
|
return _context51.abrupt("return", _context51.t0);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context51.stop();
|
|
}
|
|
}
|
|
}, _callee51, this);
|
|
}));
|
|
|
|
function isV1UpgradedOrV2() {
|
|
return _isV1UpgradedOrV.apply(this, arguments);
|
|
}
|
|
|
|
return isV1UpgradedOrV2;
|
|
}();
|
|
|
|
_proto.deployMarketplaceModule = /*#__PURE__*/function () {
|
|
var _deployMarketplaceModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee52(metadata) {
|
|
var serializedMetadata, metadataUri, nativeTokenWrapperAddress, address;
|
|
return runtime_1.wrap(function _callee52$(_context52) {
|
|
while (1) {
|
|
switch (_context52.prev = _context52.next) {
|
|
case 0:
|
|
_context52.t0 = this.jsonConvert;
|
|
_context52.next = 3;
|
|
return this._prepareMetadata(metadata);
|
|
|
|
case 3:
|
|
_context52.t1 = _context52.sent;
|
|
_context52.t2 = MarketplaceModuleMetadata$1;
|
|
serializedMetadata = _context52.t0.serializeObject.call(_context52.t0, _context52.t1, _context52.t2);
|
|
_context52.t3 = this.sdk.getStorage();
|
|
_context52.t4 = serializedMetadata;
|
|
_context52.t5 = this.address;
|
|
_context52.next = 11;
|
|
return this.getSignerAddress();
|
|
|
|
case 11:
|
|
_context52.t6 = _context52.sent;
|
|
_context52.next = 14;
|
|
return _context52.t3.uploadMetadata.call(_context52.t3, _context52.t4, _context52.t5, _context52.t6);
|
|
|
|
case 14:
|
|
metadataUri = _context52.sent;
|
|
_context52.t7 = getNativeTokenByChainId;
|
|
_context52.next = 18;
|
|
return this.getChainID();
|
|
|
|
case 18:
|
|
_context52.t8 = _context52.sent;
|
|
nativeTokenWrapperAddress = (0, _context52.t7)(_context52.t8).wrapped.address;
|
|
_context52.t9 = this;
|
|
_context52.t10 = ModuleType.MARKETPLACE;
|
|
_context52.t11 = this.address;
|
|
_context52.next = 25;
|
|
return this.getForwarder();
|
|
|
|
case 25:
|
|
_context52.t12 = _context52.sent;
|
|
_context52.t13 = nativeTokenWrapperAddress;
|
|
_context52.t14 = metadataUri;
|
|
_context52.t15 = metadata.marketFeeBasisPoints;
|
|
_context52.t16 = [_context52.t11, _context52.t12, _context52.t13, _context52.t14, _context52.t15];
|
|
_context52.t17 = Marketplace__factory;
|
|
_context52.next = 33;
|
|
return _context52.t9._deployModule.call(_context52.t9, _context52.t10, _context52.t16, _context52.t17);
|
|
|
|
case 33:
|
|
address = _context52.sent;
|
|
return _context52.abrupt("return", this.sdk.getMarketplaceModule(address));
|
|
|
|
case 35:
|
|
case "end":
|
|
return _context52.stop();
|
|
}
|
|
}
|
|
}, _callee52, this);
|
|
}));
|
|
|
|
function deployMarketplaceModule(_x37) {
|
|
return _deployMarketplaceModule.apply(this, arguments);
|
|
}
|
|
|
|
return deployMarketplaceModule;
|
|
}();
|
|
|
|
return AppModule;
|
|
}(ModuleWithRoles);
|
|
AppModule.roles = [RolesMap.admin];
|
|
|
|
/**
|
|
* Create a collection of NFTs that lets you optionally mint multiple copies of each NFT.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getBundleModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var BundleModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(BundleModule, _ModuleWithRoles);
|
|
|
|
function BundleModule() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = BundleModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return BundleModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return NFTCollection__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return BundleModule.moduleType;
|
|
}
|
|
/**
|
|
*
|
|
* Get a single bundle item by tokenId.
|
|
* @param tokenId - the unique token id of the nft
|
|
* @returns A promise that resolves to a `BundleMetadata`.
|
|
*/
|
|
;
|
|
|
|
_proto.get =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tokenId, address) {
|
|
var _yield$Promise$all, metadata, supply, ownedByAddress, state;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.t0 = Promise;
|
|
_context.t1 = getTokenMetadata(this.readOnlyContract, tokenId, this.sdk.getStorage());
|
|
_context.t2 = this.readOnlyContract.totalSupply(tokenId)["catch"](function () {
|
|
return BigNumber$1.from("0");
|
|
});
|
|
|
|
if (!address) {
|
|
_context.next = 9;
|
|
break;
|
|
}
|
|
|
|
_context.next = 6;
|
|
return this.balanceOf(address, tokenId);
|
|
|
|
case 6:
|
|
_context.t3 = _context.sent.toNumber();
|
|
_context.next = 10;
|
|
break;
|
|
|
|
case 9:
|
|
_context.t3 = 0;
|
|
|
|
case 10:
|
|
_context.t4 = _context.t3;
|
|
_context.t5 = this.readOnlyContract.tokenState(tokenId);
|
|
_context.t6 = [_context.t1, _context.t2, _context.t4, _context.t5];
|
|
_context.next = 15;
|
|
return _context.t0.all.call(_context.t0, _context.t6);
|
|
|
|
case 15:
|
|
_yield$Promise$all = _context.sent;
|
|
metadata = _yield$Promise$all[0];
|
|
supply = _yield$Promise$all[1];
|
|
ownedByAddress = _yield$Promise$all[2];
|
|
state = _yield$Promise$all[3];
|
|
return _context.abrupt("return", {
|
|
creator: state.creator,
|
|
supply: supply,
|
|
metadata: metadata,
|
|
ownedByAddress: BigNumber$1.from(ownedByAddress),
|
|
underlyingType: state.underlyingType
|
|
});
|
|
|
|
case 21:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function get(_x, _x2) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get NFT Data
|
|
*
|
|
* @remarks Get data associated with NFTs in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // You can get every NFT in the module
|
|
* const nfts = await module.getAll();
|
|
* console.log(nfts);
|
|
*
|
|
* // Or you can get optionally get the NFTs owned by a specific wallet
|
|
* const address = "{{wallet_address}}"; // The address you want to get the NFTs for;
|
|
* const ownedNfts = await module.getAll(address);
|
|
* console.log(ownedNfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(address) {
|
|
var _this = this;
|
|
|
|
var maxId;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 2:
|
|
maxId = _context2.sent.toNumber();
|
|
_context2.next = 5;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this.get(i.toString(), address);
|
|
}));
|
|
|
|
case 5:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getAll(_x3) {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}()
|
|
/**
|
|
* Get NFT Balance
|
|
*
|
|
* @remarks Get a wallets NFT balance (number of a specific NFT in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check NFT balance
|
|
* const address = "{{wallet_address}}";
|
|
* // The token ID of the NFT you want to check the wallets balance of
|
|
* const tokenId = "0"
|
|
*
|
|
* const balance = await module.balanceOf(address, tokenId);
|
|
* console.log(balance);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(address, tokenId) {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.readOnlyContract.balanceOf(address, tokenId);
|
|
|
|
case 2:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function balanceOf(_x4, _x5) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tokenId) {
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.t0 = this.readOnlyContract;
|
|
_context4.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context4.t1 = _context4.sent;
|
|
_context4.t2 = tokenId;
|
|
_context4.next = 7;
|
|
return _context4.t0.balanceOf.call(_context4.t0, _context4.t1, _context4.t2);
|
|
|
|
case 7:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function balance(_x6) {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address, operator, assetContract, assetId) {
|
|
var contract, approved, isTokenApproved;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
if (assetContract) {
|
|
_context5.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context5.next = 3;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 3:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 4:
|
|
if (assetId) {
|
|
_context5.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("tokenId is required");
|
|
|
|
case 6:
|
|
contract = ERC721__factory.connect(assetContract, this.providerOrSigner);
|
|
_context5.t0 = contract;
|
|
_context5.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
_context5.t1 = _context5.sent;
|
|
_context5.t2 = this.address;
|
|
_context5.next = 14;
|
|
return _context5.t0.isApprovedForAll.call(_context5.t0, _context5.t1, _context5.t2);
|
|
|
|
case 14:
|
|
approved = _context5.sent;
|
|
_context5.next = 17;
|
|
return contract.getApproved(assetId);
|
|
|
|
case 17:
|
|
_context5.t3 = _context5.sent.toLowerCase();
|
|
_context5.t4 = this.address.toLowerCase();
|
|
isTokenApproved = _context5.t3 === _context5.t4;
|
|
return _context5.abrupt("return", approved || isTokenApproved);
|
|
|
|
case 21:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function isApproved(_x7, _x8, _x9, _x10) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.setApproval =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(operator, approved) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context6.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function setApproval(_x11, _x12) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer NFT
|
|
*
|
|
* @remarks Transfer an NFT from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The token ID of the NFT you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* // The number of NFTs you want to send
|
|
* const amount = 1;
|
|
*
|
|
* await module.transfer(toAddress, tokenId, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(to, tokenId, amount) {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.t0 = this;
|
|
_context7.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context7.t1 = _context7.sent;
|
|
_context7.t2 = to;
|
|
_context7.t3 = {
|
|
tokenId: tokenId,
|
|
amount: amount
|
|
};
|
|
_context7.t4 = [0];
|
|
_context7.next = 9;
|
|
return _context7.t0.transferFrom.call(_context7.t0, _context7.t1, _context7.t2, _context7.t3, _context7.t4);
|
|
|
|
case 9:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function transfer(_x13, _x14, _x15) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.create =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(metadata) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.createBatch([metadata]);
|
|
|
|
case 2:
|
|
return _context8.abrupt("return", _context8.sent[0]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function create(_x16) {
|
|
return _create.apply(this, arguments);
|
|
}
|
|
|
|
return create;
|
|
}();
|
|
|
|
_proto.createBatch = /*#__PURE__*/function () {
|
|
var _createBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(metadatas) {
|
|
var metadataWithSupply;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
metadataWithSupply = metadatas.map(function (m) {
|
|
return {
|
|
metadata: m,
|
|
supply: 0
|
|
};
|
|
});
|
|
return _context9.abrupt("return", this.createAndMintBatch(metadataWithSupply));
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function createBatch(_x17) {
|
|
return _createBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createBatch;
|
|
}()
|
|
/**
|
|
* Mint NFT
|
|
*
|
|
* @remarks Mint an NFT with a specified supply.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Custom metadata of the NFT, note that you can fully customize this metadata with other properties.
|
|
* const metadata = {
|
|
* name: "Cool NFT",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* }
|
|
*
|
|
* const metadataWithSupply = {
|
|
* metadata,
|
|
* supply: 1, // The number of this NFT you want to mint
|
|
* }
|
|
*
|
|
* await module.createAndMint(metadataWithSupply);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.createAndMint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createAndMint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(metadataWithSupply) {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.next = 2;
|
|
return this.createAndMintBatch([metadataWithSupply]);
|
|
|
|
case 2:
|
|
return _context10.abrupt("return", _context10.sent[0]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function createAndMint(_x18) {
|
|
return _createAndMint.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMint;
|
|
}()
|
|
/**
|
|
* Mint Many NFTs
|
|
*
|
|
* @remarks Mint many different NFTs with specified supplies.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Custom metadata and supplies of your NFTs
|
|
* const metadataWithSupply = [{
|
|
* supply: 1, // The number of this NFT you want to mint
|
|
* metadata: {
|
|
* name: "Cool NFT #1",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* },
|
|
* }, {
|
|
* supply: 1,
|
|
* metadata: {
|
|
* name: "Cool NFT #2",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* },
|
|
* }];
|
|
*
|
|
* await module.createAndMintBatch(metadataWithSupply);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.createAndMintBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createAndMintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(metadataWithSupply) {
|
|
var _this2 = this;
|
|
|
|
var metadatas, _yield$this$sdk$getSt, uris, supplies, to, receipt, event, tokenIds;
|
|
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
metadatas = metadataWithSupply.map(function (a) {
|
|
return a.metadata;
|
|
});
|
|
_context11.next = 3;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas);
|
|
|
|
case 3:
|
|
_yield$this$sdk$getSt = _context11.sent;
|
|
uris = _yield$this$sdk$getSt.metadataUris;
|
|
supplies = metadataWithSupply.map(function (a) {
|
|
return a.supply;
|
|
});
|
|
_context11.next = 8;
|
|
return this.getSignerAddress();
|
|
|
|
case 8:
|
|
to = _context11.sent;
|
|
_context11.next = 11;
|
|
return this.sendTransaction("createNativeTokens", [to, uris, supplies, [0]]);
|
|
|
|
case 11:
|
|
receipt = _context11.sent;
|
|
event = this.parseEventLogs("NativeTokens", receipt == null ? void 0 : receipt.logs);
|
|
tokenIds = event == null ? void 0 : event.tokenIds;
|
|
_context11.next = 16;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this2.get(tokenId.toString());
|
|
}));
|
|
|
|
case 16:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function createAndMintBatch(_x19) {
|
|
return _createAndMintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createAndMintBatch;
|
|
}();
|
|
|
|
_proto.createWithToken = /*#__PURE__*/function () {
|
|
var _createWithToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(tokenContract, tokenAmount, args) {
|
|
var token, allowance, uri;
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
token = ERC20__factory.connect(tokenContract, this.providerOrSigner);
|
|
_context12.t0 = token;
|
|
_context12.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context12.t1 = _context12.sent;
|
|
_context12.t2 = this.address;
|
|
_context12.next = 8;
|
|
return _context12.t0.allowance.call(_context12.t0, _context12.t1, _context12.t2);
|
|
|
|
case 8:
|
|
allowance = _context12.sent;
|
|
|
|
if (!(allowance < tokenAmount)) {
|
|
_context12.next = 12;
|
|
break;
|
|
}
|
|
|
|
_context12.next = 12;
|
|
return token.increaseAllowance(this.address, tokenAmount);
|
|
|
|
case 12:
|
|
_context12.next = 14;
|
|
return this.sdk.getStorage().uploadMetadata(args.metadata);
|
|
|
|
case 14:
|
|
uri = _context12.sent;
|
|
_context12.next = 17;
|
|
return this.sendTransaction("wrapERC20", [tokenContract, tokenAmount, args.supply, uri]);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function createWithToken(_x20, _x21, _x22) {
|
|
return _createWithToken.apply(this, arguments);
|
|
}
|
|
|
|
return createWithToken;
|
|
}();
|
|
|
|
_proto.createWithErc20 = /*#__PURE__*/function () {
|
|
var _createWithErc = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(tokenContract, tokenAmount, args) {
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
return _context13.abrupt("return", this.createWithToken(tokenContract, tokenAmount, args));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function createWithErc20(_x23, _x24, _x25) {
|
|
return _createWithErc.apply(this, arguments);
|
|
}
|
|
|
|
return createWithErc20;
|
|
}();
|
|
|
|
_proto.createWithNFT = /*#__PURE__*/function () {
|
|
var _createWithNFT = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(tokenContract, tokenId, metadata) {
|
|
var asset, isTokenApproved, uri;
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
asset = ERC721__factory.connect(tokenContract, this.providerOrSigner);
|
|
_context14.t0 = asset;
|
|
_context14.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context14.t1 = _context14.sent;
|
|
_context14.t2 = this.address;
|
|
_context14.next = 8;
|
|
return _context14.t0.isApprovedForAll.call(_context14.t0, _context14.t1, _context14.t2);
|
|
|
|
case 8:
|
|
if (_context14.sent) {
|
|
_context14.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context14.next = 11;
|
|
return asset.getApproved(tokenId);
|
|
|
|
case 11:
|
|
_context14.t3 = _context14.sent.toLowerCase();
|
|
_context14.t4 = this.address.toLowerCase();
|
|
isTokenApproved = _context14.t3 === _context14.t4;
|
|
|
|
if (isTokenApproved) {
|
|
_context14.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context14.next = 17;
|
|
return this.sendContractTransaction(asset, "setApprovalForAll", [this.address]);
|
|
|
|
case 17:
|
|
_context14.next = 19;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 19:
|
|
uri = _context14.sent;
|
|
_context14.next = 22;
|
|
return this.sendTransaction("wrapERC721", [tokenContract, tokenId, uri]);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function createWithNFT(_x26, _x27, _x28) {
|
|
return _createWithNFT.apply(this, arguments);
|
|
}
|
|
|
|
return createWithNFT;
|
|
}();
|
|
|
|
_proto.unwrapNFT = /*#__PURE__*/function () {
|
|
var _unwrapNFT = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(tokenId) {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.next = 2;
|
|
return this.sendTransaction("redeemERC721", [tokenId]);
|
|
|
|
case 2:
|
|
return _context15.abrupt("return", _context15.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function unwrapNFT(_x29) {
|
|
return _unwrapNFT.apply(this, arguments);
|
|
}
|
|
|
|
return unwrapNFT;
|
|
}();
|
|
|
|
_proto.unwrapToken = /*#__PURE__*/function () {
|
|
var _unwrapToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(tokenId, amount) {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.sendTransaction("redeemERC20", [tokenId, amount]);
|
|
|
|
case 2:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function unwrapToken(_x30, _x31) {
|
|
return _unwrapToken.apply(this, arguments);
|
|
}
|
|
|
|
return unwrapToken;
|
|
}();
|
|
|
|
_proto.createWithERC721 = /*#__PURE__*/function () {
|
|
var _createWithERC = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(tokenContract, tokenId, metadata) {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
return _context17.abrupt("return", this.createWithNFT(tokenContract, tokenId, metadata));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function createWithERC721(_x32, _x33, _x34) {
|
|
return _createWithERC.apply(this, arguments);
|
|
}
|
|
|
|
return createWithERC721;
|
|
}();
|
|
|
|
_proto.mint = /*#__PURE__*/function () {
|
|
var _mint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(args) {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
_context18.t0 = this;
|
|
_context18.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context18.t1 = _context18.sent;
|
|
_context18.t2 = args;
|
|
_context18.next = 7;
|
|
return _context18.t0.mintTo.call(_context18.t0, _context18.t1, _context18.t2);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function mint(_x35) {
|
|
return _mint.apply(this, arguments);
|
|
}
|
|
|
|
return mint;
|
|
}();
|
|
|
|
_proto.mintTo = /*#__PURE__*/function () {
|
|
var _mintTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(to, args, data) {
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context19.next = 3;
|
|
return this.sendTransaction("mint", [to, args.tokenId, args.amount, data]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function mintTo(_x36, _x37, _x38) {
|
|
return _mintTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintTo;
|
|
}();
|
|
|
|
_proto.mintBatch = /*#__PURE__*/function () {
|
|
var _mintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(args) {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.t0 = this;
|
|
_context20.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context20.t1 = _context20.sent;
|
|
_context20.t2 = args;
|
|
_context20.next = 7;
|
|
return _context20.t0.mintBatchTo.call(_context20.t0, _context20.t1, _context20.t2);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function mintBatch(_x39) {
|
|
return _mintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return mintBatch;
|
|
}();
|
|
|
|
_proto.mintBatchTo = /*#__PURE__*/function () {
|
|
var _mintBatchTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(to, args, data) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context21.next = 5;
|
|
return this.sendTransaction("mintBatch", [to, ids, amounts, data]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function mintBatchTo(_x40, _x41, _x42) {
|
|
return _mintBatchTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintBatchTo;
|
|
}()
|
|
/**
|
|
* Burn NFT
|
|
*
|
|
* @remarks Burn an NFT, permanently taking it out of circulation and reducing the supply.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The token ID of the NFT you want to burn
|
|
* const tokenId = 0;
|
|
* // The number of specified NFTs you want to burn
|
|
* const amount = 1
|
|
*
|
|
* await module.burn({ tokenId, amount });
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.burn =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(args) {
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.t0 = this;
|
|
_context22.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context22.t1 = _context22.sent;
|
|
_context22.t2 = args;
|
|
_context22.next = 7;
|
|
return _context22.t0.burnFrom.call(_context22.t0, _context22.t1, _context22.t2);
|
|
|
|
case 7:
|
|
return _context22.abrupt("return", _context22.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function burn(_x43) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.burnBatch = /*#__PURE__*/function () {
|
|
var _burnBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(args) {
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.t0 = this;
|
|
_context23.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context23.t1 = _context23.sent;
|
|
_context23.t2 = args;
|
|
_context23.next = 7;
|
|
return _context23.t0.burnBatchFrom.call(_context23.t0, _context23.t1, _context23.t2);
|
|
|
|
case 7:
|
|
return _context23.abrupt("return", _context23.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function burnBatch(_x44) {
|
|
return _burnBatch.apply(this, arguments);
|
|
}
|
|
|
|
return burnBatch;
|
|
}();
|
|
|
|
_proto.burnFrom = /*#__PURE__*/function () {
|
|
var _burnFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(account, args) {
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
_context24.next = 2;
|
|
return this.sendTransaction("burn", [account, args.tokenId, args.amount]);
|
|
|
|
case 2:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function burnFrom(_x45, _x46) {
|
|
return _burnFrom.apply(this, arguments);
|
|
}
|
|
|
|
return burnFrom;
|
|
}();
|
|
|
|
_proto.burnBatchFrom = /*#__PURE__*/function () {
|
|
var _burnBatchFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(account, args) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context25.next = 4;
|
|
return this.sendTransaction("burnBatch", [account, ids, amounts]);
|
|
|
|
case 4:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function burnBatchFrom(_x47, _x48) {
|
|
return _burnBatchFrom.apply(this, arguments);
|
|
}
|
|
|
|
return burnBatchFrom;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(from, to, args, data) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context26.next = 3;
|
|
return this.sendTransaction("safeTransferFrom", [from, to, args.tokenId, args.amount, data]);
|
|
|
|
case 3:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function transferFrom(_x49, _x50, _x51, _x52) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}()
|
|
/**
|
|
* Transfer Many NFTs
|
|
*
|
|
* @remarks Transfer NFTs from the one wallet to another.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to send the NFT from
|
|
* const fromAddress = "{{wallet_address}}";
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The data of the NFTs you want to send
|
|
* const data = [{
|
|
* tokenId: 1, // The token ID of the NFT you want to send
|
|
* amount: 1, // The number of this NFT you want to send
|
|
* }, {
|
|
* tokenId: 2,
|
|
* amount: 1,
|
|
* }]
|
|
*
|
|
* // Note that the connected wallet must have approval to transfer the tokens of the fromAddress
|
|
* await module.transferBatchFrom(fromAddress, toAddress, data);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transferBatchFrom =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transferBatchFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(from, to, args, data) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context27.next = 5;
|
|
return this.sendTransaction("safeBatchTransferFrom", [from, to, ids, amounts, data]);
|
|
|
|
case 5:
|
|
return _context27.abrupt("return", _context27.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function transferBatchFrom(_x53, _x54, _x55, _x56) {
|
|
return _transferBatchFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferBatchFrom;
|
|
}();
|
|
|
|
_proto.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(amount) {
|
|
var _yield$this$getMetada, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada = _context28.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context28.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context28.t0 = this.sdk.getStorage();
|
|
_context28.t1 = _extends({}, metadata);
|
|
_context28.t2 = this.address;
|
|
_context28.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context28.t3 = _context28.sent;
|
|
_context28.next = 16;
|
|
return _context28.t0.uploadMetadata.call(_context28.t0, _context28.t1, _context28.t2, _context28.t3);
|
|
|
|
case 16:
|
|
uri = _context28.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context28.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context28.abrupt("return", _context28.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x57) {
|
|
return _setRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
_context29.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context29.sent;
|
|
_context29.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context29.abrupt("return", _context29.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x58) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}()
|
|
/**
|
|
* `getOwned` is a convenience method for getting all owned tokens
|
|
* for a particular wallet.
|
|
*
|
|
* @param _address - The address to check for token ownership
|
|
* @returns An array of BundleMetadata objects that are owned by the address
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(_address) {
|
|
var _this3 = this;
|
|
|
|
var address, maxId, balances, ownedBalances;
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context31.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context31.t0 = _address;
|
|
_context31.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context31.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context31.t0 = _context31.sent;
|
|
|
|
case 7:
|
|
address = _context31.t0;
|
|
_context31.next = 10;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 10:
|
|
maxId = _context31.sent;
|
|
_context31.next = 13;
|
|
return this.readOnlyContract.balanceOfBatch(Array(maxId.toNumber()).fill(address), Array.from(Array(maxId.toNumber()).keys()));
|
|
|
|
case 13:
|
|
balances = _context31.sent;
|
|
ownedBalances = balances.map(function (b, i) {
|
|
return {
|
|
tokenId: i,
|
|
balance: b
|
|
};
|
|
}).filter(function (b) {
|
|
return b.balance.gt(0);
|
|
});
|
|
_context31.next = 17;
|
|
return Promise.all(ownedBalances.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30(item) {
|
|
var token;
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
_context30.next = 2;
|
|
return _this3.get(item.tokenId.toString());
|
|
|
|
case 2:
|
|
token = _context30.sent;
|
|
return _context30.abrupt("return", _extends({}, token, {
|
|
ownedByAddress: item.balance
|
|
}));
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30);
|
|
}));
|
|
|
|
return function (_x60) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 17:
|
|
return _context31.abrupt("return", _context31.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this);
|
|
}));
|
|
|
|
function getOwned(_x59) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32() {
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
_context32.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context32.abrupt("return", _context32.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33() {
|
|
var _metadata$metadata;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
_context33.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context33.sent;
|
|
|
|
if (!(((_metadata$metadata = metadata.metadata) == null ? void 0 : _metadata$metadata.fee_recipient) !== undefined)) {
|
|
_context33.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context33.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context33.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34() {
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
return _context34.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(restricted) {
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context35.t0 = this;
|
|
_context35.t1 = ["admin"];
|
|
_context35.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context35.t2 = _context35.sent;
|
|
_context35.next = 8;
|
|
return _context35.t0.onlyRoles.call(_context35.t0, _context35.t1, _context35.t2);
|
|
|
|
case 8:
|
|
_context35.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context35.abrupt("return", _context35.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x61) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}();
|
|
|
|
return BundleModule;
|
|
}(ModuleWithRoles);
|
|
BundleModule.moduleType = ModuleType.BUNDLE;
|
|
BundleModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.pauser, RolesMap.transfer];
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
function isMetadataEqual(old, changed) {
|
|
if (typeof old === "object" && typeof changed === "object") {
|
|
var oldKeys = Object.keys(old).sort();
|
|
var changedKeys = Object.keys(changed).sort();
|
|
|
|
if (oldKeys === changedKeys) {
|
|
for (var i = 0; i < oldKeys.length; i++) {
|
|
if (!isMetadataEqual(old[oldKeys[i]], changed[changedKeys[i]])) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return old === changed;
|
|
}
|
|
|
|
var ListingType;
|
|
|
|
(function (ListingType) {
|
|
ListingType[ListingType["Direct"] = 0] = "Direct";
|
|
ListingType[ListingType["Auction"] = 1] = "Auction";
|
|
})(ListingType || (ListingType = {}));
|
|
|
|
var ClaimConditionType;
|
|
|
|
(function (ClaimConditionType) {
|
|
ClaimConditionType[ClaimConditionType["StartTime"] = 0] = "StartTime";
|
|
ClaimConditionType[ClaimConditionType["LimitPerWallet"] = 1] = "LimitPerWallet";
|
|
ClaimConditionType[ClaimConditionType["MerkleRoot"] = 2] = "MerkleRoot";
|
|
ClaimConditionType[ClaimConditionType["WaitTimeBetweenClaims"] = 3] = "WaitTimeBetweenClaims";
|
|
})(ClaimConditionType || (ClaimConditionType = {}));
|
|
|
|
var ProposalState;
|
|
|
|
(function (ProposalState) {
|
|
ProposalState[ProposalState["Pending"] = 0] = "Pending";
|
|
ProposalState[ProposalState["Active"] = 1] = "Active";
|
|
ProposalState[ProposalState["Canceled"] = 2] = "Canceled";
|
|
ProposalState[ProposalState["Defeated"] = 3] = "Defeated";
|
|
ProposalState[ProposalState["Succeeded"] = 4] = "Succeeded";
|
|
ProposalState[ProposalState["Queued"] = 5] = "Queued";
|
|
ProposalState[ProposalState["Expired"] = 6] = "Expired";
|
|
ProposalState[ProposalState["Executed"] = 7] = "Executed";
|
|
})(ProposalState || (ProposalState = {}));
|
|
|
|
var VoteType;
|
|
|
|
(function (VoteType) {
|
|
VoteType[VoteType["Against"] = 0] = "Against";
|
|
VoteType[VoteType["For"] = 1] = "For";
|
|
VoteType[VoteType["Abstain"] = 2] = "Abstain";
|
|
})(VoteType || (VoteType = {}));
|
|
|
|
var ClaimEligibility;
|
|
|
|
(function (ClaimEligibility) {
|
|
ClaimEligibility["NotEnoughSupply"] = "There is not enough supply to claim.";
|
|
ClaimEligibility["AddressNotAllowed"] = "This address is not on the allowlist.";
|
|
ClaimEligibility["WaitBeforeNextClaimTransaction"] = "Not enough time since last claim transaction. Please wait.";
|
|
ClaimEligibility["AlreadyClaimed"] = "You have already claimed the token.";
|
|
ClaimEligibility["NotEnoughTokens"] = "There are not enough tokens in the wallet to pay for the claim.";
|
|
ClaimEligibility["NoActiveClaimPhase"] = "There is no active claim phase at the moment. Please check back in later.";
|
|
})(ClaimEligibility || (ClaimEligibility = {}));
|
|
|
|
var ClaimConditionPhase = /*#__PURE__*/function () {
|
|
// In seconds
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
function ClaimConditionPhase(createSnapshotFunc) {
|
|
this._conditionStartTime = Math.floor(Date.now() / 1000);
|
|
this._currencyAddress = "";
|
|
this._price = 0;
|
|
this._maxQuantity = BigNumber.from(0);
|
|
this._quantityLimitPerTransaction = ethers.constants.MaxUint256;
|
|
this._merkleRootHash = hexZeroPad([0], 32);
|
|
this._merkleCondition = undefined;
|
|
this._snapshot = undefined;
|
|
this.createSnapshot = void 0;
|
|
this._waitInSeconds = 0;
|
|
this.createSnapshot = createSnapshotFunc;
|
|
}
|
|
/**
|
|
* Set the price claim condition for the drop.
|
|
*
|
|
* @param price - The price of the currency in wei. Must be >= 0.
|
|
* @param tokenAddress - The address of an ERC20 contract to use as the currency for the claim. By default this is the native currency address which is 0x0000000000000000000000000000000000000000 address.
|
|
*/
|
|
|
|
|
|
var _proto = ClaimConditionPhase.prototype;
|
|
|
|
_proto.setPrice = function setPrice(price, tokenAddress) {
|
|
if (tokenAddress === void 0) {
|
|
tokenAddress = AddressZero;
|
|
}
|
|
|
|
if (!isAddress$1(tokenAddress)) {
|
|
throw new InvalidAddressError(tokenAddress);
|
|
}
|
|
|
|
!(price >= 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "Price cannot be negative") : invariant(false) : void 0;
|
|
this._price = price;
|
|
this._currencyAddress = tokenAddress;
|
|
return this;
|
|
}
|
|
/**
|
|
* Set the start time for the claim condition.
|
|
*
|
|
* @param startTime - The start time for the claim condition. Can be a Date object or a number of seconds since the epoch.
|
|
*/
|
|
;
|
|
|
|
_proto.setConditionStartTime = function setConditionStartTime(when) {
|
|
if (typeof when === "number") {
|
|
this._conditionStartTime = Math.floor(when);
|
|
} else {
|
|
// if its starting in the past, just set it to now
|
|
this._conditionStartTime = Math.floor(when.getTime() / 1000);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
/**
|
|
* Override the maxQuantity for the claim condition after creating the phase.
|
|
*
|
|
* @param maxQuantity - The max quantity NFTs that can be claimed in this phase.
|
|
*/
|
|
;
|
|
|
|
_proto.setMaxQuantity = function setMaxQuantity(maxQuantity) {
|
|
this._maxQuantity = maxQuantity;
|
|
return this;
|
|
}
|
|
/**
|
|
* The max quantity of NFTs that can be claimed in a single transaction.
|
|
*
|
|
* @param max - The max quantity NFTs that can be claimed in a single transaction.
|
|
*/
|
|
;
|
|
|
|
_proto.setMaxQuantityPerTransaction = function setMaxQuantityPerTransaction(max) {
|
|
var maxQuantity = BigNumber.from(max);
|
|
!maxQuantity.gte(1) ? process.env.NODE_ENV !== "production" ? invariant(false, "Max quantity per transaction must be > 0") : invariant(false) : void 0;
|
|
this._quantityLimitPerTransaction = maxQuantity;
|
|
return this;
|
|
}
|
|
/**
|
|
* Sets a merkle root hash for the claim condition.
|
|
*
|
|
* @param root - The merkle root hash
|
|
*/
|
|
;
|
|
|
|
_proto.setMerkleRoot = function setMerkleRoot(root) {
|
|
this._merkleRootHash = root;
|
|
return this;
|
|
}
|
|
/**
|
|
* Sets a snapshot for the claim condition. You can use a snapshot
|
|
* to verify a merkle tree condition.
|
|
*
|
|
* @param root - The merkle root hash
|
|
*/
|
|
;
|
|
|
|
_proto.setSnapshot = function setSnapshot(addresses) {
|
|
this._snapshot = addresses;
|
|
return this;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getSnapshot = function getSnapshot() {
|
|
return this._merkleCondition;
|
|
}
|
|
/**
|
|
* Helper method that provides defaults for each claim condition.
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.buildPublicClaimCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _buildPublicClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var _this$_merkleConditio;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
if (!this._snapshot) {
|
|
_context.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context.next = 3;
|
|
return this.createSnapshot(this._snapshot);
|
|
|
|
case 3:
|
|
this._merkleCondition = _context.sent;
|
|
|
|
case 4:
|
|
return _context.abrupt("return", {
|
|
startTimestamp: BigNumber.from(this._conditionStartTime.toString()),
|
|
pricePerToken: this._price,
|
|
currency: this._currencyAddress || AddressZero,
|
|
maxMintSupply: this._maxQuantity,
|
|
waitTimeSecondsLimitPerTransaction: this._waitInSeconds,
|
|
quantityLimitPerTransaction: this._quantityLimitPerTransaction,
|
|
currentMintSupply: 0,
|
|
merkleRoot: (_this$_merkleConditio = this._merkleCondition) != null && _this$_merkleConditio.merkleRoot ? this._merkleCondition.merkleRoot : this._merkleRootHash
|
|
});
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function buildPublicClaimCondition() {
|
|
return _buildPublicClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return buildPublicClaimCondition;
|
|
}()
|
|
/**
|
|
* Wait time enforced after calling `claim` before the next `claim` can be called.
|
|
*
|
|
* @param waitInSeconds - The wait time in seconds.
|
|
*/
|
|
;
|
|
|
|
_proto.setWaitTimeBetweenClaims = function setWaitTimeBetweenClaims(waitInSeconds) {
|
|
this._waitInSeconds = waitInSeconds;
|
|
return this;
|
|
};
|
|
|
|
return ClaimConditionPhase;
|
|
}();
|
|
|
|
var ClaimConditionFactory = /*#__PURE__*/function () {
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
function ClaimConditionFactory(createSnapshotFunc) {
|
|
this.phases = [];
|
|
this.createSnapshot = void 0;
|
|
this.createSnapshot = createSnapshotFunc;
|
|
}
|
|
/**
|
|
* Used internally when creating a drop module/updating
|
|
* the claim conditions of a drop module.
|
|
*
|
|
* @internal
|
|
*
|
|
* @returns - The claim conditions that will be used when validating a users claim transaction.
|
|
*/
|
|
|
|
|
|
var _proto = ClaimConditionFactory.prototype;
|
|
|
|
_proto.buildConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _buildConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var sorted;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
sorted = [];
|
|
_context.next = 3;
|
|
return Promise.all(this.phases.map(function (c) {
|
|
return c.buildPublicClaimCondition();
|
|
})).then(function (publicClaimConditions) {
|
|
// TODO: write test to ensure they're sorted by start time, earliest first
|
|
sorted = publicClaimConditions.sort(function (a, b) {
|
|
if (a.startTimestamp.eq(b.startTimestamp)) {
|
|
return 0;
|
|
} else if (a.startTimestamp.gt(b.startTimestamp)) {
|
|
return 1;
|
|
} else {
|
|
return -1;
|
|
}
|
|
});
|
|
});
|
|
|
|
case 3:
|
|
return _context.abrupt("return", sorted);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function buildConditions() {
|
|
return _buildConditions.apply(this, arguments);
|
|
}
|
|
|
|
return buildConditions;
|
|
}()
|
|
/**
|
|
* Used internally when creating a drop module/updating
|
|
* the claim conditions of a drop module.
|
|
*
|
|
* @internal
|
|
*
|
|
* @returns - The claim conditions that will be used when validating a users claim transaction.
|
|
*/
|
|
;
|
|
|
|
_proto.buildConditionsForDropV1 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _buildConditionsForDropV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
var conditions, sorted;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return Promise.all(this.phases.map(function (c) {
|
|
return c.buildPublicClaimCondition();
|
|
}));
|
|
|
|
case 2:
|
|
conditions = _context2.sent;
|
|
conditions = conditions.map(function (c) {
|
|
var now = Math.floor(Date.now() / 1000);
|
|
return _extends({}, c, {
|
|
startTimestamp: c.startTimestamp.lt(now) ? BigNumber.from(0) : c.startTimestamp.sub(now)
|
|
});
|
|
}); // TODO: write test to ensure they're sorted by start time, earliest first
|
|
|
|
sorted = conditions.sort(function (a, b) {
|
|
if (a.startTimestamp.eq(b.startTimestamp)) {
|
|
return 0;
|
|
} else if (a.startTimestamp.gt(b.startTimestamp)) {
|
|
return 1;
|
|
} else {
|
|
return -1;
|
|
}
|
|
});
|
|
return _context2.abrupt("return", sorted);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function buildConditionsForDropV1() {
|
|
return _buildConditionsForDropV.apply(this, arguments);
|
|
}
|
|
|
|
return buildConditionsForDropV1;
|
|
}()
|
|
/**
|
|
* Converts a set of generic `PublicClaimCondition`s into a `ClaimConditionFactory`
|
|
*
|
|
* @param conditions - The conditions to load, should be returned directly from the contract.
|
|
* @returns - The loaded claim condition factory.
|
|
*/
|
|
;
|
|
|
|
_proto.fromPublicClaimConditions = function fromPublicClaimConditions(conditions) {
|
|
var phases = [];
|
|
|
|
for (var _iterator = _createForOfIteratorHelperLoose(conditions), _step; !(_step = _iterator()).done;) {
|
|
var condition = _step.value;
|
|
var phase = new ClaimConditionPhase(this.createSnapshot); // If there's a price, there must also be an associated currency
|
|
|
|
if (condition.currency) {
|
|
phase.setPrice(condition.pricePerToken, condition.currency);
|
|
}
|
|
|
|
if (condition.maxMintSupply) {
|
|
phase.setMaxQuantity(condition.maxMintSupply);
|
|
}
|
|
|
|
phase.setConditionStartTime(new Date(condition.startTimestamp.toNumber() * 1000));
|
|
phases.push(phase);
|
|
}
|
|
|
|
this.phases = phases;
|
|
return this;
|
|
}
|
|
/**
|
|
* Creates a new claim 'phase' with its own set of claim conditions
|
|
*
|
|
* @param startTime - The start time of the phase in epoch seconds or a `Date` object.
|
|
* @param maxQuantity - The max quantity of the phase. By default, this is set to be infinite. In most cases, if your drop only
|
|
has a single phase, you don't need to override this value. If your drop has multiple phases, you should override this value and specify how many tokens are available for each specific phase.
|
|
* @param maxQuantityPerTransaction - The maximum number of claims that can be made in a single transaction. By default, this is set to infinite which means that there is no limit.
|
|
*
|
|
* @returns - The claim condition builder.
|
|
*/
|
|
;
|
|
|
|
_proto.newClaimPhase = function newClaimPhase(_ref) {
|
|
var startTime = _ref.startTime,
|
|
_ref$maxQuantity = _ref.maxQuantity,
|
|
maxQuantity = _ref$maxQuantity === void 0 ? ethers.constants.MaxUint256 : _ref$maxQuantity,
|
|
_ref$maxQuantityPerTr = _ref.maxQuantityPerTransaction,
|
|
maxQuantityPerTransaction = _ref$maxQuantityPerTr === void 0 ? ethers.constants.MaxUint256 : _ref$maxQuantityPerTr;
|
|
var condition = new ClaimConditionPhase(this.createSnapshot);
|
|
condition.setConditionStartTime(startTime);
|
|
condition.setMaxQuantity(BigNumber.from(maxQuantity));
|
|
condition.setMaxQuantityPerTransaction(BigNumber.from(maxQuantityPerTransaction));
|
|
this.phases.push(condition);
|
|
return condition;
|
|
}
|
|
/**
|
|
* Removes a claim condition phase from the factory.
|
|
*
|
|
* @param phase - The phase to remove
|
|
*/
|
|
;
|
|
|
|
_proto.deleteClaimPhase =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _deleteClaimPhase = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(index) {
|
|
var sorted, cleared;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
if (!(index < 0 || index >= this.phases.length)) {
|
|
_context3.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context3.abrupt("return");
|
|
|
|
case 2:
|
|
_context3.next = 4;
|
|
return this.buildConditions();
|
|
|
|
case 4:
|
|
sorted = _context3.sent;
|
|
cleared = sorted.splice(index - 1, 1);
|
|
this.fromPublicClaimConditions(cleared);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function deleteClaimPhase(_x) {
|
|
return _deleteClaimPhase.apply(this, arguments);
|
|
}
|
|
|
|
return deleteClaimPhase;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link ClaimConditionFactory.deleteClaimPhase} instead.
|
|
*/
|
|
;
|
|
|
|
_proto.removeClaimPhase = function removeClaimPhase(_index) {
|
|
throw new FunctionDeprecatedError("deleteClaimPhase");
|
|
}
|
|
/**
|
|
* Helper method fetches all snapshots from a factory.
|
|
*
|
|
* @returns - All snapshots in the condition factory.
|
|
*/
|
|
;
|
|
|
|
_proto.allSnapshots = function allSnapshots() {
|
|
return this.phases.filter(function (p) {
|
|
return p.getSnapshot() !== undefined;
|
|
}).map(function (p) {
|
|
return p.getSnapshot();
|
|
});
|
|
};
|
|
|
|
return ClaimConditionFactory;
|
|
}();
|
|
|
|
/**
|
|
* The model for a claim proof. Currently we support only an address
|
|
* in the leaf of the merkle tree.
|
|
*/
|
|
|
|
var ClaimProof = function ClaimProof() {
|
|
this.address = "";
|
|
this.proof = [];
|
|
};
|
|
|
|
__decorate([JsonProperty("address", String)], ClaimProof.prototype, "address", void 0);
|
|
|
|
__decorate([JsonProperty("proof", [String])], ClaimProof.prototype, "proof", void 0);
|
|
|
|
ClaimProof = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("ClaimProof")], ClaimProof);
|
|
|
|
var Snapshot = function Snapshot() {
|
|
this.merkleRoot = "";
|
|
this.claims = [];
|
|
};
|
|
|
|
__decorate([JsonProperty("merkleRoot", String)], Snapshot.prototype, "merkleRoot", void 0);
|
|
|
|
__decorate([JsonProperty("claims", [ClaimProof])], Snapshot.prototype, "claims", void 0);
|
|
|
|
Snapshot = /*#__PURE__*/__decorate([/*#__PURE__*/JsonObject("Snapshot")], Snapshot);
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var OLD_CLAIM_ABI = [{
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "_tokenId",
|
|
type: "uint256"
|
|
}, {
|
|
internalType: "uint256",
|
|
name: "_quantity",
|
|
type: "uint256"
|
|
}, {
|
|
internalType: "bytes32[]",
|
|
name: "_proofs",
|
|
type: "bytes32[]"
|
|
}],
|
|
name: "claim",
|
|
outputs: [],
|
|
stateMutability: "payable",
|
|
type: "function"
|
|
}, {
|
|
anonymous: false,
|
|
inputs: [{
|
|
indexed: true,
|
|
internalType: "uint256",
|
|
name: "claimConditionIndex",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: true,
|
|
internalType: "uint256",
|
|
name: "tokenId",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: true,
|
|
internalType: "address",
|
|
name: "claimer",
|
|
type: "address"
|
|
}, {
|
|
indexed: false,
|
|
internalType: "uint256",
|
|
name: "quantityClaimed",
|
|
type: "uint256"
|
|
}],
|
|
name: "ClaimedTokens",
|
|
type: "event"
|
|
}];
|
|
/**
|
|
* Setup a collection of NFTs with a customizable number of each NFT that are minted as users claim them.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getBundleDropModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var BundleDropModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(BundleDropModule, _ModuleWithRoles);
|
|
|
|
function BundleDropModule() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _ModuleWithRoles.call.apply(_ModuleWithRoles, [this].concat(args)) || this;
|
|
_this._shouldCheckVersion = true;
|
|
_this._isNewClaim = false;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = BundleDropModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return BundleDropModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return LazyMintERC1155__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return BundleDropModule.moduleType;
|
|
};
|
|
|
|
_proto.transformResultToClaimCondition = /*#__PURE__*/function () {
|
|
var _transformResultToClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(pm) {
|
|
var cv;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return getCurrencyValue(this.providerOrSigner, pm.currency, pm.pricePerToken);
|
|
|
|
case 2:
|
|
cv = _context.sent;
|
|
return _context.abrupt("return", {
|
|
startTimestamp: new Date(BigNumber.from(pm.startTimestamp).toNumber() * 1000),
|
|
maxMintSupply: pm.maxClaimableSupply.toString(),
|
|
currentMintSupply: pm.supplyClaimed.toString(),
|
|
availableSupply: BigNumber.from(pm.maxClaimableSupply).sub(pm.supplyClaimed).toString(),
|
|
quantityLimitPerTransaction: pm.quantityLimitPerTransaction.toString(),
|
|
waitTimeSecondsLimitPerTransaction: pm.waitTimeInSecondsBetweenClaims.toString(),
|
|
price: BigNumber.from(pm.pricePerToken),
|
|
pricePerToken: BigNumber.from(pm.pricePerToken),
|
|
currency: pm.currency,
|
|
currencyContract: pm.currency,
|
|
currencyMetadata: cv,
|
|
merkleRoot: pm.merkleRoot
|
|
});
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function transformResultToClaimCondition(_x) {
|
|
return _transformResultToClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return transformResultToClaimCondition;
|
|
}();
|
|
|
|
_proto.getTokenMetadata = /*#__PURE__*/function () {
|
|
var _getTokenMetadata2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tokenId) {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return getTokenMetadata(this.readOnlyContract, tokenId, this.sdk.getStorage());
|
|
|
|
case 2:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getTokenMetadata$1(_x2) {
|
|
return _getTokenMetadata2.apply(this, arguments);
|
|
}
|
|
|
|
return getTokenMetadata$1;
|
|
}();
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(tokenId) {
|
|
var _yield$Promise$all, supply, metadata;
|
|
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return Promise.all([this.readOnlyContract.totalSupply(tokenId)["catch"](function () {
|
|
return BigNumber.from(0);
|
|
}), this.getTokenMetadata(tokenId)]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context3.sent;
|
|
supply = _yield$Promise$all[0];
|
|
metadata = _yield$Promise$all[1];
|
|
return _context3.abrupt("return", {
|
|
supply: supply,
|
|
metadata: metadata
|
|
});
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function get(_x3) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get NFT Data
|
|
*
|
|
* @remarks Get data associated with NFTs in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Get data associated with every NFT in the module
|
|
* const nfts = await module.getAll();
|
|
* console.log(nfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
var _this2 = this;
|
|
|
|
var maxId;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 2:
|
|
maxId = _context4.sent.toNumber();
|
|
_context4.next = 5;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this2.get(i.toString());
|
|
}));
|
|
|
|
case 5:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getAll() {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}()
|
|
/**
|
|
* `getOwned` is a convenience method for getting all owned tokens
|
|
* for a particular wallet.
|
|
*
|
|
* @param _address - The address to check for token ownership
|
|
* @returns An array of BundleMetadata objects that are owned by the address
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(_address) {
|
|
var _this3 = this;
|
|
|
|
var address, maxId, balances, ownedBalances;
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context6.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context6.t0 = _address;
|
|
_context6.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context6.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context6.t0 = _context6.sent;
|
|
|
|
case 7:
|
|
address = _context6.t0;
|
|
_context6.next = 10;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 10:
|
|
maxId = _context6.sent;
|
|
_context6.next = 13;
|
|
return this.readOnlyContract.balanceOfBatch(Array(maxId.toNumber()).fill(address), Array.from(Array(maxId.toNumber()).keys()));
|
|
|
|
case 13:
|
|
balances = _context6.sent;
|
|
ownedBalances = balances.map(function (b, i) {
|
|
return {
|
|
tokenId: i,
|
|
balance: b
|
|
};
|
|
}).filter(function (b) {
|
|
return b.balance.gt(0);
|
|
});
|
|
_context6.next = 17;
|
|
return Promise.all(ownedBalances.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(b) {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return _this3.get(b.tokenId.toString());
|
|
|
|
case 2:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5);
|
|
}));
|
|
|
|
return function (_x5) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 17:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function getOwned(_x4) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}();
|
|
|
|
_proto.getActiveClaimCondition = /*#__PURE__*/function () {
|
|
var _getActiveClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(tokenId) {
|
|
var index;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.readOnlyContract.getIndexOfActiveCondition(tokenId);
|
|
|
|
case 2:
|
|
index = _context7.sent;
|
|
_context7.t0 = this;
|
|
_context7.next = 6;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(tokenId, index);
|
|
|
|
case 6:
|
|
_context7.t1 = _context7.sent;
|
|
return _context7.abrupt("return", _context7.t0.transformResultToClaimCondition.call(_context7.t0, _context7.t1));
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getActiveClaimCondition(_x6) {
|
|
return _getActiveClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveClaimCondition;
|
|
}();
|
|
|
|
_proto.getAllClaimConditions = /*#__PURE__*/function () {
|
|
var _getAllClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenId) {
|
|
var _this4 = this;
|
|
|
|
var claimCondition, count, conditions, i;
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.readOnlyContract.claimConditions(tokenId);
|
|
|
|
case 2:
|
|
claimCondition = _context8.sent;
|
|
count = claimCondition.totalConditionCount.toNumber();
|
|
conditions = [];
|
|
i = 0;
|
|
|
|
case 6:
|
|
if (!(i < count)) {
|
|
_context8.next = 15;
|
|
break;
|
|
}
|
|
|
|
_context8.t0 = conditions;
|
|
_context8.next = 10;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(tokenId, i);
|
|
|
|
case 10:
|
|
_context8.t1 = _context8.sent;
|
|
|
|
_context8.t0.push.call(_context8.t0, _context8.t1);
|
|
|
|
case 12:
|
|
i++;
|
|
_context8.next = 6;
|
|
break;
|
|
|
|
case 15:
|
|
return _context8.abrupt("return", Promise.all(conditions.map(function (c) {
|
|
return _this4.transformResultToClaimCondition(c);
|
|
})));
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function getAllClaimConditions(_x7) {
|
|
return _getAllClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimConditions;
|
|
}();
|
|
|
|
_proto.getDefaultSaleRecipient = /*#__PURE__*/function () {
|
|
var _getDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.defaultSaleRecipient();
|
|
|
|
case 2:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function getDefaultSaleRecipient() {
|
|
return _getDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return getDefaultSaleRecipient;
|
|
}();
|
|
|
|
_proto.getSaleRecipient = /*#__PURE__*/function () {
|
|
var _getSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(tokenId) {
|
|
var saleRecipient;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.next = 2;
|
|
return this.readOnlyContract.saleRecipient(tokenId);
|
|
|
|
case 2:
|
|
saleRecipient = _context10.sent;
|
|
|
|
if (!(saleRecipient === AddressZero)) {
|
|
_context10.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context10.abrupt("return", this.readOnlyContract.defaultSaleRecipient());
|
|
|
|
case 5:
|
|
return _context10.abrupt("return", saleRecipient);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function getSaleRecipient(_x8) {
|
|
return _getSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return getSaleRecipient;
|
|
}()
|
|
/**
|
|
* Get NFT Balance
|
|
*
|
|
* @remarks Get a wallets NFT balance (number of a specific NFT in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check NFT balance
|
|
* const address = "{{wallet_address}}";
|
|
* // The token ID of the NFT you want to check the wallets balance of
|
|
* const tokenId = "0"
|
|
*
|
|
* const balance = await module.balanceOf(address, tokenId);
|
|
* console.log(balance);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(address, tokenId) {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.readOnlyContract.balanceOf(address, tokenId);
|
|
|
|
case 2:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function balanceOf(_x9, _x10) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(tokenId) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.t0 = this;
|
|
_context12.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context12.t1 = _context12.sent;
|
|
_context12.t2 = tokenId;
|
|
_context12.next = 7;
|
|
return _context12.t0.balanceOf.call(_context12.t0, _context12.t1, _context12.t2);
|
|
|
|
case 7:
|
|
return _context12.abrupt("return", _context12.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function balance(_x11) {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(address, operator) {
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 2:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function isApproved(_x12, _x13) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
|
|
/*
|
|
*
|
|
* @deprecated - {@link BundleDropModule.mintBatch}
|
|
*/
|
|
;
|
|
|
|
_proto.lazyMintBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(metadatas) {
|
|
var _this5 = this;
|
|
|
|
var tokenIds;
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.next = 2;
|
|
return this.createBatch(metadatas);
|
|
|
|
case 2:
|
|
tokenIds = _context14.sent;
|
|
_context14.next = 5;
|
|
return Promise.all(tokenIds.map(function (t) {
|
|
return _this5.get(t.toString());
|
|
}));
|
|
|
|
case 5:
|
|
return _context14.abrupt("return", _context14.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function lazyMintBatch(_x14) {
|
|
return _lazyMintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMintBatch;
|
|
}()
|
|
/**
|
|
* Create Many NFTs
|
|
*
|
|
* @remarks Create and mint NFTs.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Custom metadata of the NFTs to create
|
|
* const metadatas = [{
|
|
* name: "Cool NFT",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* }, {
|
|
* name: "Cool NFT",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* }];
|
|
*
|
|
* await module.createBatch(metadatas);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.createBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(metadatas) {
|
|
var startFileNumber, _yield$this$sdk$getSt, baseUri, receipt, event, startingIndex, endingIndex, tokenIds, i;
|
|
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.next = 2;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 2:
|
|
startFileNumber = _context15.sent;
|
|
_context15.next = 5;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas, this.address, startFileNumber.toNumber());
|
|
|
|
case 5:
|
|
_yield$this$sdk$getSt = _context15.sent;
|
|
baseUri = _yield$this$sdk$getSt.baseUri;
|
|
_context15.next = 9;
|
|
return this.sendTransaction("lazyMint", [metadatas.length, "" + (baseUri.endsWith("/") ? baseUri : baseUri + "/")]);
|
|
|
|
case 9:
|
|
receipt = _context15.sent;
|
|
event = this.parseEventLogs("LazyMintedTokens", receipt == null ? void 0 : receipt.logs);
|
|
startingIndex = event[0], endingIndex = event[1];
|
|
tokenIds = [];
|
|
|
|
for (i = startingIndex; i.lte(endingIndex); i = i.add(1)) {
|
|
tokenIds.push(i.toString());
|
|
}
|
|
|
|
return _context15.abrupt("return", tokenIds);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function createBatch(_x15) {
|
|
return _createBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createBatch;
|
|
}();
|
|
|
|
_proto.setSaleRecipient = /*#__PURE__*/function () {
|
|
var _setSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(tokenId, recipient) {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
return _context16.abrupt("return", this.sendTransaction("setSaleRecipient", [tokenId, recipient]));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function setSaleRecipient(_x16, _x17) {
|
|
return _setSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return setSaleRecipient;
|
|
}();
|
|
|
|
_proto.setDefaultSaleRecipient = /*#__PURE__*/function () {
|
|
var _setDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(recipient) {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
return _context17.abrupt("return", this.sendTransaction("setDefaultSaleRecipient", [recipient]));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function setDefaultSaleRecipient(_x18) {
|
|
return _setDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return setDefaultSaleRecipient;
|
|
}();
|
|
|
|
_proto.setApproval = /*#__PURE__*/function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(operator, approved) {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context18.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function setApproval(_x19, _x20) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer NFT
|
|
*
|
|
* @remarks Transfer an NFT from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The token ID of the NFT you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* // The number of NFTs you want to send
|
|
* const amount = 1;
|
|
*
|
|
* await module.transfer(toAddress, tokenId, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(to, tokenId, amount, data) {
|
|
var from;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context19.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
from = _context19.sent;
|
|
_context19.next = 6;
|
|
return this.sendTransaction("safeTransferFrom", [from, to, tokenId, amount, data]);
|
|
|
|
case 6:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function transfer(_x21, _x22, _x23, _x24) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}()
|
|
/**
|
|
* Sets public claim conditions for the next minting using the
|
|
* claim condition factory.
|
|
*
|
|
* @param factory - The claim condition factory.
|
|
*/
|
|
;
|
|
|
|
_proto.setClaimCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(tokenId, factory) {
|
|
var conditions, merkleInfo, _yield$this$getMetada, metadata, oldMerkle, existingMerkle, _i, _Object$keys, key, encoded, metadataUri;
|
|
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.next = 2;
|
|
return factory.buildConditions();
|
|
|
|
case 2:
|
|
conditions = _context20.sent.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestamp,
|
|
maxClaimableSupply: c.maxMintSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeSecondsLimitPerTransaction,
|
|
pricePerToken: c.pricePerToken,
|
|
currency: c.currency === AddressZero ? NATIVE_TOKEN_ADDRESS : c.currency,
|
|
merkleRoot: c.merkleRoot
|
|
};
|
|
});
|
|
merkleInfo = {};
|
|
factory.allSnapshots().forEach(function (s) {
|
|
merkleInfo[s.merkleRoot] = s.snapshotUri;
|
|
});
|
|
_context20.next = 7;
|
|
return this.getMetadata(false);
|
|
|
|
case 7:
|
|
_yield$this$getMetada = _context20.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
!metadata ? process.env.NODE_ENV !== "production" ? invariant(false, "Metadata is not set, this should never happen") : invariant(false) : void 0;
|
|
oldMerkle = metadata["merkle"];
|
|
existingMerkle = "merkle" in metadata ? metadata.merkle : {};
|
|
|
|
for (_i = 0, _Object$keys = Object.keys(existingMerkle); _i < _Object$keys.length; _i++) {
|
|
key = _Object$keys[_i];
|
|
merkleInfo[key] = existingMerkle[key];
|
|
}
|
|
|
|
metadata["merkle"] = merkleInfo;
|
|
encoded = [];
|
|
|
|
if (isMetadataEqual(oldMerkle, metadata["merkle"])) {
|
|
_context20.next = 20;
|
|
break;
|
|
}
|
|
|
|
_context20.next = 18;
|
|
return this.sdk.getStorage().upload(JSON.stringify(metadata));
|
|
|
|
case 18:
|
|
metadataUri = _context20.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [metadataUri]));
|
|
|
|
case 20:
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setClaimConditions", [tokenId, conditions]));
|
|
_context20.next = 23;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 23:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function setClaimCondition(_x25, _x26) {
|
|
return _setClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return setClaimCondition;
|
|
}();
|
|
|
|
_proto.updateClaimConditions = /*#__PURE__*/function () {
|
|
var _updateClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(tokenId, factory) {
|
|
var conditions, merkleInfo, _yield$this$getMetada2, metadata, oldMerkle, existingMerkle, _i2, _Object$keys2, key, encoded, metadataUri;
|
|
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return factory.buildConditions();
|
|
|
|
case 2:
|
|
conditions = _context21.sent.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestamp,
|
|
maxClaimableSupply: c.maxMintSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeSecondsLimitPerTransaction,
|
|
pricePerToken: c.pricePerToken,
|
|
currency: c.currency === AddressZero ? NATIVE_TOKEN_ADDRESS : c.currency,
|
|
merkleRoot: c.merkleRoot
|
|
};
|
|
});
|
|
merkleInfo = {};
|
|
factory.allSnapshots().forEach(function (s) {
|
|
merkleInfo[s.merkleRoot] = s.snapshotUri;
|
|
});
|
|
_context21.next = 7;
|
|
return this.getMetadata(false);
|
|
|
|
case 7:
|
|
_yield$this$getMetada2 = _context21.sent;
|
|
metadata = _yield$this$getMetada2.metadata;
|
|
!metadata ? process.env.NODE_ENV !== "production" ? invariant(false, "Metadata is not set, this should never happen") : invariant(false) : void 0;
|
|
oldMerkle = metadata["merkle"];
|
|
existingMerkle = "merkle" in metadata ? metadata.merkle : {};
|
|
|
|
for (_i2 = 0, _Object$keys2 = Object.keys(existingMerkle); _i2 < _Object$keys2.length; _i2++) {
|
|
key = _Object$keys2[_i2];
|
|
merkleInfo[key] = existingMerkle[key];
|
|
}
|
|
|
|
metadata["merkle"] = merkleInfo;
|
|
encoded = [];
|
|
|
|
if (isMetadataEqual(oldMerkle, metadata["merkle"])) {
|
|
_context21.next = 20;
|
|
break;
|
|
}
|
|
|
|
_context21.next = 18;
|
|
return this.sdk.getStorage().upload(JSON.stringify(metadata));
|
|
|
|
case 18:
|
|
metadataUri = _context21.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [metadataUri]));
|
|
|
|
case 20:
|
|
encoded.push(this.contract["interface"].encodeFunctionData("updateClaimConditions", [tokenId, conditions]));
|
|
_context21.next = 23;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 23:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function updateClaimConditions(_x27, _x28) {
|
|
return _updateClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return updateClaimConditions;
|
|
}()
|
|
/**
|
|
* Creates a claim condition factory
|
|
*
|
|
* @returns - A new claim condition factory
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimConditionFactory = function getClaimConditionFactory() {
|
|
var createSnapshotFunc = this.sdk.createSnapshot.bind(this.sdk);
|
|
var factory = new ClaimConditionFactory(createSnapshotFunc);
|
|
return factory;
|
|
}
|
|
/**
|
|
* @deprecated - Use the ClaimConditionFactory instead.
|
|
*/
|
|
;
|
|
|
|
_proto.setPublicClaimConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setPublicClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(tokenId, conditions) {
|
|
var _conditions;
|
|
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_conditions = conditions.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestamp || 0,
|
|
maxClaimableSupply: c.maxClaimableSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction || c.maxClaimableSupply,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeInSecondsBetweenClaims || 0,
|
|
pricePerToken: c.pricePerToken || 0,
|
|
currency: c.currency || AddressZero,
|
|
merkleRoot: c.merkleRoot || hexZeroPad([0], 32)
|
|
};
|
|
});
|
|
_context22.next = 3;
|
|
return this.sendTransaction("setClaimConditions", [tokenId, _conditions]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setPublicClaimConditions(_x29, _x30) {
|
|
return _setPublicClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return setPublicClaimConditions;
|
|
}()
|
|
/**
|
|
* Returns proofs and the overrides required for the transaction.
|
|
*
|
|
* @returns - `overrides` and `proofs` as an object.
|
|
*/
|
|
;
|
|
|
|
_proto.prepareClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _prepareClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(tokenId, quantity, proofs) {
|
|
var mintCondition, overrides, addressToClaim, _yield$this$getMetada3, metadata, snapshot, jsonConvert, snapshotData, item, erc20, owner, spender, allowance, totalPrice;
|
|
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context23.next = 3;
|
|
return this.getActiveClaimCondition(tokenId);
|
|
|
|
case 3:
|
|
mintCondition = _context23.sent;
|
|
_context23.next = 6;
|
|
return this.getCallOverrides();
|
|
|
|
case 6:
|
|
_context23.t0 = _context23.sent;
|
|
|
|
if (_context23.t0) {
|
|
_context23.next = 9;
|
|
break;
|
|
}
|
|
|
|
_context23.t0 = {};
|
|
|
|
case 9:
|
|
overrides = _context23.t0;
|
|
_context23.next = 12;
|
|
return this.getSignerAddress();
|
|
|
|
case 12:
|
|
addressToClaim = _context23.sent;
|
|
_context23.next = 15;
|
|
return this.getMetadata();
|
|
|
|
case 15:
|
|
_yield$this$getMetada3 = _context23.sent;
|
|
metadata = _yield$this$getMetada3.metadata;
|
|
|
|
if (mintCondition.merkleRoot.toString().startsWith(AddressZero)) {
|
|
_context23.next = 27;
|
|
break;
|
|
}
|
|
|
|
_context23.next = 20;
|
|
return this.sdk.getStorage().get(metadata == null ? void 0 : metadata.merkle[mintCondition.merkleRoot.toString()]);
|
|
|
|
case 20:
|
|
snapshot = _context23.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
return c.address.toLowerCase() === (addressToClaim == null ? void 0 : addressToClaim.toLowerCase());
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context23.next = 26;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No claim found for this address");
|
|
|
|
case 26:
|
|
proofs = item.proof;
|
|
|
|
case 27:
|
|
if (!mintCondition.pricePerToken.gt(0)) {
|
|
_context23.next = 44;
|
|
break;
|
|
}
|
|
|
|
if (!isNativeToken(mintCondition.currency)) {
|
|
_context23.next = 32;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = BigNumber.from(mintCondition.pricePerToken).mul(quantity);
|
|
_context23.next = 44;
|
|
break;
|
|
|
|
case 32:
|
|
erc20 = ERC20__factory.connect(mintCondition.currency, this.providerOrSigner);
|
|
_context23.next = 35;
|
|
return this.getSignerAddress();
|
|
|
|
case 35:
|
|
owner = _context23.sent;
|
|
spender = this.address;
|
|
_context23.next = 39;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 39:
|
|
allowance = _context23.sent;
|
|
totalPrice = BigNumber.from(mintCondition.pricePerToken).mul(BigNumber.from(quantity));
|
|
|
|
if (!allowance.lt(totalPrice)) {
|
|
_context23.next = 44;
|
|
break;
|
|
}
|
|
|
|
_context23.next = 44;
|
|
return this.sendContractTransaction(erc20, "approve", [spender, allowance.add(totalPrice)]);
|
|
|
|
case 44:
|
|
return _context23.abrupt("return", {
|
|
overrides: overrides,
|
|
proofs: proofs
|
|
});
|
|
|
|
case 45:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function prepareClaim(_x31, _x32, _x33) {
|
|
return _prepareClaim.apply(this, arguments);
|
|
}
|
|
|
|
return prepareClaim;
|
|
}()
|
|
/**
|
|
* Claim a token to yourself
|
|
*
|
|
* @param tokenId - Id of the token you want to claim
|
|
* @param quantity - Quantity of the tokens you want to claim
|
|
* @param proofs - Array of proofs
|
|
*
|
|
* @returns - Receipt for the transaction
|
|
*/
|
|
;
|
|
|
|
_proto.claim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(tokenId, quantity, proofs) {
|
|
var claimData;
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context24.next = 3;
|
|
return this.prepareClaim(tokenId, quantity, proofs);
|
|
|
|
case 3:
|
|
claimData = _context24.sent;
|
|
_context24.next = 6;
|
|
return this.isNewClaim();
|
|
|
|
case 6:
|
|
if (!_context24.sent) {
|
|
_context24.next = 21;
|
|
break;
|
|
}
|
|
|
|
_context24.t0 = this;
|
|
_context24.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
_context24.t1 = _context24.sent;
|
|
_context24.t2 = tokenId;
|
|
_context24.t3 = quantity;
|
|
_context24.t4 = claimData.proofs;
|
|
_context24.t5 = [_context24.t1, _context24.t2, _context24.t3, _context24.t4];
|
|
_context24.t6 = claimData.overrides;
|
|
_context24.next = 18;
|
|
return _context24.t0.sendTransaction.call(_context24.t0, "claim", _context24.t5, _context24.t6);
|
|
|
|
case 18:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 21:
|
|
_context24.next = 23;
|
|
return this.sendContractTransaction(new Contract$1(this.address, OLD_CLAIM_ABI, this.providerOrSigner), "claim", [tokenId, quantity, claimData.proofs], claimData.overrides);
|
|
|
|
case 23:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function claim(_x34, _x35, _x36) {
|
|
return _claim.apply(this, arguments);
|
|
}
|
|
|
|
return claim;
|
|
}()
|
|
/**
|
|
* Claim NFTs to Wallet
|
|
*
|
|
* @remarks Let the a specified wallet claim NFTs.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to claim the NFTs
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* // The number of NFTs to claim
|
|
* const quantity = 1;
|
|
*
|
|
* // The token ID of the NFT you want to claim
|
|
* const tokenId = "0"
|
|
*
|
|
* await module.claimTo(tokenId, quantity, address);
|
|
* ```
|
|
*
|
|
* @param tokenId - Id of the token you want to claim
|
|
* @param quantity - Quantity of the tokens you want to claim
|
|
* @param addressToClaim - Address you want to send the token to
|
|
* @param proofs - Array of proofs
|
|
*
|
|
* @returns - Receipt for the transaction
|
|
*/
|
|
;
|
|
|
|
_proto.claimTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _claimTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(tokenId, quantity, addressToClaim, proofs) {
|
|
var claimData, encoded;
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context25.next = 3;
|
|
return this.prepareClaim(tokenId, quantity, proofs);
|
|
|
|
case 3:
|
|
claimData = _context25.sent;
|
|
_context25.next = 6;
|
|
return this.isNewClaim();
|
|
|
|
case 6:
|
|
if (!_context25.sent) {
|
|
_context25.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context25.next = 9;
|
|
return this.sendTransaction("claim", [addressToClaim, tokenId, quantity, claimData.proofs], claimData.overrides);
|
|
|
|
case 9:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 10:
|
|
encoded = []; // forcing it old version of claim params
|
|
|
|
encoded.push(new Contract$1(this.address, OLD_CLAIM_ABI, this.providerOrSigner)["interface"].encodeFunctionData("claim", [tokenId, quantity, claimData.proofs]));
|
|
_context25.t0 = encoded;
|
|
_context25.t1 = this.contract["interface"];
|
|
_context25.next = 16;
|
|
return this.getSignerAddress();
|
|
|
|
case 16:
|
|
_context25.t2 = _context25.sent;
|
|
_context25.t3 = addressToClaim;
|
|
_context25.t4 = tokenId;
|
|
_context25.t5 = quantity;
|
|
_context25.t6 = [0];
|
|
_context25.t7 = [_context25.t2, _context25.t3, _context25.t4, _context25.t5, _context25.t6];
|
|
_context25.t8 = _context25.t1.encodeFunctionData.call(_context25.t1, "safeTransferFrom", _context25.t7);
|
|
|
|
_context25.t0.push.call(_context25.t0, _context25.t8);
|
|
|
|
_context25.next = 26;
|
|
return this.sendTransaction("multicall", [encoded], claimData.overrides);
|
|
|
|
case 26:
|
|
return _context25.abrupt("return", _context25.sent);
|
|
|
|
case 27:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function claimTo(_x37, _x38, _x39, _x40) {
|
|
return _claimTo.apply(this, arguments);
|
|
}
|
|
|
|
return claimTo;
|
|
}();
|
|
|
|
_proto.burn = /*#__PURE__*/function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(tokenId, amount) {
|
|
var account;
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return this.getSignerAddress();
|
|
|
|
case 2:
|
|
account = _context26.sent;
|
|
_context26.next = 5;
|
|
return this.sendTransaction("burn", [account, tokenId, amount]);
|
|
|
|
case 5:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function burn(_x41, _x42) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(from, to, tokenId, amount, data) {
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context27.next = 3;
|
|
return this.sendTransaction("safeTransferFrom", [from, to, tokenId, amount, data]);
|
|
|
|
case 3:
|
|
return _context27.abrupt("return", _context27.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function transferFrom(_x43, _x44, _x45, _x46, _x47) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.setModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context28.sent;
|
|
_context28.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context28.abrupt("return", _context28.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x48) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(amount) {
|
|
var _yield$this$getMetada4, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
_context29.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada4 = _context29.sent;
|
|
metadata = _yield$this$getMetada4.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context29.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context29.t0 = this.sdk.getStorage();
|
|
_context29.t1 = _extends({}, metadata);
|
|
_context29.t2 = this.address;
|
|
_context29.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context29.t3 = _context29.sent;
|
|
_context29.next = 16;
|
|
return _context29.t0.uploadMetadata.call(_context29.t0, _context29.t1, _context29.t2, _context29.t3);
|
|
|
|
case 16:
|
|
uri = _context29.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context29.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context29.abrupt("return", _context29.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x49) {
|
|
return _setRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30() {
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
_context30.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context30.abrupt("return", _context30.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31() {
|
|
var _metadata$metadata;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
_context31.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context31.sent;
|
|
|
|
if (!(((_metadata$metadata = metadata.metadata) == null ? void 0 : _metadata$metadata.fee_recipient) !== undefined)) {
|
|
_context31.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context31.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context31.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}();
|
|
|
|
_proto.getClaimConditionsFactory = function getClaimConditionsFactory() {
|
|
var createSnapshotFunc = this.sdk.createSnapshot.bind(this.sdk);
|
|
var factory = new ClaimConditionFactory(createSnapshotFunc);
|
|
return factory;
|
|
}
|
|
/**
|
|
* Returns the total supply of a specific token
|
|
*
|
|
* @param tokenId - The token ID to get the total supply of
|
|
*/
|
|
;
|
|
|
|
_proto.totalSupply =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _totalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(tokenId) {
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
_context32.next = 2;
|
|
return this.readOnlyContract.totalSupply(tokenId);
|
|
|
|
case 2:
|
|
return _context32.abrupt("return", _context32.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function totalSupply(_x50) {
|
|
return _totalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalSupply;
|
|
}()
|
|
/**
|
|
* Pulls the list of all addresses that have claimed a particular token
|
|
*
|
|
* @beta - This can be very slow for large numbers of token holders
|
|
*
|
|
* @param tokenId - The token id to get the claimers of
|
|
* @returns - A unique list of addresses that claimed the token
|
|
*/
|
|
;
|
|
|
|
_proto.getAllClaimerAddresses =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllClaimerAddresses = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(tokenId) {
|
|
var a;
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
_context33.next = 2;
|
|
return this.contract.queryFilter(this.contract.filters.ClaimedTokens(null, BigNumber.from(tokenId)));
|
|
|
|
case 2:
|
|
a = _context33.sent;
|
|
return _context33.abrupt("return", Array.from(new Set(a.map(function (b) {
|
|
return b.args.claimer;
|
|
}))));
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function getAllClaimerAddresses(_x51) {
|
|
return _getAllClaimerAddresses.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimerAddresses;
|
|
}()
|
|
/**
|
|
* For any claim conditions that a particular wallet is violating,
|
|
* this function returns human readable information about the
|
|
* breaks in the condition that can be used to inform the user.
|
|
*
|
|
* @param tokenId - The token id that would be claimed.
|
|
* @param quantity - The desired quantity that would be claimed.
|
|
* @param addressToCheck - The address that would be claiming the token.
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimIneligibilityReasons =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getClaimIneligibilityReasons = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(tokenId, quantity, addressToCheck) {
|
|
var reasons, activeConditionIndex, claimCondition, _yield$Promise$all2, merkleRootArray, merkleLower, proofs, hashedAddress, timestampForNextClaim, now, balance, totalPrice, provider, _balance2, _provider, _balance3;
|
|
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
reasons = [];
|
|
|
|
if (!(addressToCheck === undefined)) {
|
|
_context34.next = 3;
|
|
break;
|
|
}
|
|
|
|
throw new Error("addressToCheck is required");
|
|
|
|
case 3:
|
|
_context34.prev = 3;
|
|
_context34.next = 6;
|
|
return Promise.all([this.readOnlyContract.getIndexOfActiveCondition(tokenId), this.getActiveClaimCondition(tokenId)]);
|
|
|
|
case 6:
|
|
_yield$Promise$all2 = _context34.sent;
|
|
activeConditionIndex = _yield$Promise$all2[0];
|
|
claimCondition = _yield$Promise$all2[1];
|
|
_context34.next = 18;
|
|
break;
|
|
|
|
case 11:
|
|
_context34.prev = 11;
|
|
_context34.t0 = _context34["catch"](3);
|
|
|
|
if (!_context34.t0.message.includes("no public mint condition.")) {
|
|
_context34.next = 16;
|
|
break;
|
|
}
|
|
|
|
reasons.push(ClaimEligibility.NoActiveClaimPhase);
|
|
return _context34.abrupt("return", reasons);
|
|
|
|
case 16:
|
|
console.error("Failed to get active claim condition", _context34.t0);
|
|
throw new Error("Failed to get active claim condition");
|
|
|
|
case 18:
|
|
if (BigNumber.from(claimCondition.availableSupply).lt(quantity)) {
|
|
reasons.push(ClaimEligibility.NotEnoughSupply);
|
|
} // check for merkle root inclusion
|
|
|
|
|
|
merkleRootArray = ethers.utils.stripZeros(claimCondition.merkleRoot);
|
|
|
|
if (!(merkleRootArray.length > 0)) {
|
|
_context34.next = 26;
|
|
break;
|
|
}
|
|
|
|
merkleLower = claimCondition.merkleRoot.toString();
|
|
_context34.next = 24;
|
|
return this.getClaimerProofs(merkleLower, addressToCheck);
|
|
|
|
case 24:
|
|
proofs = _context34.sent;
|
|
|
|
if (proofs.length === 0) {
|
|
hashedAddress = ethers.utils.keccak256(addressToCheck).toLowerCase();
|
|
|
|
if (hashedAddress !== merkleLower) {
|
|
reasons.push(ClaimEligibility.AddressNotAllowed);
|
|
}
|
|
} // TODO: compute proofs to root, need browser compatibility
|
|
|
|
|
|
case 26:
|
|
_context34.next = 28;
|
|
return this.readOnlyContract.getTimestampForNextValidClaim(tokenId, activeConditionIndex, addressToCheck);
|
|
|
|
case 28:
|
|
timestampForNextClaim = _context34.sent;
|
|
now = BigNumber.from(Date.now()).div(1000);
|
|
|
|
if (!now.lt(timestampForNextClaim)) {
|
|
_context34.next = 39;
|
|
break;
|
|
}
|
|
|
|
if (!BigNumber.from(claimCondition.waitTimeSecondsLimitPerTransaction).eq(timestampForNextClaim)) {
|
|
_context34.next = 38;
|
|
break;
|
|
}
|
|
|
|
_context34.next = 34;
|
|
return this.readOnlyContract.balanceOf(addressToCheck, tokenId);
|
|
|
|
case 34:
|
|
balance = _context34.sent;
|
|
|
|
if (balance.gte(1)) {
|
|
reasons.push(ClaimEligibility.AlreadyClaimed);
|
|
}
|
|
|
|
_context34.next = 39;
|
|
break;
|
|
|
|
case 38:
|
|
reasons.push(ClaimEligibility.WaitBeforeNextClaimTransaction);
|
|
|
|
case 39:
|
|
if (!claimCondition.pricePerToken.gt(0)) {
|
|
_context34.next = 58;
|
|
break;
|
|
}
|
|
|
|
totalPrice = claimCondition.pricePerToken.mul(quantity);
|
|
|
|
if (!isNativeToken(claimCondition.currency)) {
|
|
_context34.next = 51;
|
|
break;
|
|
}
|
|
|
|
_context34.next = 44;
|
|
return this.getProvider();
|
|
|
|
case 44:
|
|
provider = _context34.sent;
|
|
_context34.next = 47;
|
|
return provider.getBalance(addressToCheck);
|
|
|
|
case 47:
|
|
_balance2 = _context34.sent;
|
|
|
|
if (_balance2.lt(totalPrice)) {
|
|
reasons.push(ClaimEligibility.NotEnoughTokens);
|
|
}
|
|
|
|
_context34.next = 58;
|
|
break;
|
|
|
|
case 51:
|
|
_context34.next = 53;
|
|
return this.getProvider();
|
|
|
|
case 53:
|
|
_provider = _context34.sent;
|
|
_context34.next = 56;
|
|
return ERC20__factory.connect(claimCondition.currency, _provider).balanceOf(addressToCheck);
|
|
|
|
case 56:
|
|
_balance3 = _context34.sent;
|
|
|
|
if (_balance3.lt(totalPrice)) {
|
|
reasons.push(ClaimEligibility.NotEnoughTokens);
|
|
}
|
|
|
|
case 58:
|
|
return _context34.abrupt("return", reasons);
|
|
|
|
case 59:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this, [[3, 11]]);
|
|
}));
|
|
|
|
function getClaimIneligibilityReasons(_x52, _x53, _x54) {
|
|
return _getClaimIneligibilityReasons.apply(this, arguments);
|
|
}
|
|
|
|
return getClaimIneligibilityReasons;
|
|
}()
|
|
/*
|
|
* Checks to see if the current signer can claim the specified number of tokens.
|
|
*
|
|
* @param tokenId - The id of the token to check.
|
|
* @param quantity - The quantity of tokens to check.
|
|
* @param addressToCheck - The wallet address to check.
|
|
* @returns - True if the current signer can claim the specified number of tokens, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto.canClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _canClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(tokenId, quantity, addressToCheck) {
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
if (addressToCheck) {
|
|
_context35.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context35.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
addressToCheck = _context35.sent;
|
|
|
|
case 4:
|
|
_context35.next = 6;
|
|
return this.getClaimIneligibilityReasons(tokenId, quantity, addressToCheck);
|
|
|
|
case 6:
|
|
_context35.t0 = _context35.sent.length;
|
|
return _context35.abrupt("return", _context35.t0 === 0);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35, this);
|
|
}));
|
|
|
|
function canClaim(_x55, _x56, _x57) {
|
|
return _canClaim.apply(this, arguments);
|
|
}
|
|
|
|
return canClaim;
|
|
}()
|
|
/**
|
|
* Fetches the proof for the current signer for a particular wallet.
|
|
*
|
|
* @param merkleRoot - The merkle root of the condition to check.
|
|
* @returns - The proof for the current signer for the specified condition.
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimerProofs =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getClaimerProofs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee36(merkleRoot, addressToClaim) {
|
|
var _yield$this$getMetada5, metadata, snapshot, jsonConvert, snapshotData, item;
|
|
|
|
return runtime_1.wrap(function _callee36$(_context36) {
|
|
while (1) {
|
|
switch (_context36.prev = _context36.next) {
|
|
case 0:
|
|
if (addressToClaim) {
|
|
_context36.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context36.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
addressToClaim = _context36.sent;
|
|
|
|
case 4:
|
|
_context36.next = 6;
|
|
return this.getMetadata();
|
|
|
|
case 6:
|
|
_yield$this$getMetada5 = _context36.sent;
|
|
metadata = _yield$this$getMetada5.metadata;
|
|
_context36.next = 10;
|
|
return this.sdk.getStorage().get(metadata == null ? void 0 : metadata.merkle[merkleRoot]);
|
|
|
|
case 10:
|
|
snapshot = _context36.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
var _addressToClaim;
|
|
|
|
return c.address.toLowerCase() === ((_addressToClaim = addressToClaim) == null ? void 0 : _addressToClaim.toLowerCase());
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context36.next = 16;
|
|
break;
|
|
}
|
|
|
|
return _context36.abrupt("return", []);
|
|
|
|
case 16:
|
|
return _context36.abrupt("return", item.proof);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context36.stop();
|
|
}
|
|
}
|
|
}, _callee36, this);
|
|
}));
|
|
|
|
function getClaimerProofs(_x58, _x59) {
|
|
return _getClaimerProofs.apply(this, arguments);
|
|
}
|
|
|
|
return getClaimerProofs;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee37() {
|
|
return runtime_1.wrap(function _callee37$(_context37) {
|
|
while (1) {
|
|
switch (_context37.prev = _context37.next) {
|
|
case 0:
|
|
return _context37.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context37.stop();
|
|
}
|
|
}
|
|
}, _callee37, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee38(restricted) {
|
|
return runtime_1.wrap(function _callee38$(_context38) {
|
|
while (1) {
|
|
switch (_context38.prev = _context38.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context38.t0 = this;
|
|
_context38.t1 = ["admin"];
|
|
_context38.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context38.t2 = _context38.sent;
|
|
_context38.next = 8;
|
|
return _context38.t0.onlyRoles.call(_context38.t0, _context38.t1, _context38.t2);
|
|
|
|
case 8:
|
|
_context38.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context38.abrupt("return", _context38.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context38.stop();
|
|
}
|
|
}
|
|
}, _callee38, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x60) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isNewClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isNewClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee39() {
|
|
return runtime_1.wrap(function _callee39$(_context39) {
|
|
while (1) {
|
|
switch (_context39.prev = _context39.next) {
|
|
case 0:
|
|
_context39.next = 2;
|
|
return this.checkVersion();
|
|
|
|
case 2:
|
|
return _context39.abrupt("return", this._isNewClaim);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context39.stop();
|
|
}
|
|
}
|
|
}, _callee39, this);
|
|
}));
|
|
|
|
function isNewClaim() {
|
|
return _isNewClaim.apply(this, arguments);
|
|
}
|
|
|
|
return isNewClaim;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.checkVersion =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _checkVersion = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee40() {
|
|
return runtime_1.wrap(function _callee40$(_context40) {
|
|
while (1) {
|
|
switch (_context40.prev = _context40.next) {
|
|
case 0:
|
|
if (!this._shouldCheckVersion) {
|
|
_context40.next = 11;
|
|
break;
|
|
}
|
|
|
|
_context40.prev = 1;
|
|
_context40.next = 4;
|
|
return this.readOnlyContract.VERSION();
|
|
|
|
case 4:
|
|
this._isNewClaim = true;
|
|
_context40.next = 10;
|
|
break;
|
|
|
|
case 7:
|
|
_context40.prev = 7;
|
|
_context40.t0 = _context40["catch"](1);
|
|
this._isNewClaim = false;
|
|
|
|
case 10:
|
|
this._shouldCheckVersion = false;
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context40.stop();
|
|
}
|
|
}
|
|
}, _callee40, this, [[1, 7]]);
|
|
}));
|
|
|
|
function checkVersion() {
|
|
return _checkVersion.apply(this, arguments);
|
|
}
|
|
|
|
return checkVersion;
|
|
}();
|
|
|
|
return BundleDropModule;
|
|
}(ModuleWithRoles);
|
|
BundleDropModule.moduleType = ModuleType.BUNDLE_DROP;
|
|
BundleDropModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.transfer];
|
|
|
|
/**
|
|
* Access this module by calling {@link ThirdwebSDK.getDatastoreModule}
|
|
* @alpha
|
|
*/
|
|
|
|
var DatastoreModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(DatastoreModule, _ModuleWithRoles);
|
|
|
|
function DatastoreModule() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = DatastoreModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return DatastoreModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return DataStore__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return DatastoreModule.moduleType;
|
|
};
|
|
|
|
_proto.getUint = /*#__PURE__*/function () {
|
|
var _getUint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(key) {
|
|
var keyHash;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
keyHash = ethers.utils.id(key.toString());
|
|
_context.next = 3;
|
|
return this.readOnlyContract.getUint(keyHash);
|
|
|
|
case 3:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function getUint(_x) {
|
|
return _getUint.apply(this, arguments);
|
|
}
|
|
|
|
return getUint;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.setUint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setUint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(key, value) {
|
|
var keyHash;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
keyHash = ethers.utils.id(key.toString());
|
|
_context2.next = 3;
|
|
return this.sendTransaction("setUint", [keyHash, value]);
|
|
|
|
case 3:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function setUint(_x2, _x3) {
|
|
return _setUint.apply(this, arguments);
|
|
}
|
|
|
|
return setUint;
|
|
}();
|
|
|
|
return DatastoreModule;
|
|
}(ModuleWithRoles);
|
|
DatastoreModule.moduleType = ModuleType.DATASTORE;
|
|
DatastoreModule.roles = [RolesMap.admin, RolesMap.editor];
|
|
|
|
var DEFAULT_QUERY_ALL_COUNT = 100;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var ABI_V1_22_0 = [{
|
|
anonymous: false,
|
|
inputs: [{
|
|
indexed: true,
|
|
internalType: "uint256",
|
|
name: "claimConditionIndex",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: true,
|
|
internalType: "address",
|
|
name: "claimer",
|
|
type: "address"
|
|
}, {
|
|
indexed: false,
|
|
internalType: "uint256",
|
|
name: "startTokenId",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: false,
|
|
internalType: "uint256",
|
|
name: "quantityClaimed",
|
|
type: "uint256"
|
|
}],
|
|
name: "ClaimedTokens",
|
|
type: "event"
|
|
}, {
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "_quantity",
|
|
type: "uint256"
|
|
}, {
|
|
internalType: "bytes32[]",
|
|
name: "_proofs",
|
|
type: "bytes32[]"
|
|
}],
|
|
name: "claim",
|
|
outputs: [],
|
|
stateMutability: "payable",
|
|
type: "function"
|
|
}];
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
var ABI_V1_24_0 = [{
|
|
anonymous: false,
|
|
inputs: [{
|
|
indexed: false,
|
|
internalType: "uint256",
|
|
name: "startTokenId",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: false,
|
|
internalType: "uint256",
|
|
name: "endTokenId",
|
|
type: "uint256"
|
|
}, {
|
|
indexed: false,
|
|
internalType: "string",
|
|
name: "baseURI",
|
|
type: "string"
|
|
}],
|
|
name: "LazyMintedTokens",
|
|
type: "event"
|
|
}, {
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "_amount",
|
|
type: "uint256"
|
|
}, {
|
|
internalType: "string",
|
|
name: "_baseURIForTokens",
|
|
type: "string"
|
|
}],
|
|
name: "lazyMint",
|
|
outputs: [],
|
|
stateMutability: "nonpayable",
|
|
type: "function"
|
|
}];
|
|
/**
|
|
* Setup a collection of one-of-one NFTs that are minted as users claim them.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getDropModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var DropModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(DropModule, _ModuleWithRoles);
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
function DropModule(providerOrSigner, address, options, sdk) {
|
|
var _this;
|
|
|
|
_this = _ModuleWithRoles.call(this, providerOrSigner, address, options, sdk) || this;
|
|
_this._shouldCheckVersion = true;
|
|
_this._isV0 = false;
|
|
_this._version = 0;
|
|
_this.v1Module = void 0;
|
|
_this.v1Module = new DropV1Module(providerOrSigner, address, options, sdk);
|
|
return _this;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
|
|
|
|
var _proto = DropModule.prototype;
|
|
|
|
_proto.setProviderOrSigner = function setProviderOrSigner(providerOrSigner) {
|
|
var _this$v1Module;
|
|
|
|
_ModuleWithRoles.prototype.setProviderOrSigner.call(this, providerOrSigner);
|
|
|
|
(_this$v1Module = this.v1Module) == null ? void 0 : _this$v1Module.setProviderOrSigner(providerOrSigner);
|
|
}
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return DropModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return LazyMintERC721__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return DropModule.moduleType;
|
|
};
|
|
|
|
_proto.getTokenMetadata = /*#__PURE__*/function () {
|
|
var _getTokenMetadata2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tokenId) {
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return getTokenMetadata(this.readOnlyContract, tokenId, this.sdk.getStorage());
|
|
|
|
case 2:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function getTokenMetadata$1(_x) {
|
|
return _getTokenMetadata2.apply(this, arguments);
|
|
}
|
|
|
|
return getTokenMetadata$1;
|
|
}();
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tokenId) {
|
|
var _yield$Promise$all, owner, metadata;
|
|
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return Promise.all([this.ownerOf(tokenId)["catch"](function () {
|
|
return AddressZero;
|
|
}), this.getTokenMetadata(tokenId)]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context2.sent;
|
|
owner = _yield$Promise$all[0];
|
|
metadata = _yield$Promise$all[1];
|
|
return _context2.abrupt("return", {
|
|
owner: owner,
|
|
metadata: metadata
|
|
});
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function get(_x2) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get All NFTs
|
|
*
|
|
* @remarks Get all the data associated with every NFT in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* const nfts = await module.getAll();
|
|
* console.log(nfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(queryParams) {
|
|
var _this2 = this;
|
|
|
|
var start, count, maxId;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context3.sent) {
|
|
_context3.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context3.abrupt("return", this.v1Module.getAll(queryParams));
|
|
|
|
case 4:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context3.t0 = Math;
|
|
_context3.next = 9;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 9:
|
|
_context3.t1 = _context3.sent.toNumber();
|
|
_context3.t2 = start + count;
|
|
maxId = _context3.t0.min.call(_context3.t0, _context3.t1, _context3.t2);
|
|
_context3.next = 14;
|
|
return Promise.all(Array.from(Array(maxId - start).keys()).map(function (i) {
|
|
return _this2.get((start + i).toString());
|
|
}));
|
|
|
|
case 14:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getAll(_x3) {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}();
|
|
|
|
_proto.getAllUnclaimed = /*#__PURE__*/function () {
|
|
var _getAllUnclaimed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(queryParams) {
|
|
var _this3 = this;
|
|
|
|
var start, count, maxId, unmintedId;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context4.sent) {
|
|
_context4.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context4.abrupt("return", this.v1Module.getAllUnclaimed());
|
|
|
|
case 4:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context4.t0 = BigNumber;
|
|
_context4.t1 = Math;
|
|
_context4.next = 10;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 10:
|
|
_context4.t2 = _context4.sent.toNumber();
|
|
_context4.t3 = start + count;
|
|
_context4.t4 = _context4.t1.min.call(_context4.t1, _context4.t2, _context4.t3);
|
|
maxId = _context4.t0.from.call(_context4.t0, _context4.t4);
|
|
_context4.next = 16;
|
|
return this.readOnlyContract.nextTokenIdToClaim();
|
|
|
|
case 16:
|
|
unmintedId = _context4.sent;
|
|
_context4.next = 19;
|
|
return Promise.all(Array.from(Array(maxId.sub(unmintedId).toNumber()).keys()).map(function (i) {
|
|
return _this3.getTokenMetadata(unmintedId.add(i).toString());
|
|
}));
|
|
|
|
case 19:
|
|
return _context4.abrupt("return", _context4.sent.map(function (metadata) {
|
|
return {
|
|
owner: AddressZero,
|
|
metadata: metadata
|
|
};
|
|
}));
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getAllUnclaimed(_x4) {
|
|
return _getAllUnclaimed.apply(this, arguments);
|
|
}
|
|
|
|
return getAllUnclaimed;
|
|
}();
|
|
|
|
_proto.getAllClaimed = /*#__PURE__*/function () {
|
|
var _getAllClaimed = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(queryParams) {
|
|
var _this4 = this;
|
|
|
|
var start, count, maxId;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context5.sent) {
|
|
_context5.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context5.abrupt("return", this.v1Module.getAllClaimed());
|
|
|
|
case 4:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context5.t0 = Math;
|
|
_context5.next = 9;
|
|
return this.readOnlyContract.nextTokenIdToClaim();
|
|
|
|
case 9:
|
|
_context5.t1 = _context5.sent.toNumber();
|
|
_context5.t2 = start + count;
|
|
maxId = _context5.t0.min.call(_context5.t0, _context5.t1, _context5.t2);
|
|
_context5.next = 14;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this4.get(i.toString());
|
|
}));
|
|
|
|
case 14:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getAllClaimed(_x5) {
|
|
return _getAllClaimed.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimed;
|
|
}();
|
|
|
|
_proto.ownerOf = /*#__PURE__*/function () {
|
|
var _ownerOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(tokenId) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.next = 2;
|
|
return this.readOnlyContract.ownerOf(tokenId);
|
|
|
|
case 2:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function ownerOf(_x6) {
|
|
return _ownerOf.apply(this, arguments);
|
|
}
|
|
|
|
return ownerOf;
|
|
}();
|
|
|
|
_proto.getDefaultSaleRecipient = /*#__PURE__*/function () {
|
|
var _getDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7() {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.readOnlyContract.defaultSaleRecipient();
|
|
|
|
case 2:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getDefaultSaleRecipient() {
|
|
return _getDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return getDefaultSaleRecipient;
|
|
}();
|
|
|
|
_proto.setDefaultSaleRecipient = /*#__PURE__*/function () {
|
|
var _setDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(recipient) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.sendTransaction("setDefaultSaleRecipient", [recipient]);
|
|
|
|
case 2:
|
|
return _context8.abrupt("return", _context8.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function setDefaultSaleRecipient(_x7) {
|
|
return _setDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return setDefaultSaleRecipient;
|
|
}()
|
|
/**
|
|
* Get Owned NFTs
|
|
*
|
|
* @remarks Get all the data associated with the NFTs owned by a specific wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to get the NFTs of
|
|
* const address = "{{wallet_address}}";
|
|
* const nfts = await module.getOwned(address);
|
|
* console.log(nfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(_address) {
|
|
var _this5 = this;
|
|
|
|
var address, balance, indices, tokenIds;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context9.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context9.t0 = _address;
|
|
_context9.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context9.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context9.t0 = _context9.sent;
|
|
|
|
case 7:
|
|
address = _context9.t0;
|
|
_context9.next = 10;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 10:
|
|
balance = _context9.sent;
|
|
indices = Array.from(Array(balance.toNumber()).keys());
|
|
_context9.next = 14;
|
|
return Promise.all(indices.map(function (i) {
|
|
return _this5.readOnlyContract.tokenOfOwnerByIndex(address, i);
|
|
}));
|
|
|
|
case 14:
|
|
tokenIds = _context9.sent;
|
|
_context9.next = 17;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this5.get(tokenId.toString());
|
|
}));
|
|
|
|
case 17:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function getOwned(_x8) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}()
|
|
/**
|
|
* @deprecated - For backward compatibility reason
|
|
*/
|
|
;
|
|
|
|
_proto.transformResultToMintCondition = function transformResultToMintCondition(pm) {
|
|
return {
|
|
startTimestamp: pm.startTimestamp,
|
|
maxMintSupply: pm.maxClaimableSupply,
|
|
currentMintSupply: pm.supplyClaimed,
|
|
quantityLimitPerTransaction: pm.quantityLimitPerTransaction,
|
|
waitTimeSecondsLimitPerTransaction: pm.waitTimeInSecondsBetweenClaims,
|
|
pricePerToken: pm.pricePerToken,
|
|
currency: pm.currency,
|
|
merkleRoot: pm.merkleRoot
|
|
};
|
|
};
|
|
|
|
_proto.transformResultToClaimCondition = /*#__PURE__*/function () {
|
|
var _transformResultToClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(pm) {
|
|
var cv;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.next = 2;
|
|
return getCurrencyValue(this.providerOrSigner, pm.currency, pm.pricePerToken);
|
|
|
|
case 2:
|
|
cv = _context10.sent;
|
|
return _context10.abrupt("return", {
|
|
startTimestamp: new Date(BigNumber.from(pm.startTimestamp).toNumber() * 1000),
|
|
maxMintSupply: pm.maxClaimableSupply.toString(),
|
|
currentMintSupply: pm.supplyClaimed.toString(),
|
|
availableSupply: BigNumber.from(pm.maxClaimableSupply).sub(pm.supplyClaimed).toString(),
|
|
quantityLimitPerTransaction: pm.quantityLimitPerTransaction.toString(),
|
|
waitTimeSecondsLimitPerTransaction: pm.waitTimeInSecondsBetweenClaims.toString(),
|
|
price: BigNumber.from(pm.pricePerToken),
|
|
pricePerToken: BigNumber.from(pm.pricePerToken),
|
|
currency: pm.currency,
|
|
currencyContract: pm.currency,
|
|
currencyMetadata: cv,
|
|
merkleRoot: pm.merkleRoot
|
|
});
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function transformResultToClaimCondition(_x9) {
|
|
return _transformResultToClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return transformResultToClaimCondition;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.getActiveClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getActiveMintCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getActiveMintCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11() {
|
|
var index;
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context11.sent) {
|
|
_context11.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context11.abrupt("return", this.v1Module.getActiveMintCondition());
|
|
|
|
case 4:
|
|
_context11.next = 6;
|
|
return this.readOnlyContract.getIndexOfActiveCondition();
|
|
|
|
case 6:
|
|
index = _context11.sent;
|
|
_context11.t0 = this;
|
|
_context11.next = 10;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(index);
|
|
|
|
case 10:
|
|
_context11.t1 = _context11.sent;
|
|
return _context11.abrupt("return", _context11.t0.transformResultToMintCondition.call(_context11.t0, _context11.t1));
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function getActiveMintCondition() {
|
|
return _getActiveMintCondition.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveMintCondition;
|
|
}();
|
|
|
|
_proto.getActiveClaimCondition = /*#__PURE__*/function () {
|
|
var _getActiveClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12() {
|
|
var index, mc;
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context12.sent) {
|
|
_context12.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context12.abrupt("return", this.v1Module.getActiveClaimCondition());
|
|
|
|
case 4:
|
|
_context12.next = 6;
|
|
return this.readOnlyContract.getIndexOfActiveCondition();
|
|
|
|
case 6:
|
|
index = _context12.sent;
|
|
_context12.next = 9;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(index);
|
|
|
|
case 9:
|
|
mc = _context12.sent;
|
|
_context12.next = 12;
|
|
return this.transformResultToClaimCondition(mc);
|
|
|
|
case 12:
|
|
return _context12.abrupt("return", _context12.sent);
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function getActiveClaimCondition() {
|
|
return _getActiveClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveClaimCondition;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.getAllClaimConditions} instead
|
|
*/
|
|
;
|
|
|
|
_proto.getAllMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllMintConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13() {
|
|
var claimCondition, count, conditions, i;
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context13.sent) {
|
|
_context13.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context13.abrupt("return", this.v1Module.getAllMintConditions());
|
|
|
|
case 4:
|
|
_context13.next = 6;
|
|
return this.readOnlyContract.claimConditions();
|
|
|
|
case 6:
|
|
claimCondition = _context13.sent;
|
|
count = claimCondition.totalConditionCount.toNumber();
|
|
conditions = [];
|
|
i = 0;
|
|
|
|
case 10:
|
|
if (!(i < count)) {
|
|
_context13.next = 21;
|
|
break;
|
|
}
|
|
|
|
_context13.t0 = conditions;
|
|
_context13.t1 = this;
|
|
_context13.next = 15;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(i);
|
|
|
|
case 15:
|
|
_context13.t2 = _context13.sent;
|
|
_context13.t3 = _context13.t1.transformResultToMintCondition.call(_context13.t1, _context13.t2);
|
|
|
|
_context13.t0.push.call(_context13.t0, _context13.t3);
|
|
|
|
case 18:
|
|
i++;
|
|
_context13.next = 10;
|
|
break;
|
|
|
|
case 21:
|
|
return _context13.abrupt("return", conditions);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function getAllMintConditions() {
|
|
return _getAllMintConditions.apply(this, arguments);
|
|
}
|
|
|
|
return getAllMintConditions;
|
|
}();
|
|
|
|
_proto.getAllClaimConditions = /*#__PURE__*/function () {
|
|
var _getAllClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14() {
|
|
var _this6 = this;
|
|
|
|
var claimCondition, count, conditions, i;
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context14.sent) {
|
|
_context14.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context14.abrupt("return", this.v1Module.getAllClaimConditions());
|
|
|
|
case 4:
|
|
_context14.next = 6;
|
|
return this.readOnlyContract.claimConditions();
|
|
|
|
case 6:
|
|
claimCondition = _context14.sent;
|
|
count = claimCondition.totalConditionCount.toNumber();
|
|
conditions = [];
|
|
i = 0;
|
|
|
|
case 10:
|
|
if (!(i < count)) {
|
|
_context14.next = 19;
|
|
break;
|
|
}
|
|
|
|
_context14.t0 = conditions;
|
|
_context14.next = 14;
|
|
return this.readOnlyContract.getClaimConditionAtIndex(i);
|
|
|
|
case 14:
|
|
_context14.t1 = _context14.sent;
|
|
|
|
_context14.t0.push.call(_context14.t0, _context14.t1);
|
|
|
|
case 16:
|
|
i++;
|
|
_context14.next = 10;
|
|
break;
|
|
|
|
case 19:
|
|
return _context14.abrupt("return", Promise.all(conditions.map(function (c) {
|
|
return _this6.transformResultToClaimCondition(c);
|
|
})));
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function getAllClaimConditions() {
|
|
return _getAllClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimConditions;
|
|
}();
|
|
|
|
_proto.totalSupply = /*#__PURE__*/function () {
|
|
var _totalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15() {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context15.sent) {
|
|
_context15.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context15.abrupt("return", this.v1Module.totalSupply());
|
|
|
|
case 4:
|
|
_context15.next = 6;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 6:
|
|
return _context15.abrupt("return", _context15.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function totalSupply() {
|
|
return _totalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalSupply;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.maxTotalSupply =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _maxTotalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16() {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context16.sent) {
|
|
_context16.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context16.abrupt("return", this.v1Module.maxTotalSupply());
|
|
|
|
case 4:
|
|
_context16.next = 6;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 6:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function maxTotalSupply() {
|
|
return _maxTotalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return maxTotalSupply;
|
|
}();
|
|
|
|
_proto.totalUnclaimedSupply = /*#__PURE__*/function () {
|
|
var _totalUnclaimedSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17() {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
_context17.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context17.sent) {
|
|
_context17.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context17.abrupt("return", this.v1Module.totalUnclaimedSupply());
|
|
|
|
case 4:
|
|
_context17.next = 6;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 6:
|
|
_context17.t0 = _context17.sent;
|
|
_context17.next = 9;
|
|
return this.totalClaimedSupply();
|
|
|
|
case 9:
|
|
_context17.t1 = _context17.sent;
|
|
return _context17.abrupt("return", _context17.t0.sub.call(_context17.t0, _context17.t1));
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function totalUnclaimedSupply() {
|
|
return _totalUnclaimedSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalUnclaimedSupply;
|
|
}();
|
|
|
|
_proto.totalClaimedSupply = /*#__PURE__*/function () {
|
|
var _totalClaimedSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18() {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
_context18.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context18.sent) {
|
|
_context18.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context18.abrupt("return", this.v1Module.totalClaimedSupply());
|
|
|
|
case 4:
|
|
_context18.next = 6;
|
|
return this.readOnlyContract.nextTokenIdToClaim();
|
|
|
|
case 6:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function totalClaimedSupply() {
|
|
return _totalClaimedSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalClaimedSupply;
|
|
}()
|
|
/**
|
|
* Get NFT Balance
|
|
*
|
|
* @remarks Get a wallets NFT balance (number of NFTs in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check NFT balance
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* const balance = await module.balanceOf(address);
|
|
* console.log(balance);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(address) {
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 2:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function balanceOf(_x10) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20() {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.t0 = this;
|
|
_context20.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context20.t1 = _context20.sent;
|
|
_context20.next = 6;
|
|
return _context20.t0.balanceOf.call(_context20.t0, _context20.t1);
|
|
|
|
case 6:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(address, operator) {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function isApproved(_x11, _x12) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.setApproval =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(operator, approved) {
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context22.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context22.abrupt("return", _context22.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setApproval(_x13, _x14) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer NFT
|
|
*
|
|
* @remarks Transfer an NFT from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "{{wallet_address}}";
|
|
*
|
|
* // The token ID of the NFT you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* await module.transfer(toAddress, tokenId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(to, tokenId) {
|
|
var from;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.next = 2;
|
|
return this.getSignerAddress();
|
|
|
|
case 2:
|
|
from = _context23.sent;
|
|
_context23.next = 5;
|
|
return this.sendTransaction("safeTransferFrom(address,address,uint256)", [from, to, tokenId]);
|
|
|
|
case 5:
|
|
return _context23.abrupt("return", _context23.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function transfer(_x15, _x16) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}()
|
|
/**
|
|
* @deprecated - The function has been deprecated. Use `createBatch` instead.
|
|
*/
|
|
;
|
|
|
|
_proto.lazyMint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(metadata) {
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
_context24.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context24.sent) {
|
|
_context24.next = 6;
|
|
break;
|
|
}
|
|
|
|
_context24.next = 5;
|
|
return this.v1Module.lazyMint(metadata);
|
|
|
|
case 5:
|
|
return _context24.abrupt("return");
|
|
|
|
case 6:
|
|
_context24.next = 8;
|
|
return this.createBatch([metadata]);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function lazyMint(_x17) {
|
|
return _lazyMint.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMint;
|
|
}()
|
|
/**
|
|
* @deprecated - The function has been deprecated. Use `createBatch` instead.
|
|
*/
|
|
;
|
|
|
|
_proto.lazyMintBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(metadatas) {
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
_context25.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context25.sent) {
|
|
_context25.next = 6;
|
|
break;
|
|
}
|
|
|
|
_context25.next = 5;
|
|
return this.v1Module.lazyMintBatch(metadatas);
|
|
|
|
case 5:
|
|
return _context25.abrupt("return");
|
|
|
|
case 6:
|
|
_context25.next = 8;
|
|
return this.createBatch(metadatas);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function lazyMintBatch(_x18) {
|
|
return _lazyMintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMintBatch;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.setClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto.setMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setMintConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(factory) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context26.sent) {
|
|
_context26.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context26.abrupt("return", this.v1Module.setMintConditions(factory));
|
|
|
|
case 4:
|
|
return _context26.abrupt("return", this.setClaimCondition(factory));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function setMintConditions(_x19) {
|
|
return _setMintConditions.apply(this, arguments);
|
|
}
|
|
|
|
return setMintConditions;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.setClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto.setClaimConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(factory) {
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
return _context27.abrupt("return", this.setClaimCondition(factory));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function setClaimConditions(_x20) {
|
|
return _setClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return setClaimConditions;
|
|
}()
|
|
/**
|
|
* Sets public mint conditions for the next minting using the
|
|
* claim condition factory.
|
|
*
|
|
* @param factory - The claim condition factory.
|
|
*/
|
|
;
|
|
|
|
_proto.setClaimCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setClaimCondition = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(factory) {
|
|
var conditions, merkleInfo, _yield$this$getMetada, metadata, oldMerkle, defaultMerkleRoot, encoded, metadataUri;
|
|
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context28.sent) {
|
|
_context28.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context28.abrupt("return", this.v1Module.setClaimCondition(factory));
|
|
|
|
case 4:
|
|
_context28.next = 6;
|
|
return factory.buildConditions();
|
|
|
|
case 6:
|
|
conditions = _context28.sent.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestamp,
|
|
maxClaimableSupply: c.maxMintSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeSecondsLimitPerTransaction,
|
|
pricePerToken: c.pricePerToken,
|
|
currency: c.currency === AddressZero ? NATIVE_TOKEN_ADDRESS : c.currency,
|
|
merkleRoot: c.merkleRoot
|
|
};
|
|
});
|
|
merkleInfo = {};
|
|
factory.allSnapshots().forEach(function (s) {
|
|
merkleInfo[s.merkleRoot] = s.snapshotUri;
|
|
});
|
|
_context28.next = 11;
|
|
return this.getMetadata(false);
|
|
|
|
case 11:
|
|
_yield$this$getMetada = _context28.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
!metadata ? process.env.NODE_ENV !== "production" ? invariant(false, "Metadata is not set, this should never happen") : invariant(false) : void 0;
|
|
oldMerkle = metadata["merkle"];
|
|
defaultMerkleRoot = hexZeroPad([0], 32).toString();
|
|
|
|
if (factory.allSnapshots().length > 0) {
|
|
metadata["merkle"] = merkleInfo;
|
|
} else if (conditions.filter(function (c) {
|
|
return c.merkleRoot !== defaultMerkleRoot;
|
|
}).length === 0) {
|
|
metadata["merkle"] = {};
|
|
}
|
|
|
|
encoded = [];
|
|
|
|
if (isMetadataEqual(oldMerkle, metadata["merkle"])) {
|
|
_context28.next = 23;
|
|
break;
|
|
}
|
|
|
|
_context28.next = 21;
|
|
return this.sdk.getStorage().upload(JSON.stringify(metadata));
|
|
|
|
case 21:
|
|
metadataUri = _context28.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [metadataUri]));
|
|
|
|
case 23:
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setClaimConditions", [conditions]));
|
|
_context28.next = 26;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 26:
|
|
return _context28.abrupt("return", _context28.sent);
|
|
|
|
case 27:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function setClaimCondition(_x21) {
|
|
return _setClaimCondition.apply(this, arguments);
|
|
}
|
|
|
|
return setClaimCondition;
|
|
}();
|
|
|
|
_proto.updateClaimConditions = /*#__PURE__*/function () {
|
|
var _updateClaimConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(factory) {
|
|
var conditions, merkleInfo, encoded, _yield$this$getMetada2, metadata, oldMerkle, metadataUri;
|
|
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
_context29.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context29.sent) {
|
|
_context29.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context29.abrupt("return", this.v1Module.setClaimCondition(factory));
|
|
|
|
case 4:
|
|
_context29.next = 6;
|
|
return factory.buildConditions();
|
|
|
|
case 6:
|
|
conditions = _context29.sent.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestamp,
|
|
maxClaimableSupply: c.maxMintSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeSecondsLimitPerTransaction,
|
|
pricePerToken: c.pricePerToken,
|
|
currency: c.currency === AddressZero ? NATIVE_TOKEN_ADDRESS : c.currency,
|
|
merkleRoot: c.merkleRoot
|
|
};
|
|
});
|
|
merkleInfo = {};
|
|
factory.allSnapshots().forEach(function (s) {
|
|
merkleInfo[s.merkleRoot] = s.snapshotUri;
|
|
});
|
|
encoded = [];
|
|
_context29.next = 12;
|
|
return this.getMetadata(false);
|
|
|
|
case 12:
|
|
_yield$this$getMetada2 = _context29.sent;
|
|
metadata = _yield$this$getMetada2.metadata;
|
|
!metadata ? process.env.NODE_ENV !== "production" ? invariant(false, "Metadata is not set, this should never happen") : invariant(false) : void 0;
|
|
oldMerkle = metadata["merkle"];
|
|
|
|
if (factory.allSnapshots().length === 0 && "merkle" in metadata) {
|
|
metadata["merkle"] = {};
|
|
} else {
|
|
metadata["merkle"] = merkleInfo;
|
|
}
|
|
|
|
if (isMetadataEqual(oldMerkle, metadata["merkle"])) {
|
|
_context29.next = 22;
|
|
break;
|
|
}
|
|
|
|
_context29.next = 20;
|
|
return this.sdk.getStorage().upload(JSON.stringify(metadata));
|
|
|
|
case 20:
|
|
metadataUri = _context29.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [metadataUri]));
|
|
|
|
case 22:
|
|
encoded.push(this.contract["interface"].encodeFunctionData("updateClaimConditions", [conditions]));
|
|
_context29.next = 25;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 25:
|
|
return _context29.abrupt("return", _context29.sent);
|
|
|
|
case 26:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function updateClaimConditions(_x22) {
|
|
return _updateClaimConditions.apply(this, arguments);
|
|
}
|
|
|
|
return updateClaimConditions;
|
|
}()
|
|
/**
|
|
* Creates a claim condition factory
|
|
*
|
|
* @returns - A new claim condition factory
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimConditionsFactory = function getClaimConditionsFactory() {
|
|
var createSnapshotFunc = this.sdk.createSnapshot.bind(this.sdk);
|
|
var factory = new ClaimConditionFactory(createSnapshotFunc);
|
|
return factory;
|
|
}
|
|
/**
|
|
* @deprecated - Use the {@link DropModule.getClaimConditionsFactory} instead.
|
|
*/
|
|
;
|
|
|
|
_proto.getMintConditionsFactory = function getMintConditionsFactory() {
|
|
return this.getClaimConditionsFactory();
|
|
}
|
|
/**
|
|
* @deprecated - Use the {@link DropModule.setClaimConditions} instead.
|
|
*/
|
|
;
|
|
|
|
_proto.setPublicMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setPublicMintConditions = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30(conditions) {
|
|
var now, _conditions;
|
|
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
_context30.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context30.sent) {
|
|
_context30.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context30.abrupt("return", this.v1Module.setPublicMintConditions(conditions));
|
|
|
|
case 4:
|
|
now = BigNumber.from(Date.now()).div(1000);
|
|
_conditions = conditions.map(function (c) {
|
|
return {
|
|
startTimestamp: now.add(c.startTimestampInSeconds || 0),
|
|
maxClaimableSupply: c.maxMintSupply,
|
|
supplyClaimed: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction || c.maxMintSupply,
|
|
waitTimeInSecondsBetweenClaims: c.waitTimeSecondsLimitPerTransaction || 0,
|
|
pricePerToken: c.pricePerToken || 0,
|
|
currency: c.currency || AddressZero,
|
|
merkleRoot: c.merkleRoot || hexZeroPad([0], 32)
|
|
};
|
|
});
|
|
_context30.next = 8;
|
|
return this.sendTransaction("setClaimConditions", [_conditions]);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function setPublicMintConditions(_x23) {
|
|
return _setPublicMintConditions.apply(this, arguments);
|
|
}
|
|
|
|
return setPublicMintConditions;
|
|
}()
|
|
/**
|
|
* For any claim conditions that a particular wallet is violating,
|
|
* this function returns human readable information about the
|
|
* breaks in the condition that can be used to inform the user.
|
|
*
|
|
* @param quantity - The desired quantity that would be claimed.
|
|
*
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimIneligibilityReasons =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getClaimIneligibilityReasons = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(quantity, addressToCheck) {
|
|
var reasons, activeConditionIndex, claimCondition, _yield$Promise$all2, merkleRootArray, merkleLower, proofs, hashedAddress, timestampForNextClaim, now, balance, totalPrice, provider, _balance2, _provider, _balance3;
|
|
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
reasons = [];
|
|
|
|
if (!(addressToCheck === undefined)) {
|
|
_context31.next = 3;
|
|
break;
|
|
}
|
|
|
|
throw new Error("addressToCheck is required");
|
|
|
|
case 3:
|
|
_context31.prev = 3;
|
|
_context31.next = 6;
|
|
return Promise.all([this.readOnlyContract.getIndexOfActiveCondition(), this.getActiveClaimCondition()]);
|
|
|
|
case 6:
|
|
_yield$Promise$all2 = _context31.sent;
|
|
activeConditionIndex = _yield$Promise$all2[0];
|
|
claimCondition = _yield$Promise$all2[1];
|
|
_context31.next = 18;
|
|
break;
|
|
|
|
case 11:
|
|
_context31.prev = 11;
|
|
_context31.t0 = _context31["catch"](3);
|
|
|
|
if (!_context31.t0.message.includes("no public mint condition.")) {
|
|
_context31.next = 16;
|
|
break;
|
|
}
|
|
|
|
reasons.push(ClaimEligibility.NoActiveClaimPhase);
|
|
return _context31.abrupt("return", reasons);
|
|
|
|
case 16:
|
|
console.error("Failed to get active claim condition", _context31.t0);
|
|
throw new Error("Failed to get active claim condition");
|
|
|
|
case 18:
|
|
if (BigNumber.from(claimCondition.availableSupply).lt(quantity)) {
|
|
reasons.push(ClaimEligibility.NotEnoughSupply);
|
|
} // check for merkle root inclusion
|
|
|
|
|
|
merkleRootArray = ethers.utils.stripZeros(claimCondition.merkleRoot);
|
|
|
|
if (!(merkleRootArray.length > 0)) {
|
|
_context31.next = 26;
|
|
break;
|
|
}
|
|
|
|
merkleLower = claimCondition.merkleRoot.toString();
|
|
_context31.next = 24;
|
|
return this.getClaimerProofs(merkleLower, addressToCheck);
|
|
|
|
case 24:
|
|
proofs = _context31.sent;
|
|
|
|
if (proofs.length === 0) {
|
|
hashedAddress = ethers.utils.keccak256(addressToCheck).toLowerCase();
|
|
|
|
if (hashedAddress !== merkleLower) {
|
|
reasons.push(ClaimEligibility.AddressNotAllowed);
|
|
}
|
|
} // TODO: compute proofs to root, need browser compatibility
|
|
|
|
|
|
case 26:
|
|
_context31.next = 28;
|
|
return this.readOnlyContract.getTimestampForNextValidClaim(activeConditionIndex, addressToCheck);
|
|
|
|
case 28:
|
|
timestampForNextClaim = _context31.sent;
|
|
now = BigNumber.from(Date.now()).div(1000);
|
|
|
|
if (!now.lt(timestampForNextClaim)) {
|
|
_context31.next = 39;
|
|
break;
|
|
}
|
|
|
|
if (!BigNumber.from(claimCondition.waitTimeSecondsLimitPerTransaction).eq(timestampForNextClaim)) {
|
|
_context31.next = 38;
|
|
break;
|
|
}
|
|
|
|
_context31.next = 34;
|
|
return this.readOnlyContract.balanceOf(addressToCheck);
|
|
|
|
case 34:
|
|
balance = _context31.sent;
|
|
|
|
if (balance.gte(1)) {
|
|
reasons.push(ClaimEligibility.AlreadyClaimed);
|
|
}
|
|
|
|
_context31.next = 39;
|
|
break;
|
|
|
|
case 38:
|
|
reasons.push(ClaimEligibility.WaitBeforeNextClaimTransaction);
|
|
|
|
case 39:
|
|
if (!claimCondition.pricePerToken.gt(0)) {
|
|
_context31.next = 58;
|
|
break;
|
|
}
|
|
|
|
totalPrice = claimCondition.pricePerToken.mul(quantity);
|
|
|
|
if (!isNativeToken(claimCondition.currency)) {
|
|
_context31.next = 51;
|
|
break;
|
|
}
|
|
|
|
_context31.next = 44;
|
|
return this.getProvider();
|
|
|
|
case 44:
|
|
provider = _context31.sent;
|
|
_context31.next = 47;
|
|
return provider.getBalance(addressToCheck);
|
|
|
|
case 47:
|
|
_balance2 = _context31.sent;
|
|
|
|
if (_balance2.lt(totalPrice)) {
|
|
reasons.push(ClaimEligibility.NotEnoughTokens);
|
|
}
|
|
|
|
_context31.next = 58;
|
|
break;
|
|
|
|
case 51:
|
|
_context31.next = 53;
|
|
return this.getProvider();
|
|
|
|
case 53:
|
|
_provider = _context31.sent;
|
|
_context31.next = 56;
|
|
return ERC20__factory.connect(claimCondition.currency, _provider).balanceOf(addressToCheck);
|
|
|
|
case 56:
|
|
_balance3 = _context31.sent;
|
|
|
|
if (_balance3.lt(totalPrice)) {
|
|
reasons.push(ClaimEligibility.NotEnoughTokens);
|
|
}
|
|
|
|
case 58:
|
|
return _context31.abrupt("return", reasons);
|
|
|
|
case 59:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this, [[3, 11]]);
|
|
}));
|
|
|
|
function getClaimIneligibilityReasons(_x24, _x25) {
|
|
return _getClaimIneligibilityReasons.apply(this, arguments);
|
|
}
|
|
|
|
return getClaimIneligibilityReasons;
|
|
}()
|
|
/**
|
|
* Can Claim
|
|
*
|
|
* @remarks Check if the drop can currently be claimed.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Quantity of tokens to check if they are claimable
|
|
* const quantity = 1;
|
|
*
|
|
* await module.canClaim(quantity);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.canClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _canClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(quantity, addressToCheck) {
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
if (!(addressToCheck === undefined)) {
|
|
_context32.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context32.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
addressToCheck = _context32.sent;
|
|
|
|
case 4:
|
|
_context32.next = 6;
|
|
return this.isV0();
|
|
|
|
case 6:
|
|
if (!_context32.sent) {
|
|
_context32.next = 8;
|
|
break;
|
|
}
|
|
|
|
return _context32.abrupt("return", this.v1Module.canClaim(quantity, []));
|
|
|
|
case 8:
|
|
_context32.next = 10;
|
|
return this.getClaimIneligibilityReasons(quantity, addressToCheck);
|
|
|
|
case 10:
|
|
_context32.t0 = _context32.sent.length;
|
|
return _context32.abrupt("return", _context32.t0 === 0);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function canClaim(_x26, _x27) {
|
|
return _canClaim.apply(this, arguments);
|
|
}
|
|
|
|
return canClaim;
|
|
}()
|
|
/**
|
|
* Returns proofs and the overrides required for the transaction.
|
|
*
|
|
* @returns - `overrides` and `proofs` as an object.
|
|
*/
|
|
;
|
|
|
|
_proto.prepareClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _prepareClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(quantity, proofs) {
|
|
var mintCondition, _yield$this$getMetada3, metadata, addressToClaim, snapshot, jsonConvert, snapshotData, item, overrides, erc20, owner, spender, allowance, totalPrice;
|
|
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context33.next = 3;
|
|
return this.getActiveClaimCondition();
|
|
|
|
case 3:
|
|
mintCondition = _context33.sent;
|
|
_context33.next = 6;
|
|
return this.getMetadata();
|
|
|
|
case 6:
|
|
_yield$this$getMetada3 = _context33.sent;
|
|
metadata = _yield$this$getMetada3.metadata;
|
|
_context33.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
addressToClaim = _context33.sent;
|
|
|
|
if (mintCondition.merkleRoot.toString().startsWith(AddressZero)) {
|
|
_context33.next = 21;
|
|
break;
|
|
}
|
|
|
|
_context33.next = 14;
|
|
return this.sdk.getStorage().get(metadata == null ? void 0 : metadata.merkle[mintCondition.merkleRoot.toString()]);
|
|
|
|
case 14:
|
|
snapshot = _context33.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
return c.address.toLowerCase() === addressToClaim.toLowerCase();
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context33.next = 20;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No claim found for this address");
|
|
|
|
case 20:
|
|
proofs = item.proof;
|
|
|
|
case 21:
|
|
_context33.next = 23;
|
|
return this.getCallOverrides();
|
|
|
|
case 23:
|
|
_context33.t0 = _context33.sent;
|
|
|
|
if (_context33.t0) {
|
|
_context33.next = 26;
|
|
break;
|
|
}
|
|
|
|
_context33.t0 = {};
|
|
|
|
case 26:
|
|
overrides = _context33.t0;
|
|
|
|
if (!mintCondition.pricePerToken.gt(0)) {
|
|
_context33.next = 44;
|
|
break;
|
|
}
|
|
|
|
if (!isNativeToken(mintCondition.currency)) {
|
|
_context33.next = 32;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = BigNumber.from(mintCondition.pricePerToken).mul(quantity);
|
|
_context33.next = 44;
|
|
break;
|
|
|
|
case 32:
|
|
erc20 = ERC20__factory.connect(mintCondition.currency, this.providerOrSigner);
|
|
_context33.next = 35;
|
|
return this.getSignerAddress();
|
|
|
|
case 35:
|
|
owner = _context33.sent;
|
|
spender = this.address;
|
|
_context33.next = 39;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 39:
|
|
allowance = _context33.sent;
|
|
totalPrice = BigNumber.from(mintCondition.pricePerToken).mul(BigNumber.from(quantity));
|
|
|
|
if (!allowance.lt(totalPrice)) {
|
|
_context33.next = 44;
|
|
break;
|
|
}
|
|
|
|
_context33.next = 44;
|
|
return this.sendContractTransaction(erc20, "approve", [spender, allowance.add(totalPrice)]);
|
|
|
|
case 44:
|
|
return _context33.abrupt("return", {
|
|
overrides: overrides,
|
|
proofs: proofs
|
|
});
|
|
|
|
case 45:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function prepareClaim(_x28, _x29) {
|
|
return _prepareClaim.apply(this, arguments);
|
|
}
|
|
|
|
return prepareClaim;
|
|
}()
|
|
/**
|
|
* Claim NFTs to Wallet
|
|
*
|
|
* @remarks Let the a specified wallet claim NFTs.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to claim the NFTs
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* // The number of NFTs to claim
|
|
* const quantity = 1;
|
|
*
|
|
* await module.claimTo(quantity, address);
|
|
* ```
|
|
*
|
|
* @param quantity - Quantity of the tokens you want to claim
|
|
* @param addressToClaim - Address you want to send the token to
|
|
* @param proofs - Array of proofs
|
|
*
|
|
* @returns - Receipt for the transaction
|
|
*/
|
|
;
|
|
|
|
_proto.claimTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _claimTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(quantity, addressToClaim, proofs) {
|
|
var claimData, contract, receipt, encoded, events, startingIndex, endingIndex, i;
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context34.next = 3;
|
|
return this.prepareClaim(quantity, proofs);
|
|
|
|
case 3:
|
|
claimData = _context34.sent;
|
|
_context34.next = 6;
|
|
return this.isNewClaim();
|
|
|
|
case 6:
|
|
if (!_context34.sent) {
|
|
_context34.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context34.next = 9;
|
|
return this.sendTransaction("claim", [addressToClaim, quantity, claimData.proofs], claimData.overrides);
|
|
|
|
case 9:
|
|
return _context34.abrupt("return", _context34.sent);
|
|
|
|
case 10:
|
|
// backward compatibility for < 1.22.0 claim
|
|
contract = new Contract$1(this.address, ABI_V1_22_0, this.providerOrSigner);
|
|
_context34.next = 13;
|
|
return this.sendContractTransaction(contract, "claim", [quantity, claimData.proofs], claimData.overrides);
|
|
|
|
case 13:
|
|
receipt = _context34.sent;
|
|
encoded = [];
|
|
events = this.parseLogs("ClaimedTokens", receipt == null ? void 0 : receipt.logs, contract);
|
|
startingIndex = events[0].args.startTokenId;
|
|
endingIndex = startingIndex.add(quantity);
|
|
i = startingIndex;
|
|
|
|
case 19:
|
|
if (!i.lt(endingIndex)) {
|
|
_context34.next = 33;
|
|
break;
|
|
}
|
|
|
|
_context34.t0 = encoded;
|
|
_context34.t1 = this.contract["interface"];
|
|
_context34.next = 24;
|
|
return this.getSignerAddress();
|
|
|
|
case 24:
|
|
_context34.t2 = _context34.sent;
|
|
_context34.t3 = addressToClaim;
|
|
_context34.t4 = i;
|
|
_context34.t5 = [_context34.t2, _context34.t3, _context34.t4];
|
|
_context34.t6 = _context34.t1.encodeFunctionData.call(_context34.t1, "transferFrom", _context34.t5);
|
|
|
|
_context34.t0.push.call(_context34.t0, _context34.t6);
|
|
|
|
case 30:
|
|
i = i.add(1);
|
|
_context34.next = 19;
|
|
break;
|
|
|
|
case 33:
|
|
_context34.next = 35;
|
|
return this.sendTransaction("multicall", [encoded], claimData.overrides);
|
|
|
|
case 35:
|
|
return _context34.abrupt("return", _context34.sent);
|
|
|
|
case 36:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this);
|
|
}));
|
|
|
|
function claimTo(_x30, _x31, _x32) {
|
|
return _claimTo.apply(this, arguments);
|
|
}
|
|
|
|
return claimTo;
|
|
}()
|
|
/** Claim NFTs
|
|
*
|
|
* @param quantity - Quantity of the tokens you want to claim
|
|
* @param proofs - Array of proofs
|
|
*
|
|
* @returns - Receipt for the transaction
|
|
*/
|
|
;
|
|
|
|
_proto.claim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _claim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee36(quantity, proofs) {
|
|
var _receipt,
|
|
_this7 = this;
|
|
|
|
var claimData, receipt, contract, events, startingIndex, endingIndex, tokenIds, i;
|
|
return runtime_1.wrap(function _callee36$(_context36) {
|
|
while (1) {
|
|
switch (_context36.prev = _context36.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context36.next = 3;
|
|
return this.isV0();
|
|
|
|
case 3:
|
|
if (!_context36.sent) {
|
|
_context36.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context36.abrupt("return", this.v1Module.claim(quantity, proofs));
|
|
|
|
case 5:
|
|
_context36.next = 7;
|
|
return this.prepareClaim(quantity, proofs);
|
|
|
|
case 7:
|
|
claimData = _context36.sent;
|
|
contract = this.contract;
|
|
_context36.next = 11;
|
|
return this.isNewClaim();
|
|
|
|
case 11:
|
|
if (!_context36.sent) {
|
|
_context36.next = 25;
|
|
break;
|
|
}
|
|
|
|
_context36.t0 = this;
|
|
_context36.next = 15;
|
|
return this.getSignerAddress();
|
|
|
|
case 15:
|
|
_context36.t1 = _context36.sent;
|
|
_context36.t2 = quantity;
|
|
_context36.t3 = claimData.proofs;
|
|
_context36.t4 = [_context36.t1, _context36.t2, _context36.t3];
|
|
_context36.t5 = claimData.overrides;
|
|
_context36.next = 22;
|
|
return _context36.t0.sendTransaction.call(_context36.t0, "claim", _context36.t4, _context36.t5);
|
|
|
|
case 22:
|
|
receipt = _context36.sent;
|
|
_context36.next = 29;
|
|
break;
|
|
|
|
case 25:
|
|
// backward compatibility for < 1.22.0 claim
|
|
contract = new Contract$1(this.address, ABI_V1_22_0, this.providerOrSigner);
|
|
_context36.next = 28;
|
|
return this.sendContractTransaction(contract, "claim", [quantity, claimData.proofs], claimData.overrides);
|
|
|
|
case 28:
|
|
receipt = _context36.sent;
|
|
|
|
case 29:
|
|
events = this.parseLogs("ClaimedTokens", (_receipt = receipt) == null ? void 0 : _receipt.logs, contract);
|
|
startingIndex = events[0].args.startTokenId;
|
|
endingIndex = startingIndex.add(quantity);
|
|
tokenIds = [];
|
|
|
|
for (i = startingIndex; i.lt(endingIndex); i = i.add(1)) {
|
|
tokenIds.push(BigNumber.from(i.toString()));
|
|
}
|
|
|
|
_context36.next = 36;
|
|
return Promise.all(tokenIds.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(t) {
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
_context35.next = 2;
|
|
return _this7.get(t.toString());
|
|
|
|
case 2:
|
|
return _context35.abrupt("return", _context35.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35);
|
|
}));
|
|
|
|
return function (_x35) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 36:
|
|
return _context36.abrupt("return", _context36.sent);
|
|
|
|
case 37:
|
|
case "end":
|
|
return _context36.stop();
|
|
}
|
|
}
|
|
}, _callee36, this);
|
|
}));
|
|
|
|
function claim(_x33, _x34) {
|
|
return _claim.apply(this, arguments);
|
|
}
|
|
|
|
return claim;
|
|
}();
|
|
|
|
_proto.burn = /*#__PURE__*/function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee37(tokenId) {
|
|
return runtime_1.wrap(function _callee37$(_context37) {
|
|
while (1) {
|
|
switch (_context37.prev = _context37.next) {
|
|
case 0:
|
|
_context37.next = 2;
|
|
return this.sendTransaction("burn", [tokenId]);
|
|
|
|
case 2:
|
|
return _context37.abrupt("return", _context37.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context37.stop();
|
|
}
|
|
}
|
|
}, _callee37, this);
|
|
}));
|
|
|
|
function burn(_x36) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee38(from, to, tokenId) {
|
|
return runtime_1.wrap(function _callee38$(_context38) {
|
|
while (1) {
|
|
switch (_context38.prev = _context38.next) {
|
|
case 0:
|
|
_context38.next = 2;
|
|
return this.sendTransaction("transferFrom", [from, to, tokenId]);
|
|
|
|
case 2:
|
|
return _context38.abrupt("return", _context38.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context38.stop();
|
|
}
|
|
}
|
|
}, _callee38, this);
|
|
}));
|
|
|
|
function transferFrom(_x37, _x38, _x39) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.setModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee39(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee39$(_context39) {
|
|
while (1) {
|
|
switch (_context39.prev = _context39.next) {
|
|
case 0:
|
|
_context39.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context39.sent;
|
|
_context39.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context39.abrupt("return", _context39.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context39.stop();
|
|
}
|
|
}
|
|
}, _callee39, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x40) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee40(amount) {
|
|
var _yield$this$getMetada4, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee40$(_context40) {
|
|
while (1) {
|
|
switch (_context40.prev = _context40.next) {
|
|
case 0:
|
|
_context40.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada4 = _context40.sent;
|
|
metadata = _yield$this$getMetada4.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context40.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context40.t0 = this.sdk.getStorage();
|
|
_context40.t1 = _extends({}, metadata);
|
|
_context40.t2 = this.address;
|
|
_context40.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context40.t3 = _context40.sent;
|
|
_context40.next = 16;
|
|
return _context40.t0.uploadMetadata.call(_context40.t0, _context40.t1, _context40.t2, _context40.t3);
|
|
|
|
case 16:
|
|
uri = _context40.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context40.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context40.abrupt("return", _context40.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context40.stop();
|
|
}
|
|
}
|
|
}, _callee40, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x41) {
|
|
return _setRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee41() {
|
|
return runtime_1.wrap(function _callee41$(_context41) {
|
|
while (1) {
|
|
switch (_context41.prev = _context41.next) {
|
|
case 0:
|
|
_context41.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context41.abrupt("return", _context41.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context41.stop();
|
|
}
|
|
}
|
|
}, _callee41, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee42() {
|
|
var _metadata$metadata;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee42$(_context42) {
|
|
while (1) {
|
|
switch (_context42.prev = _context42.next) {
|
|
case 0:
|
|
_context42.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context42.sent;
|
|
|
|
if (!(((_metadata$metadata = metadata.metadata) == null ? void 0 : _metadata$metadata.fee_recipient) !== undefined)) {
|
|
_context42.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context42.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context42.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context42.stop();
|
|
}
|
|
}
|
|
}, _callee42, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}()
|
|
/**
|
|
* Create batch allows you to create a batch of tokens
|
|
* in one transaction. This function can only be called
|
|
* once per module at the moment.
|
|
*
|
|
* @beta
|
|
*
|
|
* @param metadatas - The metadata to include in the batch.
|
|
*/
|
|
;
|
|
|
|
_proto.createBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee43(metadatas) {
|
|
var _receipt2;
|
|
|
|
var startFileNumber, _yield$this$sdk$getSt, baseUri, receipt, contract, events, _events$0$args, startingIndex, endingIndex, tokenIds, i;
|
|
|
|
return runtime_1.wrap(function _callee43$(_context43) {
|
|
while (1) {
|
|
switch (_context43.prev = _context43.next) {
|
|
case 0:
|
|
_context43.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context43.sent) {
|
|
_context43.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context43.abrupt("return", this.v1Module.createBatch(metadatas));
|
|
|
|
case 4:
|
|
_context43.next = 6;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 6:
|
|
startFileNumber = _context43.sent;
|
|
_context43.next = 9;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas, this.address, startFileNumber.toNumber());
|
|
|
|
case 9:
|
|
_yield$this$sdk$getSt = _context43.sent;
|
|
baseUri = _yield$this$sdk$getSt.baseUri;
|
|
contract = this.contract;
|
|
_context43.next = 14;
|
|
return this.hasDelayedReveal();
|
|
|
|
case 14:
|
|
if (!_context43.sent) {
|
|
_context43.next = 20;
|
|
break;
|
|
}
|
|
|
|
_context43.next = 17;
|
|
return this.sendTransaction("lazyMint", [metadatas.length, baseUri.endsWith("/") ? baseUri : baseUri + "/", ethers.utils.toUtf8Bytes("")]);
|
|
|
|
case 17:
|
|
receipt = _context43.sent;
|
|
_context43.next = 24;
|
|
break;
|
|
|
|
case 20:
|
|
contract = new Contract$1(this.address, ABI_V1_24_0, this.providerOrSigner);
|
|
_context43.next = 23;
|
|
return this.sendContractTransaction(contract, "lazyMint", [metadatas.length, baseUri.endsWith("/") ? baseUri : baseUri + "/"]);
|
|
|
|
case 23:
|
|
receipt = _context43.sent;
|
|
|
|
case 24:
|
|
events = this.parseLogs("LazyMintedTokens", (_receipt2 = receipt) == null ? void 0 : _receipt2.logs, contract);
|
|
_events$0$args = events[0].args, startingIndex = _events$0$args[0], endingIndex = _events$0$args[1];
|
|
tokenIds = [];
|
|
|
|
for (i = startingIndex; i.lte(endingIndex); i = i.add(1)) {
|
|
tokenIds.push(i.toString());
|
|
}
|
|
|
|
return _context43.abrupt("return", tokenIds);
|
|
|
|
case 29:
|
|
case "end":
|
|
return _context43.stop();
|
|
}
|
|
}
|
|
}, _callee43, this);
|
|
}));
|
|
|
|
function createBatch(_x42) {
|
|
return _createBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createBatch;
|
|
}()
|
|
/**
|
|
* Algorithm to hash delay reveal password, so we don't broadcast the input password on-chain.
|
|
*
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.hashDelayRevealPassword =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _hashDelayRevealPassword = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee44(batchTokenIndex, password) {
|
|
var chainId, contractAddress;
|
|
return runtime_1.wrap(function _callee44$(_context44) {
|
|
while (1) {
|
|
switch (_context44.prev = _context44.next) {
|
|
case 0:
|
|
_context44.next = 2;
|
|
return this.getChainID();
|
|
|
|
case 2:
|
|
chainId = _context44.sent;
|
|
contractAddress = this.address;
|
|
return _context44.abrupt("return", ethers.utils.solidityKeccak256(["string", "uint256", "uint256", "address"], [password, chainId, batchTokenIndex, contractAddress]));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context44.stop();
|
|
}
|
|
}
|
|
}, _callee44, this);
|
|
}));
|
|
|
|
function hashDelayRevealPassword(_x43, _x44) {
|
|
return _hashDelayRevealPassword.apply(this, arguments);
|
|
}
|
|
|
|
return hashDelayRevealPassword;
|
|
}()
|
|
/**
|
|
* Create batch allows you to create a batch of tokens
|
|
* in one transaction. This function can only be called
|
|
* once per module at the moment.
|
|
*
|
|
* @param metadatas - The metadata to include in the batch.
|
|
*/
|
|
;
|
|
|
|
_proto.createDelayedRevealBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createDelayedRevealBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee45(placeholder, metadatas, password) {
|
|
var _yield$this$sdk$getSt2, placeholderUri, startFileNumber, _yield$this$sdk$getSt3, baseUri, baseUriId, encryptedBaseUri, receipt, events, _events$0$args2, startingIndex, endingIndex, tokenIds, i;
|
|
|
|
return runtime_1.wrap(function _callee45$(_context45) {
|
|
while (1) {
|
|
switch (_context45.prev = _context45.next) {
|
|
case 0:
|
|
_context45.next = 2;
|
|
return this.hasDelayedReveal();
|
|
|
|
case 2:
|
|
if (_context45.sent) {
|
|
_context45.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw new Error("delay reveal unsupported");
|
|
|
|
case 4:
|
|
if (password) {
|
|
_context45.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Password is required");
|
|
|
|
case 6:
|
|
_context45.next = 8;
|
|
return this.sdk.getStorage().uploadMetadataBatch([placeholder], this.address);
|
|
|
|
case 8:
|
|
_yield$this$sdk$getSt2 = _context45.sent;
|
|
placeholderUri = _yield$this$sdk$getSt2.baseUri;
|
|
_context45.next = 12;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 12:
|
|
startFileNumber = _context45.sent;
|
|
_context45.next = 15;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas, this.address, startFileNumber.toNumber());
|
|
|
|
case 15:
|
|
_yield$this$sdk$getSt3 = _context45.sent;
|
|
baseUri = _yield$this$sdk$getSt3.baseUri;
|
|
_context45.next = 19;
|
|
return this.readOnlyContract.getBaseURICount();
|
|
|
|
case 19:
|
|
baseUriId = _context45.sent;
|
|
_context45.t0 = this.readOnlyContract;
|
|
_context45.t1 = ethers.utils.toUtf8Bytes(baseUri.endsWith("/") ? baseUri : baseUri + "/");
|
|
_context45.next = 24;
|
|
return this.hashDelayRevealPassword(baseUriId, password);
|
|
|
|
case 24:
|
|
_context45.t2 = _context45.sent;
|
|
_context45.next = 27;
|
|
return _context45.t0.encryptDecrypt.call(_context45.t0, _context45.t1, _context45.t2);
|
|
|
|
case 27:
|
|
encryptedBaseUri = _context45.sent;
|
|
_context45.next = 30;
|
|
return this.sendTransaction("lazyMint", [metadatas.length, placeholderUri.endsWith("/") ? placeholderUri : placeholderUri + "/", encryptedBaseUri]);
|
|
|
|
case 30:
|
|
receipt = _context45.sent;
|
|
events = this.parseLogs("LazyMintedTokens", receipt == null ? void 0 : receipt.logs);
|
|
_events$0$args2 = events[0].args, startingIndex = _events$0$args2[0], endingIndex = _events$0$args2[1];
|
|
tokenIds = [];
|
|
|
|
for (i = startingIndex; i.lte(endingIndex); i = i.add(1)) {
|
|
tokenIds.push(i.toString());
|
|
}
|
|
|
|
return _context45.abrupt("return", tokenIds);
|
|
|
|
case 36:
|
|
case "end":
|
|
return _context45.stop();
|
|
}
|
|
}
|
|
}, _callee45, this);
|
|
}));
|
|
|
|
function createDelayedRevealBatch(_x45, _x46, _x47) {
|
|
return _createDelayedRevealBatch.apply(this, arguments);
|
|
}
|
|
|
|
return createDelayedRevealBatch;
|
|
}();
|
|
|
|
_proto.reveal = /*#__PURE__*/function () {
|
|
var _reveal = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee46(batchId, password) {
|
|
var key, decryptedUri;
|
|
return runtime_1.wrap(function _callee46$(_context46) {
|
|
while (1) {
|
|
switch (_context46.prev = _context46.next) {
|
|
case 0:
|
|
_context46.next = 2;
|
|
return this.hasDelayedReveal();
|
|
|
|
case 2:
|
|
if (_context46.sent) {
|
|
_context46.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw new Error("delay reveal unsupported");
|
|
|
|
case 4:
|
|
if (password) {
|
|
_context46.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Password is required");
|
|
|
|
case 6:
|
|
_context46.next = 8;
|
|
return this.hashDelayRevealPassword(batchId, password);
|
|
|
|
case 8:
|
|
key = _context46.sent;
|
|
_context46.prev = 9;
|
|
_context46.next = 12;
|
|
return this.contract.callStatic.reveal(batchId, key);
|
|
|
|
case 12:
|
|
decryptedUri = _context46.sent;
|
|
|
|
if (!(!decryptedUri.includes("://") || !decryptedUri.endsWith("/"))) {
|
|
_context46.next = 15;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Error revealing batch " + batchId + " - make sure your password is correct");
|
|
|
|
case 15:
|
|
_context46.next = 21;
|
|
break;
|
|
|
|
case 17:
|
|
_context46.prev = 17;
|
|
_context46.t0 = _context46["catch"](9);
|
|
console.log("Error revealing batch " + batchId, _context46.t0);
|
|
throw new Error("Error revealing batch " + batchId + " - make sure your password is correct");
|
|
|
|
case 21:
|
|
_context46.next = 23;
|
|
return this.sendTransaction("reveal", [batchId, key]);
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context46.stop();
|
|
}
|
|
}
|
|
}, _callee46, this, [[9, 17]]);
|
|
}));
|
|
|
|
function reveal(_x48, _x49) {
|
|
return _reveal.apply(this, arguments);
|
|
}
|
|
|
|
return reveal;
|
|
}()
|
|
/**
|
|
* Gets a list of token uris that needs to be revealed.
|
|
*/
|
|
;
|
|
|
|
_proto.getBatchesToReveal =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getBatchesToReveal = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee47() {
|
|
var _this8 = this;
|
|
|
|
var count, countRangeArray, uriIndices, uriIndicesWithZeroStart, tokenUris, tokenMetadatas, encryptedBaseUris;
|
|
return runtime_1.wrap(function _callee47$(_context47) {
|
|
while (1) {
|
|
switch (_context47.prev = _context47.next) {
|
|
case 0:
|
|
_context47.next = 2;
|
|
return this.hasDelayedReveal();
|
|
|
|
case 2:
|
|
if (_context47.sent) {
|
|
_context47.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Contract does not support delay reveal");
|
|
|
|
case 4:
|
|
_context47.next = 6;
|
|
return this.readOnlyContract.getBaseURICount();
|
|
|
|
case 6:
|
|
count = _context47.sent;
|
|
|
|
if (!count.isZero()) {
|
|
_context47.next = 9;
|
|
break;
|
|
}
|
|
|
|
return _context47.abrupt("return", []);
|
|
|
|
case 9:
|
|
countRangeArray = Array.from(Array(count.toNumber()).keys()); // map over to get the base uri indices, which should be the end token id of every batch
|
|
|
|
_context47.next = 12;
|
|
return Promise.all(countRangeArray.map(function (i) {
|
|
return _this8.readOnlyContract.baseURIIndices(i);
|
|
}));
|
|
|
|
case 12:
|
|
uriIndices = _context47.sent;
|
|
// first batch always start from 0. don't need to fetch the last batch so pop it from the range array
|
|
uriIndicesWithZeroStart = uriIndices.slice(0, uriIndices.length - 1); // returns the token uri for each batches. first batch always starts from token id 0.
|
|
|
|
_context47.next = 16;
|
|
return Promise.all(Array.from([0].concat(uriIndicesWithZeroStart)).map(function (i) {
|
|
return _this8.readOnlyContract.tokenURI(i);
|
|
}));
|
|
|
|
case 16:
|
|
tokenUris = _context47.sent;
|
|
_context47.next = 19;
|
|
return Promise.all(Array.from([0].concat(uriIndicesWithZeroStart)).map(function (i) {
|
|
return _this8.getTokenMetadata(i.toString());
|
|
}));
|
|
|
|
case 19:
|
|
tokenMetadatas = _context47.sent;
|
|
_context47.next = 22;
|
|
return Promise.all(Array.from([].concat(uriIndices)).map(function (i) {
|
|
return _this8.readOnlyContract.encryptedBaseURI(i);
|
|
}));
|
|
|
|
case 22:
|
|
encryptedBaseUris = _context47.sent;
|
|
return _context47.abrupt("return", tokenUris.map(function (uri, index) {
|
|
return {
|
|
batchId: BigNumber.from(index),
|
|
batchUri: uri,
|
|
placeholderMetadata: tokenMetadatas[index]
|
|
};
|
|
}).filter(function (_, index) {
|
|
return ethers.utils.hexDataLength(encryptedBaseUris[index]) > 0;
|
|
}));
|
|
|
|
case 24:
|
|
case "end":
|
|
return _context47.stop();
|
|
}
|
|
}
|
|
}, _callee47, this);
|
|
}));
|
|
|
|
function getBatchesToReveal() {
|
|
return _getBatchesToReveal.apply(this, arguments);
|
|
}
|
|
|
|
return getBatchesToReveal;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*
|
|
* @returns - True if the batch has been created, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto.canCreateBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _canCreateBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee48() {
|
|
return runtime_1.wrap(function _callee48$(_context48) {
|
|
while (1) {
|
|
switch (_context48.prev = _context48.next) {
|
|
case 0:
|
|
_context48.next = 2;
|
|
return this.isV0();
|
|
|
|
case 2:
|
|
if (!_context48.sent) {
|
|
_context48.next = 4;
|
|
break;
|
|
}
|
|
|
|
return _context48.abrupt("return", this.v1Module.canCreateBatch());
|
|
|
|
case 4:
|
|
return _context48.abrupt("return", true);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context48.stop();
|
|
}
|
|
}
|
|
}, _callee48, this);
|
|
}));
|
|
|
|
function canCreateBatch() {
|
|
return _canCreateBatch.apply(this, arguments);
|
|
}
|
|
|
|
return canCreateBatch;
|
|
}()
|
|
/**
|
|
* Check if contract is v0 or not. If the contract doesn't have nextTokenIdToMint = v0 contract.
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isV0 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee49() {
|
|
return runtime_1.wrap(function _callee49$(_context49) {
|
|
while (1) {
|
|
switch (_context49.prev = _context49.next) {
|
|
case 0:
|
|
_context49.next = 2;
|
|
return this.checkVersion();
|
|
|
|
case 2:
|
|
return _context49.abrupt("return", this._isV0);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context49.stop();
|
|
}
|
|
}
|
|
}, _callee49, this);
|
|
}));
|
|
|
|
function isV0() {
|
|
return _isV.apply(this, arguments);
|
|
}
|
|
|
|
return isV0;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isNewClaim =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isNewClaim = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee50() {
|
|
return runtime_1.wrap(function _callee50$(_context50) {
|
|
while (1) {
|
|
switch (_context50.prev = _context50.next) {
|
|
case 0:
|
|
_context50.next = 2;
|
|
return this.checkVersion();
|
|
|
|
case 2:
|
|
return _context50.abrupt("return", this._version >= 1);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context50.stop();
|
|
}
|
|
}
|
|
}, _callee50, this);
|
|
}));
|
|
|
|
function isNewClaim() {
|
|
return _isNewClaim.apply(this, arguments);
|
|
}
|
|
|
|
return isNewClaim;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.hasDelayedReveal =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _hasDelayedReveal = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee51() {
|
|
return runtime_1.wrap(function _callee51$(_context51) {
|
|
while (1) {
|
|
switch (_context51.prev = _context51.next) {
|
|
case 0:
|
|
_context51.next = 2;
|
|
return this.checkVersion();
|
|
|
|
case 2:
|
|
return _context51.abrupt("return", this._version >= 2);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context51.stop();
|
|
}
|
|
}
|
|
}, _callee51, this);
|
|
}));
|
|
|
|
function hasDelayedReveal() {
|
|
return _hasDelayedReveal.apply(this, arguments);
|
|
}
|
|
|
|
return hasDelayedReveal;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.checkVersion =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _checkVersion = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee52() {
|
|
return runtime_1.wrap(function _callee52$(_context52) {
|
|
while (1) {
|
|
switch (_context52.prev = _context52.next) {
|
|
case 0:
|
|
if (!this._shouldCheckVersion) {
|
|
_context52.next = 20;
|
|
break;
|
|
}
|
|
|
|
_context52.prev = 1;
|
|
_context52.next = 4;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 4:
|
|
this._isV0 = false;
|
|
_context52.next = 10;
|
|
break;
|
|
|
|
case 7:
|
|
_context52.prev = 7;
|
|
_context52.t0 = _context52["catch"](1);
|
|
this._isV0 = true;
|
|
|
|
case 10:
|
|
_context52.prev = 10;
|
|
_context52.next = 13;
|
|
return this.readOnlyContract.VERSION();
|
|
|
|
case 13:
|
|
this._version = _context52.sent.toNumber();
|
|
_context52.next = 19;
|
|
break;
|
|
|
|
case 16:
|
|
_context52.prev = 16;
|
|
_context52.t1 = _context52["catch"](10);
|
|
this._version = 0;
|
|
|
|
case 19:
|
|
this._shouldCheckVersion = false;
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context52.stop();
|
|
}
|
|
}
|
|
}, _callee52, this, [[1, 7], [10, 16]]);
|
|
}));
|
|
|
|
function checkVersion() {
|
|
return _checkVersion.apply(this, arguments);
|
|
}
|
|
|
|
return checkVersion;
|
|
}()
|
|
/**
|
|
* Fetches the proof for the current signer for a particular wallet.
|
|
*
|
|
* @param merkleRoot - The merkle root of the condition to check.
|
|
* @returns - The proof for the current signer for the specified condition.
|
|
*/
|
|
;
|
|
|
|
_proto.getClaimerProofs =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getClaimerProofs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee53(merkleRoot, addressToClaim) {
|
|
var _yield$this$getMetada5, metadata, snapshot, jsonConvert, snapshotData, item;
|
|
|
|
return runtime_1.wrap(function _callee53$(_context53) {
|
|
while (1) {
|
|
switch (_context53.prev = _context53.next) {
|
|
case 0:
|
|
if (addressToClaim) {
|
|
_context53.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context53.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
addressToClaim = _context53.sent;
|
|
|
|
case 4:
|
|
_context53.next = 6;
|
|
return this.getMetadata();
|
|
|
|
case 6:
|
|
_yield$this$getMetada5 = _context53.sent;
|
|
metadata = _yield$this$getMetada5.metadata;
|
|
_context53.next = 10;
|
|
return this.sdk.getStorage().get(metadata == null ? void 0 : metadata.merkle[merkleRoot]);
|
|
|
|
case 10:
|
|
snapshot = _context53.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
var _addressToClaim;
|
|
|
|
return c.address.toLowerCase() === ((_addressToClaim = addressToClaim) == null ? void 0 : _addressToClaim.toLowerCase());
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context53.next = 16;
|
|
break;
|
|
}
|
|
|
|
return _context53.abrupt("return", []);
|
|
|
|
case 16:
|
|
return _context53.abrupt("return", item.proof);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context53.stop();
|
|
}
|
|
}
|
|
}, _callee53, this);
|
|
}));
|
|
|
|
function getClaimerProofs(_x50, _x51) {
|
|
return _getClaimerProofs.apply(this, arguments);
|
|
}
|
|
|
|
return getClaimerProofs;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee54() {
|
|
return runtime_1.wrap(function _callee54$(_context54) {
|
|
while (1) {
|
|
switch (_context54.prev = _context54.next) {
|
|
case 0:
|
|
return _context54.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context54.stop();
|
|
}
|
|
}
|
|
}, _callee54, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee55(restricted) {
|
|
return runtime_1.wrap(function _callee55$(_context55) {
|
|
while (1) {
|
|
switch (_context55.prev = _context55.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context55.t0 = this;
|
|
_context55.t1 = ["admin"];
|
|
_context55.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context55.t2 = _context55.sent;
|
|
_context55.next = 8;
|
|
return _context55.t0.onlyRoles.call(_context55.t0, _context55.t1, _context55.t2);
|
|
|
|
case 8:
|
|
_context55.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context55.abrupt("return", _context55.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context55.stop();
|
|
}
|
|
}
|
|
}, _callee55, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x52) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}();
|
|
|
|
return DropModule;
|
|
}(ModuleWithRoles);
|
|
/**
|
|
* @internal
|
|
* @deprecated - Should use DropV2
|
|
*/
|
|
|
|
DropModule.moduleType = ModuleType.DROP;
|
|
DropModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.transfer];
|
|
|
|
var DropV1Module = /*#__PURE__*/function (_ModuleWithRoles2) {
|
|
_inheritsLoose(DropV1Module, _ModuleWithRoles2);
|
|
|
|
function DropV1Module() {
|
|
var _this9;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this9 = _ModuleWithRoles2.call.apply(_ModuleWithRoles2, [this].concat(args)) || this;
|
|
_this9.storage = _this9.sdk.getStorage();
|
|
return _this9;
|
|
}
|
|
|
|
var _proto2 = DropV1Module.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto2.getModuleRoles = function getModuleRoles() {
|
|
return DropModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto2.connectContract = function connectContract() {
|
|
return LazyNFT__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto2.getModuleType = function getModuleType() {
|
|
return DropModule.moduleType;
|
|
};
|
|
|
|
_proto2.getTokenMetadata = /*#__PURE__*/function () {
|
|
var _getTokenMetadata3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee56(tokenId) {
|
|
return runtime_1.wrap(function _callee56$(_context56) {
|
|
while (1) {
|
|
switch (_context56.prev = _context56.next) {
|
|
case 0:
|
|
_context56.next = 2;
|
|
return getTokenMetadata(this.readOnlyContract, tokenId, this.sdk.getStorage());
|
|
|
|
case 2:
|
|
return _context56.abrupt("return", _context56.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context56.stop();
|
|
}
|
|
}
|
|
}, _callee56, this);
|
|
}));
|
|
|
|
function getTokenMetadata$1(_x53) {
|
|
return _getTokenMetadata3.apply(this, arguments);
|
|
}
|
|
|
|
return getTokenMetadata$1;
|
|
}();
|
|
|
|
_proto2.get = /*#__PURE__*/function () {
|
|
var _get2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee57(tokenId) {
|
|
var _yield$Promise$all3, owner, metadata;
|
|
|
|
return runtime_1.wrap(function _callee57$(_context57) {
|
|
while (1) {
|
|
switch (_context57.prev = _context57.next) {
|
|
case 0:
|
|
_context57.next = 2;
|
|
return Promise.all([this.ownerOf(tokenId)["catch"](function () {
|
|
return AddressZero;
|
|
}), this.getTokenMetadata(tokenId)]);
|
|
|
|
case 2:
|
|
_yield$Promise$all3 = _context57.sent;
|
|
owner = _yield$Promise$all3[0];
|
|
metadata = _yield$Promise$all3[1];
|
|
return _context57.abrupt("return", {
|
|
owner: owner,
|
|
metadata: metadata
|
|
});
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context57.stop();
|
|
}
|
|
}
|
|
}, _callee57, this);
|
|
}));
|
|
|
|
function get(_x54) {
|
|
return _get2.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}();
|
|
|
|
_proto2.getAll = /*#__PURE__*/function () {
|
|
var _getAll2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee58(queryParams) {
|
|
var _this10 = this;
|
|
|
|
var start, count, maxId;
|
|
return runtime_1.wrap(function _callee58$(_context58) {
|
|
while (1) {
|
|
switch (_context58.prev = _context58.next) {
|
|
case 0:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context58.t0 = Math;
|
|
_context58.next = 5;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 5:
|
|
_context58.t1 = _context58.sent.toNumber();
|
|
_context58.t2 = start + count;
|
|
maxId = _context58.t0.min.call(_context58.t0, _context58.t1, _context58.t2);
|
|
_context58.next = 10;
|
|
return Promise.all(Array.from(Array(maxId - start).keys()).map(function (i) {
|
|
return _this10.get((start + i).toString());
|
|
}));
|
|
|
|
case 10:
|
|
return _context58.abrupt("return", _context58.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context58.stop();
|
|
}
|
|
}
|
|
}, _callee58, this);
|
|
}));
|
|
|
|
function getAll(_x55) {
|
|
return _getAll2.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}();
|
|
|
|
_proto2.getAllUnclaimed = /*#__PURE__*/function () {
|
|
var _getAllUnclaimed2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee59(queryParams) {
|
|
var _this11 = this;
|
|
|
|
var start, count, maxId, unmintedId;
|
|
return runtime_1.wrap(function _callee59$(_context59) {
|
|
while (1) {
|
|
switch (_context59.prev = _context59.next) {
|
|
case 0:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context59.t0 = BigNumber;
|
|
_context59.t1 = Math;
|
|
_context59.next = 6;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 6:
|
|
_context59.t2 = _context59.sent.toNumber();
|
|
_context59.t3 = start + count;
|
|
_context59.t4 = _context59.t1.min.call(_context59.t1, _context59.t2, _context59.t3);
|
|
maxId = _context59.t0.from.call(_context59.t0, _context59.t4);
|
|
_context59.next = 12;
|
|
return this.readOnlyContract.nextMintTokenId();
|
|
|
|
case 12:
|
|
unmintedId = _context59.sent;
|
|
_context59.next = 15;
|
|
return Promise.all(Array.from(Array(maxId.sub(unmintedId).toNumber()).keys()).map(function (i) {
|
|
return _this11.getTokenMetadata(unmintedId.add(i).toString());
|
|
}));
|
|
|
|
case 15:
|
|
return _context59.abrupt("return", _context59.sent.map(function (metadata) {
|
|
return {
|
|
owner: AddressZero,
|
|
metadata: metadata
|
|
};
|
|
}));
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context59.stop();
|
|
}
|
|
}
|
|
}, _callee59, this);
|
|
}));
|
|
|
|
function getAllUnclaimed(_x56) {
|
|
return _getAllUnclaimed2.apply(this, arguments);
|
|
}
|
|
|
|
return getAllUnclaimed;
|
|
}();
|
|
|
|
_proto2.getAllClaimed = /*#__PURE__*/function () {
|
|
var _getAllClaimed2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee60(queryParams) {
|
|
var _this12 = this;
|
|
|
|
var start, count, maxId;
|
|
return runtime_1.wrap(function _callee60$(_context60) {
|
|
while (1) {
|
|
switch (_context60.prev = _context60.next) {
|
|
case 0:
|
|
start = BigNumber.from((queryParams == null ? void 0 : queryParams.start) || 0).toNumber();
|
|
count = BigNumber.from((queryParams == null ? void 0 : queryParams.count) || DEFAULT_QUERY_ALL_COUNT).toNumber();
|
|
_context60.t0 = Math;
|
|
_context60.next = 5;
|
|
return this.readOnlyContract.nextMintTokenId();
|
|
|
|
case 5:
|
|
_context60.t1 = _context60.sent.toNumber();
|
|
_context60.t2 = start + count;
|
|
maxId = _context60.t0.min.call(_context60.t0, _context60.t1, _context60.t2);
|
|
_context60.next = 10;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this12.get(i.toString());
|
|
}));
|
|
|
|
case 10:
|
|
return _context60.abrupt("return", _context60.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context60.stop();
|
|
}
|
|
}
|
|
}, _callee60, this);
|
|
}));
|
|
|
|
function getAllClaimed(_x57) {
|
|
return _getAllClaimed2.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimed;
|
|
}();
|
|
|
|
_proto2.ownerOf = /*#__PURE__*/function () {
|
|
var _ownerOf2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee61(tokenId) {
|
|
return runtime_1.wrap(function _callee61$(_context61) {
|
|
while (1) {
|
|
switch (_context61.prev = _context61.next) {
|
|
case 0:
|
|
_context61.next = 2;
|
|
return this.readOnlyContract.ownerOf(tokenId);
|
|
|
|
case 2:
|
|
return _context61.abrupt("return", _context61.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context61.stop();
|
|
}
|
|
}
|
|
}, _callee61, this);
|
|
}));
|
|
|
|
function ownerOf(_x58) {
|
|
return _ownerOf2.apply(this, arguments);
|
|
}
|
|
|
|
return ownerOf;
|
|
}();
|
|
|
|
_proto2.getOwned = /*#__PURE__*/function () {
|
|
var _getOwned2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee62(_address) {
|
|
var _this13 = this;
|
|
|
|
var address, balance, indices, tokenIds;
|
|
return runtime_1.wrap(function _callee62$(_context62) {
|
|
while (1) {
|
|
switch (_context62.prev = _context62.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context62.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context62.t0 = _address;
|
|
_context62.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context62.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context62.t0 = _context62.sent;
|
|
|
|
case 7:
|
|
address = _context62.t0;
|
|
_context62.next = 10;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 10:
|
|
balance = _context62.sent;
|
|
indices = Array.from(Array(balance.toNumber()).keys());
|
|
_context62.next = 14;
|
|
return Promise.all(indices.map(function (i) {
|
|
return _this13.readOnlyContract.tokenOfOwnerByIndex(address, i);
|
|
}));
|
|
|
|
case 14:
|
|
tokenIds = _context62.sent;
|
|
_context62.next = 17;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this13.get(tokenId.toString());
|
|
}));
|
|
|
|
case 17:
|
|
return _context62.abrupt("return", _context62.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context62.stop();
|
|
}
|
|
}
|
|
}, _callee62, this);
|
|
}));
|
|
|
|
function getOwned(_x59) {
|
|
return _getOwned2.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}();
|
|
|
|
_proto2.transformResultToClaimCondition = /*#__PURE__*/function () {
|
|
var _transformResultToClaimCondition2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee63(pm) {
|
|
var cv;
|
|
return runtime_1.wrap(function _callee63$(_context63) {
|
|
while (1) {
|
|
switch (_context63.prev = _context63.next) {
|
|
case 0:
|
|
_context63.next = 2;
|
|
return getCurrencyValue(this.providerOrSigner, pm.currency, pm.pricePerToken);
|
|
|
|
case 2:
|
|
cv = _context63.sent;
|
|
return _context63.abrupt("return", {
|
|
startTimestamp: new Date(BigNumber.from(pm.startTimestamp).toNumber() * 1000),
|
|
maxMintSupply: pm.maxMintSupply.toString(),
|
|
currentMintSupply: pm.currentMintSupply.toString(),
|
|
availableSupply: BigNumber.from(pm.maxMintSupply).sub(pm.currentMintSupply).toString(),
|
|
quantityLimitPerTransaction: pm.quantityLimitPerTransaction.toString(),
|
|
waitTimeSecondsLimitPerTransaction: pm.waitTimeSecondsLimitPerTransaction.toString(),
|
|
price: BigNumber.from(pm.pricePerToken),
|
|
pricePerToken: BigNumber.from(pm.pricePerToken),
|
|
currency: pm.currency,
|
|
currencyContract: pm.currency,
|
|
currencyMetadata: cv,
|
|
merkleRoot: pm.merkleRoot
|
|
});
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context63.stop();
|
|
}
|
|
}
|
|
}, _callee63, this);
|
|
}));
|
|
|
|
function transformResultToClaimCondition(_x60) {
|
|
return _transformResultToClaimCondition2.apply(this, arguments);
|
|
}
|
|
|
|
return transformResultToClaimCondition;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.getActiveClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto2.getActiveMintCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getActiveMintCondition2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee64() {
|
|
var index;
|
|
return runtime_1.wrap(function _callee64$(_context64) {
|
|
while (1) {
|
|
switch (_context64.prev = _context64.next) {
|
|
case 0:
|
|
_context64.next = 2;
|
|
return this.readOnlyContract.getLastStartedMintConditionIndex();
|
|
|
|
case 2:
|
|
index = _context64.sent;
|
|
_context64.next = 5;
|
|
return this.readOnlyContract.mintConditions(index);
|
|
|
|
case 5:
|
|
return _context64.abrupt("return", _context64.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context64.stop();
|
|
}
|
|
}
|
|
}, _callee64, this);
|
|
}));
|
|
|
|
function getActiveMintCondition() {
|
|
return _getActiveMintCondition2.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveMintCondition;
|
|
}();
|
|
|
|
_proto2.getActiveClaimCondition = /*#__PURE__*/function () {
|
|
var _getActiveClaimCondition2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee65() {
|
|
var index, mc;
|
|
return runtime_1.wrap(function _callee65$(_context65) {
|
|
while (1) {
|
|
switch (_context65.prev = _context65.next) {
|
|
case 0:
|
|
_context65.next = 2;
|
|
return this.readOnlyContract.getLastStartedMintConditionIndex();
|
|
|
|
case 2:
|
|
index = _context65.sent;
|
|
_context65.next = 5;
|
|
return this.readOnlyContract.mintConditions(index);
|
|
|
|
case 5:
|
|
mc = _context65.sent;
|
|
_context65.next = 8;
|
|
return this.transformResultToClaimCondition(mc);
|
|
|
|
case 8:
|
|
return _context65.abrupt("return", _context65.sent);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context65.stop();
|
|
}
|
|
}
|
|
}, _callee65, this);
|
|
}));
|
|
|
|
function getActiveClaimCondition() {
|
|
return _getActiveClaimCondition2.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveClaimCondition;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.getAllClaimConditions} instead
|
|
*/
|
|
;
|
|
|
|
_proto2.getAllMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllMintConditions2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee66() {
|
|
var conditions, i;
|
|
return runtime_1.wrap(function _callee66$(_context66) {
|
|
while (1) {
|
|
switch (_context66.prev = _context66.next) {
|
|
case 0:
|
|
conditions = [];
|
|
i = 0;
|
|
|
|
case 2:
|
|
_context66.prev = 2;
|
|
_context66.t0 = conditions;
|
|
_context66.next = 6;
|
|
return this.readOnlyContract.mintConditions(i);
|
|
|
|
case 6:
|
|
_context66.t1 = _context66.sent;
|
|
|
|
_context66.t0.push.call(_context66.t0, _context66.t1);
|
|
|
|
_context66.next = 13;
|
|
break;
|
|
|
|
case 10:
|
|
_context66.prev = 10;
|
|
_context66.t2 = _context66["catch"](2);
|
|
return _context66.abrupt("break", 16);
|
|
|
|
case 13:
|
|
i++;
|
|
_context66.next = 2;
|
|
break;
|
|
|
|
case 16:
|
|
return _context66.abrupt("return", conditions);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context66.stop();
|
|
}
|
|
}
|
|
}, _callee66, this, [[2, 10]]);
|
|
}));
|
|
|
|
function getAllMintConditions() {
|
|
return _getAllMintConditions2.apply(this, arguments);
|
|
}
|
|
|
|
return getAllMintConditions;
|
|
}();
|
|
|
|
_proto2.getAllClaimConditions = /*#__PURE__*/function () {
|
|
var _getAllClaimConditions2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee67() {
|
|
var conditions, i, mc;
|
|
return runtime_1.wrap(function _callee67$(_context67) {
|
|
while (1) {
|
|
switch (_context67.prev = _context67.next) {
|
|
case 0:
|
|
conditions = [];
|
|
i = 0;
|
|
|
|
case 2:
|
|
_context67.prev = 2;
|
|
_context67.next = 5;
|
|
return this.readOnlyContract.mintConditions(i);
|
|
|
|
case 5:
|
|
mc = _context67.sent;
|
|
_context67.t0 = conditions;
|
|
_context67.next = 9;
|
|
return this.transformResultToClaimCondition(mc);
|
|
|
|
case 9:
|
|
_context67.t1 = _context67.sent;
|
|
|
|
_context67.t0.push.call(_context67.t0, _context67.t1);
|
|
|
|
_context67.next = 16;
|
|
break;
|
|
|
|
case 13:
|
|
_context67.prev = 13;
|
|
_context67.t2 = _context67["catch"](2);
|
|
return _context67.abrupt("break", 19);
|
|
|
|
case 16:
|
|
i++;
|
|
_context67.next = 2;
|
|
break;
|
|
|
|
case 19:
|
|
return _context67.abrupt("return", conditions);
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context67.stop();
|
|
}
|
|
}
|
|
}, _callee67, this, [[2, 13]]);
|
|
}));
|
|
|
|
function getAllClaimConditions() {
|
|
return _getAllClaimConditions2.apply(this, arguments);
|
|
}
|
|
|
|
return getAllClaimConditions;
|
|
}();
|
|
|
|
_proto2.totalSupply = /*#__PURE__*/function () {
|
|
var _totalSupply2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee68() {
|
|
return runtime_1.wrap(function _callee68$(_context68) {
|
|
while (1) {
|
|
switch (_context68.prev = _context68.next) {
|
|
case 0:
|
|
_context68.next = 2;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 2:
|
|
return _context68.abrupt("return", _context68.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context68.stop();
|
|
}
|
|
}
|
|
}, _callee68, this);
|
|
}));
|
|
|
|
function totalSupply() {
|
|
return _totalSupply2.apply(this, arguments);
|
|
}
|
|
|
|
return totalSupply;
|
|
}();
|
|
|
|
_proto2.maxTotalSupply = /*#__PURE__*/function () {
|
|
var _maxTotalSupply2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee69() {
|
|
return runtime_1.wrap(function _callee69$(_context69) {
|
|
while (1) {
|
|
switch (_context69.prev = _context69.next) {
|
|
case 0:
|
|
_context69.next = 2;
|
|
return this.readOnlyContract.maxTotalSupply();
|
|
|
|
case 2:
|
|
return _context69.abrupt("return", _context69.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context69.stop();
|
|
}
|
|
}
|
|
}, _callee69, this);
|
|
}));
|
|
|
|
function maxTotalSupply() {
|
|
return _maxTotalSupply2.apply(this, arguments);
|
|
}
|
|
|
|
return maxTotalSupply;
|
|
}();
|
|
|
|
_proto2.totalUnclaimedSupply = /*#__PURE__*/function () {
|
|
var _totalUnclaimedSupply2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee70() {
|
|
return runtime_1.wrap(function _callee70$(_context70) {
|
|
while (1) {
|
|
switch (_context70.prev = _context70.next) {
|
|
case 0:
|
|
_context70.next = 2;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 2:
|
|
_context70.t0 = _context70.sent;
|
|
_context70.next = 5;
|
|
return this.totalClaimedSupply();
|
|
|
|
case 5:
|
|
_context70.t1 = _context70.sent;
|
|
return _context70.abrupt("return", _context70.t0.sub.call(_context70.t0, _context70.t1));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context70.stop();
|
|
}
|
|
}
|
|
}, _callee70, this);
|
|
}));
|
|
|
|
function totalUnclaimedSupply() {
|
|
return _totalUnclaimedSupply2.apply(this, arguments);
|
|
}
|
|
|
|
return totalUnclaimedSupply;
|
|
}();
|
|
|
|
_proto2.totalClaimedSupply = /*#__PURE__*/function () {
|
|
var _totalClaimedSupply2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee71() {
|
|
return runtime_1.wrap(function _callee71$(_context71) {
|
|
while (1) {
|
|
switch (_context71.prev = _context71.next) {
|
|
case 0:
|
|
_context71.next = 2;
|
|
return this.readOnlyContract.nextMintTokenId();
|
|
|
|
case 2:
|
|
return _context71.abrupt("return", _context71.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context71.stop();
|
|
}
|
|
}
|
|
}, _callee71, this);
|
|
}));
|
|
|
|
function totalClaimedSupply() {
|
|
return _totalClaimedSupply2.apply(this, arguments);
|
|
}
|
|
|
|
return totalClaimedSupply;
|
|
}();
|
|
|
|
_proto2.balanceOf = /*#__PURE__*/function () {
|
|
var _balanceOf2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee72(address) {
|
|
return runtime_1.wrap(function _callee72$(_context72) {
|
|
while (1) {
|
|
switch (_context72.prev = _context72.next) {
|
|
case 0:
|
|
_context72.next = 2;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 2:
|
|
return _context72.abrupt("return", _context72.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context72.stop();
|
|
}
|
|
}
|
|
}, _callee72, this);
|
|
}));
|
|
|
|
function balanceOf(_x61) {
|
|
return _balanceOf2.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto2.balance = /*#__PURE__*/function () {
|
|
var _balance4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee73() {
|
|
return runtime_1.wrap(function _callee73$(_context73) {
|
|
while (1) {
|
|
switch (_context73.prev = _context73.next) {
|
|
case 0:
|
|
_context73.t0 = this;
|
|
_context73.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context73.t1 = _context73.sent;
|
|
_context73.next = 6;
|
|
return _context73.t0.balanceOf.call(_context73.t0, _context73.t1);
|
|
|
|
case 6:
|
|
return _context73.abrupt("return", _context73.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context73.stop();
|
|
}
|
|
}
|
|
}, _callee73, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance4.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto2.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee74(address, operator) {
|
|
return runtime_1.wrap(function _callee74$(_context74) {
|
|
while (1) {
|
|
switch (_context74.prev = _context74.next) {
|
|
case 0:
|
|
_context74.next = 2;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 2:
|
|
return _context74.abrupt("return", _context74.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context74.stop();
|
|
}
|
|
}
|
|
}, _callee74, this);
|
|
}));
|
|
|
|
function isApproved(_x62, _x63) {
|
|
return _isApproved2.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto2.setApproval =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setApproval2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee75(operator, approved) {
|
|
return runtime_1.wrap(function _callee75$(_context75) {
|
|
while (1) {
|
|
switch (_context75.prev = _context75.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context75.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context75.abrupt("return", _context75.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context75.stop();
|
|
}
|
|
}
|
|
}, _callee75, this);
|
|
}));
|
|
|
|
function setApproval(_x64, _x65) {
|
|
return _setApproval2.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}();
|
|
|
|
_proto2.transfer = /*#__PURE__*/function () {
|
|
var _transfer2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee76(to, tokenId) {
|
|
var from;
|
|
return runtime_1.wrap(function _callee76$(_context76) {
|
|
while (1) {
|
|
switch (_context76.prev = _context76.next) {
|
|
case 0:
|
|
_context76.next = 2;
|
|
return this.getSignerAddress();
|
|
|
|
case 2:
|
|
from = _context76.sent;
|
|
_context76.next = 5;
|
|
return this.sendTransaction("safeTransferFrom(address,address,uint256)", [from, to, tokenId]);
|
|
|
|
case 5:
|
|
return _context76.abrupt("return", _context76.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context76.stop();
|
|
}
|
|
}
|
|
}, _callee76, this);
|
|
}));
|
|
|
|
function transfer(_x66, _x67) {
|
|
return _transfer2.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}()
|
|
/**
|
|
* @deprecated - The function has been deprecated. Use `createBatch` instead.
|
|
*/
|
|
;
|
|
|
|
_proto2.lazyMint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMint2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee77(metadata) {
|
|
return runtime_1.wrap(function _callee77$(_context77) {
|
|
while (1) {
|
|
switch (_context77.prev = _context77.next) {
|
|
case 0:
|
|
_context77.next = 2;
|
|
return this.lazyMintBatch([metadata]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context77.stop();
|
|
}
|
|
}
|
|
}, _callee77, this);
|
|
}));
|
|
|
|
function lazyMint(_x68) {
|
|
return _lazyMint2.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMint;
|
|
}();
|
|
|
|
_proto2.pinToIpfs = /*#__PURE__*/function () {
|
|
var _pinToIpfs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee78(files) {
|
|
return runtime_1.wrap(function _callee78$(_context78) {
|
|
while (1) {
|
|
switch (_context78.prev = _context78.next) {
|
|
case 0:
|
|
_context78.next = 2;
|
|
return this.storage.uploadBatch(files, this.address);
|
|
|
|
case 2:
|
|
return _context78.abrupt("return", _context78.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context78.stop();
|
|
}
|
|
}
|
|
}, _callee78, this);
|
|
}));
|
|
|
|
function pinToIpfs(_x69) {
|
|
return _pinToIpfs.apply(this, arguments);
|
|
}
|
|
|
|
return pinToIpfs;
|
|
}()
|
|
/**
|
|
* @deprecated - The function has been deprecated. Use `mintBatch` instead.
|
|
*/
|
|
;
|
|
|
|
_proto2.lazyMintBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMintBatch2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee79(metadatas) {
|
|
var _yield$this$sdk$getSt4, baseUri, uris;
|
|
|
|
return runtime_1.wrap(function _callee79$(_context79) {
|
|
while (1) {
|
|
switch (_context79.prev = _context79.next) {
|
|
case 0:
|
|
_context79.next = 2;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas);
|
|
|
|
case 2:
|
|
_yield$this$sdk$getSt4 = _context79.sent;
|
|
baseUri = _yield$this$sdk$getSt4.baseUri;
|
|
uris = Array.from(Array(metadatas.length).keys()).map(function (i) {
|
|
return "" + baseUri + i + "/";
|
|
});
|
|
_context79.next = 7;
|
|
return this.sendTransaction("lazyMintBatch", [uris]);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context79.stop();
|
|
}
|
|
}
|
|
}, _callee79, this);
|
|
}));
|
|
|
|
function lazyMintBatch(_x70) {
|
|
return _lazyMintBatch2.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMintBatch;
|
|
}()
|
|
/**
|
|
* @deprecated - The function has been deprecated. Use `mintBatch` instead.
|
|
*/
|
|
;
|
|
|
|
_proto2.lazyMintAmount =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _lazyMintAmount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee80(amount) {
|
|
return runtime_1.wrap(function _callee80$(_context80) {
|
|
while (1) {
|
|
switch (_context80.prev = _context80.next) {
|
|
case 0:
|
|
_context80.next = 2;
|
|
return this.sendTransaction("lazyMintAmount", [amount]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context80.stop();
|
|
}
|
|
}
|
|
}, _callee80, this);
|
|
}));
|
|
|
|
function lazyMintAmount(_x71) {
|
|
return _lazyMintAmount.apply(this, arguments);
|
|
}
|
|
|
|
return lazyMintAmount;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.setClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto2.setMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setMintConditions2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee81(factory) {
|
|
return runtime_1.wrap(function _callee81$(_context81) {
|
|
while (1) {
|
|
switch (_context81.prev = _context81.next) {
|
|
case 0:
|
|
return _context81.abrupt("return", this.setClaimCondition(factory));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context81.stop();
|
|
}
|
|
}
|
|
}, _callee81, this);
|
|
}));
|
|
|
|
function setMintConditions(_x72) {
|
|
return _setMintConditions2.apply(this, arguments);
|
|
}
|
|
|
|
return setMintConditions;
|
|
}()
|
|
/**
|
|
* @deprecated - Use {@link DropModule.setClaimCondition} instead
|
|
*/
|
|
;
|
|
|
|
_proto2.setClaimConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setClaimConditions2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee82(factory) {
|
|
return runtime_1.wrap(function _callee82$(_context82) {
|
|
while (1) {
|
|
switch (_context82.prev = _context82.next) {
|
|
case 0:
|
|
return _context82.abrupt("return", this.setClaimCondition(factory));
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context82.stop();
|
|
}
|
|
}
|
|
}, _callee82, this);
|
|
}));
|
|
|
|
function setClaimConditions(_x73) {
|
|
return _setClaimConditions2.apply(this, arguments);
|
|
}
|
|
|
|
return setClaimConditions;
|
|
}()
|
|
/**
|
|
* Sets public mint conditions for the next minting using the
|
|
* claim condition factory.
|
|
*
|
|
* @param factory - The claim condition factory.
|
|
*/
|
|
;
|
|
|
|
_proto2.setClaimCondition =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setClaimCondition2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee83(factory) {
|
|
var conditions, merkleInfo, _yield$this$getMetada6, metadata, metatdataUri, encoded;
|
|
|
|
return runtime_1.wrap(function _callee83$(_context83) {
|
|
while (1) {
|
|
switch (_context83.prev = _context83.next) {
|
|
case 0:
|
|
_context83.next = 2;
|
|
return factory.buildConditionsForDropV1();
|
|
|
|
case 2:
|
|
conditions = _context83.sent;
|
|
merkleInfo = {};
|
|
factory.allSnapshots().forEach(function (s) {
|
|
merkleInfo[s.merkleRoot] = s.snapshotUri;
|
|
});
|
|
_context83.next = 7;
|
|
return this.getMetadata(false);
|
|
|
|
case 7:
|
|
_yield$this$getMetada6 = _context83.sent;
|
|
metadata = _yield$this$getMetada6.metadata;
|
|
!metadata ? process.env.NODE_ENV !== "production" ? invariant(false, "Metadata is not set, this should never happen") : invariant(false) : void 0;
|
|
|
|
if (factory.allSnapshots().length === 0 && "merkle" in metadata) {
|
|
metadata["merkle"] = {};
|
|
} else {
|
|
metadata["merkle"] = merkleInfo;
|
|
}
|
|
|
|
_context83.next = 13;
|
|
return this.storage.upload(JSON.stringify(metadata));
|
|
|
|
case 13:
|
|
metatdataUri = _context83.sent;
|
|
encoded = [this.contract["interface"].encodeFunctionData("setContractURI", [metatdataUri]), this.contract["interface"].encodeFunctionData("setPublicMintConditions", [conditions])];
|
|
_context83.next = 17;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 17:
|
|
return _context83.abrupt("return", _context83.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context83.stop();
|
|
}
|
|
}
|
|
}, _callee83, this);
|
|
}));
|
|
|
|
function setClaimCondition(_x74) {
|
|
return _setClaimCondition2.apply(this, arguments);
|
|
}
|
|
|
|
return setClaimCondition;
|
|
}()
|
|
/**
|
|
* Creates a claim condition factory
|
|
*
|
|
* @returns - A new claim condition factory
|
|
*/
|
|
;
|
|
|
|
_proto2.getClaimConditionsFactory = function getClaimConditionsFactory() {
|
|
var createSnapshotFunc = this.sdk.createSnapshot.bind(this.sdk);
|
|
var factory = new ClaimConditionFactory(createSnapshotFunc);
|
|
return factory;
|
|
}
|
|
/**
|
|
* @deprecated - Use the {@link DropModule.getClaimConditionsFactory} instead.
|
|
*/
|
|
;
|
|
|
|
_proto2.getMintConditionsFactory = function getMintConditionsFactory() {
|
|
return this.getClaimConditionsFactory();
|
|
}
|
|
/**
|
|
* @deprecated - Use the {@link DropModule.setClaimConditions} instead.
|
|
*/
|
|
;
|
|
|
|
_proto2.setPublicMintConditions =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setPublicMintConditions2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee84(conditions) {
|
|
var _conditions;
|
|
|
|
return runtime_1.wrap(function _callee84$(_context84) {
|
|
while (1) {
|
|
switch (_context84.prev = _context84.next) {
|
|
case 0:
|
|
_conditions = conditions.map(function (c) {
|
|
return {
|
|
startTimestamp: c.startTimestampInSeconds || 0,
|
|
maxMintSupply: c.maxMintSupply,
|
|
currentMintSupply: 0,
|
|
quantityLimitPerTransaction: c.quantityLimitPerTransaction || c.maxMintSupply,
|
|
waitTimeSecondsLimitPerTransaction: c.waitTimeSecondsLimitPerTransaction || 0,
|
|
pricePerToken: c.pricePerToken || 0,
|
|
currency: c.currency || AddressZero,
|
|
merkleRoot: c.merkleRoot || hexZeroPad([0], 32)
|
|
};
|
|
});
|
|
_context84.next = 3;
|
|
return this.sendTransaction("setPublicMintConditions", [_conditions]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context84.stop();
|
|
}
|
|
}
|
|
}, _callee84, this);
|
|
}));
|
|
|
|
function setPublicMintConditions(_x75) {
|
|
return _setPublicMintConditions2.apply(this, arguments);
|
|
}
|
|
|
|
return setPublicMintConditions;
|
|
}();
|
|
|
|
_proto2.canClaim = /*#__PURE__*/function () {
|
|
var _canClaim2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee85(quantity, proofs) {
|
|
var mintCondition, overrides, owner, erc20, spender, allowance, totalPrice;
|
|
return runtime_1.wrap(function _callee85$(_context85) {
|
|
while (1) {
|
|
switch (_context85.prev = _context85.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context85.prev = 1;
|
|
_context85.next = 4;
|
|
return this.getActiveClaimCondition();
|
|
|
|
case 4:
|
|
mintCondition = _context85.sent;
|
|
_context85.next = 7;
|
|
return this.getCallOverrides();
|
|
|
|
case 7:
|
|
_context85.t0 = _context85.sent;
|
|
|
|
if (_context85.t0) {
|
|
_context85.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context85.t0 = {};
|
|
|
|
case 10:
|
|
overrides = _context85.t0;
|
|
_context85.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
owner = _context85.sent;
|
|
|
|
if (!mintCondition.merkleRoot) {
|
|
_context85.next = 18;
|
|
break;
|
|
}
|
|
|
|
_context85.next = 17;
|
|
return this.getClaimerProofs(mintCondition == null ? void 0 : mintCondition.merkleRoot, owner);
|
|
|
|
case 17:
|
|
proofs = _context85.sent;
|
|
|
|
case 18:
|
|
if (!mintCondition.pricePerToken.gt(0)) {
|
|
_context85.next = 30;
|
|
break;
|
|
}
|
|
|
|
if (!(mintCondition.currency === AddressZero)) {
|
|
_context85.next = 23;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = BigNumber.from(mintCondition.pricePerToken).mul(quantity);
|
|
_context85.next = 30;
|
|
break;
|
|
|
|
case 23:
|
|
erc20 = ERC20__factory.connect(mintCondition.currency, this.providerOrSigner);
|
|
spender = this.address;
|
|
_context85.next = 27;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 27:
|
|
allowance = _context85.sent;
|
|
totalPrice = BigNumber.from(mintCondition.pricePerToken).mul(BigNumber.from(quantity));
|
|
|
|
if (allowance.lt(totalPrice)) ;
|
|
|
|
case 30:
|
|
_context85.next = 32;
|
|
return this.contract.callStatic.claim(quantity, proofs, overrides);
|
|
|
|
case 32:
|
|
return _context85.abrupt("return", true);
|
|
|
|
case 35:
|
|
_context85.prev = 35;
|
|
_context85.t1 = _context85["catch"](1);
|
|
return _context85.abrupt("return", false);
|
|
|
|
case 38:
|
|
case "end":
|
|
return _context85.stop();
|
|
}
|
|
}
|
|
}, _callee85, this, [[1, 35]]);
|
|
}));
|
|
|
|
function canClaim(_x76, _x77) {
|
|
return _canClaim2.apply(this, arguments);
|
|
}
|
|
|
|
return canClaim;
|
|
}()
|
|
/**
|
|
* Fetches the proof for the current signer for a particular wallet.
|
|
*
|
|
* @param merkleRoot - The merkle root of the condition to check.
|
|
* @returns - The proof for the current signer for the specified condition.
|
|
*/
|
|
;
|
|
|
|
_proto2.getClaimerProofs =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getClaimerProofs2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee86(merkleRoot, addressToClaim) {
|
|
var _yield$this$getMetada7, metadata, snapshot, jsonConvert, snapshotData, item;
|
|
|
|
return runtime_1.wrap(function _callee86$(_context86) {
|
|
while (1) {
|
|
switch (_context86.prev = _context86.next) {
|
|
case 0:
|
|
if (addressToClaim) {
|
|
_context86.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context86.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
addressToClaim = _context86.sent;
|
|
|
|
case 4:
|
|
_context86.next = 6;
|
|
return this.getMetadata();
|
|
|
|
case 6:
|
|
_yield$this$getMetada7 = _context86.sent;
|
|
metadata = _yield$this$getMetada7.metadata;
|
|
_context86.next = 10;
|
|
return this.storage.get(metadata == null ? void 0 : metadata.merkle[merkleRoot]);
|
|
|
|
case 10:
|
|
snapshot = _context86.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
var _addressToClaim2;
|
|
|
|
return c.address.toLowerCase() === ((_addressToClaim2 = addressToClaim) == null ? void 0 : _addressToClaim2.toLowerCase());
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context86.next = 16;
|
|
break;
|
|
}
|
|
|
|
return _context86.abrupt("return", []);
|
|
|
|
case 16:
|
|
return _context86.abrupt("return", item.proof);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context86.stop();
|
|
}
|
|
}
|
|
}, _callee86, this);
|
|
}));
|
|
|
|
function getClaimerProofs(_x78, _x79) {
|
|
return _getClaimerProofs2.apply(this, arguments);
|
|
}
|
|
|
|
return getClaimerProofs;
|
|
}();
|
|
|
|
_proto2.claim = /*#__PURE__*/function () {
|
|
var _claim2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee88(quantity, proofs) {
|
|
var _this14 = this;
|
|
|
|
var mintCondition, _yield$this$getMetada8, metadata, addressToClaim, snapshot, jsonConvert, snapshotData, item, overrides, erc20, owner, spender, allowance, totalPrice, receipt, event, startingIndex, endingIndex, tokenIds, i;
|
|
|
|
return runtime_1.wrap(function _callee88$(_context88) {
|
|
while (1) {
|
|
switch (_context88.prev = _context88.next) {
|
|
case 0:
|
|
if (proofs === void 0) {
|
|
proofs = [/*#__PURE__*/hexZeroPad([0], 32)];
|
|
}
|
|
|
|
_context88.next = 3;
|
|
return this.getActiveClaimCondition();
|
|
|
|
case 3:
|
|
mintCondition = _context88.sent;
|
|
_context88.next = 6;
|
|
return this.getMetadata();
|
|
|
|
case 6:
|
|
_yield$this$getMetada8 = _context88.sent;
|
|
metadata = _yield$this$getMetada8.metadata;
|
|
_context88.next = 10;
|
|
return this.getSignerAddress();
|
|
|
|
case 10:
|
|
addressToClaim = _context88.sent;
|
|
|
|
if (mintCondition.merkleRoot.toString().startsWith(AddressZero)) {
|
|
_context88.next = 21;
|
|
break;
|
|
}
|
|
|
|
_context88.next = 14;
|
|
return this.storage.get(metadata == null ? void 0 : metadata.merkle[mintCondition.merkleRoot.toString()]);
|
|
|
|
case 14:
|
|
snapshot = _context88.sent;
|
|
jsonConvert = new JsonConvert();
|
|
snapshotData = jsonConvert.deserializeObject(JSON.parse(snapshot), Snapshot);
|
|
item = snapshotData.claims.find(function (c) {
|
|
return c.address.toLowerCase() === addressToClaim.toLowerCase();
|
|
});
|
|
|
|
if (!(item === undefined)) {
|
|
_context88.next = 20;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No claim found for this address");
|
|
|
|
case 20:
|
|
proofs = item.proof;
|
|
|
|
case 21:
|
|
_context88.next = 23;
|
|
return this.getCallOverrides();
|
|
|
|
case 23:
|
|
_context88.t0 = _context88.sent;
|
|
|
|
if (_context88.t0) {
|
|
_context88.next = 26;
|
|
break;
|
|
}
|
|
|
|
_context88.t0 = {};
|
|
|
|
case 26:
|
|
overrides = _context88.t0;
|
|
|
|
if (!mintCondition.pricePerToken.gt(0)) {
|
|
_context88.next = 44;
|
|
break;
|
|
}
|
|
|
|
if (!(mintCondition.currency === AddressZero)) {
|
|
_context88.next = 32;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = BigNumber.from(mintCondition.pricePerToken).mul(quantity);
|
|
_context88.next = 44;
|
|
break;
|
|
|
|
case 32:
|
|
erc20 = ERC20__factory.connect(mintCondition.currency, this.providerOrSigner);
|
|
_context88.next = 35;
|
|
return this.getSignerAddress();
|
|
|
|
case 35:
|
|
owner = _context88.sent;
|
|
spender = this.address;
|
|
_context88.next = 39;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 39:
|
|
allowance = _context88.sent;
|
|
totalPrice = BigNumber.from(mintCondition.pricePerToken).mul(BigNumber.from(quantity));
|
|
|
|
if (!allowance.lt(totalPrice)) {
|
|
_context88.next = 44;
|
|
break;
|
|
}
|
|
|
|
_context88.next = 44;
|
|
return this.sendContractTransaction(erc20, "approve", [spender, allowance.add(totalPrice)]);
|
|
|
|
case 44:
|
|
_context88.next = 46;
|
|
return this.sendTransaction("claim", [quantity, proofs], overrides);
|
|
|
|
case 46:
|
|
receipt = _context88.sent;
|
|
event = this.parseEventLogs("Claimed", receipt == null ? void 0 : receipt.logs);
|
|
startingIndex = event.startTokenId;
|
|
endingIndex = startingIndex.add(quantity);
|
|
tokenIds = [];
|
|
|
|
for (i = startingIndex; i.lt(endingIndex); i = i.add(1)) {
|
|
tokenIds.push(BigNumber.from(i.toString()));
|
|
}
|
|
|
|
_context88.next = 54;
|
|
return Promise.all(tokenIds.map( /*#__PURE__*/function () {
|
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee87(t) {
|
|
return runtime_1.wrap(function _callee87$(_context87) {
|
|
while (1) {
|
|
switch (_context87.prev = _context87.next) {
|
|
case 0:
|
|
_context87.next = 2;
|
|
return _this14.get(t.toString());
|
|
|
|
case 2:
|
|
return _context87.abrupt("return", _context87.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context87.stop();
|
|
}
|
|
}
|
|
}, _callee87);
|
|
}));
|
|
|
|
return function (_x82) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 54:
|
|
return _context88.abrupt("return", _context88.sent);
|
|
|
|
case 55:
|
|
case "end":
|
|
return _context88.stop();
|
|
}
|
|
}
|
|
}, _callee88, this);
|
|
}));
|
|
|
|
function claim(_x80, _x81) {
|
|
return _claim2.apply(this, arguments);
|
|
}
|
|
|
|
return claim;
|
|
}();
|
|
|
|
_proto2.burn = /*#__PURE__*/function () {
|
|
var _burn2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee89(tokenId) {
|
|
return runtime_1.wrap(function _callee89$(_context89) {
|
|
while (1) {
|
|
switch (_context89.prev = _context89.next) {
|
|
case 0:
|
|
_context89.next = 2;
|
|
return this.sendTransaction("burn", [tokenId]);
|
|
|
|
case 2:
|
|
return _context89.abrupt("return", _context89.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context89.stop();
|
|
}
|
|
}
|
|
}, _callee89, this);
|
|
}));
|
|
|
|
function burn(_x83) {
|
|
return _burn2.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto2.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee90(from, to, tokenId) {
|
|
return runtime_1.wrap(function _callee90$(_context90) {
|
|
while (1) {
|
|
switch (_context90.prev = _context90.next) {
|
|
case 0:
|
|
_context90.next = 2;
|
|
return this.sendTransaction("transferFrom", [from, to, tokenId]);
|
|
|
|
case 2:
|
|
return _context90.abrupt("return", _context90.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context90.stop();
|
|
}
|
|
}
|
|
}, _callee90, this);
|
|
}));
|
|
|
|
function transferFrom(_x84, _x85, _x86) {
|
|
return _transferFrom2.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto2.setModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setModuleMetadata2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee91(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee91$(_context91) {
|
|
while (1) {
|
|
switch (_context91.prev = _context91.next) {
|
|
case 0:
|
|
_context91.next = 2;
|
|
return this.storage.uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context91.sent;
|
|
_context91.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context91.abrupt("return", _context91.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context91.stop();
|
|
}
|
|
}
|
|
}, _callee91, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x87) {
|
|
return _setModuleMetadata2.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto2.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee92(amount) {
|
|
var _yield$this$getMetada9, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee92$(_context92) {
|
|
while (1) {
|
|
switch (_context92.prev = _context92.next) {
|
|
case 0:
|
|
_context92.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
_yield$this$getMetada9 = _context92.sent;
|
|
metadata = _yield$this$getMetada9.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context92.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context92.t0 = this.storage;
|
|
_context92.t1 = _extends({}, metadata);
|
|
_context92.t2 = this.address;
|
|
_context92.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context92.t3 = _context92.sent;
|
|
_context92.next = 16;
|
|
return _context92.t0.uploadMetadata.call(_context92.t0, _context92.t1, _context92.t2, _context92.t3);
|
|
|
|
case 16:
|
|
uri = _context92.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context92.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context92.abrupt("return", _context92.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context92.stop();
|
|
}
|
|
}
|
|
}, _callee92, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x88) {
|
|
return _setRoyaltyBps2.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}();
|
|
|
|
_proto2.setBaseTokenUri = /*#__PURE__*/function () {
|
|
var _setBaseTokenUri = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee93(uri) {
|
|
return runtime_1.wrap(function _callee93$(_context93) {
|
|
while (1) {
|
|
switch (_context93.prev = _context93.next) {
|
|
case 0:
|
|
_context93.next = 2;
|
|
return this.sendTransaction("setBaseTokenURI", [uri]);
|
|
|
|
case 2:
|
|
return _context93.abrupt("return", _context93.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context93.stop();
|
|
}
|
|
}
|
|
}, _callee93, this);
|
|
}));
|
|
|
|
function setBaseTokenUri(_x89) {
|
|
return _setBaseTokenUri.apply(this, arguments);
|
|
}
|
|
|
|
return setBaseTokenUri;
|
|
}();
|
|
|
|
_proto2.setMaxTotalSupply = /*#__PURE__*/function () {
|
|
var _setMaxTotalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee94(amount) {
|
|
return runtime_1.wrap(function _callee94$(_context94) {
|
|
while (1) {
|
|
switch (_context94.prev = _context94.next) {
|
|
case 0:
|
|
_context94.next = 2;
|
|
return this.sendTransaction("setMaxTotalSupply", [amount]);
|
|
|
|
case 2:
|
|
return _context94.abrupt("return", _context94.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context94.stop();
|
|
}
|
|
}
|
|
}, _callee94, this);
|
|
}));
|
|
|
|
function setMaxTotalSupply(_x90) {
|
|
return _setMaxTotalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return setMaxTotalSupply;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto2.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee95() {
|
|
return runtime_1.wrap(function _callee95$(_context95) {
|
|
while (1) {
|
|
switch (_context95.prev = _context95.next) {
|
|
case 0:
|
|
_context95.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context95.abrupt("return", _context95.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context95.stop();
|
|
}
|
|
}
|
|
}, _callee95, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps2.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto2.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee96() {
|
|
var _metadata$metadata2;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee96$(_context96) {
|
|
while (1) {
|
|
switch (_context96.prev = _context96.next) {
|
|
case 0:
|
|
_context96.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context96.sent;
|
|
|
|
if (!(((_metadata$metadata2 = metadata.metadata) == null ? void 0 : _metadata$metadata2.fee_recipient) !== undefined)) {
|
|
_context96.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context96.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context96.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context96.stop();
|
|
}
|
|
}
|
|
}, _callee96, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress2.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}()
|
|
/**
|
|
* Create batch allows you to create a batch of tokens
|
|
* in one transaction. This function can only be called
|
|
* once per module at the moment.
|
|
*
|
|
* @beta
|
|
*
|
|
* @param metadatas - The metadata to include in the batch.
|
|
*/
|
|
;
|
|
|
|
_proto2.createBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createBatch2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee97(metadatas) {
|
|
var startFileNumber, _yield$this$storage$u, baseUri, encoded;
|
|
|
|
return runtime_1.wrap(function _callee97$(_context97) {
|
|
while (1) {
|
|
switch (_context97.prev = _context97.next) {
|
|
case 0:
|
|
_context97.next = 2;
|
|
return this.canCreateBatch();
|
|
|
|
case 2:
|
|
if (_context97.sent) {
|
|
_context97.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Batch already created!");
|
|
|
|
case 4:
|
|
_context97.next = 6;
|
|
return this.readOnlyContract.nextMintTokenId();
|
|
|
|
case 6:
|
|
startFileNumber = _context97.sent;
|
|
_context97.next = 9;
|
|
return this.storage.uploadMetadataBatch(metadatas, this.address, startFileNumber.toNumber());
|
|
|
|
case 9:
|
|
_yield$this$storage$u = _context97.sent;
|
|
baseUri = _yield$this$storage$u.baseUri;
|
|
encoded = [this.contract["interface"].encodeFunctionData("setBaseTokenURI", [baseUri]), this.contract["interface"].encodeFunctionData("lazyMintAmount", [metadatas.length])];
|
|
_context97.next = 14;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 14:
|
|
return _context97.abrupt("return", []);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context97.stop();
|
|
}
|
|
}
|
|
}, _callee97, this);
|
|
}));
|
|
|
|
function createBatch(_x91) {
|
|
return _createBatch2.apply(this, arguments);
|
|
}
|
|
|
|
return createBatch;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*
|
|
* @returns - True if the batch has been created, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto2.canCreateBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _canCreateBatch2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee98() {
|
|
return runtime_1.wrap(function _callee98$(_context98) {
|
|
while (1) {
|
|
switch (_context98.prev = _context98.next) {
|
|
case 0:
|
|
_context98.next = 2;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 2:
|
|
return _context98.abrupt("return", _context98.sent.eq(0));
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context98.stop();
|
|
}
|
|
}
|
|
}, _callee98, this);
|
|
}));
|
|
|
|
function canCreateBatch() {
|
|
return _canCreateBatch2.apply(this, arguments);
|
|
}
|
|
|
|
return canCreateBatch;
|
|
}();
|
|
|
|
_proto2.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee99() {
|
|
return runtime_1.wrap(function _callee99$(_context99) {
|
|
while (1) {
|
|
switch (_context99.prev = _context99.next) {
|
|
case 0:
|
|
return _context99.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context99.stop();
|
|
}
|
|
}
|
|
}, _callee99, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted2.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto2.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee100(restricted) {
|
|
return runtime_1.wrap(function _callee100$(_context100) {
|
|
while (1) {
|
|
switch (_context100.prev = _context100.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context100.t0 = this;
|
|
_context100.t1 = ["admin"];
|
|
_context100.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context100.t2 = _context100.sent;
|
|
_context100.next = 8;
|
|
return _context100.t0.onlyRoles.call(_context100.t0, _context100.t1, _context100.t2);
|
|
|
|
case 8:
|
|
_context100.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context100.abrupt("return", _context100.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context100.stop();
|
|
}
|
|
}
|
|
}, _callee100, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x92) {
|
|
return _setRestrictedTransfer2.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}();
|
|
|
|
return DropV1Module;
|
|
}(ModuleWithRoles); // This is a deprecated class, DropV1, see above
|
|
|
|
|
|
DropV1Module.moduleType = ModuleType.DROP;
|
|
DropV1Module.roles = [RolesMap.admin, RolesMap.minter, RolesMap.transfer];
|
|
|
|
/**
|
|
* Access this module by calling {@link ThirdwebSDK.getMarketModule}
|
|
* @public
|
|
*
|
|
* @deprecated
|
|
*/
|
|
|
|
var MarketModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(MarketModule, _ModuleWithRoles);
|
|
|
|
function MarketModule() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = MarketModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return MarketModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return Market__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return MarketModule.moduleType;
|
|
};
|
|
|
|
_proto.transformResultToListing = /*#__PURE__*/function () {
|
|
var _transformResultToListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(listing) {
|
|
var currency, metadata;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
currency = null;
|
|
_context.prev = 1;
|
|
_context.next = 4;
|
|
return getCurrencyValue(this.providerOrSigner, listing.currency, listing.pricePerToken);
|
|
|
|
case 4:
|
|
currency = _context.sent;
|
|
_context.next = 9;
|
|
break;
|
|
|
|
case 7:
|
|
_context.prev = 7;
|
|
_context.t0 = _context["catch"](1);
|
|
|
|
case 9:
|
|
metadata = undefined;
|
|
_context.prev = 10;
|
|
_context.next = 13;
|
|
return getMetadataWithoutContract(this.providerOrSigner, listing.assetContract, listing.tokenId.toString(), this.sdk.getStorage());
|
|
|
|
case 13:
|
|
metadata = _context.sent;
|
|
_context.next = 18;
|
|
break;
|
|
|
|
case 16:
|
|
_context.prev = 16;
|
|
_context.t1 = _context["catch"](10);
|
|
|
|
case 18:
|
|
return _context.abrupt("return", {
|
|
id: listing.listingId.toString(),
|
|
seller: listing.seller,
|
|
tokenId: listing.tokenId.toString(),
|
|
tokenContract: listing.assetContract,
|
|
tokenMetadata: metadata,
|
|
quantity: listing.quantity,
|
|
price: listing.pricePerToken,
|
|
currencyContract: listing.currency,
|
|
tokensPerBuyer: listing.tokensPerBuyer,
|
|
currencyMetadata: currency,
|
|
saleStart: listing.saleStart.gt(0) ? new Date(listing.saleStart.toNumber() * 1000) : null,
|
|
saleEnd: listing.saleEnd.gt(0) && listing.saleEnd.lte(Number.MAX_SAFE_INTEGER - 1) ? new Date(listing.saleEnd.toNumber() * 1000) : null
|
|
});
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this, [[1, 7], [10, 16]]);
|
|
}));
|
|
|
|
function transformResultToListing(_x) {
|
|
return _transformResultToListing.apply(this, arguments);
|
|
}
|
|
|
|
return transformResultToListing;
|
|
}()
|
|
/**
|
|
* @deprecated Use {@link MarketModule.get} instead.
|
|
*/
|
|
;
|
|
|
|
_proto.getListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(listingId) {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return this.get(listingId);
|
|
|
|
case 2:
|
|
return _context2.abrupt("return", _context2.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getListing(_x2) {
|
|
return _getListing.apply(this, arguments);
|
|
}
|
|
|
|
return getListing;
|
|
}()
|
|
/**
|
|
* @deprecated Use {@link MarketModule.getAll} instead.
|
|
*/
|
|
;
|
|
|
|
_proto.getAllListings =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllListings = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(filter) {
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.getAll(filter);
|
|
|
|
case 2:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getAllListings(_x3) {
|
|
return _getAllListings.apply(this, arguments);
|
|
}
|
|
|
|
return getAllListings;
|
|
}();
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return this.readOnlyContract.listings(listingId);
|
|
|
|
case 2:
|
|
listing = _context4.sent;
|
|
_context4.next = 5;
|
|
return this.transformResultToListing(listing);
|
|
|
|
case 5:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function get(_x4) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}();
|
|
|
|
_proto.getAll = /*#__PURE__*/function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(filter) {
|
|
var _this = this;
|
|
|
|
var listings;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
listings = [];
|
|
|
|
if (filter) {
|
|
_context5.next = 9;
|
|
break;
|
|
}
|
|
|
|
_context5.t0 = listings;
|
|
_context5.next = 5;
|
|
return this.readOnlyContract.getAllListings();
|
|
|
|
case 5:
|
|
_context5.t1 = _context5.sent;
|
|
listings = _context5.t0.concat.call(_context5.t0, _context5.t1);
|
|
_context5.next = 38;
|
|
break;
|
|
|
|
case 9:
|
|
if (!(filter.tokenContract && filter.tokenId)) {
|
|
_context5.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context5.t2 = listings;
|
|
_context5.next = 13;
|
|
return this.readOnlyContract.getListingsByAsset(filter.tokenContract, filter.tokenId);
|
|
|
|
case 13:
|
|
_context5.t3 = _context5.sent;
|
|
listings = _context5.t2.concat.call(_context5.t2, _context5.t3);
|
|
_context5.next = 38;
|
|
break;
|
|
|
|
case 17:
|
|
if (!filter.seller) {
|
|
_context5.next = 25;
|
|
break;
|
|
}
|
|
|
|
_context5.t4 = listings;
|
|
_context5.next = 21;
|
|
return this.readOnlyContract.getListingsBySeller(filter.seller);
|
|
|
|
case 21:
|
|
_context5.t5 = _context5.sent;
|
|
listings = _context5.t4.concat.call(_context5.t4, _context5.t5);
|
|
_context5.next = 38;
|
|
break;
|
|
|
|
case 25:
|
|
if (!filter.tokenContract) {
|
|
_context5.next = 33;
|
|
break;
|
|
}
|
|
|
|
_context5.t6 = listings;
|
|
_context5.next = 29;
|
|
return this.readOnlyContract.getListingsByAssetContract(filter.tokenContract);
|
|
|
|
case 29:
|
|
_context5.t7 = _context5.sent;
|
|
listings = _context5.t6.concat.call(_context5.t6, _context5.t7);
|
|
_context5.next = 38;
|
|
break;
|
|
|
|
case 33:
|
|
_context5.t8 = listings;
|
|
_context5.next = 36;
|
|
return this.readOnlyContract.getAllListings();
|
|
|
|
case 36:
|
|
_context5.t9 = _context5.sent;
|
|
listings = _context5.t8.concat.call(_context5.t8, _context5.t9);
|
|
|
|
case 38:
|
|
listings = listings.filter(function (l) {
|
|
if (l.quantity.eq(0)) {
|
|
return false;
|
|
}
|
|
|
|
if (filter) {
|
|
var filterSeller = (filter == null ? void 0 : filter.seller) || "";
|
|
var filterTokenContract = (filter == null ? void 0 : filter.tokenContract) || "";
|
|
var filterTokenId = (filter == null ? void 0 : filter.tokenId) || "";
|
|
|
|
if (filterSeller && filterSeller.toLowerCase() !== l.seller.toLowerCase()) {
|
|
return false;
|
|
}
|
|
|
|
if (filterTokenContract && filterTokenContract.toLowerCase() !== l.assetContract.toLowerCase()) {
|
|
return false;
|
|
}
|
|
|
|
if (filterTokenId && filterTokenId.toLowerCase() !== l.tokenId.toString().toLowerCase()) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}).map(function (l) {
|
|
return _this.transformResultToListing(l);
|
|
});
|
|
_context5.next = 41;
|
|
return Promise.all(listings);
|
|
|
|
case 41:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 42:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getAll(_x5) {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}();
|
|
|
|
_proto.getMarketFeeBps = /*#__PURE__*/function () {
|
|
var _getMarketFeeBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6() {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.next = 2;
|
|
return this.readOnlyContract.marketFeeBps();
|
|
|
|
case 2:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function getMarketFeeBps() {
|
|
return _getMarketFeeBps.apply(this, arguments);
|
|
}
|
|
|
|
return getMarketFeeBps;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.list =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _list = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(assetContract, tokenId, currencyContract, price, quantity, tokensPerBuyer, secondsUntilStart, secondsUntilEnd) {
|
|
var from, erc165, isERC721, asset, approved, isTokenApproved, _asset, _approved, receipt, event, listing, signer;
|
|
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
if (tokensPerBuyer === void 0) {
|
|
tokensPerBuyer = 0;
|
|
}
|
|
|
|
if (secondsUntilStart === void 0) {
|
|
secondsUntilStart = 0;
|
|
}
|
|
|
|
if (secondsUntilEnd === void 0) {
|
|
secondsUntilEnd = 0;
|
|
}
|
|
|
|
_context7.prev = 3;
|
|
_context7.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
from = _context7.sent;
|
|
erc165 = ERC165__factory.connect(assetContract, this.providerOrSigner);
|
|
!(quantity > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "quantity must be greater than 0") : invariant(false) : void 0; // check for token approval
|
|
|
|
_context7.next = 11;
|
|
return erc165.supportsInterface(InterfaceId_IERC721);
|
|
|
|
case 11:
|
|
isERC721 = _context7.sent;
|
|
|
|
if (!isERC721) {
|
|
_context7.next = 28;
|
|
break;
|
|
}
|
|
|
|
asset = ERC721__factory.connect(assetContract, this.providerOrSigner);
|
|
_context7.next = 16;
|
|
return asset.isApprovedForAll(from, this.address);
|
|
|
|
case 16:
|
|
approved = _context7.sent;
|
|
|
|
if (approved) {
|
|
_context7.next = 26;
|
|
break;
|
|
}
|
|
|
|
_context7.next = 20;
|
|
return asset.getApproved(tokenId);
|
|
|
|
case 20:
|
|
_context7.t0 = _context7.sent.toLowerCase();
|
|
_context7.t1 = this.address.toLowerCase();
|
|
isTokenApproved = _context7.t0 === _context7.t1;
|
|
|
|
if (isTokenApproved) {
|
|
_context7.next = 26;
|
|
break;
|
|
}
|
|
|
|
_context7.next = 26;
|
|
return this.sendContractTransaction(asset, "setApprovalForAll", [this.address, true]);
|
|
|
|
case 26:
|
|
_context7.next = 35;
|
|
break;
|
|
|
|
case 28:
|
|
_asset = ERC1155__factory.connect(assetContract, this.providerOrSigner);
|
|
_context7.next = 31;
|
|
return _asset.isApprovedForAll(from, this.address);
|
|
|
|
case 31:
|
|
_approved = _context7.sent;
|
|
|
|
if (_approved) {
|
|
_context7.next = 35;
|
|
break;
|
|
}
|
|
|
|
_context7.next = 35;
|
|
return this.sendContractTransaction(_asset, "setApprovalForAll", [this.address, true]);
|
|
|
|
case 35:
|
|
_context7.next = 37;
|
|
return this.sendTransaction("list", [assetContract, tokenId, currencyContract, price, quantity, tokensPerBuyer, secondsUntilStart, secondsUntilEnd]);
|
|
|
|
case 37:
|
|
receipt = _context7.sent;
|
|
event = this.parseEventLogs("NewListing", receipt == null ? void 0 : receipt.logs);
|
|
listing = event == null ? void 0 : event.listing;
|
|
_context7.next = 42;
|
|
return this.transformResultToListing(listing);
|
|
|
|
case 42:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 45:
|
|
_context7.prev = 45;
|
|
_context7.t2 = _context7["catch"](3);
|
|
_context7.next = 49;
|
|
return this.getSignerAddress();
|
|
|
|
case 49:
|
|
signer = _context7.sent;
|
|
_context7.next = 52;
|
|
return this.sdk.getNFTModule(assetContract).ownerOf(tokenId);
|
|
|
|
case 52:
|
|
_context7.t3 = _context7.sent;
|
|
_context7.t4 = signer;
|
|
|
|
if (!(_context7.t3 !== _context7.t4)) {
|
|
_context7.next = 58;
|
|
break;
|
|
}
|
|
|
|
throw new MissingOwnerRoleError();
|
|
|
|
case 58:
|
|
_context7.next = 60;
|
|
return this.readOnlyContract.restrictedListerRoleOnly();
|
|
|
|
case 60:
|
|
_context7.t6 = _context7.sent;
|
|
|
|
if (!_context7.t6) {
|
|
_context7.next = 67;
|
|
break;
|
|
}
|
|
|
|
_context7.t7 = signer;
|
|
_context7.next = 65;
|
|
return this.getRoleMembers("lister");
|
|
|
|
case 65:
|
|
_context7.t8 = _context7.sent;
|
|
_context7.t6 = !(_context7.t7 in _context7.t8);
|
|
|
|
case 67:
|
|
_context7.t5 = _context7.t6;
|
|
|
|
if (!_context7.t5) {
|
|
_context7.next = 74;
|
|
break;
|
|
}
|
|
|
|
_context7.t9 = signer;
|
|
_context7.next = 72;
|
|
return this.getRoleMembers("admin");
|
|
|
|
case 72:
|
|
_context7.t10 = _context7.sent;
|
|
_context7.t5 = !(_context7.t9 in _context7.t10);
|
|
|
|
case 74:
|
|
if (!_context7.t5) {
|
|
_context7.next = 76;
|
|
break;
|
|
}
|
|
|
|
throw new MissingRoleError(signer, "lister");
|
|
|
|
case 76:
|
|
throw _context7.t2;
|
|
|
|
case 77:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this, [[3, 45]]);
|
|
}));
|
|
|
|
function list(_x6, _x7, _x8, _x9, _x10, _x11, _x12, _x13) {
|
|
return _list.apply(this, arguments);
|
|
}
|
|
|
|
return list;
|
|
}();
|
|
|
|
_proto.unlistAll = /*#__PURE__*/function () {
|
|
var _unlistAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(listingId) {
|
|
var maxQuantity;
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.get(listingId);
|
|
|
|
case 2:
|
|
maxQuantity = _context8.sent.quantity;
|
|
_context8.next = 5;
|
|
return this.unlist(listingId, maxQuantity);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function unlistAll(_x14) {
|
|
return _unlistAll.apply(this, arguments);
|
|
}
|
|
|
|
return unlistAll;
|
|
}();
|
|
|
|
_proto.unlist = /*#__PURE__*/function () {
|
|
var _unlist = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(listingId, quantity) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.sendTransaction("unlist", [listingId, quantity]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function unlist(_x15, _x16) {
|
|
return _unlist.apply(this, arguments);
|
|
}
|
|
|
|
return unlist;
|
|
}();
|
|
|
|
_proto.setRestrictedListerRoleOnly = /*#__PURE__*/function () {
|
|
var _setRestrictedListerRoleOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(restricted) {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.next = 2;
|
|
return this.sendTransaction("setRestrictedListerRoleOnly", [restricted]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function setRestrictedListerRoleOnly(_x17) {
|
|
return _setRestrictedListerRoleOnly.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedListerRoleOnly;
|
|
}();
|
|
|
|
_proto.buy = /*#__PURE__*/function () {
|
|
var _buy = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(listingId, quantity) {
|
|
var listing, owner, spender, totalPrice, erc20, allowance, receipt, event, tokensPerBuyer;
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.prev = 0;
|
|
_context11.next = 3;
|
|
return this.get(listingId);
|
|
|
|
case 3:
|
|
listing = _context11.sent;
|
|
_context11.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
owner = _context11.sent;
|
|
spender = this.address;
|
|
totalPrice = listing.price.mul(BigNumber.from(quantity));
|
|
|
|
if (!(listing.currencyContract && listing.currencyContract !== AddressZero)) {
|
|
_context11.next = 17;
|
|
break;
|
|
}
|
|
|
|
erc20 = ERC20__factory.connect(listing.currencyContract, this.providerOrSigner);
|
|
_context11.next = 13;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 13:
|
|
allowance = _context11.sent;
|
|
|
|
if (!allowance.lt(totalPrice)) {
|
|
_context11.next = 17;
|
|
break;
|
|
}
|
|
|
|
_context11.next = 17;
|
|
return this.sendContractTransaction(erc20, "approve", [spender, allowance.add(totalPrice)]);
|
|
|
|
case 17:
|
|
_context11.next = 19;
|
|
return this.sendTransaction("buy", [listingId, quantity]);
|
|
|
|
case 19:
|
|
receipt = _context11.sent;
|
|
event = this.parseEventLogs("NewSale", receipt == null ? void 0 : receipt.logs);
|
|
_context11.next = 23;
|
|
return this.transformResultToListing(event == null ? void 0 : event.listing);
|
|
|
|
case 23:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 26:
|
|
_context11.prev = 26;
|
|
_context11.t0 = _context11["catch"](0);
|
|
_context11.next = 30;
|
|
return this.get(listingId);
|
|
|
|
case 30:
|
|
tokensPerBuyer = _context11.sent.tokensPerBuyer.toNumber();
|
|
|
|
if (!(quantity > tokensPerBuyer)) {
|
|
_context11.next = 33;
|
|
break;
|
|
}
|
|
|
|
throw new QuantityAboveLimitError(tokensPerBuyer.toString());
|
|
|
|
case 33:
|
|
throw _context11.t0;
|
|
|
|
case 34:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this, [[0, 26]]);
|
|
}));
|
|
|
|
function buy(_x18, _x19) {
|
|
return _buy.apply(this, arguments);
|
|
}
|
|
|
|
return buy;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.setModuleMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context12.sent;
|
|
_context12.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context12.abrupt("return", _context12.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x20) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}();
|
|
|
|
_proto.setMarketFeeBps = /*#__PURE__*/function () {
|
|
var _setMarketFeeBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(fee) {
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.sendTransaction("setMarketFeeBps", [fee]);
|
|
|
|
case 2:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function setMarketFeeBps(_x21) {
|
|
return _setMarketFeeBps.apply(this, arguments);
|
|
}
|
|
|
|
return setMarketFeeBps;
|
|
}();
|
|
|
|
return MarketModule;
|
|
}(ModuleWithRoles);
|
|
MarketModule.moduleType = ModuleType.MARKET;
|
|
MarketModule.roles = [RolesMap.admin, RolesMap.lister, RolesMap.pauser];
|
|
|
|
var MAX_BPS = 10000;
|
|
/**
|
|
* Create your own whitelabel marketplace that enables users to buy and sell any digital assets.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getMarketplaceModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var MarketplaceModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(MarketplaceModule, _ModuleWithRoles);
|
|
|
|
function MarketplaceModule() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _ModuleWithRoles.call.apply(_ModuleWithRoles, [this].concat(args)) || this;
|
|
_this._shouldCheckVersion = true;
|
|
_this._isNewBuy = false;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = MarketplaceModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return MarketplaceModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return Marketplace__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return MarketplaceModule.moduleType;
|
|
}
|
|
/**
|
|
* Create Direct Listing
|
|
*
|
|
* @remarks Create a new listing on the marketplace where people can buy an asset directly.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Data of the listing you want to create
|
|
* const listing = {
|
|
* // address of the contract the asset you want to list is on
|
|
* assetContractAddress: "0x...",
|
|
* // token ID of the asset you want to list
|
|
* tokenId: "0",
|
|
* // in how many seconds with the listing open up
|
|
* startTimeInSeconds: 0,
|
|
* // how long the listing will be open for
|
|
* listingDurationInSeconds: 86400,
|
|
* // how many of the asset you want to list
|
|
* quantity: 1,
|
|
* // address of the currency contract that will be used to pay for the listing
|
|
* currencyContractAddress: "0x0000000000000000000000000000000000000000",
|
|
* // how much the asset will be sold for
|
|
* buyoutPricePerToken: "1",
|
|
* }
|
|
*
|
|
* await module.createDirectListing(listing);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.createDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(listing) {
|
|
var receipt, event;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
this.validateNewListingParam(listing);
|
|
_context.t0 = this;
|
|
_context.t1 = listing.assetContractAddress;
|
|
_context.t2 = listing.tokenId;
|
|
_context.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context.t3 = _context.sent;
|
|
_context.next = 9;
|
|
return _context.t0.handleTokenApproval.call(_context.t0, _context.t1, _context.t2, _context.t3);
|
|
|
|
case 9:
|
|
_context.next = 11;
|
|
return this.sendTransaction("createListing", [{
|
|
assetContract: listing.assetContractAddress,
|
|
tokenId: listing.tokenId,
|
|
buyoutPricePerToken: listing.buyoutPricePerToken,
|
|
currencyToAccept: listing.currencyContractAddress,
|
|
listingType: ListingType.Direct,
|
|
quantityToList: listing.quantity,
|
|
reservePricePerToken: listing.buyoutPricePerToken,
|
|
secondsUntilEndTime: listing.listingDurationInSeconds,
|
|
startTime: listing.startTimeInSeconds
|
|
}]);
|
|
|
|
case 11:
|
|
receipt = _context.sent;
|
|
event = this.parseEventLogs("NewListing", receipt == null ? void 0 : receipt.logs);
|
|
return _context.abrupt("return", event.listingId);
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function createDirectListing(_x) {
|
|
return _createDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return createDirectListing;
|
|
}()
|
|
/**
|
|
* Create Auction
|
|
*
|
|
* @remarks Create a new auction where people can bid on an asset.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Data of the auction you want to create
|
|
* const auction = {
|
|
* // address of the contract the asset you want to list is on
|
|
* assetContractAddress: "0x...",
|
|
* // token ID of the asset you want to list
|
|
* tokenId: "0",
|
|
* // in how many seconds with the listing open up
|
|
* startTimeInSeconds: 0,
|
|
* // how long the listing will be open for
|
|
* listingDurationInSeconds: 86400,
|
|
* // how many of the asset you want to list
|
|
* quantity: 1,
|
|
* // address of the currency contract that will be used to pay for the listing
|
|
* currencyContractAddress: "0x0000000000000000000000000000000000000000",
|
|
* // how much people would have to bid to instantly buy the asset
|
|
* buyoutPricePerToken: "10",
|
|
* // the minimum bid that will be accepted for the token
|
|
* reservePricePerToken: "1",
|
|
* }
|
|
*
|
|
* await module.createAuctionListing(auction);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.createAuctionListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(listing) {
|
|
var receipt, event;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
this.validateNewListingParam(listing);
|
|
_context2.t0 = this;
|
|
_context2.t1 = listing.assetContractAddress;
|
|
_context2.t2 = listing.tokenId;
|
|
_context2.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context2.t3 = _context2.sent;
|
|
_context2.next = 9;
|
|
return _context2.t0.handleTokenApproval.call(_context2.t0, _context2.t1, _context2.t2, _context2.t3);
|
|
|
|
case 9:
|
|
_context2.next = 11;
|
|
return this.sendTransaction("createListing", [{
|
|
assetContract: listing.assetContractAddress,
|
|
tokenId: listing.tokenId,
|
|
buyoutPricePerToken: listing.buyoutPricePerToken,
|
|
currencyToAccept: listing.currencyContractAddress,
|
|
listingType: ListingType.Auction,
|
|
quantityToList: listing.quantity,
|
|
reservePricePerToken: listing.reservePricePerToken,
|
|
secondsUntilEndTime: listing.listingDurationInSeconds,
|
|
startTime: listing.startTimeInSeconds
|
|
}]);
|
|
|
|
case 11:
|
|
receipt = _context2.sent;
|
|
event = this.parseEventLogs("NewListing", receipt == null ? void 0 : receipt.logs);
|
|
return _context2.abrupt("return", event.listingId);
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function createAuctionListing(_x2) {
|
|
return _createAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return createAuctionListing;
|
|
}();
|
|
|
|
_proto.makeDirectListingOffer = /*#__PURE__*/function () {
|
|
var _makeDirectListingOffer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(offer) {
|
|
var quantity, value, overrides;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
if (!isNativeToken(offer.currencyContractAddress)) {
|
|
_context3.next = 2;
|
|
break;
|
|
}
|
|
|
|
throw new Error("You must use the wrapped native token address when making an offer with a native token");
|
|
|
|
case 2:
|
|
_context3.prev = 2;
|
|
_context3.next = 5;
|
|
return this.getDirectListing(offer.listingId);
|
|
|
|
case 5:
|
|
_context3.next = 11;
|
|
break;
|
|
|
|
case 7:
|
|
_context3.prev = 7;
|
|
_context3.t0 = _context3["catch"](2);
|
|
console.error("Failed to get listing, err =", _context3.t0);
|
|
throw new Error("Error getting the listing with id " + offer.listingId);
|
|
|
|
case 11:
|
|
quantity = BigNumber.from(offer.quantityDesired);
|
|
value = BigNumber.from(offer.pricePerToken).mul(quantity);
|
|
_context3.next = 15;
|
|
return this.getCallOverrides();
|
|
|
|
case 15:
|
|
_context3.t1 = _context3.sent;
|
|
|
|
if (_context3.t1) {
|
|
_context3.next = 18;
|
|
break;
|
|
}
|
|
|
|
_context3.t1 = {};
|
|
|
|
case 18:
|
|
overrides = _context3.t1;
|
|
_context3.next = 21;
|
|
return this.setAllowance(value, offer.currencyContractAddress, overrides);
|
|
|
|
case 21:
|
|
_context3.next = 23;
|
|
return this.sendTransaction("offer", [offer.listingId, offer.quantityDesired, offer.currencyContractAddress, offer.pricePerToken], overrides);
|
|
|
|
case 23:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this, [[2, 7]]);
|
|
}));
|
|
|
|
function makeDirectListingOffer(_x3) {
|
|
return _makeDirectListingOffer.apply(this, arguments);
|
|
}
|
|
|
|
return makeDirectListingOffer;
|
|
}();
|
|
|
|
_proto.setAllowance = /*#__PURE__*/function () {
|
|
var _setAllowance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(value, currencyAddress, overrides) {
|
|
var erc20, owner, spender, allowance;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
if (!isNativeToken(currencyAddress)) {
|
|
_context4.next = 4;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = value;
|
|
_context4.next = 15;
|
|
break;
|
|
|
|
case 4:
|
|
erc20 = ERC20__factory.connect(currencyAddress, this.providerOrSigner);
|
|
_context4.next = 7;
|
|
return this.getSignerAddress();
|
|
|
|
case 7:
|
|
owner = _context4.sent;
|
|
spender = this.address;
|
|
_context4.next = 11;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 11:
|
|
allowance = _context4.sent;
|
|
|
|
if (!allowance.lt(value)) {
|
|
_context4.next = 15;
|
|
break;
|
|
}
|
|
|
|
_context4.next = 15;
|
|
return this.sendContractTransaction(erc20, "increaseAllowance", [spender, value.sub(allowance)]);
|
|
|
|
case 15:
|
|
return _context4.abrupt("return", overrides);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function setAllowance(_x4, _x5, _x6) {
|
|
return _setAllowance.apply(this, arguments);
|
|
}
|
|
|
|
return setAllowance;
|
|
}()
|
|
/**
|
|
* Bid On Auction
|
|
*
|
|
* @remarks Make a bid on an auction listings
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the asset you want to bid on
|
|
* const listingId = 0;
|
|
* // The price you are willing to bid for a single token of the listing
|
|
* const pricePerToken = 1;
|
|
*
|
|
* await module.makeAuctionListingBid({ listingId, pricePerToken });
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.makeAuctionListingBid =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _makeAuctionListingBid = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(bid) {
|
|
var listing, bidBuffer, winningBid, isWinningBid, pricePerToken, reservePrice, quantity, value, overrides;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return this.validateAuctionListing(BigNumber.from(bid.listingId));
|
|
|
|
case 2:
|
|
listing = _context5.sent;
|
|
_context5.next = 5;
|
|
return this.getBidBufferBps();
|
|
|
|
case 5:
|
|
bidBuffer = _context5.sent;
|
|
_context5.next = 8;
|
|
return this.getWinningBid(bid.listingId);
|
|
|
|
case 8:
|
|
winningBid = _context5.sent;
|
|
|
|
if (!winningBid) {
|
|
_context5.next = 16;
|
|
break;
|
|
}
|
|
|
|
_context5.next = 12;
|
|
return this.isWinningBid(winningBid.pricePerToken, bid.pricePerToken, bidBuffer);
|
|
|
|
case 12:
|
|
isWinningBid = _context5.sent;
|
|
!isWinningBid ? process.env.NODE_ENV !== "production" ? invariant(false, "Bid price is too low based on the current winning bid and the bid buffer") : invariant(false) : void 0;
|
|
_context5.next = 19;
|
|
break;
|
|
|
|
case 16:
|
|
pricePerToken = BigNumber.from(bid.pricePerToken);
|
|
reservePrice = BigNumber.from(listing.reservePrice);
|
|
!pricePerToken.gte(reservePrice) ? process.env.NODE_ENV !== "production" ? invariant(false, "Bid price is too low based on reserve price") : invariant(false) : void 0;
|
|
|
|
case 19:
|
|
quantity = BigNumber.from(listing.quantity);
|
|
value = BigNumber.from(bid.pricePerToken).mul(quantity);
|
|
_context5.next = 23;
|
|
return this.getCallOverrides();
|
|
|
|
case 23:
|
|
_context5.t0 = _context5.sent;
|
|
|
|
if (_context5.t0) {
|
|
_context5.next = 26;
|
|
break;
|
|
}
|
|
|
|
_context5.t0 = {};
|
|
|
|
case 26:
|
|
overrides = _context5.t0;
|
|
_context5.next = 29;
|
|
return this.setAllowance(value, listing.currencyContractAddress, overrides);
|
|
|
|
case 29:
|
|
_context5.next = 31;
|
|
return this.sendTransaction("offer", [bid.listingId, listing.quantity, listing.currencyContractAddress, bid.pricePerToken], overrides);
|
|
|
|
case 31:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function makeAuctionListingBid(_x7) {
|
|
return _makeAuctionListingBid.apply(this, arguments);
|
|
}
|
|
|
|
return makeAuctionListingBid;
|
|
}();
|
|
|
|
_proto.isWinningBid = /*#__PURE__*/function () {
|
|
var _isWinningBid = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(winningPrice, newBidPrice, bidBuffer) {
|
|
var buffer;
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
bidBuffer = BigNumber.from(bidBuffer);
|
|
winningPrice = BigNumber.from(winningPrice);
|
|
newBidPrice = BigNumber.from(newBidPrice);
|
|
buffer = newBidPrice.sub(winningPrice).mul(MAX_BPS).div(winningPrice);
|
|
return _context6.abrupt("return", buffer.gte(bidBuffer));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6);
|
|
}));
|
|
|
|
function isWinningBid(_x8, _x9, _x10) {
|
|
return _isWinningBid.apply(this, arguments);
|
|
}
|
|
|
|
return isWinningBid;
|
|
}()
|
|
/**
|
|
* Get Auction Winner
|
|
*
|
|
* @remarks Get the winner of the auction after an auction ends.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the auction that closed
|
|
* const listingId = 0;
|
|
*
|
|
* module
|
|
* .getAuctionWinner(listingId)
|
|
* .then((auctionWinner) => console.log(auctionWinner))
|
|
* .catch((err) => console.error(err));
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.getAuctionWinner =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAuctionWinner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(listingId) {
|
|
var closedAuctions, auction;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.readOnlyContract.queryFilter(this.contract.filters.AuctionClosed());
|
|
|
|
case 2:
|
|
closedAuctions = _context7.sent;
|
|
auction = closedAuctions.find(function (a) {
|
|
return a.args.listingId.eq(BigNumber.from(listingId));
|
|
});
|
|
|
|
if (auction) {
|
|
_context7.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Could not find auction with listingId " + listingId + " in closed auctions");
|
|
|
|
case 6:
|
|
return _context7.abrupt("return", auction.args.winningBidder);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getAuctionWinner(_x11) {
|
|
return _getAuctionWinner.apply(this, arguments);
|
|
}
|
|
|
|
return getAuctionWinner;
|
|
}();
|
|
|
|
_proto.getDirectListing = /*#__PURE__*/function () {
|
|
var _getDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.readOnlyContract.listings(listingId);
|
|
|
|
case 2:
|
|
listing = _context8.sent;
|
|
|
|
if (!(listing.listingId.toString() !== listingId.toString())) {
|
|
_context8.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new ListingNotFoundError(this.address, listingId.toString());
|
|
|
|
case 5:
|
|
if (!(listing.listingType !== ListingType.Direct)) {
|
|
_context8.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new WrongListingTypeError(this.address, listingId.toString(), "Auction", "Direct");
|
|
|
|
case 7:
|
|
_context8.next = 9;
|
|
return this.mapDirectListing(listing);
|
|
|
|
case 9:
|
|
return _context8.abrupt("return", _context8.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function getDirectListing(_x12) {
|
|
return _getDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return getDirectListing;
|
|
}();
|
|
|
|
_proto.getAuctionListing = /*#__PURE__*/function () {
|
|
var _getAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.listings(listingId);
|
|
|
|
case 2:
|
|
listing = _context9.sent;
|
|
|
|
if (!(listing.listingId.toString() !== listingId.toString())) {
|
|
_context9.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new ListingNotFoundError(this.address, listingId.toString());
|
|
|
|
case 5:
|
|
if (!(listing.listingType !== ListingType.Auction)) {
|
|
_context9.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new WrongListingTypeError(this.address, listingId.toString(), "Direct", "Auction");
|
|
|
|
case 7:
|
|
_context9.next = 9;
|
|
return this.mapAuctionListing(listing);
|
|
|
|
case 9:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function getAuctionListing(_x13) {
|
|
return _getAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return getAuctionListing;
|
|
}()
|
|
/**
|
|
* Helper method maps the auction listing to the direct listing interface.
|
|
*
|
|
* @internal
|
|
* @param listing - The listing to map, as returned from the contract.
|
|
* @returns - The mapped interface.
|
|
*/
|
|
;
|
|
|
|
_proto.mapDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mapDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(listing) {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.t0 = listing.assetContract;
|
|
_context10.t1 = listing.buyoutPricePerToken;
|
|
_context10.t2 = listing.currency;
|
|
_context10.next = 5;
|
|
return getCurrencyValue(this.providerOrSigner, listing.currency, listing.buyoutPricePerToken);
|
|
|
|
case 5:
|
|
_context10.t3 = _context10.sent;
|
|
_context10.t4 = listing.listingId.toString();
|
|
_context10.t5 = listing.tokenId;
|
|
_context10.t6 = listing.quantity;
|
|
_context10.t7 = listing.startTime;
|
|
_context10.next = 12;
|
|
return getTokenMetadataUsingStorage(listing.assetContract, this.providerOrSigner, listing.tokenId.toString(), this.sdk.getStorage());
|
|
|
|
case 12:
|
|
_context10.t8 = _context10.sent;
|
|
_context10.t9 = listing.endTime;
|
|
_context10.t10 = listing.tokenOwner;
|
|
_context10.t11 = ListingType.Direct;
|
|
return _context10.abrupt("return", {
|
|
assetContractAddress: _context10.t0,
|
|
buyoutPrice: _context10.t1,
|
|
currencyContractAddress: _context10.t2,
|
|
buyoutCurrencyValuePerToken: _context10.t3,
|
|
id: _context10.t4,
|
|
tokenId: _context10.t5,
|
|
quantity: _context10.t6,
|
|
startTimeInSeconds: _context10.t7,
|
|
asset: _context10.t8,
|
|
secondsUntilEnd: _context10.t9,
|
|
sellerAddress: _context10.t10,
|
|
type: _context10.t11
|
|
});
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function mapDirectListing(_x14) {
|
|
return _mapDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return mapDirectListing;
|
|
}()
|
|
/**
|
|
* Helper method maps the auction listing to the auction listing interface.
|
|
*
|
|
* @internal
|
|
* @param listing - The listing to map, as returned from the contract.
|
|
* @returns - The mapped interface.
|
|
*/
|
|
;
|
|
|
|
_proto.mapAuctionListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mapAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(listing) {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.t0 = listing.assetContract;
|
|
_context11.t1 = listing.buyoutPricePerToken;
|
|
_context11.t2 = listing.currency;
|
|
_context11.next = 5;
|
|
return getCurrencyValue(this.providerOrSigner, listing.currency, listing.buyoutPricePerToken);
|
|
|
|
case 5:
|
|
_context11.t3 = _context11.sent;
|
|
_context11.t4 = listing.listingId.toString();
|
|
_context11.t5 = listing.tokenId;
|
|
_context11.t6 = listing.quantity;
|
|
_context11.t7 = listing.startTime;
|
|
_context11.next = 12;
|
|
return getTokenMetadataUsingStorage(listing.assetContract, this.providerOrSigner, listing.tokenId.toString(), this.sdk.getStorage());
|
|
|
|
case 12:
|
|
_context11.t8 = _context11.sent;
|
|
_context11.next = 15;
|
|
return getCurrencyValue(this.providerOrSigner, listing.currency, listing.reservePricePerToken);
|
|
|
|
case 15:
|
|
_context11.t9 = _context11.sent;
|
|
_context11.t10 = listing.reservePricePerToken;
|
|
_context11.t11 = listing.endTime;
|
|
_context11.t12 = listing.tokenOwner;
|
|
_context11.t13 = ListingType.Auction;
|
|
return _context11.abrupt("return", {
|
|
assetContractAddress: _context11.t0,
|
|
buyoutPrice: _context11.t1,
|
|
currencyContractAddress: _context11.t2,
|
|
buyoutCurrencyValuePerToken: _context11.t3,
|
|
id: _context11.t4,
|
|
tokenId: _context11.t5,
|
|
quantity: _context11.t6,
|
|
startTimeInEpochSeconds: _context11.t7,
|
|
asset: _context11.t8,
|
|
reservePriceCurrencyValuePerToken: _context11.t9,
|
|
reservePrice: _context11.t10,
|
|
endTimeInEpochSeconds: _context11.t11,
|
|
sellerAddress: _context11.t12,
|
|
type: _context11.t13
|
|
});
|
|
|
|
case 21:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function mapAuctionListing(_x15) {
|
|
return _mapAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return mapAuctionListing;
|
|
}();
|
|
|
|
_proto.handleTokenApproval = /*#__PURE__*/function () {
|
|
var _handleTokenApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(assetContract, tokenId, from) {
|
|
var erc165, isERC721, asset, approved, isTokenApproved, _asset, _approved;
|
|
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
erc165 = ERC165__factory.connect(assetContract, this.providerOrSigner); // check for token approval
|
|
|
|
_context12.next = 3;
|
|
return erc165.supportsInterface(InterfaceId_IERC721);
|
|
|
|
case 3:
|
|
isERC721 = _context12.sent;
|
|
|
|
if (!isERC721) {
|
|
_context12.next = 20;
|
|
break;
|
|
}
|
|
|
|
asset = ERC721__factory.connect(assetContract, this.providerOrSigner);
|
|
_context12.next = 8;
|
|
return asset.isApprovedForAll(from, this.address);
|
|
|
|
case 8:
|
|
approved = _context12.sent;
|
|
|
|
if (approved) {
|
|
_context12.next = 18;
|
|
break;
|
|
}
|
|
|
|
_context12.next = 12;
|
|
return asset.getApproved(tokenId);
|
|
|
|
case 12:
|
|
_context12.t0 = _context12.sent.toLowerCase();
|
|
_context12.t1 = this.address.toLowerCase();
|
|
isTokenApproved = _context12.t0 === _context12.t1;
|
|
|
|
if (isTokenApproved) {
|
|
_context12.next = 18;
|
|
break;
|
|
}
|
|
|
|
_context12.next = 18;
|
|
return this.sendContractTransaction(asset, "setApprovalForAll", [this.address, true]);
|
|
|
|
case 18:
|
|
_context12.next = 27;
|
|
break;
|
|
|
|
case 20:
|
|
_asset = ERC1155__factory.connect(assetContract, this.providerOrSigner);
|
|
_context12.next = 23;
|
|
return _asset.isApprovedForAll(from, this.address);
|
|
|
|
case 23:
|
|
_approved = _context12.sent;
|
|
|
|
if (_approved) {
|
|
_context12.next = 27;
|
|
break;
|
|
}
|
|
|
|
_context12.next = 27;
|
|
return this.sendContractTransaction(_asset, "setApprovalForAll", [this.address, true]);
|
|
|
|
case 27:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function handleTokenApproval(_x16, _x17, _x18) {
|
|
return _handleTokenApproval.apply(this, arguments);
|
|
}
|
|
|
|
return handleTokenApproval;
|
|
}()
|
|
/**
|
|
* This method checks if the given token is approved for the marketplace module.
|
|
* This is particularly useful for direct listings where the token
|
|
* being listed may be moved before the listing is actually closed.
|
|
*
|
|
* TODO: Ask Jake/Krishang: do we need to also check the owners balance of the token,
|
|
* based on the listing quantity? I.e. query the balance of the tokenId, and check if
|
|
* the seller holds enough of the token
|
|
*
|
|
* @internal
|
|
* @param assetContract - The address of the asset contract.
|
|
* @param tokenId - The token id of the token.
|
|
* @param from - The address of the account that owns the token.
|
|
* @returns - True if the marketplace is approved on the token, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto.isTokenApprovedForMarketplace =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isTokenApprovedForMarketplace = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(assetContract, tokenId, from) {
|
|
var erc165, isERC721, asset, approved, _asset2;
|
|
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.prev = 0;
|
|
erc165 = ERC165__factory.connect(assetContract, this.providerOrSigner); // check for token approval
|
|
|
|
_context13.next = 4;
|
|
return erc165.supportsInterface(InterfaceId_IERC721);
|
|
|
|
case 4:
|
|
isERC721 = _context13.sent;
|
|
|
|
if (!isERC721) {
|
|
_context13.next = 19;
|
|
break;
|
|
}
|
|
|
|
asset = ERC721__factory.connect(assetContract, this.providerOrSigner);
|
|
_context13.next = 9;
|
|
return asset.isApprovedForAll(from, this.address);
|
|
|
|
case 9:
|
|
approved = _context13.sent;
|
|
|
|
if (!approved) {
|
|
_context13.next = 12;
|
|
break;
|
|
}
|
|
|
|
return _context13.abrupt("return", true);
|
|
|
|
case 12:
|
|
_context13.next = 14;
|
|
return asset.getApproved(tokenId);
|
|
|
|
case 14:
|
|
_context13.t0 = _context13.sent.toLowerCase();
|
|
_context13.t1 = this.address.toLowerCase();
|
|
return _context13.abrupt("return", _context13.t0 === _context13.t1);
|
|
|
|
case 19:
|
|
_asset2 = ERC1155__factory.connect(assetContract, this.providerOrSigner);
|
|
_context13.next = 22;
|
|
return _asset2.isApprovedForAll(from, this.address);
|
|
|
|
case 22:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 23:
|
|
_context13.next = 29;
|
|
break;
|
|
|
|
case 25:
|
|
_context13.prev = 25;
|
|
_context13.t2 = _context13["catch"](0);
|
|
console.error("Failed to check if token is approved", _context13.t2);
|
|
return _context13.abrupt("return", false);
|
|
|
|
case 29:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this, [[0, 25]]);
|
|
}));
|
|
|
|
function isTokenApprovedForMarketplace(_x19, _x20, _x21) {
|
|
return _isTokenApprovedForMarketplace.apply(this, arguments);
|
|
}
|
|
|
|
return isTokenApprovedForMarketplace;
|
|
}()
|
|
/**
|
|
* Use this method to check if a direct listing is still valid.
|
|
*
|
|
* Ways a direct listing can become invalid:
|
|
* 1. The asset holder transferred the asset to another wallet
|
|
* 2. The asset holder burned the asset
|
|
* 3. The asset holder removed the approval on the marketplace
|
|
*
|
|
* @internal
|
|
* @param listing - The listing to check.
|
|
* @returns - True if the listing is valid, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto.isStillValidDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isStillValidDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(listing, quantity) {
|
|
var approved, erc165, isERC721, asset, tokenOwnerAddress, _asset3, balance;
|
|
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.next = 2;
|
|
return this.isTokenApprovedForMarketplace(listing.assetContractAddress, listing.tokenId, listing.sellerAddress);
|
|
|
|
case 2:
|
|
approved = _context14.sent;
|
|
|
|
if (approved) {
|
|
_context14.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context14.abrupt("return", false);
|
|
|
|
case 5:
|
|
erc165 = ERC165__factory.connect(listing.assetContractAddress, this.providerOrSigner); // check for token approval
|
|
|
|
_context14.next = 8;
|
|
return erc165.supportsInterface(InterfaceId_IERC721);
|
|
|
|
case 8:
|
|
isERC721 = _context14.sent;
|
|
|
|
if (!isERC721) {
|
|
_context14.next = 17;
|
|
break;
|
|
}
|
|
|
|
asset = ERC721__factory.connect(listing.assetContractAddress, this.providerOrSigner); // burned token would fail on ownerOf cuz invalid token
|
|
|
|
_context14.next = 13;
|
|
return asset.ownerOf(listing.tokenId)["catch"](function () {
|
|
return AddressZero;
|
|
});
|
|
|
|
case 13:
|
|
tokenOwnerAddress = _context14.sent;
|
|
return _context14.abrupt("return", tokenOwnerAddress.toLowerCase() === listing.sellerAddress.toLowerCase());
|
|
|
|
case 17:
|
|
_asset3 = ERC1155__factory.connect(listing.assetContractAddress, this.providerOrSigner);
|
|
_context14.next = 20;
|
|
return _asset3.balanceOf(listing.sellerAddress, listing.tokenId);
|
|
|
|
case 20:
|
|
balance = _context14.sent;
|
|
return _context14.abrupt("return", balance.gte(quantity || listing.quantity));
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function isStillValidDirectListing(_x22, _x23) {
|
|
return _isStillValidDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return isStillValidDirectListing;
|
|
}() // TODO: Complete method implementation with subgraph
|
|
// /**
|
|
// * @beta - This method is not yet complete.
|
|
// *
|
|
// * @param listingId
|
|
// * @returns
|
|
// */
|
|
// public async getActiveOffers(listingId: BigNumberish): Promise<Offer[]> {
|
|
// const listing = await this.validateDirectListing(BigNumber.from(listingId));
|
|
// const offers = await this.readOnlyContract.offers(listing.id, "");
|
|
// return await Promise.all(
|
|
// offers.map(async (offer: any) => {
|
|
// return await this.mapOffer(BigNumber.from(listingId), offer);
|
|
// }),
|
|
// );
|
|
// }
|
|
|
|
/**
|
|
* Used to verify fields in new listing.
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.validateNewListingParam = function validateNewListingParam(param) {
|
|
!(param.assetContractAddress !== undefined && param.assetContractAddress !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Asset contract address is required") : invariant(false) : void 0;
|
|
!(param.buyoutPricePerToken !== undefined && param.buyoutPricePerToken !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Buyout price is required") : invariant(false) : void 0;
|
|
!(param.listingDurationInSeconds !== undefined && param.listingDurationInSeconds !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Listing duration is required") : invariant(false) : void 0;
|
|
!(param.startTimeInSeconds !== undefined && param.startTimeInSeconds !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Start time is required") : invariant(false) : void 0;
|
|
!(param.tokenId !== undefined && param.tokenId !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Token ID is required") : invariant(false) : void 0;
|
|
!(param.quantity !== undefined && param.quantity !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Quantity is required") : invariant(false) : void 0;
|
|
|
|
switch (param.type) {
|
|
case "NewAuctionListing":
|
|
{
|
|
!(param.reservePricePerToken !== undefined && param.reservePricePerToken !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Reserve price is required") : invariant(false) : void 0;
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* Throws error if listing could not be found
|
|
*
|
|
* @param listingId - Listing to check for
|
|
*/
|
|
;
|
|
|
|
_proto.validateDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _validateDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(listingId) {
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.prev = 0;
|
|
_context15.next = 3;
|
|
return this.getDirectListing(listingId);
|
|
|
|
case 3:
|
|
return _context15.abrupt("return", _context15.sent);
|
|
|
|
case 6:
|
|
_context15.prev = 6;
|
|
_context15.t0 = _context15["catch"](0);
|
|
console.error("Error getting the listing with id " + listingId);
|
|
throw _context15.t0;
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this, [[0, 6]]);
|
|
}));
|
|
|
|
function validateDirectListing(_x24) {
|
|
return _validateDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return validateDirectListing;
|
|
}()
|
|
/**
|
|
* Throws error if listing could not be found
|
|
*
|
|
* @param listingId - Listing to check for
|
|
*/
|
|
;
|
|
|
|
_proto.validateAuctionListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _validateAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(listingId) {
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.prev = 0;
|
|
_context16.next = 3;
|
|
return this.getAuctionListing(listingId);
|
|
|
|
case 3:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 6:
|
|
_context16.prev = 6;
|
|
_context16.t0 = _context16["catch"](0);
|
|
console.error("Error getting the listing with id " + listingId);
|
|
throw _context16.t0;
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this, [[0, 6]]);
|
|
}));
|
|
|
|
function validateAuctionListing(_x25) {
|
|
return _validateAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return validateAuctionListing;
|
|
}()
|
|
/**
|
|
* Maps a contract offer to the strict interface
|
|
*
|
|
* @internal
|
|
* @param offer
|
|
* @returns - An `Offer` object
|
|
*/
|
|
;
|
|
|
|
_proto.mapOffer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mapOffer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(listingId, offer) {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
_context17.t0 = offer.quantityDesired;
|
|
_context17.t1 = offer.pricePerToken;
|
|
_context17.t2 = offer.currency;
|
|
_context17.t3 = offer.offeror;
|
|
_context17.t4 = offer.quantityWanted;
|
|
_context17.next = 7;
|
|
return getCurrencyValue(this.providerOrSigner, offer.currency, offer.quantityWanted.mul(offer.pricePerToken));
|
|
|
|
case 7:
|
|
_context17.t5 = _context17.sent;
|
|
_context17.t6 = listingId;
|
|
return _context17.abrupt("return", {
|
|
quantity: _context17.t0,
|
|
pricePerToken: _context17.t1,
|
|
currencyContractAddress: _context17.t2,
|
|
buyerAddress: _context17.t3,
|
|
quantityDesired: _context17.t4,
|
|
currencyValue: _context17.t5,
|
|
listingId: _context17.t6
|
|
});
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function mapOffer(_x26, _x27) {
|
|
return _mapOffer.apply(this, arguments);
|
|
}
|
|
|
|
return mapOffer;
|
|
}();
|
|
|
|
_proto.getActiveOffer = /*#__PURE__*/function () {
|
|
var _getActiveOffer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(listingId, address) {
|
|
var offers;
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
this.validateDirectListing(BigNumber.from(listingId));
|
|
!isAddress(address) ? process.env.NODE_ENV !== "production" ? invariant(false, "Address must be a valid address") : invariant(false) : void 0;
|
|
_context18.next = 4;
|
|
return this.readOnlyContract.offers(listingId, address);
|
|
|
|
case 4:
|
|
offers = _context18.sent;
|
|
|
|
if (!(offers.offeror === AddressZero)) {
|
|
_context18.next = 7;
|
|
break;
|
|
}
|
|
|
|
return _context18.abrupt("return", undefined);
|
|
|
|
case 7:
|
|
_context18.next = 9;
|
|
return this.mapOffer(BigNumber.from(listingId), offers);
|
|
|
|
case 9:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function getActiveOffer(_x28, _x29) {
|
|
return _getActiveOffer.apply(this, arguments);
|
|
}
|
|
|
|
return getActiveOffer;
|
|
}()
|
|
/**
|
|
* Get Highest Bid
|
|
*
|
|
* @remarks Get the current highest bid of an active auction.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the auction that closed
|
|
* const listingId = 0;
|
|
*
|
|
* module
|
|
* .getWinningBid(listingId)
|
|
* .then((offer) => console.log(offer))
|
|
* .catch((err) => console.error(err));
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.getWinningBid =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getWinningBid = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(listingId) {
|
|
var offers;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
this.validateAuctionListing(BigNumber.from(listingId));
|
|
_context19.next = 3;
|
|
return this.readOnlyContract.winningBid(listingId);
|
|
|
|
case 3:
|
|
offers = _context19.sent;
|
|
|
|
if (!(offers.offeror === AddressZero)) {
|
|
_context19.next = 6;
|
|
break;
|
|
}
|
|
|
|
return _context19.abrupt("return", undefined);
|
|
|
|
case 6:
|
|
_context19.next = 8;
|
|
return this.mapOffer(BigNumber.from(listingId), offers);
|
|
|
|
case 8:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function getWinningBid(_x30) {
|
|
return _getWinningBid.apply(this, arguments);
|
|
}
|
|
|
|
return getWinningBid;
|
|
}();
|
|
|
|
_proto.getBidBufferBps = /*#__PURE__*/function () {
|
|
var _getBidBufferBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20() {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
return _context20.abrupt("return", this.readOnlyContract.bidBufferBps());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function getBidBufferBps() {
|
|
return _getBidBufferBps.apply(this, arguments);
|
|
}
|
|
|
|
return getBidBufferBps;
|
|
}();
|
|
|
|
_proto.getTimeBufferInSeconds = /*#__PURE__*/function () {
|
|
var _getTimeBufferInSeconds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21() {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.readOnlyContract.timeBuffer();
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function getTimeBufferInSeconds() {
|
|
return _getTimeBufferInSeconds.apply(this, arguments);
|
|
}
|
|
|
|
return getTimeBufferInSeconds;
|
|
}();
|
|
|
|
_proto.acceptDirectListingOffer = /*#__PURE__*/function () {
|
|
var _acceptDirectListingOffer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(listingId, addressOfOfferor) {
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
/**
|
|
* TODO:
|
|
* - Provide better error handling if offer is too lower.
|
|
*/
|
|
this.validateDirectListing(BigNumber.from(listingId));
|
|
_context22.next = 3;
|
|
return this.sendTransaction("acceptOffer", [listingId, addressOfOfferor]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function acceptDirectListingOffer(_x31, _x32) {
|
|
return _acceptDirectListingOffer.apply(this, arguments);
|
|
}
|
|
|
|
return acceptDirectListingOffer;
|
|
}()
|
|
/**
|
|
* Buyout Auction
|
|
*
|
|
* @remarks Buy a specific direct listing from the marketplace.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the asset you want to buy
|
|
* const listingId = 0;
|
|
*
|
|
* await module.buyoutAuctionListing(listingId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.buyoutAuctionListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _buyoutAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.next = 2;
|
|
return this.validateAuctionListing(BigNumber.from(listingId));
|
|
|
|
case 2:
|
|
listing = _context23.sent;
|
|
_context23.next = 5;
|
|
return this.makeAuctionListingBid({
|
|
listingId: listingId,
|
|
pricePerToken: listing.buyoutPrice
|
|
});
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function buyoutAuctionListing(_x33) {
|
|
return _buyoutAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return buyoutAuctionListing;
|
|
}()
|
|
/**
|
|
* Buy Listing
|
|
*
|
|
* @remarks Buy a specific direct listing from the marketplace.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the asset you want to buy
|
|
* const listingId = 0;
|
|
* // Quantity of the asset you want to buy
|
|
* const quantityDesired = 1;
|
|
*
|
|
* await module.buyoutDirectListing({ listingId, quantityDesired });
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.buyoutDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _buyoutDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24(_buyout) {
|
|
var listing, valid, quantity, value, overrides;
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
_context24.next = 2;
|
|
return this.validateDirectListing(BigNumber.from(_buyout.listingId));
|
|
|
|
case 2:
|
|
listing = _context24.sent;
|
|
_context24.next = 5;
|
|
return this.isStillValidDirectListing(listing, _buyout.quantityDesired);
|
|
|
|
case 5:
|
|
valid = _context24.sent;
|
|
|
|
if (valid) {
|
|
_context24.next = 8;
|
|
break;
|
|
}
|
|
|
|
throw new Error("The asset on this listing has been moved from the listers wallet, this listing is now invalid");
|
|
|
|
case 8:
|
|
quantity = BigNumber.from(_buyout.quantityDesired);
|
|
value = BigNumber.from(listing.buyoutPrice).mul(quantity);
|
|
_context24.next = 12;
|
|
return this.getCallOverrides();
|
|
|
|
case 12:
|
|
_context24.t0 = _context24.sent;
|
|
|
|
if (_context24.t0) {
|
|
_context24.next = 15;
|
|
break;
|
|
}
|
|
|
|
_context24.t0 = {};
|
|
|
|
case 15:
|
|
overrides = _context24.t0;
|
|
_context24.next = 18;
|
|
return this.setAllowance(value, listing.currencyContractAddress, overrides);
|
|
|
|
case 18:
|
|
_context24.next = 20;
|
|
return this.isNewBuy();
|
|
|
|
case 20:
|
|
if (!_context24.sent) {
|
|
_context24.next = 25;
|
|
break;
|
|
}
|
|
|
|
_context24.next = 23;
|
|
return this.sendTransaction("buy", [_buyout.listingId, quantity, listing.currencyContractAddress, value], overrides);
|
|
|
|
case 23:
|
|
_context24.next = 27;
|
|
break;
|
|
|
|
case 25:
|
|
_context24.next = 27;
|
|
return this.sendContractTransaction(new ethers.Contract(this.address, [{
|
|
inputs: [{
|
|
internalType: "uint256",
|
|
name: "_listingId",
|
|
type: "uint256"
|
|
}, {
|
|
internalType: "uint256",
|
|
name: "_quantityToBuy",
|
|
type: "uint256"
|
|
}],
|
|
name: "buy",
|
|
outputs: [],
|
|
stateMutability: "payable",
|
|
type: "function"
|
|
}], this.providerOrSigner), "buy", [_buyout.listingId, quantity], overrides);
|
|
|
|
case 27:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function buyoutDirectListing(_x34) {
|
|
return _buyoutDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return buyoutDirectListing;
|
|
}() // TODO: Complete method implementation with subgraph
|
|
// /**
|
|
// *
|
|
// * @beta - This method is not yet ready for production use
|
|
// *
|
|
// * @param _listingId - The listing ID to get active bids for
|
|
// */
|
|
// public async getActiveBids(_listingId: BigNumberish): Promise<Offer[]> {
|
|
// throw new Error("Method not implemented.");
|
|
// }
|
|
;
|
|
|
|
_proto.updateDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _updateDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25(listing) {
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
_context25.next = 2;
|
|
return this.sendTransaction("updateListing", [listing.id, listing.quantity, // eslint-disable-next-line line-comment-position
|
|
listing.buyoutPrice, listing.buyoutPrice, listing.currencyContractAddress, listing.startTimeInSeconds, listing.secondsUntilEnd]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function updateDirectListing(_x35) {
|
|
return _updateDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return updateDirectListing;
|
|
}();
|
|
|
|
_proto.updateAuctionListing = /*#__PURE__*/function () {
|
|
var _updateAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(listing) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return this.sendTransaction("updateListing", [listing.id, listing.quantity, listing.reservePrice, listing.buyoutPrice, listing.currencyContractAddress, listing.startTimeInEpochSeconds, listing.endTimeInEpochSeconds]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function updateAuctionListing(_x36) {
|
|
return _updateAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return updateAuctionListing;
|
|
}()
|
|
/**
|
|
* Cancel Direct Listing
|
|
*
|
|
* @remarks Cancel a direct listing on the marketplace
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the direct listing you want to cancel
|
|
* const listingId = "0"
|
|
*
|
|
* await module.cancelDirectListing(listingId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.cancelDirectListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _cancelDirectListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
_context27.next = 2;
|
|
return this.validateDirectListing(BigNumber.from(listingId));
|
|
|
|
case 2:
|
|
listing = _context27.sent;
|
|
listing.quantity = 0;
|
|
_context27.next = 6;
|
|
return this.updateDirectListing(listing);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function cancelDirectListing(_x37) {
|
|
return _cancelDirectListing.apply(this, arguments);
|
|
}
|
|
|
|
return cancelDirectListing;
|
|
}()
|
|
/**
|
|
* Cancel Auction Listing
|
|
*
|
|
* @remarks Cancel an auction listing on the marketplace
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The listing ID of the auction listing you want to cancel
|
|
* const listingId = "0"
|
|
*
|
|
* await module.cancelAuctionListing(listingId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.cancelAuctionListing =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _cancelAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28(listingId) {
|
|
var listing, now, startTime, offers;
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return this.validateAuctionListing(BigNumber.from(listingId));
|
|
|
|
case 2:
|
|
listing = _context28.sent;
|
|
now = BigNumber.from(Math.floor(Date.now() / 1000));
|
|
startTime = BigNumber.from(listing.startTimeInEpochSeconds);
|
|
_context28.next = 7;
|
|
return this.readOnlyContract.winningBid(listingId);
|
|
|
|
case 7:
|
|
offers = _context28.sent;
|
|
|
|
if (!(now.gt(startTime) && offers.offeror !== AddressZero)) {
|
|
_context28.next = 10;
|
|
break;
|
|
}
|
|
|
|
throw new AuctionAlreadyStartedError(listingId.toString());
|
|
|
|
case 10:
|
|
_context28.t0 = this;
|
|
_context28.t1 = BigNumber.from(listingId);
|
|
_context28.next = 14;
|
|
return this.getSignerAddress();
|
|
|
|
case 14:
|
|
_context28.t2 = _context28.sent;
|
|
_context28.t3 = [_context28.t1, _context28.t2];
|
|
_context28.next = 18;
|
|
return _context28.t0.sendTransaction.call(_context28.t0, "closeAuction", _context28.t3);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function cancelAuctionListing(_x38) {
|
|
return _cancelAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return cancelAuctionListing;
|
|
}();
|
|
|
|
_proto.closeAuctionListing = /*#__PURE__*/function () {
|
|
var _closeAuctionListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(listingId, closeFor) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
if (closeFor) {
|
|
_context29.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context29.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
closeFor = _context29.sent;
|
|
|
|
case 4:
|
|
_context29.next = 6;
|
|
return this.validateAuctionListing(BigNumber.from(listingId));
|
|
|
|
case 6:
|
|
listing = _context29.sent;
|
|
_context29.prev = 7;
|
|
_context29.next = 10;
|
|
return this.sendTransaction("closeAuction", [BigNumber.from(listingId), closeFor]);
|
|
|
|
case 10:
|
|
_context29.next = 19;
|
|
break;
|
|
|
|
case 12:
|
|
_context29.prev = 12;
|
|
_context29.t0 = _context29["catch"](7);
|
|
|
|
if (!_context29.t0.message.includes("cannot close auction before it has ended")) {
|
|
_context29.next = 18;
|
|
break;
|
|
}
|
|
|
|
throw new AuctionHasNotEndedError(listingId.toString(), listing.endTimeInEpochSeconds.toString());
|
|
|
|
case 18:
|
|
throw _context29.t0;
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this, [[7, 12]]);
|
|
}));
|
|
|
|
function closeAuctionListing(_x39, _x40) {
|
|
return _closeAuctionListing.apply(this, arguments);
|
|
}
|
|
|
|
return closeAuctionListing;
|
|
}();
|
|
|
|
_proto.setBidBufferBps = /*#__PURE__*/function () {
|
|
var _setBidBufferBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30(buffer) {
|
|
var timeBuffer;
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
_context30.t0 = this;
|
|
_context30.t1 = ["admin"];
|
|
_context30.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context30.t2 = _context30.sent;
|
|
_context30.next = 7;
|
|
return _context30.t0.onlyRoles.call(_context30.t0, _context30.t1, _context30.t2);
|
|
|
|
case 7:
|
|
_context30.next = 9;
|
|
return this.getTimeBufferInSeconds();
|
|
|
|
case 9:
|
|
timeBuffer = _context30.sent;
|
|
_context30.next = 12;
|
|
return this.sendTransaction("setAuctionBuffers", [timeBuffer, BigNumber.from(buffer)]);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function setBidBufferBps(_x41) {
|
|
return _setBidBufferBps.apply(this, arguments);
|
|
}
|
|
|
|
return setBidBufferBps;
|
|
}();
|
|
|
|
_proto.setTimeBufferInSeconds = /*#__PURE__*/function () {
|
|
var _setTimeBufferInSeconds = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(buffer) {
|
|
var bidBuffer;
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
_context31.t0 = this;
|
|
_context31.t1 = ["admin"];
|
|
_context31.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context31.t2 = _context31.sent;
|
|
_context31.next = 7;
|
|
return _context31.t0.onlyRoles.call(_context31.t0, _context31.t1, _context31.t2);
|
|
|
|
case 7:
|
|
_context31.next = 9;
|
|
return this.getBidBufferBps();
|
|
|
|
case 9:
|
|
bidBuffer = _context31.sent;
|
|
_context31.next = 12;
|
|
return this.sendTransaction("setAuctionBuffers", [BigNumber.from(buffer), bidBuffer]);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this);
|
|
}));
|
|
|
|
function setTimeBufferInSeconds(_x42) {
|
|
return _setTimeBufferInSeconds.apply(this, arguments);
|
|
}
|
|
|
|
return setTimeBufferInSeconds;
|
|
}();
|
|
|
|
_proto.buyoutListing = /*#__PURE__*/function () {
|
|
var _buyoutListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(listingId, quantityDesired) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
_context32.next = 2;
|
|
return this.readOnlyContract.listings(listingId);
|
|
|
|
case 2:
|
|
listing = _context32.sent;
|
|
|
|
if (!(listing.listingId.toString() !== listingId.toString())) {
|
|
_context32.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new ListingNotFoundError(this.address, listingId.toString());
|
|
|
|
case 5:
|
|
_context32.t0 = listing.listingType;
|
|
_context32.next = _context32.t0 === ListingType.Direct ? 8 : _context32.t0 === ListingType.Auction ? 12 : 15;
|
|
break;
|
|
|
|
case 8:
|
|
!(quantityDesired !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, "quantityDesired is required when buying out a direct listing") : invariant(false) : void 0;
|
|
_context32.next = 11;
|
|
return this.buyoutDirectListing({
|
|
listingId: listingId,
|
|
quantityDesired: quantityDesired
|
|
});
|
|
|
|
case 11:
|
|
return _context32.abrupt("return", _context32.sent);
|
|
|
|
case 12:
|
|
_context32.next = 14;
|
|
return this.buyoutAuctionListing(listingId);
|
|
|
|
case 14:
|
|
return _context32.abrupt("return", _context32.sent);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function buyoutListing(_x43, _x44) {
|
|
return _buyoutListing.apply(this, arguments);
|
|
}
|
|
|
|
return buyoutListing;
|
|
}();
|
|
|
|
_proto.getListing = /*#__PURE__*/function () {
|
|
var _getListing = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(listingId) {
|
|
var listing;
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
_context33.next = 2;
|
|
return this.readOnlyContract.listings(listingId);
|
|
|
|
case 2:
|
|
listing = _context33.sent;
|
|
|
|
if (!(listing.listingId.toString() !== listingId.toString())) {
|
|
_context33.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new ListingNotFoundError(this.address, listingId.toString());
|
|
|
|
case 5:
|
|
_context33.t0 = listing.listingType;
|
|
_context33.next = _context33.t0 === ListingType.Auction ? 8 : _context33.t0 === ListingType.Direct ? 11 : 14;
|
|
break;
|
|
|
|
case 8:
|
|
_context33.next = 10;
|
|
return this.mapAuctionListing(listing);
|
|
|
|
case 10:
|
|
return _context33.abrupt("return", _context33.sent);
|
|
|
|
case 11:
|
|
_context33.next = 13;
|
|
return this.mapDirectListing(listing);
|
|
|
|
case 13:
|
|
return _context33.abrupt("return", _context33.sent);
|
|
|
|
case 14:
|
|
throw new Error("Unknown listing type: " + listing.listingType);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function getListing(_x45) {
|
|
return _getListing.apply(this, arguments);
|
|
}
|
|
|
|
return getListing;
|
|
}();
|
|
|
|
_proto.getAllListings = /*#__PURE__*/function () {
|
|
var _getAllListings = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(filter) {
|
|
var rawListings, start;
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
_context34.next = 2;
|
|
return this.getAllListingsNoFilter();
|
|
|
|
case 2:
|
|
rawListings = _context34.sent;
|
|
|
|
if (filter) {
|
|
if (filter.seller) {
|
|
rawListings = rawListings.filter(function (seller) {
|
|
var _filter$seller;
|
|
|
|
return seller.sellerAddress.toString().toLowerCase() === (filter == null ? void 0 : (_filter$seller = filter.seller) == null ? void 0 : _filter$seller.toString().toLowerCase());
|
|
});
|
|
}
|
|
|
|
if (filter.tokenContract) {
|
|
if (!filter.tokenId) {
|
|
rawListings = rawListings.filter(function (tokenContract) {
|
|
var _filter$tokenContract;
|
|
|
|
return tokenContract.assetContractAddress.toString().toLowerCase() === (filter == null ? void 0 : (_filter$tokenContract = filter.tokenContract) == null ? void 0 : _filter$tokenContract.toString().toLowerCase());
|
|
});
|
|
} else {
|
|
rawListings = rawListings.filter(function (tokenContract) {
|
|
var _filter$tokenContract2, _filter$tokenId;
|
|
|
|
return tokenContract.assetContractAddress.toString().toLowerCase() === (filter == null ? void 0 : (_filter$tokenContract2 = filter.tokenContract) == null ? void 0 : _filter$tokenContract2.toString().toLowerCase()) && tokenContract.tokenId.toString() === (filter == null ? void 0 : (_filter$tokenId = filter.tokenId) == null ? void 0 : _filter$tokenId.toString());
|
|
});
|
|
}
|
|
}
|
|
|
|
if (filter.start !== undefined) {
|
|
start = filter.start;
|
|
rawListings = rawListings.filter(function (_, index) {
|
|
return index >= start;
|
|
});
|
|
|
|
if (filter.count !== undefined && rawListings.length > filter.count) {
|
|
rawListings = rawListings.slice(0, filter.count);
|
|
}
|
|
}
|
|
}
|
|
|
|
return _context34.abrupt("return", rawListings.filter(function (l) {
|
|
return l !== undefined;
|
|
}));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34, this);
|
|
}));
|
|
|
|
function getAllListings(_x46) {
|
|
return _getAllListings.apply(this, arguments);
|
|
}
|
|
|
|
return getAllListings;
|
|
}();
|
|
|
|
_proto.getAllListingsNoFilter = /*#__PURE__*/function () {
|
|
var _getAllListingsNoFilter = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee36() {
|
|
var _this2 = this;
|
|
|
|
var listings;
|
|
return runtime_1.wrap(function _callee36$(_context36) {
|
|
while (1) {
|
|
switch (_context36.prev = _context36.next) {
|
|
case 0:
|
|
_context36.t0 = Promise;
|
|
_context36.t1 = Array;
|
|
_context36.t2 = Array;
|
|
_context36.next = 5;
|
|
return this.readOnlyContract.totalListings();
|
|
|
|
case 5:
|
|
_context36.t3 = _context36.sent.toNumber();
|
|
_context36.t4 = (0, _context36.t2)(_context36.t3).keys();
|
|
_context36.t5 = _context36.t1.from.call(_context36.t1, _context36.t4).map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(i) {
|
|
var listing, valid;
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
_context35.prev = 0;
|
|
_context35.next = 3;
|
|
return _this2.getListing(i);
|
|
|
|
case 3:
|
|
listing = _context35.sent;
|
|
_context35.next = 9;
|
|
break;
|
|
|
|
case 6:
|
|
_context35.prev = 6;
|
|
_context35.t0 = _context35["catch"](0);
|
|
return _context35.abrupt("return", undefined);
|
|
|
|
case 9:
|
|
if (!(listing.type === ListingType.Auction)) {
|
|
_context35.next = 11;
|
|
break;
|
|
}
|
|
|
|
return _context35.abrupt("return", listing);
|
|
|
|
case 11:
|
|
_context35.next = 13;
|
|
return _this2.isStillValidDirectListing(listing);
|
|
|
|
case 13:
|
|
valid = _context35.sent;
|
|
|
|
if (valid) {
|
|
_context35.next = 16;
|
|
break;
|
|
}
|
|
|
|
return _context35.abrupt("return", undefined);
|
|
|
|
case 16:
|
|
return _context35.abrupt("return", listing);
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35, null, [[0, 6]]);
|
|
}));
|
|
|
|
return function (_x47) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}());
|
|
_context36.next = 10;
|
|
return _context36.t0.all.call(_context36.t0, _context36.t5);
|
|
|
|
case 10:
|
|
listings = _context36.sent;
|
|
return _context36.abrupt("return", listings.filter(function (l) {
|
|
return l !== undefined;
|
|
}));
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context36.stop();
|
|
}
|
|
}
|
|
}, _callee36, this);
|
|
}));
|
|
|
|
function getAllListingsNoFilter() {
|
|
return _getAllListingsNoFilter.apply(this, arguments);
|
|
}
|
|
|
|
return getAllListingsNoFilter;
|
|
}();
|
|
|
|
_proto.isRestrictedListerRoleOnly = /*#__PURE__*/function () {
|
|
var _isRestrictedListerRoleOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee37() {
|
|
return runtime_1.wrap(function _callee37$(_context37) {
|
|
while (1) {
|
|
switch (_context37.prev = _context37.next) {
|
|
case 0:
|
|
return _context37.abrupt("return", this.readOnlyContract.restrictedListerRoleOnly());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context37.stop();
|
|
}
|
|
}
|
|
}, _callee37, this);
|
|
}));
|
|
|
|
function isRestrictedListerRoleOnly() {
|
|
return _isRestrictedListerRoleOnly.apply(this, arguments);
|
|
}
|
|
|
|
return isRestrictedListerRoleOnly;
|
|
}();
|
|
|
|
_proto.setRestrictedListerRoleOnly = /*#__PURE__*/function () {
|
|
var _setRestrictedListerRoleOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee38(isRestricted) {
|
|
return runtime_1.wrap(function _callee38$(_context38) {
|
|
while (1) {
|
|
switch (_context38.prev = _context38.next) {
|
|
case 0:
|
|
_context38.next = 2;
|
|
return this.sendTransaction("setRestrictedListerRoleOnly", [isRestricted]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context38.stop();
|
|
}
|
|
}
|
|
}, _callee38, this);
|
|
}));
|
|
|
|
function setRestrictedListerRoleOnly(_x48) {
|
|
return _setRestrictedListerRoleOnly.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedListerRoleOnly;
|
|
}();
|
|
|
|
_proto.allowListingFromSpecificAssetOnly = /*#__PURE__*/function () {
|
|
var _allowListingFromSpecificAssetOnly = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee39(contractAddress) {
|
|
var encoded, members;
|
|
return runtime_1.wrap(function _callee39$(_context39) {
|
|
while (1) {
|
|
switch (_context39.prev = _context39.next) {
|
|
case 0:
|
|
_context39.next = 2;
|
|
return this.isV2();
|
|
|
|
case 2:
|
|
if (_context39.sent) {
|
|
_context39.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw Error("Not supported in this version of the contract, please upgrade");
|
|
|
|
case 4:
|
|
encoded = [];
|
|
_context39.next = 7;
|
|
return this.getRoleMembers(RolesMap.asset);
|
|
|
|
case 7:
|
|
members = _context39.sent;
|
|
|
|
if (AddressZero in members) {
|
|
encoded.push(this.contract["interface"].encodeFunctionData("revokeRole", [getRoleHash(RolesMap.asset), AddressZero]));
|
|
}
|
|
|
|
encoded.push(this.contract["interface"].encodeFunctionData("grantRole", [getRoleHash(RolesMap.asset), contractAddress]));
|
|
_context39.next = 12;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context39.stop();
|
|
}
|
|
}
|
|
}, _callee39, this);
|
|
}));
|
|
|
|
function allowListingFromSpecificAssetOnly(_x49) {
|
|
return _allowListingFromSpecificAssetOnly.apply(this, arguments);
|
|
}
|
|
|
|
return allowListingFromSpecificAssetOnly;
|
|
}();
|
|
|
|
_proto.allowListingFromAnyAsset = /*#__PURE__*/function () {
|
|
var _allowListingFromAnyAsset = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee40() {
|
|
var encoded, members, addr;
|
|
return runtime_1.wrap(function _callee40$(_context40) {
|
|
while (1) {
|
|
switch (_context40.prev = _context40.next) {
|
|
case 0:
|
|
_context40.next = 2;
|
|
return this.isV2();
|
|
|
|
case 2:
|
|
if (_context40.sent) {
|
|
_context40.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw Error("Not supported in this version of the contract, please upgrade");
|
|
|
|
case 4:
|
|
encoded = [];
|
|
_context40.next = 7;
|
|
return this.getRoleMembers(RolesMap.asset);
|
|
|
|
case 7:
|
|
members = _context40.sent;
|
|
|
|
for (addr in members) {
|
|
encoded.push(this.contract["interface"].encodeFunctionData("revokeRole", [getRoleHash(RolesMap.asset), addr]));
|
|
}
|
|
|
|
encoded.push(this.contract["interface"].encodeFunctionData("grantRole", [getRoleHash(RolesMap.asset), AddressZero]));
|
|
_context40.next = 12;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context40.stop();
|
|
}
|
|
}
|
|
}, _callee40, this);
|
|
}));
|
|
|
|
function allowListingFromAnyAsset() {
|
|
return _allowListingFromAnyAsset.apply(this, arguments);
|
|
}
|
|
|
|
return allowListingFromAnyAsset;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isV2 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee41() {
|
|
var version;
|
|
return runtime_1.wrap(function _callee41$(_context41) {
|
|
while (1) {
|
|
switch (_context41.prev = _context41.next) {
|
|
case 0:
|
|
_context41.next = 2;
|
|
return this.readOnlyContract.VERSION();
|
|
|
|
case 2:
|
|
version = _context41.sent;
|
|
return _context41.abrupt("return", version.toNumber() === 2);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context41.stop();
|
|
}
|
|
}
|
|
}, _callee41, this);
|
|
}));
|
|
|
|
function isV2() {
|
|
return _isV.apply(this, arguments);
|
|
}
|
|
|
|
return isV2;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.isNewBuy =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isNewBuy = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee42() {
|
|
return runtime_1.wrap(function _callee42$(_context42) {
|
|
while (1) {
|
|
switch (_context42.prev = _context42.next) {
|
|
case 0:
|
|
_context42.next = 2;
|
|
return this.checkVersion();
|
|
|
|
case 2:
|
|
return _context42.abrupt("return", this._isNewBuy);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context42.stop();
|
|
}
|
|
}
|
|
}, _callee42, this);
|
|
}));
|
|
|
|
function isNewBuy() {
|
|
return _isNewBuy.apply(this, arguments);
|
|
}
|
|
|
|
return isNewBuy;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.checkVersion =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _checkVersion = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee43() {
|
|
return runtime_1.wrap(function _callee43$(_context43) {
|
|
while (1) {
|
|
switch (_context43.prev = _context43.next) {
|
|
case 0:
|
|
if (!this._shouldCheckVersion) {
|
|
_context43.next = 11;
|
|
break;
|
|
}
|
|
|
|
_context43.prev = 1;
|
|
_context43.next = 4;
|
|
return this.readOnlyContract.VERSION();
|
|
|
|
case 4:
|
|
this._isNewBuy = true;
|
|
_context43.next = 10;
|
|
break;
|
|
|
|
case 7:
|
|
_context43.prev = 7;
|
|
_context43.t0 = _context43["catch"](1);
|
|
this._isNewBuy = false;
|
|
|
|
case 10:
|
|
this._shouldCheckVersion = false;
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context43.stop();
|
|
}
|
|
}
|
|
}, _callee43, this, [[1, 7]]);
|
|
}));
|
|
|
|
function checkVersion() {
|
|
return _checkVersion.apply(this, arguments);
|
|
}
|
|
|
|
return checkVersion;
|
|
}();
|
|
|
|
return MarketplaceModule;
|
|
}(ModuleWithRoles);
|
|
MarketplaceModule.moduleType = ModuleType.MARKETPLACE;
|
|
MarketplaceModule.roles = [RolesMap.admin, RolesMap.lister, RolesMap.asset];
|
|
|
|
var MintRequest$1 = [{
|
|
name: "to",
|
|
type: "address"
|
|
}, {
|
|
name: "uri",
|
|
type: "string"
|
|
}, {
|
|
name: "price",
|
|
type: "uint256"
|
|
}, {
|
|
name: "currency",
|
|
type: "address"
|
|
}, {
|
|
name: "validityStartTimestamp",
|
|
type: "uint128"
|
|
}, {
|
|
name: "validityEndTimestamp",
|
|
type: "uint128"
|
|
}, {
|
|
name: "uid",
|
|
type: "bytes32"
|
|
}];
|
|
/**
|
|
* Create a collection of one-of-one NFTs.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getNFTModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var NFTModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(NFTModule, _ModuleWithRoles);
|
|
|
|
function NFTModule() {
|
|
var _this;
|
|
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
args[_key] = arguments[_key];
|
|
}
|
|
|
|
_this = _ModuleWithRoles.call.apply(_ModuleWithRoles, [this].concat(args)) || this;
|
|
_this._shouldCheckVersion = true;
|
|
_this._isV1 = false;
|
|
_this.v1Contract = void 0;
|
|
return _this;
|
|
}
|
|
|
|
var _proto = NFTModule.prototype;
|
|
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return NFTModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return SignatureMint721__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return NFTModule.moduleType;
|
|
};
|
|
|
|
/**
|
|
* Check if contract is v1 or v2. If the contract doesn't have nextTokenIdToMint = v1 contract.
|
|
*/
|
|
_proto.isV1 =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _isV = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
if (!this._shouldCheckVersion) {
|
|
_context.next = 12;
|
|
break;
|
|
}
|
|
|
|
_context.prev = 1;
|
|
_context.next = 4;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 4:
|
|
this._isV1 = false;
|
|
_context.next = 11;
|
|
break;
|
|
|
|
case 7:
|
|
_context.prev = 7;
|
|
_context.t0 = _context["catch"](1);
|
|
this._isV1 = true;
|
|
this.v1Contract = NFT__factory.connect(this.address, this.providerOrSigner);
|
|
|
|
case 11:
|
|
this._shouldCheckVersion = false;
|
|
|
|
case 12:
|
|
return _context.abrupt("return", this._isV1);
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this, [[1, 7]]);
|
|
}));
|
|
|
|
function isV1() {
|
|
return _isV.apply(this, arguments);
|
|
}
|
|
|
|
return isV1;
|
|
}()
|
|
/**
|
|
* Fetches an NFT from storage with the resolved metadata.
|
|
*
|
|
* @param tokenId - The id of the token to fetch.
|
|
* @returns - The NFT metadata.
|
|
*/
|
|
;
|
|
|
|
_proto.get =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(tokenId) {
|
|
var storage, uri, metadata;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
storage = this.sdk.getStorage();
|
|
_context2.next = 3;
|
|
return this.readOnlyContract.tokenURI(tokenId);
|
|
|
|
case 3:
|
|
uri = _context2.sent;
|
|
_context2.t0 = JSON;
|
|
_context2.next = 7;
|
|
return storage.get(uri);
|
|
|
|
case 7:
|
|
_context2.t1 = _context2.sent;
|
|
metadata = _context2.t0.parse.call(_context2.t0, _context2.t1);
|
|
return _context2.abrupt("return", _extends({}, metadata, {
|
|
id: tokenId,
|
|
uri: uri,
|
|
image: storage.resolveFullUrl(metadata.image)
|
|
}));
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function get(_x) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get All NFTs
|
|
*
|
|
* @remarks Get all the data associated with every NFT in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* const nfts = await module.getAll();
|
|
* console.log(nfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
var _this2 = this;
|
|
|
|
var maxId, _yield$this$v1Contrac, _this$v1Contract;
|
|
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
if (!_context3.sent) {
|
|
_context3.next = 14;
|
|
break;
|
|
}
|
|
|
|
_context3.next = 5;
|
|
return (_this$v1Contract = this.v1Contract) == null ? void 0 : _this$v1Contract.nextTokenId();
|
|
|
|
case 5:
|
|
_context3.t0 = _yield$this$v1Contrac = _context3.sent;
|
|
|
|
if (!(_context3.t0 == null)) {
|
|
_context3.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context3.t1 = void 0;
|
|
_context3.next = 11;
|
|
break;
|
|
|
|
case 10:
|
|
_context3.t1 = _yield$this$v1Contrac.toNumber();
|
|
|
|
case 11:
|
|
maxId = _context3.t1;
|
|
_context3.next = 17;
|
|
break;
|
|
|
|
case 14:
|
|
_context3.next = 16;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 16:
|
|
maxId = _context3.sent.toNumber();
|
|
|
|
case 17:
|
|
_context3.next = 19;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this2.get(i.toString());
|
|
}));
|
|
|
|
case 19:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getAll() {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}();
|
|
|
|
_proto.getWithOwner = /*#__PURE__*/function () {
|
|
var _getWithOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tokenId) {
|
|
var _yield$Promise$all, owner, metadata;
|
|
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return Promise.all([this.ownerOf(tokenId), this.get(tokenId)]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context4.sent;
|
|
owner = _yield$Promise$all[0];
|
|
metadata = _yield$Promise$all[1];
|
|
return _context4.abrupt("return", {
|
|
owner: owner,
|
|
metadata: metadata
|
|
});
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getWithOwner(_x2) {
|
|
return _getWithOwner.apply(this, arguments);
|
|
}
|
|
|
|
return getWithOwner;
|
|
}();
|
|
|
|
_proto.getAllWithOwner = /*#__PURE__*/function () {
|
|
var _getAllWithOwner = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5() {
|
|
var _this3 = this;
|
|
|
|
var maxId, _yield$this$v1Contrac2, _this$v1Contract2;
|
|
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
if (!_context5.sent) {
|
|
_context5.next = 14;
|
|
break;
|
|
}
|
|
|
|
_context5.next = 5;
|
|
return (_this$v1Contract2 = this.v1Contract) == null ? void 0 : _this$v1Contract2.nextTokenId();
|
|
|
|
case 5:
|
|
_context5.t0 = _yield$this$v1Contrac2 = _context5.sent;
|
|
|
|
if (!(_context5.t0 == null)) {
|
|
_context5.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context5.t1 = void 0;
|
|
_context5.next = 11;
|
|
break;
|
|
|
|
case 10:
|
|
_context5.t1 = _yield$this$v1Contrac2.toNumber();
|
|
|
|
case 11:
|
|
maxId = _context5.t1;
|
|
_context5.next = 17;
|
|
break;
|
|
|
|
case 14:
|
|
_context5.next = 16;
|
|
return this.readOnlyContract.nextTokenIdToMint();
|
|
|
|
case 16:
|
|
maxId = _context5.sent.toNumber();
|
|
|
|
case 17:
|
|
_context5.next = 19;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this3.getWithOwner(i.toString());
|
|
}));
|
|
|
|
case 19:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getAllWithOwner() {
|
|
return _getAllWithOwner.apply(this, arguments);
|
|
}
|
|
|
|
return getAllWithOwner;
|
|
}()
|
|
/**
|
|
* Checks the owner of a particular NFT
|
|
*
|
|
* @param tokenId - ID of the NFT to get the owner of
|
|
* @returns the owner of the token, or a zero address if the
|
|
* token has been burned
|
|
*/
|
|
;
|
|
|
|
_proto.ownerOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ownerOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(tokenId) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.prev = 0;
|
|
_context6.next = 3;
|
|
return this.readOnlyContract.ownerOf(tokenId);
|
|
|
|
case 3:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 6:
|
|
_context6.prev = 6;
|
|
_context6.t0 = _context6["catch"](0);
|
|
return _context6.abrupt("return", AddressZero);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this, [[0, 6]]);
|
|
}));
|
|
|
|
function ownerOf(_x3) {
|
|
return _ownerOf.apply(this, arguments);
|
|
}
|
|
|
|
return ownerOf;
|
|
}()
|
|
/**
|
|
* Get Owned NFTs
|
|
*
|
|
* @remarks Get all the data associated with the NFTs owned by a specific wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to get the NFTs of
|
|
* const address = "{{wallet_address}}";
|
|
* const nfts = await module.getOwned(address);
|
|
* console.log(nfts);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(_address) {
|
|
var _this4 = this;
|
|
|
|
var address, balance, indices, tokenIds;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context7.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context7.t0 = _address;
|
|
_context7.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context7.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context7.t0 = _context7.sent;
|
|
|
|
case 7:
|
|
address = _context7.t0;
|
|
_context7.next = 10;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 10:
|
|
balance = _context7.sent;
|
|
indices = Array.from(Array(balance.toNumber()).keys());
|
|
_context7.next = 14;
|
|
return Promise.all(indices.map(function (i) {
|
|
return _this4.readOnlyContract.tokenOfOwnerByIndex(address, i);
|
|
}));
|
|
|
|
case 14:
|
|
tokenIds = _context7.sent;
|
|
_context7.next = 17;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this4.get(tokenId.toString());
|
|
}));
|
|
|
|
case 17:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getOwned(_x4) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}();
|
|
|
|
_proto.totalSupply = /*#__PURE__*/function () {
|
|
var _totalSupply = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8() {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.readOnlyContract.totalSupply();
|
|
|
|
case 2:
|
|
return _context8.abrupt("return", _context8.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function totalSupply() {
|
|
return _totalSupply.apply(this, arguments);
|
|
}
|
|
|
|
return totalSupply;
|
|
}()
|
|
/**
|
|
* Get NFT Balance
|
|
*
|
|
* @remarks Get a wallets NFT balance (number of NFTs in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check NFT balance
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* const balance = await module.balanceOf(address);
|
|
* console.log(balance);
|
|
* ```
|
|
*
|
|
* @returns The balance of the NFTs in the wallet
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(address) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.balanceOf(address);
|
|
|
|
case 2:
|
|
return _context9.abrupt("return", _context9.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function balanceOf(_x5) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10() {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.t0 = this;
|
|
_context10.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context10.t1 = _context10.sent;
|
|
_context10.next = 6;
|
|
return _context10.t0.balanceOf.call(_context10.t0, _context10.t1);
|
|
|
|
case 6:
|
|
return _context10.abrupt("return", _context10.sent);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(address, operator) {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 2:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function isApproved(_x6, _x7) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}() // write functions
|
|
;
|
|
|
|
_proto.setApproval =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(operator, approved) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context12.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
return _context12.abrupt("return", _context12.sent);
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function setApproval(_x8, _x9) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer NFT
|
|
*
|
|
* @remarks Transfer an NFT from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the NFT to
|
|
* const toAddress = "{{wallet_address}}";
|
|
*
|
|
* // The token ID of the NFT you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* await module.transfer(toAddress, tokenId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(to, tokenId) {
|
|
var from;
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.isTransferRestricted();
|
|
|
|
case 2:
|
|
if (!_context13.sent) {
|
|
_context13.next = 4;
|
|
break;
|
|
}
|
|
|
|
throw new RestrictedTransferError(this.address);
|
|
|
|
case 4:
|
|
_context13.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
from = _context13.sent;
|
|
_context13.next = 9;
|
|
return this.sendTransaction("safeTransferFrom(address,address,uint256)", [from, to, tokenId]);
|
|
|
|
case 9:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function transfer(_x10, _x11) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}() // owner functions
|
|
;
|
|
|
|
_proto.mint =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mint = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(metadata) {
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.t0 = this;
|
|
_context14.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context14.t1 = _context14.sent;
|
|
_context14.t2 = metadata;
|
|
_context14.next = 7;
|
|
return _context14.t0.mintTo.call(_context14.t0, _context14.t1, _context14.t2);
|
|
|
|
case 7:
|
|
return _context14.abrupt("return", _context14.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function mint(_x12) {
|
|
return _mint.apply(this, arguments);
|
|
}
|
|
|
|
return mint;
|
|
}();
|
|
|
|
_proto._v1MintTo = /*#__PURE__*/function () {
|
|
var _v1MintTo2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(to, metadata) {
|
|
var uri, receipt, events;
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
!(this.v1Contract !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, "v1 contract is undefined") : invariant(false) : void 0;
|
|
_context15.next = 3;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 3:
|
|
uri = _context15.sent;
|
|
_context15.next = 6;
|
|
return this.sendContractTransaction(this.v1Contract, "mintNFT", [to, uri]);
|
|
|
|
case 6:
|
|
receipt = _context15.sent;
|
|
events = this.parseLogs("Minted", receipt == null ? void 0 : receipt.logs, this.v1Contract);
|
|
|
|
if (!(events.length === 0)) {
|
|
_context15.next = 10;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No Minted event found, failed to mint");
|
|
|
|
case 10:
|
|
_context15.next = 12;
|
|
return this.get(events[0].args.tokenId.toString());
|
|
|
|
case 12:
|
|
return _context15.abrupt("return", _context15.sent);
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this);
|
|
}));
|
|
|
|
function _v1MintTo(_x13, _x14) {
|
|
return _v1MintTo2.apply(this, arguments);
|
|
}
|
|
|
|
return _v1MintTo;
|
|
}()
|
|
/**
|
|
* Mint NFT
|
|
*
|
|
* @remarks Mint an NFT to a specified wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to mint the NFT to
|
|
* const toAddress = "{{wallet_address}}"
|
|
*
|
|
* // Custom metadata of the NFT, note that you can fully customize this metadata with other properties.
|
|
* const metadata = {
|
|
* name: "Cool NFT",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* }
|
|
*
|
|
* await module.mintTo(toAddress, metadata);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.mintTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mintTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(to, metadata) {
|
|
var uri, receipt, event, tokenId;
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
if (!_context16.sent) {
|
|
_context16.next = 6;
|
|
break;
|
|
}
|
|
|
|
_context16.next = 5;
|
|
return this._v1MintTo(to, metadata);
|
|
|
|
case 5:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 6:
|
|
_context16.next = 8;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 8:
|
|
uri = _context16.sent;
|
|
_context16.next = 11;
|
|
return this.sendTransaction("mintTo", [to, uri]);
|
|
|
|
case 11:
|
|
receipt = _context16.sent;
|
|
event = this.parseLogs("TokenMinted", receipt == null ? void 0 : receipt.logs);
|
|
|
|
if (!(event.length === 0)) {
|
|
_context16.next = 15;
|
|
break;
|
|
}
|
|
|
|
throw new Error("TokenMinted event not found");
|
|
|
|
case 15:
|
|
tokenId = event[0].args.tokenIdMinted;
|
|
_context16.next = 18;
|
|
return this.get(tokenId.toString());
|
|
|
|
case 18:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function mintTo(_x15, _x16) {
|
|
return _mintTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintTo;
|
|
}();
|
|
|
|
_proto.mintBatch = /*#__PURE__*/function () {
|
|
var _mintBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(metadatas) {
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
_context17.t0 = this;
|
|
_context17.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context17.t1 = _context17.sent;
|
|
_context17.t2 = metadatas;
|
|
_context17.next = 7;
|
|
return _context17.t0.mintBatchTo.call(_context17.t0, _context17.t1, _context17.t2);
|
|
|
|
case 7:
|
|
return _context17.abrupt("return", _context17.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function mintBatch(_x17) {
|
|
return _mintBatch.apply(this, arguments);
|
|
}
|
|
|
|
return mintBatch;
|
|
}();
|
|
|
|
_proto._v1MintBatchTo = /*#__PURE__*/function () {
|
|
var _v1MintBatchTo2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18(to, metadatas) {
|
|
var _this5 = this;
|
|
|
|
var _yield$this$sdk$getSt, uris, receipt, events, tokenIds;
|
|
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
!(this.v1Contract !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, "v1 contract is undefined") : invariant(false) : void 0;
|
|
_context18.next = 3;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas);
|
|
|
|
case 3:
|
|
_yield$this$sdk$getSt = _context18.sent;
|
|
uris = _yield$this$sdk$getSt.metadataUris;
|
|
_context18.next = 7;
|
|
return this.sendContractTransaction(this.v1Contract, "mintNFTBatch", [to, uris]);
|
|
|
|
case 7:
|
|
receipt = _context18.sent;
|
|
events = this.parseLogs("MintedBatch", receipt == null ? void 0 : receipt.logs, this.v1Contract);
|
|
|
|
if (!(events.length === 0)) {
|
|
_context18.next = 11;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No MintedBatch event found, failed to mint");
|
|
|
|
case 11:
|
|
tokenIds = events[0].args.tokenIds;
|
|
_context18.next = 14;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this5.get(tokenId.toString());
|
|
}));
|
|
|
|
case 14:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function _v1MintBatchTo(_x18, _x19) {
|
|
return _v1MintBatchTo2.apply(this, arguments);
|
|
}
|
|
|
|
return _v1MintBatchTo;
|
|
}()
|
|
/**
|
|
* Mint Many NFTs
|
|
*
|
|
* @remarks Mint many NFTs at once to a specified wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to mint the NFT to
|
|
* const toAddress = "{{wallet_address}}"
|
|
*
|
|
* // Custom metadata of the NFTs you want to mint.
|
|
* const metadatas = [{
|
|
* name: "Cool NFT #1",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/image.png"), // This can be an image url or file
|
|
* }, {
|
|
* name: "Cool NFT #2",
|
|
* description: "This is a cool NFT",
|
|
* image: fs.readFileSync("path/to/other/image.png"),
|
|
* }];
|
|
*
|
|
* await module.mintBatchTo(toAddress, metadatas);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.mintBatchTo =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _mintBatchTo = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19(to, metadatas) {
|
|
var _this6 = this;
|
|
|
|
var _yield$this$sdk$getSt2, uris, multicall, receipt, events, tokenIds;
|
|
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return this.isV1();
|
|
|
|
case 2:
|
|
if (!_context19.sent) {
|
|
_context19.next = 6;
|
|
break;
|
|
}
|
|
|
|
_context19.next = 5;
|
|
return this._v1MintBatchTo(to, metadatas);
|
|
|
|
case 5:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 6:
|
|
_context19.next = 8;
|
|
return this.sdk.getStorage().uploadMetadataBatch(metadatas);
|
|
|
|
case 8:
|
|
_yield$this$sdk$getSt2 = _context19.sent;
|
|
uris = _yield$this$sdk$getSt2.metadataUris;
|
|
multicall = uris.map(function (uri) {
|
|
return _this6.contract["interface"].encodeFunctionData("mintTo", [to, uri]);
|
|
});
|
|
_context19.next = 13;
|
|
return this.sendTransaction("multicall", [multicall]);
|
|
|
|
case 13:
|
|
receipt = _context19.sent;
|
|
events = this.parseLogs("TokenMinted", receipt.logs);
|
|
|
|
if (!(events.length === 0 || events.length < metadatas.length)) {
|
|
_context19.next = 17;
|
|
break;
|
|
}
|
|
|
|
throw new Error("TokenMinted event not found, minting failed");
|
|
|
|
case 17:
|
|
tokenIds = events.map(function (e) {
|
|
return e.args.tokenIdMinted;
|
|
});
|
|
_context19.next = 20;
|
|
return Promise.all(tokenIds.map(function (tokenId) {
|
|
return _this6.get(tokenId.toString());
|
|
}));
|
|
|
|
case 20:
|
|
return _context19.abrupt("return", _context19.sent);
|
|
|
|
case 21:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function mintBatchTo(_x20, _x21) {
|
|
return _mintBatchTo.apply(this, arguments);
|
|
}
|
|
|
|
return mintBatchTo;
|
|
}()
|
|
/**
|
|
* Burn NFT
|
|
*
|
|
* @remarks Burn an NFT, permanently taking it out of circulation and reducing the supply.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The token ID of the NFT you want to burn
|
|
* const tokenId = 0;
|
|
*
|
|
* await module.burn(tokenId);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.burn =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _burn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20(tokenId) {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
_context20.next = 2;
|
|
return this.sendTransaction("burn", [tokenId]);
|
|
|
|
case 2:
|
|
return _context20.abrupt("return", _context20.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function burn(_x22) {
|
|
return _burn.apply(this, arguments);
|
|
}
|
|
|
|
return burn;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(from, to, tokenId) {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
_context21.next = 2;
|
|
return this.sendTransaction("transferFrom", [from, to, tokenId]);
|
|
|
|
case 2:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function transferFrom(_x23, _x24, _x25) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}();
|
|
|
|
_proto.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(amount) {
|
|
var _yield$this$getMetada, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
_context22.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada = _context22.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context22.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context22.t0 = this.sdk.getStorage();
|
|
_context22.t1 = _extends({}, metadata);
|
|
_context22.t2 = this.address;
|
|
_context22.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context22.t3 = _context22.sent;
|
|
_context22.next = 16;
|
|
return _context22.t0.uploadMetadata.call(_context22.t0, _context22.t1, _context22.t2, _context22.t3);
|
|
|
|
case 16:
|
|
uri = _context22.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context22.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context22.abrupt("return", _context22.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x26) {
|
|
return _setRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
_context23.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context23.sent;
|
|
_context23.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context23.abrupt("return", _context23.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x27) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee24() {
|
|
return runtime_1.wrap(function _callee24$(_context24) {
|
|
while (1) {
|
|
switch (_context24.prev = _context24.next) {
|
|
case 0:
|
|
_context24.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context24.abrupt("return", _context24.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context24.stop();
|
|
}
|
|
}
|
|
}, _callee24, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee25() {
|
|
var _metadata$metadata;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee25$(_context25) {
|
|
while (1) {
|
|
switch (_context25.prev = _context25.next) {
|
|
case 0:
|
|
_context25.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context25.sent;
|
|
|
|
if (!(((_metadata$metadata = metadata.metadata) == null ? void 0 : _metadata$metadata.fee_recipient) !== undefined)) {
|
|
_context25.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context25.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context25.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context25.stop();
|
|
}
|
|
}
|
|
}, _callee25, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}()
|
|
/**
|
|
* Set the default primary sales recipient for this contract
|
|
* @param address - the wallet that should receive the proceeds from primary sales
|
|
*/
|
|
;
|
|
|
|
_proto.setPrimarySaleRecipient =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setPrimarySaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee26(address) {
|
|
return runtime_1.wrap(function _callee26$(_context26) {
|
|
while (1) {
|
|
switch (_context26.prev = _context26.next) {
|
|
case 0:
|
|
_context26.next = 2;
|
|
return this.sendTransaction("setDefaultSaleRecipient", [address]);
|
|
|
|
case 2:
|
|
return _context26.abrupt("return", _context26.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context26.stop();
|
|
}
|
|
}
|
|
}, _callee26, this);
|
|
}));
|
|
|
|
function setPrimarySaleRecipient(_x28) {
|
|
return _setPrimarySaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return setPrimarySaleRecipient;
|
|
}();
|
|
|
|
_proto.getPrimarySaleRecipient = /*#__PURE__*/function () {
|
|
var _getPrimarySaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee27() {
|
|
return runtime_1.wrap(function _callee27$(_context27) {
|
|
while (1) {
|
|
switch (_context27.prev = _context27.next) {
|
|
case 0:
|
|
_context27.next = 2;
|
|
return this.readOnlyContract.defaultSaleRecipient();
|
|
|
|
case 2:
|
|
return _context27.abrupt("return", _context27.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context27.stop();
|
|
}
|
|
}
|
|
}, _callee27, this);
|
|
}));
|
|
|
|
function getPrimarySaleRecipient() {
|
|
return _getPrimarySaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return getPrimarySaleRecipient;
|
|
}();
|
|
|
|
_proto.getDefaultSaleRecipient = /*#__PURE__*/function () {
|
|
var _getDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee28() {
|
|
return runtime_1.wrap(function _callee28$(_context28) {
|
|
while (1) {
|
|
switch (_context28.prev = _context28.next) {
|
|
case 0:
|
|
_context28.next = 2;
|
|
return this.readOnlyContract.defaultSaleRecipient();
|
|
|
|
case 2:
|
|
return _context28.abrupt("return", _context28.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context28.stop();
|
|
}
|
|
}
|
|
}, _callee28, this);
|
|
}));
|
|
|
|
function getDefaultSaleRecipient() {
|
|
return _getDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return getDefaultSaleRecipient;
|
|
}()
|
|
/**
|
|
* Set the default primary sales recipient for this contract
|
|
* @param recipient - the wallet that should receive the proceeds from primary sales
|
|
*/
|
|
;
|
|
|
|
_proto.setDefaultSaleRecipient =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setDefaultSaleRecipient = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee29(recipient) {
|
|
return runtime_1.wrap(function _callee29$(_context29) {
|
|
while (1) {
|
|
switch (_context29.prev = _context29.next) {
|
|
case 0:
|
|
_context29.next = 2;
|
|
return this.sendTransaction("setDefaultSaleRecipient", [recipient]);
|
|
|
|
case 2:
|
|
return _context29.abrupt("return", _context29.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context29.stop();
|
|
}
|
|
}
|
|
}, _callee29, this);
|
|
}));
|
|
|
|
function setDefaultSaleRecipient(_x29) {
|
|
return _setDefaultSaleRecipient.apply(this, arguments);
|
|
}
|
|
|
|
return setDefaultSaleRecipient;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee30() {
|
|
return runtime_1.wrap(function _callee30$(_context30) {
|
|
while (1) {
|
|
switch (_context30.prev = _context30.next) {
|
|
case 0:
|
|
return _context30.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context30.stop();
|
|
}
|
|
}
|
|
}, _callee30, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee31(restricted) {
|
|
return runtime_1.wrap(function _callee31$(_context31) {
|
|
while (1) {
|
|
switch (_context31.prev = _context31.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context31.t0 = this;
|
|
_context31.t1 = ["admin"];
|
|
_context31.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context31.t2 = _context31.sent;
|
|
_context31.next = 8;
|
|
return _context31.t0.onlyRoles.call(_context31.t0, _context31.t1, _context31.t2);
|
|
|
|
case 8:
|
|
_context31.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context31.abrupt("return", _context31.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context31.stop();
|
|
}
|
|
}
|
|
}, _callee31, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x30) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}();
|
|
|
|
_proto.mintWithSignature = /*#__PURE__*/function () {
|
|
var _mintWithSignature = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee32(req, signature) {
|
|
var message, overrides, receipt, t;
|
|
return runtime_1.wrap(function _callee32$(_context32) {
|
|
while (1) {
|
|
switch (_context32.prev = _context32.next) {
|
|
case 0:
|
|
message = _extends({}, this.mapPayload(req), {
|
|
uri: req.uri
|
|
});
|
|
_context32.next = 3;
|
|
return this.getCallOverrides();
|
|
|
|
case 3:
|
|
overrides = _context32.sent;
|
|
_context32.next = 6;
|
|
return this.setAllowance(BigNumber.from(message.price), req.currencyAddress, overrides);
|
|
|
|
case 6:
|
|
_context32.next = 8;
|
|
return this.sendTransaction("mintWithSignature", [message, signature], overrides);
|
|
|
|
case 8:
|
|
receipt = _context32.sent;
|
|
_context32.next = 11;
|
|
return this.parseLogs("MintWithSignature", receipt.logs);
|
|
|
|
case 11:
|
|
t = _context32.sent;
|
|
|
|
if (!(t.length === 0)) {
|
|
_context32.next = 14;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No MintWithSignature event found");
|
|
|
|
case 14:
|
|
return _context32.abrupt("return", t[0].args.tokenIdMinted);
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context32.stop();
|
|
}
|
|
}
|
|
}, _callee32, this);
|
|
}));
|
|
|
|
function mintWithSignature(_x31, _x32) {
|
|
return _mintWithSignature.apply(this, arguments);
|
|
}
|
|
|
|
return mintWithSignature;
|
|
}();
|
|
|
|
_proto.verify = /*#__PURE__*/function () {
|
|
var _verify = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee33(mintRequest, signature) {
|
|
var message, v;
|
|
return runtime_1.wrap(function _callee33$(_context33) {
|
|
while (1) {
|
|
switch (_context33.prev = _context33.next) {
|
|
case 0:
|
|
message = this.mapPayload(mintRequest);
|
|
_context33.next = 3;
|
|
return this.readOnlyContract.verify(_extends({}, message, {
|
|
uri: mintRequest.uri
|
|
}), signature);
|
|
|
|
case 3:
|
|
v = _context33.sent;
|
|
return _context33.abrupt("return", v[0]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context33.stop();
|
|
}
|
|
}
|
|
}, _callee33, this);
|
|
}));
|
|
|
|
function verify(_x33, _x34) {
|
|
return _verify.apply(this, arguments);
|
|
}
|
|
|
|
return verify;
|
|
}();
|
|
|
|
_proto.generateSignatureBatch = /*#__PURE__*/function () {
|
|
var _generateSignatureBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee35(payloads) {
|
|
var _this7 = this;
|
|
|
|
var resolveId, _yield$this$sdk$getSt3, uris, chainId, signer;
|
|
|
|
return runtime_1.wrap(function _callee35$(_context35) {
|
|
while (1) {
|
|
switch (_context35.prev = _context35.next) {
|
|
case 0:
|
|
resolveId = function resolveId(mintRequest) {
|
|
if (mintRequest.id === undefined) {
|
|
var buffer = Buffer.alloc(16);
|
|
v4({}, buffer);
|
|
return hexlify$1(toUtf8Bytes(buffer.toString("hex")));
|
|
} else {
|
|
return hexlify$1(mintRequest.id);
|
|
}
|
|
};
|
|
|
|
_context35.t0 = this;
|
|
_context35.t1 = ["minter"];
|
|
_context35.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context35.t2 = _context35.sent;
|
|
_context35.next = 8;
|
|
return _context35.t0.onlyRoles.call(_context35.t0, _context35.t1, _context35.t2);
|
|
|
|
case 8:
|
|
_context35.next = 10;
|
|
return this.sdk.getStorage().uploadMetadataBatch(payloads.map(function (r) {
|
|
return r.metadata;
|
|
}));
|
|
|
|
case 10:
|
|
_yield$this$sdk$getSt3 = _context35.sent;
|
|
uris = _yield$this$sdk$getSt3.metadataUris;
|
|
_context35.next = 14;
|
|
return this.getChainID();
|
|
|
|
case 14:
|
|
chainId = _context35.sent;
|
|
signer = this.getSigner();
|
|
_context35.next = 18;
|
|
return Promise.all(payloads.map( /*#__PURE__*/function () {
|
|
var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee34(m, i) {
|
|
var id, uri;
|
|
return runtime_1.wrap(function _callee34$(_context34) {
|
|
while (1) {
|
|
switch (_context34.prev = _context34.next) {
|
|
case 0:
|
|
id = resolveId(m);
|
|
uri = uris[i];
|
|
_context34.t0 = _extends({}, m, {
|
|
id: id,
|
|
uri: uri
|
|
});
|
|
_context34.next = 5;
|
|
return _this7.signTypedDataEmitEvent(signer, {
|
|
name: "SignatureMint721",
|
|
version: "1",
|
|
chainId: chainId,
|
|
verifyingContract: _this7.address
|
|
}, {
|
|
MintRequest: MintRequest$1
|
|
}, _extends({
|
|
uri: uri
|
|
}, _this7.mapPayload(m), {
|
|
uid: id
|
|
}));
|
|
|
|
case 5:
|
|
_context34.t1 = _context34.sent.toString();
|
|
return _context34.abrupt("return", {
|
|
payload: _context34.t0,
|
|
signature: _context34.t1
|
|
});
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context34.stop();
|
|
}
|
|
}
|
|
}, _callee34);
|
|
}));
|
|
|
|
return function (_x36, _x37) {
|
|
return _ref.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 18:
|
|
return _context35.abrupt("return", _context35.sent);
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context35.stop();
|
|
}
|
|
}
|
|
}, _callee35, this);
|
|
}));
|
|
|
|
function generateSignatureBatch(_x35) {
|
|
return _generateSignatureBatch.apply(this, arguments);
|
|
}
|
|
|
|
return generateSignatureBatch;
|
|
}();
|
|
|
|
_proto.generateSignature = /*#__PURE__*/function () {
|
|
var _generateSignature = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee36(mintRequest) {
|
|
return runtime_1.wrap(function _callee36$(_context36) {
|
|
while (1) {
|
|
switch (_context36.prev = _context36.next) {
|
|
case 0:
|
|
_context36.next = 2;
|
|
return this.generateSignatureBatch([mintRequest]);
|
|
|
|
case 2:
|
|
return _context36.abrupt("return", _context36.sent[0]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context36.stop();
|
|
}
|
|
}
|
|
}, _callee36, this);
|
|
}));
|
|
|
|
function generateSignature(_x38) {
|
|
return _generateSignature.apply(this, arguments);
|
|
}
|
|
|
|
return generateSignature;
|
|
}()
|
|
/**
|
|
* Maps a payload to the format expected by the contract
|
|
*
|
|
* @internal
|
|
*
|
|
* @param mintRequest - The payload to map.
|
|
* @returns - The mapped payload.
|
|
*/
|
|
;
|
|
|
|
_proto.mapPayload = function mapPayload(mintRequest) {
|
|
return {
|
|
to: mintRequest.to,
|
|
price: mintRequest.price,
|
|
currency: mintRequest.currencyAddress,
|
|
validityEndTimestamp: mintRequest.mintEndTimeEpochSeconds,
|
|
validityStartTimestamp: mintRequest.mintStartTimeEpochSeconds,
|
|
uid: mintRequest.id
|
|
};
|
|
} // TODO: write in common place and stop duping
|
|
;
|
|
|
|
_proto.setAllowance =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _setAllowance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee37(value, currencyAddress, overrides) {
|
|
var erc20, owner, spender, allowance;
|
|
return runtime_1.wrap(function _callee37$(_context37) {
|
|
while (1) {
|
|
switch (_context37.prev = _context37.next) {
|
|
case 0:
|
|
if (!(currencyAddress === NATIVE_TOKEN_ADDRESS || currencyAddress === AddressZero)) {
|
|
_context37.next = 4;
|
|
break;
|
|
}
|
|
|
|
overrides["value"] = value;
|
|
_context37.next = 16;
|
|
break;
|
|
|
|
case 4:
|
|
erc20 = ERC20__factory.connect(currencyAddress, this.providerOrSigner);
|
|
_context37.next = 7;
|
|
return this.getSignerAddress();
|
|
|
|
case 7:
|
|
owner = _context37.sent;
|
|
spender = this.address;
|
|
_context37.next = 11;
|
|
return erc20.allowance(owner, spender);
|
|
|
|
case 11:
|
|
allowance = _context37.sent;
|
|
|
|
if (!allowance.lt(value)) {
|
|
_context37.next = 15;
|
|
break;
|
|
}
|
|
|
|
_context37.next = 15;
|
|
return this.sendContractTransaction(erc20, "increaseAllowance", [spender, value.sub(allowance)]);
|
|
|
|
case 15:
|
|
return _context37.abrupt("return", overrides);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context37.stop();
|
|
}
|
|
}
|
|
}, _callee37, this);
|
|
}));
|
|
|
|
function setAllowance(_x39, _x40, _x41) {
|
|
return _setAllowance.apply(this, arguments);
|
|
}
|
|
|
|
return setAllowance;
|
|
}();
|
|
|
|
return NFTModule;
|
|
}(ModuleWithRoles);
|
|
NFTModule.moduleType = ModuleType.NFT;
|
|
NFTModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.transfer];
|
|
|
|
var UnderlyingType;
|
|
|
|
(function (UnderlyingType) {
|
|
UnderlyingType[UnderlyingType["None"] = 0] = "None";
|
|
UnderlyingType[UnderlyingType["ERC20"] = 1] = "ERC20";
|
|
UnderlyingType[UnderlyingType["ERC721"] = 2] = "ERC721";
|
|
})(UnderlyingType || (UnderlyingType = {}));
|
|
/**
|
|
* Create lootboxes of NFTs with rarity based open mechanics.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getPackModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
|
|
var PackModule = /*#__PURE__*/function (_ModuleWithRoles) {
|
|
_inheritsLoose(PackModule, _ModuleWithRoles);
|
|
|
|
function PackModule() {
|
|
return _ModuleWithRoles.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = PackModule.prototype;
|
|
|
|
/**
|
|
* @override
|
|
* @internal
|
|
*/
|
|
_proto.getModuleRoles = function getModuleRoles() {
|
|
return PackModule.roles;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.connectContract = function connectContract() {
|
|
return Pack__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return PackModule.moduleType;
|
|
}
|
|
/**
|
|
* Open Pack
|
|
*
|
|
* @remarks Open a pack to burn it and obtain the reward asset inside.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The pack ID of the asset you want to buy
|
|
* const packId = "0";
|
|
* const rewards = await module.open(packId);
|
|
* console.log(rewards);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.open =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _open = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(packId) {
|
|
var _this = this;
|
|
|
|
var receipt, logs, event, requestId, opener, fulfillEvent, rewardIds, rewardContract;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return this.sendTransaction("openPack", [packId]);
|
|
|
|
case 2:
|
|
receipt = _context.sent;
|
|
logs = this.parseLogs("PackOpenRequest", receipt == null ? void 0 : receipt.logs);
|
|
|
|
if (!(logs.length === 0)) {
|
|
_context.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Failed to open pack");
|
|
|
|
case 6:
|
|
event = logs[0];
|
|
requestId = event.args.requestId;
|
|
opener = event.args.opener;
|
|
_context.next = 11;
|
|
return new Promise(function (resolve) {
|
|
_this.readOnlyContract.once( // eslint-disable-next-line new-cap
|
|
_this.readOnlyContract.filters.PackOpenFulfilled(null, opener), function (_packId, _opener, _requestId, rewardContract, rewardIds) {
|
|
if (requestId === _requestId) {
|
|
resolve({
|
|
packId: _packId,
|
|
opener: _opener,
|
|
requestId: requestId,
|
|
rewardContract: rewardContract,
|
|
rewardIds: rewardIds
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
case 11:
|
|
fulfillEvent = _context.sent;
|
|
rewardIds = fulfillEvent.rewardIds, rewardContract = fulfillEvent.rewardContract;
|
|
_context.next = 15;
|
|
return Promise.all(rewardIds.map(function (rewardId) {
|
|
return getMetadataWithoutContract(_this.providerOrSigner, rewardContract, rewardId.toString(), _this.sdk.getStorage());
|
|
}));
|
|
|
|
case 15:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function open(_x) {
|
|
return _open.apply(this, arguments);
|
|
}
|
|
|
|
return open;
|
|
}();
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(packId) {
|
|
var _yield$Promise$all, meta, state, supply, entity;
|
|
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return Promise.all([getMetadataWithoutContract(this.providerOrSigner, this.address, packId, this.sdk.getStorage()), this.readOnlyContract.getPack(packId), this.readOnlyContract.totalSupply(packId)["catch"](function () {
|
|
return BigNumber.from("0");
|
|
})]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context2.sent;
|
|
meta = _yield$Promise$all[0];
|
|
state = _yield$Promise$all[1];
|
|
supply = _yield$Promise$all[2];
|
|
entity = {
|
|
id: packId,
|
|
metadata: meta,
|
|
creator: state.creator,
|
|
currentSupply: supply,
|
|
openStart: state.openStart.gt(0) ? new Date(state.openStart.toNumber() * 1000) : null
|
|
};
|
|
return _context2.abrupt("return", entity);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function get(_x2) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get Pack Data
|
|
*
|
|
* @remarks Get data associated with every pack in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* const packs = await module.getAll();
|
|
* console.log(packs);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
var _this2 = this;
|
|
|
|
var maxId;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 2:
|
|
maxId = _context3.sent.toNumber();
|
|
_context3.next = 5;
|
|
return Promise.all(Array.from(Array(maxId).keys()).map(function (i) {
|
|
return _this2.get(i.toString());
|
|
}));
|
|
|
|
case 5:
|
|
return _context3.abrupt("return", _context3.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getAll() {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}()
|
|
/**
|
|
* Get Pack Reward Data
|
|
*
|
|
* @remarks Get data associated with the rewards inside a specified pack
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The pack ID of the pack whos rewards you want to get
|
|
* const packId = 0;
|
|
*
|
|
* const nfts = await module.getNFTs(packId);
|
|
* console.log(nfts);
|
|
* ```
|
|
*
|
|
* @returns The NFT metadata for all NFTs in the module.
|
|
*/
|
|
;
|
|
|
|
_proto.getNFTs =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getNFTs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(packId) {
|
|
var _this3 = this;
|
|
|
|
var packReward, rewards;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return this.readOnlyContract.getPackWithRewards(packId);
|
|
|
|
case 2:
|
|
packReward = _context4.sent;
|
|
|
|
if (packReward.source) {
|
|
_context4.next = 5;
|
|
break;
|
|
}
|
|
|
|
throw new NotFoundError();
|
|
|
|
case 5:
|
|
_context4.next = 7;
|
|
return Promise.all(packReward.tokenIds.map(function (tokenId) {
|
|
return getMetadataWithoutContract(_this3.providerOrSigner, packReward.source, tokenId.toString(), _this3.sdk.getStorage());
|
|
}));
|
|
|
|
case 7:
|
|
rewards = _context4.sent;
|
|
return _context4.abrupt("return", rewards.map(function (reward, i) {
|
|
return {
|
|
supply: packReward.amountsPacked[i],
|
|
metadata: reward
|
|
};
|
|
}));
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getNFTs(_x3) {
|
|
return _getNFTs.apply(this, arguments);
|
|
}
|
|
|
|
return getNFTs;
|
|
}()
|
|
/**
|
|
* Get Pack Balance
|
|
*
|
|
* @remarks Get a wallets pack balance (number of a specific packs in this module owned by the wallet).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet to check pack balance
|
|
* const address = "{{wallet_address}}"";
|
|
* // The token ID of the pack you want to check the wallets balance of
|
|
* const tokenId = "0"
|
|
*
|
|
* const balance = await module.balanceOf(address, tokenId);
|
|
* console.log(balance);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address, tokenId) {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return this.readOnlyContract.balanceOf(address, tokenId);
|
|
|
|
case 2:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function balanceOf(_x4, _x5) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}();
|
|
|
|
_proto.balance = /*#__PURE__*/function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(tokenId) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.t0 = this;
|
|
_context6.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context6.t1 = _context6.sent;
|
|
_context6.t2 = tokenId;
|
|
_context6.next = 7;
|
|
return _context6.t0.balanceOf.call(_context6.t0, _context6.t1, _context6.t2);
|
|
|
|
case 7:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function balance(_x6) {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}();
|
|
|
|
_proto.isApproved = /*#__PURE__*/function () {
|
|
var _isApproved = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(address, operator) {
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.readOnlyContract.isApprovedForAll(address, operator);
|
|
|
|
case 2:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function isApproved(_x7, _x8) {
|
|
return _isApproved.apply(this, arguments);
|
|
}
|
|
|
|
return isApproved;
|
|
}();
|
|
|
|
_proto.setApproval = /*#__PURE__*/function () {
|
|
var _setApproval = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(operator, approved) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
if (approved === void 0) {
|
|
approved = true;
|
|
}
|
|
|
|
_context8.next = 3;
|
|
return this.sendTransaction("setApprovalForAll", [operator, approved]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function setApproval(_x9, _x10) {
|
|
return _setApproval.apply(this, arguments);
|
|
}
|
|
|
|
return setApproval;
|
|
}()
|
|
/**
|
|
* Transfer Pack
|
|
*
|
|
* @remarks Transfer a pack from the connected wallet to another wallet.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Address of the wallet you want to send the pack to
|
|
* const toAddress = "0x...";
|
|
*
|
|
* // The token ID of the pack you want to send
|
|
* const tokenId = "0";
|
|
*
|
|
* // The number of packs you want to send
|
|
* const amount = 1;
|
|
*
|
|
* await module.transfer(toAddress, tokenId, amount);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.transfer =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _transfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(to, tokenId, amount) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.t0 = this;
|
|
_context9.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
_context9.t1 = _context9.sent;
|
|
_context9.t2 = to;
|
|
_context9.t3 = tokenId;
|
|
_context9.t4 = amount;
|
|
_context9.t5 = [0];
|
|
_context9.t6 = [_context9.t1, _context9.t2, _context9.t3, _context9.t4, _context9.t5];
|
|
_context9.next = 11;
|
|
return _context9.t0.sendTransaction.call(_context9.t0, "safeTransferFrom", _context9.t6);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function transfer(_x11, _x12, _x13) {
|
|
return _transfer.apply(this, arguments);
|
|
}
|
|
|
|
return transfer;
|
|
}() // owner functions
|
|
|
|
/**
|
|
* Create Pack
|
|
*
|
|
* @remarks Create a new pack with its own rewards.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // Data to create the pack
|
|
* const pack = {
|
|
* // The address of the contract that holds the rewards you want to include
|
|
* assetContract: "0x...",
|
|
* // The metadata of the pack
|
|
* metadata: {
|
|
* name: "Cool Pack",
|
|
* description: "This is a cool pack",
|
|
* // This can be an image url or image file
|
|
* image: readFileSync("path/to/image.png"),
|
|
* },
|
|
* // The NFTs you want to include in the pack
|
|
* assets: [
|
|
* {
|
|
* tokenId: 0, // The token ID of the asset you want to add
|
|
* amount: 1, // The amount of the asset you want to add
|
|
* }, {
|
|
* tokenId: 1,
|
|
* amount: 1,
|
|
* }
|
|
* ],
|
|
* };
|
|
*
|
|
* await module.create(pack);
|
|
* ```
|
|
*
|
|
* @param args - Args for the pack creation
|
|
* @returns - The newly created pack metadata
|
|
*/
|
|
;
|
|
|
|
_proto.create =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _create = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(args) {
|
|
var asset, from, ids, amounts, uri, packParams, tx, receipt, log, packId;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
asset = ERC1155__factory.connect(args.assetContract, this.providerOrSigner);
|
|
_context10.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
from = _context10.sent;
|
|
ids = args.assets.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.assets.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context10.next = 8;
|
|
return this.sdk.getStorage().uploadMetadata(args.metadata);
|
|
|
|
case 8:
|
|
uri = _context10.sent;
|
|
packParams = ethers.utils.defaultAbiCoder.encode(["string", "uint256", "uint256"], [uri, args.secondsUntilOpenStart || 0, args.rewardsPerOpen || 1]); // TODO: make it gasless
|
|
|
|
_context10.t0 = asset;
|
|
_context10.t1 = from;
|
|
_context10.t2 = this.address;
|
|
_context10.t3 = ids;
|
|
_context10.t4 = amounts;
|
|
_context10.t5 = packParams;
|
|
_context10.next = 18;
|
|
return this.getCallOverrides();
|
|
|
|
case 18:
|
|
_context10.t6 = _context10.sent;
|
|
_context10.next = 21;
|
|
return _context10.t0.safeBatchTransferFrom.call(_context10.t0, _context10.t1, _context10.t2, _context10.t3, _context10.t4, _context10.t5, _context10.t6);
|
|
|
|
case 21:
|
|
tx = _context10.sent;
|
|
_context10.next = 24;
|
|
return tx.wait();
|
|
|
|
case 24:
|
|
receipt = _context10.sent;
|
|
log = this.parseLogs("PackCreated", receipt.logs);
|
|
|
|
if (!(log.length === 0)) {
|
|
_context10.next = 28;
|
|
break;
|
|
}
|
|
|
|
throw new Error("PackCreated event not found");
|
|
|
|
case 28:
|
|
packId = log[0].args.packId;
|
|
_context10.next = 31;
|
|
return this.get(packId.toString());
|
|
|
|
case 31:
|
|
return _context10.abrupt("return", _context10.sent);
|
|
|
|
case 32:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function create(_x14) {
|
|
return _create.apply(this, arguments);
|
|
}
|
|
|
|
return create;
|
|
}();
|
|
|
|
_proto.transferFrom = /*#__PURE__*/function () {
|
|
var _transferFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(from, to, args, data) {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
_context11.next = 3;
|
|
return this.sendTransaction("safeTransferFrom", [from, to, args.tokenId, args.amount, data]);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function transferFrom(_x15, _x16, _x17, _x18) {
|
|
return _transferFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferFrom;
|
|
}();
|
|
|
|
_proto.transferBatchFrom = /*#__PURE__*/function () {
|
|
var _transferBatchFrom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(from, to, args, data) {
|
|
var ids, amounts;
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
if (data === void 0) {
|
|
data = [0];
|
|
}
|
|
|
|
ids = args.map(function (a) {
|
|
return a.tokenId;
|
|
});
|
|
amounts = args.map(function (a) {
|
|
return a.amount;
|
|
});
|
|
_context12.next = 5;
|
|
return this.sendTransaction("safeBatchTransferFrom", [from, to, ids, amounts, data]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function transferBatchFrom(_x19, _x20, _x21, _x22) {
|
|
return _transferBatchFrom.apply(this, arguments);
|
|
}
|
|
|
|
return transferBatchFrom;
|
|
}();
|
|
|
|
_proto.getLinkBalance = /*#__PURE__*/function () {
|
|
var _getLinkBalance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13() {
|
|
var chainId, chainlink, erc20;
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
_context13.next = 2;
|
|
return this.getChainID();
|
|
|
|
case 2:
|
|
chainId = _context13.sent;
|
|
chainlink = ChainlinkVrf[chainId];
|
|
erc20 = ERC20__factory.connect(chainlink.linkTokenAddress, this.providerOrSigner);
|
|
_context13.t0 = getCurrencyValue;
|
|
_context13.t1 = this.providerOrSigner;
|
|
_context13.t2 = chainlink.linkTokenAddress;
|
|
_context13.next = 10;
|
|
return erc20.balanceOf(this.address);
|
|
|
|
case 10:
|
|
_context13.t3 = _context13.sent;
|
|
_context13.next = 13;
|
|
return (0, _context13.t0)(_context13.t1, _context13.t2, _context13.t3);
|
|
|
|
case 13:
|
|
return _context13.abrupt("return", _context13.sent);
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function getLinkBalance() {
|
|
return _getLinkBalance.apply(this, arguments);
|
|
}
|
|
|
|
return getLinkBalance;
|
|
}();
|
|
|
|
_proto.depositLink = /*#__PURE__*/function () {
|
|
var _depositLink = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee14(amount) {
|
|
var chainId, chainlink, erc20, tx;
|
|
return runtime_1.wrap(function _callee14$(_context14) {
|
|
while (1) {
|
|
switch (_context14.prev = _context14.next) {
|
|
case 0:
|
|
_context14.next = 2;
|
|
return this.getChainID();
|
|
|
|
case 2:
|
|
chainId = _context14.sent;
|
|
chainlink = ChainlinkVrf[chainId];
|
|
erc20 = ERC20__factory.connect(chainlink.linkTokenAddress, this.providerOrSigner); // TODO: make it gasless
|
|
|
|
_context14.t0 = erc20;
|
|
_context14.t1 = this.address;
|
|
_context14.t2 = amount;
|
|
_context14.next = 10;
|
|
return this.getCallOverrides();
|
|
|
|
case 10:
|
|
_context14.t3 = _context14.sent;
|
|
_context14.next = 13;
|
|
return _context14.t0.transfer.call(_context14.t0, _context14.t1, _context14.t2, _context14.t3);
|
|
|
|
case 13:
|
|
tx = _context14.sent;
|
|
_context14.next = 16;
|
|
return tx.wait();
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context14.stop();
|
|
}
|
|
}
|
|
}, _callee14, this);
|
|
}));
|
|
|
|
function depositLink(_x23) {
|
|
return _depositLink.apply(this, arguments);
|
|
}
|
|
|
|
return depositLink;
|
|
}();
|
|
|
|
_proto.withdrawLink = /*#__PURE__*/function () {
|
|
var _withdrawLink = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee15(to, amount) {
|
|
var _contract, chainId, chainlink;
|
|
|
|
return runtime_1.wrap(function _callee15$(_context15) {
|
|
while (1) {
|
|
switch (_context15.prev = _context15.next) {
|
|
case 0:
|
|
_context15.prev = 0;
|
|
// old version of the contract
|
|
_contract = new Contract$1(this.address, [{
|
|
inputs: [{
|
|
internalType: "address",
|
|
name: "_to",
|
|
type: "address"
|
|
}, {
|
|
internalType: "uint256",
|
|
name: "_amount",
|
|
type: "uint256"
|
|
}],
|
|
name: "transferLink",
|
|
outputs: [],
|
|
stateMutability: "nonpayable",
|
|
type: "function"
|
|
}], this.providerOrSigner);
|
|
_context15.next = 4;
|
|
return this.sendContractTransaction(_contract, "transferLink", [to, amount]);
|
|
|
|
case 4:
|
|
_context15.next = 14;
|
|
break;
|
|
|
|
case 6:
|
|
_context15.prev = 6;
|
|
_context15.t0 = _context15["catch"](0);
|
|
_context15.next = 10;
|
|
return this.getChainID();
|
|
|
|
case 10:
|
|
chainId = _context15.sent;
|
|
chainlink = ChainlinkVrf[chainId];
|
|
_context15.next = 14;
|
|
return this.sendTransaction("transferERC20", [chainlink.linkTokenAddress, to, amount]);
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context15.stop();
|
|
}
|
|
}
|
|
}, _callee15, this, [[0, 6]]);
|
|
}));
|
|
|
|
function withdrawLink(_x24, _x25) {
|
|
return _withdrawLink.apply(this, arguments);
|
|
}
|
|
|
|
return withdrawLink;
|
|
}();
|
|
|
|
_proto.setRoyaltyBps = /*#__PURE__*/function () {
|
|
var _setRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee16(amount) {
|
|
var _yield$this$getMetada, metadata, encoded, uri;
|
|
|
|
return runtime_1.wrap(function _callee16$(_context16) {
|
|
while (1) {
|
|
switch (_context16.prev = _context16.next) {
|
|
case 0:
|
|
_context16.next = 2;
|
|
return this.getMetadata(false);
|
|
|
|
case 2:
|
|
_yield$this$getMetada = _context16.sent;
|
|
metadata = _yield$this$getMetada.metadata;
|
|
encoded = [];
|
|
|
|
if (metadata) {
|
|
_context16.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("No metadata found, this module might be invalid!");
|
|
|
|
case 7:
|
|
metadata.seller_fee_basis_points = amount;
|
|
_context16.t0 = this.sdk.getStorage();
|
|
_context16.t1 = _extends({}, metadata);
|
|
_context16.t2 = this.address;
|
|
_context16.next = 13;
|
|
return this.getSignerAddress();
|
|
|
|
case 13:
|
|
_context16.t3 = _context16.sent;
|
|
_context16.next = 16;
|
|
return _context16.t0.uploadMetadata.call(_context16.t0, _context16.t1, _context16.t2, _context16.t3);
|
|
|
|
case 16:
|
|
uri = _context16.sent;
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setRoyaltyBps", [amount]));
|
|
encoded.push(this.contract["interface"].encodeFunctionData("setContractURI", [uri]));
|
|
_context16.next = 21;
|
|
return this.sendTransaction("multicall", [encoded]);
|
|
|
|
case 21:
|
|
return _context16.abrupt("return", _context16.sent);
|
|
|
|
case 22:
|
|
case "end":
|
|
return _context16.stop();
|
|
}
|
|
}
|
|
}, _callee16, this);
|
|
}));
|
|
|
|
function setRoyaltyBps(_x26) {
|
|
return _setRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return setRoyaltyBps;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee17(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee17$(_context17) {
|
|
while (1) {
|
|
switch (_context17.prev = _context17.next) {
|
|
case 0:
|
|
_context17.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context17.sent;
|
|
_context17.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context17.stop();
|
|
}
|
|
}
|
|
}, _callee17, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x27) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}()
|
|
/**
|
|
* Gets the royalty BPS (basis points) of the contract
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyBps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyBps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee18() {
|
|
return runtime_1.wrap(function _callee18$(_context18) {
|
|
while (1) {
|
|
switch (_context18.prev = _context18.next) {
|
|
case 0:
|
|
_context18.next = 2;
|
|
return this.readOnlyContract.royaltyBps();
|
|
|
|
case 2:
|
|
return _context18.abrupt("return", _context18.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context18.stop();
|
|
}
|
|
}
|
|
}, _callee18, this);
|
|
}));
|
|
|
|
function getRoyaltyBps() {
|
|
return _getRoyaltyBps.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyBps;
|
|
}()
|
|
/**
|
|
* Gets the address of the royalty recipient
|
|
*
|
|
* @returns - The royalty BPS
|
|
*/
|
|
;
|
|
|
|
_proto.getRoyaltyRecipientAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRoyaltyRecipientAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee19() {
|
|
var _metadata$metadata;
|
|
|
|
var metadata;
|
|
return runtime_1.wrap(function _callee19$(_context19) {
|
|
while (1) {
|
|
switch (_context19.prev = _context19.next) {
|
|
case 0:
|
|
_context19.next = 2;
|
|
return this.getMetadata();
|
|
|
|
case 2:
|
|
metadata = _context19.sent;
|
|
|
|
if (!(((_metadata$metadata = metadata.metadata) == null ? void 0 : _metadata$metadata.fee_recipient) !== undefined)) {
|
|
_context19.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context19.abrupt("return", metadata.metadata.fee_recipient);
|
|
|
|
case 5:
|
|
return _context19.abrupt("return", "");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context19.stop();
|
|
}
|
|
}
|
|
}, _callee19, this);
|
|
}));
|
|
|
|
function getRoyaltyRecipientAddress() {
|
|
return _getRoyaltyRecipientAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRoyaltyRecipientAddress;
|
|
}();
|
|
|
|
_proto.isTransferRestricted = /*#__PURE__*/function () {
|
|
var _isTransferRestricted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee20() {
|
|
return runtime_1.wrap(function _callee20$(_context20) {
|
|
while (1) {
|
|
switch (_context20.prev = _context20.next) {
|
|
case 0:
|
|
return _context20.abrupt("return", this.readOnlyContract.transfersRestricted());
|
|
|
|
case 1:
|
|
case "end":
|
|
return _context20.stop();
|
|
}
|
|
}
|
|
}, _callee20, this);
|
|
}));
|
|
|
|
function isTransferRestricted() {
|
|
return _isTransferRestricted.apply(this, arguments);
|
|
}
|
|
|
|
return isTransferRestricted;
|
|
}();
|
|
|
|
_proto.setRestrictedTransfer = /*#__PURE__*/function () {
|
|
var _setRestrictedTransfer = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee21(restricted) {
|
|
return runtime_1.wrap(function _callee21$(_context21) {
|
|
while (1) {
|
|
switch (_context21.prev = _context21.next) {
|
|
case 0:
|
|
if (restricted === void 0) {
|
|
restricted = false;
|
|
}
|
|
|
|
_context21.t0 = this;
|
|
_context21.t1 = ["admin"];
|
|
_context21.next = 5;
|
|
return this.getSignerAddress();
|
|
|
|
case 5:
|
|
_context21.t2 = _context21.sent;
|
|
_context21.next = 8;
|
|
return _context21.t0.onlyRoles.call(_context21.t0, _context21.t1, _context21.t2);
|
|
|
|
case 8:
|
|
_context21.next = 10;
|
|
return this.sendTransaction("setRestrictedTransfer", [restricted]);
|
|
|
|
case 10:
|
|
return _context21.abrupt("return", _context21.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context21.stop();
|
|
}
|
|
}
|
|
}, _callee21, this);
|
|
}));
|
|
|
|
function setRestrictedTransfer(_x28) {
|
|
return _setRestrictedTransfer.apply(this, arguments);
|
|
}
|
|
|
|
return setRestrictedTransfer;
|
|
}()
|
|
/**
|
|
* `getOwned` is a convenience method for getting all owned tokens
|
|
* for a particular wallet.
|
|
*
|
|
* @param _address - The address to check for token ownership
|
|
* @returns An array of PackMetadataWithBalance objects that are owned by the address
|
|
*/
|
|
;
|
|
|
|
_proto.getOwned =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getOwned = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee23(_address) {
|
|
var _this4 = this;
|
|
|
|
var address, maxId, balances, ownedBalances;
|
|
return runtime_1.wrap(function _callee23$(_context23) {
|
|
while (1) {
|
|
switch (_context23.prev = _context23.next) {
|
|
case 0:
|
|
if (!_address) {
|
|
_context23.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context23.t0 = _address;
|
|
_context23.next = 7;
|
|
break;
|
|
|
|
case 4:
|
|
_context23.next = 6;
|
|
return this.getSignerAddress();
|
|
|
|
case 6:
|
|
_context23.t0 = _context23.sent;
|
|
|
|
case 7:
|
|
address = _context23.t0;
|
|
_context23.next = 10;
|
|
return this.readOnlyContract.nextTokenId();
|
|
|
|
case 10:
|
|
maxId = _context23.sent;
|
|
_context23.next = 13;
|
|
return this.readOnlyContract.balanceOfBatch(Array(maxId.toNumber()).fill(address), Array.from(Array(maxId.toNumber()).keys()));
|
|
|
|
case 13:
|
|
balances = _context23.sent;
|
|
ownedBalances = balances.map(function (b, i) {
|
|
return {
|
|
tokenId: i,
|
|
balance: b
|
|
};
|
|
}).filter(function (b) {
|
|
return b.balance.gt(0);
|
|
});
|
|
_context23.next = 17;
|
|
return Promise.all(ownedBalances.map( /*#__PURE__*/function () {
|
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee22(_ref) {
|
|
var tokenId, balance, token;
|
|
return runtime_1.wrap(function _callee22$(_context22) {
|
|
while (1) {
|
|
switch (_context22.prev = _context22.next) {
|
|
case 0:
|
|
tokenId = _ref.tokenId, balance = _ref.balance;
|
|
_context22.next = 3;
|
|
return _this4.get(tokenId.toString());
|
|
|
|
case 3:
|
|
token = _context22.sent;
|
|
return _context22.abrupt("return", _extends({}, token, {
|
|
ownedByAddress: balance
|
|
}));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context22.stop();
|
|
}
|
|
}
|
|
}, _callee22);
|
|
}));
|
|
|
|
return function (_x30) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}()));
|
|
|
|
case 17:
|
|
return _context23.abrupt("return", _context23.sent);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context23.stop();
|
|
}
|
|
}
|
|
}, _callee23, this);
|
|
}));
|
|
|
|
function getOwned(_x29) {
|
|
return _getOwned.apply(this, arguments);
|
|
}
|
|
|
|
return getOwned;
|
|
}();
|
|
|
|
return PackModule;
|
|
}(ModuleWithRoles);
|
|
PackModule.moduleType = ModuleType.PACK;
|
|
PackModule.roles = [RolesMap.admin, RolesMap.minter, RolesMap.pauser, RolesMap.transfer];
|
|
|
|
/**
|
|
* Create custom royalty splits to distribute funds.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getSplitsModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var SplitsModule = /*#__PURE__*/function (_Module) {
|
|
_inheritsLoose(SplitsModule, _Module);
|
|
|
|
function SplitsModule() {
|
|
return _Module.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = SplitsModule.prototype;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
_proto.connectContract = function connectContract() {
|
|
return Royalty__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return SplitsModule.moduleType;
|
|
};
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return getCurrencyMetadata(this.providerOrSigner, this.address);
|
|
|
|
case 2:
|
|
return _context.abrupt("return", _context.sent);
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function get() {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get Recipients
|
|
*
|
|
* @remarks Get the data about the shares of every split recipient on the module
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* const recipients = await module.getAllRecepients();
|
|
* console.log(recipients);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.getAllRecipients =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAllRecipients = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
var recipients, index, totalRecipients, recipientAddress;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
recipients = [];
|
|
index = BigNumber.from(0);
|
|
_context2.next = 4;
|
|
return this.readOnlyContract.payeeCount();
|
|
|
|
case 4:
|
|
totalRecipients = _context2.sent;
|
|
|
|
case 5:
|
|
if (!index.lt(totalRecipients)) {
|
|
_context2.next = 27;
|
|
break;
|
|
}
|
|
|
|
_context2.prev = 6;
|
|
_context2.next = 9;
|
|
return this.readOnlyContract.payee(index);
|
|
|
|
case 9:
|
|
recipientAddress = _context2.sent;
|
|
_context2.t0 = recipients;
|
|
_context2.next = 13;
|
|
return this.getRecipientSplitPercentage(recipientAddress);
|
|
|
|
case 13:
|
|
_context2.t1 = _context2.sent;
|
|
|
|
_context2.t0.push.call(_context2.t0, _context2.t1);
|
|
|
|
index = index.add(1);
|
|
_context2.next = 25;
|
|
break;
|
|
|
|
case 18:
|
|
_context2.prev = 18;
|
|
_context2.t2 = _context2["catch"](6);
|
|
|
|
if (!("method" in _context2.t2 && _context2.t2["method"].toLowerCase().includes("payee(uint256)"))) {
|
|
_context2.next = 24;
|
|
break;
|
|
}
|
|
|
|
return _context2.abrupt("break", 27);
|
|
|
|
case 24:
|
|
throw _context2.t2;
|
|
|
|
case 25:
|
|
_context2.next = 5;
|
|
break;
|
|
|
|
case 27:
|
|
return _context2.abrupt("return", recipients);
|
|
|
|
case 28:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this, [[6, 18]]);
|
|
}));
|
|
|
|
function getAllRecipients() {
|
|
return _getAllRecipients.apply(this, arguments);
|
|
}
|
|
|
|
return getAllRecipients;
|
|
}()
|
|
/**
|
|
*
|
|
* Returns all the recipients and their balances in the native currency.
|
|
* @returns A map of recipient addresses to their balances in the native currency.
|
|
*
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOfAllRecipients =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOfAllRecipients = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
var recipients, balances, _iterator, _step, recipient;
|
|
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.getAllRecipients();
|
|
|
|
case 2:
|
|
recipients = _context3.sent;
|
|
balances = {};
|
|
_iterator = _createForOfIteratorHelperLoose(recipients);
|
|
|
|
case 5:
|
|
if ((_step = _iterator()).done) {
|
|
_context3.next = 12;
|
|
break;
|
|
}
|
|
|
|
recipient = _step.value;
|
|
_context3.next = 9;
|
|
return this.balanceOf(recipient.address);
|
|
|
|
case 9:
|
|
balances[recipient.address] = _context3.sent;
|
|
|
|
case 10:
|
|
_context3.next = 5;
|
|
break;
|
|
|
|
case 12:
|
|
return _context3.abrupt("return", balances);
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function balanceOfAllRecipients() {
|
|
return _balanceOfAllRecipients.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOfAllRecipients;
|
|
}()
|
|
/**
|
|
*
|
|
* Returns all the recipients and their balances in a non-native currency.
|
|
* @param tokenAddress - The address of the currency to check the balances in.
|
|
* @returns A map of recipient addresses to their balances in the specified currency.
|
|
*
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOfTokenAllRecipients =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOfTokenAllRecipients = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(tokenAddress) {
|
|
var recipients, balances, _iterator2, _step2, recipient;
|
|
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.next = 2;
|
|
return this.getAllRecipients();
|
|
|
|
case 2:
|
|
recipients = _context4.sent;
|
|
balances = {};
|
|
_iterator2 = _createForOfIteratorHelperLoose(recipients);
|
|
|
|
case 5:
|
|
if ((_step2 = _iterator2()).done) {
|
|
_context4.next = 12;
|
|
break;
|
|
}
|
|
|
|
recipient = _step2.value;
|
|
_context4.next = 9;
|
|
return this.balanceOfToken(recipient.address, tokenAddress);
|
|
|
|
case 9:
|
|
balances[recipient.address] = _context4.sent;
|
|
|
|
case 10:
|
|
_context4.next = 5;
|
|
break;
|
|
|
|
case 12:
|
|
return _context4.abrupt("return", balances);
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function balanceOfTokenAllRecipients(_x) {
|
|
return _balanceOfTokenAllRecipients.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOfTokenAllRecipients;
|
|
}();
|
|
|
|
_proto.getRecipientSplitPercentage = /*#__PURE__*/function () {
|
|
var _getRecipientSplitPercentage = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address) {
|
|
var _yield$Promise$all, totalShares, walletsShares;
|
|
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.next = 2;
|
|
return Promise.all([this.readOnlyContract.totalShares(), this.readOnlyContract.shares(address)]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context5.sent;
|
|
totalShares = _yield$Promise$all[0];
|
|
walletsShares = _yield$Promise$all[1];
|
|
return _context5.abrupt("return", {
|
|
address: address,
|
|
splitPercentage: walletsShares.mul(BigNumber.from(1e7)).div(totalShares).toNumber() / 1e5
|
|
});
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getRecipientSplitPercentage(_x2) {
|
|
return _getRecipientSplitPercentage.apply(this, arguments);
|
|
}
|
|
|
|
return getRecipientSplitPercentage;
|
|
}()
|
|
/**
|
|
* Get Funds
|
|
*
|
|
* @remarks Get the amount of funds in the native currency held by the module thats owed to a specific recipient.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The address to check the funds of
|
|
* const address = "{{wallet_address}}";
|
|
* const funds = await module.balanceOf(address);
|
|
* console.log(funds);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOf =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOf = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(address) {
|
|
var walletBalance, totalReleased, totalReceived;
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.next = 2;
|
|
return this.readOnlyContract.provider.getBalance(this.address);
|
|
|
|
case 2:
|
|
walletBalance = _context6.sent;
|
|
_context6.next = 5;
|
|
return this.readOnlyContract["totalReleased()"]();
|
|
|
|
case 5:
|
|
totalReleased = _context6.sent;
|
|
totalReceived = walletBalance.add(totalReleased);
|
|
_context6.t0 = this;
|
|
_context6.t1 = address;
|
|
_context6.t2 = totalReceived;
|
|
_context6.next = 12;
|
|
return this.readOnlyContract["released(address)"](address);
|
|
|
|
case 12:
|
|
_context6.t3 = _context6.sent;
|
|
return _context6.abrupt("return", _context6.t0._pendingPayment.call(_context6.t0, _context6.t1, _context6.t2, _context6.t3));
|
|
|
|
case 14:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function balanceOf(_x3) {
|
|
return _balanceOf.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOf;
|
|
}()
|
|
/**
|
|
* Get Token Funds
|
|
*
|
|
* @remarks Get the amount of funds in the non-native tokens held by the module thats owed to a specific recipient.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The address to check the funds of
|
|
* const address = "{{wallet_address}}";
|
|
* // The address of the currency to check the contracts funds of
|
|
* const tokenAddress = "0x..."
|
|
* const funds = await module.balanceOfToken(address, tokenAddress);
|
|
* console.log(funds);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOfToken =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOfToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(walletAddress, tokenAddress) {
|
|
var erc20, walletBalance, totalReleased, totalReceived, value;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
erc20 = ERC20__factory.connect(tokenAddress, this.providerOrSigner);
|
|
_context7.next = 3;
|
|
return erc20.balanceOf(this.address);
|
|
|
|
case 3:
|
|
walletBalance = _context7.sent;
|
|
_context7.next = 6;
|
|
return this.readOnlyContract["totalReleased(address)"](tokenAddress);
|
|
|
|
case 6:
|
|
totalReleased = _context7.sent;
|
|
totalReceived = walletBalance.add(totalReleased);
|
|
_context7.t0 = this;
|
|
_context7.t1 = walletAddress;
|
|
_context7.t2 = totalReceived;
|
|
_context7.next = 13;
|
|
return this.readOnlyContract["released(address,address)"](tokenAddress, walletAddress);
|
|
|
|
case 13:
|
|
_context7.t3 = _context7.sent;
|
|
_context7.next = 16;
|
|
return _context7.t0._pendingPayment.call(_context7.t0, _context7.t1, _context7.t2, _context7.t3);
|
|
|
|
case 16:
|
|
value = _context7.sent;
|
|
_context7.next = 19;
|
|
return getCurrencyValue(this.providerOrSigner, tokenAddress, value);
|
|
|
|
case 19:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 20:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function balanceOfToken(_x4, _x5) {
|
|
return _balanceOfToken.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOfToken;
|
|
}();
|
|
|
|
_proto.withdraw = /*#__PURE__*/function () {
|
|
var _withdraw = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(address) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.sendTransaction("release(address)", [address]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function withdraw(_x6) {
|
|
return _withdraw.apply(this, arguments);
|
|
}
|
|
|
|
return withdraw;
|
|
}();
|
|
|
|
_proto._pendingPayment = /*#__PURE__*/function () {
|
|
var _pendingPayment2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(address, totalReceived, alreadyReleased) {
|
|
var addressReceived, totalRoyaltyAvailable;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.t0 = totalReceived;
|
|
_context9.next = 3;
|
|
return this.readOnlyContract.shares(address);
|
|
|
|
case 3:
|
|
_context9.t1 = _context9.sent;
|
|
addressReceived = _context9.t0.mul.call(_context9.t0, _context9.t1);
|
|
_context9.t2 = addressReceived;
|
|
_context9.next = 8;
|
|
return this.readOnlyContract.totalShares();
|
|
|
|
case 8:
|
|
_context9.t3 = _context9.sent;
|
|
totalRoyaltyAvailable = _context9.t2.div.call(_context9.t2, _context9.t3);
|
|
return _context9.abrupt("return", totalRoyaltyAvailable.sub(alreadyReleased));
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function _pendingPayment(_x7, _x8, _x9) {
|
|
return _pendingPayment2.apply(this, arguments);
|
|
}
|
|
|
|
return _pendingPayment;
|
|
}();
|
|
|
|
_proto.withdrawToken = /*#__PURE__*/function () {
|
|
var _withdrawToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(walletAddress, tokenAddress) {
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
_context10.next = 2;
|
|
return this.sendTransaction("release(address,address)", [tokenAddress, walletAddress]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function withdrawToken(_x10, _x11) {
|
|
return _withdrawToken.apply(this, arguments);
|
|
}
|
|
|
|
return withdrawToken;
|
|
}()
|
|
/**
|
|
* Distribute Funds
|
|
*
|
|
* @remarks Distribute funds held by the contract in the native currency to all recipients.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* await module.distribute();
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.distribute =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _distribute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11() {
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.sendTransaction("distribute()", []);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function distribute() {
|
|
return _distribute.apply(this, arguments);
|
|
}
|
|
|
|
return distribute;
|
|
}()
|
|
/**
|
|
* Distribute Funds
|
|
*
|
|
* @remarks Distribute funds held by the contract in the native currency to all recipients.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The address of the currency to distribute funds
|
|
* const tokenAddress = "0x..."
|
|
* await module.distributeToken(tokenAddress);
|
|
* ```
|
|
*/
|
|
;
|
|
|
|
_proto.distributeToken =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _distributeToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(tokenAddress) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.sendTransaction("distribute(address)", [tokenAddress]);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function distributeToken(_x12) {
|
|
return _distributeToken.apply(this, arguments);
|
|
}
|
|
|
|
return distributeToken;
|
|
}();
|
|
|
|
return SplitsModule;
|
|
}(Module);
|
|
SplitsModule.moduleType = ModuleType.SPLITS;
|
|
|
|
/**
|
|
* Create a decentralized organization for token holders to vote on proposals.
|
|
*
|
|
* @example
|
|
*
|
|
* ```javascript
|
|
* import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
*
|
|
* // You can switch out this provider with any wallet or provider setup you like.
|
|
* const provider = ethers.Wallet.createRandom();
|
|
* const sdk = new ThirdwebSDK(provider);
|
|
* const module = sdk.getVoteModule("{{module_address}}");
|
|
* ```
|
|
*
|
|
* @public
|
|
*/
|
|
|
|
var VoteModule = /*#__PURE__*/function (_Module) {
|
|
_inheritsLoose(VoteModule, _Module);
|
|
|
|
function VoteModule() {
|
|
return _Module.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = VoteModule.prototype;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
_proto.connectContract = function connectContract() {
|
|
return VotingGovernor__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getModuleType = function getModuleType() {
|
|
return VoteModule.moduleType;
|
|
};
|
|
|
|
_proto.settings = /*#__PURE__*/function () {
|
|
var _settings = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var _yield$Promise$all, votingDelay, votingPeriod, votingTokenAddress, votingQuorumFraction, proposalTokenThreshold, votingTokenMetadata;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.next = 2;
|
|
return Promise.all([this.readOnlyContract.votingDelay(), this.readOnlyContract.votingPeriod(), this.readOnlyContract.token(), this.readOnlyContract.quorumNumerator(), this.readOnlyContract.proposalThreshold()]);
|
|
|
|
case 2:
|
|
_yield$Promise$all = _context.sent;
|
|
votingDelay = _yield$Promise$all[0];
|
|
votingPeriod = _yield$Promise$all[1];
|
|
votingTokenAddress = _yield$Promise$all[2];
|
|
votingQuorumFraction = _yield$Promise$all[3];
|
|
proposalTokenThreshold = _yield$Promise$all[4];
|
|
_context.next = 10;
|
|
return getCurrencyMetadata(this.providerOrSigner, votingTokenAddress);
|
|
|
|
case 10:
|
|
votingTokenMetadata = _context.sent;
|
|
return _context.abrupt("return", {
|
|
votingDelay: votingDelay.toString(),
|
|
votingPeriod: votingPeriod.toString(),
|
|
votingTokenAddress: votingTokenAddress,
|
|
votingTokenMetadata: votingTokenMetadata,
|
|
votingQuorumFraction: votingQuorumFraction.toString(),
|
|
proposalTokenThreshold: proposalTokenThreshold.toString()
|
|
});
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function settings() {
|
|
return _settings.apply(this, arguments);
|
|
}
|
|
|
|
return settings;
|
|
}()
|
|
/**
|
|
* Get a proposal by id.
|
|
*
|
|
* @param proposalId - The proposal id to get.
|
|
* @returns - The proposal.
|
|
*/
|
|
;
|
|
|
|
_proto.get =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(proposalId) {
|
|
var all, proposals;
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
_context2.next = 2;
|
|
return this.ensureExists(proposalId);
|
|
|
|
case 2:
|
|
_context2.next = 4;
|
|
return this.getAll();
|
|
|
|
case 4:
|
|
all = _context2.sent;
|
|
proposals = all.filter(function (p) {
|
|
return p.proposalId.toLowerCase() === proposalId.toLowerCase();
|
|
});
|
|
|
|
if (!(proposals.length === 0)) {
|
|
_context2.next = 8;
|
|
break;
|
|
}
|
|
|
|
throw new Error("proposal not found");
|
|
|
|
case 8:
|
|
return _context2.abrupt("return", proposals[0]);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function get(_x) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* Get All Proposals
|
|
*
|
|
* @remarks Get all the proposals in this module.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* const proposals = await module.getAll();
|
|
* console.log(proposals);
|
|
* ```
|
|
*
|
|
* @returns - All the proposals in the contract.
|
|
*/
|
|
;
|
|
|
|
_proto.getAll =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getAll = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
var _this = this;
|
|
|
|
var proposals, results, states, votes, i, p, s, v, e, j;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.readOnlyContract.queryFilter(this.contract.filters.ProposalCreated());
|
|
|
|
case 2:
|
|
proposals = _context3.sent;
|
|
results = [];
|
|
_context3.next = 6;
|
|
return Promise.all(proposals.map(function (p) {
|
|
return _this.readOnlyContract.state(p.args.proposalId);
|
|
}));
|
|
|
|
case 6:
|
|
states = _context3.sent;
|
|
_context3.next = 9;
|
|
return Promise.all(proposals.map(function (p) {
|
|
return _this.readOnlyContract.proposalVotes(p.args.proposalId);
|
|
}));
|
|
|
|
case 9:
|
|
votes = _context3.sent;
|
|
|
|
for (i = 0; i < proposals.length; i++) {
|
|
p = proposals[i].args;
|
|
s = states[i];
|
|
v = [{
|
|
type: VoteType.Against,
|
|
label: "Against",
|
|
count: votes[i].againstVotes
|
|
}, {
|
|
type: VoteType.For,
|
|
label: "For",
|
|
count: votes[i].forVotes
|
|
}, {
|
|
type: VoteType.Abstain,
|
|
label: "Abstain",
|
|
count: votes[i].abstainVotes
|
|
}];
|
|
e = [];
|
|
|
|
for (j = 0; j < p.targets.length; j++) {
|
|
e.push({
|
|
to: p.targets[j],
|
|
value: p[3][j] || 0,
|
|
data: p.calldatas[j]
|
|
});
|
|
}
|
|
|
|
results.push({
|
|
proposalId: p.proposalId.toString(),
|
|
proposer: p.proposer,
|
|
description: p.description,
|
|
startBlock: p.startBlock,
|
|
endBlock: p.endBlock,
|
|
state: s,
|
|
votes: v,
|
|
executions: e.map(function (exec) {
|
|
return {
|
|
toAddress: exec.to,
|
|
nativeTokenValue: exec.value,
|
|
transactionData: exec.data
|
|
};
|
|
})
|
|
});
|
|
}
|
|
|
|
return _context3.abrupt("return", results);
|
|
|
|
case 12:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getAll() {
|
|
return _getAll.apply(this, arguments);
|
|
}
|
|
|
|
return getAll;
|
|
}()
|
|
/**
|
|
* Create Proposal
|
|
*
|
|
* @remarks Create a new proposal for token holders to vote on.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The description of the proposal you want to pass
|
|
* const description = "This is a great proposal - vote for it!"
|
|
* // You can (optionally) pass in contract calls that will executed when the proposal is executed.
|
|
* const executions = [
|
|
* {
|
|
* // The contract you want to make a call to
|
|
* toAddress: "0x...",
|
|
* // The amount of the native currency to send in this transaction
|
|
* nativeTokenValue: 0,
|
|
* // Transaction data that will be executed when the proposal is executed
|
|
* // This is an example transfer transaction with a token module (which you would need to setup in code)
|
|
* transactionData: tokenModule.contract.interface.encodeFunctionData(
|
|
* "transfer", [
|
|
* fromAddress,
|
|
* amount,
|
|
* ]
|
|
* ),
|
|
* }
|
|
* ]
|
|
*
|
|
* const proposal = await module.propose(description, executions);
|
|
* ```
|
|
*
|
|
* @param description - The description of the proposal.
|
|
* @param executions - A set of executable transactions that will be run if the proposal is passed and executed.
|
|
* @returns - The id of the created proposal.
|
|
*/
|
|
;
|
|
|
|
_proto.propose =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _propose = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(description, executions) {
|
|
var tos, values, datas, receipt, event;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
if (!executions) {
|
|
executions = [{
|
|
toAddress: this.address,
|
|
nativeTokenValue: 0,
|
|
transactionData: "0x"
|
|
}];
|
|
}
|
|
|
|
tos = executions.map(function (p) {
|
|
return p.toAddress;
|
|
});
|
|
values = executions.map(function (p) {
|
|
return p.nativeTokenValue;
|
|
});
|
|
datas = executions.map(function (p) {
|
|
return p.transactionData;
|
|
});
|
|
_context4.next = 6;
|
|
return this.sendTransaction("propose", [tos, values, datas, description]);
|
|
|
|
case 6:
|
|
receipt = _context4.sent;
|
|
event = this.parseEventLogs("ProposalCreated", receipt == null ? void 0 : receipt.logs);
|
|
return _context4.abrupt("return", event.proposalId);
|
|
|
|
case 9:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function propose(_x2, _x3) {
|
|
return _propose.apply(this, arguments);
|
|
}
|
|
|
|
return propose;
|
|
}()
|
|
/**
|
|
* Vote
|
|
*
|
|
* @remarks Vote on an active proposal
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The proposal ID of the proposal you want to vote on
|
|
* const proposalId = "0";
|
|
* // The vote type you want to cast, can be VoteType.Against, VoteType.For, or VoteType.Abstain
|
|
* const voteType = VoteType.For;
|
|
* // The (optional) reason for the vote
|
|
* const reason = "I like this proposal!";
|
|
*
|
|
* await module.vote(proposalId, voteType, reason);
|
|
* ```
|
|
* @param proposalId - The proposal to cast a vote on.
|
|
* @param voteType - The position the voter is taking on their vote.
|
|
* @param reason - (optional) The reason for the vote.
|
|
*/
|
|
;
|
|
|
|
_proto.vote =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _vote = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(proposalId, voteType, reason) {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
if (reason === void 0) {
|
|
reason = "";
|
|
}
|
|
|
|
_context5.next = 3;
|
|
return this.ensureExists(proposalId);
|
|
|
|
case 3:
|
|
_context5.next = 5;
|
|
return this.sendTransaction("castVoteWithReason", [proposalId, voteType, reason]);
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function vote(_x4, _x5, _x6) {
|
|
return _vote.apply(this, arguments);
|
|
}
|
|
|
|
return vote;
|
|
}()
|
|
/**
|
|
* Check If Wallet Voted
|
|
*
|
|
* @remarks Check if a specified wallet has voted a specific proposal
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The proposal ID of the proposal you want to check
|
|
* const proposalId = "0";
|
|
* // The address of the wallet you want to check to see if they voted
|
|
* const address = "{{wallet_address}}";
|
|
*
|
|
* await module.hasVoted(proposalId, address);
|
|
* ```
|
|
*
|
|
* @param proposalId - The unique identifier of a proposal .
|
|
* @param account - (optional) wallet account address. Defaults to connected signer.
|
|
* @returns - True if the account has already voted on the proposal.
|
|
*/
|
|
;
|
|
|
|
_proto.hasVoted =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _hasVoted = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(proposalId, account) {
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
if (account) {
|
|
_context6.next = 4;
|
|
break;
|
|
}
|
|
|
|
_context6.next = 3;
|
|
return this.getSignerAddress();
|
|
|
|
case 3:
|
|
account = _context6.sent;
|
|
|
|
case 4:
|
|
return _context6.abrupt("return", this.readOnlyContract.hasVoted(proposalId, account));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function hasVoted(_x7, _x8) {
|
|
return _hasVoted.apply(this, arguments);
|
|
}
|
|
|
|
return hasVoted;
|
|
}()
|
|
/**
|
|
* Execute Proposal
|
|
*
|
|
* @remarks Execute the related transactions for a proposal if the proposal succeeded.
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The proposal ID ofthe proposal you want to execute
|
|
* const proposalId = "0"
|
|
* await module.execute(proposalId);
|
|
* ```
|
|
*
|
|
* @param proposalId - The proposal id to execute.
|
|
*/
|
|
;
|
|
|
|
_proto.execute =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _execute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(proposalId) {
|
|
var proposal, tos, values, datas, descriptionHash;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_context7.next = 2;
|
|
return this.ensureExists(proposalId);
|
|
|
|
case 2:
|
|
_context7.next = 4;
|
|
return this.get(proposalId);
|
|
|
|
case 4:
|
|
proposal = _context7.sent;
|
|
tos = proposal.executions.map(function (p) {
|
|
return p.toAddress;
|
|
});
|
|
values = proposal.executions.map(function (p) {
|
|
return p.nativeTokenValue;
|
|
});
|
|
datas = proposal.executions.map(function (p) {
|
|
return p.transactionData;
|
|
});
|
|
descriptionHash = ethers.utils.id(proposal.description);
|
|
_context7.next = 11;
|
|
return this.sendTransaction("execute", [tos, values, datas, descriptionHash]);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function execute(_x9) {
|
|
return _execute.apply(this, arguments);
|
|
}
|
|
|
|
return execute;
|
|
}()
|
|
/**
|
|
* Can Execute
|
|
*
|
|
* @remarks Check if a proposal can be executed (if the proposal has succeeded).
|
|
*
|
|
* @example
|
|
* ```javascript
|
|
* // The proposal ID of the proposal you want to check
|
|
* const proposalId = "0";
|
|
* const canExecute = await module.canExecute(proposalId);
|
|
* console.log(canExecute);
|
|
* ```
|
|
*
|
|
* @param proposalId - The proposal ID to check.
|
|
* @returns - True if the proposal can be executed, false otherwise.
|
|
*/
|
|
;
|
|
|
|
_proto.canExecute =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _canExecute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(proposalId) {
|
|
var proposal, tos, values, datas, descriptionHash;
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.next = 2;
|
|
return this.ensureExists(proposalId);
|
|
|
|
case 2:
|
|
_context8.next = 4;
|
|
return this.get(proposalId);
|
|
|
|
case 4:
|
|
proposal = _context8.sent;
|
|
tos = proposal.executions.map(function (p) {
|
|
return p.toAddress;
|
|
});
|
|
values = proposal.executions.map(function (p) {
|
|
return p.nativeTokenValue;
|
|
});
|
|
datas = proposal.executions.map(function (p) {
|
|
return p.transactionData;
|
|
});
|
|
descriptionHash = ethers.utils.id(proposal.description);
|
|
_context8.prev = 9;
|
|
_context8.next = 12;
|
|
return this.contract.callStatic.execute(tos, values, datas, descriptionHash);
|
|
|
|
case 12:
|
|
return _context8.abrupt("return", true);
|
|
|
|
case 15:
|
|
_context8.prev = 15;
|
|
_context8.t0 = _context8["catch"](9);
|
|
return _context8.abrupt("return", false);
|
|
|
|
case 18:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this, [[9, 15]]);
|
|
}));
|
|
|
|
function canExecute(_x10) {
|
|
return _canExecute.apply(this, arguments);
|
|
}
|
|
|
|
return canExecute;
|
|
}()
|
|
/**
|
|
* Check the balance of the project wallet in the native token of the chain
|
|
*
|
|
* @returns - The balance of the project in the native token of the chain
|
|
*/
|
|
;
|
|
|
|
_proto.balance =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balance = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9() {
|
|
var balance;
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
_context9.next = 2;
|
|
return this.readOnlyContract.provider.getBalance(this.address);
|
|
|
|
case 2:
|
|
balance = _context9.sent;
|
|
return _context9.abrupt("return", {
|
|
name: "",
|
|
symbol: "",
|
|
decimals: 18,
|
|
value: balance.toString(),
|
|
displayValue: ethers.utils.formatUnits(balance, 18)
|
|
});
|
|
|
|
case 4:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function balance() {
|
|
return _balance.apply(this, arguments);
|
|
}
|
|
|
|
return balance;
|
|
}()
|
|
/**
|
|
* Check the balance of the project wallet in a particular
|
|
* ERC20 token contract
|
|
*
|
|
* @returns - The balance of the project in the native token of the chain
|
|
*/
|
|
;
|
|
|
|
_proto.balanceOfToken =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _balanceOfToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(tokenAddress) {
|
|
var erc20;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
erc20 = ERC20__factory.connect(tokenAddress, this.readOnlyContract.provider);
|
|
_context10.t0 = getCurrencyValue;
|
|
_context10.t1 = this.providerOrSigner;
|
|
_context10.t2 = tokenAddress;
|
|
_context10.next = 6;
|
|
return erc20.balanceOf(this.address);
|
|
|
|
case 6:
|
|
_context10.t3 = _context10.sent;
|
|
_context10.next = 9;
|
|
return (0, _context10.t0)(_context10.t1, _context10.t2, _context10.t3);
|
|
|
|
case 9:
|
|
return _context10.abrupt("return", _context10.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function balanceOfToken(_x11) {
|
|
return _balanceOfToken.apply(this, arguments);
|
|
}
|
|
|
|
return balanceOfToken;
|
|
}();
|
|
|
|
_proto.setModuleMetadata = /*#__PURE__*/function () {
|
|
var _setModuleMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(metadata) {
|
|
var uri;
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
_context11.next = 2;
|
|
return this.sdk.getStorage().uploadMetadata(metadata);
|
|
|
|
case 2:
|
|
uri = _context11.sent;
|
|
_context11.next = 5;
|
|
return this.sendTransaction("setContractURI", [uri]);
|
|
|
|
case 5:
|
|
return _context11.abrupt("return", _context11.sent);
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function setModuleMetadata(_x12) {
|
|
return _setModuleMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return setModuleMetadata;
|
|
}()
|
|
/**
|
|
* Find a proposal by its id.
|
|
*
|
|
* @internal
|
|
* @param proposalId - Proposal to check for
|
|
*/
|
|
;
|
|
|
|
_proto.ensureExists =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ensureExists = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(proposalId) {
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
_context12.next = 2;
|
|
return this.readOnlyContract.state(proposalId);
|
|
|
|
case 2:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function ensureExists(_x13) {
|
|
return _ensureExists.apply(this, arguments);
|
|
}
|
|
|
|
return ensureExists;
|
|
}();
|
|
|
|
return VoteModule;
|
|
}(Module);
|
|
VoteModule.moduleType = ModuleType.VOTE;
|
|
|
|
if (!globalThis.FormData) {
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
globalThis.FormData = /*#__PURE__*/require("form-data");
|
|
}
|
|
|
|
var thirdwebIpfsServerUrl = "https://upload.nftlabs.co";
|
|
var pinataIpfsUrl = "https://api.pinata.cloud/pinning/pinFileToIPFS";
|
|
var IpfsStorage = /*#__PURE__*/function () {
|
|
function IpfsStorage(gatewayUrl) {
|
|
this.gatewayUrl = void 0;
|
|
this.gatewayUrl = gatewayUrl.replace(/\/$/, "") + "/";
|
|
}
|
|
|
|
var _proto = IpfsStorage.prototype;
|
|
|
|
_proto.upload = /*#__PURE__*/function () {
|
|
var _upload = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(data, contractAddress, signerAddress) {
|
|
var cid, _cid, headers, formData, res, body;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
if (!(typeof data === "string")) {
|
|
_context.next = 7;
|
|
break;
|
|
}
|
|
|
|
_context.next = 3;
|
|
return this.uploadBatch([data], contractAddress, 0);
|
|
|
|
case 3:
|
|
cid = _context.sent;
|
|
return _context.abrupt("return", cid + "0");
|
|
|
|
case 7:
|
|
if (!(data instanceof Buffer)) {
|
|
_context.next = 12;
|
|
break;
|
|
}
|
|
|
|
_context.next = 10;
|
|
return this.uploadBatch([data], contractAddress, 0);
|
|
|
|
case 10:
|
|
_cid = _context.sent;
|
|
return _context.abrupt("return", _cid + "0");
|
|
|
|
case 12:
|
|
// if it's file type, we're doing legacy upload
|
|
headers = {
|
|
"X-App-Name": "CONSOLE-TS-SDK-" + contractAddress,
|
|
"X-Public-Address": signerAddress || ""
|
|
};
|
|
formData = new FormData();
|
|
formData.append("file", data);
|
|
_context.prev = 15;
|
|
_context.next = 18;
|
|
return fetch(thirdwebIpfsServerUrl + "/upload", {
|
|
method: "POST",
|
|
body: formData,
|
|
headers: headers
|
|
});
|
|
|
|
case 18:
|
|
res = _context.sent;
|
|
|
|
if (!(res.status !== 200)) {
|
|
_context.next = 21;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Failed to upload to IPFS [status code = " + res.status + "]");
|
|
|
|
case 21:
|
|
_context.next = 23;
|
|
return res.json();
|
|
|
|
case 23:
|
|
body = _context.sent;
|
|
return _context.abrupt("return", body.IpfsUri);
|
|
|
|
case 27:
|
|
_context.prev = 27;
|
|
_context.t0 = _context["catch"](15);
|
|
throw new UploadError("Failed to upload to IPFS: " + _context.t0);
|
|
|
|
case 30:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this, [[15, 27]]);
|
|
}));
|
|
|
|
function upload(_x, _x2, _x3) {
|
|
return _upload.apply(this, arguments);
|
|
}
|
|
|
|
return upload;
|
|
}();
|
|
|
|
_proto.uploadBatch = /*#__PURE__*/function () {
|
|
var _uploadBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(files, contractAddress, fileStartNumber) {
|
|
var _yield$this$uploadBat, cid;
|
|
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
if (fileStartNumber === void 0) {
|
|
fileStartNumber = 0;
|
|
}
|
|
|
|
_context2.next = 3;
|
|
return this.uploadBatchWithCid(files, contractAddress, fileStartNumber);
|
|
|
|
case 3:
|
|
_yield$this$uploadBat = _context2.sent;
|
|
cid = _yield$this$uploadBat.cid;
|
|
return _context2.abrupt("return", "ipfs://" + cid + "/");
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function uploadBatch(_x4, _x5, _x6) {
|
|
return _uploadBatch.apply(this, arguments);
|
|
}
|
|
|
|
return uploadBatch;
|
|
}();
|
|
|
|
_proto.uploadBatchWithCid = /*#__PURE__*/function () {
|
|
var _uploadBatchWithCid = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(files, contractAddress, fileStartNumber) {
|
|
var token, metadata, data, fileNames, res, body;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
if (fileStartNumber === void 0) {
|
|
fileStartNumber = 0;
|
|
}
|
|
|
|
_context3.next = 3;
|
|
return this.getUploadToken(contractAddress || "");
|
|
|
|
case 3:
|
|
token = _context3.sent;
|
|
metadata = {
|
|
name: "CONSOLE-TS-SDK-" + contractAddress
|
|
};
|
|
data = new FormData();
|
|
fileNames = [];
|
|
files.forEach(function (file, i) {
|
|
var fileName = "";
|
|
var fileData = file; // if it is a file, we passthrough the file extensions,
|
|
// if it is a buffer or string, the filename would be fileStartNumber + index
|
|
// if it is a buffer or string with names, the filename would be the name
|
|
|
|
if (file instanceof File) {
|
|
var extensions = "";
|
|
|
|
if (file.name) {
|
|
var extensionStartIndex = file.name.lastIndexOf(".");
|
|
|
|
if (extensionStartIndex > -1) {
|
|
extensions = file.name.substring(extensionStartIndex);
|
|
}
|
|
}
|
|
|
|
fileName = "" + (i + fileStartNumber) + extensions;
|
|
} else if (file instanceof Buffer || typeof file === "string") {
|
|
fileName = "" + (i + fileStartNumber);
|
|
} else if (file && file.name && file != null && file.data) {
|
|
fileData = file == null ? void 0 : file.data;
|
|
fileName = "" + file.name;
|
|
} else {
|
|
// default behavior
|
|
fileName = "" + (i + fileStartNumber);
|
|
}
|
|
|
|
var filepath = "files/" + fileName;
|
|
|
|
if (fileNames.indexOf(fileName) > -1) {
|
|
throw new DuplicateFileNameError(fileName);
|
|
}
|
|
|
|
fileNames.push(fileName);
|
|
|
|
if (typeof window === "undefined") {
|
|
data.append("file", fileData, {
|
|
filepath: filepath
|
|
});
|
|
} else {
|
|
// browser does blob things, filepath is parsed differently on browser vs node.
|
|
// pls pinata?
|
|
data.append("file", new Blob([fileData]), filepath);
|
|
}
|
|
});
|
|
data.append("pinataMetadata", JSON.stringify(metadata));
|
|
_context3.next = 11;
|
|
return fetch(pinataIpfsUrl, {
|
|
method: "POST",
|
|
headers: {
|
|
Authorization: "Bearer " + token
|
|
},
|
|
body: data
|
|
});
|
|
|
|
case 11:
|
|
res = _context3.sent;
|
|
_context3.next = 14;
|
|
return res.json();
|
|
|
|
case 14:
|
|
body = _context3.sent;
|
|
|
|
if (res.ok) {
|
|
_context3.next = 18;
|
|
break;
|
|
}
|
|
|
|
console.log(body);
|
|
throw new UploadError("Failed to upload files to IPFS");
|
|
|
|
case 18:
|
|
return _context3.abrupt("return", {
|
|
cid: body.IpfsHash,
|
|
fileNames: fileNames
|
|
});
|
|
|
|
case 19:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function uploadBatchWithCid(_x7, _x8, _x9) {
|
|
return _uploadBatchWithCid.apply(this, arguments);
|
|
}
|
|
|
|
return uploadBatchWithCid;
|
|
}();
|
|
|
|
_proto.getUploadToken = /*#__PURE__*/function () {
|
|
var _getUploadToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(contractAddress) {
|
|
var headers, res, body;
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
headers = {
|
|
"X-App-Name": "CONSOLE-TS-SDK-" + contractAddress
|
|
};
|
|
_context4.next = 3;
|
|
return fetch(thirdwebIpfsServerUrl + "/grant", {
|
|
method: "GET",
|
|
headers: headers
|
|
});
|
|
|
|
case 3:
|
|
res = _context4.sent;
|
|
|
|
if (res.ok) {
|
|
_context4.next = 6;
|
|
break;
|
|
}
|
|
|
|
throw new FetchError("Failed to get upload token");
|
|
|
|
case 6:
|
|
_context4.next = 8;
|
|
return res.text();
|
|
|
|
case 8:
|
|
body = _context4.sent;
|
|
return _context4.abrupt("return", body);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4);
|
|
}));
|
|
|
|
function getUploadToken(_x10) {
|
|
return _getUploadToken.apply(this, arguments);
|
|
}
|
|
|
|
return getUploadToken;
|
|
}();
|
|
|
|
_proto.get = /*#__PURE__*/function () {
|
|
var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(hash) {
|
|
var uri, result;
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
uri = hash;
|
|
|
|
if (hash) {
|
|
uri = this.resolveFullUrl(hash);
|
|
}
|
|
|
|
_context5.next = 4;
|
|
return fetch(uri);
|
|
|
|
case 4:
|
|
result = _context5.sent;
|
|
|
|
if (result.ok) {
|
|
_context5.next = 7;
|
|
break;
|
|
}
|
|
|
|
throw new Error("Status code (!= 200) =" + result.status);
|
|
|
|
case 7:
|
|
_context5.next = 9;
|
|
return result.text();
|
|
|
|
case 9:
|
|
return _context5.abrupt("return", _context5.sent);
|
|
|
|
case 10:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function get(_x11) {
|
|
return _get.apply(this, arguments);
|
|
}
|
|
|
|
return get;
|
|
}()
|
|
/**
|
|
* This function recurisely traverses an object and hashes any
|
|
* `Buffer` or `File` objects into the returned map.
|
|
*
|
|
* @param object - The object to recurse over
|
|
* @param files - The running array of files or buffer to upload
|
|
* @returns - The final map of all hashes to files
|
|
*/
|
|
;
|
|
|
|
_proto.buildFilePropertiesMap = function buildFilePropertiesMap(object, files) {
|
|
var keys = Object.keys(object).sort();
|
|
|
|
for (var key in keys) {
|
|
var val = object[keys[key]];
|
|
var shouldUpload = val instanceof File || val instanceof Buffer;
|
|
|
|
if (shouldUpload) {
|
|
files.push(val);
|
|
}
|
|
|
|
if (typeof val === "object") {
|
|
this.buildFilePropertiesMap(val, files);
|
|
}
|
|
}
|
|
|
|
return files;
|
|
}
|
|
/**
|
|
* Pre-processes metadata and uploads all file properties
|
|
* to storage in *bulk*, then performs a string replacement of
|
|
* all file properties -> the resulting ipfs uri. This is
|
|
* called internally by `uploadMetadataBatch`.
|
|
*
|
|
* @internal
|
|
*
|
|
* @param metadata - The metadata to recursively process
|
|
* @returns - The processed metadata with properties pointing at ipfs in place of `File | Buffer`
|
|
*/
|
|
;
|
|
|
|
_proto.batchUploadProperties =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _batchUploadProperties = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(metadatas) {
|
|
var filesToUpload, _yield$this$uploadBat2, cid, fileNames, cids, _iterator, _step, filename, finalMetadata;
|
|
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
if (!(typeof metadatas === "string")) {
|
|
_context6.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context6.abrupt("return", metadatas);
|
|
|
|
case 2:
|
|
filesToUpload = this.buildFilePropertiesMap(metadatas, []);
|
|
|
|
if (!(filesToUpload.length === 0)) {
|
|
_context6.next = 5;
|
|
break;
|
|
}
|
|
|
|
return _context6.abrupt("return", metadatas);
|
|
|
|
case 5:
|
|
_context6.next = 7;
|
|
return this.uploadBatchWithCid(filesToUpload, "", 0);
|
|
|
|
case 7:
|
|
_yield$this$uploadBat2 = _context6.sent;
|
|
cid = _yield$this$uploadBat2.cid;
|
|
fileNames = _yield$this$uploadBat2.fileNames;
|
|
cids = []; // recurse ordered array
|
|
|
|
for (_iterator = _createForOfIteratorHelperLoose(fileNames); !(_step = _iterator()).done;) {
|
|
filename = _step.value;
|
|
cids.push(cid + "/" + filename);
|
|
}
|
|
|
|
_context6.next = 14;
|
|
return this.replaceFilePropertiesWithHashes(metadatas, cids);
|
|
|
|
case 14:
|
|
finalMetadata = _context6.sent;
|
|
return _context6.abrupt("return", finalMetadata);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function batchUploadProperties(_x12) {
|
|
return _batchUploadProperties.apply(this, arguments);
|
|
}
|
|
|
|
return batchUploadProperties;
|
|
}()
|
|
/**
|
|
* Given a map of file hashes to ipfs uris, this function will hash
|
|
* all properties recursively and replace them with the ipfs uris
|
|
* from the map passed in. If a hash is missing from the map, the function
|
|
* will throw an error.
|
|
*
|
|
* @internal
|
|
*
|
|
* @param object - The object to recursively process
|
|
* @param cids - The array of file hashes to ipfs uris in the recurse order
|
|
* @returns - The processed metadata with properties pointing at ipfs in place of `File | Buffer`
|
|
*/
|
|
;
|
|
|
|
_proto.replaceFilePropertiesWithHashes =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _replaceFilePropertiesWithHashes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(object, cids) {
|
|
var keys, key, val, isFile;
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
keys = Object.keys(object).sort();
|
|
_context7.t0 = runtime_1.keys(keys);
|
|
|
|
case 2:
|
|
if ((_context7.t1 = _context7.t0()).done) {
|
|
_context7.next = 15;
|
|
break;
|
|
}
|
|
|
|
key = _context7.t1.value;
|
|
val = object[keys[key]];
|
|
isFile = val instanceof File || val instanceof Buffer;
|
|
|
|
if (!(typeof val === "object" && !isFile)) {
|
|
_context7.next = 10;
|
|
break;
|
|
}
|
|
|
|
_context7.next = 9;
|
|
return this.replaceFilePropertiesWithHashes(val, cids);
|
|
|
|
case 9:
|
|
return _context7.abrupt("continue", 2);
|
|
|
|
case 10:
|
|
if (isFile) {
|
|
_context7.next = 12;
|
|
break;
|
|
}
|
|
|
|
return _context7.abrupt("continue", 2);
|
|
|
|
case 12:
|
|
object[keys[key]] = "ipfs://" + cids.splice(0, 1)[0];
|
|
_context7.next = 2;
|
|
break;
|
|
|
|
case 15:
|
|
return _context7.abrupt("return", object);
|
|
|
|
case 16:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function replaceFilePropertiesWithHashes(_x13, _x14) {
|
|
return _replaceFilePropertiesWithHashes.apply(this, arguments);
|
|
}
|
|
|
|
return replaceFilePropertiesWithHashes;
|
|
}();
|
|
|
|
_proto.uploadMetadata = /*#__PURE__*/function () {
|
|
var _uploadMetadata = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(metadata, contractAddress, _signerAddress) {
|
|
var _yield$this$uploadMet, metadataUris;
|
|
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
if (!(typeof metadata === "string")) {
|
|
_context8.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context8.abrupt("return", metadata);
|
|
|
|
case 2:
|
|
_context8.next = 4;
|
|
return this.uploadMetadataBatch([metadata], contractAddress, 0);
|
|
|
|
case 4:
|
|
_yield$this$uploadMet = _context8.sent;
|
|
metadataUris = _yield$this$uploadMet.metadataUris;
|
|
return _context8.abrupt("return", metadataUris[0]);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function uploadMetadata(_x15, _x16, _x17) {
|
|
return _uploadMetadata.apply(this, arguments);
|
|
}
|
|
|
|
return uploadMetadata;
|
|
}()
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.uploadMetadataBatch =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _uploadMetadataBatch = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(metadatas, contractAddress, startFileNumber) {
|
|
var metadataObjects, metadataToUpload, _yield$this$uploadBat3, cid, fileNames, baseUri, uris, _iterator2, _step2, metadata;
|
|
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
// we only want to upload if the metadata object is not a string
|
|
metadataObjects = metadatas.filter(function (m) {
|
|
return typeof m !== "string";
|
|
});
|
|
_context9.next = 3;
|
|
return this.batchUploadProperties(metadataObjects);
|
|
|
|
case 3:
|
|
metadataToUpload = _context9.sent.map(function (m) {
|
|
return JSON.stringify(m);
|
|
});
|
|
|
|
if (!(metadataToUpload.length === 0)) {
|
|
_context9.next = 6;
|
|
break;
|
|
}
|
|
|
|
return _context9.abrupt("return", {
|
|
baseUri: "",
|
|
metadataUris: metadatas.filter(function (m) {
|
|
return typeof m === "string";
|
|
})
|
|
});
|
|
|
|
case 6:
|
|
_context9.next = 8;
|
|
return this.uploadBatchWithCid(metadataToUpload, contractAddress, startFileNumber);
|
|
|
|
case 8:
|
|
_yield$this$uploadBat3 = _context9.sent;
|
|
cid = _yield$this$uploadBat3.cid;
|
|
fileNames = _yield$this$uploadBat3.fileNames;
|
|
baseUri = "ipfs://" + cid + "/";
|
|
uris = [];
|
|
|
|
for (_iterator2 = _createForOfIteratorHelperLoose(metadatas); !(_step2 = _iterator2()).done;) {
|
|
metadata = _step2.value;
|
|
|
|
if (typeof metadata === "string") {
|
|
uris.push(metadata);
|
|
} else {
|
|
uris.push("" + baseUri + fileNames.splice(0, 1)[0]);
|
|
}
|
|
}
|
|
|
|
return _context9.abrupt("return", {
|
|
baseUri: baseUri,
|
|
metadataUris: uris
|
|
});
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function uploadMetadataBatch(_x18, _x19, _x20) {
|
|
return _uploadMetadataBatch.apply(this, arguments);
|
|
}
|
|
|
|
return uploadMetadataBatch;
|
|
}()
|
|
/**
|
|
* Resolves the full url for a file using the configured gateway
|
|
*
|
|
* @param ipfsHash - the ipfs:// uri
|
|
* @returns - The fully formed IPFS url with the gateway url
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.resolveFullUrl = function resolveFullUrl(ipfsHash) {
|
|
if (typeof ipfsHash !== "string") {
|
|
return "";
|
|
}
|
|
|
|
return ipfsHash && ipfsHash.toLowerCase().includes("ipfs://") ? ipfsHash.replace("ipfs://", this.gatewayUrl) : ipfsHash;
|
|
};
|
|
|
|
_proto.canResolve = function canResolve(uri) {
|
|
var resolved = this.resolveFullUrl(uri);
|
|
return resolved.toLowerCase() !== uri.toLowerCase();
|
|
};
|
|
|
|
return IpfsStorage;
|
|
}();
|
|
|
|
/**
|
|
* The RegistryModule. This should always be created via `getRegistryModule()` on the main SDK.
|
|
* @internal
|
|
*/
|
|
|
|
var RegistryModule = /*#__PURE__*/function (_Module) {
|
|
_inheritsLoose(RegistryModule, _Module);
|
|
|
|
function RegistryModule() {
|
|
return _Module.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = RegistryModule.prototype;
|
|
|
|
/**
|
|
* @internal
|
|
*/
|
|
_proto.connectContract = function connectContract() {
|
|
return Registry__factory.connect(this.address, this.providerOrSigner);
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getProtocolContracts =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getProtocolContracts = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(address) {
|
|
var _this = this;
|
|
|
|
var deployer, maxVersion, versions, addresses, metadatas;
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
_context.t0 = address;
|
|
|
|
if (_context.t0) {
|
|
_context.next = 5;
|
|
break;
|
|
}
|
|
|
|
_context.next = 4;
|
|
return this.getSignerAddress();
|
|
|
|
case 4:
|
|
_context.t0 = _context.sent;
|
|
|
|
case 5:
|
|
deployer = _context.t0;
|
|
_context.next = 8;
|
|
return this.readOnlyContract.getProtocolControlCount(deployer);
|
|
|
|
case 8:
|
|
maxVersion = _context.sent;
|
|
versions = Array.from(Array(maxVersion.toNumber()).keys()).reverse();
|
|
_context.next = 12;
|
|
return Promise.all(versions.map(function (v) {
|
|
return _this.readOnlyContract.getProtocolControl(deployer, (v + 1).toString());
|
|
}));
|
|
|
|
case 12:
|
|
addresses = _context.sent;
|
|
_context.next = 15;
|
|
return Promise.all(addresses.map(function (addr) {
|
|
return getContractMetadata(_this.providerOrSigner, addr, _this.sdk.getStorage())["catch"](function () {
|
|
return undefined;
|
|
});
|
|
}));
|
|
|
|
case 15:
|
|
metadatas = _context.sent;
|
|
return _context.abrupt("return", versions.map(function (v, i) {
|
|
return {
|
|
address: addresses[i],
|
|
version: v,
|
|
metadata: metadatas[i]
|
|
};
|
|
}));
|
|
|
|
case 17:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function getProtocolContracts(_x) {
|
|
return _getProtocolContracts.apply(this, arguments);
|
|
}
|
|
|
|
return getProtocolContracts;
|
|
}();
|
|
|
|
return RegistryModule;
|
|
}(Module);
|
|
|
|
/**
|
|
* The entrypoint to the SDK.
|
|
* @public
|
|
*/
|
|
|
|
var ThirdwebSDK = /*#__PURE__*/function () {
|
|
function ThirdwebSDK(providerOrNetwork, opts) {
|
|
this.options = void 0;
|
|
this.defaultOptions = {
|
|
ipfsGatewayUrl: "https://cloudflare-ipfs.com/ipfs/",
|
|
registryContractAddress: "",
|
|
maxGasPriceInGwei: 300,
|
|
gasSpeed: "fastest",
|
|
transactionRelayerUrl: "",
|
|
transactionRelayerSendFunction: this.defaultRelayerSendFunction.bind(this),
|
|
transactionRelayerForwarderAddress: FORWARDER_ADDRESS,
|
|
readOnlyRpcUrl: "",
|
|
gasless: {
|
|
biconomy: {
|
|
apiId: "",
|
|
apiKey: "",
|
|
deadlineSeconds: 3600,
|
|
gasTier: "RAPID"
|
|
}
|
|
},
|
|
gaslessSendFunction: this.defaultGaslessSendFunction.bind(this)
|
|
};
|
|
this.modules = new Map();
|
|
this.providerOrSigner = void 0;
|
|
this._signer = null;
|
|
this._jsonConvert = new JsonConvert();
|
|
this.storage = void 0;
|
|
this.event = new EventEmitter2();
|
|
this._registry = null;
|
|
this.providerOrSigner = this.setProviderOrSigner(providerOrNetwork);
|
|
this.options = _extends({}, this.defaultOptions, opts);
|
|
this.storage = new IpfsStorage(this.options.ipfsGatewayUrl);
|
|
}
|
|
|
|
var _proto = ThirdwebSDK.prototype;
|
|
|
|
_proto.updateModuleSigners = function updateModuleSigners() {
|
|
for (var _iterator = _createForOfIteratorHelperLoose(this.modules), _step; !(_step = _iterator()).done;) {
|
|
var _step$value = _step.value,
|
|
_module = _step$value[1];
|
|
|
|
if (this.isReadOnly()) {
|
|
_module.clearSigner();
|
|
}
|
|
|
|
_module.setProviderOrSigner(this.providerOrSigner);
|
|
}
|
|
};
|
|
|
|
_proto.getProvider = function getProvider() {
|
|
var provider = Provider.isProvider(this.providerOrSigner) ? this.providerOrSigner : this.providerOrSigner.provider;
|
|
return provider;
|
|
};
|
|
|
|
_proto.getSigner = function getSigner() {
|
|
if (Signer.isSigner(this.providerOrSigner)) {
|
|
return this.providerOrSigner;
|
|
}
|
|
|
|
return undefined;
|
|
};
|
|
|
|
_proto.getChainID = /*#__PURE__*/function () {
|
|
var _getChainID = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
|
|
var provider, _yield$provider$getNe, chainId;
|
|
|
|
return runtime_1.wrap(function _callee$(_context) {
|
|
while (1) {
|
|
switch (_context.prev = _context.next) {
|
|
case 0:
|
|
provider = this.getProvider();
|
|
!provider ? process.env.NODE_ENV !== "production" ? invariant(false, "getRegistryAddress() -- No Provider") : invariant(false) : void 0;
|
|
_context.next = 4;
|
|
return provider.getNetwork();
|
|
|
|
case 4:
|
|
_yield$provider$getNe = _context.sent;
|
|
chainId = _yield$provider$getNe.chainId;
|
|
return _context.abrupt("return", chainId);
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context.stop();
|
|
}
|
|
}
|
|
}, _callee, this);
|
|
}));
|
|
|
|
function getChainID() {
|
|
return _getChainID.apply(this, arguments);
|
|
}
|
|
|
|
return getChainID;
|
|
}();
|
|
|
|
_proto.getRegistryAddress = /*#__PURE__*/function () {
|
|
var _getRegistryAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
|
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
while (1) {
|
|
switch (_context2.prev = _context2.next) {
|
|
case 0:
|
|
if (!this.options.registryContractAddress) {
|
|
_context2.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context2.abrupt("return", this.options.registryContractAddress);
|
|
|
|
case 2:
|
|
_context2.t0 = getContractAddressByChainId;
|
|
_context2.next = 5;
|
|
return this.getChainID();
|
|
|
|
case 5:
|
|
_context2.t1 = _context2.sent;
|
|
return _context2.abrupt("return", (0, _context2.t0)(_context2.t1));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context2.stop();
|
|
}
|
|
}
|
|
}, _callee2, this);
|
|
}));
|
|
|
|
function getRegistryAddress() {
|
|
return _getRegistryAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getRegistryAddress;
|
|
}()
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Registry module.
|
|
* @returns The Registry Module.
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getRegistryModule =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getRegistryModule = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
|
|
var address;
|
|
return runtime_1.wrap(function _callee3$(_context3) {
|
|
while (1) {
|
|
switch (_context3.prev = _context3.next) {
|
|
case 0:
|
|
_context3.next = 2;
|
|
return this.getRegistryAddress();
|
|
|
|
case 2:
|
|
address = _context3.sent;
|
|
!address ? process.env.NODE_ENV !== "production" ? invariant(false, "getRegistryModule() -- No Address") : invariant(false) : void 0;
|
|
return _context3.abrupt("return", this.registry = this.getOrCreateModule(address, RegistryModule));
|
|
|
|
case 5:
|
|
case "end":
|
|
return _context3.stop();
|
|
}
|
|
}
|
|
}, _callee3, this);
|
|
}));
|
|
|
|
function getRegistryModule() {
|
|
return _getRegistryModule.apply(this, arguments);
|
|
}
|
|
|
|
return getRegistryModule;
|
|
}();
|
|
|
|
_proto.getOrCreateModule = function getOrCreateModule(address, _Module) {
|
|
if (this.modules.has(address)) {
|
|
return this.modules.get(address);
|
|
}
|
|
|
|
var _newModule = new _Module(this.providerOrSigner, address, this.options, this);
|
|
|
|
this.modules.set(address, _newModule);
|
|
return _newModule;
|
|
}
|
|
/**
|
|
* you should not need this unless you are creating new modules
|
|
* @returns the active registry module forwarder address
|
|
* @internal
|
|
*/
|
|
;
|
|
|
|
_proto.getForwarderAddress =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getForwarderAddress = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
|
|
return runtime_1.wrap(function _callee4$(_context4) {
|
|
while (1) {
|
|
switch (_context4.prev = _context4.next) {
|
|
case 0:
|
|
_context4.t0 = this.registry;
|
|
|
|
if (_context4.t0) {
|
|
_context4.next = 5;
|
|
break;
|
|
}
|
|
|
|
_context4.next = 4;
|
|
return this.getRegistryModule();
|
|
|
|
case 4:
|
|
_context4.t0 = _context4.sent;
|
|
|
|
case 5:
|
|
_context4.next = 7;
|
|
return _context4.t0.readOnlyContract.forwarder();
|
|
|
|
case 7:
|
|
return _context4.abrupt("return", _context4.sent);
|
|
|
|
case 8:
|
|
case "end":
|
|
return _context4.stop();
|
|
}
|
|
}
|
|
}, _callee4, this);
|
|
}));
|
|
|
|
function getForwarderAddress() {
|
|
return _getForwarderAddress.apply(this, arguments);
|
|
}
|
|
|
|
return getForwarderAddress;
|
|
}()
|
|
/**
|
|
* Call this to get the current apps.
|
|
* @returns All currently registered apps for the connected wallet
|
|
*/
|
|
;
|
|
|
|
_proto.getApps =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getApps = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(address) {
|
|
return runtime_1.wrap(function _callee5$(_context5) {
|
|
while (1) {
|
|
switch (_context5.prev = _context5.next) {
|
|
case 0:
|
|
_context5.t0 = this.registry;
|
|
|
|
if (_context5.t0) {
|
|
_context5.next = 5;
|
|
break;
|
|
}
|
|
|
|
_context5.next = 4;
|
|
return this.getRegistryModule();
|
|
|
|
case 4:
|
|
_context5.t0 = _context5.sent;
|
|
|
|
case 5:
|
|
return _context5.abrupt("return", _context5.t0.getProtocolContracts(address));
|
|
|
|
case 6:
|
|
case "end":
|
|
return _context5.stop();
|
|
}
|
|
}
|
|
}, _callee5, this);
|
|
}));
|
|
|
|
function getApps(_x) {
|
|
return _getApps.apply(this, arguments);
|
|
}
|
|
|
|
return getApps;
|
|
}()
|
|
/**
|
|
* Call this to create a new app
|
|
* @param metadata - metadata URI or a JSON object
|
|
* @returns The transaction receipt
|
|
*/
|
|
;
|
|
|
|
_proto.createApp =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _createApp = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(metadata) {
|
|
var _this$signer;
|
|
|
|
var registryContract, gasPrice, txOpts, uri, txn;
|
|
return runtime_1.wrap(function _callee6$(_context6) {
|
|
while (1) {
|
|
switch (_context6.prev = _context6.next) {
|
|
case 0:
|
|
_context6.t0 = this.registry;
|
|
|
|
if (_context6.t0) {
|
|
_context6.next = 5;
|
|
break;
|
|
}
|
|
|
|
_context6.next = 4;
|
|
return this.getRegistryModule();
|
|
|
|
case 4:
|
|
_context6.t0 = _context6.sent;
|
|
|
|
case 5:
|
|
registryContract = _context6.t0.contract;
|
|
_context6.next = 8;
|
|
return this.getGasPrice();
|
|
|
|
case 8:
|
|
gasPrice = _context6.sent;
|
|
txOpts = {}; // could technically be `0` so simple falsy check does not suffice
|
|
|
|
if (typeof gasPrice === "number") {
|
|
txOpts.gasPrice = parseUnits(gasPrice.toString(), "gwei");
|
|
}
|
|
|
|
_context6.t1 = uploadMetadata;
|
|
_context6.t2 = metadata;
|
|
_context6.t3 = registryContract.address;
|
|
_context6.next = 16;
|
|
return (_this$signer = this.signer) == null ? void 0 : _this$signer.getAddress();
|
|
|
|
case 16:
|
|
_context6.t4 = _context6.sent;
|
|
|
|
if (_context6.t4) {
|
|
_context6.next = 19;
|
|
break;
|
|
}
|
|
|
|
_context6.t4 = undefined;
|
|
|
|
case 19:
|
|
_context6.t5 = _context6.t4;
|
|
_context6.next = 22;
|
|
return (0, _context6.t1)(_context6.t2, _context6.t3, _context6.t5);
|
|
|
|
case 22:
|
|
uri = _context6.sent;
|
|
_context6.next = 25;
|
|
return registryContract.deployProtocol(uri, txOpts);
|
|
|
|
case 25:
|
|
txn = _context6.sent;
|
|
_context6.next = 28;
|
|
return txn.wait();
|
|
|
|
case 28:
|
|
return _context6.abrupt("return", _context6.sent);
|
|
|
|
case 29:
|
|
case "end":
|
|
return _context6.stop();
|
|
}
|
|
}
|
|
}, _callee6, this);
|
|
}));
|
|
|
|
function createApp(_x2) {
|
|
return _createApp.apply(this, arguments);
|
|
}
|
|
|
|
return createApp;
|
|
}()
|
|
/**
|
|
*
|
|
* @param speed - what speed to prefer, default: "fastest"
|
|
* @param maxGas - how much gas to use at most, default: 300
|
|
* @returns the optiomal gas price
|
|
*/
|
|
;
|
|
|
|
_proto.getGasPrice =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getGasPrice = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(speed, maxGasGwei) {
|
|
var _speed, _maxGas;
|
|
|
|
return runtime_1.wrap(function _callee7$(_context7) {
|
|
while (1) {
|
|
switch (_context7.prev = _context7.next) {
|
|
case 0:
|
|
_speed = speed ? speed : this.options.gasSpeed;
|
|
_maxGas = maxGasGwei ? maxGasGwei : this.options.maxGasPriceInGwei;
|
|
_context7.t0 = getGasPriceForChain;
|
|
_context7.next = 5;
|
|
return this.getChainID();
|
|
|
|
case 5:
|
|
_context7.t1 = _context7.sent;
|
|
_context7.t2 = _speed;
|
|
_context7.t3 = _maxGas;
|
|
_context7.next = 10;
|
|
return (0, _context7.t0)(_context7.t1, _context7.t2, _context7.t3);
|
|
|
|
case 10:
|
|
return _context7.abrupt("return", _context7.sent);
|
|
|
|
case 11:
|
|
case "end":
|
|
return _context7.stop();
|
|
}
|
|
}
|
|
}, _callee7, this);
|
|
}));
|
|
|
|
function getGasPrice(_x3, _x4) {
|
|
return _getGasPrice.apply(this, arguments);
|
|
}
|
|
|
|
return getGasPrice;
|
|
}()
|
|
/**
|
|
*
|
|
* @param providerOrSignerOrNetwork - A valid "ethers" Provider, Signer or a Network address to create a Provider with.
|
|
* @returns The Provider / Signer that was passed in, or a default ethers provider constructed with the passed Network.
|
|
*/
|
|
;
|
|
|
|
_proto.setProviderOrSigner = function setProviderOrSigner(providerOrSignerOrNetwork) {
|
|
if (Provider.isProvider(providerOrSignerOrNetwork) || Signer.isSigner(providerOrSignerOrNetwork)) {
|
|
// sdk instantiated with a provider / signer
|
|
this.providerOrSigner = providerOrSignerOrNetwork;
|
|
} else {
|
|
// sdk instantiated with a network name / network url
|
|
this.providerOrSigner = ethers.getDefaultProvider(providerOrSignerOrNetwork);
|
|
} // if we're setting a signer then also update that
|
|
|
|
|
|
if (Signer.isSigner(providerOrSignerOrNetwork)) {
|
|
this.signer = providerOrSignerOrNetwork;
|
|
} else {
|
|
this.signer = null;
|
|
}
|
|
|
|
this.updateModuleSigners();
|
|
return this.providerOrSigner;
|
|
}
|
|
/**
|
|
*
|
|
* @public
|
|
* @returns Whether the SDK is in read-only mode. (Meaning it has not been passed a valid "Signer.")
|
|
*/
|
|
;
|
|
|
|
_proto.isReadOnly = function isReadOnly() {
|
|
return !Signer.isSigner(this.signer);
|
|
}
|
|
/**
|
|
* @public
|
|
* @returns The contract metadata for the given contract address.
|
|
*/
|
|
;
|
|
|
|
_proto.getContractMetadata =
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _getContractMetadata2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(address) {
|
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
while (1) {
|
|
switch (_context8.prev = _context8.next) {
|
|
case 0:
|
|
_context8.t0 = _extends;
|
|
_context8.t1 = {};
|
|
_context8.next = 4;
|
|
return getContractMetadata(this.providerOrSigner, address, this.getStorage(), true);
|
|
|
|
case 4:
|
|
_context8.t2 = _context8.sent;
|
|
_context8.t3 = {
|
|
address: address
|
|
};
|
|
return _context8.abrupt("return", (0, _context8.t0)(_context8.t1, _context8.t2, _context8.t3));
|
|
|
|
case 7:
|
|
case "end":
|
|
return _context8.stop();
|
|
}
|
|
}
|
|
}, _callee8, this);
|
|
}));
|
|
|
|
function getContractMetadata$1(_x5) {
|
|
return _getContractMetadata2.apply(this, arguments);
|
|
}
|
|
|
|
return getContractMetadata$1;
|
|
}()
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given App module.
|
|
* @returns The App Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getAppModule = function getAppModule(address) {
|
|
return this.getOrCreateModule(address, AppModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given NFT module.
|
|
* @returns The NFT Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getNFTModule = function getNFTModule(address) {
|
|
return this.getOrCreateModule(address, NFTModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Collection module.
|
|
* @returns The Bundle Module.
|
|
* @deprecated Use the new {@link ThirdwebSDK.getBundleModule} function instead.
|
|
*/
|
|
;
|
|
|
|
_proto.getCollectionModule = function getCollectionModule(address) {
|
|
return this.getBundleModule(address);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Bundle module.
|
|
* @returns The Bundle Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getBundleModule = function getBundleModule(address) {
|
|
return this.getOrCreateModule(address, BundleModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Pack module.
|
|
* @returns The Pack Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getPackModule = function getPackModule(address) {
|
|
return this.getOrCreateModule(address, PackModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Currency module.
|
|
* @returns The Currency Module.
|
|
*
|
|
* @deprecated - see {@link TokenModule}
|
|
*/
|
|
;
|
|
|
|
_proto.getCurrencyModule = function getCurrencyModule(address) {
|
|
return this.getOrCreateModule(address, CurrencyModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Token module.
|
|
* @returns The Token Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getTokenModule = function getTokenModule(address) {
|
|
return this.getOrCreateModule(address, TokenModule);
|
|
}
|
|
/**
|
|
* @alpha
|
|
*
|
|
* @param address - The contract address of the given Datastore module.
|
|
* @returns The Datastore Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getDatastoreModule = function getDatastoreModule(address) {
|
|
return this.getOrCreateModule(address, DatastoreModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Market module.
|
|
* @returns The Market Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getMarketModule = function getMarketModule(address) {
|
|
return this.getOrCreateModule(address, MarketModule);
|
|
}
|
|
/**
|
|
*
|
|
* @param address - The contract address of the given Drop module.
|
|
* @returns The Drop Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getDropModule = function getDropModule(address) {
|
|
return this.getOrCreateModule(address, DropModule);
|
|
}
|
|
/**
|
|
* @beta
|
|
*
|
|
* @param address - The contract address of the given BundleDrop module.
|
|
* @returns The Drop Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getBundleDropModule = function getBundleDropModule(address) {
|
|
return this.getOrCreateModule(address, BundleDropModule);
|
|
}
|
|
/**
|
|
* @beta
|
|
*
|
|
* @param address - The contract address of the given Marketplace module.
|
|
* @returns The Marketplace Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getMarketplaceModule = function getMarketplaceModule(address) {
|
|
return this.getOrCreateModule(address, MarketplaceModule);
|
|
}
|
|
/**
|
|
* @alpha
|
|
*
|
|
* @param address - The contract address of the given Royalty module.
|
|
* @returns The Splits Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getSplitsModule = function getSplitsModule(address) {
|
|
return this.getOrCreateModule(address, SplitsModule);
|
|
}
|
|
/**
|
|
* @alpha
|
|
*
|
|
* @param address - The contract address of the given Vote module.
|
|
* @returns The Vote Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getVoteModule = function getVoteModule(address) {
|
|
return this.getOrCreateModule(address, VoteModule);
|
|
}
|
|
/**
|
|
* @alpha
|
|
*
|
|
* @param address - The contract address of the given BundleSignature module.
|
|
* @returns The BundleSignature Module.
|
|
*/
|
|
;
|
|
|
|
_proto.getBundleSignatureModule = function getBundleSignatureModule(address) {
|
|
return this.getOrCreateModule(address, SignatureMint1155Module);
|
|
}
|
|
/**
|
|
* Used for SDK that requires js bridging like Unity SDK.
|
|
* Convenient function to let the caller calls into the SDK using routing scheme rather than function call.
|
|
*
|
|
* @internal
|
|
* @param route - sdk execution route
|
|
* @param payload - request arguments for the function
|
|
* @returns
|
|
*/
|
|
;
|
|
|
|
_proto.invokeRoute = function invokeRoute(route, payload) {
|
|
var parts = route.split(".");
|
|
|
|
if (parts.length > 0 && parts[0] === "thirdweb") {
|
|
if (parts.length === 4) {
|
|
var _this$getModuleByName;
|
|
|
|
// thirdweb.module_name.address.function_name
|
|
var moduleName = parts[1];
|
|
var moduleAddress = parts[2];
|
|
var funcName = parts[3];
|
|
return (_this$getModuleByName = this.getModuleByName(moduleName, moduleAddress))[funcName].apply(_this$getModuleByName, payload.arguments || []);
|
|
} else if (parts.length === 3) {
|
|
// reserved for: thirdweb.bridge.function_name
|
|
throw new Error("reserved for thirdweb.bridge.function_name");
|
|
} else if (parts.length === 2) {
|
|
// main sdk functions: thirdweb.function_name
|
|
var _funcName = parts[1];
|
|
return this[_funcName].apply(this, payload.arguments || []);
|
|
}
|
|
}
|
|
|
|
throw new Error("uknown route");
|
|
} // used for invoke route for unity sdk.
|
|
;
|
|
|
|
_proto.getModuleByName = function getModuleByName(name, address) {
|
|
if (name === "currency") {
|
|
return this.getCurrencyModule(address);
|
|
} else if (name === "nft") {
|
|
return this.getNFTModule(address);
|
|
} else if (name === "market") {
|
|
return this.getMarketModule(address);
|
|
} else if (name === "bundle" || name === "collection") {
|
|
return this.getCollectionModule(address);
|
|
} else if (name === "drop") {
|
|
return this.getDropModule(address);
|
|
} else if (name === "splits") {
|
|
return this.getSplitsModule(address);
|
|
} else if (name === "pack") {
|
|
return this.getPackModule(address);
|
|
} else if (name === "datastore") {
|
|
return this.getDatastoreModule(address);
|
|
} else if (name === "app" || name === "project") {
|
|
return this.getAppModule(address);
|
|
}
|
|
|
|
throw new Error("unsupported module");
|
|
};
|
|
|
|
_proto.defaultGaslessSendFunction = /*#__PURE__*/function () {
|
|
var _defaultGaslessSendFunction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(contract, transaction) {
|
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
while (1) {
|
|
switch (_context9.prev = _context9.next) {
|
|
case 0:
|
|
if (!(this.options.gasless.biconomy.apiId && this.options.gasless.biconomy.apiKey)) {
|
|
_context9.next = 2;
|
|
break;
|
|
}
|
|
|
|
return _context9.abrupt("return", this.biconomySendFunction(contract, transaction));
|
|
|
|
case 2:
|
|
return _context9.abrupt("return", this.defenderSendFunction(contract, transaction));
|
|
|
|
case 3:
|
|
case "end":
|
|
return _context9.stop();
|
|
}
|
|
}
|
|
}, _callee9, this);
|
|
}));
|
|
|
|
function defaultGaslessSendFunction(_x6, _x7) {
|
|
return _defaultGaslessSendFunction.apply(this, arguments);
|
|
}
|
|
|
|
return defaultGaslessSendFunction;
|
|
}();
|
|
|
|
_proto.biconomySendFunction = /*#__PURE__*/function () {
|
|
var _biconomySendFunction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(_contract, transaction) {
|
|
var _this$options$gasless;
|
|
|
|
var signer, provider, forwarder, batchId, batchNonce, request, hashToSign, signature, response, resp;
|
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
while (1) {
|
|
switch (_context10.prev = _context10.next) {
|
|
case 0:
|
|
signer = this.getSigner();
|
|
provider = this.getProvider();
|
|
!(signer && provider) ? process.env.NODE_ENV !== "production" ? invariant(false, "signer and provider must be set") : invariant(false) : void 0;
|
|
forwarder = new ethers.Contract(getContractAddressByChainId(transaction.chainId, "biconomyForwarder"), BiconomyForwarderAbi, provider);
|
|
batchId = 0;
|
|
_context10.next = 7;
|
|
return getAndIncrementNonce(forwarder, "getNonce", [transaction.from, batchId]);
|
|
|
|
case 7:
|
|
batchNonce = _context10.sent;
|
|
request = {
|
|
from: transaction.from,
|
|
to: transaction.to,
|
|
token: ethers.constants.AddressZero,
|
|
txGas: transaction.gasLimit.toNumber(),
|
|
tokenGasPrice: "0",
|
|
batchId: batchId,
|
|
batchNonce: batchNonce.toNumber(),
|
|
deadline: Math.floor(Date.now() / 1000 + ((_this$options$gasless = this.options.gasless.biconomy.deadlineSeconds) != null ? _this$options$gasless : 3600)),
|
|
data: transaction.data
|
|
};
|
|
hashToSign = ethers.utils.arrayify(ethers.utils.solidityKeccak256(["address", "address", "address", "uint256", "uint256", "uint256", "uint256", "uint256", "bytes32"], [request.from, request.to, request.token, request.txGas, request.tokenGasPrice, request.batchId, request.batchNonce, request.deadline, ethers.utils.keccak256(request.data)]));
|
|
this.event.emit(EventType.Signature, {
|
|
status: "submitted",
|
|
message: hashToSign,
|
|
signature: ""
|
|
});
|
|
_context10.next = 13;
|
|
return signer.signMessage(hashToSign);
|
|
|
|
case 13:
|
|
signature = _context10.sent;
|
|
this.event.emit(EventType.Signature, {
|
|
status: "completed",
|
|
message: hashToSign,
|
|
signature: signature
|
|
});
|
|
_context10.next = 17;
|
|
return fetch(this.options.transactionRelayerUrl || "https://api.biconomy.io/api/v2/meta-tx/native", {
|
|
method: "POST",
|
|
body: JSON.stringify({
|
|
from: transaction.from,
|
|
apiId: this.options.gasless.biconomy.apiId,
|
|
params: [request, signature],
|
|
to: transaction.to,
|
|
gasLimit: transaction.gasLimit.toHexString(),
|
|
gasType: this.options.gasless.biconomy.gasTier
|
|
}),
|
|
headers: {
|
|
"x-api-key": this.options.gasless.biconomy.apiKey,
|
|
"Content-Type": "application/json;charset=utf-8"
|
|
}
|
|
});
|
|
|
|
case 17:
|
|
response = _context10.sent;
|
|
|
|
if (!response.ok) {
|
|
_context10.next = 25;
|
|
break;
|
|
}
|
|
|
|
_context10.next = 21;
|
|
return response.json();
|
|
|
|
case 21:
|
|
resp = _context10.sent;
|
|
|
|
if (resp.txHash) {
|
|
_context10.next = 24;
|
|
break;
|
|
}
|
|
|
|
throw new Error("relay transaction failed: " + (resp.log || resp.message));
|
|
|
|
case 24:
|
|
return _context10.abrupt("return", resp.txHash);
|
|
|
|
case 25:
|
|
throw new Error("relay transaction failed");
|
|
|
|
case 26:
|
|
case "end":
|
|
return _context10.stop();
|
|
}
|
|
}
|
|
}, _callee10, this);
|
|
}));
|
|
|
|
function biconomySendFunction(_x8, _x9) {
|
|
return _biconomySendFunction.apply(this, arguments);
|
|
}
|
|
|
|
return biconomySendFunction;
|
|
}();
|
|
|
|
_proto.defenderSendFunction = /*#__PURE__*/function () {
|
|
var _defenderSendFunction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(contract, transaction) {
|
|
var signer, provider, forwarderAddress, forwarder, nonce, domain, types, message, signature, spender, amount, _yield$signEIP2612Per, permit, sig, _ethers$utils$splitSi, r, s, v, _yield$signTypedData, _sig, txHash;
|
|
|
|
return runtime_1.wrap(function _callee11$(_context11) {
|
|
while (1) {
|
|
switch (_context11.prev = _context11.next) {
|
|
case 0:
|
|
signer = this.getSigner();
|
|
provider = this.getProvider();
|
|
!signer ? process.env.NODE_ENV !== "production" ? invariant(false, "provider is not set") : invariant(false) : void 0;
|
|
!provider ? process.env.NODE_ENV !== "production" ? invariant(false, "provider is not set") : invariant(false) : void 0;
|
|
forwarderAddress = this.options.transactionRelayerForwarderAddress;
|
|
forwarder = Forwarder__factory.connect(forwarderAddress, provider);
|
|
_context11.next = 8;
|
|
return getAndIncrementNonce(forwarder, "getNonce", [transaction.from]);
|
|
|
|
case 8:
|
|
nonce = _context11.sent;
|
|
domain = {
|
|
name: "GSNv2 Forwarder",
|
|
version: "0.0.1",
|
|
chainId: transaction.chainId,
|
|
verifyingContract: forwarderAddress
|
|
};
|
|
types = {
|
|
ForwardRequest: ForwardRequest
|
|
};
|
|
message = {
|
|
from: transaction.from,
|
|
to: transaction.to,
|
|
value: BigNumber.from(0).toString(),
|
|
gas: BigNumber.from(transaction.gasLimit).toString(),
|
|
nonce: BigNumber.from(nonce).toString(),
|
|
data: transaction.data
|
|
};
|
|
this.event.emit(EventType.Signature, {
|
|
status: "submitted",
|
|
message: message,
|
|
signature: ""
|
|
}); // if the executing function is "approve" and matches with erc20 approve signature
|
|
// and if the token supports permit, then we use permit for gasless instead of approve.
|
|
|
|
if (!(transaction.functionName === "approve" && transaction.functionArgs.length === 2)) {
|
|
_context11.next = 26;
|
|
break;
|
|
}
|
|
|
|
spender = transaction.functionArgs[0];
|
|
amount = transaction.functionArgs[1]; // TODO: support DAI permit by signDAIPermit
|
|
|
|
_context11.next = 18;
|
|
return signEIP2612Permit(signer, contract.address, transaction.from, spender, amount);
|
|
|
|
case 18:
|
|
_yield$signEIP2612Per = _context11.sent;
|
|
permit = _yield$signEIP2612Per.message;
|
|
sig = _yield$signEIP2612Per.signature;
|
|
_ethers$utils$splitSi = ethers.utils.splitSignature(sig), r = _ethers$utils$splitSi.r, s = _ethers$utils$splitSi.s, v = _ethers$utils$splitSi.v;
|
|
message = {
|
|
to: contract.address,
|
|
owner: permit.owner,
|
|
spender: permit.spender,
|
|
value: BigNumber.from(permit.value).toString(),
|
|
nonce: BigNumber.from(permit.nonce).toString(),
|
|
deadline: BigNumber.from(permit.deadline).toString(),
|
|
r: r,
|
|
s: s,
|
|
v: v
|
|
};
|
|
signature = sig;
|
|
_context11.next = 31;
|
|
break;
|
|
|
|
case 26:
|
|
_context11.next = 28;
|
|
return signTypedData(signer, domain, types, message);
|
|
|
|
case 28:
|
|
_yield$signTypedData = _context11.sent;
|
|
_sig = _yield$signTypedData.signature;
|
|
signature = _sig;
|
|
|
|
case 31:
|
|
this.event.emit(EventType.Signature, {
|
|
status: "completed",
|
|
message: message,
|
|
signature: signature
|
|
}); // TODO: isolate http request logic in here. `transactionRelayerSendFunction` is deprecated using it for backward compatibility reasons.
|
|
|
|
_context11.next = 34;
|
|
return this.options.transactionRelayerSendFunction(message, signature);
|
|
|
|
case 34:
|
|
txHash = _context11.sent;
|
|
return _context11.abrupt("return", txHash);
|
|
|
|
case 36:
|
|
case "end":
|
|
return _context11.stop();
|
|
}
|
|
}
|
|
}, _callee11, this);
|
|
}));
|
|
|
|
function defenderSendFunction(_x10, _x11) {
|
|
return _defenderSendFunction.apply(this, arguments);
|
|
}
|
|
|
|
return defenderSendFunction;
|
|
}();
|
|
|
|
_proto.defaultRelayerSendFunction = /*#__PURE__*/function () {
|
|
var _defaultRelayerSendFunction = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(message, signature) {
|
|
var messageType, body, response, resp, result;
|
|
return runtime_1.wrap(function _callee12$(_context12) {
|
|
while (1) {
|
|
switch (_context12.prev = _context12.next) {
|
|
case 0:
|
|
messageType = "forward"; // if has owner property then it's permit :)
|
|
|
|
if (message != null && message.owner) {
|
|
messageType = "permit";
|
|
}
|
|
|
|
body = JSON.stringify({
|
|
request: message,
|
|
signature: signature,
|
|
type: messageType
|
|
});
|
|
_context12.next = 5;
|
|
return fetch(this.options.transactionRelayerUrl, {
|
|
method: "POST",
|
|
body: body
|
|
});
|
|
|
|
case 5:
|
|
response = _context12.sent;
|
|
|
|
if (!response.ok) {
|
|
_context12.next = 12;
|
|
break;
|
|
}
|
|
|
|
_context12.next = 9;
|
|
return response.json();
|
|
|
|
case 9:
|
|
resp = _context12.sent;
|
|
result = JSON.parse(resp.result);
|
|
return _context12.abrupt("return", result.txHash);
|
|
|
|
case 12:
|
|
throw new Error("relay transaction failed");
|
|
|
|
case 13:
|
|
case "end":
|
|
return _context12.stop();
|
|
}
|
|
}
|
|
}, _callee12, this);
|
|
}));
|
|
|
|
function defaultRelayerSendFunction(_x12, _x13) {
|
|
return _defaultRelayerSendFunction.apply(this, arguments);
|
|
}
|
|
|
|
return defaultRelayerSendFunction;
|
|
}();
|
|
|
|
_proto.createSnapshot = /*#__PURE__*/function () {
|
|
var _createSnapshot = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(leafs) {
|
|
var hasDuplicates, _yield$import, keccak256, hashedLeafs, tree, snapshot, serializedSnapshot, uri;
|
|
|
|
return runtime_1.wrap(function _callee13$(_context13) {
|
|
while (1) {
|
|
switch (_context13.prev = _context13.next) {
|
|
case 0:
|
|
hasDuplicates = new Set(leafs).size < leafs.length;
|
|
|
|
if (!hasDuplicates) {
|
|
_context13.next = 3;
|
|
break;
|
|
}
|
|
|
|
throw new DuplicateLeafsError();
|
|
|
|
case 3:
|
|
_context13.next = 5;
|
|
return import('keccak256');
|
|
|
|
case 5:
|
|
_yield$import = _context13.sent;
|
|
keccak256 = _yield$import["default"];
|
|
hashedLeafs = leafs.map(function (l) {
|
|
return keccak256(l);
|
|
});
|
|
tree = new MerkleTree(hashedLeafs, keccak256, {
|
|
sort: true
|
|
});
|
|
snapshot = {
|
|
merkleRoot: tree.getHexRoot(),
|
|
claims: leafs.map(function (l) {
|
|
var proof = tree.getHexProof(keccak256(l));
|
|
return {
|
|
address: l,
|
|
proof: proof
|
|
};
|
|
})
|
|
};
|
|
serializedSnapshot = JSON.stringify(this._jsonConvert.serializeObject(snapshot, Snapshot));
|
|
_context13.next = 13;
|
|
return this.storage.upload(serializedSnapshot);
|
|
|
|
case 13:
|
|
uri = _context13.sent;
|
|
return _context13.abrupt("return", {
|
|
merkleRoot: tree.getHexRoot(),
|
|
snapshotUri: uri,
|
|
snapshot: snapshot
|
|
});
|
|
|
|
case 15:
|
|
case "end":
|
|
return _context13.stop();
|
|
}
|
|
}
|
|
}, _callee13, this);
|
|
}));
|
|
|
|
function createSnapshot(_x14) {
|
|
return _createSnapshot.apply(this, arguments);
|
|
}
|
|
|
|
return createSnapshot;
|
|
}()
|
|
/**
|
|
* Accessor for the storage instance used by the SDK
|
|
*
|
|
* @returns - The Storage instance.
|
|
*/
|
|
;
|
|
|
|
_proto.getStorage = function getStorage() {
|
|
return this.storage;
|
|
}
|
|
/**
|
|
* Allows you to override the storage used across the SDK.
|
|
*
|
|
* @param storage - The Storage instance to use.
|
|
*/
|
|
;
|
|
|
|
_proto.overrideStorage = function overrideStorage(storage) {
|
|
this.storage = storage;
|
|
};
|
|
|
|
_createClass(ThirdwebSDK, [{
|
|
key: "signer",
|
|
get: // default options
|
|
|
|
/**
|
|
* The active Signer, you should not need to access this unless you are deploying new modules.
|
|
* @internal
|
|
*/
|
|
function get() {
|
|
return this._signer;
|
|
},
|
|
set: function set(value) {
|
|
this._signer = value;
|
|
}
|
|
}, {
|
|
key: "registry",
|
|
get: function get() {
|
|
return this._registry;
|
|
},
|
|
set: function set(value) {
|
|
this._registry = value;
|
|
}
|
|
}]);
|
|
|
|
return ThirdwebSDK;
|
|
}();
|
|
/**
|
|
* Deprecated, please use ThirdwebSDK instead.
|
|
* @public
|
|
* @deprecated use ThirdwebSDK instead
|
|
*/
|
|
|
|
var NFTLabsSDK = ThirdwebSDK;
|
|
|
|
/**
|
|
* Convenience function to generate a merkle root from a list of strings.
|
|
*
|
|
* @param items - Any list of strings that will be hashed and added to the tree.
|
|
* @returns - A merkle root (in hexadecimal).
|
|
*/
|
|
|
|
function generateRoot(items) {
|
|
var tree = new MerkleTree$1(items, SHA256, {
|
|
hashLeaves: true,
|
|
sortLeaves: true
|
|
});
|
|
return tree.getRoot().toString("hex");
|
|
}
|
|
|
|
/**
|
|
* The {@link https://thirdweb.com | thirdweb} typescript sdk.
|
|
*
|
|
* @remarks
|
|
* Please keep in mind that the thirdweb typescript sdk and {@link https://thirdweb.com/dashboard | Admin Dashboard} are currently in Early Access.
|
|
*
|
|
* Should you find bugs or in the case you need help please reach out to us in {@link https://discord.gg/thirdweb | Discord}. (We also have 🍪 )
|
|
*
|
|
*
|
|
* @example
|
|
* To get you started here's how you would instantiate the SDK and fetch some NFTs
|
|
*
|
|
* 1. Install the sdk
|
|
* ```shell
|
|
* npm install @3rdweb/sdk
|
|
* ```
|
|
*
|
|
* 2. Get your NFT contract address from the {@link https://thirdweb.com/dashboard | Admin Dashboard}.
|
|
*
|
|
* 3. Write the tiniest amount of code!
|
|
* ```typescript
|
|
* 1 | import { ThirdwebSDK } from "@3rdweb/sdk";
|
|
* 2 | import type { NFTModule, NFTMetadataOwner } from "@3rdweb/sdk";
|
|
* 3 |
|
|
* 5 | const contractAddress = "0x..."; // your contract address from step 2
|
|
* 6 |
|
|
* 7 | const sdk = new ThirdwebSDK();
|
|
* 8 |
|
|
* 9 | const nftModule: NFTModule = sdk.getNFTModule(contractAddress);
|
|
* 10 |
|
|
* 11 | const nftListWithOwnerAddress: NFTMetadataOwner[] = await nftModule.getAllWithOwner();
|
|
* 12 |
|
|
* 13 | console.log(nftListWithOwnerAddress);
|
|
* ```
|
|
* ```
|
|
* Output
|
|
* => [
|
|
* {
|
|
* owner: "0x...",
|
|
* metadata: {
|
|
* name: "...",
|
|
* description: "...",
|
|
* image: "..."
|
|
* },
|
|
* },
|
|
* {
|
|
* owner: "0x...",
|
|
* metadata: {
|
|
* name: "...",
|
|
* description: "...",
|
|
* image: "..."
|
|
* },
|
|
* },
|
|
* ...
|
|
* ]
|
|
* ```
|
|
*
|
|
* @packageDocumentation
|
|
*/
|
|
|
|
if (!globalThis.fetch) {
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore
|
|
globalThis.fetch = fetch$1;
|
|
}
|
|
|
|
export { AdminRoleMissingError, AppModule, AssetNotFoundError, AuctionAlreadyStartedError, AuctionHasNotEndedError, BundleDropModule, BundleDropModuleMetadata, BundleModule, BundleModuleMetadata, ChainlinkVrf, ClaimConditionFactory, ClaimConditionPhase, ClaimEligibility, ClaimProof, CommonModuleMetadata, CurrencyModule, CurrencyModuleMetadata, DEFAULT_BLOCK_TIMES_FALLBACK, DatastoreModule, DatastoreModuleMetadata, DropModule, DropModuleMetadata, DuplicateFileNameError, DuplicateLeafsError, FetchError, FileNameMissingError, FunctionDeprecatedError, InterfaceId_IERC1155, InterfaceId_IERC721, InvalidAddressError, IpfsStorage, ListingNotFoundError, ListingType, MarketModule, MarketModuleMetadata, MarketplaceModule, MarketplaceModuleMetadata, MissingOwnerRoleError, MissingRoleError, ModuleType, NATIVE_TOKEN_ADDRESS, NFTLabsSDK, NFTModule, NftModuleMetadata, NotEnoughTokensError, NotFoundError, PackModule, PackModuleMetadata, ProposalState, QuantityAboveLimitError, RestrictedTransferError, RolesMap, Snapshot, SplitsModule, SplitsModuleMetadata, ThirdwebSDK, TokenModule, TokenModuleMetadata, UnderlyingType, UploadError, VoteModule, VoteModuleMetadata, VoteType, WrongListingTypeError, convertModuleTypeToName, convertNameToModuleType, estimateBlockAtTime, generateRoot, getContractMetadata, getCurrencyBalance, getCurrencyMetadata, getCurrencyValue, getGasPriceForChain, getMetadataWithoutContract, getNativeTokenByChainId, getRoleHash, getTokenMetadata, getTokenMetadataUsingStorage, getTokenUri, isContract, isNativeToken, recursiveResolveGatewayUrl, replaceIpfsWithGateway, uploadMetadata, uploadToIPFS };
|
|
//# sourceMappingURL=sdk.esm.js.map
|