injectivejs 1.9.12 → 1.9.14

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 (41) hide show
  1. package/README.md +26 -22
  2. package/cosmos/base/v1beta1/coin.js +5 -4
  3. package/cosmos/distribution/v1beta1/distribution.js +11 -10
  4. package/cosmos/gov/v1beta1/gov.js +3 -2
  5. package/cosmos/staking/v1beta1/staking.js +15 -14
  6. package/cosmos/staking/v1beta1/tx.js +3 -2
  7. package/decimals.d.ts +20 -0
  8. package/decimals.js +102 -0
  9. package/esm/cosmos/base/v1beta1/coin.js +5 -4
  10. package/esm/cosmos/distribution/v1beta1/distribution.js +11 -10
  11. package/esm/cosmos/gov/v1beta1/gov.js +3 -2
  12. package/esm/cosmos/staking/v1beta1/staking.js +15 -14
  13. package/esm/cosmos/staking/v1beta1/tx.js +3 -2
  14. package/esm/decimals.js +98 -0
  15. package/esm/injective/auction/v1beta1/auction.js +3 -2
  16. package/esm/injective/exchange/v1beta1/events.js +13 -12
  17. package/esm/injective/exchange/v1beta1/exchange.js +183 -182
  18. package/esm/injective/exchange/v1beta1/genesis.js +5 -4
  19. package/esm/injective/exchange/v1beta1/proposal.js +99 -98
  20. package/esm/injective/exchange/v1beta1/query.js +89 -88
  21. package/esm/injective/exchange/v1beta1/tx.js +81 -80
  22. package/esm/injective/ocr/v1beta1/ocr.js +17 -16
  23. package/esm/injective/oracle/v1beta1/events.js +13 -12
  24. package/esm/injective/oracle/v1beta1/oracle.js +31 -30
  25. package/esm/injective/oracle/v1beta1/query.js +13 -12
  26. package/esm/injective/oracle/v1beta1/tx.js +5 -4
  27. package/esm/injective/stream/v1beta1/query.js +21 -20
  28. package/injective/auction/v1beta1/auction.js +3 -2
  29. package/injective/exchange/v1beta1/events.js +13 -12
  30. package/injective/exchange/v1beta1/exchange.js +183 -182
  31. package/injective/exchange/v1beta1/genesis.js +5 -4
  32. package/injective/exchange/v1beta1/proposal.js +99 -98
  33. package/injective/exchange/v1beta1/query.js +89 -88
  34. package/injective/exchange/v1beta1/tx.js +81 -80
  35. package/injective/ocr/v1beta1/ocr.js +17 -16
  36. package/injective/oracle/v1beta1/events.js +13 -12
  37. package/injective/oracle/v1beta1/oracle.js +31 -30
  38. package/injective/oracle/v1beta1/query.js +13 -12
  39. package/injective/oracle/v1beta1/tx.js +5 -4
  40. package/injective/stream/v1beta1/query.js +21 -20
  41. package/package.json +8 -8
package/README.md CHANGED
@@ -46,7 +46,7 @@ npm install injectivejs
46
46
  - [IBC Messages](#ibc-messages)
47
47
  - [Cosmos Messages](#cosmos-messages)
48
48
  - [Connecting with Wallets and Signing Messages](#connecting-with-wallets-and-signing-messages)
49
- - [Initializing the Stargate Client](#initializing-the-stargate-client)
49
+ - [Initializing the Signing Client](#initializing-the-signing-client)
50
50
  - [Creating Signers](#creating-signers)
51
51
  - [Broadcasting Messages](#broadcasting-messages)
52
52
  - [All In One Example](#all-in-one-example)
@@ -448,16 +448,20 @@ const { deposit, submitProposal, vote, voteWeighted } =
448
448
 
449
449
  Here are the docs on [creating signers](https://github.com/hyperweb-io/interchain-kit/blob/main/packages/core/README.md) in interchain-kit that can be used with Keplr and other wallets.
450
450
 
451
- ### Initializing the Stargate Client
451
+ ### Initializing the Signing Client
452
452
 
453
- Use `getSigningInjectiveClient` to get your `SigningStargateClient`, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client:
453
+ Use SigningClient.connectWithSigner and pass in the signer options for injective to get your `SigningClient`:
454
454
 
455
455
  ```js
456
- import { InjSigningClient } from "@interchainjs/injective/signing-client";
456
+ import { SigningClient } from "@interchainjs/cosmos/signing-client";
457
+ import { defaultSignerOptions } from "@interchainjs/injective/defaults";
457
458
 
458
- signingClient = await InjSigningClient.connectWithSigner(
459
+ const signingClient = await SigningClient.connectWithSigner(
459
460
  await getRpcEndpoint(),
460
- new AminoGenericOfflineSigner(aminoOfflineSigner)
461
+ new AminoGenericOfflineSigner(aminoOfflineSigner),
462
+ {
463
+ signerOptions: defaultSignerOptions.Cosmos,
464
+ }
461
465
  );
462
466
  ```
463
467
 
@@ -497,12 +501,12 @@ const fee: StdFee = {
497
501
  ],
498
502
  gas: "86364",
499
503
  };
500
- const response = await stargateClient.signAndBroadcast(address, [msg], fee);
504
+ const response = await signingClient.signAndBroadcast(address, [msg], fee);
501
505
  ```
502
506
 
503
507
  ### All In One Example
504
508
 
505
- For a comprehensive example of how to use InjectiveJS to send messages, please see the example [here](https://github.com/hyperweb-io/create-cosmos-app/blob/main/examples/injective/components/SendMsg.tsx). This example demonstrates how to:
509
+ For a comprehensive example of how to use InjectiveJS to send messages, please see the example [here](https://github.com/hyperweb-io/create-interchain-app/tree/main/examples/injective/components/SendMsg.tsx). This example demonstrates how to:
506
510
 
507
511
  - Initialize the client.
508
512
  - Create and sign messages.
@@ -511,11 +515,11 @@ For a comprehensive example of how to use InjectiveJS to send messages, please s
511
515
 
512
516
  The example provides a complete walkthrough of setting up the client, creating a message for sending tokens, and broadcasting the transaction to the Injective blockchain.
513
517
 
514
- Follow the [instructions](https://github.com/hyperweb-io/create-cosmos-app/tree/main/examples/injective) in the example to set up your InjectiveJS client and start sending messages to the Injective blockchain.
518
+ Follow the [instructions](https://github.com/hyperweb-io/create-interchain-app/tree/main/examples/injective) in the example to set up your InjectiveJS client and start sending messages to the Injective blockchain.
515
519
 
516
520
  ## Advanced Usage
517
521
 
518
- If you want to manually construct a stargate client
522
+ If you want to manually construct a signing client, you can do so by following the example below:
519
523
 
520
524
  ```js
521
525
  import {
@@ -549,7 +553,7 @@ const aminoConverters = {
549
553
  const registry = new Registry(protoRegistry);
550
554
  const aminoTypes = new AminoTypes(aminoConverters);
551
555
 
552
- const signingClient = await InjSigningClient.connectWithSigner(rpcEndpoint, signer);
556
+ const signingClient = await SigningClient.connectWithSigner(rpcEndpoint, signer);
553
557
 
554
558
  signingClient.addEncoders(registry);
555
559
  signingClient.addConverters(aminoTypes);
@@ -585,17 +589,17 @@ yarn publish
585
589
 
586
590
  A unified toolkit for building applications and smart contracts in the Interchain ecosystem
587
591
 
588
- | Category | Tools | Description |
589
- |----------------------|------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------|
590
- | **Chain Information** | [**Chain Registry**](https://github.com/hyperweb-io/chain-registry), [**Utils**](https://www.npmjs.com/package/@chain-registry/utils), [**Client**](https://www.npmjs.com/package/@chain-registry/client) | Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. |
591
- | **Wallet Connectors**| [**Interchain Kit**](https://github.com/hyperweb-io/interchain-kit)<sup>beta</sup>, [**Cosmos Kit**](https://github.com/hyperweb-io/cosmos-kit) | Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. |
592
- | **Signing Clients** | [**InterchainJS**](https://github.com/hyperweb-io/interchainjs)<sup>beta</sup>, [**CosmJS**](https://github.com/cosmos/cosmjs) | A single, universal signing interface for any network |
593
- | **SDK Clients** | [**Telescope**](https://github.com/hyperweb-io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
594
- | **Starter Kits** | [**Create Interchain App**](https://github.com/hyperweb-io/create-interchain-app)<sup>beta</sup>, [**Create Cosmos App**](https://github.com/hyperweb-io/create-cosmos-app) | Set up a modern Interchain app by running one command. |
595
- | **UI Kits** | [**Interchain UI**](https://github.com/hyperweb-io/interchain-ui) | The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. |
596
- | **Testing Frameworks** | [**Starship**](https://github.com/hyperweb-io/starship) | Unified Testing and Development for the Interchain. |
597
- | **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
598
- | **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/CosmWasm/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
592
+ | Category | Tools | Description |
593
+ | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
594
+ | **Chain Information** | [**Chain Registry**](https://github.com/hyperweb-io/chain-registry), [**Utils**](https://www.npmjs.com/package/@chain-registry/utils), [**Client**](https://www.npmjs.com/package/@chain-registry/client) | Everything from token symbols, logos, and IBC denominations for all assets you want to support in your application. |
595
+ | **Wallet Connectors** | [**Interchain Kit**](https://github.com/hyperweb-io/interchain-kit)<sup>beta</sup>, [**Cosmos Kit**](https://github.com/hyperweb-io/cosmos-kit) | Experience the convenience of connecting with a variety of web3 wallets through a single, streamlined interface. |
596
+ | **Signing Clients** | [**InterchainJS**](https://github.com/hyperweb-io/interchainjs)<sup>beta</sup>, [**CosmJS**](https://github.com/cosmos/cosmjs) | A single, universal signing interface for any network |
597
+ | **SDK Clients** | [**Telescope**](https://github.com/hyperweb-io/telescope) | Your Frontend Companion for Building with TypeScript with Cosmos SDK Modules. |
598
+ | **Starter Kits** | [**Create Interchain App**](https://github.com/hyperweb-io/create-interchain-app)<sup>beta</sup>, [**Create Cosmos App**](https://github.com/hyperweb-io/create-cosmos-app) | Set up a modern Interchain app by running one command. |
599
+ | **UI Kits** | [**Interchain UI**](https://github.com/hyperweb-io/interchain-ui) | The Interchain Design System, empowering developers with a flexible, easy-to-use UI kit. |
600
+ | **Testing Frameworks** | [**Starship**](https://github.com/hyperweb-io/starship) | Unified Testing and Development for the Interchain. |
601
+ | **TypeScript Smart Contracts** | [**Create Hyperweb App**](https://github.com/hyperweb-io/create-hyperweb-app) | Build and deploy full-stack blockchain applications with TypeScript |
602
+ | **CosmWasm Contracts** | [**CosmWasm TS Codegen**](https://github.com/CosmWasm/ts-codegen) | Convert your CosmWasm smart contracts into dev-friendly TypeScript classes. |
599
603
 
600
604
  ## Credits
601
605
 
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DecProto = exports.IntProto = exports.DecCoin = exports.Coin = void 0;
4
4
  const binary_1 = require("../../../binary");
5
+ const decimals_1 = require("../../../decimals");
5
6
  function createBaseCoin() {
6
7
  return {
7
8
  denom: "",
@@ -111,7 +112,7 @@ exports.DecCoin = {
111
112
  writer.uint32(10).string(message.denom);
112
113
  }
113
114
  if (message.amount !== "") {
114
- writer.uint32(18).string(message.amount);
115
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.amount, 18).atomics);
115
116
  }
116
117
  return writer;
117
118
  },
@@ -126,7 +127,7 @@ exports.DecCoin = {
126
127
  message.denom = reader.string();
127
128
  break;
128
129
  case 2:
129
- message.amount = reader.string();
130
+ message.amount = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
130
131
  break;
131
132
  default:
132
133
  reader.skipType(tag & 7);
@@ -273,7 +274,7 @@ exports.DecProto = {
273
274
  },
274
275
  encode(message, writer = binary_1.BinaryWriter.create()) {
275
276
  if (message.dec !== "") {
276
- writer.uint32(10).string(message.dec);
277
+ writer.uint32(10).string(decimals_1.Decimal.fromUserInput(message.dec, 18).atomics);
277
278
  }
278
279
  return writer;
279
280
  },
@@ -285,7 +286,7 @@ exports.DecProto = {
285
286
  const tag = reader.uint32();
286
287
  switch (tag >>> 3) {
287
288
  case 1:
288
- message.dec = reader.string();
289
+ message.dec = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
289
290
  break;
290
291
  default:
291
292
  reader.skipType(tag & 7);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommunityPoolSpendProposalWithDeposit = exports.DelegationDelegatorReward = exports.DelegatorStartingInfo = exports.CommunityPoolSpendProposal = exports.FeePool = exports.ValidatorSlashEvents = exports.ValidatorSlashEvent = exports.ValidatorOutstandingRewards = exports.ValidatorAccumulatedCommission = exports.ValidatorCurrentRewards = exports.ValidatorHistoricalRewards = exports.Params = void 0;
4
4
  const coin_1 = require("../../base/v1beta1/coin");
5
5
  const binary_1 = require("../../../binary");
6
+ const decimals_1 = require("../../../decimals");
6
7
  const registry_1 = require("../../../registry");
7
8
  function createBaseParams() {
8
9
  return {
@@ -23,13 +24,13 @@ exports.Params = {
23
24
  },
24
25
  encode(message, writer = binary_1.BinaryWriter.create()) {
25
26
  if (message.communityTax !== "") {
26
- writer.uint32(10).string(message.communityTax);
27
+ writer.uint32(10).string(decimals_1.Decimal.fromUserInput(message.communityTax, 18).atomics);
27
28
  }
28
29
  if (message.baseProposerReward !== "") {
29
- writer.uint32(18).string(message.baseProposerReward);
30
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.baseProposerReward, 18).atomics);
30
31
  }
31
32
  if (message.bonusProposerReward !== "") {
32
- writer.uint32(26).string(message.bonusProposerReward);
33
+ writer.uint32(26).string(decimals_1.Decimal.fromUserInput(message.bonusProposerReward, 18).atomics);
33
34
  }
34
35
  if (message.withdrawAddrEnabled === true) {
35
36
  writer.uint32(32).bool(message.withdrawAddrEnabled);
@@ -44,13 +45,13 @@ exports.Params = {
44
45
  const tag = reader.uint32();
45
46
  switch (tag >>> 3) {
46
47
  case 1:
47
- message.communityTax = reader.string();
48
+ message.communityTax = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
48
49
  break;
49
50
  case 2:
50
- message.baseProposerReward = reader.string();
51
+ message.baseProposerReward = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
51
52
  break;
52
53
  case 3:
53
- message.bonusProposerReward = reader.string();
54
+ message.bonusProposerReward = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
54
55
  break;
55
56
  case 4:
56
57
  message.withdrawAddrEnabled = reader.bool();
@@ -489,7 +490,7 @@ exports.ValidatorSlashEvent = {
489
490
  writer.uint32(8).uint64(message.validatorPeriod);
490
491
  }
491
492
  if (message.fraction !== "") {
492
- writer.uint32(18).string(message.fraction);
493
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.fraction, 18).atomics);
493
494
  }
494
495
  return writer;
495
496
  },
@@ -504,7 +505,7 @@ exports.ValidatorSlashEvent = {
504
505
  message.validatorPeriod = reader.uint64();
505
506
  break;
506
507
  case 2:
507
- message.fraction = reader.string();
508
+ message.fraction = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
508
509
  break;
509
510
  default:
510
511
  reader.skipType(tag & 7);
@@ -863,7 +864,7 @@ exports.DelegatorStartingInfo = {
863
864
  writer.uint32(8).uint64(message.previousPeriod);
864
865
  }
865
866
  if (message.stake !== "") {
866
- writer.uint32(18).string(message.stake);
867
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.stake, 18).atomics);
867
868
  }
868
869
  if (message.height !== BigInt(0)) {
869
870
  writer.uint32(24).uint64(message.height);
@@ -881,7 +882,7 @@ exports.DelegatorStartingInfo = {
881
882
  message.previousPeriod = reader.uint64();
882
883
  break;
883
884
  case 2:
884
- message.stake = reader.string();
885
+ message.stake = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
885
886
  break;
886
887
  case 3:
887
888
  message.height = reader.uint64();
@@ -19,6 +19,7 @@ const proposal_3 = require("../../../injective/peggy/v1/proposal");
19
19
  const proposal_4 = require("../../../injective/wasmx/v1/proposal");
20
20
  const helpers_1 = require("../../../helpers");
21
21
  const binary_1 = require("../../../binary");
22
+ const decimals_1 = require("../../../decimals");
22
23
  const registry_1 = require("../../../registry");
23
24
  /** VoteOption enumerates the valid vote options for a given governance proposal. */
24
25
  var VoteOption;
@@ -174,7 +175,7 @@ exports.WeightedVoteOption = {
174
175
  writer.uint32(8).int32(message.option);
175
176
  }
176
177
  if (message.weight !== "") {
177
- writer.uint32(18).string(message.weight);
178
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.weight, 18).atomics);
178
179
  }
179
180
  return writer;
180
181
  },
@@ -189,7 +190,7 @@ exports.WeightedVoteOption = {
189
190
  message.option = reader.int32();
190
191
  break;
191
192
  case 2:
192
- message.weight = reader.string();
193
+ message.weight = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
193
194
  break;
194
195
  default:
195
196
  reader.skipType(tag & 7);
@@ -14,6 +14,7 @@ const types_2 = require("../../../tendermint/abci/types");
14
14
  const binary_1 = require("../../../binary");
15
15
  const registry_1 = require("../../../registry");
16
16
  const helpers_1 = require("../../../helpers");
17
+ const decimals_1 = require("../../../decimals");
17
18
  const pubkey_1 = require("@interchainjs/pubkey");
18
19
  /** BondStatus is the status of a validator. */
19
20
  var BondStatus;
@@ -219,13 +220,13 @@ exports.CommissionRates = {
219
220
  },
220
221
  encode(message, writer = binary_1.BinaryWriter.create()) {
221
222
  if (message.rate !== "") {
222
- writer.uint32(10).string(message.rate);
223
+ writer.uint32(10).string(decimals_1.Decimal.fromUserInput(message.rate, 18).atomics);
223
224
  }
224
225
  if (message.maxRate !== "") {
225
- writer.uint32(18).string(message.maxRate);
226
+ writer.uint32(18).string(decimals_1.Decimal.fromUserInput(message.maxRate, 18).atomics);
226
227
  }
227
228
  if (message.maxChangeRate !== "") {
228
- writer.uint32(26).string(message.maxChangeRate);
229
+ writer.uint32(26).string(decimals_1.Decimal.fromUserInput(message.maxChangeRate, 18).atomics);
229
230
  }
230
231
  return writer;
231
232
  },
@@ -237,13 +238,13 @@ exports.CommissionRates = {
237
238
  const tag = reader.uint32();
238
239
  switch (tag >>> 3) {
239
240
  case 1:
240
- message.rate = reader.string();
241
+ message.rate = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
241
242
  break;
242
243
  case 2:
243
- message.maxRate = reader.string();
244
+ message.maxRate = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
244
245
  break;
245
246
  case 3:
246
- message.maxChangeRate = reader.string();
247
+ message.maxChangeRate = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
247
248
  break;
248
249
  default:
249
250
  reader.skipType(tag & 7);
@@ -561,7 +562,7 @@ exports.Validator = {
561
562
  writer.uint32(42).string(message.tokens);
562
563
  }
563
564
  if (message.delegatorShares !== "") {
564
- writer.uint32(50).string(message.delegatorShares);
565
+ writer.uint32(50).string(decimals_1.Decimal.fromUserInput(message.delegatorShares, 18).atomics);
565
566
  }
566
567
  if (message.description !== undefined) {
567
568
  exports.Description.encode(message.description, writer.uint32(58).fork()).ldelim();
@@ -611,7 +612,7 @@ exports.Validator = {
611
612
  message.tokens = reader.string();
612
613
  break;
613
614
  case 6:
614
- message.delegatorShares = reader.string();
615
+ message.delegatorShares = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
615
616
  break;
616
617
  case 7:
617
618
  message.description = exports.Description.decode(reader, reader.uint32());
@@ -1213,7 +1214,7 @@ exports.Delegation = {
1213
1214
  writer.uint32(18).string(message.validatorAddress);
1214
1215
  }
1215
1216
  if (message.shares !== "") {
1216
- writer.uint32(26).string(message.shares);
1217
+ writer.uint32(26).string(decimals_1.Decimal.fromUserInput(message.shares, 18).atomics);
1217
1218
  }
1218
1219
  return writer;
1219
1220
  },
@@ -1231,7 +1232,7 @@ exports.Delegation = {
1231
1232
  message.validatorAddress = reader.string();
1232
1233
  break;
1233
1234
  case 3:
1234
- message.shares = reader.string();
1235
+ message.shares = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
1235
1236
  break;
1236
1237
  default:
1237
1238
  reader.skipType(tag & 7);
@@ -1563,7 +1564,7 @@ exports.RedelegationEntry = {
1563
1564
  writer.uint32(26).string(message.initialBalance);
1564
1565
  }
1565
1566
  if (message.sharesDst !== "") {
1566
- writer.uint32(34).string(message.sharesDst);
1567
+ writer.uint32(34).string(decimals_1.Decimal.fromUserInput(message.sharesDst, 18).atomics);
1567
1568
  }
1568
1569
  if (message.unbondingId !== BigInt(0)) {
1569
1570
  writer.uint32(40).uint64(message.unbondingId);
@@ -1590,7 +1591,7 @@ exports.RedelegationEntry = {
1590
1591
  message.initialBalance = reader.string();
1591
1592
  break;
1592
1593
  case 4:
1593
- message.sharesDst = reader.string();
1594
+ message.sharesDst = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
1594
1595
  break;
1595
1596
  case 5:
1596
1597
  message.unbondingId = reader.uint64();
@@ -1824,7 +1825,7 @@ exports.Params = {
1824
1825
  writer.uint32(42).string(message.bondDenom);
1825
1826
  }
1826
1827
  if (message.minCommissionRate !== "") {
1827
- writer.uint32(50).string(message.minCommissionRate);
1828
+ writer.uint32(50).string(decimals_1.Decimal.fromUserInput(message.minCommissionRate, 18).atomics);
1828
1829
  }
1829
1830
  return writer;
1830
1831
  },
@@ -1851,7 +1852,7 @@ exports.Params = {
1851
1852
  message.bondDenom = reader.string();
1852
1853
  break;
1853
1854
  case 6:
1854
- message.minCommissionRate = reader.string();
1855
+ message.minCommissionRate = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
1855
1856
  break;
1856
1857
  default:
1857
1858
  reader.skipType(tag & 7);
@@ -9,6 +9,7 @@ const binary_1 = require("../../../binary");
9
9
  const registry_1 = require("../../../registry");
10
10
  const helpers_1 = require("../../../helpers");
11
11
  const pubkey_1 = require("@interchainjs/pubkey");
12
+ const decimals_1 = require("../../../decimals");
12
13
  function createBaseMsgCreateValidator() {
13
14
  return {
14
15
  description: staking_1.Description.fromPartial({}),
@@ -249,7 +250,7 @@ exports.MsgEditValidator = {
249
250
  writer.uint32(18).string(message.validatorAddress);
250
251
  }
251
252
  if (message.commissionRate !== "") {
252
- writer.uint32(26).string(message.commissionRate);
253
+ writer.uint32(26).string(decimals_1.Decimal.fromUserInput(message.commissionRate, 18).atomics);
253
254
  }
254
255
  if (message.minSelfDelegation !== "") {
255
256
  writer.uint32(34).string(message.minSelfDelegation);
@@ -270,7 +271,7 @@ exports.MsgEditValidator = {
270
271
  message.validatorAddress = reader.string();
271
272
  break;
272
273
  case 3:
273
- message.commissionRate = reader.string();
274
+ message.commissionRate = decimals_1.Decimal.fromAtomics(reader.string(), 18).toString();
274
275
  break;
275
276
  case 4:
276
277
  message.minSelfDelegation = reader.string();
package/decimals.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * This file and any referenced files were automatically generated by @cosmology/telescope@1.11.20
3
+ * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
4
+ * and run the transpile command or npm scripts command that is used to regenerate this bundle.
5
+ */
6
+ /**
7
+ * A type for arbitrary precision, non-negative decimals.
8
+ *
9
+ * Instances of this class are immutable.
10
+ */
11
+ export declare class Decimal {
12
+ static fromUserInput(input: string, fractionalDigits: number): Decimal;
13
+ static fromAtomics(atomics: string, fractionalDigits: number): Decimal;
14
+ private static verifyFractionalDigits;
15
+ get atomics(): string;
16
+ get fractionalDigits(): number;
17
+ private readonly data;
18
+ private constructor();
19
+ toString(): string;
20
+ }
package/decimals.js ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * This file and any referenced files were automatically generated by @cosmology/telescope@1.11.20
4
+ * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
5
+ * and run the transpile command or npm scripts command that is used to regenerate this bundle.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Decimal = void 0;
9
+ // The largest value we need is 18 (Ether).
10
+ const maxFractionalDigits = 30;
11
+ /**
12
+ * A type for arbitrary precision, non-negative decimals.
13
+ *
14
+ * Instances of this class are immutable.
15
+ */
16
+ class Decimal {
17
+ static fromUserInput(input, fractionalDigits) {
18
+ Decimal.verifyFractionalDigits(fractionalDigits);
19
+ const badCharacter = input.match(/[^0-9.]/);
20
+ if (badCharacter) {
21
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+ throw new Error(`Invalid character at position ${badCharacter.index + 1}`);
23
+ }
24
+ let whole;
25
+ let fractional;
26
+ if (input === "") {
27
+ whole = "0";
28
+ fractional = "";
29
+ }
30
+ else if (input.search(/\./) === -1) {
31
+ // integer format, no separator
32
+ whole = input;
33
+ fractional = "";
34
+ }
35
+ else {
36
+ const parts = input.split(".");
37
+ switch (parts.length) {
38
+ case 0:
39
+ case 1:
40
+ throw new Error("Fewer than two elements in split result. This must not happen here.");
41
+ case 2:
42
+ if (!parts[1])
43
+ throw new Error("Fractional part missing");
44
+ whole = parts[0];
45
+ fractional = parts[1].replace(/0+$/, "");
46
+ break;
47
+ default:
48
+ throw new Error("More than one separator found");
49
+ }
50
+ }
51
+ if (fractional.length > fractionalDigits) {
52
+ throw new Error("Got more fractional digits than supported");
53
+ }
54
+ const quantity = `${whole}${fractional.padEnd(fractionalDigits, "0")}`;
55
+ return new Decimal(quantity, fractionalDigits);
56
+ }
57
+ static fromAtomics(atomics, fractionalDigits) {
58
+ Decimal.verifyFractionalDigits(fractionalDigits);
59
+ return new Decimal(atomics, fractionalDigits);
60
+ }
61
+ static verifyFractionalDigits(fractionalDigits) {
62
+ if (!Number.isInteger(fractionalDigits))
63
+ throw new Error("Fractional digits is not an integer");
64
+ if (fractionalDigits < 0)
65
+ throw new Error("Fractional digits must not be negative");
66
+ if (fractionalDigits > maxFractionalDigits) {
67
+ throw new Error(`Fractional digits must not exceed ${maxFractionalDigits}`);
68
+ }
69
+ }
70
+ get atomics() {
71
+ return this.data.atomics.toString();
72
+ }
73
+ get fractionalDigits() {
74
+ return this.data.fractionalDigits;
75
+ }
76
+ data;
77
+ constructor(atomics, fractionalDigits) {
78
+ if (!atomics.match(/^[0-9]+$/)) {
79
+ throw new Error("Invalid string format. Only non-negative integers in decimal representation supported.");
80
+ }
81
+ this.data = {
82
+ atomics: BigInt(atomics),
83
+ fractionalDigits: fractionalDigits,
84
+ };
85
+ }
86
+ toString() {
87
+ const factor = BigInt(10) ** BigInt(this.data.fractionalDigits);
88
+ const whole = this.data.atomics / factor;
89
+ const fractional = this.data.atomics % factor;
90
+ if (fractional === 0n) {
91
+ return whole.toString();
92
+ }
93
+ else {
94
+ const fullFractionalPart = fractional
95
+ .toString()
96
+ .padStart(this.data.fractionalDigits, "0");
97
+ const trimmedFractionalPart = fullFractionalPart.replace(/0+$/, "");
98
+ return `${whole.toString()}.${trimmedFractionalPart}`;
99
+ }
100
+ }
101
+ }
102
+ exports.Decimal = Decimal;
@@ -1,4 +1,5 @@
1
1
  import { BinaryReader, BinaryWriter } from "../../../binary";
2
+ import { Decimal } from "../../../decimals";
2
3
  function createBaseCoin() {
3
4
  return {
4
5
  denom: "",
@@ -108,7 +109,7 @@ export const DecCoin = {
108
109
  writer.uint32(10).string(message.denom);
109
110
  }
110
111
  if (message.amount !== "") {
111
- writer.uint32(18).string(message.amount);
112
+ writer.uint32(18).string(Decimal.fromUserInput(message.amount, 18).atomics);
112
113
  }
113
114
  return writer;
114
115
  },
@@ -123,7 +124,7 @@ export const DecCoin = {
123
124
  message.denom = reader.string();
124
125
  break;
125
126
  case 2:
126
- message.amount = reader.string();
127
+ message.amount = Decimal.fromAtomics(reader.string(), 18).toString();
127
128
  break;
128
129
  default:
129
130
  reader.skipType(tag & 7);
@@ -270,7 +271,7 @@ export const DecProto = {
270
271
  },
271
272
  encode(message, writer = BinaryWriter.create()) {
272
273
  if (message.dec !== "") {
273
- writer.uint32(10).string(message.dec);
274
+ writer.uint32(10).string(Decimal.fromUserInput(message.dec, 18).atomics);
274
275
  }
275
276
  return writer;
276
277
  },
@@ -282,7 +283,7 @@ export const DecProto = {
282
283
  const tag = reader.uint32();
283
284
  switch (tag >>> 3) {
284
285
  case 1:
285
- message.dec = reader.string();
286
+ message.dec = Decimal.fromAtomics(reader.string(), 18).toString();
286
287
  break;
287
288
  default:
288
289
  reader.skipType(tag & 7);
@@ -1,5 +1,6 @@
1
1
  import { DecCoin, Coin } from "../../base/v1beta1/coin";
2
2
  import { BinaryReader, BinaryWriter } from "../../../binary";
3
+ import { Decimal } from "../../../decimals";
3
4
  import { GlobalDecoderRegistry } from "../../../registry";
4
5
  function createBaseParams() {
5
6
  return {
@@ -20,13 +21,13 @@ export const Params = {
20
21
  },
21
22
  encode(message, writer = BinaryWriter.create()) {
22
23
  if (message.communityTax !== "") {
23
- writer.uint32(10).string(message.communityTax);
24
+ writer.uint32(10).string(Decimal.fromUserInput(message.communityTax, 18).atomics);
24
25
  }
25
26
  if (message.baseProposerReward !== "") {
26
- writer.uint32(18).string(message.baseProposerReward);
27
+ writer.uint32(18).string(Decimal.fromUserInput(message.baseProposerReward, 18).atomics);
27
28
  }
28
29
  if (message.bonusProposerReward !== "") {
29
- writer.uint32(26).string(message.bonusProposerReward);
30
+ writer.uint32(26).string(Decimal.fromUserInput(message.bonusProposerReward, 18).atomics);
30
31
  }
31
32
  if (message.withdrawAddrEnabled === true) {
32
33
  writer.uint32(32).bool(message.withdrawAddrEnabled);
@@ -41,13 +42,13 @@ export const Params = {
41
42
  const tag = reader.uint32();
42
43
  switch (tag >>> 3) {
43
44
  case 1:
44
- message.communityTax = reader.string();
45
+ message.communityTax = Decimal.fromAtomics(reader.string(), 18).toString();
45
46
  break;
46
47
  case 2:
47
- message.baseProposerReward = reader.string();
48
+ message.baseProposerReward = Decimal.fromAtomics(reader.string(), 18).toString();
48
49
  break;
49
50
  case 3:
50
- message.bonusProposerReward = reader.string();
51
+ message.bonusProposerReward = Decimal.fromAtomics(reader.string(), 18).toString();
51
52
  break;
52
53
  case 4:
53
54
  message.withdrawAddrEnabled = reader.bool();
@@ -486,7 +487,7 @@ export const ValidatorSlashEvent = {
486
487
  writer.uint32(8).uint64(message.validatorPeriod);
487
488
  }
488
489
  if (message.fraction !== "") {
489
- writer.uint32(18).string(message.fraction);
490
+ writer.uint32(18).string(Decimal.fromUserInput(message.fraction, 18).atomics);
490
491
  }
491
492
  return writer;
492
493
  },
@@ -501,7 +502,7 @@ export const ValidatorSlashEvent = {
501
502
  message.validatorPeriod = reader.uint64();
502
503
  break;
503
504
  case 2:
504
- message.fraction = reader.string();
505
+ message.fraction = Decimal.fromAtomics(reader.string(), 18).toString();
505
506
  break;
506
507
  default:
507
508
  reader.skipType(tag & 7);
@@ -860,7 +861,7 @@ export const DelegatorStartingInfo = {
860
861
  writer.uint32(8).uint64(message.previousPeriod);
861
862
  }
862
863
  if (message.stake !== "") {
863
- writer.uint32(18).string(message.stake);
864
+ writer.uint32(18).string(Decimal.fromUserInput(message.stake, 18).atomics);
864
865
  }
865
866
  if (message.height !== BigInt(0)) {
866
867
  writer.uint32(24).uint64(message.height);
@@ -878,7 +879,7 @@ export const DelegatorStartingInfo = {
878
879
  message.previousPeriod = reader.uint64();
879
880
  break;
880
881
  case 2:
881
- message.stake = reader.string();
882
+ message.stake = Decimal.fromAtomics(reader.string(), 18).toString();
882
883
  break;
883
884
  case 3:
884
885
  message.height = reader.uint64();