@taquito/taquito
Version:
High level functionality that builds upon the other packages in the Tezos Typescript Library Suite.
674 lines (673 loc) • 35.3 kB
JavaScript
"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());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RPCEstimateProvider = void 0;
const errors_1 = require("../operations/errors");
const types_1 = require("../operations/types");
const estimate_1 = require("./estimate");
const utils_1 = require("@taquito/utils");
const errors_2 = require("./errors");
const provider_1 = require("../provider");
const prepare_provider_1 = require("../prepare/prepare-provider");
const core_1 = require("@taquito/core");
// stub signature that won't be verified by tezos rpc simulate_operation
const STUB_SIGNATURE = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg';
class RPCEstimateProvider extends provider_1.Provider {
constructor() {
super(...arguments);
this.REVEAL_LENGTH = 324; // injecting size tz1=320, tz2=322, tz3=322
this.REVEAL_LENGTH_TZ4 = 622; // injecting size tz4=620
this.MILLIGAS_BUFFER = 100 * 1000; // 100 buffer depends on operation kind
this.STORAGE_BUFFER = 20; // according to octez-client
this.prepare = new prepare_provider_1.PrepareProvider(this.context);
}
getKeys() {
return __awaiter(this, void 0, void 0, function* () {
const isSignerConfigured = this.context.isAnySignerConfigured();
return {
publicKeyHash: isSignerConfigured
? yield this.signer.publicKeyHash()
: yield this.context.wallet.pkh(),
publicKey: isSignerConfigured
? yield this.signer.publicKey()
: yield this.context.wallet.pk(),
};
});
}
getEstimationPropertiesFromOperationContent(content, size, costPerByte, originationSize) {
const operationResults = (0, errors_1.flattenOperationResult)({ contents: [content] });
let consumedMilligas = 0;
let accumulatedStorage = 0;
operationResults.forEach((result) => {
consumedMilligas += Number(result.consumed_milligas) || 0;
// transfer to unrevealed implicit
accumulatedStorage += 'allocated_destination_contract' in result ? originationSize : 0;
// originate
accumulatedStorage +=
'originated_contracts' in result && Array.isArray(result.originated_contracts)
? result.originated_contracts.length * originationSize
: 0;
// register_global_constants
accumulatedStorage +=
'storage_size' in result && 'global_address' in result
? Number(result.storage_size) || 0
: 0;
// transfer_ticket, originate, contract_call
accumulatedStorage +=
'paid_storage_size_diff' in result ? Number(result.paid_storage_size_diff) || 0 : 0;
//smart_rollup_originate
accumulatedStorage += 'genesis_commitment_hash' in result ? Number(result.size) || 0 : 0;
});
if ((0, types_1.isOpWithFee)(content)) {
return {
milligasLimit: (0, types_1.isOpWithGasBuffer)(content)
? consumedMilligas + Number(this.MILLIGAS_BUFFER)
: consumedMilligas,
storageLimit: accumulatedStorage > 0 ? accumulatedStorage + this.STORAGE_BUFFER : 0,
opSize: size,
minimalFeePerStorageByteMutez: costPerByte.toNumber(),
};
}
else {
return {
milligasLimit: 0,
storageLimit: 0,
opSize: size,
minimalFeePerStorageByteMutez: costPerByte.toNumber(),
baseFeeMutez: 0,
};
}
}
calculateEstimates(op, constants) {
return __awaiter(this, void 0, void 0, function* () {
const { opbytes, opOb: { branch, contents }, } = yield this.forge(op);
const operation = {
operation: { branch, contents, signature: STUB_SIGNATURE },
chain_id: yield this.context.readProvider.getChainId(),
};
const { opResponse } = yield this.simulate(operation);
const { cost_per_byte, origination_size } = constants;
const errors = [...(0, errors_1.flattenErrors)(opResponse, 'backtracked'), ...(0, errors_1.flattenErrors)(opResponse)];
// Fail early in case of errors
if (errors.length) {
throw new errors_1.TezosOperationError(errors, 'Error occurred during estimation', opResponse.contents);
}
let numberOfOps = 1;
if (Array.isArray(op.opOb.contents) && op.opOb.contents.length > 1) {
numberOfOps =
opResponse.contents[0].kind === 'reveal'
? op.opOb.contents.length - 1
: op.opOb.contents.length;
}
return opResponse.contents.map((x) => {
const content = x;
content.source = content.source || '';
let revealSize, eachOpSize;
if (content.source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)) {
revealSize = this.REVEAL_LENGTH_TZ4 / 2;
eachOpSize = (opbytes.length / 2 + utils_1.payloadLength[utils_1.PrefixV2.BLS12_381Signature]) / numberOfOps;
}
else {
revealSize = this.REVEAL_LENGTH / 2;
eachOpSize = (opbytes.length / 2 + utils_1.payloadLength[utils_1.PrefixV2.Ed25519Signature]) / numberOfOps;
}
return this.getEstimationPropertiesFromOperationContent(x,
// diff between estimated and injecting OP_SIZE is 124-126, we added buffer to use 130
x.kind === 'reveal' ? revealSize : eachOpSize, cost_per_byte, origination_size !== null && origination_size !== void 0 ? origination_size : 257 // protocol constants
);
});
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an origination operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param OriginationOperation Originate operation parameter
*/
originate(params) {
return __awaiter(this, void 0, void 0, function* () {
const preparedOperation = yield this.prepare.originate(params);
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties.shift();
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an transfer operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param TransferOperation Originate operation parameter
*/
transfer(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b;
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const toValidation = (0, utils_1.validateAddress)(rest.to);
if (toValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.to, toValidation);
}
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
if (rest.amount < 0) {
throw new core_1.InvalidAmountError(rest.amount.toString());
}
const preparedOperation = yield this.prepare.transaction(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties.shift();
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an stake pseudo-operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Stake pseudo-operation parameter
*/
stake(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b;
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
if (!rest.to) {
rest.to = rest.source;
}
if (rest.to && rest.to !== rest.source) {
throw new core_1.InvalidStakingAddressError(rest.to);
}
if (rest.amount < 0) {
throw new core_1.InvalidAmountError(rest.amount.toString());
}
const preparedOperation = yield this.prepare.stake(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an Unstake pseudo-operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Unstake pseudo-operation parameter
*/
unstake(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b;
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
if (!rest.to) {
rest.to = rest.source;
}
if (rest.to && rest.to !== rest.source) {
throw new core_1.InvalidStakingAddressError(rest.to);
}
if (rest.amount < 0) {
throw new core_1.InvalidAmountError(rest.amount.toString());
}
const preparedOperation = yield this.prepare.unstake(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an finalize_unstake pseudo-operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param finalize_unstake pseudo-operation parameter
*/
finalizeUnstake(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b;
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
if (!rest.to) {
rest.to = rest.source;
}
if (!rest.amount) {
rest.amount = 0;
}
if (rest.amount !== undefined && rest.amount !== 0) {
throw new Error('Amount must be 0 for finalize_unstake operation');
}
const preparedOperation = yield this.prepare.finalizeUnstake(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a transferTicket operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param TransferTicketParams operation parameter
*/
transferTicket(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b;
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const destinationValidation = (0, utils_1.validateAddress)(rest.destination);
if (destinationValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.destination, destinationValidation);
}
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.transferTicket(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
setDelegate(_a) {
return __awaiter(this, void 0, void 0, function* () {
var _b, _c;
var { fee, gasLimit, storageLimit } = _a, rest = __rest(_a, ["fee", "gasLimit", "storageLimit"]);
const sourceValidation = (0, utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
if (rest.source && sourceValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.source, sourceValidation);
}
const delegateValidation = (0, utils_1.validateAddress)((_c = rest.delegate) !== null && _c !== void 0 ? _c : '');
if (rest.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
throw new core_1.InvalidAddressError(rest.delegate, delegateValidation);
}
const preparedOperation = yield this.prepare.delegation(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a each operation in the batch
*
* @returns An array of Estimate objects. If a reveal operation is needed, the first element of the array is the Estimate for the reveal operation.
*/
batch(params) {
return __awaiter(this, void 0, void 0, function* () {
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperations = yield this.prepare.batch(params);
const estimateProperties = yield this.calculateEstimates(preparedOperations, protocolConstants);
return estimate_1.Estimate.createArrayEstimateInstancesFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
registerDelegate(_a, source) {
return __awaiter(this, void 0, void 0, function* () {
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const pkh = (yield this.getKeys()).publicKeyHash;
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const checkSource = source || pkh;
const preparedOperation = yield this.prepare.registerDelegate(Object.assign({ fee, storageLimit, gasLimit }, rest), checkSource);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees to reveal the current account
* @returns An estimation of gasLimit, storageLimit and fees for the operation or undefined if the account is already revealed
*
* @param Estimate
*/
reveal(params) {
return __awaiter(this, void 0, void 0, function* () {
const { publicKeyHash, publicKey } = yield this.getKeys();
if (!publicKey) {
throw new errors_2.RevealEstimateError();
}
if (yield this.isAccountRevealRequired(publicKeyHash)) {
const [, pkhPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(publicKeyHash, utils_1.publicKeyHashPrefixes);
if (pkhPrefix === utils_1.PrefixV2.BLS12_381PublicKeyHash) {
if (params && params.proof) {
(0, utils_1.b58DecodeAndCheckPrefix)(params.proof, [utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
}
else {
const { prefixSig } = yield this.signer.provePossession();
params = Object.assign(Object.assign({}, params), { proof: prefixSig });
}
}
else {
if (params && params.proof) {
throw new core_1.ProhibitedActionError('Proof field is only allowed to reveal a bls account ');
}
}
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = params
? yield this.prepare.reveal(params)
: yield this.prepare.reveal({});
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
}
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an registerGlobalConstant operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param params registerGlobalConstant operation parameter
*/
registerGlobalConstant(_a) {
return __awaiter(this, void 0, void 0, function* () {
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
const preparedOperation = yield this.prepare.registerGlobalConstant(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit, and fees for an increasePaidStorage operation
*
* @returns An estimation of gasLimit, storageLimit, and fees for the operation
*
* @param params increasePaidStorage operation parameters
*/
increasePaidStorage(_a) {
return __awaiter(this, void 0, void 0, function* () {
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
if (rest.amount <= 0) {
throw new core_1.InvalidAmountError(rest.amount.toString());
}
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.increasePaidStorage(Object.assign({ fee,
storageLimit,
gasLimit }, rest));
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an Update Consensus Key operation
* @returns An estimation of gasLimit, storageLimit and fees for the operation
* @param Estimate
*/
updateConsensusKey(params) {
return __awaiter(this, void 0, void 0, function* () {
const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
if (pkPrefix === utils_1.PrefixV2.BLS12_381PublicKey) {
if (!params.proof) {
throw new core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
}
}
else {
if (params.proof) {
throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as consensus key');
}
}
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.updateConsensusKey(params);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an Update Companion Key operation
* @returns An estimation of gasLimit, storageLimit and fees for the operation
* @param Estimate
*/
updateCompanionKey(params) {
return __awaiter(this, void 0, void 0, function* () {
const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
if (pkPrefix !== utils_1.PrefixV2.BLS12_381PublicKey) {
throw new core_1.ProhibitedActionError('companion key must be a bls account');
}
if (!params.proof) {
throw new core_1.InvalidProofError('Proof is required to set a bls account as companion key ');
}
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.updateCompanionKey(params);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a smart_rollup_add_messages operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
smartRollupAddMessages(params) {
return __awaiter(this, void 0, void 0, function* () {
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.smartRollupAddMessages(params);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an Smart Rollup Originate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param SmartRollupOriginateParams
*/
smartRollupOriginate(params) {
return __awaiter(this, void 0, void 0, function* () {
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.smartRollupOriginate(params);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for a smart_rollup_execute_outbox_message operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
smartRollupExecuteOutboxMessage(params) {
return __awaiter(this, void 0, void 0, function* () {
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.smartRollupExecuteOutboxMessage(params);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for contract call
*
* @returns An estimation of gasLimit, storageLimit and fees for the contract call
*
* @param Estimate
*/
contractCall(contractMethod) {
return __awaiter(this, void 0, void 0, function* () {
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
const preparedOperation = yield this.prepare.contractCall(contractMethod);
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
estimateProperties.shift();
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(utils_1.PrefixV2.BLS12_381PublicKeyHash)
? this.REVEAL_LENGTH_TZ4 / 2
: this.REVEAL_LENGTH / 2;
estimateProperties[0].opSize -= revealSize;
}
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
});
}
}
exports.RPCEstimateProvider = RPCEstimateProvider;