UNPKG

@magiceden/magiceden-sdk

Version:

A TypeScript SDK for interacting with Magic Eden's API across multiple chains.

177 lines (176 loc) 9.1 kB
"use strict"; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.V3ApiClient = void 0; const types_1 = require("../../types"); const decorators_1 = require("../utils/decorators"); const base_1 = require("./base"); /** * V3 API client implementation (primarily for EVM chains) */ let V3ApiClient = (() => { var _a; let _classSuper = base_1.BaseApiClient; let _instanceExtraInitializers = []; let _placeBid_decorators; let _list_decorators; let _buy_decorators; let _sell_decorators; let _cancelOrder_decorators; let _transfer_decorators; let _order_decorators; return _a = class V3ApiClient extends _classSuper { constructor(options) { super(options); __runInitializers(this, _instanceExtraInitializers); } /** * Posts a place bid request to the v3 API. * * Used to place a bid on an NFT. */ placeBid(request) { return this.api.post(this.getRequestPath(request.chain, 'bid/v5'), { maker: request.maker, params: request.params, source: 'magiceden.io', }); } /** * Posts a list order request to the v3 API. * * Used to list an NFT for sale. */ list(request) { return this.api.post(this.getRequestPath(request.chain, 'list/v5'), { maker: request.maker, params: request.params, source: 'magiceden.io', }); } /** * Posts a buy order to the v3 API. * * Used to fill listings on an NFT. */ buy(request) { return this.api.post(this.getRequestPath(request.chain, 'buy/v7'), { taker: request.taker, items: request.items, source: 'magiceden.io', ...request.options, }); } /** * Posts a sell order to the v3 API. * * Used to accept bids on an NFT. */ sell(request) { return this.api.post(this.getRequestPath(request.chain, 'sell/v7'), { taker: request.taker, items: request.items, source: 'magiceden.io', ...request.options, }); } /** * Posts a cancel order request to the v3 API. * * Used to cancel an order (whether a listing, a bid, etc). */ cancelOrder(request) { return this.api.post(this.getRequestPath(request.chain, 'cancel/v3'), { orderIds: request.orderIds, source: 'magiceden.io', ...request.options, }); } /** * Posts a transfer request to the v3 API. * * Used to transfer one or more NFTs from one address to another. */ transfer(request) { return this.api.post(this.getRequestPath(request.chain, 'transfer/v1'), { to: request.to, from: request.from, items: request.items, source: 'magiceden.io', }); } /** * Posts an submit signed order request to the v3 API */ order(request) { return this.api.post(`/rtp/${request.chain}/order/v4?signature=${request.signature}`, { ...request.data, }); } getRequestPath(chain, path) { return `/rtp/${chain}/execute/${path}`; } /** * Gets the base URL for the v3 API * * @returns Base URL */ getBaseUrl() { // Same url for dev and prod return 'https://api-mainnet.magiceden.dev/v3'; } }, (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; _placeBid_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _list_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _buy_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _sell_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _cancelOrder_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _transfer_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; _order_decorators = [(0, decorators_1.supportedOn)([types_1.ChainType.EVM])]; __esDecorate(_a, null, _placeBid_decorators, { kind: "method", name: "placeBid", static: false, private: false, access: { has: obj => "placeBid" in obj, get: obj => obj.placeBid }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _list_decorators, { kind: "method", name: "list", static: false, private: false, access: { has: obj => "list" in obj, get: obj => obj.list }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _buy_decorators, { kind: "method", name: "buy", static: false, private: false, access: { has: obj => "buy" in obj, get: obj => obj.buy }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _sell_decorators, { kind: "method", name: "sell", static: false, private: false, access: { has: obj => "sell" in obj, get: obj => obj.sell }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _cancelOrder_decorators, { kind: "method", name: "cancelOrder", static: false, private: false, access: { has: obj => "cancelOrder" in obj, get: obj => obj.cancelOrder }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _transfer_decorators, { kind: "method", name: "transfer", static: false, private: false, access: { has: obj => "transfer" in obj, get: obj => obj.transfer }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_a, null, _order_decorators, { kind: "method", name: "order", static: false, private: false, access: { has: obj => "order" in obj, get: obj => obj.order }, metadata: _metadata }, null, _instanceExtraInitializers); if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); })(), _a; })(); exports.V3ApiClient = V3ApiClient;