Calculate token omni address

When you deposit a token via HOT Bridge on NEAR Intents, its address will be deterministically altered from the original on-chain format. To compute the omni format, you can use the TypeScript library @hot-labs/omni-sdk.

Types
Format
How calculate

Onchain

any chain-specific format

HOT Bridge

v2_1.omni.hot.tg:CHAIN_BASE58

utils.toOmni

NEAR Intents

nep245:v2_1.omni.hot.tg:CHAIN_BASE58

utils.toOmniIntent

Stellar tokens

Stellar has two types of tokens:

  1. Classic Assets (G-address issuer): Use Asset.contractId() to derive the Soroban contract ID

  2. Native Soroban Contracts (C-address): Use the contract address directly

Classic Assets (G-address issuer)

In the Stellar blockchain, there's an additional complexity. The blockchain features high-level Assets, accessible through an Issuer contract and symbol. However, HOT Bridge interacts with the token contract instead. This contract can be obtained via asset.contractId(Networks.PUBLIC) and this address must be converted to an HOT Bridge address.

import { utils, Network, HotBridge } from "@hot-labs/omni-sdk";
import { Asset, Networks } from "@stellar/stellar-sdk";

const main = async () => {
  // symbol + issuer
  const asset = new Asset("CETES", "GCRYUGD5NVARGXT56XEZI5CIFCQETYHAPQQTHO2O3IQZTHDH4LATMYWC");

  // Convert contractId to omni address (NOT ISSUER!)
  const omniAddress = utils.toOmniIntent(Network.Stellar, asset.contractId(Networks.PUBLIC));
  console.log(omniAddress);

  // How to convert omni address to asset?
  const hotBridge = new HotBridge({});
  const [stellarChainId, tokenContractAddress] = utils.fromOmni(omniAddress).split(":"); // 1100:ADDRESS

  // Get asset from contract id
  const assetFromOmniId = await hotBridge.stellar.getAssetFromContractId(tokenContractAddress);

  // Check if the asset is the same
  console.log(assetFromOmniId.contractId(Networks.PUBLIC) === asset.contractId(Networks.PUBLIC));
};

main();

Native Soroban Contracts (C-address)

Last updated