UNPKG

@magiceden/magiceden-sdk

Version:

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

154 lines (153 loc) 6.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EvmNftService = void 0; const base_1 = require("./base"); const nft_1 = require("../../mappers/nft"); const transactions_1 = require("../../adapters/transactions"); const helpers_1 = require("../../helpers"); /** * EVM-specific NFT service implementation */ class EvmNftService extends base_1.BaseNftService { constructor(config) { super(config); } /** * Get publish launchpad response from API * * Not supported on EVM * @param params Publish launchpad parameters */ async getPublishLaunchpadResponse(params) { // TODO: We should move this into the createLaunchpadOperations // This way we will do the create + publish in one go, rather than two separate calls throw new Error('Not supported on EVM'); } /** * Get create launchpad operations from API * @param params Launchpad creation parameters */ async getCreateLaunchpadOperations(params) { const response = await this.v4ApiClient.createLaunchpad(nft_1.EvmApiMappers.v4.createLaunchpadRequest(params)); return transactions_1.EvmTransactionAdapters.fromV4TransactionResponse(response); } /** * Get update launchpad operations from API * @param params Launchpad update parameters */ async getUpdateLaunchpadOperations(params) { const response = await this.v4ApiClient.updateLaunchpad({ ...nft_1.EvmApiMappers.v4.updateLaunchpadRequest(params), ...(await (0, helpers_1.createEvmLaunchpadAuthorizationPayload)(this.config.wallet)), }); return transactions_1.EvmTransactionAdapters.fromV4TransactionResponse(response); } /** * Get mint operations from API * @param params Mint parameters */ async getMintOperations(params) { const response = await this.v4ApiClient.mint(nft_1.EvmApiMappers.v4.mintRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV4TransactionResponse(response); } /** * Get list operations from API * @param params Listing parameters */ async getListOperations(params) { const response = await this.v3ApiClient.list(nft_1.EvmApiMappers.v3.listRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get cancel listing operations from API * @param params Cancel listing parameters */ async getCancelListingOperations(params) { const response = await this.v3ApiClient.cancelOrder(nft_1.EvmApiMappers.v3.cancelListingRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get make item offer operations from API * @param params Make item offer parameters */ async getMakeItemOfferOperations(params) { const response = await this.v3ApiClient.placeBid(nft_1.EvmApiMappers.v3.makeItemOfferRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get take item offer operations from API * @param params Take item offer parameters */ async getTakeItemOfferOperations(params) { const response = await this.v3ApiClient.sell(nft_1.EvmApiMappers.v3.takeItemOfferRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get cancel item offer operations from API * @param params Cancel item offer parameters */ async getCancelItemOfferOperations(params) { const response = await this.v3ApiClient.cancelOrder(nft_1.EvmApiMappers.v3.cancelItemOfferRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get buy operations from API * @param params Buy parameters */ async getBuyOperations(params) { const response = await this.v3ApiClient.buy(nft_1.EvmApiMappers.v3.buyRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Get transfer operations from API * @param params Transfer parameters */ async getTransferOperations(params) { const response = await this.v3ApiClient.transfer(nft_1.EvmApiMappers.v3.transferRequest(this.config.wallet.getAddress(), params)); return transactions_1.EvmTransactionAdapters.fromV3TransactionResponse(response); } /** * Process a signature operation * @param operation Signature operation */ async processSignatureOperation(operation) { if (operation.signatureData.api !== 'v3') { throw new Error('Not implemented'); } try { const evmWallet = this.config.wallet; const signature = await evmWallet.signTypedData(operation.signatureData); if (operation.signatureData.post) { const orderResponse = await this.v3ApiClient .order({ chain: (0, helpers_1.getEvmChainFromId)(operation.signatureData.chainId), signature, data: operation.signatureData.post.body, }) .withRetries({ retries: 5, delay: 3000, }); return { signature, status: 'success', metadata: { results: orderResponse?.results, }, }; } return { signature, status: 'success', }; } catch (error) { return { signature: '', status: 'failed', error: error instanceof Error ? error.message : 'Unknown error', }; } } } exports.EvmNftService = EvmNftService;