Source

types/OrderTypes.ts

import { AssetDetailsResponse } from "./AssetTypes";
import { PagingDataParams, TokenType } from "./CommonTypes";
import { FeeType } from "./MintTypes";

export * from "./AssetTypes";

/**
 * @typedef {Object} Fees
 * @property {string?} address Wallet address to receive the transaction fees
 * @property {number?} percentage Percentage of the fee per transactions that Developer/Partner/Holder wallet will receive
 * @property {FeeType} feeType Type of fee (eg: ROYALTY) and Myria is only supported ROYALTY fee at this version
 */
export interface Fees {
  address?: string;
  percentage?: number;
  feeType: FeeType;
}

/**
 * @typedef {enum} OrderType (BUY/SELL) 
 */
export enum OrderType {
  BUY = "BUY",
  SELL = "SELL",
}

/**
 * @typedef {enum} OrderStatus (INITIAL / ACTIVE / FILLED / FAILED / CANCELLED / INACTIVE / EXPIRED)
 */
export enum OrderStatus {
  INITIAL = "INITIAL",
  ACTIVE = "ACTIVE",
  FILLED = "FILLED",
  FAILED = "FAILED",
  CANCELLED = "CANCELLED",
  INACTIVE = "INACTIVE",
  EXPIRED = "EXPIRED",
}

/**
 * @typedef {enum} AssetOrderBy The order by of listed assets (ASC/DESC) in the created time
 */
export enum AssetOrderBy {
  ASC = "ASC",
  DESC = "DESC",
}

/**
 * @typedef {Object} QueryAssetParams
 * @property {OrderType?}   orderType The type of Order (BUY/SELL)
 * @property {OrderStatus?} status  The status of Order
 * @property {string?}      sortingField The field value for sorting
 * @property {string?}      orderBy The kind of order for querying data (ASC/DESC)
 */
export interface QueryAssetParams extends PagingDataParams {
  orderType?: OrderType;
  status?: OrderStatus;
  sortingField?: string | "amountSell"; // amountSell, amountBuy, orderType, status
  orderBy?: AssetOrderBy;
  listingAssetId?: string;
}

export interface CreateOrder {
  assetRefId: number; // id of asset for sale
  tokenId: string; // Token ID
  expirationTimestamp?: string;
  orderType: OrderType.BUY | OrderType.SELL; // SELL
  fees?: Fees[]; // []
  includeFees: boolean; // FALSE
  sellerStarkKey: string; //
  amountSell: number;
  amountBuy: number;
  nonce?: number; // 1000
  assetIdSell: string; // get from response of signable order
  assetIdBuy: string; // get from response of signable order
  vaultIdSell: number; // get from response of signable order
  vaultIdBuy: number; // get from response of signable order
}

export interface OrderHashType {
  includeFees: boolean;
  walletAddress: string;
  vaultIdSell: number;
  vaultIdBuy: number;
  amountSell: string;
  amountBuy: string;
  assetIdSell: string;
  assetIdBuy: string;
  nonce: number;
  expirationTimestamp: number;
  fee?: {
    feeToken: string;
    feeVaultId: number;
    feeLimit: string;
  }
}

/**
 * @typedef {Object} SplitSignature
 * @property {string} r the hex string of r
 * @property {string} s the hex string of s
 */
export interface SplitSignature {
  r: string;
  s: string;
}

export interface CreateOrderResponse {
  status: string;
  data: OrderEntity;
}

export interface CreateOrderAPIRequest {
  assetRefId?: number;
  expirationTimestamp: string;
  orderType: "BUY" | "SELL";
  fees: Fees[] | undefined;
  includeFees: boolean;
  assetIdSell?: string;
  quantizedAmountSell: number;
  assetIdBuy?: string;
  quantizedAmountBuy: number;
  starkKey: string;
  nonce?: number;
  vaultIdSell: number;
  vaultIdBuy: number;
  sellerAddress: string;
  starkSignature: SplitSignature;
  nonQuantizedAmountSell?: number;
  nonQuantizedAmountBuy?: number;
}

/**
 * @typedef {Object} CreateOrderV2Params
 * @property {string} ownerWalletAddress Eth wallet address of owner
 * @property {string} ownerStarkKey Stark key of owner
 * @property {string} assetRefId ID of unique asset in Marketplace 
 * @property {TokenType} tokenSell.tokenType Token type of sell asset Nfts (MINTABLE_ERC721)
 * @property {string} tokenSell.data.tokenId Token ID of asset for sale
 * @property {string} tokenSell.data.tokenAddress Token Address of assets for sale (Smart contract address of Collection)
 * @property {TokenType} tokenReceived.tokenType Token type of currency asset you'd to receive per order (ERC20 / ETH) 
 * - If you specify tokenReceived as ETH so you'll get ETH once your NFTs is purchased
 * - For Myria tokens, you can specify tokenReceived as ERC20 and use tokenAddress of Myria so you'll get MYRIA tokens once your NFTs is purchased
 * @property {string} price Price to set for your order
 * @property {FeeDto[]} fees The array of fees data for the asset that pursuing for listing - Normally, fees data will be fetchable from assets details {assets/{assetId}}
 */
export interface CreateOrderV2Params {
  orderType: OrderType;
  ownerWalletAddress: string;
  ownerStarkKey: string;
  assetRefId: number;
  tokenSell: {
    tokenType: TokenType;
    data: {
      tokenId: string;
      tokenAddress: string;
    }
  };
  tokenReceived: {
    tokenType: TokenType;
    data?: {
      tokenAddress: string;
    }
  };
  price: string;
  fees: FeeDto[];
}

export interface CreateOrderEntity {
  assetRefId?: number;
  expirationTimestamp?: string;
  orderType: "BUY" | "SELL";
  fees: Fees[] | undefined;
  feeSign?: {
    feeLimit: string;
    feeToken: string;
    feeVaultId: number;
  },
  includeFees: boolean;
  assetIdSell?: string;
  amountSell: number;
  assetIdBuy?: string;
  amountBuy: number;
  sellerStarkKey: string;
  nonce?: number;
  vaultIdSell: number;
  vaultIdBuy: number;
  sellerAddress: string;
}

export interface GetOrderById {
  id: number;
}

export interface DeleteOrderPayload {
  orderId: number;
  sellerWalletAddress: string;
  nonce?: number;
}

export interface DeleteOrderApiPayload {
  orderId: number;
  nonce: number;
  signature: SplitSignature | undefined;
}

/**
 * @typedef {Object} OrderEntity
 * @property {number} assetRefId Reference asset ID for listing in Marketplace
 * @property {OrderType} orderType Type of order (SELL/BUY) 
 * - SELL if order is listing for sale - BUY if order is purchased by users
 * @property {OrderStatus} status Status of order (ACTIVE/ CANCELLED/ FILLED/ INACTIVE)
 * @property {string} expiredAt Timestamp with string format to define the expiration of order (Default as 12 years)
 * @property {Fees[]} fees The list fees define for the order entity
 * @property {boolean} includeFees The flag to identify the order contains fee or not
 * @property {string} assetIdBuy The hex string of the token buy (ETH / ERC_20 / MYRIA_TOKEN)
 * @property {number} vaultIdBuy Vault ID of token buy (ETH /ERC_20 ex Myria, USDT tokens...)
 * @property {string} assetIdSell The hex string of the token sell (NFT / MINTABLE_ERC721 / ERC721)
 * @property {number} vaultIdSell Vault ID of token sell (it's MINTABLE_ERC721 / NFT)
 * @property {string} amountBuy The ETH price that owner set for the listing assets (quantized amount)
 * @property {string} amountSell The quantized amount sell of the assets (it's always 1 if asset is NFT - MINTABLE_ERC721/ERC_721) 
 * @property {string} nonQuantizedAmountBuy The ETH price that owner set for the listing assets (original amount)
 * + For example, if the asset is listing with 2 ETH (nonQuantizedAmountSell = 1, nonQuantizedAmountBuy = 2 ETH)
 * @property {string} nonQuantizedAmountSell The original amount token sell (it's always 1 if asset is NFT - MINTABLE_ERC721/ERC_721)
 * @property {string} starkKey Stark of current owner for NFTs
 * @property {string} nonce The unique nonce to identify the transaction creating order
 * @property {SplitSignature} starkSignature Stark's signature includes r and s hex to prove the owner of transaction for listing
 */
export interface OrderEntity {
  assetRefId: number;
  orderType: OrderType.BUY | OrderType.SELL;
  status:
    | OrderStatus.ACTIVE
    | OrderStatus.CANCELLED
    | OrderStatus.FILLED
    | OrderStatus.INACTIVE;
  expiredAt: string;
  fees: Array<Fees>;
  includeFees: boolean;
  assetIdBuy: string;
  vaultIdBuy: number;
  assetIdSell: string;
  vaultIdSell: number;
  amountSell: number;
  amountBuy: number;
  orderRequestId: string;
  nonQuantizedAmountSell: number;
  nonQuantizedAmountBuy: number;
  starkKey: string;
  nonce: number;
  starkSignature: string;
}

export interface TokenDataDto {
  tokenId?: string;
  tokenAddress?: string;
  blueprint?: string;
  quantum?: string;
}

export interface TokenDto {
  type: TokenType;
  data: TokenDataDto;
}
/**
 * @typedef {Object} FeeDto
 * @property {string} address Destination wallet address that fee'll be send to
 * @property {number} percentage Percentage of fee tokens that will be send per trade transaction
 * @property {FeeType} feeType Type of Fee - Myria only supported Royalty fee currently
 */
export interface FeeDto {
  address: string;
  percentage: number;
  feeType: FeeType;
}

export interface SignableOrderInput {
  orderType: string; // 'SELL'
  ethAddress: string; // 'WALLET ADDRESS'
  starkKey: string; // 'STARK KEY'
  tokenSell: TokenDto; // NFT {}
  amountSell: string; // 1
  tokenBuy: TokenDto; // ETH
  amountBuy: string; // PRICE - WHATEVER
  includeFees: boolean; // FALSE AS ALWAYS
  fees?: FeeDto[]; // [] AS always
  assetRefId?: number;
}

export interface SignableOrderResponse {
  status: string;
  data: SignableOrderResponseData;
}

export interface SignableOrderResponseData {
  starkKey: string;
  amountSell: number;
  quantizedAmountSell: string;
  assetIdSell: string;
  vaultIdSell: number;
  amountBuy: number;
  quantizedAmountBuy: string;
  assetIdBuy: string;
  vaultIdBuy: number;
  nonce?: number;
  feeInfo?: {
    feeLimit: string;
    assetId: string;
    sourceVaultId: number;
  }
}

export interface UpdateOrderPriceParams {
  newAmountBuy: string;
  sellerWalletAddress: string;
  sellerStarkKey: string;
  nonce?: string;
  expirationTimestamp?: number;
  tokenSell: TokenDto; // Token sell for NFTs
  tokenBuy: TokenDto; // Token buy for NFTs
  fees?: FeeDto[]; // [] AS always
}

export interface UpdateOrderPrice {
  expirationTimestamp: number;
  nonce: number;
  newAmountBuy: string;
  nonQuantizedAmountBuy: string;
  nonQuantizedAmountSell: string;
  includeFees?: boolean;
  fees?: FeeDto[];
  orderType: string;
  starkKey: string;
  starkSignatureSellOrder: SplitSignature;
  starkSignatureCancelOrder: SplitSignature;
}

export interface UpdateOrderPriceResponse {
  id: number;
  createdAt: string;
  updatedAt: string;
  assetRefId: number;
  orderType: OrderType.BUY | OrderType.SELL;
  status:
    | OrderStatus.ACTIVE
    | OrderStatus.CANCELLED
    | OrderStatus.FILLED
    | OrderStatus.INACTIVE;
  expiredAt: string;
  fees: Array<Fees>;
  includeFees: true;
  assetIdSell: null;
  vaultIdSell: number;
  amountSell: string;
  assetIdBuy: null;
  vaultIdBuy: number;
  amountBuy: string;
  starkKey: string;
  nonce: number;
  starkSignature: [];
  asset: AssetDetailsResponse;
  __entity: "OrderEntity";
}