agent0.ethpy.hyperdrive.assets ============================== .. py:module:: agent0.ethpy.hyperdrive.assets .. autoapi-nested-parse:: Hyperdrive AssetId classes and methods .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: agent0.ethpy.hyperdrive.assets.BASE_TOKEN_SYMBOL Classes ------- .. autoapisummary:: agent0.ethpy.hyperdrive.assets.AssetIdPrefix Functions --------- .. autoapisummary:: agent0.ethpy.hyperdrive.assets.encode_asset_id agent0.ethpy.hyperdrive.assets.decode_asset_id Module Contents --------------- .. py:data:: BASE_TOKEN_SYMBOL :value: 'WETH' .. py:class:: AssetIdPrefix Bases: :py:obj:`enum.IntEnum` The asset ID is used to encode the trade type in a transaction receipt .. !! processed by numpydoc !! .. py:attribute:: LP :value: 0 .. py:attribute:: LONG :value: 1 .. py:attribute:: SHORT :value: 2 .. py:attribute:: WITHDRAWAL_SHARE :value: 3 .. py:function:: 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. :param prefix: A one byte prefix that specifies the asset type. :type prefix: int :param timestamp: A timestamp associated with the asset. :type timestamp: int :returns: The asset ID. :rtype: int .. !! processed by numpydoc !! .. py:function:: 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. :param asset_id: Encoded ID from a transaction. It is a concatenation, [identifier: 8 bits][timestamp: 248 bits] :type asset_id: int :returns: identifier, timestamp :rtype: tuple[int, int] .. !! processed by numpydoc !!