"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 token_math_1 = require("@melonproject/token-math");
const getTokenBySymbol_1 = require("../../utils/environment/getTokenBySymbol");
const getPrice_1 = require("../../contracts/prices/calls/getPrice");
const toBeTrueWith_1 = require("../utils/toBeTrueWith");
const getSystemTestEnvironment_1 = require("../utils/getSystemTestEnvironment");
const Environment_1 = require("../../utils/environment/Environment");
const getLogCurried_1 = require("../../utils/environment/getLogCurried");
const testLogger_1 = require("../utils/testLogger");
const requestInvestment_1 = require("../../contracts/fund/participation/transactions/requestInvestment");
const getToken_1 = require("../../contracts/dependencies/token/calls/getToken");
expect.extend({ toBeTrueWith: toBeTrueWith_1.toBeTrueWith });
const getLog = getLogCurried_1.getLogCurried('melon:protocol:systemTest:playground');
describe('playground', () => {
    afterAll(() => __awaiter(this, void 0, void 0, function* () {
        yield testLogger_1.allLogsWritten();
    }));
    test('Happy path', () => __awaiter(this, void 0, void 0, function* () {
        const master = yield getSystemTestEnvironment_1.getSystemTestEnvironment(Environment_1.Tracks.KYBER_PRICE);
        const log = getLog(master);
        const { melonContracts } = master.deployment;
        const mln = getTokenBySymbol_1.getTokenBySymbol(master, 'MLN');
        const weth = getTokenBySymbol_1.getTokenBySymbol(master, 'WETH');
        try {
            const mlnPrice = yield getPrice_1.getPrice(master, melonContracts.priceSource.toString(), mln);
            log.debug('MLN Price', mlnPrice);
        }
        catch (e) {
            throw new Error('Cannot get MLN Price from Kyber');
        }
        const fundToken = yield getToken_1.getToken(master, '0x289e7bcb82b8b386ed0317ee48bade3dc3ec0c82');
        const requestedShares = token_math_1.createQuantity(fundToken, 0.5);
        const request = yield requestInvestment_1.requestInvestment(master, '0x1a931c810800bd15f63b32c22625cd1e46fd835b', {
            investmentAmount: token_math_1.createQuantity(weth, 0.5),
            requestedShares,
        });
        log.debug('Request', request);
    }));
});
