import { BigNumber } from "@ethersproject/bignumber";
import * as exchanges from "../exchanges/handler";
import { getOfferById } from "../offers/subgraph";
import { AddressZero } from "@ethersproject/constants";
import { encodeCommitToPriceDiscoveryOffer } from "./interface";
// Implementation
export async function commitToPriceDiscoveryOffer(args) {
    let { offerId } = exchanges.parseTokenId(args.tokenIdOrOfferId);
    if (offerId.eq(0)) {
        offerId = BigNumber.from(args.tokenIdOrOfferId);
    }
    const offer = await getOfferById(args.subgraphUrl, offerId);
    // TODO: do we need to check allowance?
    const transactionRequest = {
        to: args.contractAddress,
        data: encodeCommitToPriceDiscoveryOffer(args.buyer, args.tokenIdOrOfferId, args.priceDiscovery),
        value: offer.exchangeToken.address === AddressZero ? offer.price : "0"
    };
    if (args.returnTxInfo) {
        return transactionRequest;
    }
    else {
        return args.web3Lib.sendTransaction(transactionRequest);
    }
}
//# sourceMappingURL=handler.js.map