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