@tezos-x/octez.js 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +154 -0
- package/dist/lib/batch/constants.js +16 -0
- package/dist/lib/batch/rpc-batch-provider.js +319 -0
- package/dist/lib/constants.js +133 -0
- package/dist/lib/context.js +182 -0
- package/dist/lib/contract/big-map.js +70 -0
- package/dist/lib/contract/compose.js +6 -0
- package/dist/lib/contract/constants.js +4 -0
- package/dist/lib/contract/contract-methods/contract-method-factory.js +18 -0
- package/dist/lib/contract/contract-methods/contract-method-interface.js +2 -0
- package/dist/lib/contract/contract-methods/contract-method-object-param.js +72 -0
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +124 -0
- package/dist/lib/contract/contract.js +169 -0
- package/dist/lib/contract/errors.js +140 -0
- package/dist/lib/contract/index.js +30 -0
- package/dist/lib/contract/interface.js +2 -0
- package/dist/lib/contract/manager-lambda.js +71 -0
- package/dist/lib/contract/prepare.js +240 -0
- package/dist/lib/contract/rpc-contract-provider.js +724 -0
- package/dist/lib/contract/sapling-state-abstraction.js +35 -0
- package/dist/lib/contract/semantic.js +40 -0
- package/dist/lib/contract/view_lambda.js +27 -0
- package/dist/lib/errors.js +42 -0
- package/dist/lib/estimate/errors.js +16 -0
- package/dist/lib/estimate/estimate-provider-interface.js +2 -0
- package/dist/lib/estimate/estimate.js +130 -0
- package/dist/lib/estimate/index.js +20 -0
- package/dist/lib/estimate/rpc-estimate-provider.js +673 -0
- package/dist/lib/extension/extension.js +2 -0
- package/dist/lib/forger/composite-forger.js +43 -0
- package/dist/lib/forger/errors.js +30 -0
- package/dist/lib/forger/octez.js-local-forger.js +34 -0
- package/dist/lib/forger/rpc-forger.js +12 -0
- package/dist/lib/global-constants/default-global-constants-provider.js +46 -0
- package/dist/lib/global-constants/errors.js +30 -0
- package/dist/lib/global-constants/interface-global-constants-provider.js +2 -0
- package/dist/lib/global-constants/noop-global-constants-provider.js +21 -0
- package/dist/lib/import-key.js +51 -0
- package/dist/lib/injector/helper.js +18 -0
- package/dist/lib/injector/interface.js +2 -0
- package/dist/lib/injector/rpc-injector.js +38 -0
- package/dist/lib/octez.js +404 -0
- package/dist/lib/operations/ballot-operation.js +33 -0
- package/dist/lib/operations/batch-operation.js +66 -0
- package/dist/lib/operations/delegate-operation.js +57 -0
- package/dist/lib/operations/drain-delegate-operation.js +31 -0
- package/dist/lib/operations/errors.js +130 -0
- package/dist/lib/operations/failing-noop-operation.js +2 -0
- package/dist/lib/operations/increase-paid-storage-operation.js +52 -0
- package/dist/lib/operations/index.js +54 -0
- package/dist/lib/operations/operations.js +123 -0
- package/dist/lib/operations/origination-operation.js +89 -0
- package/dist/lib/operations/proposals-operation.js +30 -0
- package/dist/lib/operations/register-global-constant-operation.js +55 -0
- package/dist/lib/operations/reveal-operation.js +74 -0
- package/dist/lib/operations/smart-rollup-add-messages-operation.js +47 -0
- package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +56 -0
- package/dist/lib/operations/smart-rollup-originate-operation.js +53 -0
- package/dist/lib/operations/transaction-operation.js +70 -0
- package/dist/lib/operations/transfer-ticket-operation.js +49 -0
- package/dist/lib/operations/types.js +90 -0
- package/dist/lib/operations/update-companion-key-operation.js +58 -0
- package/dist/lib/operations/update-consensus-key-operation.js +58 -0
- package/dist/lib/packer/interface.js +2 -0
- package/dist/lib/packer/michel-codec-packer.js +22 -0
- package/dist/lib/packer/rpc-packer.js +23 -0
- package/dist/lib/parser/interface.js +2 -0
- package/dist/lib/parser/michel-codec-parser.js +135 -0
- package/dist/lib/parser/noop-parser.js +20 -0
- package/dist/lib/prepare/index.js +18 -0
- package/dist/lib/prepare/interface.js +2 -0
- package/dist/lib/prepare/prepare-provider.js +1010 -0
- package/dist/lib/provider.js +169 -0
- package/dist/lib/read-provider/interface.js +2 -0
- package/dist/lib/read-provider/rpc-read-adapter.js +228 -0
- package/dist/lib/signer/errors.js +17 -0
- package/dist/lib/signer/noop.js +40 -0
- package/dist/lib/subscribe/create-observable-from-subscription.js +20 -0
- package/dist/lib/subscribe/errors.js +30 -0
- package/dist/lib/subscribe/filters.js +96 -0
- package/dist/lib/subscribe/interface.js +2 -0
- package/dist/lib/subscribe/observable-subscription.js +79 -0
- package/dist/lib/subscribe/polling-subcribe-provider.js +118 -0
- package/dist/lib/tz/interface.js +2 -0
- package/dist/lib/tz/rpc-tz-provider.js +63 -0
- package/dist/lib/version.js +8 -0
- package/dist/lib/wallet/batch-operation.js +84 -0
- package/dist/lib/wallet/delegation-operation.js +57 -0
- package/dist/lib/wallet/errors.js +28 -0
- package/dist/lib/wallet/increase-paid-storage-operation.js +57 -0
- package/dist/lib/wallet/index.js +25 -0
- package/dist/lib/wallet/interface.js +2 -0
- package/dist/lib/wallet/legacy.js +86 -0
- package/dist/lib/wallet/operation-factory.js +117 -0
- package/dist/lib/wallet/operation.js +157 -0
- package/dist/lib/wallet/origination-operation.js +65 -0
- package/dist/lib/wallet/receipt.js +43 -0
- package/dist/lib/wallet/register-global-constant-operation.js +62 -0
- package/dist/lib/wallet/transaction-operation.js +53 -0
- package/dist/lib/wallet/transfer-ticket-operation.js +53 -0
- package/dist/lib/wallet/wallet.js +442 -0
- package/dist/octez.es6.js +7673 -0
- package/dist/octez.es6.js.map +1 -0
- package/dist/octez.umd.js +7787 -0
- package/dist/octez.umd.js.map +1 -0
- package/dist/types/batch/constants.d.ts +3 -0
- package/dist/types/batch/rpc-batch-provider.d.ts +139 -0
- package/dist/types/constants.d.ts +81 -0
- package/dist/types/context.d.ts +100 -0
- package/dist/types/contract/big-map.d.ts +35 -0
- package/dist/types/contract/compose.d.ts +5 -0
- package/dist/types/contract/constants.d.ts +1 -0
- package/dist/types/contract/contract-methods/contract-method-factory.d.ts +14 -0
- package/dist/types/contract/contract-methods/contract-method-interface.d.ts +28 -0
- package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +39 -0
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +43 -0
- package/dist/types/contract/contract.d.ts +75 -0
- package/dist/types/contract/errors.d.ts +83 -0
- package/dist/types/contract/index.d.ts +11 -0
- package/dist/types/contract/interface.d.ts +254 -0
- package/dist/types/contract/manager-lambda.d.ts +73 -0
- package/dist/types/contract/prepare.d.ts +18 -0
- package/dist/types/contract/rpc-contract-provider.d.ts +269 -0
- package/dist/types/contract/sapling-state-abstraction.d.ts +17 -0
- package/dist/types/contract/semantic.d.ts +7 -0
- package/dist/types/contract/view_lambda.d.ts +34 -0
- package/dist/types/errors.d.ts +26 -0
- package/dist/types/estimate/errors.d.ts +8 -0
- package/dist/types/estimate/estimate-provider-interface.d.ts +156 -0
- package/dist/types/estimate/estimate.d.ts +94 -0
- package/dist/types/estimate/index.d.ts +4 -0
- package/dist/types/estimate/rpc-estimate-provider.d.ts +170 -0
- package/dist/types/extension/extension.d.ts +4 -0
- package/dist/types/forger/composite-forger.d.ts +6 -0
- package/dist/types/forger/errors.d.ts +16 -0
- package/dist/types/forger/octez.js-local-forger.d.ts +8 -0
- package/dist/types/forger/rpc-forger.d.ts +7 -0
- package/dist/types/global-constants/default-global-constants-provider.d.ts +18 -0
- package/dist/types/global-constants/errors.d.ts +16 -0
- package/dist/types/global-constants/interface-global-constants-provider.d.ts +11 -0
- package/dist/types/global-constants/noop-global-constants-provider.d.ts +5 -0
- package/dist/types/import-key.d.ts +13 -0
- package/dist/types/injector/helper.d.ts +2 -0
- package/dist/types/injector/interface.d.ts +5 -0
- package/dist/types/injector/rpc-injector.d.ts +7 -0
- package/dist/types/octez.d.ts +248 -0
- package/dist/types/operations/ballot-operation.d.ts +18 -0
- package/dist/types/operations/batch-operation.d.ts +19 -0
- package/dist/types/operations/delegate-operation.d.ts +24 -0
- package/dist/types/operations/drain-delegate-operation.d.ts +17 -0
- package/dist/types/operations/errors.d.ts +50 -0
- package/dist/types/operations/failing-noop-operation.d.ts +17 -0
- package/dist/types/operations/increase-paid-storage-operation.d.ts +23 -0
- package/dist/types/operations/index.d.ts +18 -0
- package/dist/types/operations/operations.d.ts +35 -0
- package/dist/types/operations/origination-operation.d.ts +35 -0
- package/dist/types/operations/proposals-operation.d.ts +17 -0
- package/dist/types/operations/register-global-constant-operation.d.ts +25 -0
- package/dist/types/operations/reveal-operation.d.ts +25 -0
- package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +20 -0
- package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +24 -0
- package/dist/types/operations/smart-rollup-originate-operation.d.ts +23 -0
- package/dist/types/operations/transaction-operation.d.ts +28 -0
- package/dist/types/operations/transfer-ticket-operation.d.ts +22 -0
- package/dist/types/operations/types.d.ts +461 -0
- package/dist/types/operations/update-companion-key-operation.d.ts +23 -0
- package/dist/types/operations/update-consensus-key-operation.d.ts +23 -0
- package/dist/types/packer/interface.d.ts +4 -0
- package/dist/types/packer/michel-codec-packer.d.ts +5 -0
- package/dist/types/packer/rpc-packer.d.ts +8 -0
- package/dist/types/parser/interface.d.ts +4 -0
- package/dist/types/parser/michel-codec-parser.d.ts +16 -0
- package/dist/types/parser/noop-parser.d.ts +5 -0
- package/dist/types/prepare/index.d.ts +2 -0
- package/dist/types/prepare/interface.d.ts +153 -0
- package/dist/types/prepare/prepare-provider.d.ts +213 -0
- package/dist/types/provider.d.ts +44 -0
- package/dist/types/read-provider/interface.d.ts +132 -0
- package/dist/types/read-provider/rpc-read-adapter.d.ts +130 -0
- package/dist/types/signer/errors.d.ts +8 -0
- package/dist/types/signer/noop.d.ts +11 -0
- package/dist/types/subscribe/create-observable-from-subscription.d.ts +4 -0
- package/dist/types/subscribe/errors.d.ts +18 -0
- package/dist/types/subscribe/filters.d.ts +6 -0
- package/dist/types/subscribe/interface.d.ts +48 -0
- package/dist/types/subscribe/observable-subscription.d.ts +21 -0
- package/dist/types/subscribe/polling-subcribe-provider.d.ts +23 -0
- package/dist/types/tz/interface.d.ts +20 -0
- package/dist/types/tz/rpc-tz-provider.d.ts +13 -0
- package/dist/types/version.d.ts +4 -0
- package/dist/types/wallet/batch-operation.d.ts +13 -0
- package/dist/types/wallet/delegation-operation.d.ts +12 -0
- package/dist/types/wallet/errors.d.ts +16 -0
- package/dist/types/wallet/increase-paid-storage-operation.d.ts +12 -0
- package/dist/types/wallet/index.d.ts +9 -0
- package/dist/types/wallet/interface.d.ts +66 -0
- package/dist/types/wallet/legacy.d.ts +21 -0
- package/dist/types/wallet/operation-factory.d.ts +32 -0
- package/dist/types/wallet/operation.d.ts +54 -0
- package/dist/types/wallet/origination-operation.d.ts +14 -0
- package/dist/types/wallet/receipt.d.ts +16 -0
- package/dist/types/wallet/register-global-constant-operation.d.ts +13 -0
- package/dist/types/wallet/transaction-operation.d.ts +12 -0
- package/dist/types/wallet/transfer-ticket-operation.d.ts +12 -0
- package/dist/types/wallet/wallet.d.ts +195 -0
- package/package.json +131 -0
- package/patch.js +20 -0
- package/signature.json +866 -0
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.RPCEstimateProvider = void 0;
|
|
24
|
+
const errors_1 = require("../operations/errors");
|
|
25
|
+
const types_1 = require("../operations/types");
|
|
26
|
+
const estimate_1 = require("./estimate");
|
|
27
|
+
const octez_js_utils_1 = require("@tezos-x/octez.js-utils");
|
|
28
|
+
const errors_2 = require("./errors");
|
|
29
|
+
const provider_1 = require("../provider");
|
|
30
|
+
const prepare_provider_1 = require("../prepare/prepare-provider");
|
|
31
|
+
const octez_js_core_1 = require("@tezos-x/octez.js-core");
|
|
32
|
+
// stub signature that won't be verified by tezos rpc simulate_operation
|
|
33
|
+
const STUB_SIGNATURE = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg';
|
|
34
|
+
class RPCEstimateProvider extends provider_1.Provider {
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
this.REVEAL_LENGTH = 324; // injecting size tz1=320, tz2=322, tz3=322
|
|
38
|
+
this.REVEAL_LENGTH_TZ4 = 622; // injecting size tz4=620
|
|
39
|
+
this.MILLIGAS_BUFFER = 100 * 1000; // 100 buffer depends on operation kind
|
|
40
|
+
this.STORAGE_BUFFER = 20; // according to octez-client
|
|
41
|
+
this.prepare = new prepare_provider_1.PrepareProvider(this.context);
|
|
42
|
+
}
|
|
43
|
+
getKeys() {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const isSignerConfigured = this.context.isAnySignerConfigured();
|
|
46
|
+
return {
|
|
47
|
+
publicKeyHash: isSignerConfigured
|
|
48
|
+
? yield this.signer.publicKeyHash()
|
|
49
|
+
: yield this.context.wallet.pkh(),
|
|
50
|
+
publicKey: isSignerConfigured
|
|
51
|
+
? yield this.signer.publicKey()
|
|
52
|
+
: yield this.context.wallet.pk(),
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
getEstimationPropertiesFromOperationContent(content, size, costPerByte, originationSize) {
|
|
57
|
+
const operationResults = (0, errors_1.flattenOperationResult)({ contents: [content] });
|
|
58
|
+
let consumedMilligas = 0;
|
|
59
|
+
let accumulatedStorage = 0;
|
|
60
|
+
operationResults.forEach((result) => {
|
|
61
|
+
consumedMilligas += Number(result.consumed_milligas) || 0;
|
|
62
|
+
// transfer to unrevealed implicit
|
|
63
|
+
accumulatedStorage += 'allocated_destination_contract' in result ? originationSize : 0;
|
|
64
|
+
// originate
|
|
65
|
+
accumulatedStorage +=
|
|
66
|
+
'originated_contracts' in result && Array.isArray(result.originated_contracts)
|
|
67
|
+
? result.originated_contracts.length * originationSize
|
|
68
|
+
: 0;
|
|
69
|
+
// register_global_constants
|
|
70
|
+
accumulatedStorage +=
|
|
71
|
+
'storage_size' in result && 'global_address' in result
|
|
72
|
+
? Number(result.storage_size) || 0
|
|
73
|
+
: 0;
|
|
74
|
+
// transfer_ticket, originate, contract_call
|
|
75
|
+
accumulatedStorage +=
|
|
76
|
+
'paid_storage_size_diff' in result ? Number(result.paid_storage_size_diff) || 0 : 0;
|
|
77
|
+
//smart_rollup_originate
|
|
78
|
+
accumulatedStorage += 'genesis_commitment_hash' in result ? Number(result.size) || 0 : 0;
|
|
79
|
+
});
|
|
80
|
+
if ((0, types_1.isOpWithFee)(content)) {
|
|
81
|
+
return {
|
|
82
|
+
milligasLimit: (0, types_1.isOpWithGasBuffer)(content)
|
|
83
|
+
? consumedMilligas + Number(this.MILLIGAS_BUFFER)
|
|
84
|
+
: consumedMilligas,
|
|
85
|
+
storageLimit: accumulatedStorage > 0 ? accumulatedStorage + this.STORAGE_BUFFER : 0,
|
|
86
|
+
opSize: size,
|
|
87
|
+
minimalFeePerStorageByteMutez: costPerByte.toNumber(),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return {
|
|
92
|
+
milligasLimit: 0,
|
|
93
|
+
storageLimit: 0,
|
|
94
|
+
opSize: size,
|
|
95
|
+
minimalFeePerStorageByteMutez: costPerByte.toNumber(),
|
|
96
|
+
baseFeeMutez: 0,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
calculateEstimates(op, constants) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const { opbytes, opOb: { branch, contents }, } = yield this.forge(op);
|
|
103
|
+
const operation = {
|
|
104
|
+
operation: { branch, contents, signature: STUB_SIGNATURE },
|
|
105
|
+
chain_id: yield this.context.readProvider.getChainId(),
|
|
106
|
+
};
|
|
107
|
+
const { opResponse } = yield this.simulate(operation);
|
|
108
|
+
const { cost_per_byte, origination_size } = constants;
|
|
109
|
+
const errors = [...(0, errors_1.flattenErrors)(opResponse, 'backtracked'), ...(0, errors_1.flattenErrors)(opResponse)];
|
|
110
|
+
// Fail early in case of errors
|
|
111
|
+
if (errors.length) {
|
|
112
|
+
throw new errors_1.TezosOperationError(errors, 'Error occurred during estimation', opResponse.contents);
|
|
113
|
+
}
|
|
114
|
+
let numberOfOps = 1;
|
|
115
|
+
if (Array.isArray(op.opOb.contents) && op.opOb.contents.length > 1) {
|
|
116
|
+
numberOfOps =
|
|
117
|
+
opResponse.contents[0].kind === 'reveal'
|
|
118
|
+
? op.opOb.contents.length - 1
|
|
119
|
+
: op.opOb.contents.length;
|
|
120
|
+
}
|
|
121
|
+
return opResponse.contents.map((x) => {
|
|
122
|
+
const content = x;
|
|
123
|
+
content.source = content.source || '';
|
|
124
|
+
let revealSize, eachOpSize;
|
|
125
|
+
if (content.source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)) {
|
|
126
|
+
revealSize = this.REVEAL_LENGTH_TZ4 / 2;
|
|
127
|
+
eachOpSize = (opbytes.length / 2 + octez_js_utils_1.payloadLength[octez_js_utils_1.PrefixV2.BLS12_381Signature]) / numberOfOps;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
revealSize = this.REVEAL_LENGTH / 2;
|
|
131
|
+
eachOpSize = (opbytes.length / 2 + octez_js_utils_1.payloadLength[octez_js_utils_1.PrefixV2.Ed25519Signature]) / numberOfOps;
|
|
132
|
+
}
|
|
133
|
+
return this.getEstimationPropertiesFromOperationContent(x,
|
|
134
|
+
// diff between estimated and injecting OP_SIZE is 124-126, we added buffer to use 130
|
|
135
|
+
x.kind === 'reveal' ? revealSize : eachOpSize, cost_per_byte, origination_size !== null && origination_size !== void 0 ? origination_size : 257 // protocol constants
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
*
|
|
142
|
+
* @description Estimate gasLimit, storageLimit and fees for an origination operation
|
|
143
|
+
*
|
|
144
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
145
|
+
*
|
|
146
|
+
* @param OriginationOperation Originate operation parameter
|
|
147
|
+
*/
|
|
148
|
+
originate(params) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
150
|
+
const preparedOperation = yield this.prepare.originate(params);
|
|
151
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
152
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
153
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
154
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
155
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
156
|
+
: this.REVEAL_LENGTH / 2;
|
|
157
|
+
estimateProperties.shift();
|
|
158
|
+
estimateProperties[0].opSize -= revealSize;
|
|
159
|
+
}
|
|
160
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
*
|
|
165
|
+
* @description Estimate gasLimit, storageLimit and fees for an transfer operation
|
|
166
|
+
*
|
|
167
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
168
|
+
*
|
|
169
|
+
* @param TransferOperation Originate operation parameter
|
|
170
|
+
*/
|
|
171
|
+
transfer(_a) {
|
|
172
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
var _b;
|
|
174
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
175
|
+
const toValidation = (0, octez_js_utils_1.validateAddress)(rest.to);
|
|
176
|
+
if (toValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
177
|
+
throw new octez_js_core_1.InvalidAddressError(rest.to, toValidation);
|
|
178
|
+
}
|
|
179
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
180
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
181
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
182
|
+
}
|
|
183
|
+
if (rest.amount < 0) {
|
|
184
|
+
throw new octez_js_core_1.InvalidAmountError(rest.amount.toString());
|
|
185
|
+
}
|
|
186
|
+
const preparedOperation = yield this.prepare.transaction(Object.assign({ fee,
|
|
187
|
+
storageLimit,
|
|
188
|
+
gasLimit }, rest));
|
|
189
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
190
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
191
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
192
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
193
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
194
|
+
: this.REVEAL_LENGTH / 2;
|
|
195
|
+
estimateProperties.shift();
|
|
196
|
+
estimateProperties[0].opSize -= revealSize;
|
|
197
|
+
}
|
|
198
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* @description Estimate gasLimit, storageLimit and fees for an stake pseudo-operation
|
|
204
|
+
*
|
|
205
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
206
|
+
*
|
|
207
|
+
* @param Stake pseudo-operation parameter
|
|
208
|
+
*/
|
|
209
|
+
stake(_a) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
var _b;
|
|
212
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
213
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
214
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
215
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
216
|
+
}
|
|
217
|
+
if (!rest.to) {
|
|
218
|
+
rest.to = rest.source;
|
|
219
|
+
}
|
|
220
|
+
if (rest.to && rest.to !== rest.source) {
|
|
221
|
+
throw new octez_js_core_1.InvalidStakingAddressError(rest.to);
|
|
222
|
+
}
|
|
223
|
+
if (rest.amount < 0) {
|
|
224
|
+
throw new octez_js_core_1.InvalidAmountError(rest.amount.toString());
|
|
225
|
+
}
|
|
226
|
+
const preparedOperation = yield this.prepare.stake(Object.assign({ fee,
|
|
227
|
+
storageLimit,
|
|
228
|
+
gasLimit }, rest));
|
|
229
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
230
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
231
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
232
|
+
estimateProperties.shift();
|
|
233
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
234
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
235
|
+
: this.REVEAL_LENGTH / 2;
|
|
236
|
+
estimateProperties[0].opSize -= revealSize;
|
|
237
|
+
}
|
|
238
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @description Estimate gasLimit, storageLimit and fees for an Unstake pseudo-operation
|
|
244
|
+
*
|
|
245
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
246
|
+
*
|
|
247
|
+
* @param Unstake pseudo-operation parameter
|
|
248
|
+
*/
|
|
249
|
+
unstake(_a) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
var _b;
|
|
252
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
253
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
254
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
255
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
256
|
+
}
|
|
257
|
+
if (!rest.to) {
|
|
258
|
+
rest.to = rest.source;
|
|
259
|
+
}
|
|
260
|
+
if (rest.to && rest.to !== rest.source) {
|
|
261
|
+
throw new octez_js_core_1.InvalidStakingAddressError(rest.to);
|
|
262
|
+
}
|
|
263
|
+
if (rest.amount < 0) {
|
|
264
|
+
throw new octez_js_core_1.InvalidAmountError(rest.amount.toString());
|
|
265
|
+
}
|
|
266
|
+
const preparedOperation = yield this.prepare.unstake(Object.assign({ fee,
|
|
267
|
+
storageLimit,
|
|
268
|
+
gasLimit }, rest));
|
|
269
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
270
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
271
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
272
|
+
estimateProperties.shift();
|
|
273
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
274
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
275
|
+
: this.REVEAL_LENGTH / 2;
|
|
276
|
+
estimateProperties[0].opSize -= revealSize;
|
|
277
|
+
}
|
|
278
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
*
|
|
283
|
+
* @description Estimate gasLimit, storageLimit and fees for an finalize_unstake pseudo-operation
|
|
284
|
+
*
|
|
285
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
286
|
+
*
|
|
287
|
+
* @param finalize_unstake pseudo-operation parameter
|
|
288
|
+
*/
|
|
289
|
+
finalizeUnstake(_a) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
var _b;
|
|
292
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
293
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
294
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
295
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
296
|
+
}
|
|
297
|
+
if (!rest.to) {
|
|
298
|
+
rest.to = rest.source;
|
|
299
|
+
}
|
|
300
|
+
if (!rest.amount) {
|
|
301
|
+
rest.amount = 0;
|
|
302
|
+
}
|
|
303
|
+
if (rest.amount !== undefined && rest.amount !== 0) {
|
|
304
|
+
throw new Error('Amount must be 0 for finalize_unstake operation');
|
|
305
|
+
}
|
|
306
|
+
const preparedOperation = yield this.prepare.finalizeUnstake(Object.assign({ fee,
|
|
307
|
+
storageLimit,
|
|
308
|
+
gasLimit }, rest));
|
|
309
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
310
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
311
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
312
|
+
estimateProperties.shift();
|
|
313
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
314
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
315
|
+
: this.REVEAL_LENGTH / 2;
|
|
316
|
+
estimateProperties[0].opSize -= revealSize;
|
|
317
|
+
}
|
|
318
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
*
|
|
323
|
+
* @description Estimate gasLimit, storageLimit and fees for a transferTicket operation
|
|
324
|
+
*
|
|
325
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
326
|
+
*
|
|
327
|
+
* @param TransferTicketParams operation parameter
|
|
328
|
+
*/
|
|
329
|
+
transferTicket(_a) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
var _b;
|
|
332
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
333
|
+
const destinationValidation = (0, octez_js_utils_1.validateAddress)(rest.destination);
|
|
334
|
+
if (destinationValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
335
|
+
throw new octez_js_core_1.InvalidAddressError(rest.destination, destinationValidation);
|
|
336
|
+
}
|
|
337
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
338
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
339
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
340
|
+
}
|
|
341
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
342
|
+
const preparedOperation = yield this.prepare.transferTicket(Object.assign({ fee,
|
|
343
|
+
storageLimit,
|
|
344
|
+
gasLimit }, rest));
|
|
345
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
346
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
347
|
+
estimateProperties.shift();
|
|
348
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
349
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
350
|
+
: this.REVEAL_LENGTH / 2;
|
|
351
|
+
estimateProperties[0].opSize -= revealSize;
|
|
352
|
+
}
|
|
353
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
*
|
|
358
|
+
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
|
|
359
|
+
*
|
|
360
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
361
|
+
*
|
|
362
|
+
* @param Estimate
|
|
363
|
+
*/
|
|
364
|
+
setDelegate(_a) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
var _b, _c;
|
|
367
|
+
var { fee, gasLimit, storageLimit } = _a, rest = __rest(_a, ["fee", "gasLimit", "storageLimit"]);
|
|
368
|
+
const sourceValidation = (0, octez_js_utils_1.validateAddress)((_b = rest.source) !== null && _b !== void 0 ? _b : '');
|
|
369
|
+
if (rest.source && sourceValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
370
|
+
throw new octez_js_core_1.InvalidAddressError(rest.source, sourceValidation);
|
|
371
|
+
}
|
|
372
|
+
const delegateValidation = (0, octez_js_utils_1.validateAddress)((_c = rest.delegate) !== null && _c !== void 0 ? _c : '');
|
|
373
|
+
if (rest.delegate && delegateValidation !== octez_js_utils_1.ValidationResult.VALID) {
|
|
374
|
+
throw new octez_js_core_1.InvalidAddressError(rest.delegate, delegateValidation);
|
|
375
|
+
}
|
|
376
|
+
const preparedOperation = yield this.prepare.delegation(Object.assign({ fee,
|
|
377
|
+
storageLimit,
|
|
378
|
+
gasLimit }, rest));
|
|
379
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
380
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
381
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
382
|
+
estimateProperties.shift();
|
|
383
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
384
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
385
|
+
: this.REVEAL_LENGTH / 2;
|
|
386
|
+
estimateProperties[0].opSize -= revealSize;
|
|
387
|
+
}
|
|
388
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
*
|
|
393
|
+
* @description Estimate gasLimit, storageLimit and fees for a each operation in the batch
|
|
394
|
+
*
|
|
395
|
+
* @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.
|
|
396
|
+
*/
|
|
397
|
+
batch(params) {
|
|
398
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
399
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
400
|
+
const preparedOperations = yield this.prepare.batch(params);
|
|
401
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperations, protocolConstants);
|
|
402
|
+
return estimate_1.Estimate.createArrayEstimateInstancesFromProperties(estimateProperties);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
*
|
|
407
|
+
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
|
|
408
|
+
*
|
|
409
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
410
|
+
*
|
|
411
|
+
* @param Estimate
|
|
412
|
+
*/
|
|
413
|
+
registerDelegate(_a, source) {
|
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
416
|
+
const pkh = (yield this.getKeys()).publicKeyHash;
|
|
417
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
418
|
+
const checkSource = source || pkh;
|
|
419
|
+
const preparedOperation = yield this.prepare.registerDelegate(Object.assign({ fee, storageLimit, gasLimit }, rest), checkSource);
|
|
420
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
421
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
422
|
+
estimateProperties.shift();
|
|
423
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
424
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
425
|
+
: this.REVEAL_LENGTH / 2;
|
|
426
|
+
estimateProperties[0].opSize -= revealSize;
|
|
427
|
+
}
|
|
428
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
*
|
|
433
|
+
* @description Estimate gasLimit, storageLimit and fees to reveal the current account
|
|
434
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation or undefined if the account is already revealed
|
|
435
|
+
*
|
|
436
|
+
* @param Estimate
|
|
437
|
+
*/
|
|
438
|
+
reveal(params) {
|
|
439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
const { publicKeyHash, publicKey } = yield this.getKeys();
|
|
441
|
+
if (!publicKey) {
|
|
442
|
+
throw new errors_2.RevealEstimateError();
|
|
443
|
+
}
|
|
444
|
+
if (yield this.isAccountRevealRequired(publicKeyHash)) {
|
|
445
|
+
const [, pkhPrefix] = (0, octez_js_utils_1.b58DecodeAndCheckPrefix)(publicKeyHash, octez_js_utils_1.publicKeyHashPrefixes);
|
|
446
|
+
if (pkhPrefix === octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash) {
|
|
447
|
+
if (params && params.proof) {
|
|
448
|
+
(0, octez_js_utils_1.b58DecodeAndCheckPrefix)(params.proof, [octez_js_utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
const { prefixSig } = yield this.signer.provePossession();
|
|
452
|
+
params = Object.assign(Object.assign({}, params), { proof: prefixSig });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
if (params && params.proof) {
|
|
457
|
+
throw new octez_js_core_1.ProhibitedActionError('Proof field is only allowed to reveal a bls account ');
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
461
|
+
const preparedOperation = params
|
|
462
|
+
? yield this.prepare.reveal(params)
|
|
463
|
+
: yield this.prepare.reveal({});
|
|
464
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
465
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
*
|
|
471
|
+
* @description Estimate gasLimit, storageLimit and fees for an registerGlobalConstant operation
|
|
472
|
+
*
|
|
473
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
474
|
+
*
|
|
475
|
+
* @param params registerGlobalConstant operation parameter
|
|
476
|
+
*/
|
|
477
|
+
registerGlobalConstant(_a) {
|
|
478
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
479
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
480
|
+
const preparedOperation = yield this.prepare.registerGlobalConstant(Object.assign({ fee,
|
|
481
|
+
storageLimit,
|
|
482
|
+
gasLimit }, rest));
|
|
483
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
484
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
485
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
486
|
+
estimateProperties.shift();
|
|
487
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
488
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
489
|
+
: this.REVEAL_LENGTH / 2;
|
|
490
|
+
estimateProperties[0].opSize -= revealSize;
|
|
491
|
+
}
|
|
492
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
*
|
|
497
|
+
* @description Estimate gasLimit, storageLimit, and fees for an increasePaidStorage operation
|
|
498
|
+
*
|
|
499
|
+
* @returns An estimation of gasLimit, storageLimit, and fees for the operation
|
|
500
|
+
*
|
|
501
|
+
* @param params increasePaidStorage operation parameters
|
|
502
|
+
*/
|
|
503
|
+
increasePaidStorage(_a) {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
var { fee, storageLimit, gasLimit } = _a, rest = __rest(_a, ["fee", "storageLimit", "gasLimit"]);
|
|
506
|
+
if (rest.amount <= 0) {
|
|
507
|
+
throw new octez_js_core_1.InvalidAmountError(rest.amount.toString());
|
|
508
|
+
}
|
|
509
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
510
|
+
const preparedOperation = yield this.prepare.increasePaidStorage(Object.assign({ fee,
|
|
511
|
+
storageLimit,
|
|
512
|
+
gasLimit }, rest));
|
|
513
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
514
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
515
|
+
estimateProperties.shift();
|
|
516
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
517
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
518
|
+
: this.REVEAL_LENGTH / 2;
|
|
519
|
+
estimateProperties[0].opSize -= revealSize;
|
|
520
|
+
}
|
|
521
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
*
|
|
526
|
+
* @description Estimate gasLimit, storageLimit and fees for an Update Consensus Key operation
|
|
527
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
528
|
+
* @param Estimate
|
|
529
|
+
*/
|
|
530
|
+
updateConsensusKey(params) {
|
|
531
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
532
|
+
const [, pkPrefix] = (0, octez_js_utils_1.b58DecodeAndCheckPrefix)(params.pk, octez_js_utils_1.publicKeyPrefixes);
|
|
533
|
+
if (pkPrefix === octez_js_utils_1.PrefixV2.BLS12_381PublicKey) {
|
|
534
|
+
if (!params.proof) {
|
|
535
|
+
throw new octez_js_core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
if (params.proof) {
|
|
540
|
+
throw new octez_js_core_1.ProhibitedActionError('Proof field is only allowed for a bls account as consensus key');
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
544
|
+
const preparedOperation = yield this.prepare.updateConsensusKey(params);
|
|
545
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
546
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
547
|
+
estimateProperties.shift();
|
|
548
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
549
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
550
|
+
: this.REVEAL_LENGTH / 2;
|
|
551
|
+
estimateProperties[0].opSize -= revealSize;
|
|
552
|
+
}
|
|
553
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
*
|
|
558
|
+
* @description Estimate gasLimit, storageLimit and fees for an Update Companion Key operation
|
|
559
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
560
|
+
* @param Estimate
|
|
561
|
+
*/
|
|
562
|
+
updateCompanionKey(params) {
|
|
563
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
564
|
+
const [, pkPrefix] = (0, octez_js_utils_1.b58DecodeAndCheckPrefix)(params.pk, octez_js_utils_1.publicKeyPrefixes);
|
|
565
|
+
if (pkPrefix !== octez_js_utils_1.PrefixV2.BLS12_381PublicKey) {
|
|
566
|
+
throw new octez_js_core_1.ProhibitedActionError('companion key must be a bls account');
|
|
567
|
+
}
|
|
568
|
+
if (!params.proof) {
|
|
569
|
+
throw new octez_js_core_1.InvalidProofError('Proof is required to set a bls account as companion key ');
|
|
570
|
+
}
|
|
571
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
572
|
+
const preparedOperation = yield this.prepare.updateCompanionKey(params);
|
|
573
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
574
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
575
|
+
estimateProperties.shift();
|
|
576
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
577
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
578
|
+
: this.REVEAL_LENGTH / 2;
|
|
579
|
+
estimateProperties[0].opSize -= revealSize;
|
|
580
|
+
}
|
|
581
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
*
|
|
586
|
+
* @description Estimate gasLimit, storageLimit and fees for a smart_rollup_add_messages operation
|
|
587
|
+
*
|
|
588
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
589
|
+
*
|
|
590
|
+
* @param Estimate
|
|
591
|
+
*/
|
|
592
|
+
smartRollupAddMessages(params) {
|
|
593
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
594
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
595
|
+
const preparedOperation = yield this.prepare.smartRollupAddMessages(params);
|
|
596
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
597
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
598
|
+
estimateProperties.shift();
|
|
599
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
600
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
601
|
+
: this.REVEAL_LENGTH / 2;
|
|
602
|
+
estimateProperties[0].opSize -= revealSize;
|
|
603
|
+
}
|
|
604
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
*
|
|
609
|
+
* @description Estimate gasLimit, storageLimit and fees for an Smart Rollup Originate operation
|
|
610
|
+
*
|
|
611
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
612
|
+
*
|
|
613
|
+
* @param SmartRollupOriginateParams
|
|
614
|
+
*/
|
|
615
|
+
smartRollupOriginate(params) {
|
|
616
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
617
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
618
|
+
const preparedOperation = yield this.prepare.smartRollupOriginate(params);
|
|
619
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
620
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
621
|
+
estimateProperties.shift();
|
|
622
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
623
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
624
|
+
: this.REVEAL_LENGTH / 2;
|
|
625
|
+
estimateProperties[0].opSize -= revealSize;
|
|
626
|
+
}
|
|
627
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
*
|
|
632
|
+
* @description Estimate gasLimit, storageLimit and fees for a smart_rollup_execute_outbox_message operation
|
|
633
|
+
*
|
|
634
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the operation
|
|
635
|
+
*
|
|
636
|
+
* @param Estimate
|
|
637
|
+
*/
|
|
638
|
+
smartRollupExecuteOutboxMessage(params) {
|
|
639
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
640
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
641
|
+
const preparedOperation = yield this.prepare.smartRollupExecuteOutboxMessage(params);
|
|
642
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
643
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
644
|
+
estimateProperties.shift();
|
|
645
|
+
}
|
|
646
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
*
|
|
651
|
+
* @description Estimate gasLimit, storageLimit and fees for contract call
|
|
652
|
+
*
|
|
653
|
+
* @returns An estimation of gasLimit, storageLimit and fees for the contract call
|
|
654
|
+
*
|
|
655
|
+
* @param Estimate
|
|
656
|
+
*/
|
|
657
|
+
contractCall(contractMethod) {
|
|
658
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
659
|
+
const protocolConstants = yield this.context.readProvider.getProtocolConstants('head');
|
|
660
|
+
const preparedOperation = yield this.prepare.contractCall(contractMethod);
|
|
661
|
+
const estimateProperties = yield this.calculateEstimates(preparedOperation, protocolConstants);
|
|
662
|
+
if (preparedOperation.opOb.contents[0].kind === 'reveal') {
|
|
663
|
+
estimateProperties.shift();
|
|
664
|
+
const revealSize = preparedOperation.opOb.contents[0].source.startsWith(octez_js_utils_1.PrefixV2.BLS12_381PublicKeyHash)
|
|
665
|
+
? this.REVEAL_LENGTH_TZ4 / 2
|
|
666
|
+
: this.REVEAL_LENGTH / 2;
|
|
667
|
+
estimateProperties[0].opSize -= revealSize;
|
|
668
|
+
}
|
|
669
|
+
return estimate_1.Estimate.createEstimateInstanceFromProperties(estimateProperties);
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
exports.RPCEstimateProvider = RPCEstimateProvider;
|