"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.TokenBridgeV1 = void 0;
var web3_1 = require("@alephium/web3");
var TokenBridgeV1 = /** @class */ (function () {
    function TokenBridgeV1(address, contractId, groupIndex, deployResult) {
        this.address = address;
        this.contractId = contractId;
        this.groupIndex = groupIndex;
        this.deployResult = deployResult;
    }
    TokenBridgeV1.deploy = function (signer, governanceContractId, 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*/, TokenBridgeV1.contract.deploy(signer, {
                            initialFields: {
                                governanceContractId: governanceContractId,
                                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 TokenBridgeV1(_deployResult.contractAddress, _deployResult.contractId, _deployResult.fromGroup, _deployResult)];
                }
            });
        });
    };
    TokenBridgeV1.connect = function (address, deployResult) {
        var contractId = web3_1.binToHex(web3_1.contractIdFromAddress(address));
        var groupIndex = parseInt(contractId.slice(-2));
        return new TokenBridgeV1(address, contractId, groupIndex, deployResult);
    };
    TokenBridgeV1.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*/, TokenBridgeV1.contract.fetchState(this.address, this.groupIndex)];
                    case 1:
                        state = _a.sent();
                        return [2 /*return*/, __assign(__assign({}, state), { governanceContractId: state.fields["governanceContractId"], 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
    TokenBridgeV1.stateForTest = function (governanceContractId, 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 TokenBridgeV1.contract.toState({
            governanceContractId: governanceContractId,
            localChainId: localChainId,
            receivedSequence: receivedSequence,
            sendSequence: sendSequence,
            tokenBridgeFactory: tokenBridgeFactory,
            minimalConsistencyLevel: minimalConsistencyLevel,
            refundAddress: refundAddress,
        }, newAsset, address);
    };
    TokenBridgeV1.testFoo = 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*/, TokenBridgeV1.contract.testPublicMethod("foo", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    TokenBridgeV1.contract = web3_1.Contract.fromJson(JSON.parse("{\n  \"version\": \"v1.7.0\",\n  \"name\": \"TokenBridgeV1\",\n  \"bytecode\": \"070106010000000000\",\n  \"codeHash\": \"0778af62d0feb156513decbaaa86999da11a1b7fd7aaaecc767a25155b33d15c\",\n  \"fieldsSig\": {\n    \"names\": [\n      \"governanceContractId\",\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\": \"foo\",\n      \"usePreapprovedAssets\": false,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [],\n      \"paramTypes\": [],\n      \"paramIsMutable\": [],\n      \"returnTypes\": []\n    }\n  ]\n}"));
    return TokenBridgeV1;
}());
exports.TokenBridgeV1 = TokenBridgeV1;
