diff --git a/packages/launchpad/src/coins.spec.ts b/packages/launchpad/src/coins.spec.ts deleted file mode 100644 index 5f74c4cb..00000000 --- a/packages/launchpad/src/coins.spec.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { coin, coins, parseCoins } from "./coins"; - -describe("coins", () => { - describe("coin", () => { - it("works for basic values", () => { - expect(coin(123, "utoken")).toEqual({ amount: "123", denom: "utoken" }); - expect(coin(123.0, "utoken")).toEqual({ amount: "123", denom: "utoken" }); - expect(coin(Number.MAX_SAFE_INTEGER, "utoken")).toEqual({ - amount: "9007199254740991", - denom: "utoken", - }); - expect(coin(+0, "utoken")).toEqual({ amount: "0", denom: "utoken" }); - expect(coin(-0, "utoken")).toEqual({ amount: "0", denom: "utoken" }); - }); - - it("throws for non-safe-integer values", () => { - expect(() => coin(1.23, "utoken")).toThrow(); - expect(() => coin(NaN, "utoken")).toThrow(); - expect(() => coin(Number.POSITIVE_INFINITY, "utoken")).toThrow(); - expect(() => coin(Number.MAX_SAFE_INTEGER + 1, "utoken")).toThrow(); - }); - - it("throws for negative values", () => { - expect(() => coin(-1, "utoken")).toThrow(); - expect(() => coin(Number.MIN_SAFE_INTEGER, "utoken")).toThrow(); - expect(() => coin(Number.NEGATIVE_INFINITY, "utoken")).toThrow(); - }); - }); - - describe("coins", () => { - it("returns one element array of coin", () => { - expect(coins(123, "utoken")).toEqual([{ amount: "123", denom: "utoken" }]); - }); - }); - - describe("parseCoins", () => { - it("works for empty", () => { - expect(parseCoins("")).toEqual([]); - }); - - it("works for one element", () => { - expect(parseCoins("7643ureef")).toEqual([ - { - amount: "7643", - denom: "ureef", - }, - ]); - }); - - it("works for two", () => { - expect(parseCoins("819966000ucosm,700000000ustake")).toEqual([ - { - amount: "819966000", - denom: "ucosm", - }, - { - amount: "700000000", - denom: "ustake", - }, - ]); - }); - - it("ignores empty elements", () => { - // start - expect(parseCoins(",819966000ucosm,700000000ustake")).toEqual([ - { - amount: "819966000", - denom: "ucosm", - }, - { - amount: "700000000", - denom: "ustake", - }, - ]); - // middle - expect(parseCoins("819966000ucosm,,700000000ustake")).toEqual([ - { - amount: "819966000", - denom: "ucosm", - }, - { - amount: "700000000", - denom: "ustake", - }, - ]); - // end - expect(parseCoins("819966000ucosm,700000000ustake,")).toEqual([ - { - amount: "819966000", - denom: "ucosm", - }, - { - amount: "700000000", - denom: "ustake", - }, - ]); - }); - - it("throws for invalid inputs", () => { - // denom missing - expect(() => parseCoins("3456")).toThrowError(/invalid coin string/i); - - // amount missing - expect(() => parseCoins("ucosm")).toThrowError(/invalid coin string/i); - }); - }); -}); diff --git a/packages/launchpad/src/coins.ts b/packages/launchpad/src/coins.ts deleted file mode 100644 index e62617c8..00000000 --- a/packages/launchpad/src/coins.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Coin } from "@cosmjs/amino"; -import { Uint53, Uint64 } from "@cosmjs/math"; - -/** Creates a coin */ -export function coin(amount: number, denom: string): Coin { - return { amount: new Uint53(amount).toString(), denom: denom }; -} - -/** Creates a list of coins with one element */ -export function coins(amount: number, denom: string): Coin[] { - return [coin(amount, denom)]; -} - -/** - * Takes a coins list like "819966000ucosm,700000000ustake" and parses it - */ -export function parseCoins(input: string): Coin[] { - return input - .replace(/\s/g, "") - .split(",") - .filter(Boolean) - .map((part) => { - const match = part.match(/^([0-9]+)([a-zA-Z]+)/); - if (!match) throw new Error("Got an invalid coin string"); - return { - amount: Uint64.fromString(match[1]).toString(), - denom: match[2], - }; - }); -} diff --git a/packages/launchpad/src/cosmosclient.searchtx.spec.ts b/packages/launchpad/src/cosmosclient.searchtx.spec.ts index 5fa17338..e3e6c56f 100644 --- a/packages/launchpad/src/cosmosclient.searchtx.spec.ts +++ b/packages/launchpad/src/cosmosclient.searchtx.spec.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; +import { coins, makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; -import { coins } from "./coins"; import { CosmosClient, isBroadcastTxFailure } from "./cosmosclient"; import { LcdClient } from "./lcdapi"; import { isMsgSend, MsgSend } from "./msgs"; diff --git a/packages/launchpad/src/fee.ts b/packages/launchpad/src/fee.ts index 1703792f..c76062cc 100644 --- a/packages/launchpad/src/fee.ts +++ b/packages/launchpad/src/fee.ts @@ -1,8 +1,6 @@ -import { StdFee } from "@cosmjs/amino"; +import { coins, StdFee } from "@cosmjs/amino"; import { Decimal, Uint53 } from "@cosmjs/math"; -import { coins } from "./coins"; - export type FeeTable = Record; export class GasPrice { diff --git a/packages/launchpad/src/index.ts b/packages/launchpad/src/index.ts index 6231d334..210f8e40 100644 --- a/packages/launchpad/src/index.ts +++ b/packages/launchpad/src/index.ts @@ -5,6 +5,8 @@ export { AminoMsg as Msg, AminoSignResponse, Coin, + coin, + coins, KdfConfiguration, OfflineAminoSigner as OfflineSigner, Secp256k1HdWallet, @@ -23,6 +25,7 @@ export { executeKdf, makeCosmoshubPath, makeSignDoc, + parseCoins, pubkeyToAddress, pubkeyType, serializeSignDoc, @@ -34,7 +37,6 @@ export type PubKey = SinglePubkey; import * as logs from "./logs"; export { logs }; -export { coin, coins, parseCoins } from "./coins"; export { Account, assertIsBroadcastTxSuccess, diff --git a/packages/launchpad/src/lcdapi/distribution.spec.ts b/packages/launchpad/src/lcdapi/distribution.spec.ts index c28b34f1..c2d320e8 100644 --- a/packages/launchpad/src/lcdapi/distribution.spec.ts +++ b/packages/launchpad/src/lcdapi/distribution.spec.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; +import { coin, coins, makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; import { Bech32 } from "@cosmjs/encoding"; import { sleep } from "@cosmjs/utils"; -import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { MsgDelegate } from "../msgs"; import { SigningCosmosClient } from "../signingcosmosclient"; diff --git a/packages/launchpad/src/lcdapi/gov.spec.ts b/packages/launchpad/src/lcdapi/gov.spec.ts index 94fe81d3..8fe54e47 100644 --- a/packages/launchpad/src/lcdapi/gov.spec.ts +++ b/packages/launchpad/src/lcdapi/gov.spec.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; +import { coins, makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; import { sleep } from "@cosmjs/utils"; -import { coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { SigningCosmosClient } from "../signingcosmosclient"; import { diff --git a/packages/launchpad/src/lcdapi/staking.spec.ts b/packages/launchpad/src/lcdapi/staking.spec.ts index 0dcf12c1..90ff26f9 100644 --- a/packages/launchpad/src/lcdapi/staking.spec.ts +++ b/packages/launchpad/src/lcdapi/staking.spec.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; +import { coin, coins, makeSignDoc, Secp256k1HdWallet } from "@cosmjs/amino"; import { assert, sleep } from "@cosmjs/utils"; -import { coin, coins } from "../coins"; import { assertIsBroadcastTxSuccess } from "../cosmosclient"; import { MsgDelegate, MsgUndelegate } from "../msgs"; import { SigningCosmosClient } from "../signingcosmosclient"; diff --git a/packages/launchpad/src/signingcosmosclient.spec.ts b/packages/launchpad/src/signingcosmosclient.spec.ts index 4763d583..244ce067 100644 --- a/packages/launchpad/src/signingcosmosclient.spec.ts +++ b/packages/launchpad/src/signingcosmosclient.spec.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { Coin, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/amino"; +import { Coin, coin, coins, makeCosmoshubPath, Secp256k1HdWallet } from "@cosmjs/amino"; import { assert } from "@cosmjs/utils"; -import { coin, coins } from "./coins"; import { assertIsBroadcastTxSuccess, PrivateCosmosClient } from "./cosmosclient"; import { GasPrice } from "./fee"; import { MsgDelegate, MsgSend } from "./msgs"; diff --git a/packages/launchpad/src/tx.spec.ts b/packages/launchpad/src/tx.spec.ts index bb6d11f7..9fec53b4 100644 --- a/packages/launchpad/src/tx.spec.ts +++ b/packages/launchpad/src/tx.spec.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { StdFee, StdSignature } from "@cosmjs/amino"; +import { coins, StdFee, StdSignature } from "@cosmjs/amino"; import { makeSignDoc } from "@cosmjs/amino/build/signdoc"; -import { coins } from "./coins"; import { makeStdTx } from "./tx"; describe("tx", () => {