Update token denom to $Z

This commit is contained in:
Prathamesh Musale 2025-06-17 11:57:27 +05:30
parent 939274d04c
commit 3d14a8a7ae
3 changed files with 39 additions and 3 deletions

View File

@ -1,6 +1,6 @@
[upstream]
rpcEndpoint = "http://localhost:26657"
denom = "znt"
denom = "$Z"
prefix = "zenith"
gasPrice = "1"
faucetKey = ""

View File

@ -6,11 +6,13 @@ import toml from 'toml';
import cors from 'cors';
import { DirectSecp256k1Wallet } from '@cosmjs/proto-signing';
import { GasPrice, SigningStargateClient } from '@cosmjs/stargate';
import { SigningStargateClient } from '@cosmjs/stargate';
import { Comet38Client } from '@cosmjs/tendermint-rpc';
import { fromBech32 } from '@cosmjs/encoding';
import KeyvSqlite from '@keyv/sqlite';
import { parseCustomGasPrice } from './utils';
const CONFIG_PATH = 'environments/local.toml';
const FAUCET_DATA_FILE = 'faucet_data.sqlite';
const FAUCET_DATA_TTL = 86400000; // 24 hrs
@ -123,7 +125,7 @@ async function sendTokens (config: Config, recipientAddress: string, amount: str
const client = await SigningStargateClient.createWithSigner(
cometClient,
wallet,
{ gasPrice: GasPrice.fromString(`${config.upstream.gasPrice}${config.upstream.denom}`) }
{ gasPrice: parseCustomGasPrice(`${config.upstream.gasPrice}${config.upstream.denom}`) }
);
const result = await client.sendTokens(

34
src/utils.ts Normal file
View File

@ -0,0 +1,34 @@
import { GasPrice } from '@cosmjs/stargate';
import { Decimal } from '@cosmjs/math';
/**
* Parses a gas price string with a more flexible denom regex.
* This function is a custom implementation to allow for denoms that can start with
* numbers or other valid characters, while still supporting an optional dollar sign prefix.
*
* @param gasPrice The gas price string, e.g., '0.012utoken' or '0.001$mydenom'.
* @returns A GasPrice object.
* @throws If the gas price string is invalid.
*/
export function parseCustomGasPrice (gasPrice: string): GasPrice {
// This regex allows the denom to start with an optional '$' followed by any
// alphanumeric character or ':', '.', '_', '-'. It must have at least one such character.
const matchResult = gasPrice.match(/^([0-9.]+)(\$?[a-zA-Z][a-zA-Z0-9/:._-]*)$/);
if (!matchResult) {
throw new Error('Invalid gas price string');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, amount, denom] = matchResult;
// Basic denom length check (similar to checkDenom in @cosmjs/stargate)
if (denom.length < 2 || denom.length > 128) {
throw new Error('Denom must be between 2 and 128 characters');
}
const fractionalDigits = 18; // Standard for Cosmos SDK decimals
const decimalAmount = Decimal.fromUserInput(amount, fractionalDigits);
return new GasPrice(decimalAmount, denom);
}