UNPKG

@myclique/governance-sdk

Version:

The SDK is provides easy access to the high level interactions to be governance with an Clique DAO.

1,621 lines (1,390 loc) 92.4 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } var invariant = _interopDefault(require('tiny-invariant')); var JSBI = _interopDefault(require('jsbi')); var warning = _interopDefault(require('tiny-warning')); var address = require('@ethersproject/address'); var _Decimal = _interopDefault(require('decimal.js-light')); var _Big = _interopDefault(require('big.js')); var toFormat = _interopDefault(require('toformat')); var providers = require('@ethersproject/providers'); var wallet = require('@ethersproject/wallet'); var contracts = require('@ethersproject/contracts'); var axios = _interopDefault(require('axios')); (function (CChainId) { CChainId[CChainId["GOERLI"] = 5] = "GOERLI"; CChainId[CChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI"; CChainId[CChainId["BSCTEST"] = 97] = "BSCTEST"; CChainId[CChainId["ZKSYNC_ERA_TESTNET"] = 280] = "ZKSYNC_ERA_TESTNET"; CChainId[CChainId["KLAYTN_BAOBAB"] = 1001] = "KLAYTN_BAOBAB"; CChainId[CChainId["SEPOLIA"] = 11155111] = "SEPOLIA"; CChainId[CChainId["ETH"] = 1] = "ETH"; CChainId[CChainId["POLYGON"] = 137] = "POLYGON"; CChainId[CChainId["BSC"] = 56] = "BSC"; CChainId[CChainId["ZKSYNC_ERA"] = 324] = "ZKSYNC_ERA"; CChainId[CChainId["KLAYTN"] = 8217] = "KLAYTN"; })(exports.CChainId || (exports.CChainId = {})); (function (VotingTypes) { VotingTypes[VotingTypes["ANY"] = 0] = "ANY"; VotingTypes[VotingTypes["SINGLE"] = 1] = "SINGLE"; VotingTypes[VotingTypes["MULTI"] = 2] = "MULTI"; })(exports.VotingTypes || (exports.VotingTypes = {})); (function (ProposalStatus) { ProposalStatus[ProposalStatus["SOON"] = 1] = "SOON"; ProposalStatus[ProposalStatus["OPEN"] = 2] = "OPEN"; ProposalStatus[ProposalStatus["CLOSED"] = 3] = "CLOSED"; ProposalStatus[ProposalStatus["CANCEL"] = 4] = "CANCEL"; ProposalStatus[ProposalStatus["SUCCESS"] = 5] = "SUCCESS"; })(exports.ProposalStatus || (exports.ProposalStatus = {})); (function (ProposalSignType) { ProposalSignType[ProposalSignType["CREATE_PROPOSAL"] = 0] = "CREATE_PROPOSAL"; ProposalSignType[ProposalSignType["VOTE"] = 1] = "VOTE"; })(exports.ProposalSignType || (exports.ProposalSignType = {})); (function (ProposalVotingTypes) { ProposalVotingTypes[ProposalVotingTypes["SINGLE"] = 1] = "SINGLE"; ProposalVotingTypes[ProposalVotingTypes["MULTI"] = 2] = "MULTI"; })(exports.ProposalVotingTypes || (exports.ProposalVotingTypes = {})); function _regeneratorRuntime() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function () { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function (obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) 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 ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function (skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function () { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function (exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function (type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function (record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function (finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function (tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function (iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } function _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 ? Object.assign.bind() : 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.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : 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.bind(); } 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); } var _SOLIDITY_TYPE_MAXIMA; var TradeType; (function (TradeType) { TradeType[TradeType["EXACT_INPUT"] = 0] = "EXACT_INPUT"; TradeType[TradeType["EXACT_OUTPUT"] = 1] = "EXACT_OUTPUT"; })(TradeType || (TradeType = {})); var Rounding; (function (Rounding) { Rounding[Rounding["ROUND_DOWN"] = 0] = "ROUND_DOWN"; Rounding[Rounding["ROUND_HALF_UP"] = 1] = "ROUND_HALF_UP"; Rounding[Rounding["ROUND_UP"] = 2] = "ROUND_UP"; })(Rounding || (Rounding = {})); // exports for internal consumption var ZERO = /*#__PURE__*/JSBI.BigInt(0); var ONE = /*#__PURE__*/JSBI.BigInt(1); var TEN = /*#__PURE__*/JSBI.BigInt(10); var _100 = /*#__PURE__*/JSBI.BigInt(100); var SolidityType; (function (SolidityType) { SolidityType["uint8"] = "uint8"; SolidityType["uint256"] = "uint256"; })(SolidityType || (SolidityType = {})); var SOLIDITY_TYPE_MAXIMA = (_SOLIDITY_TYPE_MAXIMA = {}, _SOLIDITY_TYPE_MAXIMA[SolidityType.uint8] = /*#__PURE__*/JSBI.BigInt('0xff'), _SOLIDITY_TYPE_MAXIMA[SolidityType.uint256] = /*#__PURE__*/JSBI.BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), _SOLIDITY_TYPE_MAXIMA); function validateSolidityTypeInstance(value, solidityType) { !JSBI.greaterThanOrEqual(value, ZERO) ? invariant(false, value + " is not a " + solidityType + ".") : void 0; !JSBI.lessThanOrEqual(value, SOLIDITY_TYPE_MAXIMA[solidityType]) ? invariant(false, value + " is not a " + solidityType + ".") : void 0; } // warns if addresses are not checksummed function validateAndParseAddress(address$1) { try { var checksummedAddress = address.getAddress(address$1); "development" !== "production" ? warning(address$1 === checksummedAddress, address$1 + " is not checksummed.") : void 0; return checksummedAddress; } catch (error) { invariant(false, address$1 + " is not a valid address.") ; } } function parseBigintIsh(bigintIsh) { return bigintIsh instanceof JSBI ? bigintIsh : typeof bigintIsh === 'bigint' ? JSBI.BigInt(bigintIsh.toString()) : JSBI.BigInt(bigintIsh); } // mock the on-chain sqrt function /** * A currency is any fungible financial instrument on Ethereum, including Ether and all ERC20 tokens. * * The only instance of the base class `Currency` is Ether. */ var Currency = /** * Constructs an instance of the base class `Currency`. The only instance of the base class `Currency` is `Currency.ETHER`. * @param decimals decimals of the currency * @param symbol symbol of the currency * @param name of the currency */ function Currency(decimals, symbol, name) { validateSolidityTypeInstance(JSBI.BigInt(decimals), SolidityType.uint8); this.decimals = decimals; this.symbol = symbol; this.name = name; }; /** * The only instance of the base class `Currency`. */ Currency.ETHER = /*#__PURE__*/new Currency(18, 'HT', 'Ether'); var ETHER = Currency.ETHER; /** * Represents an ERC20 token with a unique address and some metadata. */ var Token = /*#__PURE__*/function (_Currency) { _inheritsLoose(Token, _Currency); function Token(chainId, address, decimals, symbol, name) { var _this; _this = _Currency.call(this, decimals, symbol, name) || this; _this.chainId = chainId; _this.address = validateAndParseAddress(address); return _this; } /** * Returns true if the two tokens are equivalent, i.e. have the same chainId and address. * @param other other token to compare */ var _proto = Token.prototype; _proto.equals = function equals(other) { // short circuit on reference equality if (this === other) { return true; } return this.chainId === other.chainId && this.address === other.address; } /** * Returns true if the address of this token sorts before the address of the other token * @param other other token to compare * @throws if the tokens have the same address * @throws if the tokens are on different chains */ ; _proto.sortsBefore = function sortsBefore(other) { !(this.chainId === other.chainId) ? invariant(false, 'CHAIN_IDS') : void 0; !(this.address !== other.address) ? invariant(false, 'ADDRESSES') : void 0; return this.address.toLowerCase() < other.address.toLowerCase(); }; return Token; }(Currency); /** * Compares two currencies for equality */ function currencyEquals(currencyA, currencyB) { if (currencyA instanceof Token && currencyB instanceof Token) { return currencyA.equals(currencyB); } else if (currencyA instanceof Token) { return false; } else if (currencyB instanceof Token) { return false; } else { return currencyA === currencyB; } } var _toSignificantRoundin, _toFixedRounding; var Decimal = /*#__PURE__*/toFormat(_Decimal); var Big = /*#__PURE__*/toFormat(_Big); var toSignificantRounding = (_toSignificantRoundin = {}, _toSignificantRoundin[Rounding.ROUND_DOWN] = Decimal.ROUND_DOWN, _toSignificantRoundin[Rounding.ROUND_HALF_UP] = Decimal.ROUND_HALF_UP, _toSignificantRoundin[Rounding.ROUND_UP] = Decimal.ROUND_UP, _toSignificantRoundin); var toFixedRounding = (_toFixedRounding = {}, _toFixedRounding[Rounding.ROUND_DOWN] = 0, _toFixedRounding[Rounding.ROUND_HALF_UP] = 1, _toFixedRounding[Rounding.ROUND_UP] = 2, _toFixedRounding); var Fraction = /*#__PURE__*/function () { function Fraction(numerator, denominator) { if (denominator === void 0) { denominator = ONE; } this.numerator = parseBigintIsh(numerator); this.denominator = parseBigintIsh(denominator); } // performs floor division var _proto = Fraction.prototype; _proto.invert = function invert() { return new Fraction(this.denominator, this.numerator); }; _proto.add = function add(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); if (JSBI.equal(this.denominator, otherParsed.denominator)) { return new Fraction(JSBI.add(this.numerator, otherParsed.numerator), this.denominator); } return new Fraction(JSBI.add(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.subtract = function subtract(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); if (JSBI.equal(this.denominator, otherParsed.denominator)) { return new Fraction(JSBI.subtract(this.numerator, otherParsed.numerator), this.denominator); } return new Fraction(JSBI.subtract(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.lessThan = function lessThan(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.lessThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.equalTo = function equalTo(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.equal(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.greaterThan = function greaterThan(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return JSBI.greaterThan(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(otherParsed.numerator, this.denominator)); }; _proto.multiply = function multiply(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return new Fraction(JSBI.multiply(this.numerator, otherParsed.numerator), JSBI.multiply(this.denominator, otherParsed.denominator)); }; _proto.divide = function divide(other) { var otherParsed = other instanceof Fraction ? other : new Fraction(parseBigintIsh(other)); return new Fraction(JSBI.multiply(this.numerator, otherParsed.denominator), JSBI.multiply(this.denominator, otherParsed.numerator)); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (format === void 0) { format = { groupSeparator: '' }; } if (rounding === void 0) { rounding = Rounding.ROUND_HALF_UP; } !Number.isInteger(significantDigits) ? invariant(false, significantDigits + " is not an integer.") : void 0; !(significantDigits > 0) ? invariant(false, significantDigits + " is not positive.") : void 0; Decimal.set({ precision: significantDigits + 1, rounding: toSignificantRounding[rounding] }); var quotient = new Decimal(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(significantDigits); return quotient.toFormat(quotient.decimalPlaces(), format); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (format === void 0) { format = { groupSeparator: '' }; } if (rounding === void 0) { rounding = Rounding.ROUND_HALF_UP; } !Number.isInteger(decimalPlaces) ? invariant(false, decimalPlaces + " is not an integer.") : void 0; !(decimalPlaces >= 0) ? invariant(false, decimalPlaces + " is negative.") : void 0; Big.DP = decimalPlaces; Big.RM = toFixedRounding[rounding]; return new Big(this.numerator.toString()).div(this.denominator.toString()).toFormat(decimalPlaces, format); }; _createClass(Fraction, [{ key: "quotient", get: function get() { return JSBI.divide(this.numerator, this.denominator); } // remainder after floor division }, { key: "remainder", get: function get() { return new Fraction(JSBI.remainder(this.numerator, this.denominator), this.denominator); } }]); return Fraction; }(); var _100_PERCENT = /*#__PURE__*/new Fraction(_100); var Percent = /*#__PURE__*/function (_Fraction) { _inheritsLoose(Percent, _Fraction); function Percent() { return _Fraction.apply(this, arguments) || this; } var _proto = Percent.prototype; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 5; } return this.multiply(_100_PERCENT).toSignificant(significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = 2; } return this.multiply(_100_PERCENT).toFixed(decimalPlaces, format, rounding); }; return Percent; }(Fraction); var Big$1 = /*#__PURE__*/toFormat(_Big); var CurrencyAmount = /*#__PURE__*/function (_Fraction) { _inheritsLoose(CurrencyAmount, _Fraction); // amount _must_ be raw, i.e. in the native representation function CurrencyAmount(currency, amount) { var _this; var parsedAmount = parseBigintIsh(amount); validateSolidityTypeInstance(parsedAmount, SolidityType.uint256); _this = _Fraction.call(this, parsedAmount, JSBI.exponentiate(TEN, JSBI.BigInt(currency.decimals))) || this; _this.currency = currency; return _this; } /** * Helper that calls the constructor with the ETHER currency * @param amount ether amount in wei */ CurrencyAmount.ether = function ether(amount) { return new CurrencyAmount(ETHER, amount); }; var _proto = CurrencyAmount.prototype; _proto.add = function add(other) { !currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0; return new CurrencyAmount(this.currency, JSBI.add(this.raw, other.raw)); }; _proto.subtract = function subtract(other) { !currencyEquals(this.currency, other.currency) ? invariant(false, 'TOKEN') : void 0; return new CurrencyAmount(this.currency, JSBI.subtract(this.raw, other.raw)); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 6; } if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; } return _Fraction.prototype.toSignificant.call(this, significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = this.currency.decimals; } if (rounding === void 0) { rounding = Rounding.ROUND_DOWN; } !(decimalPlaces <= this.currency.decimals) ? invariant(false, 'DECIMALS') : void 0; return _Fraction.prototype.toFixed.call(this, decimalPlaces, format, rounding); }; _proto.toExact = function toExact(format) { if (format === void 0) { format = { groupSeparator: '' }; } Big$1.DP = this.currency.decimals; return new Big$1(this.numerator.toString()).div(this.denominator.toString()).toFormat(format); }; _createClass(CurrencyAmount, [{ key: "raw", get: function get() { return this.numerator; } }]); return CurrencyAmount; }(Fraction); var TokenAmount = /*#__PURE__*/function (_CurrencyAmount) { _inheritsLoose(TokenAmount, _CurrencyAmount); // amount _must_ be raw, i.e. in the native representation function TokenAmount(token, amount) { var _this; _this = _CurrencyAmount.call(this, token, amount) || this; _this.token = token; return _this; } var _proto = TokenAmount.prototype; _proto.add = function add(other) { !this.token.equals(other.token) ? invariant(false, 'TOKEN') : void 0; return new TokenAmount(this.token, JSBI.add(this.raw, other.raw)); }; _proto.subtract = function subtract(other) { !this.token.equals(other.token) ? invariant(false, 'TOKEN') : void 0; return new TokenAmount(this.token, JSBI.subtract(this.raw, other.raw)); }; return TokenAmount; }(CurrencyAmount); var Price = /*#__PURE__*/function (_Fraction) { _inheritsLoose(Price, _Fraction); // denominator and numerator _must_ be raw, i.e. in the native representation function Price(baseCurrency, quoteCurrency, denominator, numerator) { var _this; _this = _Fraction.call(this, numerator, denominator) || this; _this.baseCurrency = baseCurrency; _this.quoteCurrency = quoteCurrency; _this.scalar = new Fraction(JSBI.exponentiate(TEN, JSBI.BigInt(baseCurrency.decimals)), JSBI.exponentiate(TEN, JSBI.BigInt(quoteCurrency.decimals))); return _this; } var _proto = Price.prototype; _proto.invert = function invert() { return new Price(this.quoteCurrency, this.baseCurrency, this.numerator, this.denominator); }; _proto.multiply = function multiply(other) { !currencyEquals(this.quoteCurrency, other.baseCurrency) ? invariant(false, 'TOKEN') : void 0; var fraction = _Fraction.prototype.multiply.call(this, other); return new Price(this.baseCurrency, other.quoteCurrency, fraction.denominator, fraction.numerator); } // performs floor division on overflow ; _proto.quote = function quote(currencyAmount) { !currencyEquals(currencyAmount.currency, this.baseCurrency) ? invariant(false, 'TOKEN') : void 0; if (this.quoteCurrency instanceof Token) { return new TokenAmount(this.quoteCurrency, _Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient); } return CurrencyAmount.ether(_Fraction.prototype.multiply.call(this, currencyAmount.raw).quotient); }; _proto.toSignificant = function toSignificant(significantDigits, format, rounding) { if (significantDigits === void 0) { significantDigits = 6; } return this.adjusted.toSignificant(significantDigits, format, rounding); }; _proto.toFixed = function toFixed(decimalPlaces, format, rounding) { if (decimalPlaces === void 0) { decimalPlaces = 4; } return this.adjusted.toFixed(decimalPlaces, format, rounding); }; _createClass(Price, [{ key: "raw", get: function get() { return new Fraction(this.numerator, this.denominator); } }, { key: "adjusted", get: function get() { return _Fraction.prototype.multiply.call(this, this.scalar); } }]); return Price; }(Fraction); function isAddress(value) { try { return address.getAddress(value); } catch (_unused) { return false; } } function currentTimeStamp() { return Number((new Date().getTime() / 1000).toFixed()); } var UnsupportedProtocolError = /*#__PURE__*/function (_Error2) { _inheritsLoose(UnsupportedProtocolError, _Error2); function UnsupportedProtocolError(protocol) { return _Error2.call(this, "Unsupported protocol: " + protocol) || this; } return UnsupportedProtocolError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var InvalidAddressOrEnsError = /*#__PURE__*/function (_Error3) { _inheritsLoose(InvalidAddressOrEnsError, _Error3); function InvalidAddressOrEnsError() { return _Error3.call(this, "Invalid address or ENS") || this; } return InvalidAddressOrEnsError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var InvalidProposalIdVoteError = /*#__PURE__*/function (_Error6) { _inheritsLoose(InvalidProposalIdVoteError, _Error6); function InvalidProposalIdVoteError() { return _Error6.call(this, "Invalid proposal vote status") || this; } return InvalidProposalIdVoteError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var InvalidProposalIdInsufficientVotesError = /*#__PURE__*/function (_Error7) { _inheritsLoose(InvalidProposalIdInsufficientVotesError, _Error7); function InvalidProposalIdInsufficientVotesError() { return _Error7.call(this, "Insufficient votes") || this; } return InvalidProposalIdInsufficientVotesError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var InvalidProposalIdCancelError = /*#__PURE__*/function (_Error8) { _inheritsLoose(InvalidProposalIdCancelError, _Error8); function InvalidProposalIdCancelError() { return _Error8.call(this, "The current state cannot be cancelled") || this; } return InvalidProposalIdCancelError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var NoSignerError = /*#__PURE__*/function (_Error10) { _inheritsLoose(NoSignerError, _Error10); function NoSignerError() { return _Error10.call(this, "A signer is needed") || this; } return NoSignerError; }( /*#__PURE__*/_wrapNativeSuper(Error)); var _process$env; var supportedProtocols = ["https:"]; if (typeof process !== "undefined" && (_process$env = process.env) != null && _process$env.TESTING) { supportedProtocols.push("http:"); } /** * The Context class is an utility component that holds the configuration passed to Clique instance. */ var Context = /*#__PURE__*/function () { // INTERNAL CONTEXT STATE /** * @param {Object} params * * @constructor */ function Context(contextParams) { if (!contextParams.daoAddress || !isAddress(contextParams.daoAddress)) { throw new Error("Missing DAO address"); } else if (!contextParams.daoChainId) { throw new Error("Missing DAO chainId"); } else if (!Object.keys(contextParams.web3Providers).length) { throw new Error("No web3 endpoints defined"); } var _web3Providers = {}; for (var key in contextParams.web3Providers) { if (Object.prototype.hasOwnProperty.call(contextParams.web3Providers, key)) { var _web3ProviderItem = contextParams.web3Providers[Number(key)]; _web3Providers[Number(key)] = Context.resolveWeb3Providers(_web3ProviderItem); } } this.state = { signer: contextParams.signer, daoAddress: contextParams.daoAddress, daoChainId: contextParams.daoChainId, web3Providers: _web3Providers }; } /** * set web3Providers and signer * @param contextParams */ var _proto = Context.prototype; _proto.set = function set(contextParams) { var _state = Object.assign({}, this.state || {}); if (contextParams.signer) { _state.signer = contextParams.signer; } if (contextParams.web3Providers) { var _web3Providers = {}; for (var key in contextParams.web3Providers) { if (Object.prototype.hasOwnProperty.call(contextParams.web3Providers, key)) { var _web3ProviderItem = contextParams.web3Providers[Number(key)]; _web3Providers[Number(key)] = Context.resolveWeb3Providers(_web3ProviderItem); } } _state.web3Providers = _web3Providers; } this.state = _state; } /** * Getter for the Signer * * @var signer * * @returns {Signer} * * @public */ ; // INTERNAL HELPERS Context.resolveWeb3Providers = function resolveWeb3Providers(endpoints, network) { if (Array.isArray(endpoints)) { return endpoints.map(function (item) { if (typeof item === "string") { var url = new URL(item); if (!supportedProtocols.includes(url.protocol)) { throw new UnsupportedProtocolError(url.protocol); } return new providers.JsonRpcProvider(url.href, network); } return item; }); } else if (typeof endpoints === "string") { var url = new URL(endpoints); if (!supportedProtocols.includes(url.protocol)) { throw new UnsupportedProtocolError(url.protocol); } return [new providers.JsonRpcProvider(url.href, network)]; } else { return [endpoints]; } }; _createClass(Context, [{ key: "signer", get: function get() { return this.state.signer; } /** * Getter for the web3 providers * * @var web3Providers * * @returns {JsonRpcProvider[]} * * @public */ }, { key: "web3Providers", get: function get() { return this.state.web3Providers; } /** * dao address */ }, { key: "daoDaoAddress", get: function get() { return this.state.daoAddress; } /** * dao chainId */ }, { key: "daoDaoChainId", get: function get() { return this.state.daoChainId; } }]); return Context; }(); var DaoContractAbi = [{ "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "admin", "type": "address" }, { "indexed": false, "internalType": "bool", "name": "enable", "type": "bool" }], "name": "Admin", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "proposalId", "type": "uint256" }], "name": "CancelProposal", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "proposalId", "type": "uint256" }, { "indexed": true, "internalType": "address", "name": "proposer", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "startTime", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "endTime", "type": "uint256" }], "name": "CreateProposal", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint8", "name": "version", "type": "uint8" }], "name": "Initialized", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "settingType", "type": "uint256" }], "name": "Setting", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "proposalId", "type": "uint256" }, { "indexed": true, "internalType": "address", "name": "voter", "type": "address" }, { "indexed": true, "internalType": "uint256", "name": "optionIndex", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Vote", "type": "event" }, { "inputs": [], "name": "SETTING_TYPE_GENERAL", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "SETTING_TYPE_GOVERNANCE", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "SETTING_TYPE_TOKEN", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "admins", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "proposalId_", "type": "uint256" }], "name": "cancelProposal", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "string", "name": "title", "type": "string" }, { "internalType": "string", "name": "introduction", "type": "string" }, { "internalType": "string", "name": "content", "type": "string" }, { "internalType": "uint256", "name": "startTime", "type": "uint256" }, { "internalType": "uint256", "name": "endTime", "type": "uint256" }, { "internalType": "enum IDAOBase.VotingType", "name": "votingType", "type": "uint8" }], "internalType": "struct DAOBase.ProposalInput", "name": "input_", "type": "tuple" }, { "internalType": "string[]", "name": "options_", "type": "string[]" }, { "components": [{ "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "uint256", "name": "balance", "type": "uint256" }, { "internalType": "enum DAOBase.SignType", "name": "signType", "type": "uint8" }, { "internalType": "uint256", "name": "proposalIdOrDeadline", "type": "uint256" }], "internalType": "struct DAOBase.SignInfo", "name": "signInfo_", "type": "tuple" }, { "internalType": "bytes", "name": "signature_", "type": "bytes" }], "name": "createProposal", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "daoGovernance", "outputs": [{ "internalType": "uint256", "name": "proposalThreshold", "type": "uint256" }, { "internalType": "uint256", "name": "votingThreshold", "type": "uint256" }, { "internalType": "uint256", "name": "votingPeriod", "type": "uint256" }, { "internalType": "enum IDAOBase.VotingType", "name": "votingType", "type": "uint8" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "daoInfo", "outputs": [{ "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "handle", "type": "string" }, { "internalType": "string", "name": "category", "type": "string" }, { "internalType": "string", "name": "description", "type": "string" }, { "internalType": "string", "name": "twitter", "type": "string" }, { "internalType": "string", "name": "github", "type": "string" }, { "internalType": "string", "name": "discord", "type": "string" }, { "internalType": "string", "name": "daoLogo", "type": "string" }, { "internalType": "string", "name": "website", "type": "string" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "daoToken", "outputs": [{ "internalType": "uint256", "name": "chainId", "type": "uint256" }, { "internalType": "address", "name": "tokenAddress", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "daoVersion", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "pure", "type": "function" }, { "inputs": [], "name": "factoryAddress", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "proposalId_", "type": "uint256" }], "name": "getProposalOptionById", "outputs": [{ "components": [{ "internalType": "string", "name": "name", "type": "string" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }], "internalType": "struct DAOBase.ProposalOption[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "account_", "type": "address" }, { "internalType": "uint256", "name": "proposalId_", "type": "uint256" }], "name": "getVoteInfoByAccountAndProposalId", "outputs": [{ "components": [{ "internalType": "uint25