-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { TelescopeBuilder } from '../builder'; | ||
export declare const plugin: (builder: TelescopeBuilder) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters