@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.
- package/README.md +1 -1
- package/dist/lib/batch/rpc-batch-provider.js +91 -83
- package/dist/lib/context.js +22 -26
- package/dist/lib/contract/big-map.js +16 -29
- package/dist/lib/contract/contract-methods/contract-method-object-param.js +7 -7
- package/dist/lib/contract/contract-methods/contract-on-chain-view.js +31 -44
- package/dist/lib/contract/contract.js +21 -32
- package/dist/lib/contract/errors.js +9 -9
- package/dist/lib/contract/prepare.js +36 -45
- package/dist/lib/contract/rpc-contract-provider.js +426 -475
- package/dist/lib/contract/sapling-state-abstraction.js +3 -14
- package/dist/lib/contract/semantic.js +2 -2
- package/dist/lib/errors.js +3 -3
- package/dist/lib/estimate/errors.js +1 -1
- package/dist/lib/estimate/estimate.js +66 -20
- package/dist/lib/estimate/rpc-estimate-provider.js +427 -460
- package/dist/lib/forger/composite-forger.js +16 -27
- package/dist/lib/forger/errors.js +2 -2
- package/dist/lib/forger/taquito-local-forger.js +9 -22
- package/dist/lib/global-constants/default-global-constants-provider.js +8 -19
- package/dist/lib/global-constants/errors.js +2 -2
- package/dist/lib/global-constants/noop-global-constants-provider.js +2 -13
- package/dist/lib/import-key.js +23 -34
- package/dist/lib/injector/rpc-injector.js +13 -24
- package/dist/lib/operations/ballot-operation.js +2 -3
- package/dist/lib/operations/delegate-operation.js +5 -8
- package/dist/lib/operations/drain-delegate-operation.js +1 -1
- package/dist/lib/operations/errors.js +9 -6
- package/dist/lib/operations/increase-paid-storage-operation.js +4 -7
- package/dist/lib/operations/operations.js +100 -30
- package/dist/lib/operations/origination-operation.js +16 -27
- package/dist/lib/operations/proposals-operation.js +2 -3
- package/dist/lib/operations/register-global-constant-operation.js +4 -7
- package/dist/lib/operations/reveal-operation.js +1 -1
- package/dist/lib/operations/smart-rollup-add-messages-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-execute-outbox-message-operation.js +4 -7
- package/dist/lib/operations/smart-rollup-originate-operation.js +4 -7
- package/dist/lib/operations/transaction-operation.js +2 -2
- package/dist/lib/operations/transfer-ticket-operation.js +4 -6
- package/dist/lib/operations/types.js +17 -19
- package/dist/lib/operations/update-companion-key-operation.js +4 -7
- package/dist/lib/operations/update-consensus-key-operation.js +4 -7
- package/dist/lib/packer/michel-codec-packer.js +3 -14
- package/dist/lib/packer/rpc-packer.js +2 -13
- package/dist/lib/parser/michel-codec-parser.js +82 -107
- package/dist/lib/parser/noop-parser.js +2 -13
- package/dist/lib/prepare/prepare-provider.js +780 -744
- package/dist/lib/provider.js +322 -128
- package/dist/lib/read-provider/rpc-read-adapter.js +76 -121
- package/dist/lib/signer/errors.js +1 -1
- package/dist/lib/signer/noop.js +9 -26
- package/dist/lib/subscribe/errors.js +2 -2
- package/dist/lib/subscribe/polling-subcribe-provider.js +35 -38
- package/dist/lib/taquito.js +33 -33
- package/dist/lib/tz/rpc-tz-provider.js +27 -44
- package/dist/lib/version.js +2 -2
- package/dist/lib/wallet/batch-operation.js +32 -45
- package/dist/lib/wallet/delegation-operation.js +25 -40
- package/dist/lib/wallet/errors.js +15 -3
- package/dist/lib/wallet/increase-paid-storage-operation.js +25 -40
- package/dist/lib/wallet/legacy.js +28 -63
- package/dist/lib/wallet/operation-factory.js +27 -56
- package/dist/lib/wallet/operation.js +123 -59
- package/dist/lib/wallet/origination-operation.js +34 -46
- package/dist/lib/wallet/register-global-constant-operation.js +26 -43
- package/dist/lib/wallet/transaction-operation.js +21 -36
- package/dist/lib/wallet/transfer-ticket-operation.js +21 -36
- package/dist/lib/wallet/wallet.js +187 -184
- package/dist/taquito.es6.js +3424 -3197
- package/dist/taquito.es6.js.map +1 -1
- package/dist/taquito.min.js +1 -1
- package/dist/taquito.umd.js +7930 -7701
- package/dist/taquito.umd.js.map +1 -1
- package/dist/types/batch/rpc-batch-provider.d.ts +18 -18
- package/dist/types/context.d.ts +4 -4
- package/dist/types/contract/big-map.d.ts +3 -3
- package/dist/types/contract/contract-methods/contract-method-interface.d.ts +4 -4
- package/dist/types/contract/contract-methods/contract-method-object-param.d.ts +6 -6
- package/dist/types/contract/contract-methods/contract-on-chain-view.d.ts +3 -3
- package/dist/types/contract/contract.d.ts +6 -6
- package/dist/types/contract/errors.d.ts +11 -11
- package/dist/types/contract/interface.d.ts +42 -42
- package/dist/types/contract/rpc-contract-provider.d.ts +44 -43
- package/dist/types/contract/sapling-state-abstraction.d.ts +1 -1
- package/dist/types/contract/semantic.d.ts +2 -2
- package/dist/types/errors.d.ts +5 -5
- package/dist/types/estimate/errors.d.ts +1 -1
- package/dist/types/estimate/estimate-provider-interface.d.ts +81 -84
- package/dist/types/estimate/estimate.d.ts +28 -11
- package/dist/types/estimate/rpc-estimate-provider.d.ts +34 -30
- package/dist/types/forger/errors.d.ts +2 -2
- package/dist/types/global-constants/default-global-constants-provider.d.ts +2 -2
- package/dist/types/global-constants/errors.d.ts +2 -2
- package/dist/types/global-constants/interface-global-constants-provider.d.ts +1 -1
- package/dist/types/import-key.d.ts +2 -2
- package/dist/types/operations/ballot-operation.d.ts +1 -1
- package/dist/types/operations/delegate-operation.d.ts +2 -2
- package/dist/types/operations/drain-delegate-operation.d.ts +1 -1
- package/dist/types/operations/errors.d.ts +5 -5
- package/dist/types/operations/failing-noop-operation.d.ts +1 -1
- package/dist/types/operations/increase-paid-storage-operation.d.ts +1 -1
- package/dist/types/operations/operations.d.ts +2 -2
- package/dist/types/operations/origination-operation.d.ts +5 -5
- package/dist/types/operations/proposals-operation.d.ts +1 -1
- package/dist/types/operations/register-global-constant-operation.d.ts +2 -2
- package/dist/types/operations/reveal-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-add-messages-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-execute-outbox-message-operation.d.ts +1 -1
- package/dist/types/operations/smart-rollup-originate-operation.d.ts +1 -1
- package/dist/types/operations/transaction-operation.d.ts +2 -2
- package/dist/types/operations/transfer-ticket-operation.d.ts +2 -2
- package/dist/types/operations/types.d.ts +387 -25
- package/dist/types/operations/update-companion-key-operation.d.ts +1 -1
- package/dist/types/operations/update-consensus-key-operation.d.ts +1 -1
- package/dist/types/prepare/interface.d.ts +32 -33
- package/dist/types/prepare/prepare-provider.d.ts +34 -60
- package/dist/types/provider.d.ts +7 -1
- package/dist/types/read-provider/interface.d.ts +21 -21
- package/dist/types/read-provider/rpc-read-adapter.d.ts +22 -22
- package/dist/types/signer/errors.d.ts +1 -1
- package/dist/types/signer/noop.d.ts +1 -1
- package/dist/types/subscribe/errors.d.ts +2 -2
- package/dist/types/taquito.d.ts +33 -33
- package/dist/types/wallet/errors.d.ts +10 -2
- package/dist/types/wallet/interface.d.ts +13 -13
- package/dist/types/wallet/operation.d.ts +4 -3
- package/dist/types/wallet/wallet.d.ts +36 -35
- package/package.json +27 -15
- 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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
publicKeyHash
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
publicKey
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
122
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
|
144
|
+
* @param params Originate operation parameter
|
|
147
145
|
*/
|
|
148
|
-
originate(params) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
*
|
|
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(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
*
|
|
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(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
*
|
|
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(
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
*
|
|
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(
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
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
|
-
*
|
|
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(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
*
|
|
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(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
-
*
|
|
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(
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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
|
-
*
|
|
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
|
|
417
|
+
* @param params Reveal operation parameter
|
|
437
418
|
*/
|
|
438
|
-
reveal(params) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
if (
|
|
447
|
-
|
|
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
|
-
|
|
457
|
-
|
|
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
|
-
*
|
|
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(
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
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
|
-
*
|
|
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(
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
-
*
|
|
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
|
|
507
|
+
* @param params UpdateConsensusKey operation parameter
|
|
529
508
|
*/
|
|
530
|
-
updateConsensusKey(params) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
if (
|
|
534
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
|
537
|
+
* @param params UpdateCompanionKey operation parameter
|
|
561
538
|
*/
|
|
562
|
-
updateCompanionKey(params) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
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
|
-
*
|
|
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
|
|
565
|
+
* @param params SmartRollupAddMessages operation parameter
|
|
591
566
|
*/
|
|
592
|
-
smartRollupAddMessages(params) {
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
-
*
|
|
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
|
|
586
|
+
* @param params SmartRollupOriginate operation parameter
|
|
614
587
|
*/
|
|
615
|
-
smartRollupOriginate(params) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
*
|
|
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
|
|
607
|
+
* @param params SmartRollupExecuteOutboxMessage operation parameter
|
|
637
608
|
*/
|
|
638
|
-
smartRollupExecuteOutboxMessage(params) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
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
|
-
*
|
|
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
|
|
624
|
+
* @param contractMethod ContractMethodObject for the contract call
|
|
656
625
|
*/
|
|
657
|
-
contractCall(contractMethod) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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;
|