UNPKG

@mavrykdynamics/taquito

Version:

High level functionality that builds upon the other packages in the Mavryk Typescript Library Suite.

227 lines (226 loc) 10.1 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createSmartRollupExecuteOutboxMessageOperation = exports.createSmartRollupOriginateOperation = exports.createSmartRollupAddMessagesOperation = exports.createUpdateConsensusKeyOperation = exports.createProposalsOperation = exports.createBallotOperation = exports.createDrainDelegateOperation = exports.createIncreasePaidStorageOperation = exports.createTransferTicketOperation = exports.createRegisterGlobalConstantOperation = exports.createRevealOperation = exports.createRegisterDelegateOperation = exports.createSetDelegateOperation = exports.createTransferOperation = exports.createOriginationOperation = exports.createActivationOperation = void 0; const taquito_michelson_encoder_1 = require("@mavrykdynamics/taquito-michelson-encoder"); const taquito_rpc_1 = require("@mavrykdynamics/taquito-rpc"); const constants_1 = require("../constants"); const taquito_utils_1 = require("@mavrykdynamics/taquito-utils"); const errors_1 = require("./errors"); const createActivationOperation = ({ pkh, secret }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.ACTIVATION, pkh, secret, }; }); exports.createActivationOperation = createActivationOperation; const createOriginationOperation = ({ code, init, balance = '0', delegate, storage, fee, gasLimit, storageLimit, mumav = false, }) => __awaiter(void 0, void 0, void 0, function* () { if (storage !== undefined && init !== undefined) { throw new errors_1.OriginationParameterError('Storage and Init cannot be set a the same time. Please either use storage or init but not both.'); } if (!Array.isArray(code)) { throw new errors_1.InvalidCodeParameter('Wrong code parameter type, expected an array', code); } let contractStorage; if (storage !== undefined) { const storageType = code.find((p) => 'prim' in p && p.prim === 'storage'); if ((storageType === null || storageType === void 0 ? void 0 : storageType.args) === undefined) { throw new errors_1.InvalidCodeParameter('The storage section is missing from the script', code); } const schema = new taquito_michelson_encoder_1.Schema(storageType.args[0]); // TODO contractStorage = schema.Encode(storage); } else if (init !== undefined && typeof init === 'object') { contractStorage = init; } else { throw new errors_1.InvalidInitParameter('Wrong init parameter type, expected JSON Michelson', init); } const script = { code, storage: contractStorage, }; if (isNaN(Number(balance))) { throw new errors_1.InvalidBalanceError(`Invalid Balance "${balance}", cannot be converted to a number`); } const operation = { kind: taquito_rpc_1.OpKind.ORIGINATION, fee, gas_limit: gasLimit, storage_limit: storageLimit, balance: mumav ? balance.toString() : (0, taquito_utils_1.format)('mv', 'mumav', balance).toString(), script, }; if (delegate) { operation.delegate = delegate; } return operation; }); exports.createOriginationOperation = createOriginationOperation; const createTransferOperation = ({ to, amount, parameter, fee, gasLimit, storageLimit, mumav = false, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.TRANSACTION, fee, gas_limit: gasLimit, storage_limit: storageLimit, amount: mumav ? amount.toString() : (0, taquito_utils_1.format)('mv', 'mumav', amount).toString(), destination: to, parameters: parameter, }; }); exports.createTransferOperation = createTransferOperation; const createSetDelegateOperation = ({ delegate, source, fee, gasLimit, storageLimit, }) => __awaiter(void 0, void 0, void 0, function* () { const operation = { kind: taquito_rpc_1.OpKind.DELEGATION, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, delegate, }; return operation; }); exports.createSetDelegateOperation = createSetDelegateOperation; const createRegisterDelegateOperation = ({ fee, gasLimit, storageLimit }, source) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.DELEGATION, fee, gas_limit: gasLimit, storage_limit: storageLimit, delegate: source, }; }); exports.createRegisterDelegateOperation = createRegisterDelegateOperation; const createRevealOperation = ({ fee, gasLimit, storageLimit }, source, publicKey) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.REVEAL, fee, public_key: publicKey, source, gas_limit: gasLimit !== null && gasLimit !== void 0 ? gasLimit : (0, constants_1.getRevealGasLimit)(source), storage_limit: storageLimit, }; }); exports.createRevealOperation = createRevealOperation; const createRegisterGlobalConstantOperation = ({ value, source, fee, gasLimit, storageLimit, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.REGISTER_GLOBAL_CONSTANT, value, fee, gas_limit: gasLimit, storage_limit: storageLimit, source, }; }); exports.createRegisterGlobalConstantOperation = createRegisterGlobalConstantOperation; const createTransferTicketOperation = ({ ticketContents, ticketTy, ticketTicketer, ticketAmount, destination, entrypoint, source, fee, gasLimit, storageLimit, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.TRANSFER_TICKET, fee, gas_limit: gasLimit, storage_limit: storageLimit, source, ticket_contents: ticketContents, ticket_ty: ticketTy, ticket_ticketer: ticketTicketer, ticket_amount: ticketAmount, destination, entrypoint, }; }); exports.createTransferTicketOperation = createTransferTicketOperation; const createIncreasePaidStorageOperation = ({ source, fee, gasLimit, storageLimit, amount, destination, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.INCREASE_PAID_STORAGE, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, amount, destination, }; }); exports.createIncreasePaidStorageOperation = createIncreasePaidStorageOperation; const createDrainDelegateOperation = ({ consensus_key, delegate, destination, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.DRAIN_DELEGATE, consensus_key, delegate, destination, }; }); exports.createDrainDelegateOperation = createDrainDelegateOperation; const createBallotOperation = ({ source, proposal, ballot }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.BALLOT, source, proposal, ballot, }; }); exports.createBallotOperation = createBallotOperation; const createProposalsOperation = ({ source, proposals }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.PROPOSALS, source, proposals, }; }); exports.createProposalsOperation = createProposalsOperation; const createUpdateConsensusKeyOperation = ({ source, fee, gasLimit, storageLimit, pk, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.UPDATE_CONSENSUS_KEY, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, pk, }; }); exports.createUpdateConsensusKeyOperation = createUpdateConsensusKeyOperation; const createSmartRollupAddMessagesOperation = ({ source, fee, gasLimit, storageLimit, message, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.SMART_ROLLUP_ADD_MESSAGES, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, message, }; }); exports.createSmartRollupAddMessagesOperation = createSmartRollupAddMessagesOperation; const createSmartRollupOriginateOperation = ({ source, fee, gasLimit, storageLimit, pvmKind, kernel, parametersType, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.SMART_ROLLUP_ORIGINATE, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, pvm_kind: pvmKind, kernel, parameters_ty: parametersType, }; }); exports.createSmartRollupOriginateOperation = createSmartRollupOriginateOperation; const createSmartRollupExecuteOutboxMessageOperation = ({ source, fee, gasLimit, storageLimit, rollup, cementedCommitment, outputProof, }) => __awaiter(void 0, void 0, void 0, function* () { return { kind: taquito_rpc_1.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE, source, fee, gas_limit: gasLimit, storage_limit: storageLimit, rollup, cemented_commitment: cementedCommitment, output_proof: outputProof, }; }); exports.createSmartRollupExecuteOutboxMessageOperation = createSmartRollupExecuteOutboxMessageOperation;