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