UNPKG

@tempus-labs/utils

Version:

Tempus utility helpers

54 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TempusOTC = void 0; const ContractBase_1 = require("../utils/ContractBase"); const address_1 = require("@ethersproject/address"); /** * Wrapper around TempusOTC */ class TempusOTC extends ContractBase_1.ContractBase { constructor(contract, tokenToBuy, tokenToSell, sellAmount) { super("TempusOTC", 18, contract); this.tokenToBuy = tokenToBuy; this.tokenToSell = tokenToSell; this.sellAmount = sellAmount; } static async create(owner, tokenToBuy, tokenToSell, buyAmount, sellAmount, taker) { const transactionCount = await owner.getTransactionCount() + 1; const futureTempusOTCAddress = (0, address_1.getContractAddress)({ from: owner.address, nonce: transactionCount }); await tokenToBuy.approve(owner, futureTempusOTCAddress, buyAmount); let tempusOTC = await ContractBase_1.ContractBase.deployContractBy("TempusOTC", owner, tokenToBuy.address, tokenToSell.address, tokenToBuy.toBigNum(buyAmount), tokenToSell.toBigNum(sellAmount), taker, { nonce: transactionCount }); return new TempusOTC(tempusOTC, tokenToBuy, tokenToSell, sellAmount); } /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * @param token The address of the token which we want to approve * @param user The caller who is sending this approve * @param amount Amount of tokens to approve in contract decimals, eg 2.0 or "0.00001" */ async approve(token, user, amount) { await token.approve(user, this.address, amount); } /** * @dev Accept offer * @param user The caller who is accept offer (must be same as taker) */ async buy(user) { await this.approve(this.tokenToSell, user, this.sellAmount); return this.connect(user).buy(); } /** * @dev Cancel offer * @param user The caller who is cancel offer (must be same user that create offer and contract owner) */ async cancel(user) { return this.connect(user).cancel(); } } exports.TempusOTC = TempusOTC; //# sourceMappingURL=TempusOTC.js.map