Skip to content

Commit

Permalink
clients/js: remove the unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
panoel committed Jun 12, 2024
1 parent 9ab14ab commit 3fba783
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 278 deletions.
1 change: 0 additions & 1 deletion clients/js/src/algorand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Network,
toChainId,
} from "@wormhole-foundation/sdk-base";
import { encoding } from "@wormhole-foundation/sdk";

export async function execute_algorand(
payload: Payload,
Expand Down
53 changes: 1 addition & 52 deletions clients/js/src/chains/generic/getOriginalAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
Chain,
ChainId,
Network,
chainToChainId,
chainToPlatform,
contracts,
toChain,
Expand All @@ -34,9 +33,8 @@ import algorand from "@wormhole-foundation/sdk/algorand";
import aptos from "@wormhole-foundation/sdk/aptos";
import cosmwasm from "@wormhole-foundation/sdk/cosmwasm";
import sui from "@wormhole-foundation/sdk/sui";
// import { WormholeWrappedInfo } from "@certusone/wormhole-sdk";

export const getOriginalAsset_old = async (
export const getOriginalAsset = async (
chain: ChainId | Chain,
network: Network,
assetAddress: string,
Expand Down Expand Up @@ -92,13 +90,6 @@ export const getOriginalAsset_old = async (
assetAddress,
toChainId(chain)
);
// const wh = await wormhole(network, [evm]);
// const asset = Wormhole.tokenId(chainName, assetAddress);
// const tokenId = await wh.getOriginalAsset(asset);
// let wwi: WormholeWrappedInfo = {
// chainId: chainToChainId(chainName),
// tokenId: tokenId,
// };
}
case "Terra":
case "Terra2": {
Expand Down Expand Up @@ -156,45 +147,3 @@ export const getOriginalAsset_old = async (
impossible(chainName);
}
};

export const getOriginalAsset_new = async (
chain: ChainId | Chain,
network: Network,
assetAddress: string
): Promise<TokenId> => {
const chainName = toChain(chain);
const asset = Wormhole.tokenId(chainName, assetAddress);
const platform = chainToPlatform(chainName);
let wh;
wh = await wormhole(network, [solana, evm, algorand, aptos, cosmwasm, sui]);
// switch (platform) {
// case "Solana": {
// wh = await wormhole(network, [solana]);
// }
// case "Evm": {
// wh = await wormhole(network, [evm]);
// }
// case "Algorand": {
// wh = await wormhole(network, [algorand]);
// }
// case "Aptos": {
// wh = await wormhole(network, [aptos]);
// }
// case "Btc": {
// wh = await wormhole(network, [btc]);
// }
// case "Cosmwasm": {
// wh = await wormhole(network, [cosmwasm]);
// }
// case "Near": {
// wh = await wormhole(network, [near]);
// }
// case "Sui": {
// wh = await wormhole(network, [sui]);
// }
// }
// if (wh) {
return wh.getOriginalAsset(asset);
// }
throw new Error(`${platform} not supported`);
};
4 changes: 2 additions & 2 deletions clients/js/src/cmds/info/origin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yargs from "yargs";
import { getOriginalAsset_old } from "../../chains/generic";
import { getOriginalAsset } from "../../chains/generic";
import { CHAIN_ID_OR_NAME_CHOICES, RPC_OPTIONS } from "../../consts";
import { getNetwork } from "../../utils";
import { tryUint8ArrayToNative } from "../../sdk/array";
Expand Down Expand Up @@ -34,7 +34,7 @@ export const handler = async (
console.warn = () => {};

const network = getNetwork(argv.network);
const res = await getOriginalAsset_old(argv.chain, network, argv.address);
const res = await getOriginalAsset(argv.chain, network, argv.address);
console.log({
...res,
assetAddress: tryUint8ArrayToNative(res.assetAddress, toChain(res.chainId)),
Expand Down
4 changes: 3 additions & 1 deletion clients/js/src/cmds/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ethers } from "ethers";
import { NETWORKS } from "../consts";
import { chainToChain, getNetwork } from "../utils";
import { Chain, assertChain, contracts } from "@wormhole-foundation/sdk-base";
import { relayer } from "@certusone/wormhole-sdk";

export const command = "status <network> <chain> <tx>";
export const desc =
Expand Down Expand Up @@ -46,12 +47,13 @@ export const handler = async (
);
}

// TODO: Convert this over to sdkv2
// const info = await relayer.getWormholeRelayerInfo(chain, argv.tx, {
// environment: network,
// sourceChainProvider,
// targetChainProviders,
// });

// console.log(relayer.stringifyWormholeRelayerInfo(info));

console.log("Not implemented");
};
14 changes: 0 additions & 14 deletions clients/js/src/sdk/algorand.ts

This file was deleted.

191 changes: 22 additions & 169 deletions clients/js/src/sdk/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ import {
sha256,
stripZeros,
} from "ethers/lib/utils";
// import { Provider as NearProvider } from "near-api-js/lib/providers";
// import { ethers } from "ethers";
import {
nativeStringToHexAlgorand,
// hexToNativeAssetStringAlgorand,
// nativeStringToHexAlgorand,
uint8ArrayToNativeStringAlgorand,
} from "./algorand";
import { bech32 } from "bech32";
// import { canonicalAddress, humanAddress } from "./cosmos";
// import { buildTokenId } from "./cosmwasm/address";
// import { isNativeDenom } from "./terra";
// import { hashLookup } from "./near";
// import { getExternalAddressFromType, isValidAptosType } from "./aptos";
// import { isValidSuiAddress } from "@mysten/sui.js";
// import { isValidSuiType } from "./sui";
import {
Chain,
ChainId,
Expand All @@ -34,31 +19,33 @@ import {
import {
PlatformToChains,
UniversalAddress,
// canonicalAddress,
encoding,
platformToChains,
} from "@wormhole-foundation/sdk";
import { isValidSuiAddress } from "@mysten/sui.js";
import { sha3_256 } from "js-sha3";
import { isValidSuiType } from "./sui";
import {
nativeStringToHexAlgorand,
uint8ArrayToNativeStringAlgorand,
} from "@certusone/wormhole-sdk/lib/esm/algorand";
import { isValidSuiType } from "@certusone/wormhole-sdk/lib/esm/sui";

// /**
// *
// * Returns true iff the hex string represents a native Terra denom.
// *
// * Native assets on terra don't have an associated smart contract address, just
// * like eth isn't an ERC-20 contract on Ethereum.
// *
// * The difference is that the EVM implementations of Portal don't support eth
// * directly, and instead require swapping to an ERC-20 wrapped eth (WETH)
// * contract first.
// *
// * The Terra implementation instead supports Terra-native denoms without
// * wrapping to CW-20 token first. As these denoms don't have an address, they
// * are encoded in the Portal payloads by the setting the first byte to 1. This
// * encoding is safe, because the first 12 bytes of the 32-byte wormhole address
// * space are not used on Terra otherwise, as cosmos addresses are 20 bytes wide.
// */
/**
*
* Returns true iff the hex string represents a native Terra denom.
*
* Native assets on terra don't have an associated smart contract address, just
* like eth isn't an ERC-20 contract on Ethereum.
*
* The difference is that the EVM implementations of Portal don't support eth
* directly, and instead require swapping to an ERC-20 wrapped eth (WETH)
* contract first.
*
* The Terra implementation instead supports Terra-native denoms without
* wrapping to CW-20 token first. As these denoms don't have an address, they
* are encoded in the Portal payloads by the setting the first byte to 1. This
* encoding is safe, because the first 12 bytes of the 32-byte wormhole address
* space are not used on Terra otherwise, as cosmos addresses are 20 bytes wide.
*/
export const isHexNativeTerra = (h: string): boolean => h.startsWith("01");

const isLikely20ByteCosmwasm = (h: string): boolean =>
Expand Down Expand Up @@ -97,20 +84,6 @@ export function buildTokenId(
);
}

// export function buildTokenId_old(
// chain: Exclude<
// CosmWasmChainId | CosmWasmChainName,
// typeof CHAIN_ID_TERRA | "terra"
// >,
// address: string
// ) {
// const chainId: CosmWasmChainId = coalesceCosmWasmChainId(chain);
// return (
// (isNativeCosmWasmDenom(chainId, address) ? "01" : "00") +
// keccak256(Buffer.from(address, "utf-8")).substring(4)
// );
// }

/**
*
* Convert an address in a wormhole's 32-byte array representation into a chain's
Expand Down Expand Up @@ -192,18 +165,6 @@ export const tryUint8ArrayToNative = (
}
};

// export const tryHexToNativeStringNear = async (
// provider: NearProvider,
// tokenBridge: string,
// address: string
// ): Promise<string> => {
// const { found, value } = await hashLookup(provider, tokenBridge, address);
// if (!found) {
// throw new Error("Address not found");
// }
// return value;
// };

/**
*
* Convert an address in a wormhole's 32-byte hex representation into a chain's native
Expand All @@ -217,59 +178,6 @@ export const tryHexToNativeAssetString = (h: string, c: ChainId): string =>
new UniversalAddress(h).toNative("Algorand").toBigInt().toString()
: new UniversalAddress(h).toNative(toChain(c)).toString();

// /**
// *
// * Convert an address in a wormhole's 32-byte hex representation into a chain's native
// * string representation.
// *
// * @deprecated since 0.3.0, use [[tryHexToNativeString]] instead.
// */
// export const hexToNativeAssetString = (
// h: string | undefined,
// c: ChainId
// ): string | undefined => {
// if (!h) {
// return undefined;
// }
// try {
// return tryHexToNativeAssetString(h, c);
// } catch (e) {
// return undefined;
// }
// };

// /**
// *
// * Convert an address in a wormhole's 32-byte hex representation into a chain's native
// * string representation.
// *
// * @throws if address is not the right length for the given chain
// */
// export const tryHexToNativeString = (h: string, c: ChainId | Chain): string =>
// tryUint8ArrayToNative(hexToUint8Array(h), c);

// /**
// *
// * Convert an address in a wormhole's 32-byte hex representation into a chain's native
// * string representation.
// *
// * @deprecated since 0.3.0, use [[tryHexToNativeString]] instead.
// */
// export const hexToNativeString = (
// h: string | undefined,
// c: ChainId | Chain
// ): string | undefined => {
// if (!h) {
// return undefined;
// }

// try {
// return tryHexToNativeString(h, c);
// } catch (e) {
// return undefined;
// }
// };

/**
*
* Convert an address in a chain's native representation into a 32-byte hex string
Expand Down Expand Up @@ -331,24 +239,6 @@ export const tryNativeToHexString = (
}
};

// /**
// *
// * Convert an address in a chain's native representation into a 32-byte hex string
// * understood by wormhole.
// *
// * @deprecated since 0.3.0, use [[tryNativeToHexString]] instead.
// * @throws if address is a malformed string for the given chain id
// */
// export const nativeToHexString = (
// address: string | undefined,
// chain: ChainId | Chain
// ): string | null => {
// if (!address) {
// return null;
// }
// return tryNativeToHexString(address, chain);
// };

/**
*
* Convert an address in a chain's native representation into a 32-byte array
Expand All @@ -364,43 +254,6 @@ export function tryNativeToUint8Array(
return hexToUint8Array(tryNativeToHexString(address, chainId));
}

// /**
// *
// * Convert an address in a chain's native representation into a 32-byte hex string
// * understood by wormhole.
// *
// * @deprecated since 0.3.0, use [[tryUint8ArrayToNative]] instead.
// * @throws if address is a malformed string for the given chain id
// */
// export const uint8ArrayToNative = (a: Uint8Array, chainId: ChainId) =>
// hexToNativeString(uint8ArrayToHex(a), chainId);

// export function chunks<T>(array: T[], size: number): T[][] {
// return Array.apply<number, T[], T[][]>(
// 0,
// new Array(Math.ceil(array.length / size))
// ).map((_, index) => array.slice(index * size, (index + 1) * size));
// }

// export function textToHexString(name: string): string {
// return Buffer.from(name, "binary").toString("hex");
// }

// export function textToUint8Array(name: string): Uint8Array {
// return new Uint8Array(Buffer.from(name, "binary"));
// }

// export function hex(x: string): Buffer {
// return Buffer.from(
// ethers.utils.hexlify(x, { allowMissingPrefix: true }).substring(2),
// "hex"
// );
// }

// export function ensureHexPrefix(x: string): string {
// return x.substring(0, 2) !== "0x" ? `0x${x}` : x;
// }

export const isNativeDenomInjective = (denom: string) => denom === "inj";
export const isNativeDenomXpla = (denom: string) => denom === "axpla";
export const isNativeDenomSei = (denom: string) => denom === "usei";
Expand Down
Loading

0 comments on commit 3fba783

Please sign in to comment.