From 81549c876c3f485ca046225bca3dd28df0137945 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Thu, 12 Sep 2024 09:46:43 -0700 Subject: [PATCH] fix: encoding Decimal values --- packages/cosmic-proto/package.json | 2 +- packages/cosmic-proto/src/codegen/binary.ts | 14 +- .../src/codegen/google/protobuf/descriptor.ts | 9 +- packages/cosmic-proto/src/codegen/helpers.ts | 72 +- packages/cosmic-proto/src/codegen/index.ts | 2 +- .../cosmic-proto/src/codegen/json-safe.ts | 14 +- .../src/codegen/tendermint/abci/types.ts | 7 +- .../src/codegen/tendermint/types/types.ts | 2 + packages/cosmic-proto/src/codegen/utf8.ts | 2 +- packages/cosmic-proto/src/codegen/varint.ts | 6 +- patches/@cosmology+telescope+1.7.1.patch | 1005 ----------------- yarn.lock | 95 +- 12 files changed, 138 insertions(+), 1092 deletions(-) delete mode 100644 patches/@cosmology+telescope+1.7.1.patch diff --git a/packages/cosmic-proto/package.json b/packages/cosmic-proto/package.json index 9b7f465c62c..1b82434a185 100644 --- a/packages/cosmic-proto/package.json +++ b/packages/cosmic-proto/package.json @@ -144,7 +144,7 @@ "devDependencies": { "@agoric/cosmos": "^0.34.1", "@ava/typescript": "^4.1.0", - "@cosmology/telescope": "^1.7.1", + "@cosmology/telescope": "https://gitpkg.vercel.app/agoric-labs/telescope/packages/telescope?8d2c2f6ba637a5578eead09a7368dc41c262a9d0", "@endo/bundle-source": "^3.4.0", "@endo/import-bundle": "^1.2.2", "ava": "^5.3.1", diff --git a/packages/cosmic-proto/src/codegen/binary.ts b/packages/cosmic-proto/src/codegen/binary.ts index 33c34900cf4..22d542844d2 100644 --- a/packages/cosmic-proto/src/codegen/binary.ts +++ b/packages/cosmic-proto/src/codegen/binary.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ @@ -100,7 +100,7 @@ export class BinaryReader implements IBinaryReader { len: number; assertBounds(): void { - if (this.pos > this.len) throw RangeError('premature EOF'); + if (this.pos > this.len) throw new RangeError('premature EOF'); } constructor(buf?: ArrayLike) { @@ -115,7 +115,7 @@ export class BinaryReader implements IBinaryReader { fieldNo = tag >>> 3, wireType = tag & 7; if (fieldNo <= 0 || wireType < 0 || wireType > 5) - throw Error( + throw new Error( 'illegal tag: field no ' + fieldNo + ' wire type ' + wireType, ); return [fieldNo, wireType, tag]; @@ -214,11 +214,11 @@ export class BinaryReader implements IBinaryReader { } float(): number { - throw Error('float not supported'); + throw new Error('float not supported'); } double(): number { - throw Error('double not supported'); + throw new Error('double not supported'); } bool(): boolean { @@ -466,11 +466,11 @@ export class BinaryWriter implements IBinaryWriter { sfixed32 = BinaryWriter.prototype.fixed32; float(value: number): BinaryWriter { - throw Error('float not supported' + value); + throw new Error('float not supported' + value); } double(value: number): BinaryWriter { - throw Error('double not supported' + value); + throw new Error('double not supported' + value); } bytes(value: Uint8Array): BinaryWriter { diff --git a/packages/cosmic-proto/src/codegen/google/protobuf/descriptor.ts b/packages/cosmic-proto/src/codegen/google/protobuf/descriptor.ts index 3ec3b438f39..a381d00927f 100644 --- a/packages/cosmic-proto/src/codegen/google/protobuf/descriptor.ts +++ b/packages/cosmic-proto/src/codegen/google/protobuf/descriptor.ts @@ -31,6 +31,7 @@ export enum FieldDescriptorProto_Type { * treat group fields as unknown fields. */ TYPE_GROUP = 10, + /** TYPE_MESSAGE - Length-delimited aggregate. */ TYPE_MESSAGE = 11, /** TYPE_BYTES - New in version 2. */ TYPE_BYTES = 12, @@ -198,12 +199,9 @@ export function fieldDescriptorProto_LabelToJSON( } /** Generated classes can be optimized for speed or code size. */ export enum FileOptions_OptimizeMode { - /** - * SPEED - Generate complete code for parsing, serialization, - * etc. - */ + /** SPEED - Generate complete code for parsing, serialization, */ SPEED = 1, - /** CODE_SIZE - Use ReflectionOps to implement these methods. */ + /** CODE_SIZE - etc. */ CODE_SIZE = 2, /** LITE_RUNTIME - Generate code using MessageLite and the lite runtime. */ LITE_RUNTIME = 3, @@ -393,6 +391,7 @@ export interface FileDescriptorSetSDKType { export interface FileDescriptorProto { /** file name, relative to root of source tree */ name: string; + /** e.g. "foo", "foo.bar", etc. */ package: string; /** Names of files imported by this file. */ dependency: string[]; diff --git a/packages/cosmic-proto/src/codegen/helpers.ts b/packages/cosmic-proto/src/codegen/helpers.ts index a5547f7a637..e9674426df1 100644 --- a/packages/cosmic-proto/src/codegen/helpers.ts +++ b/packages/cosmic-proto/src/codegen/helpers.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ @@ -35,7 +35,7 @@ export function omitDefault( return input === BigInt(0) ? undefined : input; } - throw Error(`Got unsupported type ${typeof input}`); + throw new Error(`Got unsupported type ${typeof input}`); } interface Duration { @@ -223,9 +223,10 @@ function numberToLong(number: number) { return BigInt(Math.trunc(number)); } +// START agoric-sdk patch // The largest value we need is 18 (Ether). const maxFractionalDigits = 30; -// Subset of Decimal in @cosmjs/math + /** * A type for arbitrary precision, non-negative decimals. * @@ -241,7 +242,9 @@ export class Decimal { const badCharacter = input.match(/[^0-9.]/); if (badCharacter) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - throw Error(`Invalid character at position ${badCharacter.index! + 1}`); + throw new Error( + `Invalid character at position ${badCharacter.index! + 1}`, + ); } let whole: string; @@ -250,7 +253,7 @@ export class Decimal { if (input === '') { whole = '0'; fractional = ''; - } else if (input.search(/./) === -1) { + } else if (input.search(/\./) === -1) { // integer format, no separator whole = input; fractional = ''; @@ -259,21 +262,21 @@ export class Decimal { switch (parts.length) { case 0: case 1: - throw Error( + throw new Error( 'Fewer than two elements in split result. This must not happen here.', ); case 2: - if (!parts[1]) throw Error('Fractional part missing'); + if (!parts[1]) throw new Error('Fractional part missing'); whole = parts[0]; fractional = parts[1].replace(/0+$/, ''); break; default: - throw Error('More than one separator found'); + throw new Error('More than one separator found'); } } if (fractional.length > fractionalDigits) { - throw Error('Got more fractional digits than supported'); + throw new Error('Got more fractional digits than supported'); } const quantity = `${whole}${fractional.padEnd(fractionalDigits, '0')}`; @@ -291,11 +294,56 @@ export class Decimal { private static verifyFractionalDigits(fractionalDigits: number): void { if (!Number.isInteger(fractionalDigits)) - throw Error('Fractional digits is not an integer'); + throw new Error('Fractional digits is not an integer'); if (fractionalDigits < 0) - throw Error('Fractional digits must not be negative'); + throw new Error('Fractional digits must not be negative'); if (fractionalDigits > maxFractionalDigits) { - throw Error(`Fractional digits must not exceed ${maxFractionalDigits}`); + throw new Error( + `Fractional digits must not exceed ${maxFractionalDigits}`, + ); + } + } + + public get atomics(): string { + return this.data.atomics.toString(); + } + + public get fractionalDigits(): number { + return this.data.fractionalDigits; + } + + private readonly data: { + readonly atomics: bigint; + readonly fractionalDigits: number; + }; + + private constructor(atomics: string, fractionalDigits: number) { + if (!atomics.match(/^[0-9]+$/)) { + throw new Error( + 'Invalid string format. Only non-negative integers in decimal representation supported.', + ); + } + + this.data = { + atomics: BigInt(atomics), + fractionalDigits: fractionalDigits, + }; + } + + public toString(): string { + const factor = BigInt(10) ** BigInt(this.data.fractionalDigits); + const whole = this.data.atomics / factor; + const fractional = this.data.atomics % factor; + + if (fractional === 0n) { + return whole.toString(); + } else { + const fullFractionalPart = fractional + .toString() + .padStart(this.data.fractionalDigits, '0'); + const trimmedFractionalPart = fullFractionalPart.replace(/0+$/, ''); + return `${whole.toString()}.${trimmedFractionalPart}`; } } } +// END agoric-sdk patch diff --git a/packages/cosmic-proto/src/codegen/index.ts b/packages/cosmic-proto/src/codegen/index.ts index 80dd20e32b1..e6e4d93d04b 100644 --- a/packages/cosmic-proto/src/codegen/index.ts +++ b/packages/cosmic-proto/src/codegen/index.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/json-safe.ts b/packages/cosmic-proto/src/codegen/json-safe.ts index a026dbef565..b35e037fe21 100644 --- a/packages/cosmic-proto/src/codegen/json-safe.ts +++ b/packages/cosmic-proto/src/codegen/json-safe.ts @@ -1,12 +1,14 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ -export type JsonSafe = { - [Prop in keyof T]: T[Prop] extends Uint8Array | bigint | Date - ? string - : T[Prop]; -}; +export type JsonSafe = T extends Uint8Array | bigint | Date + ? string + : T extends Array + ? Array> + : T extends object + ? { [K in keyof T]: JsonSafe } + : T; diff --git a/packages/cosmic-proto/src/codegen/tendermint/abci/types.ts b/packages/cosmic-proto/src/codegen/tendermint/abci/types.ts index 913c9ee017f..8d1fd3f6eb9 100644 --- a/packages/cosmic-proto/src/codegen/tendermint/abci/types.ts +++ b/packages/cosmic-proto/src/codegen/tendermint/abci/types.ts @@ -849,12 +849,9 @@ export interface TxResultSDKType { } /** Validator */ export interface Validator { - /** - * The first 20 bytes of SHA256(public key) - * PubKey pub_key = 2 [(gogoproto.nullable)=false]; - */ + /** The first 20 bytes of SHA256(public key) */ address: Uint8Array; - /** The voting power */ + /** PubKey pub_key = 2 [(gogoproto.nullable)=false]; */ power: bigint; } export interface ValidatorProtoMsg { diff --git a/packages/cosmic-proto/src/codegen/tendermint/types/types.ts b/packages/cosmic-proto/src/codegen/tendermint/types/types.ts index 52eba4662ac..e34af751bbc 100644 --- a/packages/cosmic-proto/src/codegen/tendermint/types/types.ts +++ b/packages/cosmic-proto/src/codegen/tendermint/types/types.ts @@ -158,6 +158,7 @@ export interface Header { lastBlockId: BlockID; /** hashes of block data */ lastCommitHash: Uint8Array; + /** transactions */ dataHash: Uint8Array; /** hashes from the app output from the prev block */ validatorsHash: Uint8Array; @@ -167,6 +168,7 @@ export interface Header { consensusHash: Uint8Array; /** state after txs from the previous block */ appHash: Uint8Array; + /** root hash of all results from the txs from the previous block */ lastResultsHash: Uint8Array; /** consensus info */ evidenceHash: Uint8Array; diff --git a/packages/cosmic-proto/src/codegen/utf8.ts b/packages/cosmic-proto/src/codegen/utf8.ts index f2d864a1976..d0412e27b6c 100644 --- a/packages/cosmic-proto/src/codegen/utf8.ts +++ b/packages/cosmic-proto/src/codegen/utf8.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/varint.ts b/packages/cosmic-proto/src/codegen/varint.ts index 4e82d8337ef..dd800ff82d9 100644 --- a/packages/cosmic-proto/src/codegen/varint.ts +++ b/packages/cosmic-proto/src/codegen/varint.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.8.3 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ @@ -86,7 +86,7 @@ export function varint64read(this: ReaderLike): [number, number] { } } - throw Error('invalid varint'); + throw new Error('invalid varint'); } /** @@ -353,7 +353,7 @@ export function varint32read(this: ReaderLike): number { for (let readBytes = 5; (b & 0x80) !== 0 && readBytes < 10; readBytes++) b = this.buf[this.pos++]; - if ((b & 0x80) != 0) throw Error('invalid varint'); + if ((b & 0x80) != 0) throw new Error('invalid varint'); this.assertBounds(); diff --git a/patches/@cosmology+telescope+1.7.1.patch b/patches/@cosmology+telescope+1.7.1.patch deleted file mode 100644 index dcc4a034512..00000000000 --- a/patches/@cosmology+telescope+1.7.1.patch +++ /dev/null @@ -1,1005 +0,0 @@ -diff --git a/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js b/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js -index 950827a..9e9214c 100644 ---- a/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js -+++ b/node_modules/@cosmology/telescope/main/helpers/internal-for-bigint.js -@@ -5,41 +5,11 @@ const getHelperForBigint = (options) => { - return `${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `import { Dec } from "@keplr-wallet/unit"; - - ` : ""} --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || -- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -- --const btoa: (bin: string) => string = -- globalThis.btoa || -- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -252,6 +222,88 @@ export function fromJsonTimestamp(o: any): Timestamp { - function numberToLong(number: number) { - return BigInt(Math.trunc(number)); - } -+ -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ - ${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? - ` - export function padDecimal(decStr: string): string{ -diff --git a/node_modules/@cosmology/telescope/main/helpers/internal.js b/node_modules/@cosmology/telescope/main/helpers/internal.js -index b27664f..5cf4c6a 100644 ---- a/node_modules/@cosmology/telescope/main/helpers/internal.js -+++ b/node_modules/@cosmology/telescope/main/helpers/internal.js -@@ -5,6 +5,8 @@ const getHelper = (options) => { - return `import * as _m0 from "protobufjs/minimal"; - import Long from 'long';${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` - import { Dec } from "@keplr-wallet/unit"; -+import { encodeBase64, decodeBase64 } from '@endo/base64'; -+ - ` : ""} - - // @ts-ignore -@@ -16,39 +18,9 @@ if (_m0.util.Long !== Long) { - - export { Long }; - --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -- --const btoa: (bin: string) => string = -- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -236,7 +208,91 @@ export function fromJsonTimestamp(o: any): Timestamp { - - function numberToLong(number: number) { - return Long.fromNumber(number); --}${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` -+} -+ -+ -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ -+${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` - - export function padDecimal(decStr: string): string{ - return decStr ? new Dec(decStr).toString() : decStr; -diff --git a/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js b/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js -index 07b6e47..87c78db 100644 ---- a/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js -+++ b/node_modules/@cosmology/telescope/main/helpers/internalForBigInt.js -@@ -2,41 +2,11 @@ - Object.defineProperty(exports, "__esModule", { value: true }); - exports.internalForBigInt = void 0; - exports.internalForBigInt = ` --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || -- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - --const btoa: (bin: string) => string = -- globalThis.btoa || -- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -diff --git a/node_modules/@cosmology/telescope/main/utils/index.js b/node_modules/@cosmology/telescope/main/utils/index.js -index 998db7f..3301179 100644 ---- a/node_modules/@cosmology/telescope/main/utils/index.js -+++ b/node_modules/@cosmology/telescope/main/utils/index.js -@@ -36,7 +36,7 @@ exports.UTILS = { - bytesFromBase64: '__helpers__', - BrowserHeaders: 'browser-headers', - connectComet: '@cosmjs/tendermint-rpc', -- Decimal: '@cosmjs/math', -+ Decimal: '__helpers__', - padDecimal: '__helpers__', - createProtobufRpcClient: '@cosmjs/stargate', - Pubkey: '@cosmjs/amino', -diff --git a/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js b/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js -index 1d19b1c..5a9ec29 100644 ---- a/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js -+++ b/node_modules/@cosmology/telescope/module/helpers/internal-for-bigint.js -@@ -2,41 +2,11 @@ export const getHelperForBigint = (options) => { - return `${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `import { Dec } from "@keplr-wallet/unit"; - - ` : ""} --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || -- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - --const btoa: (bin: string) => string = -- globalThis.btoa || -- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -249,11 +219,95 @@ export function fromJsonTimestamp(o: any): Timestamp { - function numberToLong(number: number) { - return BigInt(Math.trunc(number)); - } -+ -+ -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ - ${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? - ` - export function padDecimal(decStr: string): string{ - return decStr ? new Dec(decStr).toString() : decStr; - } -+ - ` : ""} - `; - }; -diff --git a/node_modules/@cosmology/telescope/module/helpers/internal.js b/node_modules/@cosmology/telescope/module/helpers/internal.js -index 28e50cf..c713941 100644 ---- a/node_modules/@cosmology/telescope/module/helpers/internal.js -+++ b/node_modules/@cosmology/telescope/module/helpers/internal.js -@@ -2,6 +2,7 @@ export const getHelper = (options) => { - return `import * as _m0 from "protobufjs/minimal"; - import Long from 'long';${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` - import { Dec } from "@keplr-wallet/unit"; -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - ` : ""} - - // @ts-ignore -@@ -13,39 +14,9 @@ if (_m0.util.Long !== Long) { - - export { Long }; - --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -- --const btoa: (bin: string) => string = -- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -231,6 +202,87 @@ export function fromJsonTimestamp(o: any): Timestamp { - } - } - -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ - function numberToLong(number: number) { - return Long.fromNumber(number); - }${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` -@@ -238,6 +290,7 @@ function numberToLong(number: number) { - export function padDecimal(decStr: string): string{ - return decStr ? new Dec(decStr).toString() : decStr; - } -+ - ` : ""} - `; - }; -diff --git a/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js b/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js -index ecb2e3e..4e96aff 100644 ---- a/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js -+++ b/node_modules/@cosmology/telescope/module/helpers/internalForBigInt.js -@@ -1,39 +1,9 @@ - export const internalForBigInt = ` --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || -- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - --const btoa: (bin: string) => string = -- globalThis.btoa || -- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -diff --git a/node_modules/@cosmology/telescope/module/utils/index.js b/node_modules/@cosmology/telescope/module/utils/index.js -index aa561fd..21c4e00 100644 ---- a/node_modules/@cosmology/telescope/module/utils/index.js -+++ b/node_modules/@cosmology/telescope/module/utils/index.js -@@ -18,7 +18,7 @@ export const UTILS = { - bytesFromBase64: '__helpers__', - BrowserHeaders: 'browser-headers', - connectComet: '@cosmjs/tendermint-rpc', -- Decimal: '@cosmjs/math', -+ Decimal: '__helpers__', - padDecimal: '__helpers__', - createProtobufRpcClient: '@cosmjs/stargate', - Pubkey: '@cosmjs/amino', -diff --git a/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts b/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts -index f7daa3d..555ffda 100644 ---- a/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts -+++ b/node_modules/@cosmology/telescope/src/helpers/internal-for-bigint.ts -@@ -4,41 +4,11 @@ export const getHelperForBigint = (options: TelescopeOptions) => { - return `${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? `import { Dec } from "@keplr-wallet/unit"; - - `: ""} --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || -- ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -- --const btoa: (bin: string) => string = -- globalThis.btoa || -- ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -+import { encodeBase64, decodeBase64 } from '@endo/base64'; - --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -251,6 +221,88 @@ export function fromJsonTimestamp(o: any): Timestamp { - function numberToLong(number: number) { - return BigInt(Math.trunc(number)); - } -+ -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ - ${ - options.aminoEncoding?.customTypes?.useCosmosSDKDec ? - ` -diff --git a/node_modules/@cosmology/telescope/src/helpers/internal.ts b/node_modules/@cosmology/telescope/src/helpers/internal.ts -index fc58715..98a1582 100644 ---- a/node_modules/@cosmology/telescope/src/helpers/internal.ts -+++ b/node_modules/@cosmology/telescope/src/helpers/internal.ts -@@ -4,6 +4,8 @@ export const getHelper = (options: TelescopeOptions) => { - return `import * as _m0 from "protobufjs/minimal"; - import Long from 'long';${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` - import { Dec } from "@keplr-wallet/unit"; -+import { encodeBase64, decodeBase64 } from '@endo/base64'; -+ - `: ""} - - // @ts-ignore -@@ -15,39 +17,9 @@ if (_m0.util.Long !== Long) { - - export { Long }; - --declare var self: any | undefined; --declare var window: any | undefined; --declare var global: any | undefined; --var globalThis: any = (() => { -- if (typeof globalThis !== 'undefined') return globalThis; -- if (typeof self !== 'undefined') return self; -- if (typeof window !== 'undefined') return window; -- if (typeof global !== 'undefined') return global; -- throw 'Unable to locate global object'; --})(); -- --const atob: (b64: string) => string = -- globalThis.atob || ((b64) => globalThis.Buffer.from(b64, 'base64').toString('binary')); -- --export function bytesFromBase64(b64: string): Uint8Array { -- const bin = atob(b64); -- const arr = new Uint8Array(bin.length); -- for (let i = 0; i < bin.length; ++i) { -- arr[i] = bin.charCodeAt(i); -- } -- return arr; --} -- --const btoa: (bin: string) => string = -- globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); -- --export function base64FromBytes(arr: Uint8Array): string { -- const bin: string[] = []; -- arr.forEach((byte) => { -- bin.push(String.fromCharCode(byte)); -- }); -- return btoa(bin.join('')); --} -+// use Endo for broader compatibility -+export const bytesFromBase64: (input: string) => Uint8Array = decodeBase64; -+export const base64FromBytes: (input: Uint8Array) => string = encodeBase64; - - export interface AminoHeight { - readonly revision_number?: string; -@@ -233,6 +205,87 @@ export function fromJsonTimestamp(o: any): Timestamp { - } - } - -+// The largest value we need is 18 (Ether). -+const maxFractionalDigits = 30; -+// Subset of Decimal in @cosmjs/math -+/** -+ * A type for arbitrary precision, non-negative decimals. -+ * -+ * Instances of this class are immutable. -+ */ -+export class Decimal { -+ public static fromUserInput( -+ input: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ -+ const badCharacter = input.match(/[^0-9.]/); -+ if (badCharacter) { -+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -+ throw new Error( -+ \`Invalid character at position \${badCharacter.index! + 1}\`, -+ ); -+ } -+ -+ let whole: string; -+ let fractional: string; -+ -+ if (input === '') { -+ whole = '0'; -+ fractional = ''; -+ } else if (input.search(/\./) === -1) { -+ // integer format, no separator -+ whole = input; -+ fractional = ''; -+ } else { -+ const parts = input.split('.'); -+ switch (parts.length) { -+ case 0: -+ case 1: -+ throw new Error( -+ 'Fewer than two elements in split result. This must not happen here.', -+ ); -+ case 2: -+ if (!parts[1]) throw new Error('Fractional part missing'); -+ whole = parts[0]; -+ fractional = parts[1].replace(/0+$/, ''); -+ break; -+ default: -+ throw new Error('More than one separator found'); -+ } -+ } -+ -+ if (fractional.length > fractionalDigits) { -+ throw new Error('Got more fractional digits than supported'); -+ } -+ -+ const quantity = \`\${whole}\${fractional.padEnd(fractionalDigits, '0')}\`; -+ -+ return new Decimal(quantity, fractionalDigits); -+ } -+ -+ public static fromAtomics( -+ atomics: string, -+ fractionalDigits: number, -+ ): Decimal { -+ Decimal.verifyFractionalDigits(fractionalDigits); -+ return new Decimal(atomics, fractionalDigits); -+ } -+ -+ private static verifyFractionalDigits(fractionalDigits: number): void { -+ if (!Number.isInteger(fractionalDigits)) -+ throw new Error('Fractional digits is not an integer'); -+ if (fractionalDigits < 0) -+ throw new Error('Fractional digits must not be negative'); -+ if (fractionalDigits > maxFractionalDigits) { -+ throw new Error( -+ \`Fractional digits must not exceed \${maxFractionalDigits}\`, -+ ); -+ } -+ } -+} -+ - function numberToLong(number: number) { - return Long.fromNumber(number); - }${options.aminoEncoding?.customTypes?.useCosmosSDKDec ? ` -diff --git a/node_modules/@cosmology/telescope/src/utils/index.ts b/node_modules/@cosmology/telescope/src/utils/index.ts -index 1ed202f..6d2cc38 100644 ---- a/node_modules/@cosmology/telescope/src/utils/index.ts -+++ b/node_modules/@cosmology/telescope/src/utils/index.ts -@@ -21,7 +21,7 @@ export const UTILS = { - bytesFromBase64: '__helpers__', - BrowserHeaders: 'browser-headers', - connectComet: '@cosmjs/tendermint-rpc', -- Decimal: '@cosmjs/math', -+ Decimal: '__helpers__', - padDecimal: '__helpers__', - createProtobufRpcClient: '@cosmjs/stargate', - Pubkey: '@cosmjs/amino', diff --git a/yarn.lock b/yarn.lock index c3eaa17b259..95eef5ed1d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1296,34 +1296,35 @@ resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.32.3.tgz#5dcaee6dd7cc846cdc073e9a7a7f63242f5f7e31" integrity sha512-WCZK4yksj2hBDz4w7xFZQTRZQ/RJhBX26uFHmmQFIcNUUVAihrLO+RerqJgk0dZqC42wstM9pEUQGtPmLcIYvg== -"@cosmology/ast@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@cosmology/ast/-/ast-1.7.1.tgz#a93e38d08c1c35d6e209cb04e580cd2b325a1110" - integrity sha512-dLqKUpxy9G8iS4Imd9JRDnP6Ca7EkyiqWWwgZacBLLuFK0mIDed0Fb8JP85pExV26XTC/Un3Nhi8yWiNQlKakQ== +"@cosmology/ast@^1.8.1": + version "1.8.1" + resolved "https://registry.yarnpkg.com/@cosmology/ast/-/ast-1.8.1.tgz#35a32fc117b007d6f7c9f5dcc82613989d206883" + integrity sha512-wjJDf3qk0SLaJsS6KJJqQpz+0iLl4V8V1cE7HwgwZT3F4nhTLfyK/13NbJcf0MhEfQ7+tNKFnVJIJJGfUxTPKQ== dependencies: "@babel/types" "7.23.6" - "@cosmology/types" "^1.7.0" - "@cosmology/utils" "^1.7.0" + "@cosmology/types" "^1.8.1" + "@cosmology/utils" "^1.8.1" case "1.6.3" dotty "0.1.2" -"@cosmology/proto-parser@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@cosmology/proto-parser/-/proto-parser-1.7.0.tgz#8d7abd40a91ee26bd1cc0518a84d871216a35434" - integrity sha512-7qJmGNUUaFG6Y2OgpO1x/ro0t5yOs+bILYwV2lYmqqTDqGJU3FTPewxFMx9vTZ2SHeVTVG1iQgdZslmwmRX/iQ== +"@cosmology/proto-parser@^1.8.1": + version "1.8.1" + resolved "https://registry.yarnpkg.com/@cosmology/proto-parser/-/proto-parser-1.8.1.tgz#2b6d8864b9593e518b20cd5dacbbcc68bd028f16" + integrity sha512-XgvhZH2af/6lJRYO19ozbdKdNziJu4p6HTv4u4CmUAgUpVG/tSA81cXTOMM+nJo1PPrhtqh9Nad9ISwLePvx2A== dependencies: - "@cosmology/protobufjs" "6.11.6" - "@cosmology/types" "^1.7.0" - "@cosmology/utils" "^1.7.0" + "@cosmology/protobufjs" "7.3.2" + "@cosmology/types" "^1.8.1" + "@cosmology/utils" "^1.8.1" dotty "0.1.2" + fast-json-patch "3.1.1" glob "8.0.3" minimatch "5.1.0" mkdirp "3.0.0" -"@cosmology/protobufjs@6.11.6": - version "6.11.6" - resolved "https://registry.yarnpkg.com/@cosmology/protobufjs/-/protobufjs-6.11.6.tgz#6f7bd340ab4a27969b1f75b4bff21a74e03b971a" - integrity sha512-k1opGC9CTX5vD2447pUqLmleVv0Kb8RasBUxkZHudVOvuXs2qAAGONmMIEGRCROKTodhTY9fdTnGU2lCZqAwNw== +"@cosmology/protobufjs@7.3.2": + version "7.3.2" + resolved "https://registry.yarnpkg.com/@cosmology/protobufjs/-/protobufjs-7.3.2.tgz#6c2acdaec9e4b7aab4647bb236da1258e7526a87" + integrity sha512-zHf/yqGQ7QSjIYvv7kvGKY9yXNjqj55kWdRyntrXwnte/tY8uMTuCFD/EWC48LGhGu3P7nbzTlhyCGMc3xm9bw== dependencies: "@protobufjs/aspromise" "^1.1.2" "@protobufjs/base64" "^1.1.2" @@ -1335,23 +1336,22 @@ "@protobufjs/path" "^1.1.2" "@protobufjs/pool" "^1.1.0" "@protobufjs/utf8" "^1.1.0" - "@types/long" "^4.0.1" + "@types/long" "^5.0.0" "@types/node" ">=13.7.0" - long "^4.0.0" + long "^5.0.0" -"@cosmology/telescope@^1.7.1": - version "1.7.1" - resolved "https://registry.yarnpkg.com/@cosmology/telescope/-/telescope-1.7.1.tgz#1d4357bfc49c41a03c5fbe91fe60c028ffbdfcf6" - integrity sha512-mB/h8iGfVNi+ZV3KzEy6xFKVlAe9d9pOTz/Vu+OCMcrEFS/xHgWMs+eNDGAbWuaCp06qYyZSc0pN7rMVojnElg== +"@cosmology/telescope@https://gitpkg.vercel.app/agoric-labs/telescope/packages/telescope?8d2c2f6ba637a5578eead09a7368dc41c262a9d0": + version "1.8.3" + resolved "https://gitpkg.vercel.app/agoric-labs/telescope/packages/telescope?8d2c2f6ba637a5578eead09a7368dc41c262a9d0#6cbf7b95125ced918760fc7382bcf9b52b209923" dependencies: "@babel/generator" "^7.23.6" "@babel/parser" "^7.23.6" "@babel/traverse" "7.23.6" "@babel/types" "7.23.6" - "@cosmology/ast" "^1.7.1" - "@cosmology/proto-parser" "^1.7.0" - "@cosmology/types" "^1.7.0" - "@cosmology/utils" "^1.7.0" + "@cosmology/ast" "^1.8.1" + "@cosmology/proto-parser" "^1.8.1" + "@cosmology/types" "^1.8.1" + "@cosmology/utils" "^1.8.1" "@cosmwasm/ts-codegen" "0.35.7" "@types/parse-package-name" "0.1.0" case "1.6.3" @@ -1369,19 +1369,20 @@ rimraf "5.0.0" yaml "^2.3.4" -"@cosmology/types@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@cosmology/types/-/types-1.7.0.tgz#089b43227b0ae4e4799be2d2e1f1b71a0091d422" - integrity sha512-BdevNk957uA/I12mgp24Dp4lrfN4lOgb1xoSJTvlmOJuks1q+vcQHiRyVfncxE5aFRNCG6ROHHu9IFckBW07hQ== +"@cosmology/types@^1.8.1": + version "1.8.1" + resolved "https://registry.yarnpkg.com/@cosmology/types/-/types-1.8.1.tgz#782868b232a214b55f41908353be87afa79c9302" + integrity sha512-M/4HZZu0mNwwzK7ITa5A4biVKGVk8EtaQJlHuuctygKvjKcvmmAglna754o9CdkfPEyUXBzYnLU6q7UIFgcO+g== dependencies: case "1.6.3" + fast-json-patch "3.1.1" -"@cosmology/utils@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@cosmology/utils/-/utils-1.7.0.tgz#7a09bee4d4fa65f1049dcb5a88939fe55fbbd5d4" - integrity sha512-TLaRenW/CTy8wo8z3mvSq0koM9XwL2aLcmdZEWUqhhVyUA0VOfDloh+3d/oLQxsBBzAiaDauX+wju3dkrY8moA== +"@cosmology/utils@^1.8.1": + version "1.8.1" + resolved "https://registry.yarnpkg.com/@cosmology/utils/-/utils-1.8.1.tgz#9fd7f0815da726f7a2a11d713f7e8886f94f0a6b" + integrity sha512-PrZffk81GQ0pJHH7kRJi9PZVt4qWa/9V3mbUyc3vXIWqeAk1bQ+5O5MLKirtRj4cEM3zt5WnDUISPCrt4VIQkA== dependencies: - "@cosmology/types" "^1.7.0" + "@cosmology/types" "^1.8.1" dotty "0.1.2" "@cosmwasm/ts-codegen@0.35.7": @@ -3552,10 +3553,12 @@ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8" integrity sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ== -"@types/long@^4.0.1": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/long/-/long-4.0.2.tgz#b74129719fc8d11c01868010082d483b7545591a" - integrity sha512-MqTGEo5bj5t157U6fA/BiDynNkn0YknVdh48CMPkTSpFTVmvao5UQmm7uEF6xBEo7qIMAlY/JSleYaE6VOdpaA== +"@types/long@^5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@types/long/-/long-5.0.0.tgz#daaa7b7f74c919c946ff74889d5ca2afe363b2cd" + integrity sha512-eQs9RsucA/LNjnMoJvWG/nXa7Pot/RbBzilF/QRIU/xRl+0ApxrSUFsV5lmf01SvSlqMzJ7Zwxe440wmz2SJGA== + dependencies: + long "*" "@types/mdast@^4.0.0": version "4.0.4" @@ -6354,6 +6357,11 @@ fast-glob@3.2.7: merge2 "^1.3.0" micromatch "^4.0.4" +fast-json-patch@3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/fast-json-patch/-/fast-json-patch-3.1.1.tgz#85064ea1b1ebf97a3f7ad01e23f9337e72c66947" + integrity sha512-vf6IHUX2SBcA+5/+4883dsIjpBTqmfBjmYiWK1savxQmFk4JfBMLa7ynTYOs1Rolp/T1betJxHiGD3g1Mn8lUQ== + fast-json-stable-stringify@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633" @@ -8188,12 +8196,7 @@ logform@^2.2.0, logform@^2.3.2: safe-stable-stringify "^2.3.1" triple-beam "^1.3.0" -long@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28" - integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA== - -long@^5.0.0, long@^5.2.0, long@^5.2.1: +long@*, long@^5.0.0, long@^5.2.0, long@^5.2.1: version "5.2.3" resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1" integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==