import { Params, SpotMarket, DerivativeMarket, PerpetualMarketInfo, DerivativeMarketSettlementInfo, TradingRewardCampaignInfo, CampaignRewardPool, FeeDiscountSchedule, TradeRecords, BinaryOptionsMarket, FeeDiscountTierTTL, SpotLimitOrder, DerivativeLimitOrder, DerivativeMarketOrder, Deposit, Position, SubaccountTradeNonce, ExpiryFuturesMarketInfo, PerpetualMarketFunding } from "./exchange";
import { DenomDecimals } from "./tx";
import * as _m0 from "protobufjs/minimal";
import { Long } from "../../../helpers";
/** GenesisState defines the exchange module's genesis state. */

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: []
  };
}
export const GenesisState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.spotMarkets) {
      SpotMarket.encode(v, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.derivativeMarkets) {
      DerivativeMarket.encode(v, writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.spotOrderbook) {
      SpotOrderBook.encode(v, writer.uint32(34).fork()).ldelim();
    }
    for (const v of message.derivativeOrderbook) {
      DerivativeOrderBook.encode(v, writer.uint32(42).fork()).ldelim();
    }
    for (const v of message.balances) {
      Balance.encode(v, writer.uint32(50).fork()).ldelim();
    }
    for (const v of message.positions) {
      DerivativePosition.encode(v, writer.uint32(58).fork()).ldelim();
    }
    for (const v of message.subaccountTradeNonces) {
      SubaccountNonce.encode(v, writer.uint32(66).fork()).ldelim();
    }
    for (const v of message.expiryFuturesMarketInfoState) {
      ExpiryFuturesMarketInfoState.encode(v, writer.uint32(74).fork()).ldelim();
    }
    for (const v of message.perpetualMarketInfo) {
      PerpetualMarketInfo.encode(v, writer.uint32(82).fork()).ldelim();
    }
    for (const v of message.perpetualMarketFundingState) {
      PerpetualMarketFundingState.encode(v, writer.uint32(90).fork()).ldelim();
    }
    for (const v of message.derivativeMarketSettlementScheduled) {
      DerivativeMarketSettlementInfo.encode(v, writer.uint32(98).fork()).ldelim();
    }
    if (message.isSpotExchangeEnabled === true) {
      writer.uint32(104).bool(message.isSpotExchangeEnabled);
    }
    if (message.isDerivativesExchangeEnabled === true) {
      writer.uint32(112).bool(message.isDerivativesExchangeEnabled);
    }
    if (message.tradingRewardCampaignInfo !== undefined) {
      TradingRewardCampaignInfo.encode(message.tradingRewardCampaignInfo, writer.uint32(122).fork()).ldelim();
    }
    for (const v of message.tradingRewardPoolCampaignSchedule) {
      CampaignRewardPool.encode(v, writer.uint32(130).fork()).ldelim();
    }
    for (const v of message.tradingRewardCampaignAccountPoints) {
      TradingRewardCampaignAccountPoints.encode(v, writer.uint32(138).fork()).ldelim();
    }
    if (message.feeDiscountSchedule !== undefined) {
      FeeDiscountSchedule.encode(message.feeDiscountSchedule, writer.uint32(146).fork()).ldelim();
    }
    for (const v of message.feeDiscountAccountTierTtl) {
      FeeDiscountAccountTierTTL.encode(v, writer.uint32(154).fork()).ldelim();
    }
    for (const v of message.feeDiscountBucketVolumeAccounts) {
      FeeDiscountBucketVolumeAccounts.encode(v, writer.uint32(162).fork()).ldelim();
    }
    if (message.isFirstFeeCycleFinished === true) {
      writer.uint32(168).bool(message.isFirstFeeCycleFinished);
    }
    for (const v of message.pendingTradingRewardPoolCampaignSchedule) {
      CampaignRewardPool.encode(v, writer.uint32(178).fork()).ldelim();
    }
    for (const v of message.pendingTradingRewardCampaignAccountPoints) {
      TradingRewardCampaignAccountPendingPoints.encode(v, writer.uint32(186).fork()).ldelim();
    }
    for (const v of message.rewardsOptOutAddresses) {
      writer.uint32(194).string(v);
    }
    for (const v of message.historicalTradeRecords) {
      TradeRecords.encode(v, writer.uint32(202).fork()).ldelim();
    }
    for (const v of message.binaryOptionsMarkets) {
      BinaryOptionsMarket.encode(v, writer.uint32(210).fork()).ldelim();
    }
    for (const v of message.binaryOptionsMarketIdsScheduledForSettlement) {
      writer.uint32(218).string(v);
    }
    for (const v of message.spotMarketIdsScheduledToForceClose) {
      writer.uint32(226).string(v);
    }
    for (const v of message.denomDecimals) {
      DenomDecimals.encode(v, writer.uint32(234).fork()).ldelim();
    }
    for (const v of message.conditionalDerivativeOrderbooks) {
      ConditionalDerivativeOrderBook.encode(v, writer.uint32(242).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseGenesisState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.spotMarkets.push(SpotMarket.decode(reader, reader.uint32()));
          break;
        case 3:
          message.derivativeMarkets.push(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(PerpetualMarketInfo.decode(reader, reader.uint32()));
          break;
        case 11:
          message.perpetualMarketFundingState.push(PerpetualMarketFundingState.decode(reader, reader.uint32()));
          break;
        case 12:
          message.derivativeMarketSettlementScheduled.push(DerivativeMarketSettlementInfo.decode(reader, reader.uint32()));
          break;
        case 13:
          message.isSpotExchangeEnabled = reader.bool();
          break;
        case 14:
          message.isDerivativesExchangeEnabled = reader.bool();
          break;
        case 15:
          message.tradingRewardCampaignInfo = TradingRewardCampaignInfo.decode(reader, reader.uint32());
          break;
        case 16:
          message.tradingRewardPoolCampaignSchedule.push(CampaignRewardPool.decode(reader, reader.uint32()));
          break;
        case 17:
          message.tradingRewardCampaignAccountPoints.push(TradingRewardCampaignAccountPoints.decode(reader, reader.uint32()));
          break;
        case 18:
          message.feeDiscountSchedule = 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(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(TradeRecords.decode(reader, reader.uint32()));
          break;
        case 26:
          message.binaryOptionsMarkets.push(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(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(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;
    const message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
    message.spotMarkets = ((_object$spotMarkets = object.spotMarkets) === null || _object$spotMarkets === void 0 ? void 0 : _object$spotMarkets.map(e => SpotMarket.fromPartial(e))) || [];
    message.derivativeMarkets = ((_object$derivativeMar = object.derivativeMarkets) === null || _object$derivativeMar === void 0 ? void 0 : _object$derivativeMar.map(e => DerivativeMarket.fromPartial(e))) || [];
    message.spotOrderbook = ((_object$spotOrderbook = object.spotOrderbook) === null || _object$spotOrderbook === void 0 ? void 0 : _object$spotOrderbook.map(e => SpotOrderBook.fromPartial(e))) || [];
    message.derivativeOrderbook = ((_object$derivativeOrd = object.derivativeOrderbook) === null || _object$derivativeOrd === void 0 ? void 0 : _object$derivativeOrd.map(e => DerivativeOrderBook.fromPartial(e))) || [];
    message.balances = ((_object$balances = object.balances) === null || _object$balances === void 0 ? void 0 : _object$balances.map(e => Balance.fromPartial(e))) || [];
    message.positions = ((_object$positions = object.positions) === null || _object$positions === void 0 ? void 0 : _object$positions.map(e => DerivativePosition.fromPartial(e))) || [];
    message.subaccountTradeNonces = ((_object$subaccountTra = object.subaccountTradeNonces) === null || _object$subaccountTra === void 0 ? void 0 : _object$subaccountTra.map(e => SubaccountNonce.fromPartial(e))) || [];
    message.expiryFuturesMarketInfoState = ((_object$expiryFutures = object.expiryFuturesMarketInfoState) === null || _object$expiryFutures === void 0 ? void 0 : _object$expiryFutures.map(e => ExpiryFuturesMarketInfoState.fromPartial(e))) || [];
    message.perpetualMarketInfo = ((_object$perpetualMark = object.perpetualMarketInfo) === null || _object$perpetualMark === void 0 ? void 0 : _object$perpetualMark.map(e => PerpetualMarketInfo.fromPartial(e))) || [];
    message.perpetualMarketFundingState = ((_object$perpetualMark2 = object.perpetualMarketFundingState) === null || _object$perpetualMark2 === void 0 ? void 0 : _object$perpetualMark2.map(e => PerpetualMarketFundingState.fromPartial(e))) || [];
    message.derivativeMarketSettlementScheduled = ((_object$derivativeMar2 = object.derivativeMarketSettlementScheduled) === null || _object$derivativeMar2 === void 0 ? void 0 : _object$derivativeMar2.map(e => 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 ? TradingRewardCampaignInfo.fromPartial(object.tradingRewardCampaignInfo) : undefined;
    message.tradingRewardPoolCampaignSchedule = ((_object$tradingReward = object.tradingRewardPoolCampaignSchedule) === null || _object$tradingReward === void 0 ? void 0 : _object$tradingReward.map(e => CampaignRewardPool.fromPartial(e))) || [];
    message.tradingRewardCampaignAccountPoints = ((_object$tradingReward2 = object.tradingRewardCampaignAccountPoints) === null || _object$tradingReward2 === void 0 ? void 0 : _object$tradingReward2.map(e => TradingRewardCampaignAccountPoints.fromPartial(e))) || [];
    message.feeDiscountSchedule = object.feeDiscountSchedule !== undefined && object.feeDiscountSchedule !== null ? FeeDiscountSchedule.fromPartial(object.feeDiscountSchedule) : undefined;
    message.feeDiscountAccountTierTtl = ((_object$feeDiscountAc = object.feeDiscountAccountTierTtl) === null || _object$feeDiscountAc === void 0 ? void 0 : _object$feeDiscountAc.map(e => FeeDiscountAccountTierTTL.fromPartial(e))) || [];
    message.feeDiscountBucketVolumeAccounts = ((_object$feeDiscountBu = object.feeDiscountBucketVolumeAccounts) === null || _object$feeDiscountBu === void 0 ? void 0 : _object$feeDiscountBu.map(e => 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(e => CampaignRewardPool.fromPartial(e))) || [];
    message.pendingTradingRewardCampaignAccountPoints = ((_object$pendingTradin2 = object.pendingTradingRewardCampaignAccountPoints) === null || _object$pendingTradin2 === void 0 ? void 0 : _object$pendingTradin2.map(e => TradingRewardCampaignAccountPendingPoints.fromPartial(e))) || [];
    message.rewardsOptOutAddresses = ((_object$rewardsOptOut = object.rewardsOptOutAddresses) === null || _object$rewardsOptOut === void 0 ? void 0 : _object$rewardsOptOut.map(e => e)) || [];
    message.historicalTradeRecords = ((_object$historicalTra = object.historicalTradeRecords) === null || _object$historicalTra === void 0 ? void 0 : _object$historicalTra.map(e => TradeRecords.fromPartial(e))) || [];
    message.binaryOptionsMarkets = ((_object$binaryOptions = object.binaryOptionsMarkets) === null || _object$binaryOptions === void 0 ? void 0 : _object$binaryOptions.map(e => BinaryOptionsMarket.fromPartial(e))) || [];
    message.binaryOptionsMarketIdsScheduledForSettlement = ((_object$binaryOptions2 = object.binaryOptionsMarketIdsScheduledForSettlement) === null || _object$binaryOptions2 === void 0 ? void 0 : _object$binaryOptions2.map(e => e)) || [];
    message.spotMarketIdsScheduledToForceClose = ((_object$spotMarketIds = object.spotMarketIdsScheduledToForceClose) === null || _object$spotMarketIds === void 0 ? void 0 : _object$spotMarketIds.map(e => e)) || [];
    message.denomDecimals = ((_object$denomDecimals = object.denomDecimals) === null || _object$denomDecimals === void 0 ? void 0 : _object$denomDecimals.map(e => DenomDecimals.fromPartial(e))) || [];
    message.conditionalDerivativeOrderbooks = ((_object$conditionalDe = object.conditionalDerivativeOrderbooks) === null || _object$conditionalDe === void 0 ? void 0 : _object$conditionalDe.map(e => ConditionalDerivativeOrderBook.fromPartial(e))) || [];
    return message;
  }
};
function createBaseFeeDiscountAccountTierTTL() {
  return {
    account: "",
    tierTtl: undefined
  };
}
export const FeeDiscountAccountTierTTL = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.tierTtl !== undefined) {
      FeeDiscountTierTTL.encode(message.tierTtl, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseFeeDiscountAccountTierTTL();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.account = reader.string();
          break;
        case 2:
          message.tierTtl = FeeDiscountTierTTL.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$account;
    const message = createBaseFeeDiscountAccountTierTTL();
    message.account = (_object$account = object.account) !== null && _object$account !== void 0 ? _object$account : "";
    message.tierTtl = object.tierTtl !== undefined && object.tierTtl !== null ? FeeDiscountTierTTL.fromPartial(object.tierTtl) : undefined;
    return message;
  }
};
function createBaseFeeDiscountBucketVolumeAccounts() {
  return {
    bucketStartTimestamp: Long.ZERO,
    accountVolume: []
  };
}
export const FeeDiscountBucketVolumeAccounts = {
  encode(message, writer = _m0.Writer.create()) {
    if (!message.bucketStartTimestamp.isZero()) {
      writer.uint32(8).int64(message.bucketStartTimestamp);
    }
    for (const v of message.accountVolume) {
      AccountVolume.encode(v, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseFeeDiscountBucketVolumeAccounts();
    while (reader.pos < end) {
      const 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(object) {
    var _object$accountVolume;
    const message = createBaseFeeDiscountBucketVolumeAccounts();
    message.bucketStartTimestamp = object.bucketStartTimestamp !== undefined && object.bucketStartTimestamp !== null ? Long.fromValue(object.bucketStartTimestamp) : Long.ZERO;
    message.accountVolume = ((_object$accountVolume = object.accountVolume) === null || _object$accountVolume === void 0 ? void 0 : _object$accountVolume.map(e => AccountVolume.fromPartial(e))) || [];
    return message;
  }
};
function createBaseAccountVolume() {
  return {
    account: "",
    volume: ""
  };
}
export const AccountVolume = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.volume !== "") {
      writer.uint32(18).string(message.volume);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseAccountVolume();
    while (reader.pos < end) {
      const 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(object) {
    var _object$account2, _object$volume;
    const 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;
  }
};
function createBaseTradingRewardCampaignAccountPoints() {
  return {
    account: "",
    points: ""
  };
}
export const TradingRewardCampaignAccountPoints = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.account !== "") {
      writer.uint32(10).string(message.account);
    }
    if (message.points !== "") {
      writer.uint32(18).string(message.points);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseTradingRewardCampaignAccountPoints();
    while (reader.pos < end) {
      const 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(object) {
    var _object$account3, _object$points;
    const 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;
  }
};
function createBaseTradingRewardCampaignAccountPendingPoints() {
  return {
    rewardPoolStartTimestamp: Long.ZERO,
    accountPoints: []
  };
}
export const TradingRewardCampaignAccountPendingPoints = {
  encode(message, writer = _m0.Writer.create()) {
    if (!message.rewardPoolStartTimestamp.isZero()) {
      writer.uint32(8).int64(message.rewardPoolStartTimestamp);
    }
    for (const v of message.accountPoints) {
      TradingRewardCampaignAccountPoints.encode(v, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseTradingRewardCampaignAccountPendingPoints();
    while (reader.pos < end) {
      const 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(object) {
    var _object$accountPoints;
    const message = createBaseTradingRewardCampaignAccountPendingPoints();
    message.rewardPoolStartTimestamp = object.rewardPoolStartTimestamp !== undefined && object.rewardPoolStartTimestamp !== null ? Long.fromValue(object.rewardPoolStartTimestamp) : Long.ZERO;
    message.accountPoints = ((_object$accountPoints = object.accountPoints) === null || _object$accountPoints === void 0 ? void 0 : _object$accountPoints.map(e => TradingRewardCampaignAccountPoints.fromPartial(e))) || [];
    return message;
  }
};
function createBaseSpotOrderBook() {
  return {
    marketId: "",
    isBuySide: false,
    orders: []
  };
}
export const SpotOrderBook = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isBuySide === true) {
      writer.uint32(16).bool(message.isBuySide);
    }
    for (const v of message.orders) {
      SpotLimitOrder.encode(v, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseSpotOrderBook();
    while (reader.pos < end) {
      const 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(SpotLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$marketId, _object$isBuySide, _object$orders;
    const 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(e => SpotLimitOrder.fromPartial(e))) || [];
    return message;
  }
};
function createBaseDerivativeOrderBook() {
  return {
    marketId: "",
    isBuySide: false,
    orders: []
  };
}
export const DerivativeOrderBook = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.isBuySide === true) {
      writer.uint32(16).bool(message.isBuySide);
    }
    for (const v of message.orders) {
      DerivativeLimitOrder.encode(v, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseDerivativeOrderBook();
    while (reader.pos < end) {
      const 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(DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$marketId2, _object$isBuySide2, _object$orders2;
    const 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(e => DerivativeLimitOrder.fromPartial(e))) || [];
    return message;
  }
};
function createBaseConditionalDerivativeOrderBook() {
  return {
    marketId: "",
    limitBuyOrders: [],
    marketBuyOrders: [],
    limitSellOrders: [],
    marketSellOrders: []
  };
}
export const ConditionalDerivativeOrderBook = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    for (const v of message.limitBuyOrders) {
      DerivativeLimitOrder.encode(v, writer.uint32(18).fork()).ldelim();
    }
    for (const v of message.marketBuyOrders) {
      DerivativeMarketOrder.encode(v, writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.limitSellOrders) {
      DerivativeLimitOrder.encode(v, writer.uint32(34).fork()).ldelim();
    }
    for (const v of message.marketSellOrders) {
      DerivativeMarketOrder.encode(v, writer.uint32(42).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseConditionalDerivativeOrderBook();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.limitBuyOrders.push(DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        case 3:
          message.marketBuyOrders.push(DerivativeMarketOrder.decode(reader, reader.uint32()));
          break;
        case 4:
          message.limitSellOrders.push(DerivativeLimitOrder.decode(reader, reader.uint32()));
          break;
        case 5:
          message.marketSellOrders.push(DerivativeMarketOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$marketId3, _object$limitBuyOrder, _object$marketBuyOrde, _object$limitSellOrde, _object$marketSellOrd;
    const 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(e => DerivativeLimitOrder.fromPartial(e))) || [];
    message.marketBuyOrders = ((_object$marketBuyOrde = object.marketBuyOrders) === null || _object$marketBuyOrde === void 0 ? void 0 : _object$marketBuyOrde.map(e => DerivativeMarketOrder.fromPartial(e))) || [];
    message.limitSellOrders = ((_object$limitSellOrde = object.limitSellOrders) === null || _object$limitSellOrde === void 0 ? void 0 : _object$limitSellOrde.map(e => DerivativeLimitOrder.fromPartial(e))) || [];
    message.marketSellOrders = ((_object$marketSellOrd = object.marketSellOrders) === null || _object$marketSellOrd === void 0 ? void 0 : _object$marketSellOrd.map(e => DerivativeMarketOrder.fromPartial(e))) || [];
    return message;
  }
};
function createBaseBalance() {
  return {
    subaccountId: "",
    denom: "",
    deposits: undefined
  };
}
export const Balance = {
  encode(message, writer = _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) {
      Deposit.encode(message.deposits, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseBalance();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.denom = reader.string();
          break;
        case 3:
          message.deposits = Deposit.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$subaccountId, _object$denom;
    const 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 ? Deposit.fromPartial(object.deposits) : undefined;
    return message;
  }
};
function createBaseDerivativePosition() {
  return {
    subaccountId: "",
    marketId: "",
    position: undefined
  };
}
export const DerivativePosition = {
  encode(message, writer = _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) {
      Position.encode(message.position, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseDerivativePosition();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.marketId = reader.string();
          break;
        case 3:
          message.position = Position.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$subaccountId2, _object$marketId4;
    const 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 ? Position.fromPartial(object.position) : undefined;
    return message;
  }
};
function createBaseSubaccountNonce() {
  return {
    subaccountId: "",
    subaccountTradeNonce: undefined
  };
}
export const SubaccountNonce = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.subaccountId !== "") {
      writer.uint32(10).string(message.subaccountId);
    }
    if (message.subaccountTradeNonce !== undefined) {
      SubaccountTradeNonce.encode(message.subaccountTradeNonce, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseSubaccountNonce();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.subaccountId = reader.string();
          break;
        case 2:
          message.subaccountTradeNonce = SubaccountTradeNonce.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$subaccountId3;
    const message = createBaseSubaccountNonce();
    message.subaccountId = (_object$subaccountId3 = object.subaccountId) !== null && _object$subaccountId3 !== void 0 ? _object$subaccountId3 : "";
    message.subaccountTradeNonce = object.subaccountTradeNonce !== undefined && object.subaccountTradeNonce !== null ? SubaccountTradeNonce.fromPartial(object.subaccountTradeNonce) : undefined;
    return message;
  }
};
function createBaseExpiryFuturesMarketInfoState() {
  return {
    marketId: "",
    marketInfo: undefined
  };
}
export const ExpiryFuturesMarketInfoState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.marketInfo !== undefined) {
      ExpiryFuturesMarketInfo.encode(message.marketInfo, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseExpiryFuturesMarketInfoState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.marketInfo = ExpiryFuturesMarketInfo.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$marketId5;
    const message = createBaseExpiryFuturesMarketInfoState();
    message.marketId = (_object$marketId5 = object.marketId) !== null && _object$marketId5 !== void 0 ? _object$marketId5 : "";
    message.marketInfo = object.marketInfo !== undefined && object.marketInfo !== null ? ExpiryFuturesMarketInfo.fromPartial(object.marketInfo) : undefined;
    return message;
  }
};
function createBasePerpetualMarketFundingState() {
  return {
    marketId: "",
    funding: undefined
  };
}
export const PerpetualMarketFundingState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.marketId !== "") {
      writer.uint32(10).string(message.marketId);
    }
    if (message.funding !== undefined) {
      PerpetualMarketFunding.encode(message.funding, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBasePerpetualMarketFundingState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.marketId = reader.string();
          break;
        case 2:
          message.funding = PerpetualMarketFunding.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromPartial(object) {
    var _object$marketId6;
    const message = createBasePerpetualMarketFundingState();
    message.marketId = (_object$marketId6 = object.marketId) !== null && _object$marketId6 !== void 0 ? _object$marketId6 : "";
    message.funding = object.funding !== undefined && object.funding !== null ? PerpetualMarketFunding.fromPartial(object.funding) : undefined;
    return message;
  }
};