injectivejs 1.9.13 → 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.
- package/cosmos/base/v1beta1/coin.js +5 -4
- package/cosmos/distribution/v1beta1/distribution.js +11 -10
- package/cosmos/gov/v1beta1/gov.js +3 -2
- package/cosmos/staking/v1beta1/staking.js +15 -14
- package/cosmos/staking/v1beta1/tx.js +3 -2
- package/decimals.d.ts +20 -0
- package/decimals.js +102 -0
- package/esm/cosmos/base/v1beta1/coin.js +5 -4
- package/esm/cosmos/distribution/v1beta1/distribution.js +11 -10
- package/esm/cosmos/gov/v1beta1/gov.js +3 -2
- package/esm/cosmos/staking/v1beta1/staking.js +15 -14
- package/esm/cosmos/staking/v1beta1/tx.js +3 -2
- package/esm/decimals.js +98 -0
- package/esm/injective/auction/v1beta1/auction.js +3 -2
- package/esm/injective/exchange/v1beta1/events.js +13 -12
- package/esm/injective/exchange/v1beta1/exchange.js +183 -182
- package/esm/injective/exchange/v1beta1/genesis.js +5 -4
- package/esm/injective/exchange/v1beta1/proposal.js +99 -98
- package/esm/injective/exchange/v1beta1/query.js +89 -88
- package/esm/injective/exchange/v1beta1/tx.js +81 -80
- package/esm/injective/ocr/v1beta1/ocr.js +17 -16
- package/esm/injective/oracle/v1beta1/events.js +13 -12
- package/esm/injective/oracle/v1beta1/oracle.js +31 -30
- package/esm/injective/oracle/v1beta1/query.js +13 -12
- package/esm/injective/oracle/v1beta1/tx.js +5 -4
- package/esm/injective/stream/v1beta1/query.js +21 -20
- package/injective/auction/v1beta1/auction.js +3 -2
- package/injective/exchange/v1beta1/events.js +13 -12
- package/injective/exchange/v1beta1/exchange.js +183 -182
- package/injective/exchange/v1beta1/genesis.js +5 -4
- package/injective/exchange/v1beta1/proposal.js +99 -98
- package/injective/exchange/v1beta1/query.js +89 -88
- package/injective/exchange/v1beta1/tx.js +81 -80
- package/injective/ocr/v1beta1/ocr.js +17 -16
- package/injective/oracle/v1beta1/events.js +13 -12
- package/injective/oracle/v1beta1/oracle.js +31 -30
- package/injective/oracle/v1beta1/query.js +13 -12
- package/injective/oracle/v1beta1/tx.js +5 -4
- package/injective/stream/v1beta1/query.js +21 -20
- package/package.json +8 -8
|
@@ -6,6 +6,7 @@ import { BinaryReader, BinaryWriter } from "../../../binary";
|
|
|
6
6
|
import { GlobalDecoderRegistry } from "../../../registry";
|
|
7
7
|
import { toTimestamp, fromTimestamp } from "../../../helpers";
|
|
8
8
|
import { encodePubkey, decodePubkey } from "@interchainjs/pubkey";
|
|
9
|
+
import { Decimal } from "../../../decimals";
|
|
9
10
|
function createBaseMsgCreateValidator() {
|
|
10
11
|
return {
|
|
11
12
|
description: Description.fromPartial({}),
|
|
@@ -246,7 +247,7 @@ export const MsgEditValidator = {
|
|
|
246
247
|
writer.uint32(18).string(message.validatorAddress);
|
|
247
248
|
}
|
|
248
249
|
if (message.commissionRate !== "") {
|
|
249
|
-
writer.uint32(26).string(message.commissionRate);
|
|
250
|
+
writer.uint32(26).string(Decimal.fromUserInput(message.commissionRate, 18).atomics);
|
|
250
251
|
}
|
|
251
252
|
if (message.minSelfDelegation !== "") {
|
|
252
253
|
writer.uint32(34).string(message.minSelfDelegation);
|
|
@@ -267,7 +268,7 @@ export const MsgEditValidator = {
|
|
|
267
268
|
message.validatorAddress = reader.string();
|
|
268
269
|
break;
|
|
269
270
|
case 3:
|
|
270
|
-
message.commissionRate = reader.string();
|
|
271
|
+
message.commissionRate = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
271
272
|
break;
|
|
272
273
|
case 4:
|
|
273
274
|
message.minSelfDelegation = reader.string();
|
package/esm/decimals.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
// The largest value we need is 18 (Ether).
|
|
7
|
+
const maxFractionalDigits = 30;
|
|
8
|
+
/**
|
|
9
|
+
* A type for arbitrary precision, non-negative decimals.
|
|
10
|
+
*
|
|
11
|
+
* Instances of this class are immutable.
|
|
12
|
+
*/
|
|
13
|
+
export class Decimal {
|
|
14
|
+
static fromUserInput(input, fractionalDigits) {
|
|
15
|
+
Decimal.verifyFractionalDigits(fractionalDigits);
|
|
16
|
+
const badCharacter = input.match(/[^0-9.]/);
|
|
17
|
+
if (badCharacter) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
+
throw new Error(`Invalid character at position ${badCharacter.index + 1}`);
|
|
20
|
+
}
|
|
21
|
+
let whole;
|
|
22
|
+
let fractional;
|
|
23
|
+
if (input === "") {
|
|
24
|
+
whole = "0";
|
|
25
|
+
fractional = "";
|
|
26
|
+
}
|
|
27
|
+
else if (input.search(/\./) === -1) {
|
|
28
|
+
// integer format, no separator
|
|
29
|
+
whole = input;
|
|
30
|
+
fractional = "";
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const parts = input.split(".");
|
|
34
|
+
switch (parts.length) {
|
|
35
|
+
case 0:
|
|
36
|
+
case 1:
|
|
37
|
+
throw new Error("Fewer than two elements in split result. This must not happen here.");
|
|
38
|
+
case 2:
|
|
39
|
+
if (!parts[1])
|
|
40
|
+
throw new Error("Fractional part missing");
|
|
41
|
+
whole = parts[0];
|
|
42
|
+
fractional = parts[1].replace(/0+$/, "");
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
throw new Error("More than one separator found");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (fractional.length > fractionalDigits) {
|
|
49
|
+
throw new Error("Got more fractional digits than supported");
|
|
50
|
+
}
|
|
51
|
+
const quantity = `${whole}${fractional.padEnd(fractionalDigits, "0")}`;
|
|
52
|
+
return new Decimal(quantity, fractionalDigits);
|
|
53
|
+
}
|
|
54
|
+
static fromAtomics(atomics, fractionalDigits) {
|
|
55
|
+
Decimal.verifyFractionalDigits(fractionalDigits);
|
|
56
|
+
return new Decimal(atomics, fractionalDigits);
|
|
57
|
+
}
|
|
58
|
+
static verifyFractionalDigits(fractionalDigits) {
|
|
59
|
+
if (!Number.isInteger(fractionalDigits))
|
|
60
|
+
throw new Error("Fractional digits is not an integer");
|
|
61
|
+
if (fractionalDigits < 0)
|
|
62
|
+
throw new Error("Fractional digits must not be negative");
|
|
63
|
+
if (fractionalDigits > maxFractionalDigits) {
|
|
64
|
+
throw new Error(`Fractional digits must not exceed ${maxFractionalDigits}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
get atomics() {
|
|
68
|
+
return this.data.atomics.toString();
|
|
69
|
+
}
|
|
70
|
+
get fractionalDigits() {
|
|
71
|
+
return this.data.fractionalDigits;
|
|
72
|
+
}
|
|
73
|
+
data;
|
|
74
|
+
constructor(atomics, fractionalDigits) {
|
|
75
|
+
if (!atomics.match(/^[0-9]+$/)) {
|
|
76
|
+
throw new Error("Invalid string format. Only non-negative integers in decimal representation supported.");
|
|
77
|
+
}
|
|
78
|
+
this.data = {
|
|
79
|
+
atomics: BigInt(atomics),
|
|
80
|
+
fractionalDigits: fractionalDigits,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
toString() {
|
|
84
|
+
const factor = BigInt(10) ** BigInt(this.data.fractionalDigits);
|
|
85
|
+
const whole = this.data.atomics / factor;
|
|
86
|
+
const fractional = this.data.atomics % factor;
|
|
87
|
+
if (fractional === 0n) {
|
|
88
|
+
return whole.toString();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const fullFractionalPart = fractional
|
|
92
|
+
.toString()
|
|
93
|
+
.padStart(this.data.fractionalDigits, "0");
|
|
94
|
+
const trimmedFractionalPart = fullFractionalPart.replace(/0+$/, "");
|
|
95
|
+
return `${whole.toString()}.${trimmedFractionalPart}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Coin } from "../../../cosmos/base/v1beta1/coin";
|
|
2
2
|
import { BinaryReader, BinaryWriter } from "../../../binary";
|
|
3
|
+
import { Decimal } from "../../../decimals";
|
|
3
4
|
function createBaseParams() {
|
|
4
5
|
return {
|
|
5
6
|
auctionPeriod: BigInt(0),
|
|
@@ -20,7 +21,7 @@ export const Params = {
|
|
|
20
21
|
writer.uint32(8).int64(message.auctionPeriod);
|
|
21
22
|
}
|
|
22
23
|
if (message.minNextBidIncrementRate !== "") {
|
|
23
|
-
writer.uint32(18).string(message.minNextBidIncrementRate);
|
|
24
|
+
writer.uint32(18).string(Decimal.fromUserInput(message.minNextBidIncrementRate, 18).atomics);
|
|
24
25
|
}
|
|
25
26
|
return writer;
|
|
26
27
|
},
|
|
@@ -35,7 +36,7 @@ export const Params = {
|
|
|
35
36
|
message.auctionPeriod = reader.int64();
|
|
36
37
|
break;
|
|
37
38
|
case 2:
|
|
38
|
-
message.minNextBidIncrementRate = reader.string();
|
|
39
|
+
message.minNextBidIncrementRate = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
39
40
|
break;
|
|
40
41
|
default:
|
|
41
42
|
reader.skipType(tag & 7);
|
|
@@ -2,6 +2,7 @@ import { TradeLog, DerivativeTradeLog, SubaccountPosition, BinaryOptionsMarket,
|
|
|
2
2
|
import { Coin } from "../../../cosmos/base/v1beta1/coin";
|
|
3
3
|
import { isSet, bytesFromBase64, base64FromBytes } from "../../../helpers";
|
|
4
4
|
import { BinaryReader, BinaryWriter } from "../../../binary";
|
|
5
|
+
import { Decimal } from "../../../decimals";
|
|
5
6
|
function createBaseEventBatchSpotExecution() {
|
|
6
7
|
return {
|
|
7
8
|
marketId: "",
|
|
@@ -142,7 +143,7 @@ export const EventBatchDerivativeExecution = {
|
|
|
142
143
|
writer.uint32(24).bool(message.isLiquidation);
|
|
143
144
|
}
|
|
144
145
|
if (message.cumulativeFunding !== undefined) {
|
|
145
|
-
writer.uint32(34).string(message.cumulativeFunding);
|
|
146
|
+
writer.uint32(34).string(Decimal.fromUserInput(message.cumulativeFunding, 18).atomics);
|
|
146
147
|
}
|
|
147
148
|
if (message.executionType !== 0) {
|
|
148
149
|
writer.uint32(40).int32(message.executionType);
|
|
@@ -169,7 +170,7 @@ export const EventBatchDerivativeExecution = {
|
|
|
169
170
|
message.isLiquidation = reader.bool();
|
|
170
171
|
break;
|
|
171
172
|
case 4:
|
|
172
|
-
message.cumulativeFunding = reader.string();
|
|
173
|
+
message.cumulativeFunding = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
173
174
|
break;
|
|
174
175
|
case 5:
|
|
175
176
|
message.executionType = reader.int32();
|
|
@@ -272,10 +273,10 @@ export const EventLostFundsFromLiquidation = {
|
|
|
272
273
|
writer.uint32(18).bytes(message.subaccountId);
|
|
273
274
|
}
|
|
274
275
|
if (message.lostFundsFromAvailableDuringPayout !== "") {
|
|
275
|
-
writer.uint32(26).string(message.lostFundsFromAvailableDuringPayout);
|
|
276
|
+
writer.uint32(26).string(Decimal.fromUserInput(message.lostFundsFromAvailableDuringPayout, 18).atomics);
|
|
276
277
|
}
|
|
277
278
|
if (message.lostFundsFromOrderCancels !== "") {
|
|
278
|
-
writer.uint32(34).string(message.lostFundsFromOrderCancels);
|
|
279
|
+
writer.uint32(34).string(Decimal.fromUserInput(message.lostFundsFromOrderCancels, 18).atomics);
|
|
279
280
|
}
|
|
280
281
|
return writer;
|
|
281
282
|
},
|
|
@@ -293,10 +294,10 @@ export const EventLostFundsFromLiquidation = {
|
|
|
293
294
|
message.subaccountId = reader.bytes();
|
|
294
295
|
break;
|
|
295
296
|
case 3:
|
|
296
|
-
message.lostFundsFromAvailableDuringPayout = reader.string();
|
|
297
|
+
message.lostFundsFromAvailableDuringPayout = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
297
298
|
break;
|
|
298
299
|
case 4:
|
|
299
|
-
message.lostFundsFromOrderCancels = reader.string();
|
|
300
|
+
message.lostFundsFromOrderCancels = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
300
301
|
break;
|
|
301
302
|
default:
|
|
302
303
|
reader.skipType(tag & 7);
|
|
@@ -1378,10 +1379,10 @@ export const EventPerpetualMarketFundingUpdate = {
|
|
|
1378
1379
|
writer.uint32(24).bool(message.isHourlyFunding);
|
|
1379
1380
|
}
|
|
1380
1381
|
if (message.fundingRate !== undefined) {
|
|
1381
|
-
writer.uint32(34).string(message.fundingRate);
|
|
1382
|
+
writer.uint32(34).string(Decimal.fromUserInput(message.fundingRate, 18).atomics);
|
|
1382
1383
|
}
|
|
1383
1384
|
if (message.markPrice !== undefined) {
|
|
1384
|
-
writer.uint32(42).string(message.markPrice);
|
|
1385
|
+
writer.uint32(42).string(Decimal.fromUserInput(message.markPrice, 18).atomics);
|
|
1385
1386
|
}
|
|
1386
1387
|
return writer;
|
|
1387
1388
|
},
|
|
@@ -1402,10 +1403,10 @@ export const EventPerpetualMarketFundingUpdate = {
|
|
|
1402
1403
|
message.isHourlyFunding = reader.bool();
|
|
1403
1404
|
break;
|
|
1404
1405
|
case 4:
|
|
1405
|
-
message.fundingRate = reader.string();
|
|
1406
|
+
message.fundingRate = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
1406
1407
|
break;
|
|
1407
1408
|
case 5:
|
|
1408
|
-
message.markPrice = reader.string();
|
|
1409
|
+
message.markPrice = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
1409
1410
|
break;
|
|
1410
1411
|
default:
|
|
1411
1412
|
reader.skipType(tag & 7);
|
|
@@ -1852,7 +1853,7 @@ export const DerivativeMarketOrderCancel = {
|
|
|
1852
1853
|
DerivativeMarketOrder.encode(message.marketOrder, writer.uint32(10).fork()).ldelim();
|
|
1853
1854
|
}
|
|
1854
1855
|
if (message.cancelQuantity !== "") {
|
|
1855
|
-
writer.uint32(18).string(message.cancelQuantity);
|
|
1856
|
+
writer.uint32(18).string(Decimal.fromUserInput(message.cancelQuantity, 18).atomics);
|
|
1856
1857
|
}
|
|
1857
1858
|
return writer;
|
|
1858
1859
|
},
|
|
@@ -1867,7 +1868,7 @@ export const DerivativeMarketOrderCancel = {
|
|
|
1867
1868
|
message.marketOrder = DerivativeMarketOrder.decode(reader, reader.uint32());
|
|
1868
1869
|
break;
|
|
1869
1870
|
case 2:
|
|
1870
|
-
message.cancelQuantity = reader.string();
|
|
1871
|
+
message.cancelQuantity = Decimal.fromAtomics(reader.string(), 18).toString();
|
|
1871
1872
|
break;
|
|
1872
1873
|
default:
|
|
1873
1874
|
reader.skipType(tag & 7);
|