"use strict";
// SPDX-License-Identifier: Apache-2.0
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/dividend/Dividend");
const RegisteredAmortization_1 = require("../../../domain/context/amortization/RegisteredAmortization");
const Amortization_1 = require("../../../domain/context/amortization/Amortization");
const AmortizationFor_1 = require("../../../domain/context/amortization/AmortizationFor");
const AmortizationPaymentAmount_1 = require("../../../domain/context/amortization/AmortizationPaymentAmount");
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/dividend/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/dividend/DividendAmountFor");
const RateStatus_1 = require("../../../domain/context/bond/RateStatus");
const CouponFor_1 = require("../../../domain/context/bond/CouponFor");
const LOCAL_JSON_RPC_RELAY_URL = "http://127.0.0.1:7546/api";
let RPCQueryAdapter = class RPCQueryAdapter {
    networkService;
    mirrorNode;
    provider;
    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.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 getNonceFor(address, target) {
        LogService_1.default.logTrace(`Getting Nounce`);
        return await this.connect(asset_tokenization_contracts_1.NoncesFacet__factory, address.toString()).nonces(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 Number(roleCount);
    }
    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 Number(membersCount);
    }
    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.fromBigint(regulationInfo.regulationData.regulationType),
            subType: RegulationType_1.CastRegulationSubType.fromBigint(regulationInfo.regulationData.regulationSubType),
            dealSize: regulationInfo.regulationData.dealSize.toString(),
            accreditedInvestors: RegulationType_1.CastAccreditedInvestors.fromBigint(regulationInfo.regulationData.accreditedInvestors),
            maxNonAccreditedInvestors: Number(regulationInfo.regulationData.maxNonAccreditedInvestors),
            manualInvestorVerification: RegulationType_1.CastManualInvestorVerification.fromBigint(regulationInfo.regulationData.manualInvestorVerification),
            internationalInvestors: RegulationType_1.CastInternationalInvestorscation.fromBigint(regulationInfo.regulationData.internationalInvestors),
            resaleHoldPeriod: RegulationType_1.CastResaleHoldPeriodorscation.fromBigint(regulationInfo.regulationData.resaleHoldPeriod),
        };
        return new Security_1.Security({
            name: erc20Metadata.info.name,
            symbol: erc20Metadata.info.symbol,
            isin: erc20Metadata.info.isin,
            type: SecurityType_1.CastSecurityType.fromBigint(erc20Metadata.securityType),
            decimals: Number(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.fromBigint(regulationInfo.regulationData.regulationType),
            regulationsubType: RegulationType_1.CastRegulationSubType.fromBigint(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.fromBigint(res.dividendRight), res.currency, new BigDecimal_1.default(res.nominalValue.toString()), Number(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()), Number(res.nominalValueDecimals), Number(res.startingDate), Number(res.maturityDate));
    }
    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 Number(controlListCount);
    }
    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 getDividendFor(address, target, dividend) {
        LogService_1.default.logTrace(`Getting dividends for`);
        const dividendFor = await this.connect(asset_tokenization_contracts_1.Dividend__factory, address.toString()).getDividendFor(dividend, target.toString());
        return new DividendFor_1.DividendFor(new BigDecimal_1.default(dividendFor.tokenBalance), Number(dividendFor.decimals), dividendFor.isDisabled);
    }
    async getDividendAmountFor(address, target, dividend) {
        LogService_1.default.logTrace(`Getting dividends amount for`);
        const dividendAmountFor = await this.connect(asset_tokenization_contracts_1.Dividend__factory, address.toString()).getDividendAmountFor(dividend, target.toString());
        return new DividendAmountFor_1.DividendAmountFor(dividendAmountFor.numerator.toString(), dividendAmountFor.denominator.toString(), dividendAmountFor.recordDateReached);
    }
    async getDividend(address, dividend) {
        LogService_1.default.logTrace(`Getting dividends`);
        const { registeredDividend_, isDisabled_ } = await this.connect(asset_tokenization_contracts_1.Dividend__factory, address.toString()).getDividend(dividend);
        return new Dividend_1.Dividend(new BigDecimal_1.default(registeredDividend_.dividend.amount.toString()), Number(registeredDividend_.dividend.amountDecimals), Number(registeredDividend_.dividend.recordDate), Number(registeredDividend_.dividend.executionDate), Number(registeredDividend_.snapshotId), isDisabled_);
    }
    async getDividendsCount(address) {
        LogService_1.default.logTrace(`Getting dividends count`);
        const dividendsCount = await this.connect(asset_tokenization_contracts_1.Dividend__factory, address.toString()).getDividendsCount();
        return Number(dividendsCount);
    }
    async getVotingFor(address, target, voting) {
        LogService_1.default.logTrace(`Getting voting for`);
        const votingFor = await this.connect(asset_tokenization_contracts_1.VotingFacet__factory, address.toString()).getVotingFor(voting, target.toString());
        return new VotingFor_1.VotingFor(new BigDecimal_1.default(votingFor.tokenBalance), Number(votingFor.decimals), votingFor.isDisabled);
    }
    async getVoting(address, voting) {
        LogService_1.default.logTrace(`Getting voting`);
        const { registeredVoting_, isDisabled_ } = await this.connect(asset_tokenization_contracts_1.VotingFacet__factory, address.toString()).getVoting(voting);
        return new VotingRights_1.VotingRights(Number(registeredVoting_.voting.recordDate), registeredVoting_.voting.data, Number(registeredVoting_.snapshotId), isDisabled_);
    }
    async getVotingsCount(address) {
        LogService_1.default.logTrace(`Getting votings count`);
        const votingsCount = await this.connect(asset_tokenization_contracts_1.VotingFacet__factory, address.toString()).getVotingCount();
        return Number(votingsCount);
    }
    async getCouponFor(address, target, coupon) {
        LogService_1.default.logTrace(`Getting Coupon for`);
        const couponFor = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponFor(coupon, target.toString());
        const couponDomain = new Coupon_1.Coupon(Number(couponFor.coupon.recordDate), Number(couponFor.coupon.executionDate), new BigDecimal_1.default(couponFor.coupon.rate.toString()), Number(couponFor.coupon.rateDecimals), Number(couponFor.coupon.startDate), Number(couponFor.coupon.endDate), Number(couponFor.coupon.fixingDate), RateStatus_1.CastRateStatus.fromBigint(couponFor.coupon.rateStatus));
        const couponAmountDomain = new CouponAmountFor_1.CouponAmountFor(couponFor.couponAmount.numerator.toString(), couponFor.couponAmount.denominator.toString(), couponFor.couponAmount.recordDateReached);
        return new CouponFor_1.CouponFor(new BigDecimal_1.default(couponFor.tokenBalance), new BigDecimal_1.default(couponFor.nominalValue), Number(couponFor.decimals), couponFor.recordDateReached, couponDomain, couponAmountDomain, couponFor.isDisabled);
    }
    async getCouponsFor(address, couponId, pageIndex, pageLength) {
        LogService_1.default.logTrace(`Getting Coupons for`);
        const result = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponsFor(couponId, pageIndex, pageLength);
        const coupons = result.couponFor_.map((couponFor) => {
            const couponDomain = new Coupon_1.Coupon(Number(couponFor.coupon.recordDate), Number(couponFor.coupon.executionDate), new BigDecimal_1.default(couponFor.coupon.rate.toString()), Number(couponFor.coupon.rateDecimals), Number(couponFor.coupon.startDate), Number(couponFor.coupon.endDate), Number(couponFor.coupon.fixingDate), RateStatus_1.CastRateStatus.fromBigint(couponFor.coupon.rateStatus));
            const couponAmountDomain = new CouponAmountFor_1.CouponAmountFor(couponFor.couponAmount.numerator.toString(), couponFor.couponAmount.denominator.toString(), couponFor.couponAmount.recordDateReached);
            return new CouponFor_1.CouponFor(new BigDecimal_1.default(couponFor.tokenBalance), new BigDecimal_1.default(couponFor.nominalValue), Number(couponFor.decimals), couponFor.recordDateReached, couponDomain, couponAmountDomain, couponFor.isDisabled);
        });
        return { coupons, accounts: [...result.accounts_] };
    }
    async getCouponAmountFor(address, target, coupon) {
        LogService_1.default.logTrace(`Getting Coupon Amount for`);
        const couponAmountFor = await this.connect(asset_tokenization_contracts_1.Coupon__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 { registeredCoupon_, isDisabled_ } = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCoupon(coupon);
        return new Coupon_1.Coupon(Number(registeredCoupon_.coupon.recordDate), Number(registeredCoupon_.coupon.executionDate), new BigDecimal_1.default(registeredCoupon_.coupon.rate.toString()), Number(registeredCoupon_.coupon.rateDecimals), Number(registeredCoupon_.coupon.startDate), Number(registeredCoupon_.coupon.endDate), Number(registeredCoupon_.coupon.fixingDate), RateStatus_1.CastRateStatus.fromBigint(registeredCoupon_.coupon.rateStatus), Number(registeredCoupon_.snapshotId), isDisabled_);
    }
    async getCouponCount(address) {
        LogService_1.default.logTrace(`Getting Coupon count`);
        const couponCount = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponCount();
        return Number(couponCount);
    }
    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.toBigInt(), 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.toBigInt(), 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.toBigInt(), 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 Number(scheduledSnapshotsCount);
    }
    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.fromBigint(res.regulationType),
            subType: RegulationType_1.CastRegulationSubType.fromBigint(res.regulationSubType),
            dealSize: res.dealSize.toString(),
            accreditedInvestors: RegulationType_1.CastAccreditedInvestors.fromBigint(res.accreditedInvestors),
            maxNonAccreditedInvestors: Number(res.maxNonAccreditedInvestors),
            manualInvestorVerification: RegulationType_1.CastManualInvestorVerification.fromBigint(res.manualInvestorVerification),
            internationalInvestors: RegulationType_1.CastInternationalInvestorscation.fromBigint(res.internationalInvestors),
            resaleHoldPeriod: RegulationType_1.CastResaleHoldPeriodorscation.fromBigint(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 Number(count);
    }
    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_, Number(configInfo.version_)];
    }
    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(Number(scheduledBalanceAdjustmentInfo.balanceAdjustment_.executionDate), Number(scheduledBalanceAdjustmentInfo.balanceAdjustment_.factor), Number(scheduledBalanceAdjustmentInfo.balanceAdjustment_.decimals), scheduledBalanceAdjustmentInfo.isDisabled_);
    }
    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 Number(scheduledBalanceAdjustmentCount);
    }
    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 Number(heldAmountFor);
    }
    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 Number(heldAmountForByPartition);
    }
    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 Number(holdCountForByPartition);
    }
    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) => Number(id));
    }
    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(Number(hold.expirationTimestamp_), hold.amount_, 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 Number(count);
    }
    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, Number(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 Number(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, Number(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 Number(kycAccountsCount);
    }
    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 Number(clearedAmountFor);
    }
    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 Number(clearedAmountForByPartition);
    }
    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 Number(clearingCountForByPartition);
    }
    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) => Number(id));
    }
    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()), Number(clearing.expirationTimestamp), clearing.data, clearing.operatorData, clearing.holdEscrow, Number(clearing.holdExpirationTimestamp), 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()), Number(clearing.expirationTimestamp), 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()), Number(clearing.expirationTimestamp), 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 Number(getExternalPausesCount);
    }
    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 Number(getExternalPausesCount);
    }
    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 Number(getExternalKycListsCount);
    }
    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 Number(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 Number(frozenTokens);
    }
    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 Number(total);
    }
    async balancesOfAtSnapshot(address, snapshotId, pageIndex, pageLength) {
        LogService_1.default.logTrace(`Getting balances at snapshot ${snapshotId} for security ${address.toString()}, page ${pageIndex}, length ${pageLength}`);
        return await this.connect(asset_tokenization_contracts_1.SnapshotsFacet__factory, address.toString()).balancesOfAtSnapshot(snapshotId, pageIndex, pageLength);
    }
    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.Coupon__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.Coupon__factory, address.toString()).getTotalCouponHolders(couponId);
        return Number(total);
    }
    async getCouponFromOrderedListAt(address, pos) {
        LogService_1.default.logTrace(`Getting coupon from ordered list at position ${pos} for security ${address.toString()}`);
        const couponId = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponFromOrderedListAt(pos);
        return Number(couponId);
    }
    async getCouponsOrderedList(address, pageIndex, pageLength) {
        LogService_1.default.logTrace(`Getting coupons ordered list for security ${address.toString()}, page ${pageIndex}, length ${pageLength}`);
        // If pagination parameters are provided, use paginated call
        if (pageIndex !== undefined && pageLength !== undefined) {
            const couponIds = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponsOrderedList(pageIndex, pageLength);
            return couponIds.map((id) => Number(id));
        }
        // Otherwise get all coupons (simulate by getting first page with large length)
        const couponIds = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponsOrderedList(0, 1000);
        return couponIds.map((id) => Number(id));
    }
    async getCouponsOrderedListTotal(address) {
        LogService_1.default.logTrace(`Getting coupons ordered list total for security ${address.toString()}`);
        const total = await this.connect(asset_tokenization_contracts_1.Coupon__factory, address.toString()).getCouponsOrderedListTotal();
        return Number(total);
    }
    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.Dividend__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.Dividend__factory, address.toString()).getTotalDividendHolders(dividendId);
        return Number(total);
    }
    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.VotingFacet__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.VotingFacet__factory, address.toString()).getTotalVotingHolders(voteId);
        return Number(total);
    }
    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 Number(total);
    }
    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 Number(await this.connect(asset_tokenization_contracts_1.ProceedRecipientsFacet__factory, address.toString()).getProceedRecipientsCount());
    }
    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);
    }
    async actionContentHashExists(address, contentHash) {
        LogService_1.default.logTrace(`Getting actionContentHashExists for ${contentHash} for the security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.CorporateActionsFacet__factory, address.toString()).actionContentHashExists(contentHash);
    }
    async getCorporateAction(address, corporateActionId) {
        LogService_1.default.logTrace(`Getting corporate action ${corporateActionId} for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.CorporateActionsFacet__factory, address.toString()).getCorporateAction(corporateActionId);
        return {
            actionType: result.actionType_,
            actionTypeId: Number(result.actionTypeId_),
            data: result.data_,
            isDisabled: result.isDisabled_,
        };
    }
    async getCorporateActions(address, start, end) {
        LogService_1.default.logTrace(`Getting corporate actions from ${start} to ${end} for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.CorporateActionsFacet__factory, address.toString()).getCorporateActions(start, end);
        return {
            actionTypes: result.actionTypes_,
            actionTypeIds: result.actionTypeIds_.map((id) => Number(id)),
            datas: result.datas_,
            isDisabled: result.isDisabled_,
        };
    }
    async getCorporateActionsByType(address, actionType, start, end) {
        LogService_1.default.logTrace(`Getting corporate actions of type ${actionType} from ${start} to ${end} for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.CorporateActionsFacet__factory, address.toString()).getCorporateActionsByType(actionType, start, end);
        return {
            actionTypes: result.actionTypes_,
            actionTypeIds: result.actionTypeIds_.map((id) => Number(id)),
            datas: result.datas_,
            isDisabled: result.isDisabled_,
        };
    }
    async getRate(address) {
        const result = await this.connect(asset_tokenization_contracts_1.FixedRate__factory, address.toString()).getRate();
        return [result.rate_, Number(result.decimals_)];
    }
    async getInterestRate(address) {
        LogService_1.default.logTrace(`Getting interest rate for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.KpiLinkedRate__factory, address.toString()).getInterestRate();
        return [
            result.maxRate,
            result.baseRate,
            result.minRate,
            result.startPeriod,
            result.startRate,
            result.missedPenalty,
            result.reportPeriod,
            result.rateDecimals,
        ];
    }
    async getKpiLatestKpiData(address, from, to, kpi) {
        LogService_1.default.logTrace(`Getting latest KPI data for the security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.Kpis__factory, address.toString()).getLatestKpiData(from, to, kpi.toString());
        return { value: result[0], exists: result[1] };
    }
    async getMinDate(address) {
        LogService_1.default.logTrace(`Getting min date for the security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.Kpis__factory, address.toString()).getMinDate();
        return Number(result);
    }
    async getImpactData(address) {
        LogService_1.default.logTrace(`Getting impact data for the security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.KpiLinkedRate__factory, address.toString()).getImpactData();
        return [
            result.maxDeviationCap,
            result.baseLine,
            result.maxDeviationFloor,
            Number(result.impactDataDecimals),
            result.adjustmentPrecision,
        ];
    }
    async isCheckPointDate(address, date, project) {
        LogService_1.default.logTrace(`Checking if date ${date.toString()} is a checkpoint date for project ${project.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.Kpis__factory, address.toString()).isCheckPointDate(date, project.toString());
    }
    async scheduledCouponListingCount(address) {
        LogService_1.default.logTrace(`Getting scheduled coupon listing count for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.ScheduledCouponListingFacet__factory, address.toString()).scheduledCouponListingCount();
        return Number(result);
    }
    async getScheduledCouponListing(address, pageIndex, pageLength) {
        LogService_1.default.logTrace(`Getting scheduled coupon listing for security: ${address.toString()}`);
        return await this.connect(asset_tokenization_contracts_1.ScheduledCouponListingFacet__factory, address.toString()).getScheduledCouponListing(pageIndex, pageLength);
    }
    async getNominalValue(address) {
        LogService_1.default.logTrace(`Getting nominal value for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.NominalValue__factory, address.toString()).getNominalValue();
        return new BigDecimal_1.default(result.toString());
    }
    async getNominalValueDecimals(address) {
        LogService_1.default.logTrace(`Getting nominal value decimals for security: ${address.toString()}`);
        const result = await this.connect(asset_tokenization_contracts_1.NominalValue__factory, address.toString()).getNominalValueDecimals();
        return Number(result);
    }
    async getAmortization(address, amortizationId) {
        LogService_1.default.logTrace(`Getting amortization: ${amortizationId}`);
        const { registeredAmortization_, isDisabled_ } = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortization(amortizationId);
        return new RegisteredAmortization_1.RegisteredAmortization(new Amortization_1.Amortization(Number(registeredAmortization_.amortization.recordDate), Number(registeredAmortization_.amortization.executionDate), new BigDecimal_1.default(registeredAmortization_.amortization.tokensToRedeem.toString())), Number(registeredAmortization_.snapshotId), isDisabled_);
    }
    async getAmortizationFor(address, target, amortizationId) {
        LogService_1.default.logTrace(`Getting amortization for: ${target.toString()}, amortizationId: ${amortizationId}`);
        const af = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortizationFor(amortizationId, target.toString());
        return new AmortizationFor_1.AmortizationFor(af.account, Number(af.recordDate), Number(af.executionDate), Number(af.holdId), af.holdActive, new BigDecimal_1.default(af.tokenHeldAmount.toString()), Number(af.decimalsHeld), new BigDecimal_1.default(af.abafAtHold.toString()), new BigDecimal_1.default(af.tokenBalance.toString()), Number(af.decimalsBalance), af.recordDateReached, new BigDecimal_1.default(af.abafAtSnapshot.toString()), new BigDecimal_1.default(af.nominalValue.toString()), Number(af.nominalValueDecimals));
    }
    async getAmortizationsFor(address, amortizationId, start, end) {
        LogService_1.default.logTrace(`Getting amortizations for: amortizationId=${amortizationId}`);
        const result = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortizationsFor(amortizationId, start, end);
        return result.map((af) => new AmortizationFor_1.AmortizationFor(af.account, Number(af.recordDate), Number(af.executionDate), Number(af.holdId), af.holdActive, new BigDecimal_1.default(af.tokenHeldAmount.toString()), Number(af.decimalsHeld), new BigDecimal_1.default(af.abafAtHold.toString()), new BigDecimal_1.default(af.tokenBalance.toString()), Number(af.decimalsBalance), af.recordDateReached, new BigDecimal_1.default(af.abafAtSnapshot.toString()), new BigDecimal_1.default(af.nominalValue.toString()), Number(af.nominalValueDecimals)));
    }
    async getAmortizationsCount(address) {
        LogService_1.default.logTrace(`Getting amortizations count`);
        const count = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortizationsCount();
        return Number(count);
    }
    async getAmortizationHolders(address, amortizationId, start, end) {
        LogService_1.default.logTrace(`Getting amortization holders for amortizationId: ${amortizationId}`);
        return await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortizationHolders(amortizationId, start, end);
    }
    async getTotalAmortizationHolders(address, amortizationId) {
        LogService_1.default.logTrace(`Getting total amortization holders for amortizationId: ${amortizationId}`);
        const total = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getTotalAmortizationHolders(amortizationId);
        return Number(total);
    }
    async getAmortizationPaymentAmount(address, amortizationId, tokenHolder) {
        LogService_1.default.logTrace(`Getting amortization payment amount: amortizationId=${amortizationId}, tokenHolder=${tokenHolder.toString()}`);
        const { tokenAmount_, decimals_ } = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getAmortizationPaymentAmount(amortizationId, tokenHolder.toString());
        return new AmortizationPaymentAmount_1.AmortizationPaymentAmount(new BigDecimal_1.default(tokenAmount_.toString()), Number(decimals_));
    }
    async getActiveAmortizationHoldHolders(address, amortizationId, start, end) {
        LogService_1.default.logTrace(`Getting active amortization hold holders for amortizationId: ${amortizationId}`);
        return await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getActiveAmortizationHoldHolders(amortizationId, start, end);
    }
    async getTotalActiveAmortizationHoldHolders(address, amortizationId) {
        LogService_1.default.logTrace(`Getting total active amortization hold holders for amortizationId: ${amortizationId}`);
        const total = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getTotalActiveAmortizationHoldHolders(amortizationId);
        return Number(total);
    }
    async getActiveAmortizationIds(address, start, end) {
        LogService_1.default.logTrace(`Getting active amortization IDs`);
        const ids = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getActiveAmortizationIds(start, end);
        return ids.map(Number);
    }
    async getTotalActiveAmortizationIds(address) {
        LogService_1.default.logTrace(`Getting total active amortization IDs`);
        const total = await this.connect(asset_tokenization_contracts_1.AmortizationFacet__factory, address.toString()).getTotalActiveAmortizationIds();
        return Number(total);
    }
};
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);
