"use strict";
// Script used to generate the proposal for the manual Vault migration.
// https://kintsugi.subsquare.io/democracy/referendum/56
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 });
const api_1 = require("@polkadot/api");
function main() {
    return __awaiter(this, void 0, void 0, function* () {
        const wsProvider = new api_1.WsProvider('wss://api-kusama.interlay.io/parachain');
        const api = yield api_1.ApiPromise.create({ provider: wsProvider });
        // Block containing the runtime upgrade
        // https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fapi-kusama.interlay.io%2Fparachain#/explorer/query/0x3a4293ca2b4d24ea852b9510059cb8769e8321b3051bb690aef2703ebc74a65e
        const preUpgradeApi = yield api.at("0x3a4293ca2b4d24ea852b9510059cb8769e8321b3051bb690aef2703ebc74a65e");
        const allVaults = yield preUpgradeApi.query.vaultRegistry.vaults.entries();
        const toSet = allVaults.map(([key, vault]) => {
            // In this upgrade we removed theft reporting
            let vaultJSON = vault.toJSON();
            delete vaultJSON.wallet;
            if (vaultJSON.status.committedTheft === null) {
                vaultJSON.status = { liquidated: null };
            }
            const codec = api.createType("VaultRegistryVault", vaultJSON);
            return [key.toHex(), codec.toHex()];
        });
        // Encoded data for the proposal
        console.log(api.tx.system.setStorage(toSet).method.toHex());
        yield api.disconnect();
    });
}
main();
//# sourceMappingURL=2022-08-08-vault-migration.js.map