"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const deployAndInitTestEnv_1 = require("../../../../tests/utils/deployAndInitTestEnv");
const Contracts_1 = require("../../../../Contracts");
const getTokenBySymbol_1 = require("../../../../utils/environment/getTokenBySymbol");
const token_math_1 = require("@melonproject/token-math");
const makeOasisDexOrder_1 = require("./makeOasisDexOrder");
const setupInvestedTestFund_1 = require("../../../../tests/utils/setupInvestedTestFund");
const cancelOasisDexOrder_1 = require("./cancelOasisDexOrder");
describe('makeOasisDexOrder', () => {
    const shared = {};
    beforeAll(() => __awaiter(this, void 0, void 0, function* () {
        shared.env = yield deployAndInitTestEnv_1.deployAndInitTestEnv();
        shared.accounts = yield shared.env.eth.getAccounts();
        shared.routes = yield setupInvestedTestFund_1.setupInvestedTestFund(shared.env);
        shared.oasisDex =
            shared.env.deployment.exchangeConfigs[Contracts_1.Exchanges.MatchingMarket].exchange;
        shared.mln = getTokenBySymbol_1.getTokenBySymbol(shared.env, 'MLN');
        shared.weth = getTokenBySymbol_1.getTokenBySymbol(shared.env, 'WETH');
    }));
    it('make oasisdex order', () => __awaiter(this, void 0, void 0, function* () {
        const makerQuantity = token_math_1.createQuantity(shared.weth, 0.05);
        const takerQuantity = token_math_1.createQuantity(shared.mln, 1);
        const order = yield makeOasisDexOrder_1.makeOasisDexOrder(shared.env, shared.routes.tradingAddress, { makerQuantity, takerQuantity });
        expect(order.buy).toEqual(takerQuantity);
        expect(order.sell).toEqual(makerQuantity);
        expect(order.maker).toEqual(shared.routes.tradingAddress);
        yield expect(makeOasisDexOrder_1.makeOasisDexOrder(shared.env, shared.routes.tradingAddress, {
            makerQuantity,
            takerQuantity,
        })).rejects.toThrow('open order');
        yield cancelOasisDexOrder_1.cancelOasisDexOrder(shared.env, shared.routes.tradingAddress, {
            id: order.id,
            maker: shared.routes.tradingAddress,
            makerAsset: order.sell.token.address,
            takerAsset: order.buy.token.address,
        });
        // Now it should work again
        yield makeOasisDexOrder_1.makeOasisDexOrder(shared.env, shared.routes.tradingAddress, {
            makerQuantity,
            takerQuantity,
        });
    }));
});
