Skip to content

Commit

Permalink
sdk/js: add cosmoshub and evmos chain ids (#3317)
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Picco authored Sep 11, 2023
1 parent a9437e8 commit e826617
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sdk/js/src/cosmwasm/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { LCDClient as XplaLCDClient } from "@xpla/xpla.js";
import { keccak256 } from "ethers/lib/utils";
import { isNativeDenom } from "../terra";
import {
CHAIN_ID_COSMOSHUB,
CHAIN_ID_EVMOS,
CHAIN_ID_WORMCHAIN,
CHAIN_ID_INJECTIVE,
CHAIN_ID_SEI,
CHAIN_ID_TERRA,
Expand All @@ -16,6 +19,9 @@ import {
export const isNativeDenomInjective = (denom: string) => denom === "inj";
export const isNativeDenomXpla = (denom: string) => denom === "axpla";
export const isNativeDenomSei = (denom: string) => denom === "usei";
export const isNativeDenomWormchain = (denom: string) => denom === "uworm";
export const isNativeDenomCosmosHub = (denom: string) => denom === "uatom";
export const isNativeDenomEvmos = (denom: string) => denom === "aevmos";

export function isNativeCosmWasmDenom(
chainId: CosmWasmChainId,
Expand All @@ -25,7 +31,10 @@ export function isNativeCosmWasmDenom(
(isTerraChain(chainId) && isNativeDenom(address)) ||
(chainId === CHAIN_ID_INJECTIVE && isNativeDenomInjective(address)) ||
(chainId === CHAIN_ID_XPLA && isNativeDenomXpla(address)) ||
(chainId === CHAIN_ID_SEI && isNativeDenomSei(address))
(chainId === CHAIN_ID_SEI && isNativeDenomSei(address)) ||
(chainId === CHAIN_ID_WORMCHAIN && isNativeDenomWormchain(address)) ||
(chainId === CHAIN_ID_COSMOSHUB && isNativeDenomCosmosHub(address)) ||
(chainId === CHAIN_ID_EVMOS && isNativeDenomEvmos(address))
);
}

Expand Down
10 changes: 10 additions & 0 deletions sdk/js/src/utils/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
CHAIN_ID_XPLA,
CHAIN_ID_SEI,
CHAIN_ID_BTC,
CHAIN_ID_COSMOSHUB,
CHAIN_ID_EVMOS,
} from "./consts";
import { hashLookup } from "./near";
import { getExternalAddressFromType, isValidAptosType } from "./aptos";
Expand Down Expand Up @@ -120,6 +122,10 @@ export const tryUint8ArrayToNative = (
throw Error("uint8ArrayToNative: Use tryHexToNativeStringNear instead.");
} else if (chainId === CHAIN_ID_OSMOSIS) {
throw Error("uint8ArrayToNative: Osmosis not supported yet.");
} else if (chainId === CHAIN_ID_COSMOSHUB) {
throw Error("uint8ArrayToNative: CosmosHub not supported yet.");
} else if (chainId === CHAIN_ID_EVMOS) {
throw Error("uint8ArrayToNative: Evmos not supported yet.");
} else if (chainId === CHAIN_ID_SUI) {
throw Error("uint8ArrayToNative: Sui not supported yet.");
} else if (chainId === CHAIN_ID_APTOS) {
Expand Down Expand Up @@ -257,6 +263,10 @@ export const tryNativeToHexString = (
return uint8ArrayToHex(arrayify(sha256(Buffer.from(address))));
} else if (chainId === CHAIN_ID_OSMOSIS) {
throw Error("hexToNativeString: Osmosis not supported yet.");
} else if (chainId === CHAIN_ID_COSMOSHUB) {
throw Error("uint8ArrayToNative: CosmosHub not supported yet.");
} else if (chainId === CHAIN_ID_EVMOS) {
throw Error("uint8ArrayToNative: Evmos not supported yet.");
} else if (chainId === CHAIN_ID_SUI) {
if (!isValidSuiType(address) && isValidSuiAddress(address)) {
return uint8ArrayToHex(
Expand Down
39 changes: 39 additions & 0 deletions sdk/js/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const CHAINS = {
sei: 32,
rootstock: 33,
wormchain: 3104,
cosmoshub: 4000,
evmos: 4001,
sepolia: 10002,
} as const;

Expand Down Expand Up @@ -78,6 +80,10 @@ export const CosmWasmChainNames = [
"injective",
"xpla",
"sei",
"wormchain",
"osmosis",
"evmos",
"cosmoshub",
] as const;
export type CosmWasmChainName = typeof CosmWasmChainNames[number];

Expand Down Expand Up @@ -276,6 +282,16 @@ const MAINNET = {
token_bridge: undefined,
nft_bridge: undefined,
},
cosmoshub: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
evmos: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};

const TESTNET = {
Expand Down Expand Up @@ -455,6 +471,16 @@ const TESTNET = {
token_bridge: "0xDB5492265f6038831E89f495670FF909aDe94bd9",
nft_bridge: "0x6a0B52ac198e4870e5F3797d5B403838a5bbFD99",
},
cosmoshub: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
evmos: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};

const DEVNET = {
Expand Down Expand Up @@ -633,6 +659,16 @@ const DEVNET = {
token_bridge: undefined,
nft_bridge: undefined,
},
cosmoshub: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
evmos: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};

/**
Expand Down Expand Up @@ -706,6 +742,9 @@ export const CHAIN_ID_BASE = CHAINS["base"];
export const CHAIN_ID_SEI = CHAINS["sei"];
export const CHAIN_ID_ROOTSTOCK = CHAINS["rootstock"];
export const CHAIN_ID_WORMCHAIN = CHAINS["wormchain"];
export const CHAIN_ID_GATEWAY = CHAIN_ID_WORMCHAIN;
export const CHAIN_ID_COSMOSHUB = CHAINS["cosmoshub"];
export const CHAIN_ID_EVMOS = CHAINS["evmos"];
export const CHAIN_ID_SEPOLIA = CHAINS["sepolia"];

// This inverts the [[CHAINS]] object so that we can look up a chain by id
Expand Down

0 comments on commit e826617

Please sign in to comment.