Skip to content

A library to (de)serialize cbor from different DEXes (decentralized exchanges) to specific types for order transaction construction.

License

Notifications You must be signed in to change notification settings

will-break-it/dex-order-serialization-lib

Repository files navigation

DEX Order Serialization Library

This library serves as serialization library for Cardano's decentralized exchanges (DEXs). It offers types to simplify the transaction construction and cbor encoding for datums and redeemers to place an order for a specfic DEX. Furthermore, its types are also able to read in cbor and decode it to corresponding types, if valid.

Type structure

As this library supports decoding from and encoding to cbor, there are generally two types per datum and redeemer. One for constructing and encoding, which this library refers to as builder type. And another one for decoding hex-encoded cbor to a specific type, which this library names decoder.

Builder type

Every builder type follows the same pattern inspired by cardano-serialization-lib (CSL) as follows:

Example for creating an IAssetClass:

const minswapAC: IAssetClass = AssetClassBuilder.new()
  .currencySymbol('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6')
  .tokenName('4d494e')
  .build();

const plutusData: PlutusData = minswapAC.encode();
const cborBytes: UInt8Array = plutusData.to_bytes();
const cborHex: string = toHex(plutusData.to_bytes());

Decoder type

A decoder usually takes no arguments to be constructed and offers a decode method.

Example for decoding an IAssetClass:

try {
  const minswap: IAssetClass = new AssetClassDecoder()
    .decode('29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c6434d494e');
} catch (e) {
  /* invalid asset class cbor passed */
}

Further DEX-specific Documentation

More specific examples related to orders for each DEX can be found under the following links:

About

A library to (de)serialize cbor from different DEXes (decentralized exchanges) to specific types for order transaction construction.

Resources

License

Stars

Watchers

Forks

Packages