"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.AttestTokenHandler = void 0;
var web3_1 = require("@alephium/web3");
var AttestTokenHandler = /** @class */ (function () {
    function AttestTokenHandler(address, contractId, groupIndex, deployResult) {
        this.address = address;
        this.contractId = contractId;
        this.groupIndex = groupIndex;
        this.deployResult = deployResult;
    }
    AttestTokenHandler.deploy = function (signer, governance, localTokenBridge, chainId, tokenBridgeId, receivedSequence, isLocalHandler, _extraParams) {
        return __awaiter(this, void 0, void 0, function () {
            var _deployResult;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, AttestTokenHandler.contract.deploy(signer, {
                            initialFields: {
                                governance: governance,
                                localTokenBridge: localTokenBridge,
                                chainId: chainId,
                                tokenBridgeId: tokenBridgeId,
                                receivedSequence: receivedSequence,
                                isLocalHandler: isLocalHandler,
                            },
                            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 AttestTokenHandler(_deployResult.contractAddress, _deployResult.contractId, _deployResult.fromGroup, _deployResult)];
                }
            });
        });
    };
    AttestTokenHandler.connect = function (address, deployResult) {
        var contractId = web3_1.binToHex(web3_1.contractIdFromAddress(address));
        var groupIndex = parseInt(contractId.slice(-2));
        return new AttestTokenHandler(address, contractId, groupIndex, deployResult);
    };
    AttestTokenHandler.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*/, AttestTokenHandler.contract.fetchState(this.address, this.groupIndex)];
                    case 1:
                        state = _a.sent();
                        return [2 /*return*/, __assign(__assign({}, state), { governance: state.fields["governance"], localTokenBridge: state.fields["localTokenBridge"], chainId: state.fields["chainId"], tokenBridgeId: state.fields["tokenBridgeId"], receivedSequence: state.fields["receivedSequence"], isLocalHandler: state.fields["isLocalHandler"] })];
                }
            });
        });
    };
    // This is used for testing contract functions
    AttestTokenHandler.stateForTest = function (governance, localTokenBridge, chainId, tokenBridgeId, receivedSequence, isLocalHandler, 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 AttestTokenHandler.contract.toState({
            governance: governance,
            localTokenBridge: localTokenBridge,
            chainId: chainId,
            tokenBridgeId: tokenBridgeId,
            receivedSequence: receivedSequence,
            isLocalHandler: isLocalHandler,
        }, newAsset, address);
    };
    AttestTokenHandler.testParseAttestToken = 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*/, AttestTokenHandler.contract.testPrivateMethod("parseAttestToken", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    AttestTokenHandler.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: 1, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, AttestTokenHandler.contract.testPublicMethod("createLocalTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    AttestTokenHandler.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: 2, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, AttestTokenHandler.contract.testPublicMethod("createRemoteTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    AttestTokenHandler.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: 3, testArgs: args, initialFields: _initFields, initialAsset: _initialAsset });
                        return [4 /*yield*/, AttestTokenHandler.contract.testPublicMethod("updateRemoteTokenPool", _testParams)];
                    case 1:
                        _testResult = _d.sent();
                        return [2 /*return*/, __assign(__assign({}, _testResult), { returns: _testResult.returns })];
                }
            });
        });
    };
    AttestTokenHandler.contract = web3_1.Contract.fromJson(JSON.parse("{\n  \"version\": \"v1.7.0\",\n  \"name\": \"AttestTokenHandler\",\n  \"bytecode\": \"0604409540c440fa41230000010b0540571600040e11ce000103170517041703170217011601ce022f0c7b1603ce03410d7b16020c2f130d7b1604a000340f7b16040d2aa10016050c0d621401024113187b16050d1321621706160513211323626d17071607ce022f13177b160513231324626c170816051324134044621709160513404413406462170a1605431340642f0e7b16061609160a1608160402010304060019ce04131f7b160000001817051818170416017a1602a216041603a31604160516011602100cce01010e01030308001ace0419131f7b160000001707170617051704170316011602a21603ce0216061604160516071601160213080cce01010f010001050014ce0419131f7b160000001704181703170217011601ce02160216031604110cce010110\",\n  \"codeHash\": \"741f7658d2746b8d678a329a1ebc1f433ef645c0d4c7e0dc425b958b0a87b8bb\",\n  \"fieldsSig\": {\n    \"names\": [\n      \"governance\",\n      \"localTokenBridge\",\n      \"chainId\",\n      \"tokenBridgeId\",\n      \"receivedSequence\",\n      \"isLocalHandler\"\n    ],\n    \"types\": [\n      \"ByteVec\",\n      \"ByteVec\",\n      \"U256\",\n      \"ByteVec\",\n      \"U256\",\n      \"Bool\"\n    ],\n    \"isMutable\": [\n      false,\n      false,\n      false,\n      false,\n      true,\n      false\n    ]\n  },\n  \"eventsSig\": [],\n  \"functions\": [\n    {\n      \"name\": \"parseAttestToken\",\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        \"ByteVec\",\n        \"ByteVec\",\n        \"ByteVec\",\n        \"U256\",\n        \"U256\"\n      ]\n    },\n    {\n      \"name\": \"createLocalTokenPool\",\n      \"usePreapprovedAssets\": true,\n      \"useAssetsInContract\": false,\n      \"isPublic\": true,\n      \"paramNames\": [\n        \"vaa\",\n        \"payer\",\n        \"createContractAlphAmount\",\n        \"tokenAmount\"\n      ],\n      \"paramTypes\": [\n        \"ByteVec\",\n        \"Address\",\n        \"U256\",\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        \"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\": \"updateRemoteTokenPool\",\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}"));
    return AttestTokenHandler;
}());
exports.AttestTokenHandler = AttestTokenHandler;
