"use strict";
/*
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RPCQueryAdapter = void 0;
/* eslint-disable no-case-declarations */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const ethers_1 = require("ethers");
const tsyringe_1 = require("tsyringe");
const LazyInjectDecorator_1 = require("../../../core/decorator/LazyInjectDecorator");
const NetworkService_1 = __importDefault(require("../../../app/service/network/NetworkService"));
const LogService_1 = __importDefault(require("../../../app/service/log/LogService"));
const MirrorNodeAdapter_1 = require("../mirror/MirrorNodeAdapter");
const Security_1 = require("../../../domain/context/security/Security");
const BondDetails_1 = require("../../../domain/context/bond/BondDetails");
const Dividend_1 = require("../../../domain/context/equity/Dividend");
const BigDecimal_1 = __importDefault(require("../../../domain/context/shared/BigDecimal"));
const HederaId_1 = require("../../../domain/context/shared/HederaId");
const asset_tokenization_contracts_1 = require("@hashgraph/asset-tokenization-contracts");
const ScheduledSnapshot_1 = require("../../../domain/context/security/ScheduledSnapshot");
const VotingRights_1 = require("../../../domain/context/equity/VotingRights");
const Coupon_1 = require("../../../domain/context/bond/Coupon");
const EquityDetails_1 = require("../../../domain/context/equity/EquityDetails");
const DividendType_1 = require("../../../domain/context/equity/DividendType");
const SecurityType_1 = require("../../../domain/context/factory/SecurityType");
const Constants_1 = require("../../../core/Constants");
const RegulationType_1 = require("../../../domain/context/factory/RegulationType");
const ScheduledBalanceAdjustment_1 = require("../../../domain/context/equity/ScheduledBalanceAdjustment");
const DividendFor_1 = require("../../../domain/context/equity/DividendFor");
const VotingFor_1 = require("../../../domain/context/equity/VotingFor");
const Kyc_1 = require("../../../domain/context/kyc/Kyc");
const KycAccountData_1 = require("../../../domain/context/kyc/KycAccountData");
const Clearing_1 = require("../../../domain/context/security/Clearing");
const Hold_1 = require("../../../domain/context/security/Hold");
const CouponAmountFor_1 = require("../../../domain/context/bond/CouponAmountFor");
const PrincipalFor_1 = require("../../../domain/context/bond/PrincipalFor");
const DividendAmountFor_1 = require("../../../domain/context/equity/DividendAmountFor");
const LOCAL_JSON_RPC_RELAY_URL = 'http://127.0.0.1:7546/api';
let RPCQueryAdapter = class RPCQueryAdapter {
    constructor(networkService, mirrorNode) {
        this.networkService = networkService;
        this.mirrorNode = mirrorNode;
    }
    async init(urlRpcProvider, apiKey) {
        const url = urlRpcProvider
            ? apiKey
                ? urlRpcProvider + apiKey
                : urlRpcProvider
            : LOCAL_JSON_RPC_RELAY_URL;
        this.provider = new ethers_1.ethers.providers.JsonRpcProvider(url);
        LogService_1.default.logTrace('RPC Query Adapter Initialized on: ', url);
        return this.networkService.environment;
    }
    connect(fac, address) {
        return fac.connect(address, this.provider);
    }
    async balanceOf(address, target) {
        LogService_1.default.logTrace(`Getting balance of ${address.toString()} security for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).balanceOf(target.toString());
    }
    async balanceOfByPartition(address, target, partitionId) {
        LogService_1.default.logTrace(`Getting balance of ${address.toString()} security for partition ${partitionId} for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).balanceOfByPartition(partitionId, target.toString());
    }
    async balanceOfAtSnapshot(address, target, snapshotId) {
        LogService_1.default.logTrace(`Getting balance of ${address.toString()} security at snapshot ${snapshotId.toString()} for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).balanceOfAtSnapshot(snapshotId, target.toString());
    }
    async balanceOfAtSnapshotByPartition(address, target, partitionId, snapshotId) {
        LogService_1.default.logTrace(`Getting balance of ${address.toString()} security for partition ${partitionId} at snapshot ${snapshotId.toString()} for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).balanceOfAtSnapshotByPartition(partitionId, snapshotId, target.toString());
    }
    async getNounceFor(address, target) {
        LogService_1.default.logTrace(`Getting Nounce`);
        return await this.connect(asset_tokenization_contracts_1.ProtectedPartitionsFacet__factory, address.toString()).getNounceFor(target.toString());
    }
    async partitionsOf(address, targetId) {
        LogService_1.default.logTrace(`Getting partitions for account ${targetId.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).partitionsOf(targetId.toString());
    }
    async partitionsOfAtSnapshot(address, targetId, snapshotId) {
        LogService_1.default.logTrace(`Getting partitions for account ${targetId.toString()} at snapshot ${snapshotId.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).partitionsOfAtSnapshot(snapshotId, targetId.toString());
    }
    async totalSupply(address) {
        LogService_1.default.logTrace(`Getting total supply of ${address.toString()} security`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).totalSupply();
    }
    async totalSupplyAtSnapshot(address, snapshotId) {
        LogService_1.default.logTrace(`Getting total supply of ${address.toString()} security at snapshot ${snapshotId.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).totalSupplyAtSnapshot(snapshotId);
    }
    async getRolesFor(address, target, start, end) {
        LogService_1.default.logTrace(`Getting roles for ${target.toString()} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.AccessControlFacet__factory, address.toString()).getRolesFor(target.toString(), start, end);
    }
    async getRoleMembers(address, role, start, end) {
        LogService_1.default.logTrace(`Getting roles members for role ${role} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.AccessControlFacet__factory, address.toString()).getRoleMembers(role, start, end);
    }
    async getRoleCountFor(address, target) {
        LogService_1.default.logTrace(`Getting role count for ${target.toString()}`);
        const roleCount = await this.connect(asset_tokenization_contracts_1.AccessControlFacet__factory, address.toString()).getRoleCountFor(target.toString());
        return roleCount.toNumber();
    }
    async getRoleMemberCount(address, role) {
        LogService_1.default.logTrace(`Getting role member count for ${role}`);
        const membersCount = await this.connect(asset_tokenization_contracts_1.AccessControlFacet__factory, address.toString()).getRoleMemberCount(role);
        return membersCount.toNumber();
    }
    async hasRole(address, target, role) {
        LogService_1.default.logTrace(`Getting if the account ${target.toString()} has the role ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.AccessControlFacet__factory, address.toString()).hasRole(role, target.toString());
    }
    async getSecurity(address) {
        LogService_1.default.logTrace(`Requesting security details for security: ${address.toString()}`);
        const erc20Metadata = await this.connect(asset_tokenization_contracts_1.ERC20Facet__factory, address.toString()).getERC20Metadata();
        const totalSupply = await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).totalSupply();
        const maxSupply = await this.connect(asset_tokenization_contracts_1.CapFacet__factory, address.toString()).getMaxSupply();
        const isWhiteList = await this.connect(asset_tokenization_contracts_1.ControlListFacet__factory, address.toString()).getControlListType();
        const erc20VotesActivated = await this.connect(asset_tokenization_contracts_1.ERC20Votes__factory, address.toString()).isActivated();
        const isControllable = await this.connect(asset_tokenization_contracts_1.ERC1644Facet__factory, address.toString()).isControllable();
        const arePartitionsProtected = await this.connect(asset_tokenization_contracts_1.ProtectedPartitionsFacet__factory, address.toString()).arePartitionsProtected();
        const clearingActive = await this.connect(asset_tokenization_contracts_1.ClearingActionsFacet__factory, address.toString()).isClearingActivated();
        const internalKycActivated = await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).isInternalKycActivated();
        const isMultiPartition = await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).isMultiPartition();
        const isIssuable = await this.connect(asset_tokenization_contracts_1.ERC1594Facet__factory, address.toString()).isIssuable();
        const isPaused = await this.connect(asset_tokenization_contracts_1.PauseFacet__factory, address.toString()).isPaused();
        const regulationInfo = await this.connect(asset_tokenization_contracts_1.Security__factory, address.toString()).getSecurityRegulationData();
        const diamondAddress = await this.mirrorNode.getHederaIdfromContractAddress(address.toString());
        const regulation = {
            type: RegulationType_1.CastRegulationType.fromNumber(regulationInfo.regulationData.regulationType),
            subType: RegulationType_1.CastRegulationSubType.fromNumber(regulationInfo.regulationData.regulationSubType),
            dealSize: regulationInfo.regulationData.dealSize.toString(),
            accreditedInvestors: RegulationType_1.CastAccreditedInvestors.fromNumber(regulationInfo.regulationData.accreditedInvestors),
            maxNonAccreditedInvestors: regulationInfo.regulationData.maxNonAccreditedInvestors.toNumber(),
            manualInvestorVerification: RegulationType_1.CastManualInvestorVerification.fromNumber(regulationInfo.regulationData.manualInvestorVerification),
            internationalInvestors: RegulationType_1.CastInternationalInvestorscation.fromNumber(regulationInfo.regulationData.internationalInvestors),
            resaleHoldPeriod: RegulationType_1.CastResaleHoldPeriodorscation.fromNumber(regulationInfo.regulationData.resaleHoldPeriod),
        };
        return new Security_1.Security({
            name: erc20Metadata.info.name,
            symbol: erc20Metadata.info.symbol,
            isin: erc20Metadata.info.isin,
            type: SecurityType_1.CastSecurityType.fromNumber(erc20Metadata.securityType),
            decimals: erc20Metadata.info.decimals,
            isWhiteList: isWhiteList,
            erc20VotesActivated: erc20VotesActivated,
            isControllable: isControllable,
            arePartitionsProtected: arePartitionsProtected,
            clearingActive: clearingActive,
            internalKycActivated: internalKycActivated,
            isMultiPartition: isMultiPartition,
            isIssuable: isIssuable,
            totalSupply: new BigDecimal_1.default(totalSupply.toString()),
            maxSupply: new BigDecimal_1.default(maxSupply.toString()),
            diamondAddress: HederaId_1.HederaId.from(diamondAddress),
            evmDiamondAddress: address,
            paused: isPaused,
            regulationType: RegulationType_1.CastRegulationType.fromNumber(regulationInfo.regulationData.regulationType),
            regulationsubType: RegulationType_1.CastRegulationSubType.fromNumber(regulationInfo.regulationData.regulationSubType),
            regulation: regulation,
            isCountryControlListWhiteList: regulationInfo.additionalSecurityData.countriesControlListType,
            countries: regulationInfo.additionalSecurityData.listOfCountries,
            info: regulationInfo.additionalSecurityData.info,
        });
    }
    async getEquityDetails(address) {
        LogService_1.default.logTrace(`Requesting equity details for equity: ${address.toString()}`);
        const res = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getEquityDetails();
        return new EquityDetails_1.EquityDetails(res.votingRight, res.informationRight, res.liquidationRight, res.subscriptionRight, res.conversionRight, res.redemptionRight, res.putRight, DividendType_1.CastDividendType.fromNumber(res.dividendRight), res.currency, new BigDecimal_1.default(res.nominalValue.toString()), res.nominalValueDecimals);
    }
    async getBondDetails(address) {
        LogService_1.default.logTrace(`Requesting bond details for bond: ${address.toString()}`);
        const res = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getBondDetails();
        return new BondDetails_1.BondDetails(res.currency, new BigDecimal_1.default(res.nominalValue.toString()), res.nominalValueDecimals, res.startingDate.toNumber(), res.maturityDate.toNumber());
    }
    async getControlListMembers(address, start, end) {
        LogService_1.default.logTrace(`Getting control list members from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.ControlListFacet__factory, address.toString()).getControlListMembers(start, end);
    }
    async getControlListCount(address) {
        LogService_1.default.logTrace(`Getting control list count`);
        const controlListCount = await this.connect(asset_tokenization_contracts_1.ControlListFacet__factory, address.toString()).getControlListCount();
        return controlListCount.toNumber();
    }
    async getControlListType(address) {
        LogService_1.default.logTrace(`Getting control list type`);
        return await this.connect(asset_tokenization_contracts_1.ControlListFacet__factory, address.toString()).getControlListType();
    }
    async isAccountInControlList(address, target) {
        LogService_1.default.logTrace(`Getting if account ${target.toString()} is in control list`);
        return await this.connect(asset_tokenization_contracts_1.ControlListFacet__factory, address.toString()).isInControlList(target.toString());
    }
    async getDividendsFor(address, target, dividend) {
        LogService_1.default.logTrace(`Getting dividends for`);
        const dividendFor = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getDividendsFor(dividend, target.toString());
        return new DividendFor_1.DividendFor(new BigDecimal_1.default(dividendFor.tokenBalance), dividendFor.decimals);
    }
    async getDividendAmountFor(address, target, dividend) {
        LogService_1.default.logTrace(`Getting dividends amount for`);
        const dividendAmountFor = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getDividendAmountFor(dividend, target.toString());
        return new DividendAmountFor_1.DividendAmountFor(dividendAmountFor.numerator.toString(), dividendAmountFor.denominator.toString(), dividendAmountFor.recordDateReached);
    }
    async getDividends(address, dividend) {
        LogService_1.default.logTrace(`Getting dividends`);
        const dividendInfo = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getDividends(dividend);
        return new Dividend_1.Dividend(new BigDecimal_1.default(dividendInfo.dividend.amount.toString()), dividendInfo.dividend.amountDecimals, dividendInfo.dividend.recordDate.toNumber(), dividendInfo.dividend.executionDate.toNumber(), dividendInfo.snapshotId.toNumber());
    }
    async getDividendsCount(address) {
        LogService_1.default.logTrace(`Getting dividends count`);
        const dividendsCount = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getDividendsCount();
        return dividendsCount.toNumber();
    }
    async getVotingFor(address, target, voting) {
        LogService_1.default.logTrace(`Getting voting for`);
        const votingFor = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getVotingFor(voting, target.toString());
        return new VotingFor_1.VotingFor(new BigDecimal_1.default(votingFor.tokenBalance), votingFor.decimals);
    }
    async getVoting(address, voting) {
        LogService_1.default.logTrace(`Getting voting`);
        const votingInfo = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getVoting(voting);
        return new VotingRights_1.VotingRights(votingInfo.voting.recordDate.toNumber(), votingInfo.voting.data, votingInfo.snapshotId.toNumber());
    }
    async getVotingsCount(address) {
        LogService_1.default.logTrace(`Getting votings count`);
        const votingsCount = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getVotingCount();
        return votingsCount.toNumber();
    }
    async getCouponFor(address, target, coupon) {
        LogService_1.default.logTrace(`Getting Coupon for`);
        const couponFor = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getCouponFor(coupon, target.toString());
        return couponFor.tokenBalance;
    }
    async getCouponAmountFor(address, target, coupon) {
        LogService_1.default.logTrace(`Getting Coupon Amount for`);
        const couponAmountFor = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getCouponAmountFor(coupon, target.toString());
        return new CouponAmountFor_1.CouponAmountFor(couponAmountFor.numerator.toString(), couponAmountFor.denominator.toString(), couponAmountFor.recordDateReached);
    }
    async getPrincipalFor(address, target) {
        LogService_1.default.logTrace(`Getting Principal for`);
        const principalFor = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getPrincipalFor(target.toString());
        return new PrincipalFor_1.PrincipalFor(principalFor.numerator.toString(), principalFor.denominator.toString());
    }
    async getCoupon(address, coupon) {
        LogService_1.default.logTrace(`Getting Coupon`);
        const couponInfo = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getCoupon(coupon);
        return new Coupon_1.Coupon(couponInfo.coupon.recordDate.toNumber(), couponInfo.coupon.executionDate.toNumber(), new BigDecimal_1.default(couponInfo.coupon.rate.toString()), couponInfo.coupon.rateDecimals, couponInfo.snapshotId.toNumber());
    }
    async getCouponCount(address) {
        LogService_1.default.logTrace(`Getting Coupon count`);
        const couponCount = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getCouponCount();
        return couponCount.toNumber();
    }
    async isPaused(address) {
        LogService_1.default.logTrace(`Checking if the security: ${address.toString()} is paused`);
        return await this.connect(asset_tokenization_contracts_1.PauseFacet__factory, address.toString()).isPaused();
    }
    async arePartitionsProtected(address) {
        LogService_1.default.logTrace(`Checking if the security: ${address.toString()} partitions are protected`);
        return await this.connect(asset_tokenization_contracts_1.ProtectedPartitionsFacet__factory, address.toString()).arePartitionsProtected();
    }
    async canTransferByPartition(address, sourceId, targetId, amount, partitionId, data, operatorData, operatorId) {
        LogService_1.default.logTrace(`Checking can transfer by partition`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).canTransferByPartition(sourceId.toString(), targetId.toString(), partitionId, amount.toBigNumber(), data, operatorData, {
            from: operatorId,
        });
    }
    async canTransfer(address, targetId, amount, data, operatorId) {
        LogService_1.default.logTrace(`Checking can transfer`);
        return await this.connect(asset_tokenization_contracts_1.ERC1594Facet__factory, address.toString()).canTransfer(targetId.toString(), amount.toBigNumber(), data, {
            from: operatorId,
        });
    }
    async canRedeemByPartition(address, sourceId, amount, partitionId, data, operatorData, operatorId) {
        LogService_1.default.logTrace(`Checking can redeem`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).canRedeemByPartition(sourceId.toString(), partitionId, amount.toBigNumber(), data, operatorData, {
            from: operatorId,
        });
    }
    async getDocument(address, name) {
        LogService_1.default.logTrace(`Getting document: ${name}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1643Facet__factory, address.toString()).getDocument(name);
    }
    async getAllDocuments(address) {
        LogService_1.default.logTrace(`Getting all documents`);
        return await this.connect(asset_tokenization_contracts_1.ERC1643Facet__factory, address.toString()).getAllDocuments();
    }
    async isOperatorForPartition(address, partitionId, operator, target) {
        LogService_1.default.logTrace(`Checking if the account: ${operator.toString()} is operator for ${target.toString()} and partition ${partitionId}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).isOperatorForPartition(partitionId, operator.toString(), target.toString());
    }
    async isOperator(address, operator, target) {
        LogService_1.default.logTrace(`Checking if the account: ${operator.toString()} is operator for ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).isOperator(operator.toString(), target.toString());
    }
    async getScheduledSnapshots(address, start, end) {
        LogService_1.default.logTrace(`Getting scheduled snapshots from ${start} to ${end}`);
        const snapshots = await this.connect(asset_tokenization_contracts_1.ScheduledSnapshotsFacet__factory, address.toString()).getScheduledSnapshots(start, end);
        return snapshots.map((s) => new ScheduledSnapshot_1.ScheduledSnapshot(s.scheduledTimestamp, s.data));
    }
    async scheduledSnapshotCount(address) {
        LogService_1.default.logTrace(`Getting scheduled snapshots count`);
        const scheduledSnapshotsCount = await this.connect(asset_tokenization_contracts_1.ScheduledSnapshotsFacet__factory, address.toString()).scheduledSnapshotCount();
        return scheduledSnapshotsCount.toNumber();
    }
    async getMaxSupply(address) {
        LogService_1.default.logTrace(`Getting max supply for ${address.toString()} security`);
        return await this.connect(asset_tokenization_contracts_1.CapFacet__factory, address.toString()).getMaxSupply();
    }
    async getMaxSupplyByPartition(address, partitionId) {
        LogService_1.default.logTrace(`Getting max supply by partition for ${address.toString()} security`);
        return await this.connect(asset_tokenization_contracts_1.CapFacet__factory, address.toString()).getMaxSupplyByPartition(partitionId);
    }
    async getTotalSupplyByPartition(address, partitionId) {
        LogService_1.default.logTrace(`Getting max supply by partition for ${address.toString()} security`);
        return await this.connect(asset_tokenization_contracts_1.ERC1410ReadFacet__factory, address.toString()).totalSupplyByPartition(partitionId);
    }
    async getRegulationDetails(type, subType, factoryAddress) {
        LogService_1.default.logTrace(`Getting regulation for type ${type.toString()} and subtype ${subType.toString()} in factory ${factoryAddress.toString()}`);
        const res = await this.connect(asset_tokenization_contracts_1.Factory__factory, factoryAddress.toString()).getAppliedRegulationData(type, subType);
        const regulation = {
            type: RegulationType_1.CastRegulationType.fromNumber(res.regulationType),
            subType: RegulationType_1.CastRegulationSubType.fromNumber(res.regulationSubType),
            dealSize: res.dealSize.toString(),
            accreditedInvestors: RegulationType_1.CastAccreditedInvestors.fromNumber(res.accreditedInvestors),
            maxNonAccreditedInvestors: res.maxNonAccreditedInvestors.toNumber(),
            manualInvestorVerification: RegulationType_1.CastManualInvestorVerification.fromNumber(res.manualInvestorVerification),
            internationalInvestors: RegulationType_1.CastInternationalInvestorscation.fromNumber(res.internationalInvestors),
            resaleHoldPeriod: RegulationType_1.CastResaleHoldPeriodorscation.fromNumber(res.resaleHoldPeriod),
        };
        return regulation;
    }
    async getLockedBalanceOf(address, target) {
        LogService_1.default.logTrace(`Getting locked balance of ${address.toString()} security for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.LockFacet__factory, address.toString()).getLockedAmountForByPartition(Constants_1._PARTITION_ID_1, target.toString());
    }
    async getLockCount(address, target) {
        LogService_1.default.logTrace(`Getting lock count of ${address.toString()} security for the account ${target.toString()}`);
        const count = await this.connect(asset_tokenization_contracts_1.LockFacet__factory, address.toString()).getLockCountForByPartition(Constants_1._PARTITION_ID_1, target.toString());
        return count.toNumber();
    }
    async getLocksId(address, target, start, end) {
        LogService_1.default.logTrace(`Getting locks id of ${address.toString()} security for the account ${target.toString()} from ${start.toString()} to ${end.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.LockFacet__factory, address.toString()).getLocksIdForByPartition(Constants_1._PARTITION_ID_1, target.toString(), start, end);
    }
    async getLock(address, target, lockId) {
        LogService_1.default.logTrace(`Getting lock ${lockId.toString()} of ${address.toString()} security for the account ${target.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.LockFacet__factory, address.toString()).getLockForByPartition(Constants_1._PARTITION_ID_1, target.toString(), lockId);
    }
    async getConfigInfo(address) {
        LogService_1.default.logTrace(`Getting config info for ${address.toString()}`);
        const configInfo = await this.connect(asset_tokenization_contracts_1.DiamondFacet__factory, address.toString()).getConfigInfo();
        return [
            configInfo.resolver_.toString(),
            configInfo.configurationId_,
            configInfo.version_.toNumber(),
        ];
    }
    async getScheduledBalanceAdjustment(address, balanceAdjustmentId) {
        LogService_1.default.logTrace(`Getting scheduled balance adjustment`);
        const scheduledBalanceAdjustmentInfo = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getScheduledBalanceAdjustment(balanceAdjustmentId);
        return new ScheduledBalanceAdjustment_1.ScheduledBalanceAdjustment(scheduledBalanceAdjustmentInfo.executionDate.toNumber(), scheduledBalanceAdjustmentInfo.factor.toNumber(), scheduledBalanceAdjustmentInfo.decimals);
    }
    async getScheduledBalanceAdjustmentCount(address) {
        LogService_1.default.logTrace(`Getting scheduled balance adjustment count`);
        const scheduledBalanceAdjustmentCount = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getScheduledBalanceAdjustmentCount();
        return scheduledBalanceAdjustmentCount.toNumber();
    }
    async getHeldAmountFor(address, targetId) {
        LogService_1.default.logTrace(`Getting Held Amount For ${targetId}`);
        const heldAmountFor = await this.connect(asset_tokenization_contracts_1.HoldReadFacet__factory, address.toString()).getHeldAmountFor(targetId.toString());
        return heldAmountFor.toNumber();
    }
    async getHeldAmountForByPartition(address, partitionId, targetId) {
        LogService_1.default.logTrace(`Getting Held Amount For ${targetId} by partition ${partitionId}`);
        const heldAmountForByPartition = await this.connect(asset_tokenization_contracts_1.HoldReadFacet__factory, address.toString()).getHeldAmountForByPartition(partitionId, targetId.toString());
        return heldAmountForByPartition.toNumber();
    }
    async getHoldCountForByPartition(address, partitionId, targetId) {
        LogService_1.default.logTrace(`Getting Hold Count For ${address} by partition ${partitionId}`);
        const holdCountForByPartition = await this.connect(asset_tokenization_contracts_1.HoldReadFacet__factory, address.toString()).getHoldCountForByPartition(partitionId, targetId.toString());
        return holdCountForByPartition.toNumber();
    }
    async getHoldsIdForByPartition(address, partitionId, target, start, end) {
        LogService_1.default.logTrace(`Getting Holds Id For ${target} by partition ${partitionId} from ${start} to ${end}`);
        const holdsIdForByPartition = await this.connect(asset_tokenization_contracts_1.HoldReadFacet__factory, address.toString()).getHoldsIdForByPartition(partitionId, target.toString(), start, end);
        return holdsIdForByPartition.map((id) => id.toNumber());
    }
    async getHoldForByPartition(address, partitionId, targetId, holdId) {
        LogService_1.default.logTrace(`Getting hold details for ${targetId} id ${holdId} by partition ${partitionId}`);
        const hold = await this.connect(asset_tokenization_contracts_1.HoldReadFacet__factory, address.toString()).getHoldForByPartition({
            partition: partitionId,
            tokenHolder: targetId.toString(),
            holdId,
        });
        return new Hold_1.HoldDetails(hold.expirationTimestamp_.toNumber(), new BigDecimal_1.default(hold.amount_.toString()), hold.escrow_, targetId.toString(), hold.destination_, hold.data_, hold.operatorData_);
    }
    async getRevocationRegistryAddress(address) {
        LogService_1.default.logTrace(`Getting Revocation Registry Address of ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SsiManagementFacet__factory, address.toString()).getRevocationRegistryAddress();
    }
    async getIssuerListCount(address) {
        LogService_1.default.logTrace(`Getting Issuer List Count of ${address.toString()}`);
        const count = await this.connect(asset_tokenization_contracts_1.SsiManagementFacet__factory, address.toString()).getIssuerListCount();
        return count.toNumber();
    }
    async getIssuerListMembers(address, start, end) {
        LogService_1.default.logTrace(`Getting Issuer List Count of ${address.toString()} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.SsiManagementFacet__factory, address.toString()).getIssuerListMembers(start, end);
    }
    async isIssuer(address, issuer) {
        LogService_1.default.logTrace(`Getting if ${issuer.toString()} is an Issuer`);
        return await this.connect(asset_tokenization_contracts_1.SsiManagementFacet__factory, address.toString()).isIssuer(issuer.toString());
    }
    async getKycFor(address, targetId) {
        LogService_1.default.logTrace(`Getting KYC details for ${targetId}}`);
        const kycData = await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).getKycFor(targetId.toString());
        return new Kyc_1.Kyc(kycData.validFrom.toString(), kycData.validTo.toString(), kycData.vcId, kycData.issuer, kycData.status);
    }
    async getKycStatusFor(address, targetId) {
        LogService_1.default.logTrace(`Getting KYC status for ${targetId}}`);
        const kycData = await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).getKycStatusFor(targetId.toString());
        return kycData;
    }
    async getKycAccountsData(address, kycStatus, start, end) {
        LogService_1.default.logTrace(`Getting accounts data with KYC status ${kycStatus}`);
        const [accounts, kycAccountsData] = await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).getKycAccountsData(kycStatus, start, end);
        return accounts.map((account, index) => new KycAccountData_1.KycAccountData(account, kycAccountsData[index].validFrom.toString(), kycAccountsData[index].validTo.toString(), kycAccountsData[index].vcId, kycAccountsData[index].issuer, kycAccountsData[index].status));
    }
    async getKycAccountsCount(address, kycStatus) {
        LogService_1.default.logTrace(`Getting count of accounts with KYC status ${kycStatus}}`);
        const kycAccountsCount = await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).getKycAccountsCount(kycStatus);
        return kycAccountsCount.toNumber();
    }
    async getClearedAmountFor(address, targetId) {
        LogService_1.default.logTrace(`Getting Cleared Amount For ${targetId}`);
        const clearedAmountFor = await this.connect(asset_tokenization_contracts_1.ClearingReadFacet__factory, address.toString()).getClearedAmountFor(targetId.toString());
        return clearedAmountFor.toNumber();
    }
    async getClearedAmountForByPartition(address, partitionId, targetId) {
        LogService_1.default.logTrace(`Getting Cleared Amount For ${targetId} by partition ${partitionId}`);
        const clearedAmountForByPartition = await this.connect(asset_tokenization_contracts_1.ClearingReadFacet__factory, address.toString()).getClearedAmountForByPartition(partitionId, targetId.toString());
        return clearedAmountForByPartition.toNumber();
    }
    async getClearingCountForByPartition(address, partitionId, targetId, clearingOperationType) {
        LogService_1.default.logTrace(`Getting Clearing Count For ${address} by partition ${partitionId}`);
        const clearingCountForByPartition = await this.connect(asset_tokenization_contracts_1.ClearingReadFacet__factory, address.toString()).getClearingCountForByPartition(partitionId, targetId.toString(), Clearing_1.CastClearingOperationType.toNumber(clearingOperationType));
        return clearingCountForByPartition.toNumber();
    }
    async getClearingsIdForByPartition(address, partitionId, target, clearingOperationType, start, end) {
        LogService_1.default.logTrace(`Getting Clearings Id For ${target} by partition ${partitionId} from ${start} to ${end}`);
        const clearingsIdForByPartition = await this.connect(asset_tokenization_contracts_1.ClearingReadFacet__factory, address.toString()).getClearingsIdForByPartition(partitionId, target.toString(), Clearing_1.CastClearingOperationType.toNumber(clearingOperationType), start, end);
        return clearingsIdForByPartition.map((id) => id.toNumber());
    }
    async getClearingCreateHoldForByPartition(address, partitionId, targetId, clearingId) {
        LogService_1.default.logTrace(`Getting Clearing Create Hold details for ${targetId} id ${clearingId} by partition ${partitionId}`);
        const clearing = await this.connect(asset_tokenization_contracts_1.ClearingHoldCreationFacet__factory, address.toString()).getClearingCreateHoldForByPartition(partitionId, targetId.toString(), clearingId);
        return new Clearing_1.ClearingHoldCreation(new BigDecimal_1.default(clearing.amount.toString()), clearing.expirationTimestamp.toNumber(), clearing.data, clearing.operatorData, clearing.holdEscrow, clearing.holdExpirationTimestamp.toNumber(), clearing.holdTo, clearing.holdData);
    }
    async getClearingRedeemForByPartition(address, partitionId, targetId, clearingId) {
        LogService_1.default.logTrace(`Getting Clearing Redeem details for ${targetId} id ${clearingId} by partition ${partitionId}`);
        const clearing = await this.connect(asset_tokenization_contracts_1.ClearingRedeemFacet__factory, address.toString()).getClearingRedeemForByPartition(partitionId, targetId.toString(), clearingId);
        return new Clearing_1.ClearingRedeem(new BigDecimal_1.default(clearing.amount.toString()), clearing.expirationTimestamp.toNumber(), clearing.data, clearing.operatorData);
    }
    async getClearingTransferForByPartition(address, partitionId, targetId, clearingId) {
        LogService_1.default.logTrace(`Getting Clearing Transfer details for ${targetId} id ${clearingId} by partition ${partitionId}`);
        const clearing = await this.connect(asset_tokenization_contracts_1.ClearingTransferFacet__factory, address.toString()).getClearingTransferForByPartition(partitionId, targetId.toString(), clearingId);
        return new Clearing_1.ClearingTransfer(new BigDecimal_1.default(clearing.amount.toString()), clearing.expirationTimestamp.toNumber(), clearing.destination, clearing.data, clearing.operatorData);
    }
    async isClearingActivated(address) {
        LogService_1.default.logTrace(`Getting if clearing is activated to security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ClearingActionsFacet__factory, address.toString()).isClearingActivated();
    }
    async isExternalPause(address, externalPauseAddress) {
        LogService_1.default.logTrace(`Checking if the address ${externalPauseAddress.toString()} is a external pause for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalPauseManagementFacet__factory, address.toString()).isExternalPause(externalPauseAddress.toString());
    }
    async getExternalPausesCount(address) {
        LogService_1.default.logTrace(`Getting External Pauses Count for ${address.toString()}`);
        const getExternalPausesCount = await this.connect(asset_tokenization_contracts_1.ExternalPauseManagementFacet__factory, address.toString()).getExternalPausesCount();
        return getExternalPausesCount.toNumber();
    }
    async getExternalPausesMembers(address, start, end) {
        LogService_1.default.logTrace(`Getting External Pauses Members For security ${address.toString()} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalPauseManagementFacet__factory, address.toString()).getExternalPausesMembers(start, end);
    }
    async isPausedMock(address) {
        LogService_1.default.logTrace(`Checking if the external pause mock contract: ${address.toString()} is paused`);
        return await this.connect(asset_tokenization_contracts_1.MockedExternalPause__factory, address.toString()).isPaused();
    }
    async isExternalControlList(address, externalControlListAddress) {
        LogService_1.default.logTrace(`Checking if the address ${externalControlListAddress.toString()} is a external control list for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalControlListManagementFacet__factory, address.toString()).isExternalControlList(externalControlListAddress.toString());
    }
    async getExternalControlListsCount(address) {
        LogService_1.default.logTrace(`Getting External Control Lists Count for ${address.toString()}`);
        const getExternalPausesCount = await this.connect(asset_tokenization_contracts_1.ExternalControlListManagementFacet__factory, address.toString()).getExternalControlListsCount();
        return getExternalPausesCount.toNumber();
    }
    async getExternalControlListsMembers(address, start, end) {
        LogService_1.default.logTrace(`Getting External Control Lists Members For security ${address.toString()} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalControlListManagementFacet__factory, address.toString()).getExternalControlListsMembers(start, end);
    }
    async isAuthorizedBlackListMock(address, targetId) {
        LogService_1.default.logTrace(`Checking if address ${targetId.toString()} is authorized in external black list ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.MockedBlacklist__factory, address.toString()).isAuthorized(targetId.toString());
    }
    async isAuthorizedWhiteListMock(address, targetId) {
        LogService_1.default.logTrace(`Checking if address ${targetId.toString()} is authorized in external white list ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.MockedWhitelist__factory, address.toString()).isAuthorized(targetId.toString());
    }
    async isExternalKycList(address, externalKycListAddress) {
        LogService_1.default.logTrace(`Checking if the address ${externalKycListAddress.toString()} is a external kyc list for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory, address.toString()).isExternalKycList(externalKycListAddress.toString());
    }
    async getExternalKycListsCount(address) {
        LogService_1.default.logTrace(`Getting External Kyc Lists Count for ${address.toString()}`);
        const getExternalKycListsCount = await this.connect(asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory, address.toString()).getExternalKycListsCount();
        return getExternalKycListsCount.toNumber();
    }
    async getExternalKycListsMembers(address, start, end) {
        LogService_1.default.logTrace(`Getting External Kyc Lists Members For security ${address.toString()} from ${start} to ${end}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory, address.toString()).getExternalKycListsMembers(start, end);
    }
    async isExternallyGranted(address, kycStatus, targetId) {
        LogService_1.default.logTrace(`Checking if the address ${targetId.toString()} has the status '${kycStatus}' for the contract: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ExternalKycListManagementFacet__factory, address.toString()).isExternallyGranted(targetId.toString(), kycStatus);
    }
    async isInternalKycActivated(address) {
        LogService_1.default.logTrace(`Checking if the internal kyc is activated for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.KycFacet__factory, address.toString()).isInternalKycActivated();
    }
    async getKycStatusMock(address, targetId) {
        LogService_1.default.logTrace(`Getting Kyc status for account ${targetId}} for the mock contract ${address.toString()}`);
        const kycStatus = await this.connect(asset_tokenization_contracts_1.MockedExternalKycList__factory, address.toString()).getKycStatus(targetId.toString());
        return kycStatus;
    }
    async onchainID(address) {
        LogService_1.default.logTrace(`Getting OnchainID for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC3643ReadFacet__factory, address.toString()).onchainID();
    }
    async identityRegistry(address) {
        LogService_1.default.logTrace(`Getting IdentityRegistry for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC3643ReadFacet__factory, address.toString()).identityRegistry();
    }
    async compliance(address) {
        LogService_1.default.logTrace(`Getting Compliance for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ERC3643ReadFacet__factory, address.toString()).compliance();
    }
    async getFrozenPartialTokens(address, targetId) {
        LogService_1.default.logTrace(`Getting frozen partial tokens for account ${targetId}} for the mock contract ${address.toString()}`);
        const frozenTokens = await this.connect(asset_tokenization_contracts_1.FreezeFacet__factory, address.toString()).getFrozenTokens(targetId.toString());
        return frozenTokens.toNumber();
    }
    async isAddressRecovered(address, targetId) {
        LogService_1.default.logTrace(`Getting recovery status of ${targetId}`);
        const isAddressRecovered = await this.connect(asset_tokenization_contracts_1.ERC3643ReadFacet__factory, address.toString()).isAddressRecovered(targetId.toString());
        return isAddressRecovered;
    }
    async getTokenHoldersAtSnapshot(address, snapshotId, start, end) {
        LogService_1.default.logTrace(`Getting token holders at snapshot ${snapshotId} for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).getTokenHoldersAtSnapshot(snapshotId, start, end);
    }
    async getTotalTokenHoldersAtSnapshot(address, snapshotId) {
        LogService_1.default.logTrace(`Getting total token holders at snapshot ${snapshotId} for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).getTotalTokenHoldersAtSnapshot(snapshotId);
        return total.toNumber();
    }
    async getCouponHolders(address, couponId, start, end) {
        LogService_1.default.logTrace(`Getting coupon holders for coupon ${couponId} for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getCouponHolders(couponId, start, end);
    }
    async getTotalCouponHolders(address, couponId) {
        LogService_1.default.logTrace(`Getting total coupon holders for coupon ${couponId} for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.BondRead__factory, address.toString()).getTotalCouponHolders(couponId);
        return total.toNumber();
    }
    async getDividendHolders(address, dividendId, start, end) {
        LogService_1.default.logTrace(`Getting dividend holders for dividend ${dividendId} for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getDividendHolders(dividendId, start, end);
    }
    async getTotalDividendHolders(address, dividendId) {
        LogService_1.default.logTrace(`Getting total dividend holders for dividend ${dividendId} for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getTotalDividendHolders(dividendId);
        return total.toNumber();
    }
    async getVotingHolders(address, voteId, start, end) {
        LogService_1.default.logTrace(`Getting voting holders for vote ${voteId} for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getVotingHolders(voteId, start, end);
    }
    async getTotalVotingHolders(address, voteId) {
        LogService_1.default.logTrace(`Getting total voting holders for vote ${voteId} for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.Equity__factory, address.toString()).getTotalVotingHolders(voteId);
        return total.toNumber();
    }
    async getSecurityHolders(address, start, end) {
        LogService_1.default.logTrace(`Getting security holders for security ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.Security__factory, address.toString()).getSecurityHolders(start, end);
    }
    async getTotalSecurityHolders(address) {
        LogService_1.default.logTrace(`Getting total security holders for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.Security__factory, address.toString()).getTotalSecurityHolders();
        return total.toNumber();
    }
    async getTrexTokenBySalt(factory, salt) {
        LogService_1.default.logTrace(`Getting TREX token by salt ${salt}`);
        const token = await this.connect(asset_tokenization_contracts_1.TREXFactoryAts__factory, factory.toString()).getToken(salt);
        return token;
    }
    async isProceedRecipient(address, proceedRecipient) {
        LogService_1.default.logTrace(`Checking if the address ${proceedRecipient.toString()} is a proceed recipient for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ProceedRecipientsFacet__factory, address.toString()).isProceedRecipient(proceedRecipient.toString());
    }
    async getProceedRecipientData(address, proceedRecipient) {
        LogService_1.default.logTrace(`Getting proceed recipient data for the address ${proceedRecipient.toString()} for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ProceedRecipientsFacet__factory, address.toString()).getProceedRecipientData(proceedRecipient.toString());
    }
    async getProceedRecipientsCount(address) {
        LogService_1.default.logTrace(`Getting proceedRecipients count for the security: ${address.toString()}`);
        return (await this.connect(asset_tokenization_contracts_1.ProceedRecipientsFacet__factory, address.toString()).getProceedRecipientsCount()).toNumber();
    }
    async getProceedRecipients(address, page, pageLength) {
        LogService_1.default.logTrace(`Getting proceedRecipients from ${page} to ${pageLength} for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ProceedRecipientsFacet__factory, address.toString()).getProceedRecipients(page, pageLength);
    }
};
exports.RPCQueryAdapter = RPCQueryAdapter;
exports.RPCQueryAdapter = RPCQueryAdapter = __decorate([
    (0, tsyringe_1.singleton)(),
    __param(0, (0, LazyInjectDecorator_1.lazyInject)(NetworkService_1.default)),
    __param(1, (0, LazyInjectDecorator_1.lazyInject)(MirrorNodeAdapter_1.MirrorNodeAdapter)),
    __metadata("design:paramtypes", [NetworkService_1.default,
        MirrorNodeAdapter_1.MirrorNodeAdapter])
], RPCQueryAdapter);
