@firmachain/firma-js 0.2.2 → 0.2.6

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -154
  3. package/dist/sdk/FirmaBankService.d.ts +5 -5
  4. package/dist/sdk/FirmaBankService.js +30 -30
  5. package/dist/sdk/FirmaConfig.d.ts +3 -3
  6. package/dist/sdk/FirmaContractService.d.ts +5 -5
  7. package/dist/sdk/FirmaContractService.js +19 -19
  8. package/dist/sdk/FirmaDistributionService.d.ts +13 -9
  9. package/dist/sdk/FirmaDistributionService.js +162 -78
  10. package/dist/sdk/FirmaFeeGrantService.d.ts +11 -8
  11. package/dist/sdk/FirmaFeeGrantService.js +128 -53
  12. package/dist/sdk/FirmaGovService.d.ts +28 -16
  13. package/dist/sdk/FirmaGovService.js +447 -119
  14. package/dist/sdk/FirmaIpfsService.d.ts +4 -4
  15. package/dist/sdk/FirmaIpfsService.js +14 -14
  16. package/dist/sdk/FirmaNftService.d.ts +4 -4
  17. package/dist/sdk/FirmaNftService.js +18 -20
  18. package/dist/sdk/FirmaSDK.js +2 -1
  19. package/dist/sdk/FirmaStakingService.d.ts +9 -6
  20. package/dist/sdk/FirmaStakingService.js +177 -97
  21. package/dist/sdk/FirmaUtil.d.ts +3 -2
  22. package/dist/sdk/FirmaUtil.js +16 -11
  23. package/dist/sdk/FirmaWalletService.d.ts +6 -6
  24. package/dist/sdk/FirmaWalletService.js +22 -22
  25. package/dist/sdk/firmachain/bank/BankQueryClient.d.ts +1 -1
  26. package/dist/sdk/firmachain/bank/BankQueryClient.js +4 -4
  27. package/dist/sdk/firmachain/bank/BankTxClient.d.ts +3 -4
  28. package/dist/sdk/firmachain/bank/BankTxClient.js +2 -2
  29. package/dist/sdk/firmachain/common/ITxClient.d.ts +5 -5
  30. package/dist/sdk/firmachain/common/ITxClient.js +7 -7
  31. package/dist/sdk/firmachain/common/TendermintQueryClient.d.ts +1 -1
  32. package/dist/sdk/firmachain/common/TendermintQueryClient.js +5 -4
  33. package/dist/sdk/firmachain/common/accounts.js +25 -20
  34. package/dist/sdk/firmachain/common/signingstargateclient.js +3 -3
  35. package/dist/sdk/firmachain/contract/ContractQueryClient.d.ts +2 -2
  36. package/dist/sdk/firmachain/contract/ContractQueryClient.js +17 -11
  37. package/dist/sdk/firmachain/contract/ContractTxClient.d.ts +3 -4
  38. package/dist/sdk/firmachain/contract/ContractTxClient.js +3 -3
  39. package/dist/sdk/firmachain/distribution/DistributionQueryClient.d.ts +2 -1
  40. package/dist/sdk/firmachain/distribution/DistributionQueryClient.js +33 -16
  41. package/dist/sdk/firmachain/distribution/DistributionTxClient.d.ts +5 -6
  42. package/dist/sdk/firmachain/distribution/DistributionTxClient.js +3 -3
  43. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.d.ts +2 -2
  44. package/dist/sdk/firmachain/feegrant/FeeGrantQueryClient.js +4 -4
  45. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.d.ts +3 -4
  46. package/dist/sdk/firmachain/feegrant/FeeGrantTxClient.js +2 -2
  47. package/dist/sdk/firmachain/gov/GovQueryClient.d.ts +51 -3
  48. package/dist/sdk/firmachain/gov/GovQueryClient.js +62 -11
  49. package/dist/sdk/firmachain/gov/GovTxClient.d.ts +4 -5
  50. package/dist/sdk/firmachain/gov/GovTxClient.js +3 -3
  51. package/dist/sdk/firmachain/nft/NftQueryClient.d.ts +2 -2
  52. package/dist/sdk/firmachain/nft/NftQueryClient.js +11 -8
  53. package/dist/sdk/firmachain/nft/NftTxClient.d.ts +4 -5
  54. package/dist/sdk/firmachain/nft/NftTxClient.js +3 -3
  55. package/dist/sdk/firmachain/staking/StakingQueryClient.d.ts +3 -1
  56. package/dist/sdk/firmachain/staking/StakingQueryClient.js +48 -16
  57. package/dist/sdk/firmachain/staking/StakingTxClient.d.ts +6 -7
  58. package/dist/sdk/firmachain/staking/StakingTxClient.js +2 -2
  59. package/package.json +1 -1
@@ -40,8 +40,8 @@ exports.FirmaStakingService = void 0;
40
40
  var staking_1 = require("./firmachain/staking");
41
41
  var FirmaUtil_1 = require("./FirmaUtil");
42
42
  var FirmaStakingService = /** @class */ (function () {
43
- function FirmaStakingService(_config) {
44
- this._config = _config;
43
+ function FirmaStakingService(config) {
44
+ this.config = config;
45
45
  }
46
46
  FirmaStakingService.prototype.getGasEstimationDelegate = function (wallet, validatorAddres, amount, txMisc) {
47
47
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
@@ -87,21 +87,18 @@ var FirmaStakingService = /** @class */ (function () {
87
87
  });
88
88
  });
89
89
  };
90
- FirmaStakingService.prototype.getSignedTxDelegate = function (wallet, validatorAddres, amount, txMisc) {
90
+ FirmaStakingService.prototype.getGasEstimationRedelegate = function (wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc) {
91
91
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
92
92
  return __awaiter(this, void 0, void 0, function () {
93
- var txClient, address, sendAmount, message, error_3;
93
+ var txRaw, error_3;
94
94
  return __generator(this, function (_a) {
95
95
  switch (_a.label) {
96
96
  case 0:
97
97
  _a.trys.push([0, 3, , 4]);
98
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
99
- return [4 /*yield*/, wallet.getAddress()];
98
+ return [4 /*yield*/, this.getSignedTxRedelegate(wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc)];
100
99
  case 1:
101
- address = _a.sent();
102
- sendAmount = { denom: this._config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
103
- message = txClient.msgDelegate({ delegatorAddress: address, validatorAddress: validatorAddres, amount: sendAmount });
104
- return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this._config.denom, txMisc))];
100
+ txRaw = _a.sent();
101
+ return [4 /*yield*/, FirmaUtil_1.FirmaUtil.estimateGas(txRaw)];
105
102
  case 2: return [2 /*return*/, _a.sent()];
106
103
  case 3:
107
104
  error_3 = _a.sent();
@@ -112,7 +109,7 @@ var FirmaStakingService = /** @class */ (function () {
112
109
  });
113
110
  });
114
111
  };
115
- FirmaStakingService.prototype.getSignedTxUndelegate = function (wallet, validatorAddres, amount, txMisc) {
112
+ FirmaStakingService.prototype.getSignedTxDelegate = function (wallet, validatorAddres, amount, txMisc) {
116
113
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
117
114
  return __awaiter(this, void 0, void 0, function () {
118
115
  var txClient, address, sendAmount, message, error_4;
@@ -120,13 +117,17 @@ var FirmaStakingService = /** @class */ (function () {
120
117
  switch (_a.label) {
121
118
  case 0:
122
119
  _a.trys.push([0, 3, , 4]);
123
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
120
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
124
121
  return [4 /*yield*/, wallet.getAddress()];
125
122
  case 1:
126
123
  address = _a.sent();
127
- sendAmount = { denom: this._config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
128
- message = txClient.msgUndelegate({ delegatorAddress: address, validatorAddress: validatorAddres, amount: sendAmount });
129
- return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this._config.denom, txMisc))];
124
+ sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
125
+ message = txClient.msgDelegate({
126
+ delegatorAddress: address,
127
+ validatorAddress: validatorAddres,
128
+ amount: sendAmount
129
+ });
130
+ return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
130
131
  case 2: return [2 /*return*/, _a.sent()];
131
132
  case 3:
132
133
  error_4 = _a.sent();
@@ -137,7 +138,7 @@ var FirmaStakingService = /** @class */ (function () {
137
138
  });
138
139
  });
139
140
  };
140
- FirmaStakingService.prototype.getSignedTxRedelegate = function (wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc) {
141
+ FirmaStakingService.prototype.getSignedTxUndelegate = function (wallet, validatorAddres, amount, txMisc) {
141
142
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
142
143
  return __awaiter(this, void 0, void 0, function () {
143
144
  var txClient, address, sendAmount, message, error_5;
@@ -145,16 +146,17 @@ var FirmaStakingService = /** @class */ (function () {
145
146
  switch (_a.label) {
146
147
  case 0:
147
148
  _a.trys.push([0, 3, , 4]);
148
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
149
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
149
150
  return [4 /*yield*/, wallet.getAddress()];
150
151
  case 1:
151
152
  address = _a.sent();
152
- sendAmount = { denom: this._config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
153
- message = txClient.msgRedelegate({
154
- delegatorAddress: address, validatorSrcAddress: validatorSrcAddress,
155
- validatorDstAddress: validatorDstAddress, amount: sendAmount
153
+ sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
154
+ message = txClient.msgUndelegate({
155
+ delegatorAddress: address,
156
+ validatorAddress: validatorAddres,
157
+ amount: sendAmount
156
158
  });
157
- return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this._config.denom, txMisc))];
159
+ return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
158
160
  case 2: return [2 /*return*/, _a.sent()];
159
161
  case 3:
160
162
  error_5 = _a.sent();
@@ -165,32 +167,37 @@ var FirmaStakingService = /** @class */ (function () {
165
167
  });
166
168
  });
167
169
  };
168
- FirmaStakingService.prototype.getSignedTxCreateValidator = function (wallet, validatorInfo, txMisc) {
170
+ FirmaStakingService.prototype.getSignedTxRedelegate = function (wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc) {
169
171
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
170
172
  return __awaiter(this, void 0, void 0, function () {
171
- var txClient, message, error_6;
173
+ var txClient, address, sendAmount, message, error_6;
172
174
  return __generator(this, function (_a) {
173
175
  switch (_a.label) {
174
176
  case 0:
175
- _a.trys.push([0, 2, , 3]);
176
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
177
- message = txClient.msgCreateValidator({
178
- description: validatorInfo.description, commission: validatorInfo.commission,
179
- minSelfDelegation: validatorInfo.minSelfDelegation, delegatorAddress: validatorInfo.delegatorAddress,
180
- validatorAddress: validatorInfo.validatorAddress, pubkey: validatorInfo.pubkey, value: validatorInfo.value
177
+ _a.trys.push([0, 3, , 4]);
178
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
179
+ return [4 /*yield*/, wallet.getAddress()];
180
+ case 1:
181
+ address = _a.sent();
182
+ sendAmount = { denom: this.config.denom, amount: FirmaUtil_1.FirmaUtil.getUFCTStringFromFCT(amount) };
183
+ message = txClient.msgRedelegate({
184
+ delegatorAddress: address,
185
+ validatorSrcAddress: validatorSrcAddress,
186
+ validatorDstAddress: validatorDstAddress,
187
+ amount: sendAmount
181
188
  });
182
- return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this._config.denom, txMisc))];
183
- case 1: return [2 /*return*/, _a.sent()];
184
- case 2:
189
+ return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
190
+ case 2: return [2 /*return*/, _a.sent()];
191
+ case 3:
185
192
  error_6 = _a.sent();
186
193
  FirmaUtil_1.FirmaUtil.printLog(error_6);
187
194
  throw error_6;
188
- case 3: return [2 /*return*/];
195
+ case 4: return [2 /*return*/];
189
196
  }
190
197
  });
191
198
  });
192
199
  };
193
- FirmaStakingService.prototype.getSignedTxEditValidator = function (wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc) {
200
+ FirmaStakingService.prototype.getSignedTxCreateValidator = function (wallet, validatorInfo, txMisc) {
194
201
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
195
202
  return __awaiter(this, void 0, void 0, function () {
196
203
  var txClient, message, error_7;
@@ -198,12 +205,17 @@ var FirmaStakingService = /** @class */ (function () {
198
205
  switch (_a.label) {
199
206
  case 0:
200
207
  _a.trys.push([0, 2, , 3]);
201
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
202
- message = txClient.msgEditValidator({
203
- validatorAddress: validatorAddress, description: description,
204
- commissionRate: commissionRate, minSelfDelegation: minSelfDelegation
208
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
209
+ message = txClient.msgCreateValidator({
210
+ description: validatorInfo.description,
211
+ commission: validatorInfo.commission,
212
+ minSelfDelegation: validatorInfo.minSelfDelegation,
213
+ delegatorAddress: validatorInfo.delegatorAddress,
214
+ validatorAddress: validatorInfo.validatorAddress,
215
+ pubkey: validatorInfo.pubkey,
216
+ value: validatorInfo.value
205
217
  });
206
- return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this._config.denom, txMisc))];
218
+ return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
207
219
  case 1: return [2 /*return*/, _a.sent()];
208
220
  case 2:
209
221
  error_7 = _a.sent();
@@ -214,30 +226,33 @@ var FirmaStakingService = /** @class */ (function () {
214
226
  });
215
227
  });
216
228
  };
217
- FirmaStakingService.prototype.createValidator = function (wallet, validatorInfo, txMisc) {
229
+ FirmaStakingService.prototype.getSignedTxEditValidator = function (wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc) {
218
230
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
219
231
  return __awaiter(this, void 0, void 0, function () {
220
- var txRaw, txClient, error_8;
232
+ var txClient, message, error_8;
221
233
  return __generator(this, function (_a) {
222
234
  switch (_a.label) {
223
235
  case 0:
224
- _a.trys.push([0, 3, , 4]);
225
- return [4 /*yield*/, this.getSignedTxCreateValidator(wallet, validatorInfo, txMisc)];
226
- case 1:
227
- txRaw = _a.sent();
228
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
229
- return [4 /*yield*/, txClient.broadcast(txRaw)];
230
- case 2: return [2 /*return*/, _a.sent()];
231
- case 3:
236
+ _a.trys.push([0, 2, , 3]);
237
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
238
+ message = txClient.msgEditValidator({
239
+ validatorAddress: validatorAddress,
240
+ description: description,
241
+ commissionRate: commissionRate,
242
+ minSelfDelegation: minSelfDelegation
243
+ });
244
+ return [4 /*yield*/, txClient.sign([message], staking_1.getSignAndBroadcastOption(this.config.denom, txMisc))];
245
+ case 1: return [2 /*return*/, _a.sent()];
246
+ case 2:
232
247
  error_8 = _a.sent();
233
248
  FirmaUtil_1.FirmaUtil.printLog(error_8);
234
249
  throw error_8;
235
- case 4: return [2 /*return*/];
250
+ case 3: return [2 /*return*/];
236
251
  }
237
252
  });
238
253
  });
239
254
  };
240
- FirmaStakingService.prototype.editValidator = function (wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc) {
255
+ FirmaStakingService.prototype.createValidator = function (wallet, validatorInfo, txMisc) {
241
256
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
242
257
  return __awaiter(this, void 0, void 0, function () {
243
258
  var txRaw, txClient, error_9;
@@ -245,10 +260,10 @@ var FirmaStakingService = /** @class */ (function () {
245
260
  switch (_a.label) {
246
261
  case 0:
247
262
  _a.trys.push([0, 3, , 4]);
248
- return [4 /*yield*/, this.getSignedTxEditValidator(wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc)];
263
+ return [4 /*yield*/, this.getSignedTxCreateValidator(wallet, validatorInfo, txMisc)];
249
264
  case 1:
250
265
  txRaw = _a.sent();
251
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
266
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
252
267
  return [4 /*yield*/, txClient.broadcast(txRaw)];
253
268
  case 2: return [2 /*return*/, _a.sent()];
254
269
  case 3:
@@ -260,7 +275,7 @@ var FirmaStakingService = /** @class */ (function () {
260
275
  });
261
276
  });
262
277
  };
263
- FirmaStakingService.prototype.redelegate = function (wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc) {
278
+ FirmaStakingService.prototype.editValidator = function (wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc) {
264
279
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
265
280
  return __awaiter(this, void 0, void 0, function () {
266
281
  var txRaw, txClient, error_10;
@@ -268,10 +283,10 @@ var FirmaStakingService = /** @class */ (function () {
268
283
  switch (_a.label) {
269
284
  case 0:
270
285
  _a.trys.push([0, 3, , 4]);
271
- return [4 /*yield*/, this.getSignedTxRedelegate(wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc)];
286
+ return [4 /*yield*/, this.getSignedTxEditValidator(wallet, validatorAddress, description, commissionRate, minSelfDelegation, txMisc)];
272
287
  case 1:
273
288
  txRaw = _a.sent();
274
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
289
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
275
290
  return [4 /*yield*/, txClient.broadcast(txRaw)];
276
291
  case 2: return [2 /*return*/, _a.sent()];
277
292
  case 3:
@@ -283,7 +298,7 @@ var FirmaStakingService = /** @class */ (function () {
283
298
  });
284
299
  });
285
300
  };
286
- FirmaStakingService.prototype.undelegate = function (wallet, targetAddress, amount, txMisc) {
301
+ FirmaStakingService.prototype.redelegate = function (wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc) {
287
302
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
288
303
  return __awaiter(this, void 0, void 0, function () {
289
304
  var txRaw, txClient, error_11;
@@ -291,10 +306,10 @@ var FirmaStakingService = /** @class */ (function () {
291
306
  switch (_a.label) {
292
307
  case 0:
293
308
  _a.trys.push([0, 3, , 4]);
294
- return [4 /*yield*/, this.getSignedTxUndelegate(wallet, targetAddress, amount, txMisc)];
309
+ return [4 /*yield*/, this.getSignedTxRedelegate(wallet, validatorSrcAddress, validatorDstAddress, amount, txMisc)];
295
310
  case 1:
296
311
  txRaw = _a.sent();
297
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
312
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
298
313
  return [4 /*yield*/, txClient.broadcast(txRaw)];
299
314
  case 2: return [2 /*return*/, _a.sent()];
300
315
  case 3:
@@ -306,7 +321,7 @@ var FirmaStakingService = /** @class */ (function () {
306
321
  });
307
322
  });
308
323
  };
309
- FirmaStakingService.prototype.delegate = function (wallet, targetAddress, amount, txMisc) {
324
+ FirmaStakingService.prototype.undelegate = function (wallet, targetAddress, amount, txMisc) {
310
325
  if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
311
326
  return __awaiter(this, void 0, void 0, function () {
312
327
  var txRaw, txClient, error_12;
@@ -314,10 +329,10 @@ var FirmaStakingService = /** @class */ (function () {
314
329
  switch (_a.label) {
315
330
  case 0:
316
331
  _a.trys.push([0, 3, , 4]);
317
- return [4 /*yield*/, this.getSignedTxDelegate(wallet, targetAddress, amount, txMisc)];
332
+ return [4 /*yield*/, this.getSignedTxUndelegate(wallet, targetAddress, amount, txMisc)];
318
333
  case 1:
319
334
  txRaw = _a.sent();
320
- txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this._config.rpcAddress);
335
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
321
336
  return [4 /*yield*/, txClient.broadcast(txRaw)];
322
337
  case 2: return [2 /*return*/, _a.sent()];
323
338
  case 3:
@@ -329,37 +344,39 @@ var FirmaStakingService = /** @class */ (function () {
329
344
  });
330
345
  });
331
346
  };
332
- // query
333
- FirmaStakingService.prototype.getTotalUndelegateInfo = function (address) {
347
+ FirmaStakingService.prototype.delegate = function (wallet, targetAddress, amount, txMisc) {
348
+ if (txMisc === void 0) { txMisc = staking_1.DefaultTxMisc; }
334
349
  return __awaiter(this, void 0, void 0, function () {
335
- var queryClient, result, error_13;
350
+ var txRaw, txClient, error_13;
336
351
  return __generator(this, function (_a) {
337
352
  switch (_a.label) {
338
353
  case 0:
339
- _a.trys.push([0, 2, , 3]);
340
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
341
- return [4 /*yield*/, queryClient.queryGetTotalUndelegateInfo(address)];
354
+ _a.trys.push([0, 3, , 4]);
355
+ return [4 /*yield*/, this.getSignedTxDelegate(wallet, targetAddress, amount, txMisc)];
342
356
  case 1:
343
- result = _a.sent();
344
- return [2 /*return*/, result];
345
- case 2:
357
+ txRaw = _a.sent();
358
+ txClient = new staking_1.StakingTxClient(wallet.getRawWallet(), this.config.rpcAddress);
359
+ return [4 /*yield*/, txClient.broadcast(txRaw)];
360
+ case 2: return [2 /*return*/, _a.sent()];
361
+ case 3:
346
362
  error_13 = _a.sent();
347
363
  FirmaUtil_1.FirmaUtil.printLog(error_13);
348
364
  throw error_13;
349
- case 3: return [2 /*return*/];
365
+ case 4: return [2 /*return*/];
350
366
  }
351
367
  });
352
368
  });
353
369
  };
354
- FirmaStakingService.prototype.getTotalRedelegationInfo = function (address) {
370
+ // query
371
+ FirmaStakingService.prototype.getUndelegationInfoFromValidator = function (address, validatorAddress) {
355
372
  return __awaiter(this, void 0, void 0, function () {
356
373
  var queryClient, result, error_14;
357
374
  return __generator(this, function (_a) {
358
375
  switch (_a.label) {
359
376
  case 0:
360
377
  _a.trys.push([0, 2, , 3]);
361
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
362
- return [4 /*yield*/, queryClient.querygetTotalRedelegationInfo(address)];
378
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
379
+ return [4 /*yield*/, queryClient.queryGetUndelegationInfoFromValidator(address, validatorAddress)];
363
380
  case 1:
364
381
  result = _a.sent();
365
382
  return [2 /*return*/, result];
@@ -372,15 +389,15 @@ var FirmaStakingService = /** @class */ (function () {
372
389
  });
373
390
  });
374
391
  };
375
- FirmaStakingService.prototype.getUndelegationListFromValidator = function (valoperAddress) {
392
+ FirmaStakingService.prototype.getDelegationInfoFromValidator = function (address, validatorAddress) {
376
393
  return __awaiter(this, void 0, void 0, function () {
377
394
  var queryClient, result, error_15;
378
395
  return __generator(this, function (_a) {
379
396
  switch (_a.label) {
380
397
  case 0:
381
398
  _a.trys.push([0, 2, , 3]);
382
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
383
- return [4 /*yield*/, queryClient.queryGetUndelegationListFromValidator(valoperAddress)];
399
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
400
+ return [4 /*yield*/, queryClient.queryGetDelegationInfoFromValidator(address, validatorAddress)];
384
401
  case 1:
385
402
  result = _a.sent();
386
403
  return [2 /*return*/, result];
@@ -393,15 +410,15 @@ var FirmaStakingService = /** @class */ (function () {
393
410
  });
394
411
  });
395
412
  };
396
- FirmaStakingService.prototype.getDelegationListFromValidator = function (valoperAddress) {
413
+ FirmaStakingService.prototype.getTotalUndelegateInfo = function (address) {
397
414
  return __awaiter(this, void 0, void 0, function () {
398
415
  var queryClient, result, error_16;
399
416
  return __generator(this, function (_a) {
400
417
  switch (_a.label) {
401
418
  case 0:
402
419
  _a.trys.push([0, 2, , 3]);
403
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
404
- return [4 /*yield*/, queryClient.queryGetDelegateListFromValidator(valoperAddress)];
420
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
421
+ return [4 /*yield*/, queryClient.queryGetTotalUndelegateInfo(address)];
405
422
  case 1:
406
423
  result = _a.sent();
407
424
  return [2 /*return*/, result];
@@ -414,15 +431,15 @@ var FirmaStakingService = /** @class */ (function () {
414
431
  });
415
432
  });
416
433
  };
417
- FirmaStakingService.prototype.getTotalDelegationInfo = function (address) {
434
+ FirmaStakingService.prototype.getTotalRedelegationInfo = function (address) {
418
435
  return __awaiter(this, void 0, void 0, function () {
419
436
  var queryClient, result, error_17;
420
437
  return __generator(this, function (_a) {
421
438
  switch (_a.label) {
422
439
  case 0:
423
440
  _a.trys.push([0, 2, , 3]);
424
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
425
- return [4 /*yield*/, queryClient.queryGetTotalDelegationInfo(address)];
441
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
442
+ return [4 /*yield*/, queryClient.querygetTotalRedelegationInfo(address)];
426
443
  case 1:
427
444
  result = _a.sent();
428
445
  return [2 /*return*/, result];
@@ -435,15 +452,15 @@ var FirmaStakingService = /** @class */ (function () {
435
452
  });
436
453
  });
437
454
  };
438
- FirmaStakingService.prototype.getParams = function () {
455
+ FirmaStakingService.prototype.getUndelegationListFromValidator = function (valoperAddress) {
439
456
  return __awaiter(this, void 0, void 0, function () {
440
457
  var queryClient, result, error_18;
441
458
  return __generator(this, function (_a) {
442
459
  switch (_a.label) {
443
460
  case 0:
444
461
  _a.trys.push([0, 2, , 3]);
445
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
446
- return [4 /*yield*/, queryClient.queryGetParams()];
462
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
463
+ return [4 /*yield*/, queryClient.queryGetUndelegationListFromValidator(valoperAddress)];
447
464
  case 1:
448
465
  result = _a.sent();
449
466
  return [2 /*return*/, result];
@@ -456,15 +473,15 @@ var FirmaStakingService = /** @class */ (function () {
456
473
  });
457
474
  });
458
475
  };
459
- FirmaStakingService.prototype.getPool = function () {
476
+ FirmaStakingService.prototype.getDelegationListFromValidator = function (valoperAddress) {
460
477
  return __awaiter(this, void 0, void 0, function () {
461
478
  var queryClient, result, error_19;
462
479
  return __generator(this, function (_a) {
463
480
  switch (_a.label) {
464
481
  case 0:
465
482
  _a.trys.push([0, 2, , 3]);
466
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
467
- return [4 /*yield*/, queryClient.queryGetPool()];
483
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
484
+ return [4 /*yield*/, queryClient.queryGetDelegateListFromValidator(valoperAddress)];
468
485
  case 1:
469
486
  result = _a.sent();
470
487
  return [2 /*return*/, result];
@@ -477,15 +494,15 @@ var FirmaStakingService = /** @class */ (function () {
477
494
  });
478
495
  });
479
496
  };
480
- FirmaStakingService.prototype.getValidator = function (valoperAddress) {
497
+ FirmaStakingService.prototype.getTotalDelegationInfo = function (address) {
481
498
  return __awaiter(this, void 0, void 0, function () {
482
499
  var queryClient, result, error_20;
483
500
  return __generator(this, function (_a) {
484
501
  switch (_a.label) {
485
502
  case 0:
486
503
  _a.trys.push([0, 2, , 3]);
487
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
488
- return [4 /*yield*/, queryClient.queryValidator(valoperAddress)];
504
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
505
+ return [4 /*yield*/, queryClient.queryGetTotalDelegationInfo(address)];
489
506
  case 1:
490
507
  result = _a.sent();
491
508
  return [2 /*return*/, result];
@@ -498,15 +515,15 @@ var FirmaStakingService = /** @class */ (function () {
498
515
  });
499
516
  });
500
517
  };
501
- FirmaStakingService.prototype.getValidatorList = function () {
518
+ FirmaStakingService.prototype.getParams = function () {
502
519
  return __awaiter(this, void 0, void 0, function () {
503
520
  var queryClient, result, error_21;
504
521
  return __generator(this, function (_a) {
505
522
  switch (_a.label) {
506
523
  case 0:
507
524
  _a.trys.push([0, 2, , 3]);
508
- queryClient = new staking_1.StakingQueryClient(this._config.restApiAddress);
509
- return [4 /*yield*/, queryClient.queryValidators()];
525
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
526
+ return [4 /*yield*/, queryClient.queryGetParams()];
510
527
  case 1:
511
528
  result = _a.sent();
512
529
  return [2 /*return*/, result];
@@ -519,6 +536,69 @@ var FirmaStakingService = /** @class */ (function () {
519
536
  });
520
537
  });
521
538
  };
539
+ FirmaStakingService.prototype.getPool = function () {
540
+ return __awaiter(this, void 0, void 0, function () {
541
+ var queryClient, result, error_22;
542
+ return __generator(this, function (_a) {
543
+ switch (_a.label) {
544
+ case 0:
545
+ _a.trys.push([0, 2, , 3]);
546
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
547
+ return [4 /*yield*/, queryClient.queryGetPool()];
548
+ case 1:
549
+ result = _a.sent();
550
+ return [2 /*return*/, result];
551
+ case 2:
552
+ error_22 = _a.sent();
553
+ FirmaUtil_1.FirmaUtil.printLog(error_22);
554
+ throw error_22;
555
+ case 3: return [2 /*return*/];
556
+ }
557
+ });
558
+ });
559
+ };
560
+ FirmaStakingService.prototype.getValidator = function (valoperAddress) {
561
+ return __awaiter(this, void 0, void 0, function () {
562
+ var queryClient, result, error_23;
563
+ return __generator(this, function (_a) {
564
+ switch (_a.label) {
565
+ case 0:
566
+ _a.trys.push([0, 2, , 3]);
567
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
568
+ return [4 /*yield*/, queryClient.queryValidator(valoperAddress)];
569
+ case 1:
570
+ result = _a.sent();
571
+ return [2 /*return*/, result];
572
+ case 2:
573
+ error_23 = _a.sent();
574
+ FirmaUtil_1.FirmaUtil.printLog(error_23);
575
+ throw error_23;
576
+ case 3: return [2 /*return*/];
577
+ }
578
+ });
579
+ });
580
+ };
581
+ FirmaStakingService.prototype.getValidatorList = function () {
582
+ return __awaiter(this, void 0, void 0, function () {
583
+ var queryClient, result, error_24;
584
+ return __generator(this, function (_a) {
585
+ switch (_a.label) {
586
+ case 0:
587
+ _a.trys.push([0, 2, , 3]);
588
+ queryClient = new staking_1.StakingQueryClient(this.config.restApiAddress);
589
+ return [4 /*yield*/, queryClient.queryValidators()];
590
+ case 1:
591
+ result = _a.sent();
592
+ return [2 /*return*/, result];
593
+ case 2:
594
+ error_24 = _a.sent();
595
+ FirmaUtil_1.FirmaUtil.printLog(error_24);
596
+ throw error_24;
597
+ case 3: return [2 /*return*/];
598
+ }
599
+ });
600
+ });
601
+ };
522
602
  return FirmaStakingService;
523
603
  }());
524
604
  exports.FirmaStakingService = FirmaStakingService;
@@ -1,7 +1,8 @@
1
- import { TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
1
+ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
2
2
  import { FirmaConfig } from "./FirmaConfig";
3
3
  export declare class FirmaUtil {
4
- static Config: FirmaConfig;
4
+ static config: FirmaConfig;
5
+ constructor(firmaConfig: FirmaConfig);
5
6
  static getUFCTStringFromFCTStr(fctAmount: string): string;
6
7
  static getFCTStringFromUFCTStr(uFctAmount: string): string;
7
8
  static getUFCTStringFromFCT(fctAmount: number): string;
@@ -40,12 +40,13 @@ exports.FirmaUtil = void 0;
40
40
  var fs_1 = require("fs");
41
41
  var tx_1 = require("cosmjs-types/cosmos/tx/v1beta1/tx");
42
42
  var TendermintQueryClient_1 = require("./firmachain/common/TendermintQueryClient");
43
- var CryptoJS = require('crypto-js');
44
- var sha256 = require('crypto-js/sha256');
45
- var encHex = require('crypto-js/enc-hex');
43
+ var CryptoJS = require("crypto-js");
44
+ var sha256 = require("crypto-js/sha256");
45
+ var encHex = require("crypto-js/enc-hex");
46
46
  var encoding_1 = require("@cosmjs/encoding");
47
47
  var FirmaUtil = /** @class */ (function () {
48
- function FirmaUtil() {
48
+ function FirmaUtil(firmaConfig) {
49
+ FirmaUtil.config = firmaConfig;
49
50
  }
50
51
  FirmaUtil.getUFCTStringFromFCTStr = function (fctAmount) {
51
52
  var fct = Number.parseFloat(fctAmount);
@@ -80,24 +81,28 @@ var FirmaUtil = /** @class */ (function () {
80
81
  };
81
82
  FirmaUtil.getValOperAddressFromAccAddress = function (address) {
82
83
  var data = encoding_1.Bech32.decode(address).data;
83
- return encoding_1.Bech32.encode(FirmaUtil.Config.prefix + "valoper", data);
84
+ return encoding_1.Bech32.encode(FirmaUtil.config.prefix + "valoper", data);
84
85
  };
85
86
  FirmaUtil.getAccAddressFromValOperAddress = function (address) {
86
87
  var data = encoding_1.Bech32.decode(address).data;
87
- return encoding_1.Bech32.encode(FirmaUtil.Config.prefix, data);
88
+ return encoding_1.Bech32.encode(FirmaUtil.config.prefix, data);
88
89
  };
89
90
  FirmaUtil.estimateGas = function (txRaw) {
90
91
  return __awaiter(this, void 0, void 0, function () {
91
- var encodedTx, hexTx, queryClient, error_1;
92
+ var encodedTx, hexTx, queryClient, gas, multiplier, targetGas, error_1;
92
93
  return __generator(this, function (_a) {
93
94
  switch (_a.label) {
94
95
  case 0:
95
96
  _a.trys.push([0, 2, , 3]);
96
97
  encodedTx = Uint8Array.from(tx_1.TxRaw.encode(txRaw).finish());
97
- hexTx = "0x" + Buffer.from(encodedTx).toString('hex');
98
- queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.Config.rpcAddress);
98
+ hexTx = "0x" + Buffer.from(encodedTx).toString("hex");
99
+ queryClient = new TendermintQueryClient_1.TendermintQueryClient(FirmaUtil.config.rpcAddress);
99
100
  return [4 /*yield*/, queryClient.queryEstimateGas(hexTx)];
100
- case 1: return [2 /*return*/, _a.sent()];
101
+ case 1:
102
+ gas = _a.sent();
103
+ multiplier = 1.25;
104
+ targetGas = Math.ceil(gas * multiplier);
105
+ return [2 /*return*/, Math.ceil(targetGas * 0.01)]; // 3.2 -> 4
101
106
  case 2:
102
107
  error_1 = _a.sent();
103
108
  FirmaUtil.printLog(error_1);
@@ -108,7 +113,7 @@ var FirmaUtil = /** @class */ (function () {
108
113
  });
109
114
  };
110
115
  FirmaUtil.printLog = function (log) {
111
- if (FirmaUtil.Config.isShowLog == false)
116
+ if (FirmaUtil.config.isShowLog === false)
112
117
  return;
113
118
  console.log("[FirmaSDK] " + log);
114
119
  };