@uniswap/token-lists#TokenInfo TypeScript Examples

The following examples show how to use @uniswap/token-lists#TokenInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hooks.ts    From interface-v2 with GNU General Public License v3.0 6 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(
      tokenInfo.chainId,
      tokenInfo.address,
      tokenInfo.decimals,
      tokenInfo.symbol,
      tokenInfo.name,
    );
    this.tokenInfo = tokenInfo;
    this.tags = tags;
  }
Example #2
Source File: buildLists.ts    From default-token-list with MIT License 6 votes vote down vote up
makeTokenList = (
  previousTokenList: TokenList | null,
  tokens: TokenInfo[]
): TokenList => {
  let timestamp: string = new Date().toISOString();
  if (process.env.CI) {
    if (!previousTokenList) {
      throw new Error("Token list not found");
    }
    // if in CI, use the timestamp generated from the previous process
    timestamp = previousTokenList.timestamp;
  }
  return {
    name: previousTokenList?.name ?? "Unknown List",
    logoURI: `${LOGO_URI_BASE}/logo.svg`,
    keywords: ["celo", "ubeswap", "defi"],
    timestamp,
    tokens,
    version: {
      major: parseInt(version[0]),
      minor: parseInt(version[1]),
      patch: parseInt(version[2]),
    },
  };
}
Example #3
Source File: hooks.ts    From luaswap-interface with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #4
Source File: hooks.ts    From goose-frontend-amm with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #5
Source File: hooks.ts    From goose-frontend-amm with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #6
Source File: hooks.ts    From pancake-swap-exchange-testnet with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #7
Source File: hooks.ts    From pancake-swap-exchange-testnet with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #8
Source File: hooks.ts    From panther-frontend-dex with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #9
Source File: hooks.ts    From panther-frontend-dex with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #10
Source File: hooks.ts    From forward.swaps with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #11
Source File: hooks.ts    From forward.swaps with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #12
Source File: hooks.ts    From glide-frontend with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #13
Source File: hooks.ts    From luaswap-interface with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #14
Source File: hooks.ts    From vvs-ui with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #15
Source File: hooks.ts    From vvs-ui with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #16
Source File: hooks.ts    From pancakeswap-testnet with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #17
Source File: hooks.ts    From pancakeswap-testnet with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #18
Source File: hooks.ts    From glide-frontend with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #19
Source File: hooks.ts    From cuiswap with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
  }
Example #20
Source File: wrappedTokenInfo.ts    From limit-orders-lib with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo;
Example #21
Source File: wrappedTokenInfo.ts    From limit-orders-lib with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, list: TokenList) {
    this.tokenInfo = tokenInfo;
    this.list = list;
  }
Example #22
Source File: Tokens.ts    From limit-orders-lib with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a filter function to apply to a token for whether it matches a particular search query
 * @param search the search query to apply to the token
 */
export function createTokenFilterFunction<T extends Token | TokenInfo>(
  search: string
): (tokens: T) => boolean {
  const searchingAddress = isAddress(search);

  if (searchingAddress) {
    const lower = searchingAddress.toLowerCase();
    return (t: T) =>
      "isToken" in t
        ? searchingAddress === t.address
        : lower === t.address.toLowerCase();
  }

  const lowerSearchParts = search
    .toLowerCase()
    .split(/\s+/)
    .filter((s) => s.length > 0);

  if (lowerSearchParts.length === 0) return alwaysTrue;

  const matchesSearch = (s: string): boolean => {
    const sParts = s
      .toLowerCase()
      .split(/\s+/)
      .filter((s) => s.length > 0);

    return lowerSearchParts.every(
      (p) =>
        p.length === 0 ||
        sParts.some((sp) => sp.startsWith(p) || sp.endsWith(p))
    );
  };

  return ({ name, symbol }: T): boolean =>
    Boolean((symbol && matchesSearch(symbol)) || (name && matchesSearch(name)));
}
Example #23
Source File: filtering.ts    From limit-orders-lib with GNU General Public License v3.0 5 votes vote down vote up
export function filterTokens<T extends Token | TokenInfo>(
  tokens: T[],
  search: string
): T[] {
  return tokens.filter(createTokenFilterFunction(search));
}
Example #24
Source File: filtering.ts    From limit-orders-lib with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a filter function to apply to a token for whether it matches a particular search query
 * @param search the search query to apply to the token
 */
export function createTokenFilterFunction<T extends Token | TokenInfo>(
  search: string
): (tokens: T) => boolean {
  const searchingAddress = isAddress(search);

  if (searchingAddress) {
    const lower = searchingAddress.toLowerCase();
    return (t: T) =>
      "isToken" in t
        ? searchingAddress === t.address
        : lower === t.address.toLowerCase();
  }

  const lowerSearchParts = search
    .toLowerCase()
    .split(/\s+/)
    .filter((s) => s.length > 0);

  if (lowerSearchParts.length === 0) return alwaysTrue;

  const matchesSearch = (s: string): boolean => {
    const sParts = s
      .toLowerCase()
      .split(/\s+/)
      .filter((s) => s.length > 0);

    return lowerSearchParts.every(
      (p) =>
        p.length === 0 ||
        sParts.some((sp) => sp.startsWith(p) || sp.endsWith(p))
    );
  };

  return ({ name, symbol }: T): boolean =>
    Boolean((symbol && matchesSearch(symbol)) || (name && matchesSearch(name)));
}
Example #25
Source File: hooks.ts    From dyp with Do What The F*ck You Want To Public License 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #26
Source File: hooks.ts    From dyp with Do What The F*ck You Want To Public License 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #27
Source File: hooks.ts    From cheeseswap-interface with GNU General Public License v3.0 5 votes vote down vote up
public readonly tokenInfo: TokenInfo
Example #28
Source File: hooks.ts    From cheeseswap-interface with GNU General Public License v3.0 5 votes vote down vote up
constructor(tokenInfo: TokenInfo, tags: TagInfo[]) {
    super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
    this.tokenInfo = tokenInfo
    this.tags = tags
  }
Example #29
Source File: buildLists.ts    From default-token-list with MIT License 5 votes vote down vote up
main = async () => {
  const allTokens = await Promise.all(
    rawTokens.map(async ({ logoURI: elLogoURI, logoFile, ...el }) => {
      const logoURI =
        elLogoURI ||
        (logoFile ? `${LOGO_URI_BASE}/assets/${logoFile}` : null) ||
        `${LOGO_URI_BASE}/assets/asset_${el.symbol.replace("xV1", "")}.png`;

      // Validate
      if (logoURI.startsWith(LOGO_URI_BASE)) {
        const logoPath = `${__dirname}/..${logoURI.substring(
          LOGO_URI_BASE.length
        )}`;
        const stat = await fs.stat(logoPath);
        if (!stat.isFile()) {
          throw new Error(
            `logo for ${el.address} on ${el.chainId} does not exist`
          );
        }
      }
      return {
        ...el,
        decimals: el.decimals || 18,
        logoURI,
        isExperimental: el.isExperimental,
      };
    })
  );

  const [mainTokenListTokens, experimentalTokenListTokens] = allTokens.reduce(
    ([mainTokens, experimentalTokens], { isExperimental, ...tok }) => {
      if (isExperimental !== true && tok.chainId === 42220) {
        return [
          [...mainTokens, tok],
          [...experimentalTokens, tok],
        ];
      } else {
        return [mainTokens, [...experimentalTokens, tok]];
      }
    },
    [[] as TokenInfo[], [] as TokenInfo[]]
  );

  const previousTokenList = requireOrNull(
    __dirname,
    "../ubeswap.token-list.json"
  );
  const previousExperimentalTokenList = requireOrNull(
    __dirname,
    "../ubeswap-experimental.token-list.json"
  );

  const tokenList = makeTokenList(previousTokenList, mainTokenListTokens);
  const experimentalTokenList = makeTokenList(
    previousExperimentalTokenList,
    experimentalTokenListTokens
  );

  await fs.writeFile(
    __dirname + "/../ubeswap.token-list.json",
    JSON.stringify(tokenList, null, 2)
  );

  await fs.writeFile(
    __dirname + "/../ubeswap-experimental.token-list.json",
    JSON.stringify(experimentalTokenList, null, 2)
  );
}