agent0.ethpy.hyperdrive.assets

Hyperdrive AssetId classes and methods

Attributes

BASE_TOKEN_SYMBOL

Classes

AssetIdPrefix

The asset ID is used to encode the trade type in a transaction receipt

Functions

encode_asset_id(→ int)

Encodes a prefix and a timestamp into an asset ID.

decode_asset_id(→ tuple[int, int])

Decodes a transaction asset ID into its constituent parts of an identifier, data, and a timestamp.

Module Contents

agent0.ethpy.hyperdrive.assets.BASE_TOKEN_SYMBOL = 'WETH'
class agent0.ethpy.hyperdrive.assets.AssetIdPrefix

Bases: enum.IntEnum

The asset ID is used to encode the trade type in a transaction receipt

LP = 0
LONG = 1
SHORT = 2
WITHDRAWAL_SHARE = 3
agent0.ethpy.hyperdrive.assets.encode_asset_id(prefix: int, timestamp: int) int

Encodes a prefix and a timestamp into an asset ID.

Asset IDs are used so that LP, long, and short tokens can all be represented in a single MultiToken instance. The zero asset ID indicates the LP token.

Encode the asset ID by left-shifting the prefix by 248 bits, then bitwise-or-ing the result with the timestamp.

Parameters:
  • prefix (int) – A one byte prefix that specifies the asset type.

  • timestamp (int) – A timestamp associated with the asset.

Returns:

The asset ID.

Return type:

int

agent0.ethpy.hyperdrive.assets.decode_asset_id(asset_id: int) tuple[int, int]

Decodes a transaction asset ID into its constituent parts of an identifier, data, and a timestamp.

First calculate the prefix mask by left-shifting 1 by 248 bits and subtracting 1 from the result. This gives us a bit-mask with 248 bits set to 1 and the rest set to 0. Then apply this mask to the input ID using the bitwise-and operator & to extract the lower 248 bits as the timestamp.

Parameters:

asset_id (int) – Encoded ID from a transaction. It is a concatenation, [identifier: 8 bits][timestamp: 248 bits]

Returns:

identifier, timestamp

Return type:

tuple[int, int]