//@ts-nocheck
import { DecCoin, Coin } from "../../../cosmos/base/v1beta1/coin";
import * as _m0 from "protobufjs/minimal";
import { isSet } from "../../../helpers";
/**
 * FunctionParam is a key-value pair used for specifying a specific bond
 * parameter.
 */

/**
 * FunctionParam is a key-value pair used for specifying a specific bond
 * parameter.
 */

/** BondDetails contains details about the current state of a given bond. */

/** BondDetails contains details about the current state of a given bond. */

/** Bond defines a token bonding curve type with all of its parameters. */

/** Bond defines a token bonding curve type with all of its parameters. */

/**
 * BaseOrder defines a base order type. It contains all the necessary fields for
 * specifying the general details about a buy, sell, or swap order.
 */

/**
 * BaseOrder defines a base order type. It contains all the necessary fields for
 * specifying the general details about a buy, sell, or swap order.
 */

/**
 * BuyOrder defines a type for submitting a buy order on a bond, together with
 * the maximum amount of reserve tokens the buyer is willing to pay.
 */

/**
 * BuyOrder defines a type for submitting a buy order on a bond, together with
 * the maximum amount of reserve tokens the buyer is willing to pay.
 */

/** SellOrder defines a type for submitting a sell order on a bond. */

/** SellOrder defines a type for submitting a sell order on a bond. */

/**
 * SwapOrder defines a type for submitting a swap order between two tokens on a
 * bond.
 */

/**
 * SwapOrder defines a type for submitting a swap order between two tokens on a
 * bond.
 */

/**
 * Batch holds a collection of outstanding buy, sell, and swap orders on a
 * particular bond.
 */

/**
 * Batch holds a collection of outstanding buy, sell, and swap orders on a
 * particular bond.
 */

/** Params defines the parameters for the bonds module. */

/** Params defines the parameters for the bonds module. */

function createBaseFunctionParam() {
  return {
    param: "",
    value: ""
  };
}
export const FunctionParam = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.param !== "") {
      writer.uint32(10).string(message.param);
    }
    if (message.value !== "") {
      writer.uint32(18).string(message.value);
    }
    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 = createBaseFunctionParam();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.param = reader.string();
          break;
        case 2:
          message.value = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      param: isSet(object.param) ? String(object.param) : "",
      value: isSet(object.value) ? String(object.value) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    message.param !== undefined && (obj.param = message.param);
    message.value !== undefined && (obj.value = message.value);
    return obj;
  },
  fromPartial(object) {
    var _object$param, _object$value;
    const message = createBaseFunctionParam();
    message.param = (_object$param = object.param) !== null && _object$param !== void 0 ? _object$param : "";
    message.value = (_object$value = object.value) !== null && _object$value !== void 0 ? _object$value : "";
    return message;
  }
};
function createBaseBondDetails() {
  return {
    bondDid: "",
    spotPrice: [],
    supply: undefined,
    reserve: []
  };
}
export const BondDetails = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.bondDid !== "") {
      writer.uint32(10).string(message.bondDid);
    }
    for (const v of message.spotPrice) {
      DecCoin.encode(v, writer.uint32(18).fork()).ldelim();
    }
    if (message.supply !== undefined) {
      Coin.encode(message.supply, writer.uint32(26).fork()).ldelim();
    }
    for (const v of message.reserve) {
      Coin.encode(v, writer.uint32(34).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 = createBaseBondDetails();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.bondDid = reader.string();
          break;
        case 2:
          message.spotPrice.push(DecCoin.decode(reader, reader.uint32()));
          break;
        case 3:
          message.supply = Coin.decode(reader, reader.uint32());
          break;
        case 4:
          message.reserve.push(Coin.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      bondDid: isSet(object.bondDid) ? String(object.bondDid) : "",
      spotPrice: Array.isArray(object === null || object === void 0 ? void 0 : object.spotPrice) ? object.spotPrice.map(e => DecCoin.fromJSON(e)) : [],
      supply: isSet(object.supply) ? Coin.fromJSON(object.supply) : undefined,
      reserve: Array.isArray(object === null || object === void 0 ? void 0 : object.reserve) ? object.reserve.map(e => Coin.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.bondDid !== undefined && (obj.bondDid = message.bondDid);
    if (message.spotPrice) {
      obj.spotPrice = message.spotPrice.map(e => e ? DecCoin.toJSON(e) : undefined);
    } else {
      obj.spotPrice = [];
    }
    message.supply !== undefined && (obj.supply = message.supply ? Coin.toJSON(message.supply) : undefined);
    if (message.reserve) {
      obj.reserve = message.reserve.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.reserve = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$bondDid, _object$spotPrice, _object$reserve;
    const message = createBaseBondDetails();
    message.bondDid = (_object$bondDid = object.bondDid) !== null && _object$bondDid !== void 0 ? _object$bondDid : "";
    message.spotPrice = ((_object$spotPrice = object.spotPrice) === null || _object$spotPrice === void 0 ? void 0 : _object$spotPrice.map(e => DecCoin.fromPartial(e))) || [];
    message.supply = object.supply !== undefined && object.supply !== null ? Coin.fromPartial(object.supply) : undefined;
    message.reserve = ((_object$reserve = object.reserve) === null || _object$reserve === void 0 ? void 0 : _object$reserve.map(e => Coin.fromPartial(e))) || [];
    return message;
  }
};
function createBaseBond() {
  return {
    token: "",
    name: "",
    description: "",
    creatorDid: "",
    controllerDid: "",
    functionType: "",
    functionParameters: [],
    reserveTokens: [],
    txFeePercentage: "",
    exitFeePercentage: "",
    feeAddress: "",
    reserveWithdrawalAddress: "",
    maxSupply: undefined,
    orderQuantityLimits: [],
    sanityRate: "",
    sanityMarginPercentage: "",
    currentSupply: undefined,
    currentReserve: [],
    availableReserve: [],
    currentOutcomePaymentReserve: [],
    allowSells: false,
    allowReserveWithdrawals: false,
    alphaBond: false,
    batchBlocks: "",
    outcomePayment: "",
    state: "",
    bondDid: "",
    oracleDid: ""
  };
}
export const Bond = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.token !== "") {
      writer.uint32(10).string(message.token);
    }
    if (message.name !== "") {
      writer.uint32(18).string(message.name);
    }
    if (message.description !== "") {
      writer.uint32(26).string(message.description);
    }
    if (message.creatorDid !== "") {
      writer.uint32(34).string(message.creatorDid);
    }
    if (message.controllerDid !== "") {
      writer.uint32(42).string(message.controllerDid);
    }
    if (message.functionType !== "") {
      writer.uint32(50).string(message.functionType);
    }
    for (const v of message.functionParameters) {
      FunctionParam.encode(v, writer.uint32(58).fork()).ldelim();
    }
    for (const v of message.reserveTokens) {
      writer.uint32(66).string(v);
    }
    if (message.txFeePercentage !== "") {
      writer.uint32(74).string(message.txFeePercentage);
    }
    if (message.exitFeePercentage !== "") {
      writer.uint32(82).string(message.exitFeePercentage);
    }
    if (message.feeAddress !== "") {
      writer.uint32(90).string(message.feeAddress);
    }
    if (message.reserveWithdrawalAddress !== "") {
      writer.uint32(98).string(message.reserveWithdrawalAddress);
    }
    if (message.maxSupply !== undefined) {
      Coin.encode(message.maxSupply, writer.uint32(106).fork()).ldelim();
    }
    for (const v of message.orderQuantityLimits) {
      Coin.encode(v, writer.uint32(114).fork()).ldelim();
    }
    if (message.sanityRate !== "") {
      writer.uint32(122).string(message.sanityRate);
    }
    if (message.sanityMarginPercentage !== "") {
      writer.uint32(130).string(message.sanityMarginPercentage);
    }
    if (message.currentSupply !== undefined) {
      Coin.encode(message.currentSupply, writer.uint32(138).fork()).ldelim();
    }
    for (const v of message.currentReserve) {
      Coin.encode(v, writer.uint32(146).fork()).ldelim();
    }
    for (const v of message.availableReserve) {
      Coin.encode(v, writer.uint32(154).fork()).ldelim();
    }
    for (const v of message.currentOutcomePaymentReserve) {
      Coin.encode(v, writer.uint32(162).fork()).ldelim();
    }
    if (message.allowSells === true) {
      writer.uint32(168).bool(message.allowSells);
    }
    if (message.allowReserveWithdrawals === true) {
      writer.uint32(176).bool(message.allowReserveWithdrawals);
    }
    if (message.alphaBond === true) {
      writer.uint32(184).bool(message.alphaBond);
    }
    if (message.batchBlocks !== "") {
      writer.uint32(194).string(message.batchBlocks);
    }
    if (message.outcomePayment !== "") {
      writer.uint32(202).string(message.outcomePayment);
    }
    if (message.state !== "") {
      writer.uint32(210).string(message.state);
    }
    if (message.bondDid !== "") {
      writer.uint32(218).string(message.bondDid);
    }
    if (message.oracleDid !== "") {
      writer.uint32(226).string(message.oracleDid);
    }
    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 = createBaseBond();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.token = reader.string();
          break;
        case 2:
          message.name = reader.string();
          break;
        case 3:
          message.description = reader.string();
          break;
        case 4:
          message.creatorDid = reader.string();
          break;
        case 5:
          message.controllerDid = reader.string();
          break;
        case 6:
          message.functionType = reader.string();
          break;
        case 7:
          message.functionParameters.push(FunctionParam.decode(reader, reader.uint32()));
          break;
        case 8:
          message.reserveTokens.push(reader.string());
          break;
        case 9:
          message.txFeePercentage = reader.string();
          break;
        case 10:
          message.exitFeePercentage = reader.string();
          break;
        case 11:
          message.feeAddress = reader.string();
          break;
        case 12:
          message.reserveWithdrawalAddress = reader.string();
          break;
        case 13:
          message.maxSupply = Coin.decode(reader, reader.uint32());
          break;
        case 14:
          message.orderQuantityLimits.push(Coin.decode(reader, reader.uint32()));
          break;
        case 15:
          message.sanityRate = reader.string();
          break;
        case 16:
          message.sanityMarginPercentage = reader.string();
          break;
        case 17:
          message.currentSupply = Coin.decode(reader, reader.uint32());
          break;
        case 18:
          message.currentReserve.push(Coin.decode(reader, reader.uint32()));
          break;
        case 19:
          message.availableReserve.push(Coin.decode(reader, reader.uint32()));
          break;
        case 20:
          message.currentOutcomePaymentReserve.push(Coin.decode(reader, reader.uint32()));
          break;
        case 21:
          message.allowSells = reader.bool();
          break;
        case 22:
          message.allowReserveWithdrawals = reader.bool();
          break;
        case 23:
          message.alphaBond = reader.bool();
          break;
        case 24:
          message.batchBlocks = reader.string();
          break;
        case 25:
          message.outcomePayment = reader.string();
          break;
        case 26:
          message.state = reader.string();
          break;
        case 27:
          message.bondDid = reader.string();
          break;
        case 28:
          message.oracleDid = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      token: isSet(object.token) ? String(object.token) : "",
      name: isSet(object.name) ? String(object.name) : "",
      description: isSet(object.description) ? String(object.description) : "",
      creatorDid: isSet(object.creatorDid) ? String(object.creatorDid) : "",
      controllerDid: isSet(object.controllerDid) ? String(object.controllerDid) : "",
      functionType: isSet(object.functionType) ? String(object.functionType) : "",
      functionParameters: Array.isArray(object === null || object === void 0 ? void 0 : object.functionParameters) ? object.functionParameters.map(e => FunctionParam.fromJSON(e)) : [],
      reserveTokens: Array.isArray(object === null || object === void 0 ? void 0 : object.reserveTokens) ? object.reserveTokens.map(e => String(e)) : [],
      txFeePercentage: isSet(object.txFeePercentage) ? String(object.txFeePercentage) : "",
      exitFeePercentage: isSet(object.exitFeePercentage) ? String(object.exitFeePercentage) : "",
      feeAddress: isSet(object.feeAddress) ? String(object.feeAddress) : "",
      reserveWithdrawalAddress: isSet(object.reserveWithdrawalAddress) ? String(object.reserveWithdrawalAddress) : "",
      maxSupply: isSet(object.maxSupply) ? Coin.fromJSON(object.maxSupply) : undefined,
      orderQuantityLimits: Array.isArray(object === null || object === void 0 ? void 0 : object.orderQuantityLimits) ? object.orderQuantityLimits.map(e => Coin.fromJSON(e)) : [],
      sanityRate: isSet(object.sanityRate) ? String(object.sanityRate) : "",
      sanityMarginPercentage: isSet(object.sanityMarginPercentage) ? String(object.sanityMarginPercentage) : "",
      currentSupply: isSet(object.currentSupply) ? Coin.fromJSON(object.currentSupply) : undefined,
      currentReserve: Array.isArray(object === null || object === void 0 ? void 0 : object.currentReserve) ? object.currentReserve.map(e => Coin.fromJSON(e)) : [],
      availableReserve: Array.isArray(object === null || object === void 0 ? void 0 : object.availableReserve) ? object.availableReserve.map(e => Coin.fromJSON(e)) : [],
      currentOutcomePaymentReserve: Array.isArray(object === null || object === void 0 ? void 0 : object.currentOutcomePaymentReserve) ? object.currentOutcomePaymentReserve.map(e => Coin.fromJSON(e)) : [],
      allowSells: isSet(object.allowSells) ? Boolean(object.allowSells) : false,
      allowReserveWithdrawals: isSet(object.allowReserveWithdrawals) ? Boolean(object.allowReserveWithdrawals) : false,
      alphaBond: isSet(object.alphaBond) ? Boolean(object.alphaBond) : false,
      batchBlocks: isSet(object.batchBlocks) ? String(object.batchBlocks) : "",
      outcomePayment: isSet(object.outcomePayment) ? String(object.outcomePayment) : "",
      state: isSet(object.state) ? String(object.state) : "",
      bondDid: isSet(object.bondDid) ? String(object.bondDid) : "",
      oracleDid: isSet(object.oracleDid) ? String(object.oracleDid) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    message.token !== undefined && (obj.token = message.token);
    message.name !== undefined && (obj.name = message.name);
    message.description !== undefined && (obj.description = message.description);
    message.creatorDid !== undefined && (obj.creatorDid = message.creatorDid);
    message.controllerDid !== undefined && (obj.controllerDid = message.controllerDid);
    message.functionType !== undefined && (obj.functionType = message.functionType);
    if (message.functionParameters) {
      obj.functionParameters = message.functionParameters.map(e => e ? FunctionParam.toJSON(e) : undefined);
    } else {
      obj.functionParameters = [];
    }
    if (message.reserveTokens) {
      obj.reserveTokens = message.reserveTokens.map(e => e);
    } else {
      obj.reserveTokens = [];
    }
    message.txFeePercentage !== undefined && (obj.txFeePercentage = message.txFeePercentage);
    message.exitFeePercentage !== undefined && (obj.exitFeePercentage = message.exitFeePercentage);
    message.feeAddress !== undefined && (obj.feeAddress = message.feeAddress);
    message.reserveWithdrawalAddress !== undefined && (obj.reserveWithdrawalAddress = message.reserveWithdrawalAddress);
    message.maxSupply !== undefined && (obj.maxSupply = message.maxSupply ? Coin.toJSON(message.maxSupply) : undefined);
    if (message.orderQuantityLimits) {
      obj.orderQuantityLimits = message.orderQuantityLimits.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.orderQuantityLimits = [];
    }
    message.sanityRate !== undefined && (obj.sanityRate = message.sanityRate);
    message.sanityMarginPercentage !== undefined && (obj.sanityMarginPercentage = message.sanityMarginPercentage);
    message.currentSupply !== undefined && (obj.currentSupply = message.currentSupply ? Coin.toJSON(message.currentSupply) : undefined);
    if (message.currentReserve) {
      obj.currentReserve = message.currentReserve.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.currentReserve = [];
    }
    if (message.availableReserve) {
      obj.availableReserve = message.availableReserve.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.availableReserve = [];
    }
    if (message.currentOutcomePaymentReserve) {
      obj.currentOutcomePaymentReserve = message.currentOutcomePaymentReserve.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.currentOutcomePaymentReserve = [];
    }
    message.allowSells !== undefined && (obj.allowSells = message.allowSells);
    message.allowReserveWithdrawals !== undefined && (obj.allowReserveWithdrawals = message.allowReserveWithdrawals);
    message.alphaBond !== undefined && (obj.alphaBond = message.alphaBond);
    message.batchBlocks !== undefined && (obj.batchBlocks = message.batchBlocks);
    message.outcomePayment !== undefined && (obj.outcomePayment = message.outcomePayment);
    message.state !== undefined && (obj.state = message.state);
    message.bondDid !== undefined && (obj.bondDid = message.bondDid);
    message.oracleDid !== undefined && (obj.oracleDid = message.oracleDid);
    return obj;
  },
  fromPartial(object) {
    var _object$token, _object$name, _object$description, _object$creatorDid, _object$controllerDid, _object$functionType, _object$functionParam, _object$reserveTokens, _object$txFeePercenta, _object$exitFeePercen, _object$feeAddress, _object$reserveWithdr, _object$orderQuantity, _object$sanityRate, _object$sanityMarginP, _object$currentReserv, _object$availableRese, _object$currentOutcom, _object$allowSells, _object$allowReserveW, _object$alphaBond, _object$batchBlocks, _object$outcomePaymen, _object$state, _object$bondDid2, _object$oracleDid;
    const message = createBaseBond();
    message.token = (_object$token = object.token) !== null && _object$token !== void 0 ? _object$token : "";
    message.name = (_object$name = object.name) !== null && _object$name !== void 0 ? _object$name : "";
    message.description = (_object$description = object.description) !== null && _object$description !== void 0 ? _object$description : "";
    message.creatorDid = (_object$creatorDid = object.creatorDid) !== null && _object$creatorDid !== void 0 ? _object$creatorDid : "";
    message.controllerDid = (_object$controllerDid = object.controllerDid) !== null && _object$controllerDid !== void 0 ? _object$controllerDid : "";
    message.functionType = (_object$functionType = object.functionType) !== null && _object$functionType !== void 0 ? _object$functionType : "";
    message.functionParameters = ((_object$functionParam = object.functionParameters) === null || _object$functionParam === void 0 ? void 0 : _object$functionParam.map(e => FunctionParam.fromPartial(e))) || [];
    message.reserveTokens = ((_object$reserveTokens = object.reserveTokens) === null || _object$reserveTokens === void 0 ? void 0 : _object$reserveTokens.map(e => e)) || [];
    message.txFeePercentage = (_object$txFeePercenta = object.txFeePercentage) !== null && _object$txFeePercenta !== void 0 ? _object$txFeePercenta : "";
    message.exitFeePercentage = (_object$exitFeePercen = object.exitFeePercentage) !== null && _object$exitFeePercen !== void 0 ? _object$exitFeePercen : "";
    message.feeAddress = (_object$feeAddress = object.feeAddress) !== null && _object$feeAddress !== void 0 ? _object$feeAddress : "";
    message.reserveWithdrawalAddress = (_object$reserveWithdr = object.reserveWithdrawalAddress) !== null && _object$reserveWithdr !== void 0 ? _object$reserveWithdr : "";
    message.maxSupply = object.maxSupply !== undefined && object.maxSupply !== null ? Coin.fromPartial(object.maxSupply) : undefined;
    message.orderQuantityLimits = ((_object$orderQuantity = object.orderQuantityLimits) === null || _object$orderQuantity === void 0 ? void 0 : _object$orderQuantity.map(e => Coin.fromPartial(e))) || [];
    message.sanityRate = (_object$sanityRate = object.sanityRate) !== null && _object$sanityRate !== void 0 ? _object$sanityRate : "";
    message.sanityMarginPercentage = (_object$sanityMarginP = object.sanityMarginPercentage) !== null && _object$sanityMarginP !== void 0 ? _object$sanityMarginP : "";
    message.currentSupply = object.currentSupply !== undefined && object.currentSupply !== null ? Coin.fromPartial(object.currentSupply) : undefined;
    message.currentReserve = ((_object$currentReserv = object.currentReserve) === null || _object$currentReserv === void 0 ? void 0 : _object$currentReserv.map(e => Coin.fromPartial(e))) || [];
    message.availableReserve = ((_object$availableRese = object.availableReserve) === null || _object$availableRese === void 0 ? void 0 : _object$availableRese.map(e => Coin.fromPartial(e))) || [];
    message.currentOutcomePaymentReserve = ((_object$currentOutcom = object.currentOutcomePaymentReserve) === null || _object$currentOutcom === void 0 ? void 0 : _object$currentOutcom.map(e => Coin.fromPartial(e))) || [];
    message.allowSells = (_object$allowSells = object.allowSells) !== null && _object$allowSells !== void 0 ? _object$allowSells : false;
    message.allowReserveWithdrawals = (_object$allowReserveW = object.allowReserveWithdrawals) !== null && _object$allowReserveW !== void 0 ? _object$allowReserveW : false;
    message.alphaBond = (_object$alphaBond = object.alphaBond) !== null && _object$alphaBond !== void 0 ? _object$alphaBond : false;
    message.batchBlocks = (_object$batchBlocks = object.batchBlocks) !== null && _object$batchBlocks !== void 0 ? _object$batchBlocks : "";
    message.outcomePayment = (_object$outcomePaymen = object.outcomePayment) !== null && _object$outcomePaymen !== void 0 ? _object$outcomePaymen : "";
    message.state = (_object$state = object.state) !== null && _object$state !== void 0 ? _object$state : "";
    message.bondDid = (_object$bondDid2 = object.bondDid) !== null && _object$bondDid2 !== void 0 ? _object$bondDid2 : "";
    message.oracleDid = (_object$oracleDid = object.oracleDid) !== null && _object$oracleDid !== void 0 ? _object$oracleDid : "";
    return message;
  }
};
function createBaseBaseOrder() {
  return {
    accountDid: "",
    amount: undefined,
    cancelled: false,
    cancelReason: ""
  };
}
export const BaseOrder = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.accountDid !== "") {
      writer.uint32(10).string(message.accountDid);
    }
    if (message.amount !== undefined) {
      Coin.encode(message.amount, writer.uint32(18).fork()).ldelim();
    }
    if (message.cancelled === true) {
      writer.uint32(24).bool(message.cancelled);
    }
    if (message.cancelReason !== "") {
      writer.uint32(34).string(message.cancelReason);
    }
    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 = createBaseBaseOrder();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.accountDid = reader.string();
          break;
        case 2:
          message.amount = Coin.decode(reader, reader.uint32());
          break;
        case 3:
          message.cancelled = reader.bool();
          break;
        case 4:
          message.cancelReason = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      accountDid: isSet(object.accountDid) ? String(object.accountDid) : "",
      amount: isSet(object.amount) ? Coin.fromJSON(object.amount) : undefined,
      cancelled: isSet(object.cancelled) ? Boolean(object.cancelled) : false,
      cancelReason: isSet(object.cancelReason) ? String(object.cancelReason) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    message.accountDid !== undefined && (obj.accountDid = message.accountDid);
    message.amount !== undefined && (obj.amount = message.amount ? Coin.toJSON(message.amount) : undefined);
    message.cancelled !== undefined && (obj.cancelled = message.cancelled);
    message.cancelReason !== undefined && (obj.cancelReason = message.cancelReason);
    return obj;
  },
  fromPartial(object) {
    var _object$accountDid, _object$cancelled, _object$cancelReason;
    const message = createBaseBaseOrder();
    message.accountDid = (_object$accountDid = object.accountDid) !== null && _object$accountDid !== void 0 ? _object$accountDid : "";
    message.amount = object.amount !== undefined && object.amount !== null ? Coin.fromPartial(object.amount) : undefined;
    message.cancelled = (_object$cancelled = object.cancelled) !== null && _object$cancelled !== void 0 ? _object$cancelled : false;
    message.cancelReason = (_object$cancelReason = object.cancelReason) !== null && _object$cancelReason !== void 0 ? _object$cancelReason : "";
    return message;
  }
};
function createBaseBuyOrder() {
  return {
    baseOrder: undefined,
    maxPrices: []
  };
}
export const BuyOrder = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.baseOrder !== undefined) {
      BaseOrder.encode(message.baseOrder, writer.uint32(10).fork()).ldelim();
    }
    for (const v of message.maxPrices) {
      Coin.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 = createBaseBuyOrder();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.baseOrder = BaseOrder.decode(reader, reader.uint32());
          break;
        case 2:
          message.maxPrices.push(Coin.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      baseOrder: isSet(object.baseOrder) ? BaseOrder.fromJSON(object.baseOrder) : undefined,
      maxPrices: Array.isArray(object === null || object === void 0 ? void 0 : object.maxPrices) ? object.maxPrices.map(e => Coin.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.baseOrder !== undefined && (obj.baseOrder = message.baseOrder ? BaseOrder.toJSON(message.baseOrder) : undefined);
    if (message.maxPrices) {
      obj.maxPrices = message.maxPrices.map(e => e ? Coin.toJSON(e) : undefined);
    } else {
      obj.maxPrices = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$maxPrices;
    const message = createBaseBuyOrder();
    message.baseOrder = object.baseOrder !== undefined && object.baseOrder !== null ? BaseOrder.fromPartial(object.baseOrder) : undefined;
    message.maxPrices = ((_object$maxPrices = object.maxPrices) === null || _object$maxPrices === void 0 ? void 0 : _object$maxPrices.map(e => Coin.fromPartial(e))) || [];
    return message;
  }
};
function createBaseSellOrder() {
  return {
    baseOrder: undefined
  };
}
export const SellOrder = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.baseOrder !== undefined) {
      BaseOrder.encode(message.baseOrder, writer.uint32(10).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 = createBaseSellOrder();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.baseOrder = BaseOrder.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      baseOrder: isSet(object.baseOrder) ? BaseOrder.fromJSON(object.baseOrder) : undefined
    };
  },
  toJSON(message) {
    const obj = {};
    message.baseOrder !== undefined && (obj.baseOrder = message.baseOrder ? BaseOrder.toJSON(message.baseOrder) : undefined);
    return obj;
  },
  fromPartial(object) {
    const message = createBaseSellOrder();
    message.baseOrder = object.baseOrder !== undefined && object.baseOrder !== null ? BaseOrder.fromPartial(object.baseOrder) : undefined;
    return message;
  }
};
function createBaseSwapOrder() {
  return {
    baseOrder: undefined,
    toToken: ""
  };
}
export const SwapOrder = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.baseOrder !== undefined) {
      BaseOrder.encode(message.baseOrder, writer.uint32(10).fork()).ldelim();
    }
    if (message.toToken !== "") {
      writer.uint32(18).string(message.toToken);
    }
    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 = createBaseSwapOrder();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.baseOrder = BaseOrder.decode(reader, reader.uint32());
          break;
        case 2:
          message.toToken = reader.string();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      baseOrder: isSet(object.baseOrder) ? BaseOrder.fromJSON(object.baseOrder) : undefined,
      toToken: isSet(object.toToken) ? String(object.toToken) : ""
    };
  },
  toJSON(message) {
    const obj = {};
    message.baseOrder !== undefined && (obj.baseOrder = message.baseOrder ? BaseOrder.toJSON(message.baseOrder) : undefined);
    message.toToken !== undefined && (obj.toToken = message.toToken);
    return obj;
  },
  fromPartial(object) {
    var _object$toToken;
    const message = createBaseSwapOrder();
    message.baseOrder = object.baseOrder !== undefined && object.baseOrder !== null ? BaseOrder.fromPartial(object.baseOrder) : undefined;
    message.toToken = (_object$toToken = object.toToken) !== null && _object$toToken !== void 0 ? _object$toToken : "";
    return message;
  }
};
function createBaseBatch() {
  return {
    bondDid: "",
    blocksRemaining: "",
    nextPublicAlpha: "",
    totalBuyAmount: undefined,
    totalSellAmount: undefined,
    buyPrices: [],
    sellPrices: [],
    buys: [],
    sells: [],
    swaps: []
  };
}
export const Batch = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.bondDid !== "") {
      writer.uint32(10).string(message.bondDid);
    }
    if (message.blocksRemaining !== "") {
      writer.uint32(18).string(message.blocksRemaining);
    }
    if (message.nextPublicAlpha !== "") {
      writer.uint32(26).string(message.nextPublicAlpha);
    }
    if (message.totalBuyAmount !== undefined) {
      Coin.encode(message.totalBuyAmount, writer.uint32(34).fork()).ldelim();
    }
    if (message.totalSellAmount !== undefined) {
      Coin.encode(message.totalSellAmount, writer.uint32(42).fork()).ldelim();
    }
    for (const v of message.buyPrices) {
      DecCoin.encode(v, writer.uint32(50).fork()).ldelim();
    }
    for (const v of message.sellPrices) {
      DecCoin.encode(v, writer.uint32(58).fork()).ldelim();
    }
    for (const v of message.buys) {
      BuyOrder.encode(v, writer.uint32(66).fork()).ldelim();
    }
    for (const v of message.sells) {
      SellOrder.encode(v, writer.uint32(74).fork()).ldelim();
    }
    for (const v of message.swaps) {
      SwapOrder.encode(v, writer.uint32(82).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 = createBaseBatch();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.bondDid = reader.string();
          break;
        case 2:
          message.blocksRemaining = reader.string();
          break;
        case 3:
          message.nextPublicAlpha = reader.string();
          break;
        case 4:
          message.totalBuyAmount = Coin.decode(reader, reader.uint32());
          break;
        case 5:
          message.totalSellAmount = Coin.decode(reader, reader.uint32());
          break;
        case 6:
          message.buyPrices.push(DecCoin.decode(reader, reader.uint32()));
          break;
        case 7:
          message.sellPrices.push(DecCoin.decode(reader, reader.uint32()));
          break;
        case 8:
          message.buys.push(BuyOrder.decode(reader, reader.uint32()));
          break;
        case 9:
          message.sells.push(SellOrder.decode(reader, reader.uint32()));
          break;
        case 10:
          message.swaps.push(SwapOrder.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      bondDid: isSet(object.bondDid) ? String(object.bondDid) : "",
      blocksRemaining: isSet(object.blocksRemaining) ? String(object.blocksRemaining) : "",
      nextPublicAlpha: isSet(object.nextPublicAlpha) ? String(object.nextPublicAlpha) : "",
      totalBuyAmount: isSet(object.totalBuyAmount) ? Coin.fromJSON(object.totalBuyAmount) : undefined,
      totalSellAmount: isSet(object.totalSellAmount) ? Coin.fromJSON(object.totalSellAmount) : undefined,
      buyPrices: Array.isArray(object === null || object === void 0 ? void 0 : object.buyPrices) ? object.buyPrices.map(e => DecCoin.fromJSON(e)) : [],
      sellPrices: Array.isArray(object === null || object === void 0 ? void 0 : object.sellPrices) ? object.sellPrices.map(e => DecCoin.fromJSON(e)) : [],
      buys: Array.isArray(object === null || object === void 0 ? void 0 : object.buys) ? object.buys.map(e => BuyOrder.fromJSON(e)) : [],
      sells: Array.isArray(object === null || object === void 0 ? void 0 : object.sells) ? object.sells.map(e => SellOrder.fromJSON(e)) : [],
      swaps: Array.isArray(object === null || object === void 0 ? void 0 : object.swaps) ? object.swaps.map(e => SwapOrder.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.bondDid !== undefined && (obj.bondDid = message.bondDid);
    message.blocksRemaining !== undefined && (obj.blocksRemaining = message.blocksRemaining);
    message.nextPublicAlpha !== undefined && (obj.nextPublicAlpha = message.nextPublicAlpha);
    message.totalBuyAmount !== undefined && (obj.totalBuyAmount = message.totalBuyAmount ? Coin.toJSON(message.totalBuyAmount) : undefined);
    message.totalSellAmount !== undefined && (obj.totalSellAmount = message.totalSellAmount ? Coin.toJSON(message.totalSellAmount) : undefined);
    if (message.buyPrices) {
      obj.buyPrices = message.buyPrices.map(e => e ? DecCoin.toJSON(e) : undefined);
    } else {
      obj.buyPrices = [];
    }
    if (message.sellPrices) {
      obj.sellPrices = message.sellPrices.map(e => e ? DecCoin.toJSON(e) : undefined);
    } else {
      obj.sellPrices = [];
    }
    if (message.buys) {
      obj.buys = message.buys.map(e => e ? BuyOrder.toJSON(e) : undefined);
    } else {
      obj.buys = [];
    }
    if (message.sells) {
      obj.sells = message.sells.map(e => e ? SellOrder.toJSON(e) : undefined);
    } else {
      obj.sells = [];
    }
    if (message.swaps) {
      obj.swaps = message.swaps.map(e => e ? SwapOrder.toJSON(e) : undefined);
    } else {
      obj.swaps = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$bondDid3, _object$blocksRemaini, _object$nextPublicAlp, _object$buyPrices, _object$sellPrices, _object$buys, _object$sells, _object$swaps;
    const message = createBaseBatch();
    message.bondDid = (_object$bondDid3 = object.bondDid) !== null && _object$bondDid3 !== void 0 ? _object$bondDid3 : "";
    message.blocksRemaining = (_object$blocksRemaini = object.blocksRemaining) !== null && _object$blocksRemaini !== void 0 ? _object$blocksRemaini : "";
    message.nextPublicAlpha = (_object$nextPublicAlp = object.nextPublicAlpha) !== null && _object$nextPublicAlp !== void 0 ? _object$nextPublicAlp : "";
    message.totalBuyAmount = object.totalBuyAmount !== undefined && object.totalBuyAmount !== null ? Coin.fromPartial(object.totalBuyAmount) : undefined;
    message.totalSellAmount = object.totalSellAmount !== undefined && object.totalSellAmount !== null ? Coin.fromPartial(object.totalSellAmount) : undefined;
    message.buyPrices = ((_object$buyPrices = object.buyPrices) === null || _object$buyPrices === void 0 ? void 0 : _object$buyPrices.map(e => DecCoin.fromPartial(e))) || [];
    message.sellPrices = ((_object$sellPrices = object.sellPrices) === null || _object$sellPrices === void 0 ? void 0 : _object$sellPrices.map(e => DecCoin.fromPartial(e))) || [];
    message.buys = ((_object$buys = object.buys) === null || _object$buys === void 0 ? void 0 : _object$buys.map(e => BuyOrder.fromPartial(e))) || [];
    message.sells = ((_object$sells = object.sells) === null || _object$sells === void 0 ? void 0 : _object$sells.map(e => SellOrder.fromPartial(e))) || [];
    message.swaps = ((_object$swaps = object.swaps) === null || _object$swaps === void 0 ? void 0 : _object$swaps.map(e => SwapOrder.fromPartial(e))) || [];
    return message;
  }
};
function createBaseParams() {
  return {
    reservedBondTokens: []
  };
}
export const Params = {
  encode(message, writer = _m0.Writer.create()) {
    for (const v of message.reservedBondTokens) {
      writer.uint32(10).string(v);
    }
    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 = createBaseParams();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.reservedBondTokens.push(reader.string());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      reservedBondTokens: Array.isArray(object === null || object === void 0 ? void 0 : object.reservedBondTokens) ? object.reservedBondTokens.map(e => String(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    if (message.reservedBondTokens) {
      obj.reservedBondTokens = message.reservedBondTokens.map(e => e);
    } else {
      obj.reservedBondTokens = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$reservedBondT;
    const message = createBaseParams();
    message.reservedBondTokens = ((_object$reservedBondT = object.reservedBondTokens) === null || _object$reservedBondT === void 0 ? void 0 : _object$reservedBondT.map(e => e)) || [];
    return message;
  }
};