Skip to content

Commit

Permalink
chore: bundle new build files
Browse files Browse the repository at this point in the history
  • Loading branch information
j-yw committed Sep 14, 2024
1 parent 197da9e commit 99b75e9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 0 additions & 1 deletion packages/telescope/types/helpers/decimals.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export declare const cosmjsDecimal = "\nexport { Decimal } from \"@cosmjs/math\";\n";
export declare const decimal = "\n// START agoric-sdk patch\n// The largest value we need is 18 (Ether).\nconst maxFractionalDigits = 30;\n/**\n * A type for arbitrary precision, non-negative decimals.\n *\n * Instances of this class are immutable.\n */\nexport class Decimal {\n public static fromUserInput(\n input: string,\n fractionalDigits: number\n ): Decimal {\n Decimal.verifyFractionalDigits(fractionalDigits);\n const badCharacter = input.match(/[^0-9.]/);\n if (badCharacter) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n throw new Error(\n `Invalid character at position ${badCharacter.index! + 1}`\n );\n }\n let whole: string;\n let fractional: string;\n if (input === \"\") {\n whole = \"0\";\n fractional = \"\";\n } else if (input.search(/\\./) === -1) {\n // integer format, no separator\n whole = input;\n fractional = \"\";\n } else {\n const parts = input.split(\".\");\n switch (parts.length) {\n case 0:\n case 1:\n throw new Error(\n \"Fewer than two elements in split result. This must not happen here.\"\n );\n case 2:\n if (!parts[1]) throw new Error(\"Fractional part missing\");\n whole = parts[0];\n fractional = parts[1].replace(/0+$/, \"\");\n break;\n default:\n throw new Error(\"More than one separator found\");\n }\n }\n if (fractional.length > fractionalDigits) {\n throw new Error(\"Got more fractional digits than supported\");\n }\n const quantity = `${whole}${fractional.padEnd(fractionalDigits, \"0\")}`;\n return new Decimal(quantity, fractionalDigits);\n }\n public static fromAtomics(\n atomics: string,\n fractionalDigits: number\n ): Decimal {\n Decimal.verifyFractionalDigits(fractionalDigits);\n return new Decimal(atomics, fractionalDigits);\n }\n private static verifyFractionalDigits(fractionalDigits: number): void {\n if (!Number.isInteger(fractionalDigits))\n throw new Error(\"Fractional digits is not an integer\");\n if (fractionalDigits < 0)\n throw new Error(\"Fractional digits must not be negative\");\n if (fractionalDigits > maxFractionalDigits) {\n throw new Error(\n `Fractional digits must not exceed ${maxFractionalDigits}`\n );\n }\n }\n public get atomics(): string {\n return this.data.atomics.toString();\n }\n public get fractionalDigits(): number {\n return this.data.fractionalDigits;\n }\n private readonly data: {\n readonly atomics: bigint;\n readonly fractionalDigits: number;\n };\n private constructor(atomics: string, fractionalDigits: number) {\n if (!atomics.match(/^[0-9]+$/)) {\n throw new Error(\n \"Invalid string format. Only non-negative integers in decimal representation supported.\"\n );\n }\n this.data = {\n atomics: BigInt(atomics),\n fractionalDigits: fractionalDigits,\n };\n }\n public toString(): string {\n const factor = BigInt(10) ** BigInt(this.data.fractionalDigits);\n const whole = this.data.atomics / factor;\n const fractional = this.data.atomics % factor;\n if (fractional === 0n) {\n return whole.toString();\n } else {\n const fullFractionalPart = fractional\n .toString()\n .padStart(this.data.fractionalDigits, \"0\");\n const trimmedFractionalPart = fullFractionalPart.replace(/0+$/, \"\");\n return `${whole.toString()}.${trimmedFractionalPart}`;\n }\n }\n}\n// END agoric-sdk patch\n";
1 change: 1 addition & 0 deletions packages/types/types/telescope.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ interface TelescopeOpts {
customTypes?: {
useCosmosSDKDec?: boolean;
useAgoricDecimal?: boolean;
base64Lib?: boolean;
};
num64?: 'long' | 'bigint';
useDeepPartial?: boolean;
Expand Down

0 comments on commit 99b75e9

Please sign in to comment.