Split token types

This commit is contained in:
Simon Warta 2020-08-11 08:48:30 +02:00
parent 3e9ae72190
commit 1e347d1de5
8 changed files with 32 additions and 31 deletions

View File

@ -1,4 +1,4 @@
import { TokenConfiguration } from "./types";
import { TokenConfiguration } from "./tokenmanager";
export const binaryName = "cosmwasm-faucet";
export const concurrency: number = Number.parseInt(process.env.FAUCET_CONCURRENCY || "", 10) || 5;

View File

@ -1,7 +1,8 @@
import { Coin } from "@cosmjs/launchpad";
import { Decimal } from "@cosmjs/math";
import { MinimalAccount, SendJob, TokenConfiguration } from "./types";
import { TokenConfiguration } from "./tokenmanager";
import { MinimalAccount, SendJob } from "./types";
/** A string representation of a coin in a human-readable format that can change at any time */
function debugCoin(coin: Coin, tokens: TokenConfiguration): string {

View File

@ -4,7 +4,7 @@ import { CosmosClient } from "@cosmjs/launchpad";
import { assert } from "@cosmjs/utils";
import { Faucet } from "./faucet";
import { TokenConfiguration } from "./types";
import { TokenConfiguration } from "./tokenmanager";
function pendingWithoutWasmd(): void {
if (!process.env.WASMD_ENABLED) {

View File

@ -3,8 +3,8 @@ import { sleep } from "@cosmjs/utils";
import { debugAccount, logAccountsState, logSendJob } from "./debugging";
import { createWallets } from "./profile";
import { TokenManager } from "./tokenmanager";
import { MinimalAccount, SendJob, TokenConfiguration } from "./types";
import { TokenConfiguration, TokenManager } from "./tokenmanager";
import { MinimalAccount, SendJob } from "./types";
function isDefined<X>(value: X | undefined): value is X {
return value !== undefined;

View File

@ -1,5 +1,5 @@
import { TokenManager } from "./tokenmanager";
import { MinimalAccount, TokenConfiguration } from "./types";
import { TokenConfiguration, TokenManager } from "./tokenmanager";
import { MinimalAccount } from "./types";
const dummyConfig: TokenConfiguration = {
bankTokens: [

View File

@ -1,7 +1,8 @@
import { Coin } from "@cosmjs/launchpad";
import { Decimal, Uint53 } from "@cosmjs/math";
import { BankTokenMeta, MinimalAccount, TokenConfiguration } from "./types";
import { BankTokenMeta } from "./tokens";
import { MinimalAccount } from "./types";
/** Send `factor` times credit amount on refilling */
const defaultRefillFactor = 20;
@ -9,6 +10,11 @@ const defaultRefillFactor = 20;
/** refill when balance gets below `factor` times credit amount */
const defaultRefillThresholdFactor = 8;
export interface TokenConfiguration {
/** Supported tokens of the Cosmos SDK bank module */
readonly bankTokens: readonly BankTokenMeta[];
}
export class TokenManager {
private readonly config: TokenConfiguration;

View File

@ -0,0 +1,17 @@
export interface BankTokenMeta {
readonly denom: string;
/**
* The token ticker symbol, e.g. ATOM or ETH.
*/
readonly tickerSymbol: string;
/**
* The number of fractional digits the token supports.
*
* A quantity is expressed as atomic units. 10^fractionalDigits of those
* atomic units make up 1 token.
*
* E.g. in Ethereum 10^18 wei are 1 ETH and from the quantity 123000000000000000000
* the last 18 digits are the fractional part and the rest the wole part.
*/
readonly fractionalDigits: number;
}

View File

@ -6,27 +6,4 @@ export interface SendJob {
readonly amount: Coin;
}
export interface BankTokenMeta {
readonly denom: string;
/**
* The token ticker symbol, e.g. ATOM or ETH.
*/
readonly tickerSymbol: string;
/**
* The number of fractional digits the token supports.
*
* A quantity is expressed as atomic units. 10^fractionalDigits of those
* atomic units make up 1 token.
*
* E.g. in Ethereum 10^18 wei are 1 ETH and from the quantity 123000000000000000000
* the last 18 digits are the fractional part and the rest the wole part.
*/
readonly fractionalDigits: number;
}
export interface TokenConfiguration {
/** Supported tokens of the Cosmos SDK bank module */
readonly bankTokens: readonly BankTokenMeta[];
}
export type MinimalAccount = Pick<Account, "address" | "balance">;