@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,13 +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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.RpcContractProvider = void 0;
13
4
  const http_utils_1 = require("@taquito/http-utils");
@@ -45,36 +36,34 @@ class RpcContractProvider extends provider_1.Provider {
45
36
  }
46
37
  /**
47
38
  *
48
- * @description Return a well formatted json object of the contract storage
39
+ * Return a well formatted json object of the contract storage
49
40
  *
50
41
  * @param contract contract address you want to get the storage from
51
42
  * @param schema optional schema can either be the contract script rpc response or a michelson-encoder schema
52
43
  * @throws {@link InvalidContractAddressError}
53
44
  * @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-contracts-contract-id-script
54
45
  */
55
- getStorage(contract, schema) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const contractValidation = (0, utils_1.validateContractAddress)(contract);
58
- if (contractValidation !== utils_1.ValidationResult.VALID) {
59
- throw new core_1.InvalidContractAddressError(contract, contractValidation);
60
- }
61
- const script = yield this.context.readProvider.getScript(contract, 'head');
62
- if (!schema) {
63
- schema = script;
64
- }
65
- let contractSchema;
66
- if (michelson_encoder_1.Schema.isSchema(schema)) {
67
- contractSchema = schema;
68
- }
69
- else {
70
- contractSchema = michelson_encoder_1.Schema.fromRPCResponse({ script: schema });
71
- }
72
- return contractSchema.Execute(script.storage, (0, semantic_1.smartContractAbstractionSemantic)(this)); // Cast into T because only the caller can know the true type of the storage
73
- });
46
+ async getStorage(contract, schema) {
47
+ const contractValidation = (0, utils_1.validateContractAddress)(contract);
48
+ if (contractValidation !== utils_1.ValidationResult.VALID) {
49
+ throw new core_1.InvalidContractAddressError(contract, contractValidation);
50
+ }
51
+ const script = await this.context.readProvider.getScript(contract, 'head');
52
+ if (!schema) {
53
+ schema = script;
54
+ }
55
+ let contractSchema;
56
+ if (michelson_encoder_1.Schema.isSchema(schema)) {
57
+ contractSchema = schema;
58
+ }
59
+ else {
60
+ contractSchema = michelson_encoder_1.Schema.fromRPCResponse({ script: schema });
61
+ }
62
+ return contractSchema.Execute(script.storage, (0, semantic_1.smartContractAbstractionSemantic)(this)); // Cast into T because only the caller can know the true type of the storage
74
63
  }
75
64
  /**
76
65
  *
77
- * @description Return a well formatted json object of a big map value
66
+ * Return a well formatted json object of a big map value
78
67
  *
79
68
  * @param id Big Map ID
80
69
  * @param keyToEncode key to query (will be encoded properly according to the schema)
@@ -83,20 +72,18 @@ class RpcContractProvider extends provider_1.Provider {
83
72
  *
84
73
  * @see https://tezos.gitlab.io/api/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr
85
74
  */
86
- getBigMapKeyByID(id, keyToEncode, schema, block) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const { key, type } = schema.EncodeBigMapKey(keyToEncode);
89
- const { packed } = yield this.context.packer.packData({ data: key, type });
90
- const encodedExpr = (0, utils_1.encodeExpr)(packed);
91
- const bigMapValue = block
92
- ? yield this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, block)
93
- : yield this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, 'head');
94
- return schema.ExecuteOnBigMapValue(bigMapValue, (0, semantic_1.smartContractAbstractionSemantic)(this));
95
- });
75
+ async getBigMapKeyByID(id, keyToEncode, schema, block) {
76
+ const { key, type } = schema.EncodeBigMapKey(keyToEncode);
77
+ const { packed } = await this.context.packer.packData({ data: key, type });
78
+ const encodedExpr = (0, utils_1.encodeExpr)(packed);
79
+ const bigMapValue = block
80
+ ? await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, block)
81
+ : await this.context.readProvider.getBigMapValue({ id: id.toString(), expr: encodedExpr }, 'head');
82
+ return schema.ExecuteOnBigMapValue(bigMapValue, (0, semantic_1.smartContractAbstractionSemantic)(this));
96
83
  }
97
84
  /**
98
85
  *
99
- * @description Fetch multiple values in a big map
86
+ * Fetch multiple values in a big map
100
87
  * All values will be fetched on the same block level. If a block is specified in the request, the values will be fetched at it.
101
88
  * Otherwise, a first request will be done to the node to fetch the level of the head and all values will be fetched at this level.
102
89
  * If one of the keys does not exist in the big map, its value will be set to undefined.
@@ -109,605 +96,569 @@ class RpcContractProvider extends provider_1.Provider {
109
96
  * @returns A MichelsonMap containing the keys queried in the big map and their value in a well-formatted JSON object format
110
97
  *
111
98
  */
112
- getBigMapKeysByID(id_1, keys_1, schema_1, block_1) {
113
- return __awaiter(this, arguments, void 0, function* (id, keys, schema, block, batchSize = 5) {
114
- const level = yield this.getBlockForRequest(keys, block);
115
- const bigMapValues = new michelson_encoder_1.MichelsonMap();
116
- // Execute batch of promises in series
117
- let position = 0;
118
- let results = [];
119
- while (position < keys.length) {
120
- const keysBatch = keys.slice(position, position + batchSize);
121
- const batch = keysBatch.map((keyToEncode) => this.getBigMapValueOrUndefined(keyToEncode, id, schema, level));
122
- results = [...results, ...(yield Promise.all(batch))];
123
- position += batchSize;
124
- }
125
- for (let i = 0; i < results.length; i++) {
126
- bigMapValues.set(keys[i], results[i]);
127
- }
128
- return bigMapValues;
129
- });
99
+ async getBigMapKeysByID(id, keys, schema, block, batchSize = 5) {
100
+ const level = await this.getBlockForRequest(keys, block);
101
+ const bigMapValues = new michelson_encoder_1.MichelsonMap();
102
+ // Execute batch of promises in series
103
+ let position = 0;
104
+ let results = [];
105
+ while (position < keys.length) {
106
+ const keysBatch = keys.slice(position, position + batchSize);
107
+ const batch = keysBatch.map((keyToEncode) => this.getBigMapValueOrUndefined(keyToEncode, id, schema, level));
108
+ results = [...results, ...(await Promise.all(batch))];
109
+ position += batchSize;
110
+ }
111
+ for (let i = 0; i < results.length; i++) {
112
+ bigMapValues.set(keys[i], results[i]);
113
+ }
114
+ return bigMapValues;
130
115
  }
131
- getBlockForRequest(keys, block) {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- return keys.length === 1 || typeof block !== 'undefined'
134
- ? block
135
- : yield this.context.readProvider.getBlockLevel('head');
136
- });
116
+ async getBlockForRequest(keys, block) {
117
+ return keys.length === 1 || typeof block !== 'undefined'
118
+ ? block
119
+ : await this.context.readProvider.getBlockLevel('head');
137
120
  }
138
- getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
139
- return __awaiter(this, void 0, void 0, function* () {
140
- try {
141
- return yield this.getBigMapKeyByID(id, keyToEncode, schema, level);
121
+ async getBigMapValueOrUndefined(keyToEncode, id, schema, level) {
122
+ try {
123
+ return await this.getBigMapKeyByID(id, keyToEncode, schema, level);
124
+ }
125
+ catch (ex) {
126
+ if (ex instanceof http_utils_1.HttpResponseError && ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
127
+ return;
142
128
  }
143
- catch (ex) {
144
- if (ex instanceof http_utils_1.HttpResponseError && ex.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
145
- return;
146
- }
147
- else {
148
- throw ex;
149
- }
129
+ else {
130
+ throw ex;
150
131
  }
151
- });
132
+ }
152
133
  }
153
134
  /**
154
135
  *
155
- * @description Return a well formatted json object of a sapling state
136
+ * Return a well formatted json object of a sapling state
156
137
  *
157
138
  * @param id Sapling state ID
158
139
  * @param block optional block level to fetch the value from
159
140
  *
160
141
  */
161
- getSaplingDiffByID(id, block) {
162
- return __awaiter(this, void 0, void 0, function* () {
163
- const saplingState = block
164
- ? yield this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
165
- : yield this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
166
- return saplingState;
167
- });
142
+ async getSaplingDiffByID(id, block) {
143
+ const saplingState = block
144
+ ? await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, block)
145
+ : await this.context.readProvider.getSaplingDiffById({ id: id.toString() }, 'head');
146
+ return saplingState;
168
147
  }
169
148
  /**
170
149
  *
171
- * @description Originate a new contract according to the script in parameters. Will sign and inject an operation using the current context
150
+ * Originate a new contract according to the script in parameters. Will sign and inject an operation using the current context
172
151
  *
173
152
  * @returns An operation handle with the result from the rpc node
174
153
  *
175
154
  * @warn You cannot specify storage and init at the same time (use init to pass the raw michelson representation of storage)
176
155
  *
177
- * @param OriginationOperation Originate operation parameter
156
+ * @param params Originate operation parameter
178
157
  */
179
- originate(params) {
180
- return __awaiter(this, void 0, void 0, function* () {
181
- const estimate = yield this.estimate(params, this.estimator.originate.bind(this.estimator));
182
- const preparedOrigination = yield this.prepare.originate(Object.assign(Object.assign({}, params), estimate));
183
- const content = preparedOrigination.opOb.contents.find((op) => op.kind === rpc_1.OpKind.ORIGINATION);
184
- const forgedOrigination = yield this.forge(preparedOrigination);
185
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(forgedOrigination);
186
- return new origination_operation_1.OriginationOperation(hash, content, forgedBytes, opResponse, context, this);
187
- });
158
+ async originate(params) {
159
+ const estimate = await this.estimate(params, this.estimator.originate.bind(this.estimator));
160
+ const preparedOrigination = await this.prepare.originate({ ...params, ...estimate });
161
+ const content = preparedOrigination.opOb.contents.find((op) => op.kind === rpc_1.OpKind.ORIGINATION);
162
+ const forgedOrigination = await this.forge(preparedOrigination);
163
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(forgedOrigination);
164
+ return new origination_operation_1.OriginationOperation(hash, content, forgedBytes, opResponse, context, this);
188
165
  }
189
166
  /**
190
167
  *
191
- * @description Set the delegate for a contract. Will sign and inject an operation using the current context
168
+ * Set the delegate for a contract. Will sign and inject an operation using the current context
192
169
  *
193
170
  * @returns An operation handle with the result from the rpc node
194
171
  *
195
- * @param SetDelegate operation parameter
172
+ * @param params SetDelegate operation parameter
196
173
  */
197
- setDelegate(params) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- var _a, _b, _c, _d;
200
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
201
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
202
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
203
- }
204
- const delegateValidation = (0, utils_1.validateAddress)((_b = params.delegate) !== null && _b !== void 0 ? _b : '');
205
- if (params.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
206
- throw new core_1.InvalidAddressError(params.delegate, delegateValidation);
207
- }
208
- // Since babylon delegation source cannot smart contract
209
- if (/^kt1/i.test((_c = params.source) !== null && _c !== void 0 ? _c : '')) {
210
- throw new errors_1.InvalidDelegationSource((_d = params.source) !== null && _d !== void 0 ? _d : '');
211
- }
212
- const publicKeyHash = yield this.signer.publicKeyHash();
213
- const sourceOrDefault = params.source || publicKeyHash;
214
- const estimate = yield this.estimate(params, this.estimator.setDelegate.bind(this.estimator));
215
- const preparedDelegation = yield this.prepare.delegation(Object.assign(Object.assign({}, params), estimate));
216
- const content = preparedDelegation.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
217
- const opBytes = yield this.forge(preparedDelegation);
218
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
219
- return new delegate_operation_1.DelegateOperation(hash, content, sourceOrDefault, forgedBytes, opResponse, context);
220
- });
174
+ async setDelegate(params) {
175
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
176
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
177
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
178
+ }
179
+ const delegateValidation = (0, utils_1.validateAddress)(params.delegate ?? '');
180
+ if (params.delegate && delegateValidation !== utils_1.ValidationResult.VALID) {
181
+ throw new core_1.InvalidAddressError(params.delegate, delegateValidation);
182
+ }
183
+ // Since babylon delegation source cannot smart contract
184
+ if (/^kt1/i.test(params.source ?? '')) {
185
+ throw new errors_1.InvalidDelegationSource(params.source ?? '');
186
+ }
187
+ const publicKeyHash = await this.signer.publicKeyHash();
188
+ const sourceOrDefault = params.source || publicKeyHash;
189
+ const estimate = await this.estimate(params, this.estimator.setDelegate.bind(this.estimator));
190
+ const preparedDelegation = await this.prepare.delegation({ ...params, ...estimate });
191
+ const content = preparedDelegation.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
192
+ const opBytes = await this.forge(preparedDelegation);
193
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
194
+ return new delegate_operation_1.DelegateOperation(hash, content, sourceOrDefault, forgedBytes, opResponse, context);
221
195
  }
222
196
  /**
223
197
  *
224
- * @description Register the current address as delegate. Will sign and inject an operation using the current context
198
+ * Register the current address as delegate. Will sign and inject an operation using the current context
225
199
  *
226
200
  * @returns An operation handle with the result from the rpc node
227
201
  *
228
- * @param RegisterDelegate operation parameter
202
+ * @param params RegisterDelegate operation parameter
229
203
  */
230
- registerDelegate(params) {
231
- return __awaiter(this, void 0, void 0, function* () {
232
- const estimate = yield this.estimate(params, this.estimator.registerDelegate.bind(this.estimator));
233
- const source = yield this.signer.publicKeyHash();
234
- const prepared = yield this.prepare.registerDelegate(Object.assign(Object.assign({}, params), estimate));
235
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
236
- const opBytes = yield this.forge(prepared);
237
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
238
- return new delegate_operation_1.DelegateOperation(hash, content, source, forgedBytes, opResponse, context);
239
- });
204
+ async registerDelegate(params) {
205
+ const estimate = await this.estimate(params, this.estimator.registerDelegate.bind(this.estimator));
206
+ const source = await this.signer.publicKeyHash();
207
+ const prepared = await this.prepare.registerDelegate({ ...params, ...estimate });
208
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DELEGATION);
209
+ const opBytes = await this.forge(prepared);
210
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
211
+ return new delegate_operation_1.DelegateOperation(hash, content, source, forgedBytes, opResponse, context);
240
212
  }
241
213
  /**
242
214
  *
243
- * @description Transfer tz from current address to a specific address. Will sign and inject an operation using the current context
215
+ * Transfer tz from current address to a specific address. Will sign and inject an operation using the current context
244
216
  *
245
217
  * @returns An operation handle with the result from the rpc node
246
218
  *
247
- * @param Transfer operation parameter
219
+ * @param params Transfer operation parameter
248
220
  */
249
- transfer(params) {
250
- return __awaiter(this, void 0, void 0, function* () {
251
- var _a;
252
- const toValidation = (0, utils_1.validateAddress)(params.to);
253
- if (toValidation !== utils_1.ValidationResult.VALID) {
254
- throw new core_1.InvalidAddressError(params.to, toValidation);
255
- }
256
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
257
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
258
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
259
- }
260
- if (params.amount < 0) {
261
- throw new core_1.InvalidAmountError(params.amount.toString());
262
- }
263
- const publicKeyHash = yield this.signer.publicKeyHash();
264
- const estimate = yield this.estimate(params, this.estimator.transfer.bind(this.estimator));
265
- const source = params.source || publicKeyHash;
266
- const prepared = yield this.prepare.transaction(Object.assign(Object.assign({}, params), estimate));
267
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
268
- const opBytes = yield this.forge(prepared);
269
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
270
- return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
271
- });
221
+ async transfer(params) {
222
+ const toValidation = (0, utils_1.validateAddress)(params.to);
223
+ if (toValidation !== utils_1.ValidationResult.VALID) {
224
+ throw new core_1.InvalidAddressError(params.to, toValidation);
225
+ }
226
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
227
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
228
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
229
+ }
230
+ if (params.amount < 0) {
231
+ throw new core_1.InvalidAmountError(params.amount.toString());
232
+ }
233
+ const publicKeyHash = await this.signer.publicKeyHash();
234
+ const estimate = await this.estimate(params, this.estimator.transfer.bind(this.estimator));
235
+ const source = params.source || publicKeyHash;
236
+ const prepared = await this.prepare.transaction({ ...params, ...estimate });
237
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
238
+ const opBytes = await this.forge(prepared);
239
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
240
+ return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
272
241
  }
273
242
  /**
274
243
  *
275
- * @description Stake a given amount for the source address
244
+ * Stake a given amount for the source address
276
245
  *
277
246
  * @returns An operation handle with the result from the rpc node
278
247
  *
279
- * @param Stake pseudo-operation parameter
248
+ * @param params Stake pseudo-operation parameter
280
249
  */
281
- stake(params) {
282
- return __awaiter(this, void 0, void 0, function* () {
283
- var _a;
284
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
285
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
286
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
287
- }
288
- if (!params.to) {
289
- params.to = params.source;
290
- }
291
- if (params.to && params.to !== params.source) {
292
- throw new core_1.InvalidStakingAddressError(params.to);
293
- }
294
- if (params.amount < 0) {
295
- throw new core_1.InvalidAmountError(params.amount.toString());
296
- }
297
- const publicKeyHash = yield this.signer.publicKeyHash();
298
- const estimate = yield this.estimate(params, this.estimator.stake.bind(this.estimator));
299
- const source = params.source || publicKeyHash;
300
- const prepared = yield this.prepare.stake(Object.assign(Object.assign({}, params), estimate));
301
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
302
- const opBytes = yield this.forge(prepared);
303
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
304
- return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
305
- });
250
+ async stake(params) {
251
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
252
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
253
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
254
+ }
255
+ if (!params.to) {
256
+ params.to = params.source;
257
+ }
258
+ if (params.to && params.to !== params.source) {
259
+ throw new core_1.InvalidStakingAddressError(params.to);
260
+ }
261
+ if (params.amount < 0) {
262
+ throw new core_1.InvalidAmountError(params.amount.toString());
263
+ }
264
+ const publicKeyHash = await this.signer.publicKeyHash();
265
+ const estimate = await this.estimate(params, this.estimator.stake.bind(this.estimator));
266
+ const source = params.source || publicKeyHash;
267
+ const prepared = await this.prepare.stake({ ...params, ...estimate });
268
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
269
+ const opBytes = await this.forge(prepared);
270
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
271
+ return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
306
272
  }
307
273
  /**
308
274
  *
309
- * @description Unstake the given amount. If "everything" is given as amount, unstakes everything from the staking balance.
275
+ * Unstake the given amount. If "everything" is given as amount, unstakes everything from the staking balance.
310
276
  * Unstaked tez remains frozen for a set amount of cycles (the slashing period) after the operation. Once this period is over,
311
277
  * the operation "finalize unstake" must be called for the funds to appear in the liquid balance.
312
278
  *
313
279
  * @returns An operation handle with the result from the rpc node
314
280
  *
315
- * @param Unstake pseudo-operation parameter
281
+ * @param params Unstake pseudo-operation parameter
316
282
  */
317
- unstake(params) {
318
- return __awaiter(this, void 0, void 0, function* () {
319
- var _a;
320
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
321
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
322
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
323
- }
324
- if (!params.to) {
325
- params.to = params.source;
326
- }
327
- if (params.to && params.to !== params.source) {
328
- throw new core_1.InvalidStakingAddressError(params.to);
329
- }
330
- if (params.amount < 0) {
331
- throw new core_1.InvalidAmountError(params.amount.toString());
332
- }
333
- const publicKeyHash = yield this.signer.publicKeyHash();
334
- const estimate = yield this.estimate(params, this.estimator.unstake.bind(this.estimator));
335
- const source = params.source || publicKeyHash;
336
- const prepared = yield this.prepare.unstake(Object.assign(Object.assign({}, params), estimate));
337
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
338
- const opBytes = yield this.forge(prepared);
339
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
340
- return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
341
- });
283
+ async unstake(params) {
284
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
285
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
286
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
287
+ }
288
+ if (!params.to) {
289
+ params.to = params.source;
290
+ }
291
+ if (params.to && params.to !== params.source) {
292
+ throw new core_1.InvalidStakingAddressError(params.to);
293
+ }
294
+ if (params.amount < 0) {
295
+ throw new core_1.InvalidAmountError(params.amount.toString());
296
+ }
297
+ const publicKeyHash = await this.signer.publicKeyHash();
298
+ const estimate = await this.estimate(params, this.estimator.unstake.bind(this.estimator));
299
+ const source = params.source || publicKeyHash;
300
+ const prepared = await this.prepare.unstake({ ...params, ...estimate });
301
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
302
+ const opBytes = await this.forge(prepared);
303
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
304
+ return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
342
305
  }
343
306
  /**
344
307
  *
345
- * @description Transfer all the finalizable unstaked funds of the source to their liquid balance
308
+ * Transfer all the finalizable unstaked funds of the source to their liquid balance
346
309
  * @returns An operation handle with the result from the rpc node
347
310
  *
348
- * @param Finalize_unstake pseudo-operation parameter
311
+ * @param params Finalize_unstake pseudo-operation parameter
349
312
  */
350
- finalizeUnstake(params) {
351
- return __awaiter(this, void 0, void 0, function* () {
352
- var _a;
353
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
354
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
355
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
356
- }
357
- if (!params.to) {
358
- params.to = params.source;
359
- }
360
- if (!params.amount) {
361
- params.amount = 0;
362
- }
363
- if (params.amount !== undefined && params.amount > 0) {
364
- throw new core_1.InvalidFinalizeUnstakeAmountError('Amount must be 0 to finalize unstake.');
365
- }
366
- const publicKeyHash = yield this.signer.publicKeyHash();
367
- const estimate = yield this.estimate(params, this.estimator.finalizeUnstake.bind(this.estimator));
368
- const source = params.source || publicKeyHash;
369
- const prepared = yield this.prepare.finalizeUnstake(Object.assign(Object.assign({}, params), estimate));
370
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
371
- const opBytes = yield this.forge(prepared);
372
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
373
- return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
374
- });
313
+ async finalizeUnstake(params) {
314
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
315
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
316
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
317
+ }
318
+ if (!params.to) {
319
+ params.to = params.source;
320
+ }
321
+ if (!params.amount) {
322
+ params.amount = 0;
323
+ }
324
+ if (params.amount !== undefined && params.amount > 0) {
325
+ throw new core_1.InvalidFinalizeUnstakeAmountError('Amount must be 0 to finalize unstake.');
326
+ }
327
+ const publicKeyHash = await this.signer.publicKeyHash();
328
+ const estimate = await this.estimate(params, this.estimator.finalizeUnstake.bind(this.estimator));
329
+ const source = params.source || publicKeyHash;
330
+ const prepared = await this.prepare.finalizeUnstake({ ...params, ...estimate });
331
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSACTION);
332
+ const opBytes = await this.forge(prepared);
333
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
334
+ return new transaction_operation_1.TransactionOperation(hash, content, source, forgedBytes, opResponse, context);
375
335
  }
376
336
  /**
377
337
  *
378
- * @description Transfer Tickets to a smart contract address
338
+ * Transfer Tickets to a smart contract address
379
339
  *
380
340
  * @returns An operation handle with the result from the rpc node
381
341
  *
382
- * @param TransferTicketParams operation parameter
342
+ * @param params TransferTicket operation parameter
383
343
  */
384
- transferTicket(params) {
385
- return __awaiter(this, void 0, void 0, function* () {
386
- var _a, _b;
387
- const destinationValidation = (0, utils_1.validateAddress)(params.destination);
388
- if (destinationValidation !== utils_1.ValidationResult.VALID) {
389
- throw new core_1.InvalidAddressError(params.destination, destinationValidation);
390
- }
391
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
392
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
393
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
394
- }
395
- const publicKeyHash = yield this.signer.publicKeyHash();
396
- const source = (_b = params.source) !== null && _b !== void 0 ? _b : publicKeyHash;
397
- const estimate = yield this.estimate(params, this.estimator.transferTicket.bind(this.estimator));
398
- const prepared = yield this.prepare.transferTicket(Object.assign(Object.assign({}, params), estimate));
399
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSFER_TICKET);
400
- const opBytes = yield this.forge(prepared);
401
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
402
- return new transfer_ticket_operation_1.TransferTicketOperation(hash, content, source, forgedBytes, opResponse, context);
403
- });
344
+ async transferTicket(params) {
345
+ const destinationValidation = (0, utils_1.validateAddress)(params.destination);
346
+ if (destinationValidation !== utils_1.ValidationResult.VALID) {
347
+ throw new core_1.InvalidAddressError(params.destination, destinationValidation);
348
+ }
349
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
350
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
351
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
352
+ }
353
+ const publicKeyHash = await this.signer.publicKeyHash();
354
+ const source = params.source ?? publicKeyHash;
355
+ const estimate = await this.estimate(params, this.estimator.transferTicket.bind(this.estimator));
356
+ const prepared = await this.prepare.transferTicket({ ...params, ...estimate });
357
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.TRANSFER_TICKET);
358
+ const opBytes = await this.forge(prepared);
359
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
360
+ return new transfer_ticket_operation_1.TransferTicketOperation(hash, content, source, forgedBytes, opResponse, context);
404
361
  }
405
362
  /**
406
363
  *
407
- * @description Reveal the public key of the current address. Will throw an error if the address is already revealed.
364
+ * Reveal the public key of the current address. Will throw an error if the address is already revealed.
408
365
  * @returns An operation handle with the result from the rpc node
409
366
  *
410
- * @param RevealParams operation parameter
367
+ * @param params Reveal operation parameter
411
368
  */
412
- reveal(params) {
413
- return __awaiter(this, void 0, void 0, function* () {
414
- const publicKeyHash = yield this.signer.publicKeyHash();
415
- const [, pkhPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(publicKeyHash, utils_1.publicKeyHashPrefixes);
416
- if (pkhPrefix === utils_1.PrefixV2.BLS12_381PublicKeyHash) {
417
- if (params.proof) {
418
- (0, utils_1.b58DecodeAndCheckPrefix)(params.proof, [utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
419
- }
420
- else {
421
- const { prefixSig } = yield this.signer.provePossession();
422
- params.proof = prefixSig;
423
- }
369
+ async reveal(params) {
370
+ const publicKeyHash = await this.signer.publicKeyHash();
371
+ const [, pkhPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(publicKeyHash, utils_1.publicKeyHashPrefixes);
372
+ if (pkhPrefix === utils_1.PrefixV2.BLS12_381PublicKeyHash) {
373
+ if (params.proof) {
374
+ (0, utils_1.b58DecodeAndCheckPrefix)(params.proof, [utils_1.PrefixV2.BLS12_381Signature]); // validate proof to be a bls signature
424
375
  }
425
376
  else {
426
- if (params.proof) {
427
- throw new core_1.ProhibitedActionError('Proof field is only allowed to reveal a bls account ');
428
- }
429
- }
430
- const estimateReveal = yield this.estimator.reveal(params);
431
- if (estimateReveal) {
432
- const estimated = yield this.estimate(params, () => __awaiter(this, void 0, void 0, function* () { return estimateReveal; }));
433
- const prepared = yield this.prepare.reveal(Object.assign(Object.assign({}, params), estimated));
434
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REVEAL);
435
- const opBytes = yield this.forge(prepared);
436
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
437
- return new reveal_operation_1.RevealOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
377
+ const { prefixSig } = await this.signer.provePossession();
378
+ params.proof = prefixSig;
438
379
  }
439
- else {
440
- throw new errors_1.RevealOperationError(`The publicKeyHash '${publicKeyHash}' has already been revealed.`);
380
+ }
381
+ else {
382
+ if (params.proof) {
383
+ throw new core_1.ProhibitedActionError('Proof field is only allowed to reveal a bls account ');
441
384
  }
442
- });
385
+ }
386
+ const estimateReveal = await this.estimator.reveal(params);
387
+ if (estimateReveal) {
388
+ const estimated = await this.estimate(params, async () => estimateReveal);
389
+ const prepared = await this.prepare.reveal({ ...params, ...estimated });
390
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REVEAL);
391
+ const opBytes = await this.forge(prepared);
392
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
393
+ return new reveal_operation_1.RevealOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
394
+ }
395
+ else {
396
+ throw new errors_1.RevealOperationError(`The publicKeyHash '${publicKeyHash}' has already been revealed.`);
397
+ }
443
398
  }
444
399
  /**
445
400
  *
446
- * @description Register a Micheline expression in a global table of constants. Will sign and inject an operation using the current context
401
+ * Register a Micheline expression in a global table of constants. Will sign and inject an operation using the current context
447
402
  *
448
403
  * @returns An operation handle with the result from the rpc node
449
404
  *
450
405
  * @param params registerGlobalConstant operation parameter
451
406
  */
452
- registerGlobalConstant(params) {
453
- return __awaiter(this, void 0, void 0, function* () {
454
- const publicKeyHash = yield this.signer.publicKeyHash();
455
- const estimate = yield this.estimate(params, this.estimator.registerGlobalConstant.bind(this.estimator));
456
- const prepared = yield this.prepare.registerGlobalConstant(Object.assign(Object.assign({}, params), estimate));
457
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REGISTER_GLOBAL_CONSTANT);
458
- const opBytes = yield this.forge(prepared);
459
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
460
- return new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
461
- });
407
+ async registerGlobalConstant(params) {
408
+ const publicKeyHash = await this.signer.publicKeyHash();
409
+ const estimate = await this.estimate(params, this.estimator.registerGlobalConstant.bind(this.estimator));
410
+ const prepared = await this.prepare.registerGlobalConstant({ ...params, ...estimate });
411
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.REGISTER_GLOBAL_CONSTANT);
412
+ const opBytes = await this.forge(prepared);
413
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
414
+ return new register_global_constant_operation_1.RegisterGlobalConstantOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
462
415
  }
463
416
  /**
464
417
  *
465
- * @description Increase the paid storage of a smart contract
418
+ * Increase the paid storage of a smart contract
466
419
  *
467
420
  * @returns An operation handle with the result from the rpc node
468
421
  *
469
422
  * @param params increasePaidStorage operation parameter
470
423
  */
471
- increasePaidStorage(params) {
472
- return __awaiter(this, void 0, void 0, function* () {
473
- if (params.amount <= 0) {
474
- throw new core_1.InvalidAmountError(params.amount.toString());
475
- }
476
- const publicKeyHash = yield this.signer.publicKeyHash();
477
- const estimate = yield this.estimate(params, this.estimator.increasePaidStorage.bind(this.estimator));
478
- const prepared = yield this.prepare.increasePaidStorage(Object.assign(Object.assign({}, params), estimate));
479
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.INCREASE_PAID_STORAGE);
480
- const opBytes = yield this.forge(prepared);
481
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
482
- return new increase_paid_storage_operation_1.IncreasePaidStorageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
483
- });
424
+ async increasePaidStorage(params) {
425
+ if (params.amount <= 0) {
426
+ throw new core_1.InvalidAmountError(params.amount.toString());
427
+ }
428
+ const publicKeyHash = await this.signer.publicKeyHash();
429
+ const estimate = await this.estimate(params, this.estimator.increasePaidStorage.bind(this.estimator));
430
+ const prepared = await this.prepare.increasePaidStorage({ ...params, ...estimate });
431
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.INCREASE_PAID_STORAGE);
432
+ const opBytes = await this.forge(prepared);
433
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
434
+ return new increase_paid_storage_operation_1.IncreasePaidStorageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
484
435
  }
485
436
  /**
486
437
  *
487
- * @description Transfers the spendable balance of the delegate to destination when consensus_key is the active consensus key of delegate
438
+ * Transfers the spendable balance of the delegate to destination when consensus_key is the active consensus key of delegate
488
439
  *
489
440
  * @returns An operation handle with the result from the rpc node
490
441
  *
491
442
  * @param params drainDelegate operation parameter
492
443
  */
493
- drainDelegate(params) {
494
- return __awaiter(this, void 0, void 0, function* () {
495
- const prepared = yield this.prepare.drainDelegate(params);
496
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DRAIN_DELEGATE);
497
- const opBytes = yield this.forge(prepared);
498
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
499
- return new drain_delegate_operation_1.DrainDelegateOperation(hash, content, forgedBytes, opResponse, context);
500
- });
444
+ async drainDelegate(params) {
445
+ const prepared = await this.prepare.drainDelegate(params);
446
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.DRAIN_DELEGATE);
447
+ const opBytes = await this.forge(prepared);
448
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
449
+ return new drain_delegate_operation_1.DrainDelegateOperation(hash, content, forgedBytes, opResponse, context);
501
450
  }
502
451
  /**
503
452
  *
504
- * @description Submit a ballot vote to a specified proposal
453
+ * Submit a ballot vote to a specified proposal
505
454
  *
506
455
  * @returns An operation handle with the result from the rpc node
507
456
  *
508
- * @param BallotParams Ballot operation parameter
457
+ * @param params Ballot operation parameter
509
458
  */
510
- ballot(params) {
511
- return __awaiter(this, void 0, void 0, function* () {
512
- var _a, _b;
513
- const publicKeyHash = yield this.signer.publicKeyHash();
514
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
515
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
516
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
517
- }
518
- const source = (_b = params.source) !== null && _b !== void 0 ? _b : publicKeyHash;
519
- const prepared = yield this.prepare.ballot(Object.assign(Object.assign({}, params), { source }));
520
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.BALLOT);
521
- const opBytes = yield this.forge(prepared);
522
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
523
- return new ballot_operation_1.BallotOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
524
- });
459
+ async ballot(params) {
460
+ const publicKeyHash = await this.signer.publicKeyHash();
461
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
462
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
463
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
464
+ }
465
+ const source = params.source ?? publicKeyHash;
466
+ const prepared = await this.prepare.ballot({ ...params, source });
467
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.BALLOT);
468
+ const opBytes = await this.forge(prepared);
469
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
470
+ return new ballot_operation_1.BallotOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
525
471
  }
526
472
  /**
527
473
  *
528
- * @description Submit or upvote a proposal during the Proposal period
474
+ * Submit or upvote a proposal during the Proposal period
529
475
  *
530
476
  * @returns An operation handle with the result from the rpc node
531
477
  *
532
- * @param ProposalsParams Proposals operation parameter
478
+ * @param params Proposals operation parameter
533
479
  */
534
- proposals(params) {
535
- return __awaiter(this, void 0, void 0, function* () {
536
- var _a, _b;
537
- const publicKeyHash = yield this.signer.publicKeyHash();
538
- const sourceValidation = (0, utils_1.validateAddress)((_a = params.source) !== null && _a !== void 0 ? _a : '');
539
- if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
540
- throw new core_1.InvalidAddressError(params.source, sourceValidation);
541
- }
542
- const source = (_b = params.source) !== null && _b !== void 0 ? _b : publicKeyHash;
543
- const prepared = yield this.prepare.proposals(Object.assign(Object.assign({}, params), { source }));
544
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.PROPOSALS);
545
- const opBytes = yield this.forge(prepared);
546
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
547
- return new proposals_operation_1.ProposalsOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
548
- });
480
+ async proposals(params) {
481
+ const publicKeyHash = await this.signer.publicKeyHash();
482
+ const sourceValidation = (0, utils_1.validateAddress)(params.source ?? '');
483
+ if (params.source && sourceValidation !== utils_1.ValidationResult.VALID) {
484
+ throw new core_1.InvalidAddressError(params.source, sourceValidation);
485
+ }
486
+ const source = params.source ?? publicKeyHash;
487
+ const prepared = await this.prepare.proposals({ ...params, source });
488
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.PROPOSALS);
489
+ const opBytes = await this.forge(prepared);
490
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
491
+ return new proposals_operation_1.ProposalsOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
549
492
  }
550
493
  /**
551
494
  *
552
- * @description Update the consensus key of a delegate starting from the current cycle plus CONSENSUS_RIGHTS_DELAY + 1
495
+ * Update the consensus key of a delegate starting from the current cycle plus CONSENSUS_RIGHTS_DELAY + 1
553
496
  * @returns An operation handle with the result from the rpc node
554
497
  *
555
- * @param UpdateConsensusKeyParams
498
+ * @param params UpdateConsensusKey operation parameter
556
499
  */
557
- updateConsensusKey(params) {
558
- return __awaiter(this, void 0, void 0, function* () {
559
- const publicKeyHash = yield this.signer.publicKeyHash();
560
- const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
561
- if (pkPrefix === utils_1.PrefixV2.BLS12_381PublicKey) {
562
- if (!params.proof) {
563
- throw new core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
564
- }
500
+ async updateConsensusKey(params) {
501
+ const publicKeyHash = await this.signer.publicKeyHash();
502
+ const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
503
+ if (pkPrefix === utils_1.PrefixV2.BLS12_381PublicKey) {
504
+ if (!params.proof) {
505
+ throw new core_1.InvalidProofError('Proof is required to set a bls account as consensus key ');
565
506
  }
566
- else {
567
- if (params.proof) {
568
- throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as consensus key');
569
- }
507
+ }
508
+ else {
509
+ if (params.proof) {
510
+ throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as consensus key');
570
511
  }
571
- const estimate = yield this.estimate(params, this.estimator.updateConsensusKey.bind(this.estimator));
572
- const prepared = yield this.prepare.updateConsensusKey(Object.assign(Object.assign({}, params), estimate));
573
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_CONSENSUS_KEY);
574
- const opBytes = yield this.forge(prepared);
575
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
576
- return new update_consensus_key_operation_1.UpdateConsensusKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
577
- });
512
+ }
513
+ const estimate = await this.estimate(params, this.estimator.updateConsensusKey.bind(this.estimator));
514
+ const prepared = await this.prepare.updateConsensusKey({ ...params, ...estimate });
515
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_CONSENSUS_KEY);
516
+ const opBytes = await this.forge(prepared);
517
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
518
+ return new update_consensus_key_operation_1.UpdateConsensusKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
578
519
  }
579
520
  /**
580
521
  *
581
- * @description Updates the companion key of the delegate starting from the current cycle plus CONSENSUS_KEY_ACTIVATION_DELAY + 1
522
+ * Updates the companion key of the delegate starting from the current cycle plus CONSENSUS_KEY_ACTIVATION_DELAY + 1
582
523
  * @returns An operation handle with the result from the rpc node
583
524
  *
584
- * @param UpdateCompanionKeyParams
525
+ * @param params UpdateCompanionKey operation parameter
585
526
  */
586
- updateCompanionKey(params) {
587
- return __awaiter(this, void 0, void 0, function* () {
588
- const publicKeyHash = yield this.signer.publicKeyHash();
589
- const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
590
- if (pkPrefix !== utils_1.PrefixV2.BLS12_381PublicKey) {
591
- throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as companion key');
592
- }
593
- if (!params.proof) {
594
- throw new core_1.InvalidProofError('Proof is required to set a bls account as companion key ');
595
- }
596
- const estimate = yield this.estimate(params, this.estimator.updateCompanionKey.bind(this.estimator));
597
- const prepared = yield this.prepare.updateCompanionKey(Object.assign(Object.assign({}, params), estimate));
598
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_COMPANION_KEY);
599
- const opBytes = yield this.forge(prepared);
600
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
601
- return new update_companion_key_operation_1.UpdateCompanionKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
602
- });
527
+ async updateCompanionKey(params) {
528
+ const publicKeyHash = await this.signer.publicKeyHash();
529
+ const [, pkPrefix] = (0, utils_1.b58DecodeAndCheckPrefix)(params.pk, utils_1.publicKeyPrefixes);
530
+ if (pkPrefix !== utils_1.PrefixV2.BLS12_381PublicKey) {
531
+ throw new core_1.ProhibitedActionError('Proof field is only allowed for a bls account as companion key');
532
+ }
533
+ if (!params.proof) {
534
+ throw new core_1.InvalidProofError('Proof is required to set a bls account as companion key ');
535
+ }
536
+ const estimate = await this.estimate(params, this.estimator.updateCompanionKey.bind(this.estimator));
537
+ const prepared = await this.prepare.updateCompanionKey({ ...params, ...estimate });
538
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.UPDATE_COMPANION_KEY);
539
+ const opBytes = await this.forge(prepared);
540
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
541
+ return new update_companion_key_operation_1.UpdateCompanionKeyOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
603
542
  }
604
543
  /**
605
- * @description Adds messages to the rollup inbox that can be executed/claimed after it gets cemented
606
- * @param SmartRollupAddMessagesParams
544
+ * Adds messages to the rollup inbox that can be executed/claimed after it gets cemented
545
+ * @param params SmartRollupAddMessages operation parameter
607
546
  * @returns An operation handle with results from the RPC node
608
547
  */
609
- smartRollupAddMessages(params) {
610
- return __awaiter(this, void 0, void 0, function* () {
611
- const publicKeyHash = yield this.signer.publicKeyHash();
612
- const estimate = yield this.estimate(params, this.estimator.smartRollupAddMessages.bind(this.estimator));
613
- const prepared = yield this.prepare.smartRollupAddMessages(Object.assign(Object.assign({}, params), estimate));
614
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ADD_MESSAGES);
615
- const opBytes = yield this.forge(prepared);
616
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
617
- return new smart_rollup_add_messages_operation_1.SmartRollupAddMessagesOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
618
- });
548
+ async smartRollupAddMessages(params) {
549
+ const publicKeyHash = await this.signer.publicKeyHash();
550
+ const estimate = await this.estimate(params, this.estimator.smartRollupAddMessages.bind(this.estimator));
551
+ const prepared = await this.prepare.smartRollupAddMessages({ ...params, ...estimate });
552
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ADD_MESSAGES);
553
+ const opBytes = await this.forge(prepared);
554
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
555
+ return new smart_rollup_add_messages_operation_1.SmartRollupAddMessagesOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
619
556
  }
620
557
  /**
621
- * @description Creates a smart rollup originate operation
622
- * @param SmartRollupOriginateParams
558
+ * Creates a smart rollup originate operation
559
+ * @param params SmartRollupOriginate operation parameter
623
560
  * @returns An operation handle with results from the RPC node
624
561
  */
625
- smartRollupOriginate(params) {
626
- return __awaiter(this, void 0, void 0, function* () {
627
- const publicKeyHash = yield this.signer.publicKeyHash();
628
- const estimate = yield this.estimate(params, this.estimator.smartRollupOriginate.bind(this.estimator));
629
- const prepared = yield this.prepare.smartRollupOriginate(Object.assign(Object.assign({}, params), estimate));
630
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ORIGINATE);
631
- const opBytes = yield this.forge(prepared);
632
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
633
- return new smart_rollup_originate_operation_1.SmartRollupOriginateOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
634
- });
562
+ async smartRollupOriginate(params) {
563
+ const publicKeyHash = await this.signer.publicKeyHash();
564
+ const estimate = await this.estimate(params, this.estimator.smartRollupOriginate.bind(this.estimator));
565
+ const prepared = await this.prepare.smartRollupOriginate({ ...params, ...estimate });
566
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_ORIGINATE);
567
+ const opBytes = await this.forge(prepared);
568
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
569
+ return new smart_rollup_originate_operation_1.SmartRollupOriginateOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
635
570
  }
636
571
  /**
637
- * @description Execute a message from a smart rollup's outbox of a cemented commitment
638
- * @param SmartRollupExecuteOutboxMessageParams
572
+ * Execute a message from a smart rollup's outbox of a cemented commitment
573
+ * @param params SmartRollupExecuteOutboxMessage operation parameter
639
574
  * @returns An operation handle with results from the RPC node
640
575
  */
641
- smartRollupExecuteOutboxMessage(params) {
642
- return __awaiter(this, void 0, void 0, function* () {
643
- const publicKeyHash = yield this.signer.publicKeyHash();
644
- const estimate = yield this.estimate(params, this.estimator.smartRollupExecuteOutboxMessage.bind(this.estimator));
645
- const prepared = yield this.prepare.smartRollupExecuteOutboxMessage(Object.assign(Object.assign({}, params), estimate));
646
- const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE);
647
- const opBytes = yield this.forge(prepared);
648
- const { hash, context, forgedBytes, opResponse } = yield this.signAndInject(opBytes);
649
- return new smart_rollup_execute_outbox_message_operation_1.SmartRollupExecuteOutboxMessageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
650
- });
576
+ async smartRollupExecuteOutboxMessage(params) {
577
+ const publicKeyHash = await this.signer.publicKeyHash();
578
+ const estimate = await this.estimate(params, this.estimator.smartRollupExecuteOutboxMessage.bind(this.estimator));
579
+ const prepared = await this.prepare.smartRollupExecuteOutboxMessage({ ...params, ...estimate });
580
+ const content = prepared.opOb.contents.find((op) => op.kind === rpc_1.OpKind.SMART_ROLLUP_EXECUTE_OUTBOX_MESSAGE);
581
+ const opBytes = await this.forge(prepared);
582
+ const { hash, context, forgedBytes, opResponse } = await this.signAndInject(opBytes);
583
+ return new smart_rollup_execute_outbox_message_operation_1.SmartRollupExecuteOutboxMessageOperation(hash, content, publicKeyHash, forgedBytes, opResponse, context);
651
584
  }
652
585
  /**
653
586
  *
654
- * @description A failing_noop operation that is guaranteed to fail.
587
+ * A failing_noop operation that is guaranteed to fail.
655
588
  *
656
589
  * @returns A FailingNoopOperation object representing the signed failing_noop operation
657
590
  *
658
591
  * @param params failingNoop operation parameter
659
592
  */
660
- failingNoop(params) {
661
- return __awaiter(this, void 0, void 0, function* () {
662
- const op = {
663
- kind: rpc_1.OpKind.FAILING_NOOP,
664
- arbitrary: params.arbitrary,
665
- };
666
- const hash = yield this.context.readProvider.getBlockHash(params.basedOnBlock);
667
- const forged = yield this.context.forger.forge({
668
- branch: hash,
669
- contents: [op],
670
- });
671
- const { prefixSig } = yield this.signer.sign(forged, new Uint8Array([3]));
672
- return {
673
- signature: prefixSig,
674
- bytes: forged,
675
- signedContent: {
676
- branch: hash,
677
- contents: [
678
- {
679
- kind: rpc_1.OpKind.FAILING_NOOP,
680
- arbitrary: params.arbitrary,
681
- },
682
- ],
683
- },
684
- };
593
+ async failingNoop(params) {
594
+ const op = {
595
+ kind: rpc_1.OpKind.FAILING_NOOP,
596
+ arbitrary: params.arbitrary,
597
+ };
598
+ const hash = await this.context.readProvider.getBlockHash(params.basedOnBlock);
599
+ const forged = await this.context.forger.forge({
600
+ branch: hash,
601
+ contents: [op],
685
602
  });
603
+ const { prefixSig } = await this.signer.sign(forged, new Uint8Array([3]));
604
+ return {
605
+ signature: prefixSig,
606
+ bytes: forged,
607
+ signedContent: {
608
+ branch: hash,
609
+ contents: [
610
+ {
611
+ kind: rpc_1.OpKind.FAILING_NOOP,
612
+ arbitrary: params.arbitrary,
613
+ },
614
+ ],
615
+ },
616
+ };
686
617
  }
687
618
  /**
688
619
  *
689
- * @description Create an smart contract abstraction for the address specified.
620
+ * Create an smart contract abstraction for the address specified.
690
621
  *
691
622
  * @param address Smart contract address
692
623
  * @throws {@link InvalidContractAddressError}
693
624
  */
694
- at(address_1) {
695
- return __awaiter(this, arguments, void 0, function* (address, contractAbstractionComposer = (x) => x) {
696
- const addressValidation = (0, utils_1.validateContractAddress)(address);
697
- if (addressValidation !== utils_1.ValidationResult.VALID) {
698
- throw new core_1.InvalidContractAddressError(address, addressValidation);
625
+ async at(address, contractAbstractionComposer = (x) => x, block = 'head') {
626
+ const addressValidation = (0, utils_1.validateContractAddress)(address);
627
+ if (addressValidation !== utils_1.ValidationResult.VALID) {
628
+ throw new core_1.InvalidContractAddressError(address, addressValidation);
629
+ }
630
+ const rpc = this.context.withExtensions().rpc;
631
+ const readProvider = this.context.withExtensions().readProvider;
632
+ const loadContractState = async (requestedBlock) => {
633
+ const script = await readProvider.getScript(address, requestedBlock);
634
+ const entrypoints = requestedBlock === 'head'
635
+ ? await readProvider.getEntrypoints(address)
636
+ : await rpc.getEntrypoints(address, { block: String(requestedBlock) });
637
+ return { script, entrypoints };
638
+ };
639
+ let contractState;
640
+ try {
641
+ contractState = await loadContractState(block);
642
+ }
643
+ catch (error) {
644
+ // Shadownet's rolling nodes occasionally 404 a just-originated contract at the exact
645
+ // inclusion level even after confirmation. Retry at head so the contract abstraction still
646
+ // resolves once the node's contract index catches up.
647
+ if (block !== 'head' &&
648
+ error instanceof http_utils_1.HttpResponseError &&
649
+ error.status === http_utils_1.STATUS_CODE.NOT_FOUND) {
650
+ contractState = await loadContractState('head');
699
651
  }
700
- const rpc = this.context.withExtensions().rpc;
701
- const readProvider = this.context.withExtensions().readProvider;
702
- const script = yield readProvider.getScript(address, 'head');
703
- const entrypoints = yield readProvider.getEntrypoints(address);
704
- const abs = new contract_1.ContractAbstraction(address, script, this, this, entrypoints, rpc, readProvider);
705
- return contractAbstractionComposer(abs, this.context);
706
- });
652
+ else {
653
+ throw error;
654
+ }
655
+ }
656
+ const abs = new contract_1.ContractAbstraction(address, contractState.script, this, this, contractState.entrypoints, rpc, readProvider);
657
+ return contractAbstractionComposer(abs, this.context);
707
658
  }
708
659
  /**
709
660
  *
710
- * @description Batch a group of operation together. Operations will be applied in the order in which they are added to the batch
661
+ * Batch a group of operation together. Operations will be applied in the order in which they are added to the batch
711
662
  *
712
663
  * @returns A batch object from which we can add more operation or send a command to execute the batch
713
664
  *