"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 @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 = "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* () {
        yield util_crypto_1.cryptoWaitReady();
        console.log("Running xcm script...");
        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 currencyId = api.createType("InterbtcPrimitivesCurrencyId", {
            token: api.createType("InterbtcPrimitivesTokenSymbol", {
                kint: true,
            })
        });
        const dest = api.createType("XcmVersionedMultiLocation", {
            v1: api.createType("XcmV1MultiLocation", {
                parents: 1,
                interior: api.createType("XcmV1MultilocationJunctions", {
                    x2: [
                        api.createType("XcmV1Junction", {
                            parachain: 3000
                        }), api.createType("XcmV1Junction", {
                            accountId32: {
                                network: api.createType("XcmV0JunctionNetworkId", { any: true }),
                                id: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" // alice 
                            }
                        })
                    ]
                })
            })
        });
        const sibling = api.createType("XcmV1MultiLocation", {
            parents: 1,
            interior: api.createType("XcmV1MultilocationJunctions", {
                x1: api.createType("XcmV1Junction", { parachain: 3000 })
            })
        });
        const setupTx = api.tx.sudo.sudo(api.tx.polkadotXcm.forceXcmVersion(sibling, 2));
        const xcmTx = api.tx.xTokens.transfer(currencyId, 100000000000, dest, 400000000000);
        // send back 10000000000, 1000000001
        console.log("Constructed the tx, broadcasting first...");
        yield transactionAPI.sendLogged(setupTx, undefined);
        console.log("broadcasting second...");
        yield transactionAPI.sendLogged(xcmTx, undefined);
        api.disconnect();
    });
}
//# sourceMappingURL=xcm-cross-chain-transfer.js.map