Add Kujira chain id

This commit is contained in:
M-Picco 2023-09-14 17:26:30 -03:00 committed by Evan Gray
parent 607a339cfb
commit bb8873ffea
4 changed files with 37 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@certusone/wormhole-sdk",
"version": "0.10.2",
"version": "0.10.3",
"description": "SDK for interacting with Wormhole",
"homepage": "https://wormhole.com",
"main": "./lib/cjs/index.js",

View File

@ -14,14 +14,18 @@ import {
CosmWasmChainId,
CosmWasmChainName,
isTerraChain,
CHAIN_ID_KUJIRA,
CHAIN_ID_OSMOSIS,
} from "../utils";
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 isNativeDenomOsmosis = (denom: string) => denom === "uosmo";
export const isNativeDenomCosmosHub = (denom: string) => denom === "uatom";
export const isNativeDenomEvmos = (denom: string) => denom === "aevmos";
export const isNativeDenomKujira = (denom: string) => denom === "ukuji";
export function isNativeCosmWasmDenom(
chainId: CosmWasmChainId,
@ -33,8 +37,10 @@ export function isNativeCosmWasmDenom(
(chainId === CHAIN_ID_XPLA && isNativeDenomXpla(address)) ||
(chainId === CHAIN_ID_SEI && isNativeDenomSei(address)) ||
(chainId === CHAIN_ID_WORMCHAIN && isNativeDenomWormchain(address)) ||
(chainId === CHAIN_ID_OSMOSIS && isNativeDenomOsmosis(address)) ||
(chainId === CHAIN_ID_COSMOSHUB && isNativeDenomCosmosHub(address)) ||
(chainId === CHAIN_ID_EVMOS && isNativeDenomEvmos(address))
(chainId === CHAIN_ID_EVMOS && isNativeDenomEvmos(address)) ||
(chainId === CHAIN_ID_KUJIRA && isNativeDenomKujira(address))
);
}

View File

@ -34,6 +34,7 @@ import {
CHAIN_ID_BTC,
CHAIN_ID_COSMOSHUB,
CHAIN_ID_EVMOS,
CHAIN_ID_KUJIRA,
} from "./consts";
import { hashLookup } from "./near";
import { getExternalAddressFromType, isValidAptosType } from "./aptos";
@ -126,6 +127,8 @@ export const tryUint8ArrayToNative = (
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_KUJIRA) {
throw Error("uint8ArrayToNative: Kujira not supported yet.");
} else if (chainId === CHAIN_ID_SUI) {
throw Error("uint8ArrayToNative: Sui not supported yet.");
} else if (chainId === CHAIN_ID_APTOS) {
@ -262,20 +265,22 @@ export const tryNativeToHexString = (
} else if (chainId === CHAIN_ID_NEAR) {
return uint8ArrayToHex(arrayify(sha256(Buffer.from(address))));
} else if (chainId === CHAIN_ID_OSMOSIS) {
throw Error("hexToNativeString: Osmosis not supported yet.");
throw Error("nativeToHexString: Osmosis not supported yet.");
} else if (chainId === CHAIN_ID_COSMOSHUB) {
throw Error("uint8ArrayToNative: CosmosHub not supported yet.");
throw Error("nativeToHexString: CosmosHub not supported yet.");
} else if (chainId === CHAIN_ID_EVMOS) {
throw Error("uint8ArrayToNative: Evmos not supported yet.");
throw Error("nativeToHexString: Evmos not supported yet.");
} else if (chainId === CHAIN_ID_KUJIRA) {
throw Error("nativeToHexString: Kujira not supported yet.");
} else if (chainId === CHAIN_ID_SUI) {
if (!isValidSuiType(address) && isValidSuiAddress(address)) {
return uint8ArrayToHex(
zeroPad(arrayify(address, { allowMissingPrefix: true }), 32)
);
}
throw Error("hexToNativeString: Sui types not supported yet.");
throw Error("nativeToHexString: Sui types not supported yet.");
} else if (chainId === CHAIN_ID_BTC) {
throw Error("hexToNativeString: Btc not supported yet.");
throw Error("nativeToHexString: Btc not supported yet.");
} else if (chainId === CHAIN_ID_APTOS) {
if (isValidAptosType(address)) {
return getExternalAddressFromType(address);
@ -285,7 +290,7 @@ export const tryNativeToHexString = (
zeroPad(arrayify(address, { allowMissingPrefix: true }), 32)
);
} else if (chainId === CHAIN_ID_UNSET) {
throw Error("hexToNativeString: Chain id unset");
throw Error("nativeToHexString: Chain id unset");
} else {
// If this case is reached
const _: never = chainId;

View File

@ -34,6 +34,7 @@ export const CHAINS = {
wormchain: 3104,
cosmoshub: 4000,
evmos: 4001,
kujira: 4002,
sepolia: 10002,
} as const;
@ -84,6 +85,7 @@ export const CosmWasmChainNames = [
"osmosis",
"evmos",
"cosmoshub",
"kujira",
] as const;
export type CosmWasmChainName = typeof CosmWasmChainNames[number];
@ -292,6 +294,11 @@ const MAINNET = {
token_bridge: undefined,
nft_bridge: undefined,
},
kujira: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};
const TESTNET = {
@ -481,6 +488,11 @@ const TESTNET = {
token_bridge: undefined,
nft_bridge: undefined,
},
kujira: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};
const DEVNET = {
@ -669,6 +681,11 @@ const DEVNET = {
token_bridge: undefined,
nft_bridge: undefined,
},
kujira: {
core: undefined,
token_bridge: undefined,
nft_bridge: undefined,
},
};
/**
@ -745,6 +762,7 @@ 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_KUJIRA = CHAINS["kujira"];
export const CHAIN_ID_SEPOLIA = CHAINS["sepolia"];
// This inverts the [[CHAINS]] object so that we can look up a chain by id