"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MockSvmSpokePoolClient = void 0;
const contracts_1 = require("@across-protocol/contracts");
const utils_1 = require("../../utils");
const SpokePoolClient_1 = require("../SpokePoolClient");
const MockSvmCpiEventsClient_1 = require("./MockSvmCpiEventsClient");
const svm_1 = require("../../arch/svm");
class MockSvmSpokePoolClient extends SpokePoolClient_1.SVMSpokePoolClient {
    mockEventsClient;
    destinationTokenForChainOverride = {};
    constructor(logger, chainId, programId = contracts_1.SvmSpokeClient.SVM_SPOKE_PROGRAM_ADDRESS, deploymentBlock = 1, eventSearchConfig = { from: 0, maxLookBack: 0 }, opts = { hubPoolClient: null }) {
        super(logger, opts.hubPoolClient, chainId, BigInt(deploymentBlock), eventSearchConfig, null, programId, null);
        this.mockEventsClient = new MockSvmCpiEventsClient_1.MockSvmCpiEventsClient();
        this.latestHeightSearched = deploymentBlock;
    }
    setConfigStoreClient(configStore) {
        this.configStoreClient = configStore;
    }
    setDestinationTokenForChain(chainId, token) {
        this.destinationTokenForChainOverride[chainId] = token;
    }
    getDestinationTokenForDeposit(deposit) {
        const override = this.destinationTokenForChainOverride[deposit.originChainId];
        return (0, utils_1.isDefined)(override) ? (0, utils_1.toAddressType)(override, this.chainId) : super.getDestinationTokenForDeposit(deposit);
    }
    setLatestBlockNumber(blockNumber) {
        this.latestHeightSearched = blockNumber;
    }
    async _update(eventsToQuery) {
        const from = this.eventSearchConfig.from ?? this.deploymentBlock;
        const to = this.eventSearchConfig.to ? BigInt(this.eventSearchConfig.to) : undefined;
        const events = await Promise.all(eventsToQuery.map((eventName) => this.mockEventsClient.queryEvents(eventName, BigInt(from), to)));
        const eventsWithBlockNumber = events.map((eventList) => eventList.map((event) => {
            return {
                txnRef: event.signature,
                blockNumber: Number(event.slot),
                txnIndex: 0,
                logIndex: 0,
                ...(0, svm_1.unwrapEventData)(event.data),
            };
        }));
        return Promise.resolve({
            success: true,
            firstDepositId: utils_1.bnZero,
            currentTime: (0, utils_1.getCurrentTime)(),
            events: eventsWithBlockNumber,
            searchEndBlock: this.eventSearchConfig.to || this.latestHeightSearched,
        });
    }
    deposit(deposit) {
        return this.mockEventsClient.deposit(deposit);
    }
    fillRelay(fill) {
        return this.mockEventsClient.fillRelay(fill);
    }
    requestSlowFill(request) {
        return this.mockEventsClient.requestSlowFill(request);
    }
    setTokensBridged(_tokensBridged) {
        throw new Error("MockSvmSpokePoolClient#setTokensBridged not implemented");
    }
    executeSlowRelayLeaf(_leaf) {
        throw new Error("MockSvmSpokePoolClient#executeV3SlowRelayLeaf not implemented");
    }
    executeRelayerRefundLeaf(_refund) {
        throw new Error("MockSvmSpokePoolClient#executeRelayerRefundLeaf not implemented");
    }
    setEnableRoute(_originToken, _destinationChainId, _enabled, _overrides = {}) {
        throw new Error("MockSvmSpokePoolClient#setEnableRoute not implemented");
    }
}
exports.MockSvmSpokePoolClient = MockSvmSpokePoolClient;
//# sourceMappingURL=MockSvmSpokePoolClient.js.map