Identifiers for supported assets

The StarkEx API supports the following types of assets:

  • ETH

  • ERC-20

  • Synthetics

    In perpetual trading, synthetic assets are not represented onchain and thus the offchain asset ID representation is enough. The asset ID of a synthetic asset is a 120-bit number that represents their identity and resolution. For example, "ETH-8".encode('ascii') represents Ethereum with a resolution of \(10^8\).

StarkEx representation of onchain assets contracts

StarkEx contracts use the following terms:

selector

A 4-byte constant that specifies one of the following asset standards:

  • ETH

  • ERC-20

address

The address of the onchain contract for a givent asset type.

assetInfo

The string concatenation of selector and address. The assetInfo parameter enables StarkEx to redeem assets according to their initial standard.

The StarkEx system calculates the value for assetId as follows:

  1. assetId = assetType

  2. assetType = hash(assetInfo, quantum)

  3. assetInfo = L1_contract_address + erc_type (selector)

Computing assetInfo, assetType, and assetId

Below you can find a pseudo-code of the computation. For the full implementation, see asset.ts in the starkware-crypto-utils Github repository.

ETH

def getEthAssetInfo():
   ETH_SELECTOR = '0x8322fff2' # '0x8322fff2' = bytes4(keccak256(“ETH()”))
   asset_info = ETH_SELECTOR
   return asset_info


def getEthAssetType(quantum):
   asset_info = getEthAssetInfo()
   asset_type = keccak256(asset_info, quantum)
                & 0x03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
   return asset_type


def getEthAssetId(quantum):
   asset_id = getEthAssetType(quantum)
   return asset_id

ERC-20

def getErc20AssetInfo(address):
   ERC20_SELECTOR = '0xf47261b0'
   # '0xf47261b0' = bytes4(keccak256('ERC20Token(address)'))
   asset_info = ERC20_SELECTOR + bytes.fromhex(address[2:]).rjust(32, b'\0')
   # For ERC20, asset_info is 36 bytes long
   return asset_info


def getErc20AssetType(address, quantum):
   asset_info = getErc20AssetInfo(address)
   asset_type = keccak256(asset_info, quantum)
                & 0x03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
   return asset_type


def getErc20AssetId(quantum, address):
   asset_id = getErc20AssetType(quantum, address)
   return asset_id