"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TradingRewardCampaignAccountPoints = exports.TradingRewardCampaignAccountPendingPoints = exports.SubaccountNonce = exports.SpotOrderBook = exports.PerpetualMarketFundingState = exports.GenesisState = exports.FeeDiscountBucketVolumeAccounts = exports.FeeDiscountAccountTierTTL = exports.ExpiryFuturesMarketInfoState = exports.DerivativePosition = exports.DerivativeOrderBook = exports.ConditionalDerivativeOrderBook = exports.Balance = exports.AccountVolume = void 0;
var _exchange = require("./exchange");
var _tx = require("./tx");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
var _helpers = require("../../../helpers");
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 createBaseGenesisState() {
  return {
    params: undefined,
    spotMarkets: [],
    derivativeMarkets: [],
    spotOrderbook: [],
    derivativeOrderbook: [],
    balances: [],
    positions: [],
    subaccountTradeNonces: [],
    expiryFuturesMarketInfoState: [],
    perpetualMarketInfo: [],
    perpetualMarketFundingState: [],
    derivativeMarketSettlementScheduled: [],
    isSpotExchangeEnabled: false,
    isDerivativesExchangeEnabled: false,
    tradingRewardCampaignInfo: undefined,
    tradingRewardPoolCampaignSchedule: [],
    tradingRewardCampaignAccountPoints: [],
    feeDiscountSchedule: undefined,
    feeDiscountAccountTierTtl: [],
    feeDiscountBucketVolumeAccounts: [],
    isFirstFeeCycleFinished: false,
    pendingTradingRewardPoolCampaignSchedule: [],
    pendingTradingRewardCampaignAccountPoints: [],
    rewardsOptOutAddresses: [],
    historicalTradeRecords: [],
    binaryOptionsMarkets: [],
    binaryOptionsMarketIdsScheduledForSettlement: [],
    spotMarketIdsScheduledToForceClose: [],
    denomDecimals: [],
    conditionalDerivativeOrderbooks: []
  };
}
var GenesisState = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.params !== undefined) {
      _exchange.Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.spotMarkets),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _exchange.SpotMarket.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    var _iterator2 = _createForOfIteratorHelper(message.derivativeMarkets),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        _exchange.DerivativeMarket.encode(_v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.spotOrderbook),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        SpotOrderBook.encode(_v2, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(message.derivativeOrderbook),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        DerivativeOrderBook.encode(_v3, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.balances),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v4 = _step5.value;
        Balance.encode(_v4, writer.uint32(50).fork()).ldelim();
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var _iterator6 = _createForOfIteratorHelper(message.positions),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var _v5 = _step6.value;
        DerivativePosition.encode(_v5, writer.uint32(58).fork()).ldelim();
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    var _iterator7 = _createForOfIteratorHelper(message.subaccountTradeNonces),
      _step7;
    try {
      for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
        var _v6 = _step7.value;
        SubaccountNonce.encode(_v6, writer.uint32(66).fork()).ldelim();
      }
    } catch (err) {
      _iterator7.e(err);
    } finally {
      _iterator7.f();
    }
    var _iterator8 = _createForOfIteratorHelper(message.expiryFuturesMarketInfoState),
      _step8;
    try {
      for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
        var _v7 = _step8.value;
        ExpiryFuturesMarketInfoState.encode(_v7, writer.uint32(74).fork()).ldelim();
      }
    } catch (err) {
      _iterator8.e(err);
    } finally {
      _iterator8.f();
    }
    var _iterator9 = _createForOfIteratorHelper(message.perpetualMarketInfo),
      _step9;
    try {
      for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
        var _v8 = _step9.value;
        _exchange.PerpetualMarketInfo.encode(_v8, writer.uint32(82).fork()).ldelim();
      }
    } catch (err) {
      _iterator9.e(err);
    } finally {
      _iterator9.f();
    }
    var _iterator10 = _createForOfIteratorHelper(message.perpetualMarketFundingState),
      _step10;
    try {
      for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
        var _v9 = _step10.value;
        PerpetualMarketFundingState.encode(_v9, writer.uint32(90).fork()).ldelim();
      }
    } catch (err) {
      _iterator10.e(err);
    } finally {
      _iterator10.f();
    }
    var _iterator11 = _createForOfIteratorHelper(message.derivativeMarketSettlementScheduled),
      _step11;
    try {
      for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
        var _v10 = _step11.value;
        _exchange.DerivativeMarketSettlementInfo.encode(_v10, writer.uint32(98).fork()).ldelim();
      }
    } catch (err) {
      _iterator11.e(err);
    } finally {
      _iterator11.f();
    }
    if (message.isSpotExchangeEnabled === true) {
      writer.uint32(104).bool(message.isSpotExchangeEnabled);
    }
    if (message.isDerivativesExchangeEnabled === true) {
      writer.uint32(112).bool(message.isDerivativesExchangeEnabled);
    }
    if (message.tradingRewardCampaignInfo !== undefined) {
      _exchange.TradingRewardCampaignInfo.encode(message.tradingRewardCampaignInfo, writer.uint32(122).fork()).ldelim();
    }
    var _iterator12 = _createForOfIteratorHelper(message.tradingRewardPoolCampaignSchedule),
      _step12;
    try {
      for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
        var _v11 = _step12.value;
        _exchange.CampaignRewardPool.encode(_v11, writer.uint32(130).fork()).ldelim();
      }
    } catch (err) {
      _iterator12.e(err);
    } finally {
      _iterator12.f();
    }
    var _iterator13 = _createForOfIteratorHelper(message.tradingRewardCampaignAccountPoints),
      _step13;
    try {
      for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
        var _v12 = _step13.value;
        TradingRewardCampaignAccountPoints.encode(_v12, writer.uint32(138).fork()).ldelim();
      }
    } catch (err) {
      _iterator13.e(err);
    } finally {
      _iterator13.f();
    }
    if (message.feeDiscountSchedule !== undefined) {
      _exchange.FeeDiscountSchedule.encode(message.feeDiscountSchedule, writer.uint32(146).fork()).ldelim();
    }
    var _iterator14 = _createForOfIteratorHelper(message.feeDiscountAccountTierTtl),
      _step14;
    try {
      for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
        var _v13 = _step14.value;
        FeeDiscountAccountTierTTL.encode(_v13, writer.uint32(154).fork()).ldelim();
      }
    } catch (err) {
      _iterator14.e(err);
    } finally {
      _iterator14.f();
    }
    var _iterator15 = _createForOfIteratorHelper(message.feeDiscountBucketVolumeAccounts),
      _step15;
    try {
      for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
        var _v14 = _step15.value;
        FeeDiscountBucketVolumeAccounts.encode(_v14, writer.uint32(162).fork()).ldelim();
      }
    } catch (err) {
      _iterator15.e(err);
    } finally {
      _iterator15.f();
    }
    if (message.isFirstFeeCycleFinished === true) {
      writer.uint32(168).bool(message.isFirstFeeCycleFinished);
    }
    var _iterator16 = _createForOfIteratorHelper(message.pendingTradingRewardPoolCampaignSchedule),
      _step16;
    try {
      for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
        var _v15 = _step16.value;
        _exchange.CampaignRewardPool.encode(_v15, writer.uint32(178).fork()).ldelim();
      }
    } catch (err) {
      _iterator16.e(err);
    } finally {
      _iterator16.f();
    }
    var _iterator17 = _createForOfIteratorHelper(message.pendingTradingRewardCampaignAccountPoints),
      _step17;
    try {
      for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
        var _v16 = _step17.value;
        TradingRewardCampaignAccountPendingPoints.encode(_v16, writer.uint32(186).fork()).ldelim();
      }
    } catch (err) {
      _iterator17.e(err);
    } finally {
      _iterator17.f();
    }
    var _iterator18 = _createForOfIteratorHelper(message.rewardsOptOutAddresses),
      _step18;
    try {
      for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
        var _v17 = _step18.value;
        writer.uint32(194).string(_v17);
      }
    } catch (err) {
      _iterator18.e(err);
    } finally {
      _iterator18.f();
    }
    var _iterator19 = _createForOfIteratorHelper(message.historicalTradeRecords),
      _step19;
    try {
      for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
        var _v18 = _step19.value;
        _exchange.TradeRecords.encode(_v18, writer.uint32(202).fork()).ldelim();
      }
    } catch (err) {
      _iterator19.e(err);
    } finally {
      _iterator19.f();
    }
    var _iterator20 = _createForOfIteratorHelper(message.binaryOptionsMarkets),
      _step20;
    try {
      for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
        var _v19 = _step20.value;
        _exchange.BinaryOptionsMarket.encode(_v19, writer.uint32(210).fork()).ldelim();
      }
    } catch (err) {
      _iterator20.e(err);
    } finally {
      _iterator20.f();
    }
    var _iterator21 = _createForOfIteratorHelper(message.binaryOptionsMarketIdsScheduledForSettlement),
      _step21;
    try {
      for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
        var _v20 = _step21.value;
        writer.uint32(218).string(_v20);
      }
    } catch (err) {
      _iterator21.e(err);
    } finally {
      _iterator21.f();
    }
    var _iterator22 = _createForOfIteratorHelper(message.spotMarketIdsScheduledToForceClose),
      _step22;
    try {
      for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
        var _v21 = _step22.value;
        writer.uint32(226).string(_v21);
      }
    } catch (err) {
      _iterator22.e(err);
    } finally {
      _iterator22.f();
    }
    var _iterator23 = _createForOfIteratorHelper(message.denomDecimals),
      _step23;
    try {
      for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
        var _v22 = _step23.value;
        _tx.DenomDecimals.encode(_v22, writer.uint32(234).fork()).ldelim();
      }
    } catch (err) {
      _iterator23.e(err);
    } finally {
      _iterator23.f();
    }
    var _iterator24 = _createForOfIteratorHelper(message.conditionalDerivativeOrderbooks),
      _step24;
    try {
      for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
        var _v23 = _step24.value;
        ConditionalDerivativeOrderBook.encode(_v23, writer.uint32(242).fork()).ldelim();
      }
    } catch (err) {
      _iterator24.e(err);
    } finally {
      _iterator24.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 = createBaseGenesisState();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = _exchange.Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.spotMarkets.push(_exchange.SpotMarket.decode(reader, reader.uint32()));
          break;
        case 3:
          message.derivativeMarkets.push(_exchange.DerivativeMarket.decode(reader, reader.uint32()));
          break;
        case 4:
          message.spotOrderbook.push(SpotOrderBook.decode(reader, reader.uint32()));
          break;
        case 5:
          message.derivativeOrderbook.push(DerivativeOrderBook.decode(reader, reader.uint32()));
          break;
        case 6:
          message.balances.push(Balance.decode(reader, reader.uint32()));
          break;
        case 7:
          message.positions.push(DerivativePosition.decode(reader, reader.uint32()));
          break;
        case 8:
          message.subaccountTradeNonces.push(SubaccountNonce.decode(reader, reader.uint32()));
          break;
        case 9:
          message.expiryFuturesMarketInfoState.push(ExpiryFuturesMarketInfoState.decode(reader, reader.uint32()));
          break;
        case 10:
          message.perpetualMarketInfo.push(_exchange.PerpetualMarketInfo.decode(reader, reader.uint32()));
          break;
        case 11:
          message.perpetualMarketFundingState.push(PerpetualMarketFundingState.decode(reader, reader.uint32()));
          break;
        case 12:
          message.derivativeMarketSettlementScheduled.push(_exchange.DerivativeMarketSettlementInfo.decode(reader, reader.uint32()));
          break;
        case 13:
          message.isSpotExchangeEnabled = reader.bool();
          break;
        case 14:
          message.isDerivativesExchangeEnabled = reader.bool();
          break;
        case 15:
          message.tradingRewardCampaignInfo = _exchange.TradingRewardCampaignInfo.decode(reader, reader.uint32());
          break;
        case 16:
          message.tradingRewardPoolCampaignSchedule.push(_exchange.CampaignRewardPool.decode(reader, reader.uint32()));
          break;
        case 17:
          message.tradingRewardCampaignAccountPoints.push(TradingRewardCampaignAccountPoints.decode(reader, reader.uint32()));
          break;
        case 18:
          message.feeDiscountSchedule = _exchange.FeeDiscountSchedule.decode(reader, reader.uint32());
          break;
        case 19:
          message.feeDiscountAccountTierTtl.push(FeeDiscountAccountTierTTL.decode(reader, reader.uint32()));
          break;
        case 20:
          message.feeDiscountBucketVolumeAccounts.push(FeeDiscountBucketVolumeAccounts.decode(reader, reader.uint32()));
          break;
        case 21:
          message.isFirstFeeCycleFinished = reader.bool();
          break;
        case 22:
          message.pendingTradingRewardPoolCampaignSchedule.push(_exchange.CampaignRewardPool.decode(reader, reader.uint32()));
          break;
        case 23:
          message.pendingTradingRewardCampaignAccountPoints.push(TradingRewardCampaignAccountPendingPoints.decode(reader, reader.uint32()));
          break;
        case 24:
          message.rewardsOptOutAddresses.push(reader.string());
          break;
        case 25:
          message.historicalTradeRecords.push(_exchange.TradeRecords.decode(reader, reader.uint32()));
          break;
        case 26:
          message.binaryOptionsMarkets.push(_exchange.BinaryOptionsMarket.decode(reader, reader.uint32()));
          break;
        case 27:
          message.binaryOptionsMarketIdsScheduledForSettlement.push(reader.string());
          break;
        case 28:
          message.spotMarketIdsScheduledToForceClose.push(reader.string());
          break;
        case 29:
          message.denomDecimals.push(_tx.DenomDecimals.decode(reader, reader.uint32()));
          break;
        case 30:
          message.conditionalDerivativeOrderbooks.push(ConditionalDerivativeOrderBook.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$spotMarkets, _object$derivativeMar, _object$spotOrderbook, _object$derivativeOrd, _object$balances, _object$positions, _object$subaccountTra, _object$expiryFutures, _object$perpetualMark, _object$perpetualMark2, _object$derivativeMar2, _object$isSpotExchang, _object$isDerivatives, _object$tradingReward, _object$tradingReward2, _object$feeDiscountAc, _object$feeDiscountBu, _object$isFirstFeeCyc, _object$pendingTradin, _object$pendingTradin2, _object$rewardsOptOut, _object$historicalTra, _object$binaryOptions, _object$binaryOptions2, _object$spotMarketIds, _object$denomDecimals, _object$conditionalDe;
    var message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? _exchange.Params.fromPartial(object.params) : undefined;
    message.spotMarkets = ((_object$spotMarkets = object.spotMarkets) === null || _object$spotMarkets === void 0 ? void 0 : _object$spotMarkets.map(function (e) {
      return _exchange.SpotMarket.fromPartial(e);
    })) || [];
    message.derivativeMarkets = ((_object$derivativeMar = object.derivativeMarkets) === null || _object$derivativeMar === void 0 ? void 0 : _object$derivativeMar.map(function (e) {
      return _exchange.DerivativeMarket.fromPartial(e);
    })) || [];
    message.spotOrderbook = ((_object$spotOrderbook = object.spotOrderbook) === null || _object$spotOrderbook === void 0 ? void 0 : _object$spotOrderbook.map(function (e) {
      return SpotOrderBook.fromPartial(e);
    })) || [];
    message.derivativeOrderbook = ((_object$derivativeOrd = object.derivativeOrderbook) === null || _object$derivativeOrd === void 0 ? void 0 : _object$derivativeOrd.map(function (e) {
      return DerivativeOrderBook.fromPartial(e);
    })) || [];
    message.balances = ((_object$balances = object.balances) === null || _object$balances === void 0 ? void 0 : _object$balances.map(function (e) {
      return Balance.fromPartial(e);
    })) || [];
    message.positions = ((_object$positions = object.positions) === null || _object$positions === void 0 ? void 0 : _object$positions.map(function (e) {
      return DerivativePosition.fromPartial(e);
    })) || [];
    message.subaccountTradeNonces = ((_object$subaccountTra = object.subaccountTradeNonces) === null || _object$subaccountTra === void 0 ? void 0 : _object$subaccountTra.map(function (e) {
      return SubaccountNonce.fromPartial(e);
    })) || [];
    message.expiryFuturesMarketInfoState = ((_object$expiryFutures = object.expiryFuturesMarketInfoState) === null || _object$expiryFutures === void 0 ? void 0 : _object$expiryFutures.map(function (e) {
      return ExpiryFuturesMarketInfoState.fromPartial(e);
    })) || [];
    message.perpetualMarketInfo = ((_object$perpetualMark = object.perpetualMarketInfo) === null || _object$perpetualMark === void 0 ? void 0 : _object$perpetualMark.map(function (e) {
      return _exchange.PerpetualMarketInfo.fromPartial(e);
    })) || [];
    message.perpetualMarketFundingState = ((_object$perpetualMark2 = object.perpetualMarketFundingState) === null || _object$perpetualMark2 === void 0 ? void 0 : _object$perpetualMark2.map(function (e) {
      return PerpetualMarketFundingState.fromPartial(e);
    })) || [];
    message.derivativeMarketSettlementScheduled = ((_object$derivativeMar2 = object.derivativeMarketSettlementScheduled) === null || _object$derivativeMar2 === void 0 ? void 0 : _object$derivativeMar2.map(function (e) {
      return _exchange.DerivativeMarketSettlementInfo.fromPartial(e);
    })) || [];
    message.isSpotExchangeEnabled = (_object$isSpotExchang = object.isSpotExchangeEnabled) !== null && _object$isSpotExchang !== void 0 ? _object$isSpotExchang : false;
    message.isDerivativesExchangeEnabled = (_object$isDerivatives = object.isDerivativesExchangeEnabled) !== null && _object$isDerivatives !== void 0 ? _object$isDerivatives : false;
    message.tradingRewardCampaignInfo = object.tradingRewardCampaignInfo !== undefined && object.tradingRewardCampaignInfo !== null ? _exchange.TradingRewardCampaignInfo.fromPartial(object.tradingRewardCampaignInfo) : undefined;
    message.tradingRewardPoolCampaignSchedule = ((_object$tradingReward = object.tradingRewardPoolCampaignSchedule) === null || _object$tradingReward === void 0 ? void 0 : _object$tradingReward.map(function (e) {
      return _exchange.CampaignRewardPool.fromPartial(e);
    })) || [];
    message.tradingRewardCampaignAccountPoints = ((_object$tradingReward2 = object.tradingRewardCampaignAccountPoints) === null || _object$tradingReward2 === void 0 ? void 0 : _object$tradingReward2.map(function (e) {
      return TradingRewardCampaignAccountPoints.fromPartial(e);
    })) || [];
    message.feeDiscountSchedule = object.feeDiscountSchedule !== undefined && object.feeDiscountSchedule !== null ? _exchange.FeeDiscountSchedule.fromPartial(object.feeDiscountSchedule) : undefined;
    message.feeDiscountAccountTierTtl = ((_object$feeDiscountAc = object.feeDiscountAccountTierTtl) === null || _object$feeDiscountAc === void 0 ? void 0 : _object$feeDiscountAc.map(function (e) {
      return FeeDiscountAccountTierTTL.fromPartial(e);
    })) || [];
    message.feeDiscountBucketVolumeAccounts = ((_object$feeDiscountBu = object.feeDiscountBucketVolumeAccounts) === null || _object$feeDiscountBu === void 0 ? void 0 : _object$feeDiscountBu.map(function (e) {
      return FeeDiscountBucketVolumeAccounts.fromPartial(e);
    })) || [];
    message.isFirstFeeCycleFinished = (_object$isFirstFeeCyc = object.isFirstFeeCycleFinished) !== null && _object$isFirstFeeCyc !== void 0 ? _object$isFirstFeeCyc : false;
    message.pendingTradingRewardPoolCampaignSchedule = ((_object$pendingTradin = object.pendingTradingRewardPoolCampaignSchedule) === null || _object$pendingTradin === void 0 ? void 0 : _object$pendingTradin.map(function (e) {
      return _exchange.CampaignRewardPool.fromPartial(e);
    })) || [];
    message.pendingTradingRewardCampaignAccountPoints = ((_object$pendingTradin2 = object.pendingTradingRewardCampaignAccountPoints) === null || _object$pendingTradin2 === void 0 ? void 0 : _object$pendingTradin2.map(function (e) {
      return TradingRewardCampaignAccountPendingPoints.fromPartial(e);
    })) || [];
    message.rewardsOptOutAddresses = ((_object$rewardsOptOut = object.rewardsOptOutAddresses) === null || _object$rewardsOptOut === void 0 ? void 0 : _object$rewardsOptOut.map(function (e) {
      return e;
    })) || [];
    message.historicalTradeRecords = ((_object$historicalTra = object.historicalTradeRecords) === null || _object$historicalTra === void 0 ? void 0 : _object$historicalTra.map(function (e) {
      return _exchange.TradeRecords.fromPartial(e);
    })) || [];
    message.binaryOptionsMarkets = ((_object$binaryOptions = object.binaryOptionsMarkets) === null || _object$binaryOptions === void 0 ? void 0 : _object$binaryOptions.map(function (e) {
      return _exchange.BinaryOptionsMarket.fromPartial(e);
    })) || [];
    message.binaryOptionsMarketIdsScheduledForSettlement = ((_object$binaryOptions2 = object.binaryOptionsMarketIdsScheduledForSettlement) === null || _object$binaryOptions2 === void 0 ? void 0 : _object$binaryOptions2.map(function (e) {
      return e;
    })) || [];
    message.spotMarketIdsScheduledToForceClose = ((_object$spotMarketIds = object.spotMarketIdsScheduledToForceClose) === null || _object$spotMarketIds === void 0 ? void 0 : _object$spotMarketIds.map(function (e) {
      return e;
    })) || [];
    message.denomDecimals = ((_object$denomDecimals = object.denomDecimals) === null || _object$denomDecimals === void 0 ? void 0 : _object$denomDecimals.map(function (e) {
      return _tx.DenomDecimals.fromPartial(e);
    })) || [];
    message.conditionalDerivativeOrderbooks = ((_object$conditionalDe = object.conditionalDerivativeOrderbooks) === null || _object$conditionalDe === void 0 ? void 0 : _object$conditionalDe.map(function (e) {
      return ConditionalDerivativeOrderBook.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.GenesisState = GenesisState;
function createBaseFeeDiscountAccountTierTTL() {
  return {
    account: "",
    tierTtl: undefined
  };
}
var FeeDiscountAccountTierTTL = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.tierTtl !== undefined) {
      _exchange.FeeDiscountTierTTL.encode(message.tierTtl, 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 = createBaseFeeDiscountAccountTierTTL();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.account = reader.string();
          break;
        case 2:
          message.tierTtl = _exchange.FeeDiscountTierTTL.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$account;
    var message = createBaseFeeDiscountAccountTierTTL();
    message.account = (_object$account = object.account) !== null && _object$account !== void 0 ? _object$account : "";
    message.tierTtl = object.tierTtl !== undefined && object.tierTtl !== null ? _exchange.FeeDiscountTierTTL.fromPartial(object.tierTtl) : undefined;
    return message;
  }
};
exports.FeeDiscountAccountTierTTL = FeeDiscountAccountTierTTL;
function createBaseFeeDiscountBucketVolumeAccounts() {
  return {
    bucketStartTimestamp: _helpers.Long.ZERO,
    accountVolume: []
  };
}
var FeeDiscountBucketVolumeAccounts = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (!message.bucketStartTimestamp.isZero()) {
      writer.uint32(8).int64(message.bucketStartTimestamp);
    }
    var _iterator25 = _createForOfIteratorHelper(message.accountVolume),
      _step25;
    try {
      for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
        var v = _step25.value;
        AccountVolume.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator25.e(err);
    } finally {
      _iterator25.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 = createBaseFeeDiscountBucketVolumeAccounts();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.bucketStartTimestamp = reader.int64();
          break;
        case 2:
          message.accountVolume.push(AccountVolume.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$accountVolume;
    var message = createBaseFeeDiscountBucketVolumeAccounts();
    message.bucketStartTimestamp = object.bucketStartTimestamp !== undefined && object.bucketStartTimestamp !== null ? _helpers.Long.fromValue(object.bucketStartTimestamp) : _helpers.Long.ZERO;
    message.accountVolume = ((_object$accountVolume = object.accountVolume) === null || _object$accountVolume === void 0 ? void 0 : _object$accountVolume.map(function (e) {
      return AccountVolume.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.FeeDiscountBucketVolumeAccounts = FeeDiscountBucketVolumeAccounts;
function createBaseAccountVolume() {
  return {
    account: "",
    volume: ""
  };
}
var AccountVolume = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.volume !== "") {
      writer.uint32(18).string(message.volume);
    }
    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 = createBaseAccountVolume();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.account = reader.string();
          break;
        case 2:
          message.volume = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$account2, _object$volume;
    var message = createBaseAccountVolume();
    message.account = (_object$account2 = object.account) !== null && _object$account2 !== void 0 ? _object$account2 : "";
    message.volume = (_object$volume = object.volume) !== null && _object$volume !== void 0 ? _object$volume : "";
    return message;
  }
};
exports.AccountVolume = AccountVolume;
function createBaseTradingRewardCampaignAccountPoints() {
  return {
    account: "",
    points: ""
  };
}
var TradingRewardCampaignAccountPoints = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.points !== "") {
      writer.uint32(18).string(message.points);
    }
    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 = createBaseTradingRewardCampaignAccountPoints();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.account = reader.string();
          break;
        case 2:
          message.points = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$account3, _object$points;
    var message = createBaseTradingRewardCampaignAccountPoints();
    message.account = (_object$account3 = object.account) !== null && _object$account3 !== void 0 ? _object$account3 : "";
    message.points = (_object$points = object.points) !== null && _object$points !== void 0 ? _object$points : "";
    return message;
  }
};
exports.TradingRewardCampaignAccountPoints = TradingRewardCampaignAccountPoints;
function createBaseTradingRewardCampaignAccountPendingPoints() {
  return {
    rewardPoolStartTimestamp: _helpers.Long.ZERO,
    accountPoints: []
  };
}
var TradingRewardCampaignAccountPendingPoints = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (!message.rewardPoolStartTimestamp.isZero()) {
      writer.uint32(8).int64(message.rewardPoolStartTimestamp);
    }
    var _iterator26 = _createForOfIteratorHelper(message.accountPoints),
      _step26;
    try {
      for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
        var v = _step26.value;
        TradingRewardCampaignAccountPoints.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator26.e(err);
    } finally {
      _iterator26.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 = createBaseTradingRewardCampaignAccountPendingPoints();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.rewardPoolStartTimestamp = reader.int64();
          break;
        case 2:
          message.accountPoints.push(TradingRewardCampaignAccountPoints.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$accountPoints;
    var message = createBaseTradingRewardCampaignAccountPendingPoints();
    message.rewardPoolStartTimestamp = object.rewardPoolStartTimestamp !== undefined && object.rewardPoolStartTimestamp !== null ? _helpers.Long.fromValue(object.rewardPoolStartTimestamp) : _helpers.Long.ZERO;
    message.accountPoints = ((_object$accountPoints = object.accountPoints) === null || _object$accountPoints === void 0 ? void 0 : _object$accountPoints.map(function (e) {
      return TradingRewardCampaignAccountPoints.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.TradingRewardCampaignAccountPendingPoints = TradingRewardCampaignAccountPendingPoints;
function createBaseSpotOrderBook() {
  return {
    marketId: "",
    isBuySide: false,
    orders: []
  };
}
var SpotOrderBook = {
  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.isBuySide === true) {
      writer.uint32(16).bool(message.isBuySide);
    }
    var _iterator27 = _createForOfIteratorHelper(message.orders),
      _step27;
    try {
      for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
        var v = _step27.value;
        _exchange.SpotLimitOrder.encode(v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator27.e(err);
    } finally {
      _iterator27.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 = createBaseSpotOrderBook();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isBuySide = reader.bool();
          break;
        case 3:
          message.orders.push(_exchange.SpotLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId, _object$isBuySide, _object$orders;
    var message = createBaseSpotOrderBook();
    message.marketId = (_object$marketId = object.marketId) !== null && _object$marketId !== void 0 ? _object$marketId : "";
    message.isBuySide = (_object$isBuySide = object.isBuySide) !== null && _object$isBuySide !== void 0 ? _object$isBuySide : false;
    message.orders = ((_object$orders = object.orders) === null || _object$orders === void 0 ? void 0 : _object$orders.map(function (e) {
      return _exchange.SpotLimitOrder.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.SpotOrderBook = SpotOrderBook;
function createBaseDerivativeOrderBook() {
  return {
    marketId: "",
    isBuySide: false,
    orders: []
  };
}
var DerivativeOrderBook = {
  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.isBuySide === true) {
      writer.uint32(16).bool(message.isBuySide);
    }
    var _iterator28 = _createForOfIteratorHelper(message.orders),
      _step28;
    try {
      for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
        var v = _step28.value;
        _exchange.DerivativeLimitOrder.encode(v, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator28.e(err);
    } finally {
      _iterator28.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 = createBaseDerivativeOrderBook();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.isBuySide = reader.bool();
          break;
        case 3:
          message.orders.push(_exchange.DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId2, _object$isBuySide2, _object$orders2;
    var message = createBaseDerivativeOrderBook();
    message.marketId = (_object$marketId2 = object.marketId) !== null && _object$marketId2 !== void 0 ? _object$marketId2 : "";
    message.isBuySide = (_object$isBuySide2 = object.isBuySide) !== null && _object$isBuySide2 !== void 0 ? _object$isBuySide2 : false;
    message.orders = ((_object$orders2 = object.orders) === null || _object$orders2 === void 0 ? void 0 : _object$orders2.map(function (e) {
      return _exchange.DerivativeLimitOrder.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.DerivativeOrderBook = DerivativeOrderBook;
function createBaseConditionalDerivativeOrderBook() {
  return {
    marketId: "",
    limitBuyOrders: [],
    marketBuyOrders: [],
    limitSellOrders: [],
    marketSellOrders: []
  };
}
var ConditionalDerivativeOrderBook = {
  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 _iterator29 = _createForOfIteratorHelper(message.limitBuyOrders),
      _step29;
    try {
      for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
        var v = _step29.value;
        _exchange.DerivativeLimitOrder.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator29.e(err);
    } finally {
      _iterator29.f();
    }
    var _iterator30 = _createForOfIteratorHelper(message.marketBuyOrders),
      _step30;
    try {
      for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
        var _v24 = _step30.value;
        _exchange.DerivativeMarketOrder.encode(_v24, writer.uint32(26).fork()).ldelim();
      }
    } catch (err) {
      _iterator30.e(err);
    } finally {
      _iterator30.f();
    }
    var _iterator31 = _createForOfIteratorHelper(message.limitSellOrders),
      _step31;
    try {
      for (_iterator31.s(); !(_step31 = _iterator31.n()).done;) {
        var _v25 = _step31.value;
        _exchange.DerivativeLimitOrder.encode(_v25, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator31.e(err);
    } finally {
      _iterator31.f();
    }
    var _iterator32 = _createForOfIteratorHelper(message.marketSellOrders),
      _step32;
    try {
      for (_iterator32.s(); !(_step32 = _iterator32.n()).done;) {
        var _v26 = _step32.value;
        _exchange.DerivativeMarketOrder.encode(_v26, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator32.e(err);
    } finally {
      _iterator32.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 = createBaseConditionalDerivativeOrderBook();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.limitBuyOrders.push(_exchange.DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        case 3:
          message.marketBuyOrders.push(_exchange.DerivativeMarketOrder.decode(reader, reader.uint32()));
          break;
        case 4:
          message.limitSellOrders.push(_exchange.DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        case 5:
          message.marketSellOrders.push(_exchange.DerivativeMarketOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId3, _object$limitBuyOrder, _object$marketBuyOrde, _object$limitSellOrde, _object$marketSellOrd;
    var message = createBaseConditionalDerivativeOrderBook();
    message.marketId = (_object$marketId3 = object.marketId) !== null && _object$marketId3 !== void 0 ? _object$marketId3 : "";
    message.limitBuyOrders = ((_object$limitBuyOrder = object.limitBuyOrders) === null || _object$limitBuyOrder === void 0 ? void 0 : _object$limitBuyOrder.map(function (e) {
      return _exchange.DerivativeLimitOrder.fromPartial(e);
    })) || [];
    message.marketBuyOrders = ((_object$marketBuyOrde = object.marketBuyOrders) === null || _object$marketBuyOrde === void 0 ? void 0 : _object$marketBuyOrde.map(function (e) {
      return _exchange.DerivativeMarketOrder.fromPartial(e);
    })) || [];
    message.limitSellOrders = ((_object$limitSellOrde = object.limitSellOrders) === null || _object$limitSellOrde === void 0 ? void 0 : _object$limitSellOrde.map(function (e) {
      return _exchange.DerivativeLimitOrder.fromPartial(e);
    })) || [];
    message.marketSellOrders = ((_object$marketSellOrd = object.marketSellOrders) === null || _object$marketSellOrd === void 0 ? void 0 : _object$marketSellOrd.map(function (e) {
      return _exchange.DerivativeMarketOrder.fromPartial(e);
    })) || [];
    return message;
  }
};
exports.ConditionalDerivativeOrderBook = ConditionalDerivativeOrderBook;
function createBaseBalance() {
  return {
    subaccountId: "",
    denom: "",
    deposits: undefined
  };
}
var Balance = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.subaccountId !== "") {
      writer.uint32(10).string(message.subaccountId);
    }
    if (message.denom !== "") {
      writer.uint32(18).string(message.denom);
    }
    if (message.deposits !== undefined) {
      _exchange.Deposit.encode(message.deposits, 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 = createBaseBalance();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.denom = reader.string();
          break;
        case 3:
          message.deposits = _exchange.Deposit.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$subaccountId, _object$denom;
    var message = createBaseBalance();
    message.subaccountId = (_object$subaccountId = object.subaccountId) !== null && _object$subaccountId !== void 0 ? _object$subaccountId : "";
    message.denom = (_object$denom = object.denom) !== null && _object$denom !== void 0 ? _object$denom : "";
    message.deposits = object.deposits !== undefined && object.deposits !== null ? _exchange.Deposit.fromPartial(object.deposits) : undefined;
    return message;
  }
};
exports.Balance = Balance;
function createBaseDerivativePosition() {
  return {
    subaccountId: "",
    marketId: "",
    position: undefined
  };
}
var DerivativePosition = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.subaccountId !== "") {
      writer.uint32(10).string(message.subaccountId);
    }
    if (message.marketId !== "") {
      writer.uint32(18).string(message.marketId);
    }
    if (message.position !== undefined) {
      _exchange.Position.encode(message.position, 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 = createBaseDerivativePosition();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.marketId = reader.string();
          break;
        case 3:
          message.position = _exchange.Position.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$subaccountId2, _object$marketId4;
    var message = createBaseDerivativePosition();
    message.subaccountId = (_object$subaccountId2 = object.subaccountId) !== null && _object$subaccountId2 !== void 0 ? _object$subaccountId2 : "";
    message.marketId = (_object$marketId4 = object.marketId) !== null && _object$marketId4 !== void 0 ? _object$marketId4 : "";
    message.position = object.position !== undefined && object.position !== null ? _exchange.Position.fromPartial(object.position) : undefined;
    return message;
  }
};
exports.DerivativePosition = DerivativePosition;
function createBaseSubaccountNonce() {
  return {
    subaccountId: "",
    subaccountTradeNonce: undefined
  };
}
var SubaccountNonce = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    if (message.subaccountId !== "") {
      writer.uint32(10).string(message.subaccountId);
    }
    if (message.subaccountTradeNonce !== undefined) {
      _exchange.SubaccountTradeNonce.encode(message.subaccountTradeNonce, 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 = createBaseSubaccountNonce();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.subaccountTradeNonce = _exchange.SubaccountTradeNonce.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$subaccountId3;
    var message = createBaseSubaccountNonce();
    message.subaccountId = (_object$subaccountId3 = object.subaccountId) !== null && _object$subaccountId3 !== void 0 ? _object$subaccountId3 : "";
    message.subaccountTradeNonce = object.subaccountTradeNonce !== undefined && object.subaccountTradeNonce !== null ? _exchange.SubaccountTradeNonce.fromPartial(object.subaccountTradeNonce) : undefined;
    return message;
  }
};
exports.SubaccountNonce = SubaccountNonce;
function createBaseExpiryFuturesMarketInfoState() {
  return {
    marketId: "",
    marketInfo: undefined
  };
}
var ExpiryFuturesMarketInfoState = {
  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.marketInfo !== undefined) {
      _exchange.ExpiryFuturesMarketInfo.encode(message.marketInfo, 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 = createBaseExpiryFuturesMarketInfoState();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.marketInfo = _exchange.ExpiryFuturesMarketInfo.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId5;
    var message = createBaseExpiryFuturesMarketInfoState();
    message.marketId = (_object$marketId5 = object.marketId) !== null && _object$marketId5 !== void 0 ? _object$marketId5 : "";
    message.marketInfo = object.marketInfo !== undefined && object.marketInfo !== null ? _exchange.ExpiryFuturesMarketInfo.fromPartial(object.marketInfo) : undefined;
    return message;
  }
};
exports.ExpiryFuturesMarketInfoState = ExpiryFuturesMarketInfoState;
function createBasePerpetualMarketFundingState() {
  return {
    marketId: "",
    funding: undefined
  };
}
var PerpetualMarketFundingState = {
  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();
    }
    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 = createBasePerpetualMarketFundingState();
    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;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial: function fromPartial(object) {
    var _object$marketId6;
    var message = createBasePerpetualMarketFundingState();
    message.marketId = (_object$marketId6 = object.marketId) !== null && _object$marketId6 !== void 0 ? _object$marketId6 : "";
    message.funding = object.funding !== undefined && object.funding !== null ? _exchange.PerpetualMarketFunding.fromPartial(object.funding) : undefined;
    return message;
  }
};
exports.PerpetualMarketFundingState = PerpetualMarketFundingState;