sdk/js: Add wormhole chain
This commit is contained in:
parent
13a18d2f7e
commit
f64703c815
|
@ -1,6 +1,6 @@
|
||||||
import { zeroPad } from "ethers/lib/utils";
|
import { zeroPad } from "ethers/lib/utils";
|
||||||
import { tryUint8ArrayToNative } from "./array";
|
|
||||||
import { canonicalAddress } from "../cosmos";
|
import { canonicalAddress } from "../cosmos";
|
||||||
|
import { tryUint8ArrayToNative, tryNativeToHexString } from "./array";
|
||||||
|
|
||||||
test("terra address conversion", () => {
|
test("terra address conversion", () => {
|
||||||
const human = "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v";
|
const human = "terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v";
|
||||||
|
@ -18,3 +18,12 @@ test("terra address conversion", () => {
|
||||||
expect(nativeContract).toBe(nativeContract);
|
expect(nativeContract).toBe(nativeContract);
|
||||||
// TODO: native to hex is wrong, which we should correct
|
// TODO: native to hex is wrong, which we should correct
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("wormchain address conversion", () => {
|
||||||
|
const human = "wormhole1ap5vgur5zlgys8whugfegnn43emka567dtq0jl";
|
||||||
|
const canonical = "000000000000000000000000e868c4707417d0481dd7e213944e758e776ed35e";
|
||||||
|
const native = tryUint8ArrayToNative(new Uint8Array(Buffer.from(canonical, "hex")), "wormholechain");
|
||||||
|
expect(native).toBe(human);
|
||||||
|
|
||||||
|
expect(tryNativeToHexString(human, "wormholechain")).toBe(canonical)
|
||||||
|
});
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
CHAIN_ID_SOLANA,
|
CHAIN_ID_SOLANA,
|
||||||
CHAIN_ID_TERRA,
|
CHAIN_ID_TERRA,
|
||||||
CHAIN_ID_TERRA2,
|
CHAIN_ID_TERRA2,
|
||||||
|
CHAIN_ID_WORMHOLE_CHAIN,
|
||||||
CHAIN_ID_UNSET,
|
CHAIN_ID_UNSET,
|
||||||
coalesceChainId,
|
coalesceChainId,
|
||||||
isEVMChain,
|
isEVMChain,
|
||||||
|
@ -89,6 +90,9 @@ export const tryUint8ArrayToNative = (
|
||||||
}
|
}
|
||||||
} else if (chainId === CHAIN_ID_ALGORAND) {
|
} else if (chainId === CHAIN_ID_ALGORAND) {
|
||||||
return uint8ArrayToNativeStringAlgorand(a);
|
return uint8ArrayToNativeStringAlgorand(a);
|
||||||
|
} else if (chainId == CHAIN_ID_WORMHOLE_CHAIN) {
|
||||||
|
// wormhole-chain addresses are always 20 bytes.
|
||||||
|
return humanAddress("wormhole", a.slice(-20));
|
||||||
} else if (chainId === CHAIN_ID_NEAR) {
|
} else if (chainId === CHAIN_ID_NEAR) {
|
||||||
throw Error("uint8ArrayToNative: Near not supported yet.");
|
throw Error("uint8ArrayToNative: Near not supported yet.");
|
||||||
} else if (chainId === CHAIN_ID_INJECTIVE) {
|
} else if (chainId === CHAIN_ID_INJECTIVE) {
|
||||||
|
@ -207,6 +211,8 @@ export const tryNativeToHexString = (
|
||||||
return buildTokenId(address);
|
return buildTokenId(address);
|
||||||
} else if (chainId === CHAIN_ID_ALGORAND) {
|
} else if (chainId === CHAIN_ID_ALGORAND) {
|
||||||
return nativeStringToHexAlgorand(address);
|
return nativeStringToHexAlgorand(address);
|
||||||
|
} else if (chainId == CHAIN_ID_WORMHOLE_CHAIN) {
|
||||||
|
return uint8ArrayToHex(zeroPad(canonicalAddress(address), 32));
|
||||||
} else if (chainId === CHAIN_ID_NEAR) {
|
} else if (chainId === CHAIN_ID_NEAR) {
|
||||||
throw Error("hexToNativeString: Near not supported yet.");
|
throw Error("hexToNativeString: Near not supported yet.");
|
||||||
} else if (chainId === CHAIN_ID_INJECTIVE) {
|
} else if (chainId === CHAIN_ID_INJECTIVE) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ export const CHAINS = {
|
||||||
gnosis: 25,
|
gnosis: 25,
|
||||||
pythnet: 26,
|
pythnet: 26,
|
||||||
ropsten: 10001,
|
ropsten: 10001,
|
||||||
|
wormholechain: 3104,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type ChainName = keyof typeof CHAINS;
|
export type ChainName = keyof typeof CHAINS;
|
||||||
|
@ -209,6 +210,11 @@ const MAINNET = {
|
||||||
token_bridge: undefined,
|
token_bridge: undefined,
|
||||||
nft_bridge: undefined,
|
nft_bridge: undefined,
|
||||||
},
|
},
|
||||||
|
wormholechain: {
|
||||||
|
core: undefined,
|
||||||
|
token_bridge: undefined,
|
||||||
|
nft_bridge: undefined,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const TESTNET = {
|
const TESTNET = {
|
||||||
|
@ -353,6 +359,11 @@ const TESTNET = {
|
||||||
token_bridge: "0xF174F9A837536C449321df1Ca093Bb96948D5386",
|
token_bridge: "0xF174F9A837536C449321df1Ca093Bb96948D5386",
|
||||||
nft_bridge: "0x2b048Da40f69c8dc386a56705915f8E966fe1eba",
|
nft_bridge: "0x2b048Da40f69c8dc386a56705915f8E966fe1eba",
|
||||||
},
|
},
|
||||||
|
wormholechain: {
|
||||||
|
core: undefined,
|
||||||
|
token_bridge: undefined,
|
||||||
|
nft_bridge: undefined,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEVNET = {
|
const DEVNET = {
|
||||||
|
@ -497,6 +508,11 @@ const DEVNET = {
|
||||||
token_bridge: undefined,
|
token_bridge: undefined,
|
||||||
nft_bridge: undefined,
|
nft_bridge: undefined,
|
||||||
},
|
},
|
||||||
|
wormholechain: {
|
||||||
|
core: "wormhole1ap5vgur5zlgys8whugfegnn43emka567dtq0jl",
|
||||||
|
token_bridge: "wormhole1zugu6cajc4z7ue29g9wnes9a5ep9cs7yu7rn3z",
|
||||||
|
nft_bridge: undefined,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -565,6 +581,7 @@ export const CHAIN_ID_OPTIMISM = CHAINS["optimism"];
|
||||||
export const CHAIN_ID_GNOSIS = CHAINS["gnosis"];
|
export const CHAIN_ID_GNOSIS = CHAINS["gnosis"];
|
||||||
export const CHAIN_ID_PYTHNET = CHAINS["pythnet"];
|
export const CHAIN_ID_PYTHNET = CHAINS["pythnet"];
|
||||||
export const CHAIN_ID_ETHEREUM_ROPSTEN = CHAINS["ropsten"];
|
export const CHAIN_ID_ETHEREUM_ROPSTEN = CHAINS["ropsten"];
|
||||||
|
export const CHAIN_ID_WORMHOLE_CHAIN = CHAINS["wormholechain"];
|
||||||
|
|
||||||
// This inverts the [[CHAINS]] object so that we can look up a chain by id
|
// This inverts the [[CHAINS]] object so that we can look up a chain by id
|
||||||
export type ChainIdToName = {
|
export type ChainIdToName = {
|
||||||
|
|
Loading…
Reference in New Issue