UNPKG

myria-core-sdk

Version:

Latest version SDK

109 lines (101 loc) 4.81 kB
import { CreateOrderEntity, CreateOrderV2Params, UpdateOrderPriceParams, UpdateOrderPriceResponse } from "../types/OrderTypes"; import { IMyriaClient } from "../clients/MyriaClient"; import { DeleteOrderPayload, GetOrderById, OrderEntity, SignableOrderInput, SignableOrderResponseData } from "../types/OrderTypes"; import { APIResponseType } from "../types/APIResponseType"; /** * Create OrderManager instance object * @class OrderManager * @param {MyriaClient} MyriaClient Interface of Myria Client * @example <caption>Constructor for OrderManager</caption> * * // Approach #1 const mClient: IMyriaClient = { networkId: Network.SEPOLIA, provider: web3Instance.currentProvider, web3: web3Instance, env: EnvTypes.STAGING, }; const moduleFactory = ModuleFactory.getInstance(mClient); const orderManager = moduleFactory.getOrderManager(); // Approach #2 const mClient: IMyriaClient = { networkId: Network.SEPOLIA, provider: web3Instance.currentProvider, web3: web3Instance, env: EnvTypes.STAGING, }; const myriaClient = new MyriaClient(mClient); const orderManager = new OrderManager(myriaClient); */ export declare class OrderManager { private orderAPI; private myriaClient; private commonModule; private commonAPI; private transactionManager; constructor(mClient: IMyriaClient); /** * @summary Create order V2 (supported both of listing NFTs by ETH/MYR) * @param {CreateOrderV2Params} params Create order v2 params including the price/nft/assets information * @returns {OrderEntity} Details order information including fees and Asset_ID_Buy/Asset_ID_Sell/AmountBuy/AmountSell * @throws {string} Exception: Order type is required * @throws {string} Exception: Owner wallet address is required * @throws {string} Exception: Owner stark key is required * @throws {string} Exception: Price must be define and must be > 0 * @throws {string} Exception: Asset Ref ID in Marketplace is required * @throws {string} Exception: Order is only supported for MINTABLE_ERC721 * @throws {string} Exception: Token address is required for listing MINTABLE_ERC721 * @throws {string} Exception: Token ID is required for listing MINTABLE_ERC721 * @throws {string} Exception: Required the token received to be well-defined and tokenAddress is mandatory * @throws {string} Exception: New listing method for ERC20 isn't available on Mainnet yet. Please try with Testnet only. * @example <caption>Sample of createOrderV2({}) on Staging env</caption> * * const mClient: IMyriaClient = { networkId: Network.SEPOLIA, provider: web3Instance.currentProvider, web3: web3Instance, env: EnvTypes.STAGING, }; const orderManager: OrderManager = new OrderManager(mClient); // Define createOrderV2 params const feeData: FeeDto[] = [ { feeType: AssetDetailsInfo?.fee?.[0].feeType, // FeeType in asset details info percentage: AssetDetailsInfo?.fee?.[0].feeType, // Percentage of Fee as apart of asset details info address: AssetDetailsInfo?.fee?.[0].address, // The destination wallet address which would receive the percentage of Fee }, ]; const paramCreateOrder: CreateOrderV2Params = { orderType: OrderType.SELL, ownerWalletAddress: 'owner_wallet_address_that_own_nft', ownerStarkKey: 'owner_stark_key_0x...', assetRefId: 'Reference asset ID that intend to listing', tokenSell: { tokenType: TokenType.MINTABLE_ERC721, data: { tokenId: 'id of token', tokenAddress: 'token address of NFT', }, }, tokenReceived: { tokenType: 'TokenType.ETH or TokenType.ERC20', data: { tokenAddress: 'token address of currency', }, }, price: "100", // Set the price for the NFTs fees: feeData, // Only having data or undefined }; const createdOrderResponse: OrderEntity = await orderManager.createOrderV2(paramCreateOrder); console.log("Order details response:"); console.log(JSON.stringify(data, null, 2)); */ createOrderV2(params: CreateOrderV2Params): Promise<OrderEntity>; createOrder(payload: CreateOrderEntity): Promise<OrderEntity>; signableOrder(payload: SignableOrderInput): Promise<SignableOrderResponseData>; getOrders(): Promise<OrderEntity[]>; getOrderById(payload: GetOrderById): Promise<OrderEntity>; deleteOrderById(payload: DeleteOrderPayload): Promise<OrderEntity>; updateOrderPrice(orderId: string, payload: UpdateOrderPriceParams): Promise<APIResponseType<UpdateOrderPriceResponse> | undefined>; }