import { SvmSpokeClient } from "@across-protocol/contracts";
import { getCurrentTime, bnZero, toAddressType, isDefined, } from "../../utils";
import { SVMSpokePoolClient } from "../SpokePoolClient";
import { MockSvmCpiEventsClient } from "./MockSvmCpiEventsClient";
import { unwrapEventData } from "../../arch/svm";
// This class replaces internal SpokePoolClient functionality, enabling
// the user to bypass on-chain queries and inject events directly.
export class MockSvmSpokePoolClient extends SVMSpokePoolClient {
    mockEventsClient;
    destinationTokenForChainOverride = {};
    constructor(logger, chainId, programId = 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();
        this.latestHeightSearched = deploymentBlock;
    }
    setConfigStoreClient(configStore) {
        this.configStoreClient = configStore;
    }
    setDestinationTokenForChain(chainId, token) {
        this.destinationTokenForChainOverride[chainId] = token;
    }
    getDestinationTokenForDeposit(deposit) {
        const override = this.destinationTokenForChainOverride[deposit.originChainId];
        return isDefined(override) ? 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;
        // Get events from the mock event client.
        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,
                ...unwrapEventData(event.data),
            };
        }));
        return Promise.resolve({
            success: true,
            firstDepositId: bnZero,
            currentTime: 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");
    }
}
//# sourceMappingURL=MockSvmSpokePoolClient.js.map