UNPKG

@superfluid-finance/sdk-core

Version:
1,216 lines (1,202 loc) 6.19 MB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.sdkCore = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.version = void 0; exports.version = "abi/5.7.0"; },{}],2:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultAbiCoder = exports.AbiCoder = void 0; // See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI var bytes_1 = require("@ethersproject/bytes"); var properties_1 = require("@ethersproject/properties"); var logger_1 = require("@ethersproject/logger"); var _version_1 = require("./_version"); var logger = new logger_1.Logger(_version_1.version); var abstract_coder_1 = require("./coders/abstract-coder"); var address_1 = require("./coders/address"); var array_1 = require("./coders/array"); var boolean_1 = require("./coders/boolean"); var bytes_2 = require("./coders/bytes"); var fixed_bytes_1 = require("./coders/fixed-bytes"); var null_1 = require("./coders/null"); var number_1 = require("./coders/number"); var string_1 = require("./coders/string"); var tuple_1 = require("./coders/tuple"); var fragments_1 = require("./fragments"); var paramTypeBytes = new RegExp(/^bytes([0-9]*)$/); var paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/); var AbiCoder = /** @class */ (function () { function AbiCoder(coerceFunc) { (0, properties_1.defineReadOnly)(this, "coerceFunc", coerceFunc || null); } AbiCoder.prototype._getCoder = function (param) { var _this = this; switch (param.baseType) { case "address": return new address_1.AddressCoder(param.name); case "bool": return new boolean_1.BooleanCoder(param.name); case "string": return new string_1.StringCoder(param.name); case "bytes": return new bytes_2.BytesCoder(param.name); case "array": return new array_1.ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name); case "tuple": return new tuple_1.TupleCoder((param.components || []).map(function (component) { return _this._getCoder(component); }), param.name); case "": return new null_1.NullCoder(param.name); } // u?int[0-9]* var match = param.type.match(paramTypeNumber); if (match) { var size = parseInt(match[2] || "256"); if (size === 0 || size > 256 || (size % 8) !== 0) { logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param); } return new number_1.NumberCoder(size / 8, (match[1] === "int"), param.name); } // bytes[0-9]+ match = param.type.match(paramTypeBytes); if (match) { var size = parseInt(match[1]); if (size === 0 || size > 32) { logger.throwArgumentError("invalid bytes length", "param", param); } return new fixed_bytes_1.FixedBytesCoder(size, param.name); } return logger.throwArgumentError("invalid type", "type", param.type); }; AbiCoder.prototype._getWordSize = function () { return 32; }; AbiCoder.prototype._getReader = function (data, allowLoose) { return new abstract_coder_1.Reader(data, this._getWordSize(), this.coerceFunc, allowLoose); }; AbiCoder.prototype._getWriter = function () { return new abstract_coder_1.Writer(this._getWordSize()); }; AbiCoder.prototype.getDefaultValue = function (types) { var _this = this; var coders = types.map(function (type) { return _this._getCoder(fragments_1.ParamType.from(type)); }); var coder = new tuple_1.TupleCoder(coders, "_"); return coder.defaultValue(); }; AbiCoder.prototype.encode = function (types, values) { var _this = this; if (types.length !== values.length) { logger.throwError("types/values length mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, { count: { types: types.length, values: values.length }, value: { types: types, values: values } }); } var coders = types.map(function (type) { return _this._getCoder(fragments_1.ParamType.from(type)); }); var coder = (new tuple_1.TupleCoder(coders, "_")); var writer = this._getWriter(); coder.encode(writer, values); return writer.data; }; AbiCoder.prototype.decode = function (types, data, loose) { var _this = this; var coders = types.map(function (type) { return _this._getCoder(fragments_1.ParamType.from(type)); }); var coder = new tuple_1.TupleCoder(coders, "_"); return coder.decode(this._getReader((0, bytes_1.arrayify)(data), loose)); }; return AbiCoder; }()); exports.AbiCoder = AbiCoder; exports.defaultAbiCoder = new AbiCoder(); },{"./_version":1,"./coders/abstract-coder":3,"./coders/address":4,"./coders/array":6,"./coders/boolean":7,"./coders/bytes":8,"./coders/fixed-bytes":9,"./coders/null":10,"./coders/number":11,"./coders/string":12,"./coders/tuple":13,"./fragments":14,"@ethersproject/bytes":31,"@ethersproject/logger":58,"@ethersproject/properties":64}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Reader = exports.Writer = exports.Coder = exports.checkResultErrors = void 0; var bytes_1 = require("@ethersproject/bytes"); var bignumber_1 = require("@ethersproject/bignumber"); var properties_1 = require("@ethersproject/properties"); var logger_1 = require("@ethersproject/logger"); var _version_1 = require("../_version"); var logger = new logger_1.Logger(_version_1.version); function checkResultErrors(result) { // Find the first error (if any) var errors = []; var checkErrors = function (path, object) { if (!Array.isArray(object)) { return; } for (var key in object) { var childPath = path.slice(); childPath.push(key); try { checkErrors(childPath, object[key]); } catch (error) { errors.push({ path: childPath, error: error }); } } }; checkErrors([], result); return errors; } exports.checkResultErrors = checkResultErrors; var Coder = /** @class */ (function () { function Coder(name, type, localName, dynamic) { // @TODO: defineReadOnly these this.name = name; this.type = type; this.localName = localName; this.dynamic = dynamic; } Coder.prototype._throwError = function (message, value) { logger.throwArgumentError(message, this.localName, value); }; return Coder; }()); exports.Coder = Coder; var Writer = /** @class */ (function () { function Writer(wordSize) { (0, properties_1.defineReadOnly)(this, "wordSize", wordSize || 32); this._data = []; this._dataLength = 0; this._padding = new Uint8Array(wordSize); } Object.defineProperty(Writer.prototype, "data", { get: function () { return (0, bytes_1.hexConcat)(this._data); }, enumerable: false, configurable: true }); Object.defineProperty(Writer.prototype, "length", { get: function () { return this._dataLength; }, enumerable: false, configurable: true }); Writer.prototype._writeData = function (data) { this._data.push(data); this._dataLength += data.length; return data.length; }; Writer.prototype.appendWriter = function (writer) { return this._writeData((0, bytes_1.concat)(writer._data)); }; // Arrayish items; padded on the right to wordSize Writer.prototype.writeBytes = function (value) { var bytes = (0, bytes_1.arrayify)(value); var paddingOffset = bytes.length % this.wordSize; if (paddingOffset) { bytes = (0, bytes_1.concat)([bytes, this._padding.slice(paddingOffset)]); } return this._writeData(bytes); }; Writer.prototype._getValue = function (value) { var bytes = (0, bytes_1.arrayify)(bignumber_1.BigNumber.from(value)); if (bytes.length > this.wordSize) { logger.throwError("value out-of-bounds", logger_1.Logger.errors.BUFFER_OVERRUN, { length: this.wordSize, offset: bytes.length }); } if (bytes.length % this.wordSize) { bytes = (0, bytes_1.concat)([this._padding.slice(bytes.length % this.wordSize), bytes]); } return bytes; }; // BigNumberish items; padded on the left to wordSize Writer.prototype.writeValue = function (value) { return this._writeData(this._getValue(value)); }; Writer.prototype.writeUpdatableValue = function () { var _this = this; var offset = this._data.length; this._data.push(this._padding); this._dataLength += this.wordSize; return function (value) { _this._data[offset] = _this._getValue(value); }; }; return Writer; }()); exports.Writer = Writer; var Reader = /** @class */ (function () { function Reader(data, wordSize, coerceFunc, allowLoose) { (0, properties_1.defineReadOnly)(this, "_data", (0, bytes_1.arrayify)(data)); (0, properties_1.defineReadOnly)(this, "wordSize", wordSize || 32); (0, properties_1.defineReadOnly)(this, "_coerceFunc", coerceFunc); (0, properties_1.defineReadOnly)(this, "allowLoose", allowLoose); this._offset = 0; } Object.defineProperty(Reader.prototype, "data", { get: function () { return (0, bytes_1.hexlify)(this._data); }, enumerable: false, configurable: true }); Object.defineProperty(Reader.prototype, "consumed", { get: function () { return this._offset; }, enumerable: false, configurable: true }); // The default Coerce function Reader.coerce = function (name, value) { var match = name.match("^u?int([0-9]+)$"); if (match && parseInt(match[1]) <= 48) { value = value.toNumber(); } return value; }; Reader.prototype.coerce = function (name, value) { if (this._coerceFunc) { return this._coerceFunc(name, value); } return Reader.coerce(name, value); }; Reader.prototype._peekBytes = function (offset, length, loose) { var alignedLength = Math.ceil(length / this.wordSize) * this.wordSize; if (this._offset + alignedLength > this._data.length) { if (this.allowLoose && loose && this._offset + length <= this._data.length) { alignedLength = length; } else { logger.throwError("data out-of-bounds", logger_1.Logger.errors.BUFFER_OVERRUN, { length: this._data.length, offset: this._offset + alignedLength }); } } return this._data.slice(this._offset, this._offset + alignedLength); }; Reader.prototype.subReader = function (offset) { return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc, this.allowLoose); }; Reader.prototype.readBytes = function (length, loose) { var bytes = this._peekBytes(0, length, !!loose); this._offset += bytes.length; // @TODO: Make sure the length..end bytes are all 0? return bytes.slice(0, length); }; Reader.prototype.readValue = function () { return bignumber_1.BigNumber.from(this.readBytes(this.wordSize)); }; return Reader; }()); exports.Reader = Reader; },{"../_version":1,"@ethersproject/bignumber":29,"@ethersproject/bytes":31,"@ethersproject/logger":58,"@ethersproject/properties":64}],4:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AddressCoder = void 0; var address_1 = require("@ethersproject/address"); var bytes_1 = require("@ethersproject/bytes"); var abstract_coder_1 = require("./abstract-coder"); var AddressCoder = /** @class */ (function (_super) { __extends(AddressCoder, _super); function AddressCoder(localName) { return _super.call(this, "address", "address", localName, false) || this; } AddressCoder.prototype.defaultValue = function () { return "0x0000000000000000000000000000000000000000"; }; AddressCoder.prototype.encode = function (writer, value) { try { value = (0, address_1.getAddress)(value); } catch (error) { this._throwError(error.message, value); } return writer.writeValue(value); }; AddressCoder.prototype.decode = function (reader) { return (0, address_1.getAddress)((0, bytes_1.hexZeroPad)(reader.readValue().toHexString(), 20)); }; return AddressCoder; }(abstract_coder_1.Coder)); exports.AddressCoder = AddressCoder; },{"./abstract-coder":3,"@ethersproject/address":22,"@ethersproject/bytes":31}],5:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AnonymousCoder = void 0; var abstract_coder_1 = require("./abstract-coder"); // Clones the functionality of an existing Coder, but without a localName var AnonymousCoder = /** @class */ (function (_super) { __extends(AnonymousCoder, _super); function AnonymousCoder(coder) { var _this = _super.call(this, coder.name, coder.type, undefined, coder.dynamic) || this; _this.coder = coder; return _this; } AnonymousCoder.prototype.defaultValue = function () { return this.coder.defaultValue(); }; AnonymousCoder.prototype.encode = function (writer, value) { return this.coder.encode(writer, value); }; AnonymousCoder.prototype.decode = function (reader) { return this.coder.decode(reader); }; return AnonymousCoder; }(abstract_coder_1.Coder)); exports.AnonymousCoder = AnonymousCoder; },{"./abstract-coder":3}],6:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrayCoder = exports.unpack = exports.pack = void 0; var logger_1 = require("@ethersproject/logger"); var _version_1 = require("../_version"); var logger = new logger_1.Logger(_version_1.version); var abstract_coder_1 = require("./abstract-coder"); var anonymous_1 = require("./anonymous"); function pack(writer, coders, values) { var arrayValues = null; if (Array.isArray(values)) { arrayValues = values; } else if (values && typeof (values) === "object") { var unique_1 = {}; arrayValues = coders.map(function (coder) { var name = coder.localName; if (!name) { logger.throwError("cannot encode object for signature with missing names", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "values", coder: coder, value: values }); } if (unique_1[name]) { logger.throwError("cannot encode object for signature with duplicate names", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "values", coder: coder, value: values }); } unique_1[name] = true; return values[name]; }); } else { logger.throwArgumentError("invalid tuple value", "tuple", values); } if (coders.length !== arrayValues.length) { logger.throwArgumentError("types/value length mismatch", "tuple", values); } var staticWriter = new abstract_coder_1.Writer(writer.wordSize); var dynamicWriter = new abstract_coder_1.Writer(writer.wordSize); var updateFuncs = []; coders.forEach(function (coder, index) { var value = arrayValues[index]; if (coder.dynamic) { // Get current dynamic offset (for the future pointer) var dynamicOffset_1 = dynamicWriter.length; // Encode the dynamic value into the dynamicWriter coder.encode(dynamicWriter, value); // Prepare to populate the correct offset once we are done var updateFunc_1 = staticWriter.writeUpdatableValue(); updateFuncs.push(function (baseOffset) { updateFunc_1(baseOffset + dynamicOffset_1); }); } else { coder.encode(staticWriter, value); } }); // Backfill all the dynamic offsets, now that we know the static length updateFuncs.forEach(function (func) { func(staticWriter.length); }); var length = writer.appendWriter(staticWriter); length += writer.appendWriter(dynamicWriter); return length; } exports.pack = pack; function unpack(reader, coders) { var values = []; // A reader anchored to this base var baseReader = reader.subReader(0); coders.forEach(function (coder) { var value = null; if (coder.dynamic) { var offset = reader.readValue(); var offsetReader = baseReader.subReader(offset.toNumber()); try { value = coder.decode(offsetReader); } catch (error) { // Cannot recover from this if (error.code === logger_1.Logger.errors.BUFFER_OVERRUN) { throw error; } value = error; value.baseType = coder.name; value.name = coder.localName; value.type = coder.type; } } else { try { value = coder.decode(reader); } catch (error) { // Cannot recover from this if (error.code === logger_1.Logger.errors.BUFFER_OVERRUN) { throw error; } value = error; value.baseType = coder.name; value.name = coder.localName; value.type = coder.type; } } if (value != undefined) { values.push(value); } }); // We only output named properties for uniquely named coders var uniqueNames = coders.reduce(function (accum, coder) { var name = coder.localName; if (name) { if (!accum[name]) { accum[name] = 0; } accum[name]++; } return accum; }, {}); // Add any named parameters (i.e. tuples) coders.forEach(function (coder, index) { var name = coder.localName; if (!name || uniqueNames[name] !== 1) { return; } if (name === "length") { name = "_length"; } if (values[name] != null) { return; } var value = values[index]; if (value instanceof Error) { Object.defineProperty(values, name, { enumerable: true, get: function () { throw value; } }); } else { values[name] = value; } }); var _loop_1 = function (i) { var value = values[i]; if (value instanceof Error) { Object.defineProperty(values, i, { enumerable: true, get: function () { throw value; } }); } }; for (var i = 0; i < values.length; i++) { _loop_1(i); } return Object.freeze(values); } exports.unpack = unpack; var ArrayCoder = /** @class */ (function (_super) { __extends(ArrayCoder, _super); function ArrayCoder(coder, length, localName) { var _this = this; var type = (coder.type + "[" + (length >= 0 ? length : "") + "]"); var dynamic = (length === -1 || coder.dynamic); _this = _super.call(this, "array", type, localName, dynamic) || this; _this.coder = coder; _this.length = length; return _this; } ArrayCoder.prototype.defaultValue = function () { // Verifies the child coder is valid (even if the array is dynamic or 0-length) var defaultChild = this.coder.defaultValue(); var result = []; for (var i = 0; i < this.length; i++) { result.push(defaultChild); } return result; }; ArrayCoder.prototype.encode = function (writer, value) { if (!Array.isArray(value)) { this._throwError("expected array value", value); } var count = this.length; if (count === -1) { count = value.length; writer.writeValue(value.length); } logger.checkArgumentCount(value.length, count, "coder array" + (this.localName ? (" " + this.localName) : "")); var coders = []; for (var i = 0; i < value.length; i++) { coders.push(this.coder); } return pack(writer, coders, value); }; ArrayCoder.prototype.decode = function (reader) { var count = this.length; if (count === -1) { count = reader.readValue().toNumber(); // Check that there is *roughly* enough data to ensure // stray random data is not being read as a length. Each // slot requires at least 32 bytes for their value (or 32 // bytes as a link to the data). This could use a much // tighter bound, but we are erroring on the side of safety. if (count * 32 > reader._data.length) { logger.throwError("insufficient data length", logger_1.Logger.errors.BUFFER_OVERRUN, { length: reader._data.length, count: count }); } } var coders = []; for (var i = 0; i < count; i++) { coders.push(new anonymous_1.AnonymousCoder(this.coder)); } return reader.coerce(this.name, unpack(reader, coders)); }; return ArrayCoder; }(abstract_coder_1.Coder)); exports.ArrayCoder = ArrayCoder; },{"../_version":1,"./abstract-coder":3,"./anonymous":5,"@ethersproject/logger":58}],7:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BooleanCoder = void 0; var abstract_coder_1 = require("./abstract-coder"); var BooleanCoder = /** @class */ (function (_super) { __extends(BooleanCoder, _super); function BooleanCoder(localName) { return _super.call(this, "bool", "bool", localName, false) || this; } BooleanCoder.prototype.defaultValue = function () { return false; }; BooleanCoder.prototype.encode = function (writer, value) { return writer.writeValue(value ? 1 : 0); }; BooleanCoder.prototype.decode = function (reader) { return reader.coerce(this.type, !reader.readValue().isZero()); }; return BooleanCoder; }(abstract_coder_1.Coder)); exports.BooleanCoder = BooleanCoder; },{"./abstract-coder":3}],8:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BytesCoder = exports.DynamicBytesCoder = void 0; var bytes_1 = require("@ethersproject/bytes"); var abstract_coder_1 = require("./abstract-coder"); var DynamicBytesCoder = /** @class */ (function (_super) { __extends(DynamicBytesCoder, _super); function DynamicBytesCoder(type, localName) { return _super.call(this, type, type, localName, true) || this; } DynamicBytesCoder.prototype.defaultValue = function () { return "0x"; }; DynamicBytesCoder.prototype.encode = function (writer, value) { value = (0, bytes_1.arrayify)(value); var length = writer.writeValue(value.length); length += writer.writeBytes(value); return length; }; DynamicBytesCoder.prototype.decode = function (reader) { return reader.readBytes(reader.readValue().toNumber(), true); }; return DynamicBytesCoder; }(abstract_coder_1.Coder)); exports.DynamicBytesCoder = DynamicBytesCoder; var BytesCoder = /** @class */ (function (_super) { __extends(BytesCoder, _super); function BytesCoder(localName) { return _super.call(this, "bytes", localName) || this; } BytesCoder.prototype.decode = function (reader) { return reader.coerce(this.name, (0, bytes_1.hexlify)(_super.prototype.decode.call(this, reader))); }; return BytesCoder; }(DynamicBytesCoder)); exports.BytesCoder = BytesCoder; },{"./abstract-coder":3,"@ethersproject/bytes":31}],9:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.FixedBytesCoder = void 0; var bytes_1 = require("@ethersproject/bytes"); var abstract_coder_1 = require("./abstract-coder"); // @TODO: Merge this with bytes var FixedBytesCoder = /** @class */ (function (_super) { __extends(FixedBytesCoder, _super); function FixedBytesCoder(size, localName) { var _this = this; var name = "bytes" + String(size); _this = _super.call(this, name, name, localName, false) || this; _this.size = size; return _this; } FixedBytesCoder.prototype.defaultValue = function () { return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2); }; FixedBytesCoder.prototype.encode = function (writer, value) { var data = (0, bytes_1.arrayify)(value); if (data.length !== this.size) { this._throwError("incorrect data length", value); } return writer.writeBytes(data); }; FixedBytesCoder.prototype.decode = function (reader) { return reader.coerce(this.name, (0, bytes_1.hexlify)(reader.readBytes(this.size))); }; return FixedBytesCoder; }(abstract_coder_1.Coder)); exports.FixedBytesCoder = FixedBytesCoder; },{"./abstract-coder":3,"@ethersproject/bytes":31}],10:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NullCoder = void 0; var abstract_coder_1 = require("./abstract-coder"); var NullCoder = /** @class */ (function (_super) { __extends(NullCoder, _super); function NullCoder(localName) { return _super.call(this, "null", "", localName, false) || this; } NullCoder.prototype.defaultValue = function () { return null; }; NullCoder.prototype.encode = function (writer, value) { if (value != null) { this._throwError("not null", value); } return writer.writeBytes([]); }; NullCoder.prototype.decode = function (reader) { reader.readBytes(0); return reader.coerce(this.name, null); }; return NullCoder; }(abstract_coder_1.Coder)); exports.NullCoder = NullCoder; },{"./abstract-coder":3}],11:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberCoder = void 0; var bignumber_1 = require("@ethersproject/bignumber"); var constants_1 = require("@ethersproject/constants"); var abstract_coder_1 = require("./abstract-coder"); var NumberCoder = /** @class */ (function (_super) { __extends(NumberCoder, _super); function NumberCoder(size, signed, localName) { var _this = this; var name = ((signed ? "int" : "uint") + (size * 8)); _this = _super.call(this, name, name, localName, false) || this; _this.size = size; _this.signed = signed; return _this; } NumberCoder.prototype.defaultValue = function () { return 0; }; NumberCoder.prototype.encode = function (writer, value) { var v = bignumber_1.BigNumber.from(value); // Check bounds are safe for encoding var maxUintValue = constants_1.MaxUint256.mask(writer.wordSize * 8); if (this.signed) { var bounds = maxUintValue.mask(this.size * 8 - 1); if (v.gt(bounds) || v.lt(bounds.add(constants_1.One).mul(constants_1.NegativeOne))) { this._throwError("value out-of-bounds", value); } } else if (v.lt(constants_1.Zero) || v.gt(maxUintValue.mask(this.size * 8))) { this._throwError("value out-of-bounds", value); } v = v.toTwos(this.size * 8).mask(this.size * 8); if (this.signed) { v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize); } return writer.writeValue(v); }; NumberCoder.prototype.decode = function (reader) { var value = reader.readValue().mask(this.size * 8); if (this.signed) { value = value.fromTwos(this.size * 8); } return reader.coerce(this.name, value); }; return NumberCoder; }(abstract_coder_1.Coder)); exports.NumberCoder = NumberCoder; },{"./abstract-coder":3,"@ethersproject/bignumber":29,"@ethersproject/constants":35}],12:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.StringCoder = void 0; var strings_1 = require("@ethersproject/strings"); var bytes_1 = require("./bytes"); var StringCoder = /** @class */ (function (_super) { __extends(StringCoder, _super); function StringCoder(localName) { return _super.call(this, "string", localName) || this; } StringCoder.prototype.defaultValue = function () { return ""; }; StringCoder.prototype.encode = function (writer, value) { return _super.prototype.encode.call(this, writer, (0, strings_1.toUtf8Bytes)(value)); }; StringCoder.prototype.decode = function (reader) { return (0, strings_1.toUtf8String)(_super.prototype.decode.call(this, reader)); }; return StringCoder; }(bytes_1.DynamicBytesCoder)); exports.StringCoder = StringCoder; },{"./bytes":8,"@ethersproject/strings":102}],13:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.TupleCoder = void 0; var abstract_coder_1 = require("./abstract-coder"); var array_1 = require("./array"); var TupleCoder = /** @class */ (function (_super) { __extends(TupleCoder, _super); function TupleCoder(coders, localName) { var _this = this; var dynamic = false; var types = []; coders.forEach(function (coder) { if (coder.dynamic) { dynamic = true; } types.push(coder.type); }); var type = ("tuple(" + types.join(",") + ")"); _this = _super.call(this, "tuple", type, localName, dynamic) || this; _this.coders = coders; return _this; } TupleCoder.prototype.defaultValue = function () { var values = []; this.coders.forEach(function (coder) { values.push(coder.defaultValue()); }); // We only output named properties for uniquely named coders var uniqueNames = this.coders.reduce(function (accum, coder) { var name = coder.localName; if (name) { if (!accum[name]) { accum[name] = 0; } accum[name]++; } return accum; }, {}); // Add named values this.coders.forEach(function (coder, index) { var name = coder.localName; if (!name || uniqueNames[name] !== 1) { return; } if (name === "length") { name = "_length"; } if (values[name] != null) { return; } values[name] = values[index]; }); return Object.freeze(values); }; TupleCoder.prototype.encode = function (writer, value) { return (0, array_1.pack)(writer, this.coders, value); }; TupleCoder.prototype.decode = function (reader) { return reader.coerce(this.name, (0, array_1.unpack)(reader, this.coders)); }; return TupleCoder; }(abstract_coder_1.Coder)); exports.TupleCoder = TupleCoder; },{"./abstract-coder":3,"./array":6}],14:[function(require,module,exports){ "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorFragment = exports.FunctionFragment = exports.ConstructorFragment = exports.EventFragment = exports.Fragment = exports.ParamType = exports.FormatTypes = void 0; var bignumber_1 = require("@ethersproject/bignumber"); var properties_1 = require("@ethersproject/properties"); var logger_1 = require("@ethersproject/logger"); var _version_1 = require("./_version"); var logger = new logger_1.Logger(_version_1.version); ; var _constructorGuard = {}; var ModifiersBytes = { calldata: true, memory: true, storage: true }; var ModifiersNest = { calldata: true, memory: true }; function checkModifier(type, name) { if (type === "bytes" || type === "string") { if (ModifiersBytes[name]) { return true; } } else if (type === "address") { if (name === "payable") { return true; } } else if (type.indexOf("[") >= 0 || type === "tuple") { if (ModifiersNest[name]) { return true; } } if (ModifiersBytes[name] || name === "payable") { logger.throwArgumentError("invalid modifier", "name", name); } return false; } // @TODO: Make sure that children of an indexed tuple are marked with a null indexed function parseParamType(param, allowIndexed) { var originalParam = param; function throwError(i) { logger.throwArgumentError("unexpected character at position " + i, "param", param); } param = param.replace(/\s/g, " "); function newNode(parent) { var node = { type: "", name: "", parent: parent, state: { allowType: true } }; if (allowIndexed) { node.indexed = false; } return node; } var parent = { type: "", name: "", state: { allowType: true } }; var node = parent; for (var i = 0; i < param.length; i++) { var c = param[i]; switch (c) { case "(": if (node.state.allowType && node.type === "") { node.type = "tuple"; } else if (!node.state.allowParams) { throwError(i); } node.state.allowType = false; node.type = verifyType(node.type); node.components = [newNode(node)]; node = node.components[0]; break; case ")": delete node.state; if (node.name === "indexed") { if (!allowIndexed) { throwError(i); } node.indexed = true; node.name = ""; } if (checkModifier(node.type, node.name)) { node.name = ""; } node.type = verifyType(node.type); var child = node; node = node.parent; if (!node) { throwError(i); } delete child.parent; node.state.allowParams = false; node.state.allowName = true; node.state.allowArray = true; break; case ",": delete node.state; if (node.name === "indexed") { if (!allowIndexed) { throwError(i); } node.indexed = true; node.name = ""; } if (checkModifier(node.type, node.name)) { node.name = ""; } node.type = verifyType(node.type); var sibling = newNode(node.parent); //{ type: "", name: "", parent: node.parent, state: { allowType: true } }; node.parent.components.push(sibling); delete node.parent; node = sibling; break; // Hit a space... case " ": // If reading type, the type is done and may read a param or name if (node.state.allowType) { if (node.type !== "") { node.type = verifyType(node.type); delete node.state.allowType; node.state.allowName = true; node.state.allowParams = true; } } // If reading name, the name is done if (node.state.allowName) { if (node.name !== "") { if (node.name === "indexed") { if (!allowIndexed) { throwError(i); } if (node.indexed) { throwError(i); } node.indexed = true; node.name = ""; } else if (checkModifier(node.type, node.name)) { node.name = ""; } else { node.state.allowName = false; } } } break; case "[": if (!node.state.allowArray) { throwError(i); } node.type += c; node.state.allowArray = false; node.state.allowName = false; node.state.readArray = true; break; case "]": if (!node.state.readArray) { throwError(i); } node.type += c; node.state.readArray = false; node.state.allowArray = true; node.state.allowName = true; break; default: if (node.state.allowType) { node.type += c; node.state.allowParams = true; node.state.allowArray = true; } else if (node.state.allowName) { node.name += c; delete node.state.allowArray; } else if (node.state.readArray) { node.type += c; } else { throwError(i); } } } if (node.parent) { logger.throwArgumentError("unexpected eof", "param", param); } delete parent.state; if (node.name === "indexed") { if (!allowIndexed) { throwError(originalParam.length - 7); } if (node.indexed) { throwError(originalParam.length - 7); } node.indexed = true; node.name = ""; } else if (checkModifier(node.type, node.name)) { node.name = ""; } parent.type = verifyType(parent.type); return parent; } function populate(object, params) { for (var key in params) { (0, properties_1.defineReadOnly)(object, key, params[key]); } } exports.FormatTypes = Object.freeze({ // Bare formatting, as is needed for computing a sighash of an event or function sighash: "sighash", // Human-Readable with Minimal spacing and without names (compact human-readable) minimal: "minimal", // Human-Readable with nice spacing, including all names full: "full", // JSON-format a la Solidity json: "json" }); var paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/); var ParamType = /** @class */ (function () { function ParamType(constructorGuard, params) { if (constructorGuard !== _constructorGuard) { logger.throwError("use fromString", logger_1.Logger.errors.UNSUPPORTED_OPERATION, { operation: "new ParamType()" }); } populate(this, params); var match = this.type.match(paramTypeArray); if (match) { populate(this, { arrayLength: parseInt(match[2] || "-1"), arrayChildren: ParamType.fromObject({ type: match[1],