"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    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) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint @typescript-eslint/no-var-requires: "off" */
const factory_1 = require("../src/factory");
const api_1 = require("@polkadot/api");
const parachain_1 = require("../src/parachain");
const util_crypto_1 = require("@polkadot/util-crypto");
// const PARACHAIN_ENDPOINT = "wss://api-dev-kintsugi.interlay.io/parachain";
// const ACCOUNT_URI = "quick sense network ozone ostrich bone hole possible timber clog urban primary//account/1";
const PARACHAIN_ENDPOINT = "ws://127.0.0.1:9988";
const ACCOUNT_URI = "//Alice";
main().catch((err) => {
    console.log("Error thrown by script:");
    console.log(err);
});
function main() {
    return __awaiter(this, void 0, void 0, function* () {
        const rawData = require("fs").readFileSync("testnet_runtime_parachain.compact.compressed.wasm");
        const data = "0x" + rawData.toString("hex");
        yield util_crypto_1.cryptoWaitReady();
        const keyring = new api_1.Keyring({ type: "sr25519" });
        const userKeyring = keyring.addFromUri(ACCOUNT_URI);
        const api = yield factory_1.createSubstrateAPI(PARACHAIN_ENDPOINT);
        const transactionAPI = new parachain_1.DefaultTransactionAPI(api, userKeyring);
        const proposal = api.tx.parachainSystem.authorizeUpgrade("0x72e1663c5c98310ff9654700738b4f2987a7d8d9d4ccbfd39babe98517ddd7eb");
        const proposalData = proposal.method.toHex();
        const proposalHash = proposal.method.hash.toHex();
        // // sudo-upgrade using set-code
        // await transactionAPI.sendLogged(api.tx.sudo.sudoUncheckedWeight(api.tx.system.setCode(data), 0), undefined);
        console.log("Locking KINT...");
        yield transactionAPI.sendLogged(api.tx.escrow.createLock(10000000000000, 2628000), undefined);
        console.log("Submitting preimage...");
        yield transactionAPI.sendLogged(api.tx.democracy.notePreimage(proposalData), undefined);
        console.log("Submitting proposal...");
        yield transactionAPI.sendLogged(api.tx.democracy.propose(proposalHash, 5000000000000), undefined);
        console.log("Fastracking proposal...");
        yield transactionAPI.sendLogged(api.tx.sudo.sudo(api.tx.democracy.fastTrack(0, 3)), undefined);
        console.log("Voting on proposal...");
        yield transactionAPI.sendLogged(api.tx.democracy.vote(0, api.createType("DemocracyVote", {
            aye: true,
            balance: 1000000000000,
        })), undefined);
        api.disconnect();
    });
}
//# sourceMappingURL=democracy.js.map