"use strict";
/* 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 };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenBridge = void 0;
var web3_1 = require("@alephium/web3");
var TokenBridge = /** @class */ (function () {
    function TokenBridge(address, contractId, groupIndex, deployResult) {
        this.address = address;
        this.contractId = contractId;
        this.groupIndex = groupIndex;
        this.deployResult = deployResult;
    }
    TokenBridge.deploy = function (signer, governance, localChainId, receivedSequence, sendSequence, tokenBridgeFactory, minimalConsistencyLevel, refundAddress, _extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _deployResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, TokenBridge.contract.deploy(signer, {
                            initialFields: {
                                governance: governance,
                                localChainId: localChainId,
                                receivedSequence: receivedSequence,
                                sendSequence: sendSequence,
                                tokenBridgeFactory: tokenBridgeFactory,
                                minimalConsistencyLevel: minimalConsistencyLevel,
                                refundAddress: refundAddress,
                            },
                            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 TokenBridge(_deployResult.contractAddress, _deployResult.contractId, _deployResult.fromGroup, _deployResult)];
                }
            });
        });
    };
    TokenBridge.connect = function (address, deployResult) {
        var contractId = web3_1.binToHex(web3_1.contractIdFromAddress(address));
        var groupIndex = parseInt(contractId.slice(-2));
        return new TokenBridge(address, contractId, groupIndex, deployResult);
    };
    TokenBridge.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*/, TokenBridge.contract.fetchState(this.address, this.groupIndex)];
                    case 1:
                        state = _a.sent();
                        return [2 /*return*/, __assign(__assign({}, state), { governance: state.fields["governance"], localChainId: state.fields["localChainId"], receivedSequence: state.fields["receivedSequence"], sendSequence: state.fields["sendSequence"], tokenBridgeFactory: state.fields["tokenBridgeFactory"], minimalConsistencyLevel: state.fields["minimalConsistencyLevel"], refundAddress: state.fields["refundAddress"] })];
                }
            });
        });
    };
    // This is used for testing contract functions
    TokenBridge.stateForTest = function (governance, localChainId, receivedSequence, sendSequence, tokenBridgeFactory, minimalConsistencyLevel, refundAddress, 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 TokenBridge.contract.toState({
            governance: governance,
            localChainId: localChainId,
            receivedSequence: receivedSequence,
            sendSequence: sendSequence,
            tokenBridgeFactory: tokenBridgeFactory,
            minimalConsistencyLevel: minimalConsistencyLevel,
            refundAddress: refundAddress,
        }, newAsset, address);
    };
    TokenBridge.testParseAndVerifyGovernanceVAA = function (args, _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: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPrivateMethod("parseAndVerifyGovernanceVAA", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testCreateAttestTokenHandler = function (args, _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: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPrivateMethod("createAttestTokenHandler", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testCreateLocalAttestTokenHandler = function (args, _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: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("createLocalAttestTokenHandler", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testParseAndVerifyRegisterChain = function (args, _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: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPrivateMethod("parseAndVerifyRegisterChain", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testRegisterChain = function (args, _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: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("registerChain", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testUpgradeContract = function (args, _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: 5, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("upgradeContract", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testDestroyUnexecutedSequenceContracts = function (args, _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: 6, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("destroyUnexecutedSequenceContracts", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testUpdateMinimalConsistencyLevel = function (args, _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: 7, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("updateMinimalConsistencyLevel", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testGetRefundAddress = 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: 8, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("getRefundAddress", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testUpdateRefundAddress = function (args, _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: 9, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("updateRefundAddress", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testParseConractUpgrade = function (args, _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: 10, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPrivateMethod("parseConractUpgrade", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testGetMessageFee = 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: 11, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("getMessageFee", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testAttestToken = function (args, _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: 12, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("attestToken", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testNextSendSequence = 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: 13, testArgs: {}, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPrivateMethod("nextSendSequence", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testCreateLocalTokenPool = function (args, _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: 14, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("createLocalTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testCreateRemoteTokenPool = function (args, _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: 15, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("createRemoteTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testUpdateRemoteTokenPool = function (args, _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: 16, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("updateRemoteTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.testTransferToken = function (args, _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: 17, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, TokenBridge.contract.testPublicMethod("transferToken", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridge.prototype.getRefundAddressCall = 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_1.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: 8,
                            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*/, web3_1.fromApiArray(_callResult.returns, ["Address"])[0]];
                }
            });
        });
    };
    TokenBridge.prototype.getMessageFeeCall = 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_1.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: 11,
                            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*/, web3_1.fromApiArray(_callResult.returns, ["U256"])[0]];
                }
            });
        });
    };
    TokenBridge.contract = web3_1.Contract.fromJson(JSON.parse("{\n  \"version\": \"v1.7.0\",\n  \"name\": \"TokenBridge\",\n  \"bytecode\": \"071240304066407b40c4411c416f41cf41fe4207424e42f142fe4363437643c94421445544e00000020502121600a00013c7546f6b656e4272696467651601100fce00010417041703170216020d2aa100160316040200030508001dce00b116021603160413056417050c130164170614010016026744170716001601a216070c0dce02010316051606c11801030202000916001601a216001601ce01b10300010000010502402716001401010000170217011601ce012f16010c2f1b130d7b160213211323626d17031603ce0130130f7b160213231340436217041602431340432f0e7b160316040201030308004031160000031704170316011602a21601160216031604040001ce00ce01b1160316040c0dce02010413066417050c0c0c0c130464170614010116036744170716011602a216070c0dce02010216051606c1180100010800402d16001401020000170217011601ce012f130d7b1602000a170617051704170316041400414c031603ba4a16a0006ba0016b44a0026644a00347441707160416074e41130e7b160316051606bb0100010800403516001401f00000170217011601ce012f130d7b160213211323621703160213231325626d170416040c3313147b1325160413082c2a170516024316052f0e7b160213251605621706140101160344cb170716060d0c1607010801000104001816001401f10000170217011601ce012f130d7b16024313222f0e7b160213211322626c17031603a102010000000102a003020100010600402616001401f20000170217011601ce012f130d7b160213211323626d1703132316032a170416024316042f0e7b16021323160462631705160548131c7b1605a1030000010a04405e160013211323626d1701132316012a17021600132316026217031600431704160416022f4c0516031400140014000216001602160213202a621705160213202a17021600160216020e2a626d170616020e2a170216001602160216062a621707160216062a17021600160216020e2a626d170816020e2a170216001602160216082a621709160216082a1702160416022f0e7b1603160516071609020100000001050c0dce000101020103070800403d16034313202f131e7b16044313202f131e7b16014313202f13107b160543102f13117b16001601a50c3313127b140102160144ce01674416026644160344160444170716000c0dce000101a216000c000d16051607160613060cce000102000000010108a0011700a0010d2aa10116000201030408004030140100ce016744cb1704b316044113157b16021600a50c3313127bb1ce011600160113046417050c1301641706140102ce016744160044170716021603a216070c0dce02010016051606c1180103080d00403114010016016744cb1708b316084113157bb116011600160213046417090c160316041605130464170a14010216016744160044170b0d1340ff3b170c16061607a2160b0c0dce0201011609160a160cc21801000508001c14010016016744cb1705b316054113157b1401021601674416004417061606cb17071602160316040f0c1607010801030a0f00404c1609a00234131b7b1603ce013013137b1602ce012f170a14010216026744160144cb170b160a4c0e160016011605a316001604160516071608110d160b01054a0d1600160b1605a316001604160516071608110d160b0109170c14010116036744cb170d160d170e16001606a2160016030c0d160e01041608160c160913060cce000102\",\n  \"codeHash\": \"e883edaac26437b449407bfec831e89c98b8139e59235f3f49246f2ef593ec08\",\n  \"fieldsSig\": {\n    \"names\": [\n      \"governance\",\n      \"localChainId\",\n      \"receivedSequence\",\n      \"sendSequence\",\n      \"tokenBridgeFactory\",\n      \"minimalConsistencyLevel\",\n      \"refundAddress\"\n    ],\n    \"types\": [\n      \"ByteVec\",\n      \"U256\",\n      \"U256\",\n      \"U256\",\n      \"ByteVec\",\n      \"U256\",\n      \"Address\"\n    ],\n    \"isMutable\": [\n      false,\n      false,\n      true,\n      true,\n      false,\n      true,\n      true\n    ]\n  },\n  \"eventsSig\": [],\n  \"functions\": [\n    {\n      \"name\": \"parseAndVerifyGovernanceVAA\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": false,\n      \"paramNames\": [\n        \"vaa\",\n        \"action\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false\n      ],\n      \"returnTypes\": [\n        \"U256\",\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"createAttestTokenHandler\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": false,\n      \"paramNames\": [\n        \"payer\",\n        \"createContractAlphAmount\",\n        \"remoteChainId\",\n        \"remoteTokenBridgeId\",\n        \"isLocal\"\n      ],\n      \"paramTypes\": [\n        \"Address\",\n        \"U256\",\n        \"U256\",\n        \"ByteVec\",\n        \"Bool\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"createLocalAttestTokenHandler\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"payer\",\n        \"createContractAlphAmount\"\n      ],\n      \"paramTypes\": [\n        \"Address\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"parseAndVerifyRegisterChain\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": false,\n      \"paramNames\": [\n        \"vaa\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": [\n        \"U256\",\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"registerChain\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\",\n        \"payer\",\n        \"createContractAlphAmount\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"Address\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"upgradeContract\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"destroyUnexecutedSequenceContracts\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"updateMinimalConsistencyLevel\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"getRefundAddress\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"Address\"\n      ]\n    },\n    {\n      \"name\": \"updateRefundAddress\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"parseConractUpgrade\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": false,\n      \"paramNames\": [\n        \"payload\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\"\n      ],\n      \"paramIsMutable\": [\n        false\n      ],\n      \"returnTypes\": [\n        \"ByteVec\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"ByteVec\"\n      ]\n    },\n    {\n      \"name\": \"getMessageFee\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"U256\"\n      ]\n    },\n    {\n      \"name\": \"attestToken\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"payer\",\n        \"localTokenId\",\n        \"decimals\",\n        \"symbol\",\n        \"name\",\n        \"nonce\",\n        \"consistencyLevel\"\n      ],\n      \"paramTypes\": [\n        \"Address\",\n        \"ByteVec\",\n        \"U256\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"nextSendSequence\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": false,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": [\n        \"U256\"\n      ]\n    },\n    {\n      \"name\": \"createLocalTokenPool\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"localTokenId\",\n        \"decimals\",\n        \"payer\",\n        \"createContractAlphAmount\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"U256\",\n        \"Address\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"createRemoteTokenPool\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"bridgeTokenId\",\n        \"tokenChainId\",\n        \"decimals\",\n        \"symbol\",\n        \"name\",\n        \"msgSequence\",\n        \"payer\",\n        \"createContractAlphAmount\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"U256\",\n        \"U256\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"U256\",\n        \"Address\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"updateRemoteTokenPool\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"bridgeTokenId\",\n        \"tokenChainId\",\n        \"symbol\",\n        \"name\",\n        \"msgSequence\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"U256\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    },\n    {\n      \"name\": \"transferToken\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"fromAddress\",\n        \"bridgeTokenId\",\n        \"tokenChainId\",\n        \"toChainId\",\n        \"toAddress\",\n        \"tokenAmount\",\n        \"messageFee\",\n        \"arbiterFee\",\n        \"nonce\",\n        \"consistencyLevel\"\n      ],\n      \"paramTypes\": [\n        \"Address\",\n        \"ByteVec\",\n        \"U256\",\n        \"U256\",\n        \"ByteVec\",\n        \"U256\",\n        \"U256\",\n        \"U256\",\n        \"ByteVec\",\n        \"U256\"\n      ],\n      \"paramIsMutable\": [\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false,\n        false\n      ],\n      \"returnTypes\": []\n    }\n  ]\n}"));
    return TokenBridge;
}());
exports.TokenBridge = TokenBridge;
