import type { EthereumWallet } from "@rarible/sdk-wallet" import { createRaribleSdk } from "@rarible/protocol-ethereum-sdk" import type { ConfigurationParameters } from "@rarible/ethereum-api-client" import type { EthereumNetwork } from "@rarible/protocol-ethereum-sdk/build/types" import type { Maybe } from "@rarible/types/build/maybe" import { Blockchain } from "@rarible/api-client" import { toBinary } from "@rarible/types" import type { IApisSdk, IRaribleInternalSdk, LogsLevel } from "../../domain" import type { CanTransferResult } from "../../types/nft/restriction/domain" import { Middlewarer } from "../../common/middleware/middleware" import { MetaUploader } from "../union/meta/upload-meta" import { EthereumMint } from "./mint" import { EthereumSell } from "./sell" import { EthereumFill } from "./fill" import { EthereumBurn } from "./burn" import { EthereumTransfer } from "./transfer" import { EthereumBid } from "./bid" import { EthereumCancel } from "./cancel" import { EthereumBalance } from "./balance" import { EthereumTokenId } from "./token-id" import { EthereumCreateCollection } from "./create-collection" import { EthereumCryptopunk } from "./cryptopunk" import type { IEthereumSdkConfig } from "./domain" export function createEthereumSdk( wallet: Maybe, apis: IApisSdk, blockchain: Blockchain.ETHEREUM | Blockchain.POLYGON, network: EthereumNetwork, config: { params?: ConfigurationParameters, logs?: LogsLevel } & IEthereumSdkConfig ): IRaribleInternalSdk { const sdk = createRaribleSdk(wallet?.ethereum, network, { apiClientParams: config.params, logs: config.logs, ethereum: config[Blockchain.ETHEREUM], polygon: config[Blockchain.POLYGON], fillCalldata: config.fillCalldata ? toBinary(config.fillCalldata) : undefined, }) const sellService = new EthereumSell(sdk, network, config) const balanceService = new EthereumBalance(sdk, apis, network) const bidService = new EthereumBid(sdk, wallet, balanceService, network, config) const mintService = new EthereumMint(sdk, apis, network) const fillerService = new EthereumFill(sdk, wallet, network, config) const createCollectionService = new EthereumCreateCollection(sdk, network) const cryptopunkService = new EthereumCryptopunk(sdk, network) const preprocessMeta = Middlewarer.skipMiddleware(mintService.preprocessMeta) const metaUploader = new MetaUploader(Blockchain.ETHEREUM, preprocessMeta) return { nft: { transfer: new EthereumTransfer(sdk, network).transfer, mint: mintService.prepare, burn: new EthereumBurn(sdk, network).burn, generateTokenId: new EthereumTokenId(sdk).generateTokenId, deploy: createCollectionService.createCollection, createCollection: createCollectionService.createCollection, preprocessMeta, uploadMeta: metaUploader.uploadMeta, }, order: { fill: fillerService.fill, buy: fillerService.buy, batchBuy: fillerService.batchBuy, acceptBid: fillerService.acceptBid, sell: sellService.sell, sellUpdate: sellService.update, bid: bidService.bid, bidUpdate: bidService.update, cancel: new EthereumCancel(sdk, network).cancel, }, balances: { getBalance: balanceService.getBalance, convert: balanceService.convert, getBiddingBalance: balanceService.getBiddingBalance, depositBiddingBalance: balanceService.depositBiddingBalance, withdrawBiddingBalance: balanceService.withdrawBiddingBalance, }, restriction: { canTransfer(): Promise { return Promise.resolve({ success: true }) }, }, ethereum: { wrapCryptoPunk: cryptopunkService.wrap, unwrapCryptoPunk: cryptopunkService.unwrap, }, } }