"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.connect = connect;
exports.getEventState = getEventState;
var tslib_1 = require("tslib");
var contracts_node_1 = require("@uma/contracts-node");
var lodash_1 = require("lodash");
var utils_1 = require("../../utils");
var Factory = contracts_node_1.ERC20Ethers__factory;
function connect(address, provider) {
    return Factory.connect(address, provider);
}
function reduceEvents(state, event) {
    if (state === void 0) { state = {}; }
    switch (event.event) {
        case "Transfer": {
            var typedEvent = event;
            var _a = typedEvent.args, from = _a.from, to = _a.to, value = _a.value;
            var balances = (0, utils_1.Balances)(state.balances || {});
            balances.sub(from, value);
            balances.add(to, value);
            return tslib_1.__assign(tslib_1.__assign({}, state), { balances: balances.balances });
        }
        case "Approval": {
            var typedEvent = event;
            var _b = typedEvent.args, owner = _b.owner, spender = _b.spender, value = _b.value;
            (0, lodash_1.set)(state, ["approvalsByOwner", owner, spender], value.toString());
            (0, lodash_1.set)(state, ["approvalsBySpender", spender, owner], value.toString());
            return tslib_1.__assign({}, state);
        }
    }
    return state;
}
function getEventState(events, initialState) {
    if (initialState === void 0) { initialState = {}; }
    return events.reduce(reduceEvents, initialState);
}
//# sourceMappingURL=client.js.map