Skip to content

Commit

Permalink
getAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 9, 2024
1 parent 387418b commit 0f5a289
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions v2/lib/addresses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getChainId } from "@zetachain/networks";

import mainnet from "../data/addresses.mainnet.json";
import testnet from "../data/addresses.testnet.json";
import { ParamChainName, ParamSymbol, ParamType } from "./types";

export const getAddress = (type: ParamType, network: ParamChainName, symbol?: ParamSymbol) => {
const networks = [...testnet, ...mainnet];
let address;
if (type !== "zrc20" && symbol) {
throw new Error("Symbol is only supported when ParamType is zrc20");
}
if (type === "zrc20" && !symbol) {
// for backwards compatibility
const chainId = getChainId(network);
address = networks.find((n: any) => {
return n.foreign_chain_id === chainId?.toString() && n.type === type && n.coin_type === "gas";
});
} else {
address = networks.find((n: any) => {
return n.chain_name === network && n.type === type && n.symbol === symbol;
});
}
return address?.address;
};

0 comments on commit 0f5a289

Please sign in to comment.