"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.EventTradingRewardDistribution = exports.EventTradingRewardCampaignUpdate = exports.EventSubaccountWithdraw = exports.EventSubaccountDeposit = exports.EventSubaccountBalanceTransfer = exports.EventSpotMarketUpdate = exports.EventPerpetualMarketUpdate = exports.EventPerpetualMarketFundingUpdate = exports.EventOrderFail = exports.EventNewSpotOrders = exports.EventNewDerivativeOrders = exports.EventNewConditionalDerivativeOrder = exports.EventLostFundsFromLiquidation = exports.EventFeeDiscountSchedule = exports.EventExpiryFuturesMarketUpdate = exports.EventDerivativeMarketPaused = exports.EventConditionalDerivativeOrderTrigger = exports.EventCancelSpotOrder = exports.EventCancelDerivativeOrder = exports.EventCancelConditionalDerivativeOrder = exports.EventBinaryOptionsMarketUpdate = exports.EventBatchSpotExecution = exports.EventBatchDerivativePosition = exports.EventBatchDerivativeExecution = exports.EventBatchDepositUpdate = exports.DerivativeMarketOrderCancel = void 0;
var _exchange = require("./exchange");
var _coin = require("../../../cosmos/base/v1beta1/coin");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
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 createBaseEventBatchSpotExecution() {
  return {
    marketId: "",
    isBuy: false,
    executionType: 0,
    trades: []
  };
}
var EventBatchSpotExecution = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isBuy === true) {
      writer.uint32(16).bool(message.isBuy);
    }
    if (message.executionType !== 0) {
      writer.uint32(24).int32(message.executionType);
    }
    var _iterator = _createForOfIteratorHelper(message.trades),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _exchange.TradeLog.encode(v, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventBatchSpotExecution();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isBuy = reader.bool();
          break;
        case 3:
          message.executionType = reader.int32();
          break;
        case 4:
          message.trades.push(_exchange.TradeLog.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId, _object$isBuy, _object$executionType, _object$trades;
    var message = createBaseEventBatchSpotExecution();
    message.marketId = (_object$marketId = object.marketId) !== null && _object$marketId !== void 0 ? _object$marketId : "";
    message.isBuy = (_object$isBuy = object.isBuy) !== null && _object$isBuy !== void 0 ? _object$isBuy : false;
    message.executionType = (_object$executionType = object.executionType) !== null && _object$executionType !== void 0 ? _object$executionType : 0;
    message.trades = ((_object$trades = object.trades) === null || _object$trades === void 0 ? void 0 : _object$trades.map(function (e) {
      return _exchange.TradeLog.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventBatchSpotExecution = EventBatchSpotExecution;
function createBaseEventBatchDerivativeExecution() {
  return {
    marketId: "",
    isBuy: false,
    isLiquidation: false,
    cumulativeFunding: undefined,
    executionType: 0,
    trades: []
  };
}
var EventBatchDerivativeExecution = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isBuy === true) {
      writer.uint32(16).bool(message.isBuy);
    }
    if (message.isLiquidation === true) {
      writer.uint32(24).bool(message.isLiquidation);
    }
    if (message.cumulativeFunding !== undefined) {
      writer.uint32(34).string(message.cumulativeFunding);
    }
    if (message.executionType !== 0) {
      writer.uint32(40).int32(message.executionType);
    }
    var _iterator2 = _createForOfIteratorHelper(message.trades),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var v = _step2.value;
        _exchange.DerivativeTradeLog.encode(v, writer.uint32(50).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventBatchDerivativeExecution();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isBuy = reader.bool();
          break;
        case 3:
          message.isLiquidation = reader.bool();
          break;
        case 4:
          message.cumulativeFunding = reader.string();
          break;
        case 5:
          message.executionType = reader.int32();
          break;
        case 6:
          message.trades.push(_exchange.DerivativeTradeLog.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId2, _object$isBuy2, _object$isLiquidation, _object$cumulativeFun, _object$executionType2, _object$trades2;
    var message = createBaseEventBatchDerivativeExecution();
    message.marketId = (_object$marketId2 = object.marketId) !== null && _object$marketId2 !== void 0 ? _object$marketId2 : "";
    message.isBuy = (_object$isBuy2 = object.isBuy) !== null && _object$isBuy2 !== void 0 ? _object$isBuy2 : false;
    message.isLiquidation = (_object$isLiquidation = object.isLiquidation) !== null && _object$isLiquidation !== void 0 ? _object$isLiquidation : false;
    message.cumulativeFunding = (_object$cumulativeFun = object.cumulativeFunding) !== null && _object$cumulativeFun !== void 0 ? _object$cumulativeFun : undefined;
    message.executionType = (_object$executionType2 = object.executionType) !== null && _object$executionType2 !== void 0 ? _object$executionType2 : 0;
    message.trades = ((_object$trades2 = object.trades) === null || _object$trades2 === void 0 ? void 0 : _object$trades2.map(function (e) {
      return _exchange.DerivativeTradeLog.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventBatchDerivativeExecution = EventBatchDerivativeExecution;
function createBaseEventLostFundsFromLiquidation() {
  return {
    marketId: "",
    subaccountId: new Uint8Array(),
    lostFundsFromAvailableDuringPayout: "",
    lostFundsFromOrderCancels: ""
  };
}
var EventLostFundsFromLiquidation = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.subaccountId.length !== 0) {
      writer.uint32(18).bytes(message.subaccountId);
    }
    if (message.lostFundsFromAvailableDuringPayout !== "") {
      writer.uint32(26).string(message.lostFundsFromAvailableDuringPayout);
    }
    if (message.lostFundsFromOrderCancels !== "") {
      writer.uint32(34).string(message.lostFundsFromOrderCancels);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventLostFundsFromLiquidation();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.subaccountId = reader.bytes();
          break;
        case 3:
          message.lostFundsFromAvailableDuringPayout = reader.string();
          break;
        case 4:
          message.lostFundsFromOrderCancels = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId3, _object$subaccountId, _object$lostFundsFrom, _object$lostFundsFrom2;
    var message = createBaseEventLostFundsFromLiquidation();
    message.marketId = (_object$marketId3 = object.marketId) !== null && _object$marketId3 !== void 0 ? _object$marketId3 : "";
    message.subaccountId = (_object$subaccountId = object.subaccountId) !== null && _object$subaccountId !== void 0 ? _object$subaccountId : new Uint8Array();
    message.lostFundsFromAvailableDuringPayout = (_object$lostFundsFrom = object.lostFundsFromAvailableDuringPayout) !== null && _object$lostFundsFrom !== void 0 ? _object$lostFundsFrom : "";
    message.lostFundsFromOrderCancels = (_object$lostFundsFrom2 = object.lostFundsFromOrderCancels) !== null && _object$lostFundsFrom2 !== void 0 ? _object$lostFundsFrom2 : "";
    return message;
  }
};
exports.EventLostFundsFromLiquidation = EventLostFundsFromLiquidation;
function createBaseEventBatchDerivativePosition() {
  return {
    marketId: "",
    positions: []
  };
}
var EventBatchDerivativePosition = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    var _iterator3 = _createForOfIteratorHelper(message.positions),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var v = _step3.value;
        _exchange.SubaccountPosition.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventBatchDerivativePosition();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.positions.push(_exchange.SubaccountPosition.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId4, _object$positions;
    var message = createBaseEventBatchDerivativePosition();
    message.marketId = (_object$marketId4 = object.marketId) !== null && _object$marketId4 !== void 0 ? _object$marketId4 : "";
    message.positions = ((_object$positions = object.positions) === null || _object$positions === void 0 ? void 0 : _object$positions.map(function (e) {
      return _exchange.SubaccountPosition.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventBatchDerivativePosition = EventBatchDerivativePosition;
function createBaseEventDerivativeMarketPaused() {
  return {
    marketId: "",
    settlePrice: "",
    totalMissingFunds: "",
    missingFundsRate: ""
  };
}
var EventDerivativeMarketPaused = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.settlePrice !== "") {
      writer.uint32(18).string(message.settlePrice);
    }
    if (message.totalMissingFunds !== "") {
      writer.uint32(26).string(message.totalMissingFunds);
    }
    if (message.missingFundsRate !== "") {
      writer.uint32(34).string(message.missingFundsRate);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventDerivativeMarketPaused();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.settlePrice = reader.string();
          break;
        case 3:
          message.totalMissingFunds = reader.string();
          break;
        case 4:
          message.missingFundsRate = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId5, _object$settlePrice, _object$totalMissingF, _object$missingFundsR;
    var message = createBaseEventDerivativeMarketPaused();
    message.marketId = (_object$marketId5 = object.marketId) !== null && _object$marketId5 !== void 0 ? _object$marketId5 : "";
    message.settlePrice = (_object$settlePrice = object.settlePrice) !== null && _object$settlePrice !== void 0 ? _object$settlePrice : "";
    message.totalMissingFunds = (_object$totalMissingF = object.totalMissingFunds) !== null && _object$totalMissingF !== void 0 ? _object$totalMissingF : "";
    message.missingFundsRate = (_object$missingFundsR = object.missingFundsRate) !== null && _object$missingFundsR !== void 0 ? _object$missingFundsR : "";
    return message;
  }
};
exports.EventDerivativeMarketPaused = EventDerivativeMarketPaused;
function createBaseEventBinaryOptionsMarketUpdate() {
  return {
    market: undefined
  };
}
var EventBinaryOptionsMarketUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.market !== undefined) {
      _exchange.BinaryOptionsMarket.encode(message.market, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventBinaryOptionsMarketUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.market = _exchange.BinaryOptionsMarket.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseEventBinaryOptionsMarketUpdate();
    message.market = object.market !== undefined && object.market !== null ? _exchange.BinaryOptionsMarket.fromPartial(object.market) : undefined;
    return message;
  }
};
exports.EventBinaryOptionsMarketUpdate = EventBinaryOptionsMarketUpdate;
function createBaseEventNewSpotOrders() {
  return {
    marketId: "",
    buyOrders: [],
    sellOrders: []
  };
}
var EventNewSpotOrders = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    var _iterator4 = _createForOfIteratorHelper(message.buyOrders),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var v = _step4.value;
        _exchange.SpotLimitOrder.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.sellOrders),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v = _step5.value;
        _exchange.SpotLimitOrder.encode(_v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventNewSpotOrders();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.buyOrders.push(_exchange.SpotLimitOrder.decode(reader, reader.uint32()));
          break;
        case 3:
          message.sellOrders.push(_exchange.SpotLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId6, _object$buyOrders, _object$sellOrders;
    var message = createBaseEventNewSpotOrders();
    message.marketId = (_object$marketId6 = object.marketId) !== null && _object$marketId6 !== void 0 ? _object$marketId6 : "";
    message.buyOrders = ((_object$buyOrders = object.buyOrders) === null || _object$buyOrders === void 0 ? void 0 : _object$buyOrders.map(function (e) {
      return _exchange.SpotLimitOrder.fromPartial(e);
    })) || [];
    message.sellOrders = ((_object$sellOrders = object.sellOrders) === null || _object$sellOrders === void 0 ? void 0 : _object$sellOrders.map(function (e) {
      return _exchange.SpotLimitOrder.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventNewSpotOrders = EventNewSpotOrders;
function createBaseEventNewDerivativeOrders() {
  return {
    marketId: "",
    buyOrders: [],
    sellOrders: []
  };
}
var EventNewDerivativeOrders = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    var _iterator6 = _createForOfIteratorHelper(message.buyOrders),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var v = _step6.value;
        _exchange.DerivativeLimitOrder.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    var _iterator7 = _createForOfIteratorHelper(message.sellOrders),
      _step7;
    try {
      for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
        var _v2 = _step7.value;
        _exchange.DerivativeLimitOrder.encode(_v2, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator7.e(err);
    } finally {
      _iterator7.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventNewDerivativeOrders();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.buyOrders.push(_exchange.DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        case 3:
          message.sellOrders.push(_exchange.DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId7, _object$buyOrders2, _object$sellOrders2;
    var message = createBaseEventNewDerivativeOrders();
    message.marketId = (_object$marketId7 = object.marketId) !== null && _object$marketId7 !== void 0 ? _object$marketId7 : "";
    message.buyOrders = ((_object$buyOrders2 = object.buyOrders) === null || _object$buyOrders2 === void 0 ? void 0 : _object$buyOrders2.map(function (e) {
      return _exchange.DerivativeLimitOrder.fromPartial(e);
    })) || [];
    message.sellOrders = ((_object$sellOrders2 = object.sellOrders) === null || _object$sellOrders2 === void 0 ? void 0 : _object$sellOrders2.map(function (e) {
      return _exchange.DerivativeLimitOrder.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventNewDerivativeOrders = EventNewDerivativeOrders;
function createBaseEventCancelSpotOrder() {
  return {
    marketId: "",
    order: undefined
  };
}
var EventCancelSpotOrder = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.order !== undefined) {
      _exchange.SpotLimitOrder.encode(message.order, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventCancelSpotOrder();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.order = _exchange.SpotLimitOrder.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId8;
    var message = createBaseEventCancelSpotOrder();
    message.marketId = (_object$marketId8 = object.marketId) !== null && _object$marketId8 !== void 0 ? _object$marketId8 : "";
    message.order = object.order !== undefined && object.order !== null ? _exchange.SpotLimitOrder.fromPartial(object.order) : undefined;
    return message;
  }
};
exports.EventCancelSpotOrder = EventCancelSpotOrder;
function createBaseEventSpotMarketUpdate() {
  return {
    market: undefined
  };
}
var EventSpotMarketUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.market !== undefined) {
      _exchange.SpotMarket.encode(message.market, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventSpotMarketUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.market = _exchange.SpotMarket.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseEventSpotMarketUpdate();
    message.market = object.market !== undefined && object.market !== null ? _exchange.SpotMarket.fromPartial(object.market) : undefined;
    return message;
  }
};
exports.EventSpotMarketUpdate = EventSpotMarketUpdate;
function createBaseEventPerpetualMarketUpdate() {
  return {
    market: undefined,
    perpetualMarketInfo: undefined,
    funding: undefined
  };
}
var EventPerpetualMarketUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.market !== undefined) {
      _exchange.DerivativeMarket.encode(message.market, writer.uint32(10).fork()).ldelim();
    }
    if (message.perpetualMarketInfo !== undefined) {
      _exchange.PerpetualMarketInfo.encode(message.perpetualMarketInfo, writer.uint32(18).fork()).ldelim();
    }
    if (message.funding !== undefined) {
      _exchange.PerpetualMarketFunding.encode(message.funding, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventPerpetualMarketUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.market = _exchange.DerivativeMarket.decode(reader, reader.uint32());
          break;
        case 2:
          message.perpetualMarketInfo = _exchange.PerpetualMarketInfo.decode(reader, reader.uint32());
          break;
        case 3:
          message.funding = _exchange.PerpetualMarketFunding.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseEventPerpetualMarketUpdate();
    message.market = object.market !== undefined && object.market !== null ? _exchange.DerivativeMarket.fromPartial(object.market) : undefined;
    message.perpetualMarketInfo = object.perpetualMarketInfo !== undefined && object.perpetualMarketInfo !== null ? _exchange.PerpetualMarketInfo.fromPartial(object.perpetualMarketInfo) : undefined;
    message.funding = object.funding !== undefined && object.funding !== null ? _exchange.PerpetualMarketFunding.fromPartial(object.funding) : undefined;
    return message;
  }
};
exports.EventPerpetualMarketUpdate = EventPerpetualMarketUpdate;
function createBaseEventExpiryFuturesMarketUpdate() {
  return {
    market: undefined,
    expiryFuturesMarketInfo: undefined
  };
}
var EventExpiryFuturesMarketUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.market !== undefined) {
      _exchange.DerivativeMarket.encode(message.market, writer.uint32(10).fork()).ldelim();
    }
    if (message.expiryFuturesMarketInfo !== undefined) {
      _exchange.ExpiryFuturesMarketInfo.encode(message.expiryFuturesMarketInfo, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventExpiryFuturesMarketUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.market = _exchange.DerivativeMarket.decode(reader, reader.uint32());
          break;
        case 3:
          message.expiryFuturesMarketInfo = _exchange.ExpiryFuturesMarketInfo.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseEventExpiryFuturesMarketUpdate();
    message.market = object.market !== undefined && object.market !== null ? _exchange.DerivativeMarket.fromPartial(object.market) : undefined;
    message.expiryFuturesMarketInfo = object.expiryFuturesMarketInfo !== undefined && object.expiryFuturesMarketInfo !== null ? _exchange.ExpiryFuturesMarketInfo.fromPartial(object.expiryFuturesMarketInfo) : undefined;
    return message;
  }
};
exports.EventExpiryFuturesMarketUpdate = EventExpiryFuturesMarketUpdate;
function createBaseEventPerpetualMarketFundingUpdate() {
  return {
    marketId: "",
    funding: undefined,
    isHourlyFunding: false,
    fundingRate: undefined,
    markPrice: undefined
  };
}
var EventPerpetualMarketFundingUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.funding !== undefined) {
      _exchange.PerpetualMarketFunding.encode(message.funding, writer.uint32(18).fork()).ldelim();
    }
    if (message.isHourlyFunding === true) {
      writer.uint32(24).bool(message.isHourlyFunding);
    }
    if (message.fundingRate !== undefined) {
      writer.uint32(34).string(message.fundingRate);
    }
    if (message.markPrice !== undefined) {
      writer.uint32(42).string(message.markPrice);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventPerpetualMarketFundingUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.funding = _exchange.PerpetualMarketFunding.decode(reader, reader.uint32());
          break;
        case 3:
          message.isHourlyFunding = reader.bool();
          break;
        case 4:
          message.fundingRate = reader.string();
          break;
        case 5:
          message.markPrice = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId9, _object$isHourlyFundi, _object$fundingRate, _object$markPrice;
    var message = createBaseEventPerpetualMarketFundingUpdate();
    message.marketId = (_object$marketId9 = object.marketId) !== null && _object$marketId9 !== void 0 ? _object$marketId9 : "";
    message.funding = object.funding !== undefined && object.funding !== null ? _exchange.PerpetualMarketFunding.fromPartial(object.funding) : undefined;
    message.isHourlyFunding = (_object$isHourlyFundi = object.isHourlyFunding) !== null && _object$isHourlyFundi !== void 0 ? _object$isHourlyFundi : false;
    message.fundingRate = (_object$fundingRate = object.fundingRate) !== null && _object$fundingRate !== void 0 ? _object$fundingRate : undefined;
    message.markPrice = (_object$markPrice = object.markPrice) !== null && _object$markPrice !== void 0 ? _object$markPrice : undefined;
    return message;
  }
};
exports.EventPerpetualMarketFundingUpdate = EventPerpetualMarketFundingUpdate;
function createBaseEventSubaccountDeposit() {
  return {
    srcAddress: "",
    subaccountId: new Uint8Array(),
    amount: undefined
  };
}
var EventSubaccountDeposit = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.srcAddress !== "") {
      writer.uint32(10).string(message.srcAddress);
    }
    if (message.subaccountId.length !== 0) {
      writer.uint32(18).bytes(message.subaccountId);
    }
    if (message.amount !== undefined) {
      _coin.Coin.encode(message.amount, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventSubaccountDeposit();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.srcAddress = reader.string();
          break;
        case 2:
          message.subaccountId = reader.bytes();
          break;
        case 3:
          message.amount = _coin.Coin.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$srcAddress, _object$subaccountId2;
    var message = createBaseEventSubaccountDeposit();
    message.srcAddress = (_object$srcAddress = object.srcAddress) !== null && _object$srcAddress !== void 0 ? _object$srcAddress : "";
    message.subaccountId = (_object$subaccountId2 = object.subaccountId) !== null && _object$subaccountId2 !== void 0 ? _object$subaccountId2 : new Uint8Array();
    message.amount = object.amount !== undefined && object.amount !== null ? _coin.Coin.fromPartial(object.amount) : undefined;
    return message;
  }
};
exports.EventSubaccountDeposit = EventSubaccountDeposit;
function createBaseEventSubaccountWithdraw() {
  return {
    subaccountId: new Uint8Array(),
    dstAddress: "",
    amount: undefined
  };
}
var EventSubaccountWithdraw = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.subaccountId.length !== 0) {
      writer.uint32(10).bytes(message.subaccountId);
    }
    if (message.dstAddress !== "") {
      writer.uint32(18).string(message.dstAddress);
    }
    if (message.amount !== undefined) {
      _coin.Coin.encode(message.amount, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventSubaccountWithdraw();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.bytes();
          break;
        case 2:
          message.dstAddress = reader.string();
          break;
        case 3:
          message.amount = _coin.Coin.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$subaccountId3, _object$dstAddress;
    var message = createBaseEventSubaccountWithdraw();
    message.subaccountId = (_object$subaccountId3 = object.subaccountId) !== null && _object$subaccountId3 !== void 0 ? _object$subaccountId3 : new Uint8Array();
    message.dstAddress = (_object$dstAddress = object.dstAddress) !== null && _object$dstAddress !== void 0 ? _object$dstAddress : "";
    message.amount = object.amount !== undefined && object.amount !== null ? _coin.Coin.fromPartial(object.amount) : undefined;
    return message;
  }
};
exports.EventSubaccountWithdraw = EventSubaccountWithdraw;
function createBaseEventSubaccountBalanceTransfer() {
  return {
    srcSubaccountId: "",
    dstSubaccountId: "",
    amount: undefined
  };
}
var EventSubaccountBalanceTransfer = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.srcSubaccountId !== "") {
      writer.uint32(10).string(message.srcSubaccountId);
    }
    if (message.dstSubaccountId !== "") {
      writer.uint32(18).string(message.dstSubaccountId);
    }
    if (message.amount !== undefined) {
      _coin.Coin.encode(message.amount, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventSubaccountBalanceTransfer();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.srcSubaccountId = reader.string();
          break;
        case 2:
          message.dstSubaccountId = reader.string();
          break;
        case 3:
          message.amount = _coin.Coin.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$srcSubaccount, _object$dstSubaccount;
    var message = createBaseEventSubaccountBalanceTransfer();
    message.srcSubaccountId = (_object$srcSubaccount = object.srcSubaccountId) !== null && _object$srcSubaccount !== void 0 ? _object$srcSubaccount : "";
    message.dstSubaccountId = (_object$dstSubaccount = object.dstSubaccountId) !== null && _object$dstSubaccount !== void 0 ? _object$dstSubaccount : "";
    message.amount = object.amount !== undefined && object.amount !== null ? _coin.Coin.fromPartial(object.amount) : undefined;
    return message;
  }
};
exports.EventSubaccountBalanceTransfer = EventSubaccountBalanceTransfer;
function createBaseEventBatchDepositUpdate() {
  return {
    depositUpdates: []
  };
}
var EventBatchDepositUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    var _iterator8 = _createForOfIteratorHelper(message.depositUpdates),
      _step8;
    try {
      for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
        var v = _step8.value;
        _exchange.DepositUpdate.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator8.e(err);
    } finally {
      _iterator8.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventBatchDepositUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.depositUpdates.push(_exchange.DepositUpdate.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$depositUpdate;
    var message = createBaseEventBatchDepositUpdate();
    message.depositUpdates = ((_object$depositUpdate = object.depositUpdates) === null || _object$depositUpdate === void 0 ? void 0 : _object$depositUpdate.map(function (e) {
      return _exchange.DepositUpdate.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventBatchDepositUpdate = EventBatchDepositUpdate;
function createBaseDerivativeMarketOrderCancel() {
  return {
    marketOrder: undefined,
    cancelQuantity: ""
  };
}
var DerivativeMarketOrderCancel = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketOrder !== undefined) {
      _exchange.DerivativeMarketOrder.encode(message.marketOrder, writer.uint32(10).fork()).ldelim();
    }
    if (message.cancelQuantity !== "") {
      writer.uint32(18).string(message.cancelQuantity);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseDerivativeMarketOrderCancel();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketOrder = _exchange.DerivativeMarketOrder.decode(reader, reader.uint32());
          break;
        case 2:
          message.cancelQuantity = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$cancelQuantit;
    var message = createBaseDerivativeMarketOrderCancel();
    message.marketOrder = object.marketOrder !== undefined && object.marketOrder !== null ? _exchange.DerivativeMarketOrder.fromPartial(object.marketOrder) : undefined;
    message.cancelQuantity = (_object$cancelQuantit = object.cancelQuantity) !== null && _object$cancelQuantit !== void 0 ? _object$cancelQuantit : "";
    return message;
  }
};
exports.DerivativeMarketOrderCancel = DerivativeMarketOrderCancel;
function createBaseEventCancelDerivativeOrder() {
  return {
    marketId: "",
    isLimitCancel: false,
    limitOrder: undefined,
    marketOrderCancel: undefined
  };
}
var EventCancelDerivativeOrder = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isLimitCancel === true) {
      writer.uint32(16).bool(message.isLimitCancel);
    }
    if (message.limitOrder !== undefined) {
      _exchange.DerivativeLimitOrder.encode(message.limitOrder, writer.uint32(26).fork()).ldelim();
    }
    if (message.marketOrderCancel !== undefined) {
      DerivativeMarketOrderCancel.encode(message.marketOrderCancel, writer.uint32(34).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventCancelDerivativeOrder();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isLimitCancel = reader.bool();
          break;
        case 3:
          message.limitOrder = _exchange.DerivativeLimitOrder.decode(reader, reader.uint32());
          break;
        case 4:
          message.marketOrderCancel = DerivativeMarketOrderCancel.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId10, _object$isLimitCancel;
    var message = createBaseEventCancelDerivativeOrder();
    message.marketId = (_object$marketId10 = object.marketId) !== null && _object$marketId10 !== void 0 ? _object$marketId10 : "";
    message.isLimitCancel = (_object$isLimitCancel = object.isLimitCancel) !== null && _object$isLimitCancel !== void 0 ? _object$isLimitCancel : false;
    message.limitOrder = object.limitOrder !== undefined && object.limitOrder !== null ? _exchange.DerivativeLimitOrder.fromPartial(object.limitOrder) : undefined;
    message.marketOrderCancel = object.marketOrderCancel !== undefined && object.marketOrderCancel !== null ? DerivativeMarketOrderCancel.fromPartial(object.marketOrderCancel) : undefined;
    return message;
  }
};
exports.EventCancelDerivativeOrder = EventCancelDerivativeOrder;
function createBaseEventFeeDiscountSchedule() {
  return {
    schedule: undefined
  };
}
var EventFeeDiscountSchedule = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.schedule !== undefined) {
      _exchange.FeeDiscountSchedule.encode(message.schedule, writer.uint32(10).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventFeeDiscountSchedule();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.schedule = _exchange.FeeDiscountSchedule.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var message = createBaseEventFeeDiscountSchedule();
    message.schedule = object.schedule !== undefined && object.schedule !== null ? _exchange.FeeDiscountSchedule.fromPartial(object.schedule) : undefined;
    return message;
  }
};
exports.EventFeeDiscountSchedule = EventFeeDiscountSchedule;
function createBaseEventTradingRewardCampaignUpdate() {
  return {
    campaignInfo: undefined,
    campaignRewardPools: []
  };
}
var EventTradingRewardCampaignUpdate = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.campaignInfo !== undefined) {
      _exchange.TradingRewardCampaignInfo.encode(message.campaignInfo, writer.uint32(10).fork()).ldelim();
    }
    var _iterator9 = _createForOfIteratorHelper(message.campaignRewardPools),
      _step9;
    try {
      for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
        var v = _step9.value;
        _exchange.CampaignRewardPool.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator9.e(err);
    } finally {
      _iterator9.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventTradingRewardCampaignUpdate();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.campaignInfo = _exchange.TradingRewardCampaignInfo.decode(reader, reader.uint32());
          break;
        case 2:
          message.campaignRewardPools.push(_exchange.CampaignRewardPool.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$campaignRewar;
    var message = createBaseEventTradingRewardCampaignUpdate();
    message.campaignInfo = object.campaignInfo !== undefined && object.campaignInfo !== null ? _exchange.TradingRewardCampaignInfo.fromPartial(object.campaignInfo) : undefined;
    message.campaignRewardPools = ((_object$campaignRewar = object.campaignRewardPools) === null || _object$campaignRewar === void 0 ? void 0 : _object$campaignRewar.map(function (e) {
      return _exchange.CampaignRewardPool.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventTradingRewardCampaignUpdate = EventTradingRewardCampaignUpdate;
function createBaseEventTradingRewardDistribution() {
  return {
    accountRewards: []
  };
}
var EventTradingRewardDistribution = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    var _iterator10 = _createForOfIteratorHelper(message.accountRewards),
      _step10;
    try {
      for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
        var v = _step10.value;
        _exchange.AccountRewards.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator10.e(err);
    } finally {
      _iterator10.f();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventTradingRewardDistribution();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.accountRewards.push(_exchange.AccountRewards.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$accountReward;
    var message = createBaseEventTradingRewardDistribution();
    message.accountRewards = ((_object$accountReward = object.accountRewards) === null || _object$accountReward === void 0 ? void 0 : _object$accountReward.map(function (e) {
      return _exchange.AccountRewards.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.EventTradingRewardDistribution = EventTradingRewardDistribution;
function createBaseEventNewConditionalDerivativeOrder() {
  return {
    marketId: "",
    order: undefined,
    hash: new Uint8Array(),
    isMarket: false
  };
}
var EventNewConditionalDerivativeOrder = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.order !== undefined) {
      _exchange.DerivativeOrder.encode(message.order, writer.uint32(18).fork()).ldelim();
    }
    if (message.hash.length !== 0) {
      writer.uint32(26).bytes(message.hash);
    }
    if (message.isMarket === true) {
      writer.uint32(32).bool(message.isMarket);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventNewConditionalDerivativeOrder();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.order = _exchange.DerivativeOrder.decode(reader, reader.uint32());
          break;
        case 3:
          message.hash = reader.bytes();
          break;
        case 4:
          message.isMarket = reader.bool();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId11, _object$hash, _object$isMarket;
    var message = createBaseEventNewConditionalDerivativeOrder();
    message.marketId = (_object$marketId11 = object.marketId) !== null && _object$marketId11 !== void 0 ? _object$marketId11 : "";
    message.order = object.order !== undefined && object.order !== null ? _exchange.DerivativeOrder.fromPartial(object.order) : undefined;
    message.hash = (_object$hash = object.hash) !== null && _object$hash !== void 0 ? _object$hash : new Uint8Array();
    message.isMarket = (_object$isMarket = object.isMarket) !== null && _object$isMarket !== void 0 ? _object$isMarket : false;
    return message;
  }
};
exports.EventNewConditionalDerivativeOrder = EventNewConditionalDerivativeOrder;
function createBaseEventCancelConditionalDerivativeOrder() {
  return {
    marketId: "",
    isLimitCancel: false,
    limitOrder: undefined,
    marketOrder: undefined
  };
}
var EventCancelConditionalDerivativeOrder = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isLimitCancel === true) {
      writer.uint32(16).bool(message.isLimitCancel);
    }
    if (message.limitOrder !== undefined) {
      _exchange.DerivativeLimitOrder.encode(message.limitOrder, writer.uint32(26).fork()).ldelim();
    }
    if (message.marketOrder !== undefined) {
      _exchange.DerivativeMarketOrder.encode(message.marketOrder, writer.uint32(34).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventCancelConditionalDerivativeOrder();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isLimitCancel = reader.bool();
          break;
        case 3:
          message.limitOrder = _exchange.DerivativeLimitOrder.decode(reader, reader.uint32());
          break;
        case 4:
          message.marketOrder = _exchange.DerivativeMarketOrder.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId12, _object$isLimitCancel2;
    var message = createBaseEventCancelConditionalDerivativeOrder();
    message.marketId = (_object$marketId12 = object.marketId) !== null && _object$marketId12 !== void 0 ? _object$marketId12 : "";
    message.isLimitCancel = (_object$isLimitCancel2 = object.isLimitCancel) !== null && _object$isLimitCancel2 !== void 0 ? _object$isLimitCancel2 : false;
    message.limitOrder = object.limitOrder !== undefined && object.limitOrder !== null ? _exchange.DerivativeLimitOrder.fromPartial(object.limitOrder) : undefined;
    message.marketOrder = object.marketOrder !== undefined && object.marketOrder !== null ? _exchange.DerivativeMarketOrder.fromPartial(object.marketOrder) : undefined;
    return message;
  }
};
exports.EventCancelConditionalDerivativeOrder = EventCancelConditionalDerivativeOrder;
function createBaseEventConditionalDerivativeOrderTrigger() {
  return {
    marketId: new Uint8Array(),
    isLimitTrigger: false,
    triggeredOrderHash: new Uint8Array(),
    placedOrderHash: new Uint8Array()
  };
}
var EventConditionalDerivativeOrderTrigger = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.marketId.length !== 0) {
      writer.uint32(10).bytes(message.marketId);
    }
    if (message.isLimitTrigger === true) {
      writer.uint32(16).bool(message.isLimitTrigger);
    }
    if (message.triggeredOrderHash.length !== 0) {
      writer.uint32(26).bytes(message.triggeredOrderHash);
    }
    if (message.placedOrderHash.length !== 0) {
      writer.uint32(34).bytes(message.placedOrderHash);
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventConditionalDerivativeOrderTrigger();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.bytes();
          break;
        case 2:
          message.isLimitTrigger = reader.bool();
          break;
        case 3:
          message.triggeredOrderHash = reader.bytes();
          break;
        case 4:
          message.placedOrderHash = reader.bytes();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId13, _object$isLimitTrigge, _object$triggeredOrde, _object$placedOrderHa;
    var message = createBaseEventConditionalDerivativeOrderTrigger();
    message.marketId = (_object$marketId13 = object.marketId) !== null && _object$marketId13 !== void 0 ? _object$marketId13 : new Uint8Array();
    message.isLimitTrigger = (_object$isLimitTrigge = object.isLimitTrigger) !== null && _object$isLimitTrigge !== void 0 ? _object$isLimitTrigge : false;
    message.triggeredOrderHash = (_object$triggeredOrde = object.triggeredOrderHash) !== null && _object$triggeredOrde !== void 0 ? _object$triggeredOrde : new Uint8Array();
    message.placedOrderHash = (_object$placedOrderHa = object.placedOrderHash) !== null && _object$placedOrderHa !== void 0 ? _object$placedOrderHa : new Uint8Array();
    return message;
  }
};
exports.EventConditionalDerivativeOrderTrigger = EventConditionalDerivativeOrderTrigger;
function createBaseEventOrderFail() {
  return {
    account: new Uint8Array(),
    hashes: [],
    flags: []
  };
}
var EventOrderFail = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.account.length !== 0) {
      writer.uint32(10).bytes(message.account);
    }
    var _iterator11 = _createForOfIteratorHelper(message.hashes),
      _step11;
    try {
      for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
        var v = _step11.value;
        writer.uint32(18).bytes(v);
      }
    } catch (err) {
      _iterator11.e(err);
    } finally {
      _iterator11.f();
    }
    writer.uint32(26).fork();
    var _iterator12 = _createForOfIteratorHelper(message.flags),
      _step12;
    try {
      for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
        var _v3 = _step12.value;
        writer.uint32(_v3);
      }
    } catch (err) {
      _iterator12.e(err);
    } finally {
      _iterator12.f();
    }
    writer.ldelim();
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseEventOrderFail();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.account = reader.bytes();
          break;
        case 2:
          message.hashes.push(reader.bytes());
          break;
        case 3:
          if ((tag & 7) === 2) {
            var end2 = reader.uint32() + reader.pos;
            while (reader.pos < end2) {
              message.flags.push(reader.uint32());
            }
          } else {
            message.flags.push(reader.uint32());
          }
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$account, _object$hashes, _object$flags;
    var message = createBaseEventOrderFail();
    message.account = (_object$account = object.account) !== null && _object$account !== void 0 ? _object$account : new Uint8Array();
    message.hashes = ((_object$hashes = object.hashes) === null || _object$hashes === void 0 ? void 0 : _object$hashes.map(function (e) {
      return e;
    })) || [];
    message.flags = ((_object$flags = object.flags) === null || _object$flags === void 0 ? void 0 : _object$flags.map(function (e) {
      return e;
    })) || [];
    return message;
  }
};
exports.EventOrderFail = EventOrderFail;