/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import { web3, Contract, binToHex, contractIdFromAddress, fromApiArray, } from "@alephium/web3";
var TokenBridgeFactory = /** @class */ (function () {
    function TokenBridgeFactory(address, contractId, groupIndex, deployResult) {
        this.address = address;
        this.contractId = contractId;
        this.groupIndex = groupIndex;
        this.deployResult = deployResult;
    }
    TokenBridgeFactory.deploy = function (signer, localTokenPoolTemplateId, remoteTokenPoolTemplateId, tokenBridgeForChainTemplateId, attestTokenHandlerTemplateId, unexecutedSequenceTemplateId, _extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _deployResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, TokenBridgeFactory.contract.deploy(signer, {
                            initialFields: {
                                localTokenPoolTemplateId: localTokenPoolTemplateId,
                                remoteTokenPoolTemplateId: remoteTokenPoolTemplateId,
                                tokenBridgeForChainTemplateId: tokenBridgeForChainTemplateId,
                                attestTokenHandlerTemplateId: attestTokenHandlerTemplateId,
                                unexecutedSequenceTemplateId: unexecutedSequenceTemplateId,
                            },
                            initialAttoAlphAmount: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAttoAlphAmount,
                            initialTokenAmounts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialTokenAmounts,
                            issueTokenAmount: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.issueTokenAmount,
                            gasAmount: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.gasAmount,
                            gasPrice: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.gasPrice,
                        })];
                    case 1:
                        _deployResult = _a.sent();
                        return [2 /*return*/, new TokenBridgeFactory(_deployResult.contractAddress, _deployResult.contractId, _deployResult.fromGroup, _deployResult)];
                }
            });
        });
    };
    TokenBridgeFactory.connect = function (address, deployResult) {
        var contractId = binToHex(contractIdFromAddress(address));
        var groupIndex = parseInt(contractId.slice(-2));
        return new TokenBridgeFactory(address, contractId, groupIndex, deployResult);
    };
    TokenBridgeFactory.prototype.fetchState = function () {
        return __awaiter(this, void 0, void 0, function () {
            var state;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, TokenBridgeFactory.contract.fetchState(this.address, this.groupIndex)];
                    case 1:
                        state = _a.sent();
                        return [2 /*return*/, __assign(__assign({}, state), { localTokenPoolTemplateId: state.fields["localTokenPoolTemplateId"], remoteTokenPoolTemplateId: state.fields["remoteTokenPoolTemplateId"], tokenBridgeForChainTemplateId: state.fields["tokenBridgeForChainTemplateId"], attestTokenHandlerTemplateId: state.fields["attestTokenHandlerTemplateId"], unexecutedSequenceTemplateId: state.fields["unexecutedSequenceTemplateId"] })];
                }
            });
        });
    };
    // This is used for testing contract functions
    TokenBridgeFactory.stateForTest = function (localTokenPoolTemplateId, remoteTokenPoolTemplateId, tokenBridgeForChainTemplateId, attestTokenHandlerTemplateId, unexecutedSequenceTemplateId, asset, address) {
        var _a;
        var newAsset = {
            alphAmount: (_a = asset === null || asset === void 0 ? void 0 : asset.alphAmount) !== null && _a !== void 0 ? _a : BigInt("1000000000000000000"),
            tokens: asset === null || asset === void 0 ? void 0 : asset.tokens,
        };
        return TokenBridgeFactory.contract.toState({
            localTokenPoolTemplateId: localTokenPoolTemplateId,
            remoteTokenPoolTemplateId: remoteTokenPoolTemplateId,
            tokenBridgeForChainTemplateId: tokenBridgeForChainTemplateId,
            attestTokenHandlerTemplateId: attestTokenHandlerTemplateId,
            unexecutedSequenceTemplateId: unexecutedSequenceTemplateId,
        }, newAsset, address);
    };
    TokenBridgeFactory.testGetLocalTokenPoolTemplateId = function (_initFields, _extraParams) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var _initialAsset, _testParams, _testResult;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        _initialAsset = {
                            alphAmount: (_b = (_a = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _a === void 0 ? void 0 : _a.alphAmount) !== null && _b !== void 0 ? _b : BigInt("1000000000000000000"),
                            tokens: (_c = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _c === void 0 ? void 0 : _c.tokens,
                        };
                        _testParams = __assign(__assign({}, _extraParams), { testMethodIndex: 0, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridgeFactory.contract.testPublicMethod("getLocalTokenPoolTemplateId", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeFactory.testGetRemoteTokenPoolTemplateId = function (_initFields, _extraParams) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var _initialAsset, _testParams, _testResult;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        _initialAsset = {
                            alphAmount: (_b = (_a = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _a === void 0 ? void 0 : _a.alphAmount) !== null && _b !== void 0 ? _b : BigInt("1000000000000000000"),
                            tokens: (_c = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _c === void 0 ? void 0 : _c.tokens,
                        };
                        _testParams = __assign(__assign({}, _extraParams), { testMethodIndex: 1, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridgeFactory.contract.testPublicMethod("getRemoteTokenPoolTemplateId", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeFactory.testGetTokenBridgeForChainTemplateId = function (_initFields, _extraParams) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var _initialAsset, _testParams, _testResult;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        _initialAsset = {
                            alphAmount: (_b = (_a = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _a === void 0 ? void 0 : _a.alphAmount) !== null && _b !== void 0 ? _b : BigInt("1000000000000000000"),
                            tokens: (_c = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _c === void 0 ? void 0 : _c.tokens,
                        };
                        _testParams = __assign(__assign({}, _extraParams), { testMethodIndex: 2, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridgeFactory.contract.testPublicMethod("getTokenBridgeForChainTemplateId", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeFactory.testGetAttestTokenHandlerTemplateId = function (_initFields, _extraParams) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var _initialAsset, _testParams, _testResult;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        _initialAsset = {
                            alphAmount: (_b = (_a = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _a === void 0 ? void 0 : _a.alphAmount) !== null && _b !== void 0 ? _b : BigInt("1000000000000000000"),
                            tokens: (_c = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _c === void 0 ? void 0 : _c.tokens,
                        };
                        _testParams = __assign(__assign({}, _extraParams), { testMethodIndex: 3, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridgeFactory.contract.testPublicMethod("getAttestTokenHandlerTemplateId", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeFactory.testGetUnexecutedSequenceTemplateId = function (_initFields, _extraParams) {
        var _a, _b, _c;
        return __awaiter(this, void 0, void 0, function () {
            var _initialAsset, _testParams, _testResult;
            return __generator(this, function (_d) {
                switch (_d.label) {
                    case 0:
                        _initialAsset = {
                            alphAmount: (_b = (_a = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _a === void 0 ? void 0 : _a.alphAmount) !== null && _b !== void 0 ? _b : BigInt("1000000000000000000"),
                            tokens: (_c = _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.initialAsset) === null || _c === void 0 ? void 0 : _c.tokens,
                        };
                        _testParams = __assign(__assign({}, _extraParams), { testMethodIndex: 4, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridgeFactory.contract.testPublicMethod("getUnexecutedSequenceTemplateId", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeFactory.prototype.getLocalTokenPoolTemplateIdCall = function (_extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _callResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, web3
                            .getCurrentNodeProvider()
                            .contracts.postContractsCallContract({
                            group: this.groupIndex,
                            worldStateBlockHash: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.worldStateBlockHash,
                            txId: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.txId,
                            address: this.address,
                            methodIndex: 0,
                            args: [],
                            existingContracts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.existingContracts,
                            inputAssets: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.inputAssets,
                        })];
                    case 1:
                        _callResult = _a.sent();
                        return [2 /*return*/, fromApiArray(_callResult.returns, ["ByteVec"])[0]];
                }
            });
        });
    };
    TokenBridgeFactory.prototype.getRemoteTokenPoolTemplateIdCall = function (_extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _callResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, web3
                            .getCurrentNodeProvider()
                            .contracts.postContractsCallContract({
                            group: this.groupIndex,
                            worldStateBlockHash: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.worldStateBlockHash,
                            txId: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.txId,
                            address: this.address,
                            methodIndex: 1,
                            args: [],
                            existingContracts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.existingContracts,
                            inputAssets: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.inputAssets,
                        })];
                    case 1:
                        _callResult = _a.sent();
                        return [2 /*return*/, fromApiArray(_callResult.returns, ["ByteVec"])[0]];
                }
            });
        });
    };
    TokenBridgeFactory.prototype.getTokenBridgeForChainTemplateIdCall = function (_extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _callResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, web3
                            .getCurrentNodeProvider()
                            .contracts.postContractsCallContract({
                            group: this.groupIndex,
                            worldStateBlockHash: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.worldStateBlockHash,
                            txId: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.txId,
                            address: this.address,
                            methodIndex: 2,
                            args: [],
                            existingContracts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.existingContracts,
                            inputAssets: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.inputAssets,
                        })];
                    case 1:
                        _callResult = _a.sent();
                        return [2 /*return*/, fromApiArray(_callResult.returns, ["ByteVec"])[0]];
                }
            });
        });
    };
    TokenBridgeFactory.prototype.getAttestTokenHandlerTemplateIdCall = function (_extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _callResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, web3
                            .getCurrentNodeProvider()
                            .contracts.postContractsCallContract({
                            group: this.groupIndex,
                            worldStateBlockHash: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.worldStateBlockHash,
                            txId: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.txId,
                            address: this.address,
                            methodIndex: 3,
                            args: [],
                            existingContracts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.existingContracts,
                            inputAssets: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.inputAssets,
                        })];
                    case 1:
                        _callResult = _a.sent();
                        return [2 /*return*/, fromApiArray(_callResult.returns, ["ByteVec"])[0]];
                }
            });
        });
    };
    TokenBridgeFactory.prototype.getUnexecutedSequenceTemplateIdCall = function (_extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _callResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, web3
                            .getCurrentNodeProvider()
                            .contracts.postContractsCallContract({
                            group: this.groupIndex,
                            worldStateBlockHash: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.worldStateBlockHash,
                            txId: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.txId,
                            address: this.address,
                            methodIndex: 4,
                            args: [],
                            existingContracts: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.existingContracts,
                            inputAssets: _extraParams === null || _extraParams === void 0 ? void 0 : _extraParams.inputAssets,
                        })];
                    case 1:
                        _callResult = _a.sent();
                        return [2 /*return*/, fromApiArray(_callResult.returns, ["ByteVec"])[0]];
                }
            });
        });
    };
    TokenBridgeFactory.contract = Contract.fromJson(JSON.parse("{\n  \"version\": \"v1.7.0\",\n  \"name\": \"TokenBridgeFactory\",\n  \"bytecode\": \"050509121b4024402d010000000102ce0002010000000102ce0102010000000102ce0202010000000102ce0302010000000102ce0402\",\n  \"codeHash\": \"b08890fe7fe29e80e21a7929ffd4a2658df0928fa1cdb5c45d63a90c55144b8f\",\n  \"fieldsSig\": {\n    \"names\": [\n      \"localTokenPoolTemplateId\",\n      \"remoteTokenPoolTemplateId\",\n      \"tokenBridgeForChainTemplateId\",\n      \"attestTokenHandlerTemplateId\",\n      \"unexecutedSequenceTemplateId\"\n    ],\n    \"types\": [\n      \"ByteVec\",\n      \"ByteVec\",\n      \"ByteVec\",\n      \"ByteVec\",\n      \"ByteVec\"\n    ],\n    \"isMutable\": [\n      false,\n      false,\n      false,\n      false,\n      false\n    ]\n  },\n  \"eventsSig\": [],\n  \"functions\": [\n    {\n      \"name\": \"getLocalTokenPoolTemplateId\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"getRemoteTokenPoolTemplateId\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"getTokenBridgeForChainTemplateId\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"getAttestTokenHandlerTemplateId\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"getUnexecutedSequenceTemplateId\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"ByteVec\"\n      ]\n    }\n  ]\n}"));
    return TokenBridgeFactory;
}());
export { TokenBridgeFactory };
