import { __assign } from "tslib";
import { ERC20Ethers__factory } from "@uma/contracts-node";
import { set } from "lodash";
import { Balances } from "../../utils";
var Factory = ERC20Ethers__factory;
export function connect(address, provider) {
    return Factory.connect(address, provider);
}
// takes all events and returns user balances and approvals
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 = Balances(state.balances || {});
            balances.sub(from, value);
            balances.add(to, value);
            return __assign(__assign({}, state), { balances: balances.balances });
        }
        case "Approval": {
            var typedEvent = event;
            var _b = typedEvent.args, owner = _b.owner, spender = _b.spender, value = _b.value;
            set(state, ["approvalsByOwner", owner, spender], value.toString());
            set(state, ["approvalsBySpender", spender, owner], value.toString());
            return __assign({}, state);
        }
    }
    return state;
}
export function getEventState(events, initialState) {
    if (initialState === void 0) { initialState = {}; }
    return events.reduce(reduceEvents, initialState);
}
//# sourceMappingURL=client.js.map