Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/abstract-cosmos/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Registry,
} from '@cosmjs/proto-signing';
import { Coin, defaultRegistryTypes } from '@cosmjs/stargate';
import { coins } from '@bitgo/statics';
import BigNumber from 'bignumber.js';
import { SignDoc, TxRaw } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
import { Any } from 'cosmjs-types/google/protobuf/any';
Expand Down Expand Up @@ -933,6 +934,19 @@ export class CosmosUtils<CustomMessage = never> implements BaseUtils {
getHashFunction(): Hash {
return createHash('sha256');
}

getTokenDenomsUsingCoinFamily(coinFamily: string): string[] {
// using set to remove duplicates as denom can be same on testnet and mainnet for a few tokens
return [
...new Set(
coins
.filter(
(coin) => coin.family.toLowerCase() === coinFamily.toLowerCase() && coin.isToken && coin.denom !== undefined
)
.map((coin) => coin.denom as string)
),
];
}
}

const utils = new CosmosUtils();
Expand Down
5 changes: 5 additions & 0 deletions modules/abstract-cosmos/test/unit/cosmosToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'should';
import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test';
import { BitGoAPI } from '@bitgo/sdk-api';
import { CosmosToken } from '../../src';
import CosmosUtils from '../../src/lib/utils';

describe('Cosmos Tokens', function () {
let bitgo: TestBitGoAPI;
Expand Down Expand Up @@ -46,4 +47,8 @@ describe('Cosmos Tokens', function () {
mainnetCosmosToken.denom.should.equal('uylds.fcc');
mainnetCosmosToken.decimalPlaces.should.equal(6);
});

it('should return denomination for YLDS token on hash using hash as coinFamily', function () {
CosmosUtils.getTokenDenomsUsingCoinFamily('hash').should.deepEqual(['uylds.fcc']);
});
});
5 changes: 4 additions & 1 deletion modules/sdk-coin-asi/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['fet', 'tfet', 'afet', 'atestfet'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['fet', 'tfet', 'afet', 'atestfet', ...cosmosUtils.getTokenDenomsUsingCoinFamily('asi')];
export const accountAddressRegex = /^(fetch)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(fetchvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(fetch)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-atom/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['natom', 'uatom', 'matom', 'atom'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['natom', 'uatom', 'matom', 'atom', ...cosmosUtils.getTokenDenomsUsingCoinFamily('atom')];
export const accountAddressRegex = /^(cosmos)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(cosmosvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(cosmos)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-baby/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['baby', 'tbaby', 'ubbn'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['baby', 'tbaby', 'ubbn', ...cosmosUtils.getTokenDenomsUsingCoinFamily('baby')];
export const accountAddressRegex = /^(bbn)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(bbnvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(bbn)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-bld/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['nbld', 'ubld', 'mbld', 'bld'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['nbld', 'ubld', 'mbld', 'bld', ...cosmosUtils.getTokenDenomsUsingCoinFamily('bld')];
export const accountAddressRegex = /^(agoric)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(agoricvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(agoric)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
7 changes: 4 additions & 3 deletions modules/sdk-coin-coreum/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export const mainnetValidDenoms = ['ucore'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['ucore', 'utestcore', ...cosmosUtils.getTokenDenomsUsingCoinFamily('coreum')];
export const mainnetAccountAddressRegex = /^(core)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const mainnetValidatorAddressRegex = /^(corevaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const MAINNET_ADDRESS_PREFIX = 'core';

export const testnetValidDenoms = ['utestcore'];
export const testnetAccountAddressRegex = /^(testcore)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const testnetValidatorAddressRegex = /^(testcorevaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const TESTNET_ADDRESS_PREFIX = 'testcore';
Expand Down
7 changes: 1 addition & 6 deletions modules/sdk-coin-coreum/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ export class CoreumUtils extends CosmosUtils {
if (amountBig.isLessThanOrEqualTo(0)) {
throw new InvalidTransactionError('transactionBuilder: validateAmount: Invalid amount: ' + amount.amount);
}
if (
(this.networkType === NetworkType.TESTNET &&
!constants.testnetValidDenoms.find((denom) => denom === amount.denom)) ||
(this.networkType === NetworkType.MAINNET &&
!constants.mainnetValidDenoms.find((denom) => denom === amount.denom))
) {
if (!constants.validDenoms.find((denom) => denom === amount.denom)) {
throw new InvalidTransactionError('transactionBuilder: validateAmount: Invalid denom: ' + amount.denom);
}
}
Expand Down
11 changes: 10 additions & 1 deletion modules/sdk-coin-cronos/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
export const validDenoms = ['cro', 'tcro', 'basecro', 'basetcro'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = [
'cro',
'tcro',
'basecro',
'basetcro',
...cosmosUtils.getTokenDenomsUsingCoinFamily('cronos'),
];

export const mainnetAccountAddressRegex = /^(cro)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const mainnetValidatorAddressRegex = /^(crocncl)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-hash/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['nhash', 'uhash', 'mhash', 'hash', 'uylds.fcc'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['nhash', 'uhash', 'mhash', 'hash', ...cosmosUtils.getTokenDenomsUsingCoinFamily('hash')];
export const mainnetAccountAddressRegex = /^(pb)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const mainnetValidatorAddressRegex = /^(pbvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const mainnetContractAddressRegex = /^(pb)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-initia/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['init', 'tinit', 'uinit'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['init', 'tinit', 'uinit', ...cosmosUtils.getTokenDenomsUsingCoinFamily('initia')];
export const accountAddressRegex = /^(init)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(initvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(init)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-injective/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['ninj', 'uinj', 'minj', 'inj'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['ninj', 'uinj', 'minj', 'inj', ...cosmosUtils.getTokenDenomsUsingCoinFamily('injective')];
export const accountAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(injvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(inj)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
5 changes: 4 additions & 1 deletion modules/sdk-coin-osmo/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['nosmo', 'uosmo', 'mosmo', 'osmo'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['nosmo', 'uosmo', 'mosmo', 'osmo', ...cosmosUtils.getTokenDenomsUsingCoinFamily('osmo')];
export const accountAddressRegex = /^(osmo)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(osmovaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(osmo)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
6 changes: 4 additions & 2 deletions modules/sdk-coin-rune/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export const mainnetValidDenoms = ['rune'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['rune', ...cosmosUtils.getTokenDenomsUsingCoinFamily('thor')];
export const mainnetAccountAddressRegex = /^(thor)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const mainnetValidatorAddressRegex = /^(thor)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const MAINNET_ADDRESS_PREFIX = 'thor';

export const testnetValidDenoms = ['rune'];
export const testnetAccountAddressRegex = /^(sthor)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const testnetValidatorAddressRegex = /^(sthor)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const TESTNET_ADDRESS_PREFIX = 'sthor';
Expand Down
6 changes: 1 addition & 5 deletions modules/sdk-coin-rune/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,7 @@ export class RuneUtils extends CosmosUtils {
}

validateDenomination(amountDenom: string): void {
if (
(this.networkType === NetworkType.TESTNET &&
!constants.testnetValidDenoms.find((denom) => denom === amountDenom)) ||
(this.networkType === NetworkType.MAINNET && !constants.mainnetValidDenoms.find((denom) => denom === amountDenom))
) {
if (!constants.validDenoms.find((denom) => denom === amountDenom)) {
throw new InvalidTransactionError('transactionBuilder: validateAmount: Invalid denom: ' + amountDenom);
}
}
Expand Down
5 changes: 4 additions & 1 deletion modules/sdk-coin-sei/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['nsei', 'usei', 'msei', 'sei'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['nsei', 'usei', 'msei', 'sei', ...cosmosUtils.getTokenDenomsUsingCoinFamily('sei')];
export const accountAddressRegex = /^(sei)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(seivaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(sei)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
5 changes: 4 additions & 1 deletion modules/sdk-coin-tia/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['ntia', 'utia', 'mtia', 'tia'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['ntia', 'utia', 'mtia', 'tia', ...cosmosUtils.getTokenDenomsUsingCoinFamily('tia')];
export const accountAddressRegex = /^(celestia)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(celestiavaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(celestia)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
5 changes: 4 additions & 1 deletion modules/sdk-coin-zeta/src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const validDenoms = ['azeta'];
import { CosmosUtils } from '@bitgo/abstract-cosmos';

const cosmosUtils = new CosmosUtils();
export const validDenoms = ['azeta', ...cosmosUtils.getTokenDenomsUsingCoinFamily('zeta')];
export const accountAddressRegex = /^(zeta)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const validatorAddressRegex = /^(zetavaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]{38})$/;
export const contractAddressRegex = /^(zeta)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l]+)$/;
Expand Down
3 changes: 3 additions & 0 deletions modules/statics/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,7 @@ export interface BaseCoinConstructorOptions {
alias?: string; // alternative name usually used during name migrations
prefix?: string;
suffix?: string;
denom?: string; // the denomination of the coin
baseUnit: string; // the base unit for each coin. e.g. satoshi for BTC
kind: CoinKind;
isToken: boolean;
Expand All @@ -3012,6 +3013,7 @@ export abstract class BaseCoin {
public readonly name: string;
public readonly prefix?: string;
public readonly suffix?: string;
public readonly denom?: string;
public readonly baseUnit: string;
/*
Property to help during migration of token names.
Expand Down Expand Up @@ -3110,6 +3112,7 @@ export abstract class BaseCoin {
this.alias = options.alias;
this.prefix = options.prefix;
this.suffix = options.suffix;
this.denom = options.denom;
this.baseUnit = options.baseUnit;
this.kind = options.kind;
this.family = options.network.family;
Expand Down